Skip to content

Commit ea19373

Browse files
author
Sander van Rossen
committed
Made extrusion work in a inverted model
1 parent 734e809 commit ea19373

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

RealtimeCSG/Assets/Plugins/RealtimeCSG/API/Foundation/Editor/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace RealtimeCSG.Foundation
22
{
33
internal static class Versioning
44
{
5-
public const string PluginVersion = "1_566";
5+
public const string PluginVersion = "1_567";
66
public const string PluginDLLVersion = "1_559";
77
}
88
}

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Bindings/NativeMethodBindings.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_EDITOR
1+
#if UNITY_EDITOR
22
using UnityEngine;
33
using UnityEditor;
44
using System;
@@ -371,7 +371,7 @@ private static bool RayCastMulti(int modelCount,
371371
ignoreNodeIDsPtr = ignoreNodeIDsHandle.AddrOfPinnedObject();
372372
}
373373

374-
GCHandle outputIntersectionsHandle = GCHandle.Alloc(__outputIntersections, GCHandleType.Pinned);
374+
GCHandle outputIntersectionsHandle = GCHandle.Alloc(__outputIntersections, GCHandleType.Pinned);
375375

376376
var visibleLayers = Tools.visibleLayers;
377377
__intersectionList.Clear();
@@ -390,7 +390,7 @@ private static bool RayCastMulti(int modelCount,
390390

391391
if (intersectionCount == 0)
392392
continue;
393-
393+
394394
if (__prevIntersectionCount < intersectionCount)
395395
{
396396
if (outputIntersectionsHandle.IsAllocated)
@@ -449,10 +449,9 @@ private static bool RayCastMulti(int modelCount,
449449
}
450450

451451
__intersectionList.Sort(delegate(LegacyBrushIntersection x, LegacyBrushIntersection y)
452-
{
453-
return (int)Mathf.Sign(y.distance - x.distance);
454-
}
455-
);
452+
{
453+
return (int)Mathf.Sign(y.distance - x.distance);
454+
});
456455

457456
intersections = __intersectionList.ToArray();
458457
return true;

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Data/SceneQuery/SceneQueryUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ public static bool FindWorldIntersection(Vector3 rayStart, Vector3 rayEnd, out L
882882
{
883883
var model = InternalCSGModelManager.Models[g];
884884

885-
if (!ModelTraits.IsModelSelectable(model))
885+
if (!model.isActiveAndEnabled || !ModelTraits.IsModelSelectable(model))
886886
continue;
887887

888888
if (ignoreUnrenderables && !ModelTraits.WillModelRender(model) &&
@@ -922,7 +922,7 @@ public static bool FindWorldIntersection(Vector3 rayStart, Vector3 rayEnd, out L
922922

923923
intersection = modelIntersection;
924924
}
925-
925+
926926
if (intersection == null)
927927
return false;
928928

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Utility/PrefabUtility.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ public static GameObject GetPrefabAsset(GameObject gameObject)
129129
{
130130
var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
131131
if (prefabStage.IsPartOfPrefabContents(gameObject))
132+
#if UNITY_2020_1_OR_NEWER
133+
return (GameObject)AssetDatabase.LoadMainAssetAtPath(prefabStage.assetPath);
134+
#else
132135
return (GameObject)AssetDatabase.LoadMainAssetAtPath(prefabStage.prefabAssetPath);
136+
#endif
133137
}
134138
#endif
135139

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/Generators/Generator.ExtrudedBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ protected bool UpdateExtrudedShape(bool registerUndo = true)
286286
Cancel();
287287
return false;
288288
}
289+
289290
if (generatedGameObjects != null && generatedGameObjects.Length > 0)
290291
{
291292
if (registerUndo)
@@ -355,8 +356,8 @@ protected bool UpdateExtrudedShape(bool registerUndo = true)
355356
brush.ControlMesh.SetDirty();
356357
if (registerUndo)
357358
EditorUtility.SetDirty(brush);
358-
}
359-
}
359+
}
360+
}
360361
HideGenerateBrushes();
361362
}
362363
}

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/Generators/Generator.FreeDraw.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using UnityEditor;
44
using UnityEngine;
@@ -92,6 +92,13 @@ public void GenerateFromPolygon(Camera camera, CSGBrush brush, CSGPlane plane, V
9292
base.planeOnGeometry = true;
9393
base.smearTextures = false;
9494

95+
96+
var brushScale = brush.transform.lossyScale;
97+
var brushInverted = (Math.Sign(brushScale.x) * Math.Sign(brushScale.y) * Math.Sign(brushScale.z)) < 0;
98+
99+
if (brushInverted)
100+
plane = plane.Negated();
101+
95102
settings.Init(meshVertices, indices);
96103

97104
haveForcedDirection = true;
@@ -364,7 +371,7 @@ internal override bool UpdateBaseShape(bool registerUndo = true)
364371
if (curvedEdges == null)
365372
return false;
366373
ShapePolygonUtility.RemoveDuplicatePoints(ref outlineVertices);
367-
374+
368375
if (generateSmoothing)
369376
{
370377
var usedSmoothingGroupIndices = SurfaceUtility.GetUsedSmoothingGroupIndices();
@@ -1373,7 +1380,7 @@ protected override void HandleEditShapeEvents(SceneView sceneView, Rect sceneRec
13731380
visualSnappedBrush.ChildData != null &&
13741381
visualSnappedBrush.ChildData.ModelTransform)
13751382
{
1376-
var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
1383+
var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
13771384
CSGRenderer.DrawOutlines(visualSnappedBrush.brushNodeID, brush_transformation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines);
13781385
}
13791386
}
@@ -1518,7 +1525,7 @@ protected override void HandleEditShapeEvents(SceneView sceneView, Rect sceneRec
15181525
visualSnappedBrush.ChildData != null &&
15191526
visualSnappedBrush.ChildData.ModelTransform)
15201527
{
1521-
var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
1528+
var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
15221529
CSGRenderer.DrawOutlines(visualSnappedBrush.brushNodeID, brush_transformation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines);
15231530
}
15241531
}

0 commit comments

Comments
 (0)