Skip to content

Commit 4a969ef

Browse files
kerfufflesFriskTheFallenHuman
authored andcommitted
MSC Bug Fixes (LogicalError#349)
Co-authored-by: Zallist <[email protected]> Co-authored-by: Gawi <[email protected]> * Update Window.mat and Window.png to support proper transparency and specularity. * Fixes LogicalError#323 * Fixes LogicalError#355 * Fixes LogicalError#350 * Fixes LogicalError#319 * Fixes LogicalError#320 * Fixes LogicalError#354 * Fixes LogicalError#356 * Fixes LogicalError#365 * Fixes LogicalError#366
1 parent a3ccdb6 commit 4a969ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+601
-177
lines changed

.gitignore

-10
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,5 @@ Logs/
4646

4747
ProjectSettings/ProjectVersion\.txt
4848

49-
5049
*.exp
51-
5250
*.lib
53-
54-
Packages/com\.chisel\.core/Chisel/Core/API\.private/Native/Plugin/x64/Chisel\[TEST\]\.exp\.meta
55-
LICENSE.md.meta
56-
Icons.zip.meta
57-
README.md.meta
58-
Readme.meta
59-
Readme/Images.meta
60-
Readme/Images/house_view.png.meta

Icons.zip.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/Editor/Resources/RealtimeCSG.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/Editor/Scripts/Control/BrushTraits.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public static bool IsSurfaceUnselectable(CSGBrush brush, int surfaceIndex, bool
3939
return true;
4040
}
4141

42-
if (ignoreSurfaceFlags)
42+
if( (texGenFlags[texGenIndex] & TexGenFlags.NoRender) == TexGenFlags.NoRender )
43+
return false;
44+
45+
if (ignoreSurfaceFlags)
4346
{
4447
var isNotRenderable = (texGenFlags[texGenIndex] & TexGenFlags.NoRender) == TexGenFlags.NoRender;
4548
if (!isNotRenderable)

Plugins/Editor/Scripts/Control/BrushUtility.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void SetPivot(CSGBrush brush, Vector3 newCenter)
5050
var realCenter = transform.position;
5151
var difference = newCenter - realCenter;
5252

53-
if (difference.sqrMagnitude < MathConstants.ConsideredZero)
53+
if (difference.magnitude < MathConstants.ConsideredZero)
5454
return;
5555

5656
transform.position += difference;
@@ -64,7 +64,7 @@ public static void TranslatePivot(CSGBrush[] brushes, Vector3 offset)
6464
{
6565
if (brushes == null ||
6666
brushes.Length == 0 ||
67-
offset.sqrMagnitude < MathConstants.ConsideredZero)
67+
offset.magnitude < MathConstants.ConsideredZero)
6868
return;
6969

7070
for (int i = 0; i < brushes.Length; i++)

Plugins/Editor/Scripts/Control/Helpers/ControlMeshUtility.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public static void MergeVerticesOnEdges(ControlMesh controlMesh, short[] pointIn
290290
var vertex2 = controlMesh.Vertices[vertexIndex2];
291291
var pointOnLine = ProjectPointLine(point, vertex1, vertex2);
292292
var delta = pointOnLine - point;
293-
var distance = delta.sqrMagnitude;
293+
var distance = delta.magnitude;
294294
if (distance < closestDistance)
295295
{
296296
closestEdge = e;
@@ -3867,7 +3867,7 @@ public static short[] FindDuplicateVerticesToRemove(CSGBrush brush, ControlMeshS
38673867
for (var index2 = index1 + 1; index2 < vertices.Length; index2++)
38683868
{
38693869
var vertex2 = vertices[index2];
3870-
if (!((vertex1 - vertex2).sqrMagnitude < MathConstants.EqualityEpsilon))
3870+
if (!((vertex1 - vertex2).magnitude < MathConstants.EqualityEpsilon))
38713871
continue;
38723872

38733873
//if ((pointSelectState[index1] & SelectState.Selected) != SelectState.Selected &&
@@ -3917,7 +3917,7 @@ public static short[] FindDuplicateVerticesToRemove(CSGBrush brush)
39173917
for (var index2 = index1 + 1; index2 < vertices.Length; index2++)
39183918
{
39193919
var vertex2 = vertices[index2];
3920-
if (!((vertex1 - vertex2).sqrMagnitude < MathConstants.EqualityEpsilon))
3920+
if (!((vertex1 - vertex2).magnitude < MathConstants.EqualityEpsilon))
39213921
continue;
39223922

39233923
var found = false;

Plugins/Editor/Scripts/Control/Helpers/ShapePolygonUtility.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public static void RemoveDuplicatePoints(ref Vector3[] vertices)
8181
// remove any points that are too close to one another
8282
for (int j = vertices.Length - 1, i = vertices.Length - 2; i >= 0; j = i, i--)
8383
{
84-
if ((vertices[j] - vertices[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
84+
if ((vertices[j] - vertices[i]).magnitude < MathConstants.DistanceEpsilon)
8585
{
8686
ArrayUtility.RemoveAt(ref vertices, j);
8787
}
8888
}
89-
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).sqrMagnitude < MathConstants.DistanceEpsilon)
89+
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).magnitude < MathConstants.DistanceEpsilon)
9090
{
9191
var lastIndex = vertices.Length - 1;
9292
ArrayUtility.RemoveAt(ref vertices, lastIndex);
@@ -101,13 +101,13 @@ public static void RemoveDuplicatePoints(ShapePolygon shapePolygon)
101101
// remove any points that are too close to one another
102102
for (int j = vertices.Length - 1, i = vertices.Length - 2; i >= 0; j = i, i--)
103103
{
104-
if ((vertices[j] - vertices[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
104+
if ((vertices[j] - vertices[i]).magnitude < MathConstants.DistanceEpsilon)
105105
{
106106
ArrayUtility.RemoveAt(ref vertices, j);
107107
ArrayUtility.RemoveAt(ref edgeTexgens, j);
108108
}
109109
}
110-
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).sqrMagnitude < MathConstants.DistanceEpsilon)
110+
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).magnitude < MathConstants.DistanceEpsilon)
111111
{
112112
var lastIndex = vertices.Length - 1;
113113
ArrayUtility.RemoveAt(ref vertices, lastIndex);
@@ -159,7 +159,7 @@ private static List<ShapePolygon> CreateCleanSubPolygonsFromVertices(Vector2[] v
159159
{
160160
for (int j = i + 2; j < vertices2d.Length; j++)
161161
{
162-
if ((vertices2d[j] - vertices2d[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
162+
if ((vertices2d[j] - vertices2d[i]).magnitude < MathConstants.DistanceEpsilon)
163163
{
164164
List<ShapePolygon> combined_polygons = null;
165165

Plugins/Editor/Scripts/Control/Managers/CSGModelManager.cs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ namespace RealtimeCSG
77
{
88
public static class CSGModelManager
99
{
10+
public static bool AllowInEditorPlayMode = false;
11+
12+
public static bool IsInPlayMode
13+
{
14+
get => !AllowInEditorPlayMode && (UnityEditor.EditorApplication.isPlaying || UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode);
15+
}
16+
1017
public static void ForceRebuild()
1118
{
1219
#if UNITY_EDITOR

Plugins/Editor/Scripts/Control/Managers/InternalCSGModelManager.Lifetime.cs

+65-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal partial class InternalCSGModelManager
1212
internal static NativeMethods External;
1313

1414
#region Clear
15-
#if UNITY_2019_4_OR_NEWER
15+
#if UNITY_2019_4_OR_NEWER
1616
[RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.SubsystemRegistration )]
1717
#endif
1818
public static void Clear()
@@ -96,7 +96,7 @@ public static void UndoRedoPerformed()
9696
public static bool skipCheckForChanges = false;
9797
public static void CheckForChanges(bool forceHierarchyUpdate = false)
9898
{
99-
if (EditorApplication.isPlayingOrWillChangePlaymode)
99+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
100100
return;
101101

102102
if (!forceHierarchyUpdate && skipCheckForChanges)
@@ -153,5 +153,68 @@ public static void ForceRebuildAll()
153153

154154
}
155155
#endregion
156+
157+
#if UNITY_EDITOR
158+
159+
[UnityEditor.InitializeOnEnterPlayMode]
160+
public static void OnEnterPlayMode()
161+
{
162+
// If saving meshes to scene files, we don't need to dynamically rebuild on scene changes
163+
if (CSGProjectSettings.Instance.SaveMeshesInSceneFiles)
164+
return;
165+
166+
static bool ensureExternalMethodsPopulated()
167+
{
168+
if (External == null ||
169+
External.ResetCSG == null)
170+
{
171+
NativeMethodBindings.RegisterUnityMethods();
172+
NativeMethodBindings.RegisterExternalMethods();
173+
}
174+
175+
if (External == null)
176+
{
177+
Debug.LogError("RealtimeCSG: Cannot rebuild meshes for some reason. External modules not loaded. Please save meshes into the Scene.");
178+
return false;
179+
}
180+
181+
return true;
182+
}
183+
184+
static void rebuildMeshes()
185+
{
186+
if (!ensureExternalMethodsPopulated())
187+
return;
188+
189+
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = true;
190+
InternalCSGModelManager.Shutdown();
191+
DoForcedMeshUpdate();
192+
InternalCSGModelManager.CheckForChanges(false);
193+
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = false;
194+
}
195+
196+
static void sceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
197+
{
198+
rebuildMeshes();
199+
}
200+
201+
static void onPlayModeChange(PlayModeStateChange playMode)
202+
{
203+
if (playMode == PlayModeStateChange.EnteredEditMode)
204+
{
205+
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= sceneLoaded;
206+
EditorApplication.playModeStateChanged -= onPlayModeChange;
207+
208+
rebuildMeshes();
209+
}
210+
}
211+
212+
if (!ensureExternalMethodsPopulated())
213+
return;
214+
215+
EditorApplication.playModeStateChanged += onPlayModeChange;
216+
UnityEngine.SceneManagement.SceneManager.sceneLoaded += sceneLoaded;
217+
}
218+
#endif
156219
}
157220
}

Plugins/Editor/Scripts/Control/Managers/InternalCSGModelManager.Registration.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static bool RegisterAllComponents()
7979

8080
Clear();
8181

82-
if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode)
82+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
8383
{
8484
return false;
8585
}
@@ -105,7 +105,7 @@ static bool RegisterAllComponents()
105105
#region Reset
106106
public static void Reset(CSGNode node)
107107
{
108-
if (EditorApplication.isPlayingOrWillChangePlaymode)
108+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
109109
{
110110
return;
111111
}
@@ -122,7 +122,7 @@ public static void Reset(CSGNode node)
122122
#region AddNodeRegistration
123123
static void AddNodeRegistration(CSGNode node)
124124
{
125-
if (EditorApplication.isPlayingOrWillChangePlaymode)
125+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
126126
{
127127
return;
128128
}
@@ -461,7 +461,7 @@ public static void Reset(CSGModel component)
461461
#region RegisterChild
462462
static void RegisterChild(ChildNodeData childData)
463463
{
464-
if (EditorApplication.isPlayingOrWillChangePlaymode)
464+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
465465
return;
466466

467467
// make sure our model has actually been initialized
@@ -485,7 +485,7 @@ static void RegisterChild(ChildNodeData childData)
485485
#region RegisterBrush
486486
static void RegisterBrush(CSGBrush brush)
487487
{
488-
if (EditorApplication.isPlayingOrWillChangePlaymode ||
488+
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
489489
External == null ||
490490
!brush ||
491491
!brush.isActiveAndEnabled ||
@@ -572,7 +572,7 @@ static void RegisterBrush(CSGBrush brush)
572572
#region RegisterOperation
573573
static void RegisterOperation(CSGOperation op)
574574
{
575-
if (EditorApplication.isPlayingOrWillChangePlaymode ||
575+
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
576576
External == null ||
577577
!op ||
578578
!op.isActiveAndEnabled ||
@@ -634,7 +634,7 @@ static void RegisterOperation(CSGOperation op)
634634
#region RegisterModel
635635
private static void RegisterModel(CSGModel model)
636636
{
637-
if (EditorApplication.isPlayingOrWillChangePlaymode ||
637+
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
638638
External == null ||
639639
!model ||
640640
!model.isActiveAndEnabled ||
@@ -726,7 +726,7 @@ public static void SetBrushMeshSurfaces(CSGBrush brush)
726726
#region UnregisterBrush
727727
static void UnregisterBrush(CSGBrush brush)
728728
{
729-
if (EditorApplication.isPlayingOrWillChangePlaymode)
729+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
730730
return;
731731

732732
if (External == null)
@@ -773,7 +773,7 @@ static void UnregisterBrush(CSGBrush brush)
773773
#region UnregisterOperation
774774
static void UnregisterOperation(CSGOperation op)
775775
{
776-
if (EditorApplication.isPlayingOrWillChangePlaymode)
776+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
777777
return;
778778

779779
if (External == null)
@@ -820,7 +820,7 @@ static void UnregisterOperation(CSGOperation op)
820820
#region UnregisterModel
821821
static void UnregisterModel(CSGModel model)
822822
{
823-
if (EditorApplication.isPlayingOrWillChangePlaymode)
823+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
824824
return;
825825

826826
if (!model.IsRegistered)
@@ -862,7 +862,7 @@ static void UnregisterModel(CSGModel model)
862862
#region EnableModel
863863
private static void EnableModel(CSGModel model)
864864
{
865-
if (EditorApplication.isPlayingOrWillChangePlaymode)
865+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
866866
return;
867867

868868
if (External == null)
@@ -889,7 +889,7 @@ private static void EnableModel(CSGModel model)
889889
#region DisableModel
890890
private static void DisableModel(CSGModel model)
891891
{
892-
if (EditorApplication.isPlayingOrWillChangePlaymode)
892+
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
893893
return;
894894

895895
if (External == null)

0 commit comments

Comments
 (0)