Skip to content

Commit

Permalink
MSC Bug Fixes (LogicalError#349)
Browse files Browse the repository at this point in the history
Co-authored-by: Zallist <Zallist@gmail.com>
Co-authored-by: Gawi <95928592+Gawidev@users.noreply.github.com>

* 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
  • Loading branch information
kerfuffles authored and FriskTheFallenHuman committed Jan 30, 2023
1 parent a3ccdb6 commit 4a969ef
Show file tree
Hide file tree
Showing 61 changed files with 601 additions and 177 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,5 @@ Logs/

ProjectSettings/ProjectVersion\.txt


*.exp

*.lib

Packages/com\.chisel\.core/Chisel/Core/API\.private/Native/Plugin/x64/Chisel\[TEST\]\.exp\.meta
LICENSE.md.meta
Icons.zip.meta
README.md.meta
Readme.meta
Readme/Images.meta
Readme/Images/house_view.png.meta
7 changes: 7 additions & 0 deletions Icons.zip.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Plugins/Editor/Resources/RealtimeCSG.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
5 changes: 4 additions & 1 deletion Plugins/Editor/Scripts/Control/BrushTraits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public static bool IsSurfaceUnselectable(CSGBrush brush, int surfaceIndex, bool
return true;
}

if (ignoreSurfaceFlags)
if( (texGenFlags[texGenIndex] & TexGenFlags.NoRender) == TexGenFlags.NoRender )
return false;

if (ignoreSurfaceFlags)
{
var isNotRenderable = (texGenFlags[texGenIndex] & TexGenFlags.NoRender) == TexGenFlags.NoRender;
if (!isNotRenderable)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Editor/Scripts/Control/BrushUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void SetPivot(CSGBrush brush, Vector3 newCenter)
var realCenter = transform.position;
var difference = newCenter - realCenter;

if (difference.sqrMagnitude < MathConstants.ConsideredZero)
if (difference.magnitude < MathConstants.ConsideredZero)
return;

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

for (int i = 0; i < brushes.Length; i++)
Expand Down
6 changes: 3 additions & 3 deletions Plugins/Editor/Scripts/Control/Helpers/ControlMeshUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static void MergeVerticesOnEdges(ControlMesh controlMesh, short[] pointIn
var vertex2 = controlMesh.Vertices[vertexIndex2];
var pointOnLine = ProjectPointLine(point, vertex1, vertex2);
var delta = pointOnLine - point;
var distance = delta.sqrMagnitude;
var distance = delta.magnitude;
if (distance < closestDistance)
{
closestEdge = e;
Expand Down Expand Up @@ -3867,7 +3867,7 @@ public static short[] FindDuplicateVerticesToRemove(CSGBrush brush, ControlMeshS
for (var index2 = index1 + 1; index2 < vertices.Length; index2++)
{
var vertex2 = vertices[index2];
if (!((vertex1 - vertex2).sqrMagnitude < MathConstants.EqualityEpsilon))
if (!((vertex1 - vertex2).magnitude < MathConstants.EqualityEpsilon))
continue;

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

var found = false;
Expand Down
10 changes: 5 additions & 5 deletions Plugins/Editor/Scripts/Control/Helpers/ShapePolygonUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public static void RemoveDuplicatePoints(ref Vector3[] vertices)
// remove any points that are too close to one another
for (int j = vertices.Length - 1, i = vertices.Length - 2; i >= 0; j = i, i--)
{
if ((vertices[j] - vertices[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
if ((vertices[j] - vertices[i]).magnitude < MathConstants.DistanceEpsilon)
{
ArrayUtility.RemoveAt(ref vertices, j);
}
}
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).sqrMagnitude < MathConstants.DistanceEpsilon)
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).magnitude < MathConstants.DistanceEpsilon)
{
var lastIndex = vertices.Length - 1;
ArrayUtility.RemoveAt(ref vertices, lastIndex);
Expand All @@ -101,13 +101,13 @@ public static void RemoveDuplicatePoints(ShapePolygon shapePolygon)
// remove any points that are too close to one another
for (int j = vertices.Length - 1, i = vertices.Length - 2; i >= 0; j = i, i--)
{
if ((vertices[j] - vertices[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
if ((vertices[j] - vertices[i]).magnitude < MathConstants.DistanceEpsilon)
{
ArrayUtility.RemoveAt(ref vertices, j);
ArrayUtility.RemoveAt(ref edgeTexgens, j);
}
}
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).sqrMagnitude < MathConstants.DistanceEpsilon)
while (vertices.Length > 3 && (vertices[0] - vertices[vertices.Length - 1]).magnitude < MathConstants.DistanceEpsilon)
{
var lastIndex = vertices.Length - 1;
ArrayUtility.RemoveAt(ref vertices, lastIndex);
Expand Down Expand Up @@ -159,7 +159,7 @@ private static List<ShapePolygon> CreateCleanSubPolygonsFromVertices(Vector2[] v
{
for (int j = i + 2; j < vertices2d.Length; j++)
{
if ((vertices2d[j] - vertices2d[i]).sqrMagnitude < MathConstants.DistanceEpsilon)
if ((vertices2d[j] - vertices2d[i]).magnitude < MathConstants.DistanceEpsilon)
{
List<ShapePolygon> combined_polygons = null;

Expand Down
7 changes: 7 additions & 0 deletions Plugins/Editor/Scripts/Control/Managers/CSGModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ namespace RealtimeCSG
{
public static class CSGModelManager
{
public static bool AllowInEditorPlayMode = false;

public static bool IsInPlayMode
{
get => !AllowInEditorPlayMode && (UnityEditor.EditorApplication.isPlaying || UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode);
}

public static void ForceRebuild()
{
#if UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal partial class InternalCSGModelManager
internal static NativeMethods External;

#region Clear
#if UNITY_2019_4_OR_NEWER
#if UNITY_2019_4_OR_NEWER
[RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.SubsystemRegistration )]
#endif
public static void Clear()
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void UndoRedoPerformed()
public static bool skipCheckForChanges = false;
public static void CheckForChanges(bool forceHierarchyUpdate = false)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (!forceHierarchyUpdate && skipCheckForChanges)
Expand Down Expand Up @@ -153,5 +153,68 @@ public static void ForceRebuildAll()

}
#endregion

#if UNITY_EDITOR

[UnityEditor.InitializeOnEnterPlayMode]
public static void OnEnterPlayMode()
{
// If saving meshes to scene files, we don't need to dynamically rebuild on scene changes
if (CSGProjectSettings.Instance.SaveMeshesInSceneFiles)
return;

static bool ensureExternalMethodsPopulated()
{
if (External == null ||
External.ResetCSG == null)
{
NativeMethodBindings.RegisterUnityMethods();
NativeMethodBindings.RegisterExternalMethods();
}

if (External == null)
{
Debug.LogError("RealtimeCSG: Cannot rebuild meshes for some reason. External modules not loaded. Please save meshes into the Scene.");
return false;
}

return true;
}

static void rebuildMeshes()
{
if (!ensureExternalMethodsPopulated())
return;

RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = true;
InternalCSGModelManager.Shutdown();
DoForcedMeshUpdate();
InternalCSGModelManager.CheckForChanges(false);
RealtimeCSG.CSGModelManager.AllowInEditorPlayMode = false;
}

static void sceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
{
rebuildMeshes();
}

static void onPlayModeChange(PlayModeStateChange playMode)
{
if (playMode == PlayModeStateChange.EnteredEditMode)
{
UnityEngine.SceneManagement.SceneManager.sceneLoaded -= sceneLoaded;
EditorApplication.playModeStateChanged -= onPlayModeChange;

rebuildMeshes();
}
}

if (!ensureExternalMethodsPopulated())
return;

EditorApplication.playModeStateChanged += onPlayModeChange;
UnityEngine.SceneManagement.SceneManager.sceneLoaded += sceneLoaded;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static bool RegisterAllComponents()

Clear();

if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
{
return false;
}
Expand All @@ -105,7 +105,7 @@ static bool RegisterAllComponents()
#region Reset
public static void Reset(CSGNode node)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
{
return;
}
Expand All @@ -122,7 +122,7 @@ public static void Reset(CSGNode node)
#region AddNodeRegistration
static void AddNodeRegistration(CSGNode node)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
{
return;
}
Expand Down Expand Up @@ -461,7 +461,7 @@ public static void Reset(CSGModel component)
#region RegisterChild
static void RegisterChild(ChildNodeData childData)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

// make sure our model has actually been initialized
Expand All @@ -485,7 +485,7 @@ static void RegisterChild(ChildNodeData childData)
#region RegisterBrush
static void RegisterBrush(CSGBrush brush)
{
if (EditorApplication.isPlayingOrWillChangePlaymode ||
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
External == null ||
!brush ||
!brush.isActiveAndEnabled ||
Expand Down Expand Up @@ -572,7 +572,7 @@ static void RegisterBrush(CSGBrush brush)
#region RegisterOperation
static void RegisterOperation(CSGOperation op)
{
if (EditorApplication.isPlayingOrWillChangePlaymode ||
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
External == null ||
!op ||
!op.isActiveAndEnabled ||
Expand Down Expand Up @@ -634,7 +634,7 @@ static void RegisterOperation(CSGOperation op)
#region RegisterModel
private static void RegisterModel(CSGModel model)
{
if (EditorApplication.isPlayingOrWillChangePlaymode ||
if (RealtimeCSG.CSGModelManager.IsInPlayMode ||
External == null ||
!model ||
!model.isActiveAndEnabled ||
Expand Down Expand Up @@ -726,7 +726,7 @@ public static void SetBrushMeshSurfaces(CSGBrush brush)
#region UnregisterBrush
static void UnregisterBrush(CSGBrush brush)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (External == null)
Expand Down Expand Up @@ -773,7 +773,7 @@ static void UnregisterBrush(CSGBrush brush)
#region UnregisterOperation
static void UnregisterOperation(CSGOperation op)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (External == null)
Expand Down Expand Up @@ -820,7 +820,7 @@ static void UnregisterOperation(CSGOperation op)
#region UnregisterModel
static void UnregisterModel(CSGModel model)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (!model.IsRegistered)
Expand Down Expand Up @@ -862,7 +862,7 @@ static void UnregisterModel(CSGModel model)
#region EnableModel
private static void EnableModel(CSGModel model)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (External == null)
Expand All @@ -889,7 +889,7 @@ private static void EnableModel(CSGModel model)
#region DisableModel
private static void DisableModel(CSGModel model)
{
if (EditorApplication.isPlayingOrWillChangePlaymode)
if (RealtimeCSG.CSGModelManager.IsInPlayMode)
return;

if (External == null)
Expand Down
Loading

0 comments on commit 4a969ef

Please sign in to comment.