public IEnumerator DisabledOperationWithPassThroughEnabled_EnableOperationComponent_OperationDoesNotExist() { var scene = TestUtility.defaultScene; var operation = TestUtility.CreateUndoableGameObjectWithOperation(); var operationGameObject = operation.gameObject; operation.enabled = false; operation.PassThrough = true; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); operation.enabled = true; yield return(null); Assert.True(operationGameObject); Assert.True(operation); Assert.AreEqual(operation.Node, (CSGTreeBranch)CSGTreeNode.InvalidNode); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); }
public IEnumerator OperationWithPassThroughEnabled_DestroyOperationComponent_OperationDoesNotExist() { var scene = TestUtility.defaultScene; var operation = TestUtility.CreateUndoableGameObjectWithOperation(); var operationGameObject = operation.gameObject; operation.PassThrough = true; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.True(operationGameObject); Assert.True(operation); Undo.DestroyObjectImmediate(operation); yield return(null); Assert.True(operationGameObject); Assert.False(operation); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); }
public static void SelectBrushVariant(CSGTreeBrush brush, bool uniqueSelection = false) { Undo.RecordObject(ChiselSyncSelection.Instance, "Selected brush variant"); var node = ChiselNodeHierarchyManager.FindChiselNodeByTreeNode(brush); if (node) { node.hierarchyItem.SetBoundsDirty(); } var selectedBrushesLookup = Instance.selectedBrushesLookup; var modified = false;/* * if (uniqueSelection) * { * foreach (var variant in brush.AllSynchronizedVariants) * { * if (variant != brush) * modified = selectedBrushesLookup.Remove(variant) || modified; * } * }*/ modified = selectedBrushesLookup.Add(brush); if (modified) { ChiselOutlineRenderer.Instance.OnSelectionChanged(); } }
public IEnumerator CompositeWithPassThroughEnabled_DestroyCompositeGameObject_CompositeDoesNotExist() { var scene = TestUtility.defaultScene; var composite = TestUtility.CreateUndoableGameObjectWithComposite(); var compositeGameObject = composite.gameObject; composite.PassThrough = true; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.True(compositeGameObject); Assert.True(composite); Undo.DestroyObjectImmediate(compositeGameObject); yield return(null); Assert.False(compositeGameObject); Assert.False(composite); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); }
public static bool GetNodesInFrustum(Frustum frustum, int visibleLayers, ref HashSet <CSGTreeNode> rectFoundNodes) { var planes = new Plane[6]; Vector4 srcVector; var allTrees = CSGManager.AllTrees; for (var t = 0; t < allTrees.Length; t++) { var tree = allTrees[t]; var model = ChiselNodeHierarchyManager.FindChiselNodeByTreeNode(tree) as ChiselModel; if (!model || !model.isActiveAndEnabled) { continue; } if (((1 << model.gameObject.layer) & visibleLayers) == 0) { continue; } var query = ChiselMeshQueryManager.GetMeshQuery(model); // We only accept RayCasts into this model if it's visible if (!ChiselMeshQueryManager.IsVisible(query)) { continue; } // Transform the frustum into the space of the tree var transform = model.transform; var worldToLocalMatrixInversed = transform.localToWorldMatrix; // localToWorldMatrix == worldToLocalMatrix.inverse var worldToLocalMatrixInversedTransposed = worldToLocalMatrixInversed.transpose; for (int p = 0; p < 6; p++) { var srcPlane = frustum.Planes[p]; srcVector.x = srcPlane.normal.x; srcVector.y = srcPlane.normal.y; srcVector.z = srcPlane.normal.z; srcVector.w = srcPlane.distance; srcVector = worldToLocalMatrixInversedTransposed * srcVector; planes[p].normal = srcVector; planes[p].distance = srcVector.w; } var treeNodesInFrustum = tree.GetNodesInFrustum(planes); if (treeNodesInFrustum == null) { continue; } for (int n = 0; n < treeNodesInFrustum.Length; n++) { var treeNode = treeNodesInFrustum[n]; rectFoundNodes.Add(treeNode); } } return(rectFoundNodes.Count > 0); }
public IEnumerator CreateBrush_DeactivateBrushGameObject_BrushDoesNotExist() { var scene = TestUtility.defaultScene; var brush = TestUtility.CreateUndoableGameObjectWithBrush(); var brushGameObject = brush.gameObject; Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist"); Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist"); Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist"); // default model Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); brushGameObject.SetActive(false); yield return(null); Assert.True(brushGameObject); Assert.True(brush); Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist"); Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); }
public IEnumerator DisabledCompositeWithPassThroughEnabled_EnableCompositeComponent_CompositeDoesNotExist() { var scene = TestUtility.defaultScene; var composite = TestUtility.CreateUndoableGameObjectWithComposite(); var compositeGameObject = composite.gameObject; composite.enabled = false; composite.PassThrough = true; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); composite.enabled = true; yield return(null); Assert.True(compositeGameObject); Assert.True(composite); Assert.AreEqual(composite.Node, (CSGTreeBranch)CSGTreeNode.InvalidNode); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); }
public static void ClearScene() { defaultScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); CSGManager.Clear(); ChiselNodeHierarchyManager.Reset(); ChiselNodeHierarchyManager.Update(); }
public IEnumerator CreateBrushWithBrushContainerAssetWithBrushMaterial_ModifyBrushMaterial_BrushIsDirty() { using (var newBrushMaterial = ChiselBrushMaterial.CreateInstance()) { newBrushMaterial.LayerUsage = LayerUsageFlags.None; var newBrushContainerAsset = CreateBox(Vector3.one, newBrushMaterial); var brushGameObject = EditorUtility.CreateGameObjectWithHideFlags("Brush", HideFlags.None); var brush = brushGameObject.AddComponent <ChiselBrush>(); brush.BrushContainerAsset = newBrushContainerAsset; yield return(null); ChiselBrushContainerAssetManager.Update(); ChiselNodeHierarchyManager.Update(); newBrushMaterial.LayerUsage = LayerUsageFlags.Renderable; ChiselBrushContainerAssetManager.Update(); Assert.IsTrue(brush.Dirty); yield return(null); UnityEngine.Object.DestroyImmediate(brushGameObject); UnityEngine.Object.DestroyImmediate(newBrushContainerAsset); } }
public IEnumerator CreateAndDestroyOperationGameObject_Undo_OperationExists() { var scene = TestUtility.defaultScene; var operation = TestUtility.CreateUndoableGameObjectWithOperation(); var operationGameObject = operation.gameObject; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Undo.FlushUndoRecordObjects(); Undo.IncrementCurrentGroup(); yield return(null); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Undo.DestroyObjectImmediate(operationGameObject); yield return(null); Assert.False(operationGameObject); Assert.False(operation); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); Undo.PerformUndo(); operation = Object.FindObjectsOfType <ChiselOperation>()[0]; operationGameObject = operation.gameObject; yield return(null); Assert.True(operationGameObject); Assert.True(operation); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Assert.AreEqual(1, ChiselNodeHierarchyManager.RootCount(scene)); }
public static SurfaceIntersection FindSurfaceIntersection(Vector2 position) { try { CSGTreeBrushIntersection brushIntersection; if (!PickFirstGameObject(position, out brushIntersection)) { return(null); } var brush = brushIntersection.brush; var node = ChiselNodeHierarchyManager.FindChiselNodeByInstanceID(brush.UserID); if (!node) { return(null); } var surface = node.FindSurfaceReference(brush, brushIntersection.surfaceID); if (surface == null) { return(null); } return(new SurfaceIntersection { surface = surface, intersection = brushIntersection.surfaceIntersection }); } catch (Exception ex) { Debug.LogException(ex); return(null); } }
public IEnumerator CreateAndDestroyCompositeComponent_Undo_CompositeExists() { var scene = TestUtility.defaultScene; var composite = TestUtility.CreateGameObjectWithUndoableCompositeComponent(); var compositeGameObject = composite.gameObject; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Undo.FlushUndoRecordObjects(); Undo.IncrementCurrentGroup(); yield return(null); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Undo.DestroyObjectImmediate(composite); yield return(null); Assert.True(compositeGameObject); Assert.False(composite); Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene)); Undo.PerformUndo(); composite = compositeGameObject.GetComponent <ChiselComposite>(); yield return(null); Assert.True(compositeGameObject); Assert.True(composite); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Assert.AreEqual(1, ChiselNodeHierarchyManager.RootCount(scene)); }
public IEnumerator CreateBrushInScene1_MoveToScene2_BrushOnlyExistsInScene2() { var scene2 = TestUtility.defaultScene; EditorSceneManager.SaveScene(scene2, TestUtility.tempFilename); var scene1 = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive); EditorSceneManager.SetActiveScene(scene1); var brush = TestUtility.CreateUndoableGameObjectWithBrush(); var brushGameObject = brush.gameObject; Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Assert.AreEqual(scene1, brush.hierarchyItem.Scene); Undo.MoveGameObjectToScene(brushGameObject, scene2, "Move gameObject to different scene"); yield return(null); Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist"); Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist"); Assert.AreEqual(scene2, brush.gameObject.scene, "Brush is not part of expected scene"); Assert.AreEqual(scene2, brush.hierarchyItem.Scene, "Brush is not registered to expected scene"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene1)); Assert.AreEqual(1, ChiselNodeHierarchyManager.RootCount(scene2)); // make sure test runner doesn't puke on its own bugs EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); }
private static bool StartToolDragging() { jumpedMousePosition += Event.current.delta; Event.current.Use(); if (ToolIsDragging) { UpdateDragVector(); return(false); } // We set ToolIsDragging to true to be able to tell the difference between dragging and clicking ToolIsDragging = true; // Find the intersecting surfaces startSurfaceReference = hoverSurfaceReference; var currentIntersection = hoverIntersection.Value.surfaceIntersection; selectedSurfaceReferences = ChiselSurfaceSelectionManager.Selection.ToArray(); // We need all the brushContainerAssets for all the surfaces we're moving, so that we can record them for an undo selectedBrushContainerAsset = ChiselSurfaceSelectionManager.SelectedBrushMeshes.ToArray(); // We copy all the original surface uvMatrices, so we always apply rotations and transformations relatively to the original // This makes it easier to recover from edge cases and makes it more accurate, floating point wise. selectedUVMatrices = new UVMatrix[selectedSurfaceReferences.Length]; for (int i = 0; i < selectedSurfaceReferences.Length; i++) { if (selectedSurfaceReferences[i].Polygon.surface == null) { selectedUVMatrices[i] = UVMatrix.identity; } else { selectedUVMatrices[i] = selectedSurfaceReferences[i].Polygon.surface.surfaceDescription.UV0; } } // Find the intersection point/plane in model space var nodeTransform = startSurfaceReference.node.hierarchyItem.Transform; var modelTransform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(nodeTransform); worldStartPosition = modelTransform.localToWorldMatrix.MultiplyPoint(hoverIntersection.Value.surfaceIntersection.worldIntersection); worldProjectionPlane = modelTransform.localToWorldMatrix.TransformPlane(hoverIntersection.Value.surfaceIntersection.worldPlane); worldIntersection = worldStartPosition; // TODO: we want to be able to determine delta movement over a plane. Ideally it would match the position of the cursor perfectly. // unfortunately when moving the cursor towards the horizon of the plane, relative to the camera, the delta movement // becomes too large or even infinity. Ideally we'd switch to a camera facing plane for these cases and determine movement in // a less perfect way that would still allow the user to move or rotate things in a reasonable way. // more accurate for small movements worldDragPlane = worldProjectionPlane; // TODO: (unfinished) prevents drag-plane from intersecting near plane (makes movement slow down to a singularity when further away from click position) //worldDragPlane = new Plane(Camera.current.transform.forward, worldStartPosition); // TODO: ideally we'd interpolate the behavior of the worldPlane between near and far behavior UpdateDragVector(); return(true); }
public IEnumerator CreateAndDestroyModelGameObject_Undo_ModelExist() { var scene = TestUtility.defaultScene; var model = TestUtility.CreateUndoableGameObjectWithModel(); var modelGameObject = model.gameObject; Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Undo.FlushUndoRecordObjects(); Undo.IncrementCurrentGroup(); yield return(null); Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist"); Assert.AreEqual(1, CSGManager.TreeNodeCount, "Expected 1 TreeNode to Exist"); Undo.DestroyObjectImmediate(modelGameObject); yield return(null); Assert.False(modelGameObject); Assert.False(model); Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); Undo.PerformUndo(); yield return(null); model = modelGameObject.GetComponent <ChiselModel>(); yield return(null); Assert.True(modelGameObject); Assert.True(model); Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist"); Assert.AreEqual(1, CSGManager.TreeNodeCount, "Expected 1 TreeNode to Exist"); Assert.AreEqual(1, ChiselNodeHierarchyManager.RootCount(scene)); }
public override void UpdateTransformation() { // TODO: recalculate transformation based on hierarchy up to (but not including) model var transform = hierarchyItem.Transform; if (!transform) { return; } // TODO: fix this mess var localToWorldMatrix = transform.localToWorldMatrix; var modelTransform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(transform); if (modelTransform) { localTransformation = modelTransform.worldToLocalMatrix * localToWorldMatrix; } else { localTransformation = localToWorldMatrix; } if (!ValidNodes) { return; } UpdateInternalTransformation(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); try { bool passThroughChanged = false; EditorGUI.BeginChangeCheck(); { EditorGUI.BeginChangeCheck(); { EditorGUILayout.PropertyField(passThroughProp); } if (EditorGUI.EndChangeCheck()) { passThroughChanged = true; } if (!passThroughProp.boolValue) { EditorGUILayout.PropertyField(operationProp); } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); if (passThroughChanged) { foreach (var target in serializedObject.targetObjects) { var operation = target as ChiselOperation; if (!operation) { continue; } ChiselNodeHierarchyManager.UpdateAvailability(operation); } } } bool hasNoChildren = false; foreach (var target in serializedObject.targetObjects) { var operation = target as ChiselOperation; if (!operation) { continue; } if (operation.transform.childCount == 0) { hasNoChildren = true; } } if (hasNoChildren) { EditorGUILayout.HelpBox(kOperationHasNoChildren, MessageType.Warning, true); } } catch (ExitGUIException) { } catch (Exception ex) { Debug.LogException(ex); } }
public override void OnSceneGUI() { if (!target) { return; } if (Tools.current != Tool.Custom || !ChiselEditGeneratorTool.IsActive()) { OnDefaultSceneTools(); return; } var generator = target as T; if (GUIUtility.hotControl == 0) { if (!OnGeneratorValidate(generator)) { if (validTargets.Contains(generator)) { OnGeneratorDeselected(generator); validTargets.Remove(generator); } return; } if (!validTargets.Contains(generator)) { OnGeneratorSelected(generator); validTargets.Add(generator); } } var sceneView = SceneView.currentDrawingSceneView; var modelMatrix = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform); var generatorNode = generator.TopNode; if (!generatorNode.Valid) { return; } // NOTE: could loop over multiple instances from here, once we support that { using (new UnityEditor.Handles.DrawingScope(UnityEditor.Handles.yAxisColor, modelMatrix * generatorNode.NodeToTreeSpaceMatrix)) { EditorGUI.BeginChangeCheck(); { OnScene(sceneView, generator); } if (EditorGUI.EndChangeCheck()) { OnTargetModifiedInScene(); } } } }
private static void OnUndoRedoPerformed() { //ProfileFrame("myLog2"); //ChiselNodeHierarchyManager.firstStart = false; ChiselNodeHierarchyManager.UpdateAllTransformations(); ChiselOutlineRenderer.Instance.OnTransformationChanged(); ChiselOutlineRenderer.OnUndoRedoPerformed(); }
public static void Rebuild() { var startTime = EditorApplication.timeSinceStartup; ChiselNodeHierarchyManager.Rebuild(); var csg_endTime = EditorApplication.timeSinceStartup; Debug.Log($"Full CSG rebuild done in {((csg_endTime - startTime) * 1000)} ms. "); }
public static Bounds CalculateBounds(ChiselGeneratorComponent generator) { if (!generator.TopTreeNode.Valid) { return(ChiselHierarchyItem.EmptyBounds); } var modelMatrix = ChiselNodeHierarchyManager.FindModelTransformMatrixOfTransform(generator.hierarchyItem.Transform); var minMax = new ChiselAABB { }; var boundsCount = 0; s_FoundBrushes.Clear(); ChiselGeneratedComponentManager.GetAllTreeBrushes(generator, s_FoundBrushes); foreach (var brush in s_FoundBrushes) { if (!brush.Valid) { continue; } var transformation = modelMatrix * (Matrix4x4)brush.NodeToTreeSpaceMatrix; var childBounds = brush.Bounds; var size = childBounds.Max - childBounds.Min; var magnitude = math.lengthsq(size); if (float.IsInfinity(magnitude) || float.IsNaN(magnitude)) { var center = ((float4)transformation.GetColumn(3)).xyz; var halfSize = size * 0.5f; childBounds = new ChiselAABB { Min = center - halfSize, Max = center + halfSize }; } if (magnitude != 0) { if (boundsCount == 0) { minMax = childBounds; } else { minMax.Encapsulate(childBounds); } boundsCount++; } } if (boundsCount == 0) { return(ChiselHierarchyItem.EmptyBounds); } var bounds = new Bounds(); bounds.SetMinMax(minMax.Min, minMax.Max); return(bounds); }
private static void OnEditorApplicationUpdate() { if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } ChiselNodeHierarchyManager.Update(); ChiselGeneratedModelMeshManager.UpdateModels(); ChiselNodeEditorBase.HandleCancelEvent(); }
public void OnSceneGUI(SceneView sceneView) { if (selectedNodeList.Count > 0) { for (int i = 0; i < selectedNodeList.Count; i++) { if (!selectedNodeList[i].transform) { UpdateSelection(); break; } } modifiedNodes.Clear(); for (int i = 0; i < selectedNodeList.Count; i++) { var transform = selectedNodeList[i].transform; var node = selectedNodeList[i].node; var curLocalToWorldMatrix = transform.localToWorldMatrix; var oldLocalToWorldMatrix = node.hierarchyItem.LocalToWorldMatrix; if (curLocalToWorldMatrix.m00 != oldLocalToWorldMatrix.m00 || curLocalToWorldMatrix.m01 != oldLocalToWorldMatrix.m01 || curLocalToWorldMatrix.m02 != oldLocalToWorldMatrix.m02 || curLocalToWorldMatrix.m03 != oldLocalToWorldMatrix.m03 || curLocalToWorldMatrix.m10 != oldLocalToWorldMatrix.m10 || curLocalToWorldMatrix.m11 != oldLocalToWorldMatrix.m11 || curLocalToWorldMatrix.m12 != oldLocalToWorldMatrix.m12 || curLocalToWorldMatrix.m13 != oldLocalToWorldMatrix.m13 || curLocalToWorldMatrix.m20 != oldLocalToWorldMatrix.m20 || curLocalToWorldMatrix.m21 != oldLocalToWorldMatrix.m21 || curLocalToWorldMatrix.m22 != oldLocalToWorldMatrix.m22 || curLocalToWorldMatrix.m23 != oldLocalToWorldMatrix.m23 //|| //curLocalToWorldMatrix.m30 != oldLocalToWorldMatrix.m30 || //curLocalToWorldMatrix.m31 != oldLocalToWorldMatrix.m31 || //curLocalToWorldMatrix.m32 != oldLocalToWorldMatrix.m32 || //curLocalToWorldMatrix.m33 != oldLocalToWorldMatrix.m33 ) { node.hierarchyItem.LocalToWorldMatrix = curLocalToWorldMatrix; node.hierarchyItem.WorldToLocalMatrix = transform.worldToLocalMatrix; modifiedNodes.Add(node); } } if (modifiedNodes.Count > 0) { ChiselNodeHierarchyManager.NotifyTransformationChanged(modifiedNodes); } } // Handle selection clicks / marquee selection ChiselRectSelectionManager.Update(sceneView); }
public static bool FindBrushMaterials(Vector2 position, out ChiselBrushMaterial[] brushMaterials, out ChiselBrushContainerAsset[] brushContainerAssets, bool selectAllSurfaces) { brushMaterials = null; brushContainerAssets = null; try { CSGTreeBrushIntersection intersection; if (!PickFirstGameObject(Event.current.mousePosition, out intersection)) { return(false); } var brush = intersection.brush; var node = ChiselNodeHierarchyManager.FindChiselNodeByInstanceID(brush.UserID); if (!node) { return(false); } if (selectAllSurfaces) { brushContainerAssets = node.GetUsedGeneratedBrushes(); if (brushContainerAssets == null) { return(false); } brushMaterials = node.GetAllBrushMaterials(brush); return(true); } else { var surface = node.FindBrushMaterial(brush, intersection.surfaceID); if (surface == null) { return(false); } brushContainerAssets = node.GetUsedGeneratedBrushes(); if (brushContainerAssets == null) { return(false); } brushMaterials = new ChiselBrushMaterial[] { surface }; return(true); } } catch (Exception ex) { Debug.LogException(ex); return(false); } }
public void CheckForTransformationChanges(SerializedObject serializedObject) { if (Event.current.type == EventType.Layout) { modifiedNodes.Clear(); foreach (var target in serializedObject.targetObjects) { var node = target as ChiselNode; if (!node) { continue; } var transform = node.transform; // TODO: probably not a good idea to use these matrices for this, since it calculates this all the way up the transformation tree var curLocalToWorldMatrix = transform.localToWorldMatrix; var oldLocalToWorldMatrix = node.hierarchyItem.LocalToWorldMatrix; if (curLocalToWorldMatrix.m00 != oldLocalToWorldMatrix.m00 || curLocalToWorldMatrix.m01 != oldLocalToWorldMatrix.m01 || curLocalToWorldMatrix.m02 != oldLocalToWorldMatrix.m02 || curLocalToWorldMatrix.m03 != oldLocalToWorldMatrix.m03 || curLocalToWorldMatrix.m10 != oldLocalToWorldMatrix.m10 || curLocalToWorldMatrix.m11 != oldLocalToWorldMatrix.m11 || curLocalToWorldMatrix.m12 != oldLocalToWorldMatrix.m12 || curLocalToWorldMatrix.m13 != oldLocalToWorldMatrix.m13 || curLocalToWorldMatrix.m20 != oldLocalToWorldMatrix.m20 || curLocalToWorldMatrix.m21 != oldLocalToWorldMatrix.m21 || curLocalToWorldMatrix.m22 != oldLocalToWorldMatrix.m22 || curLocalToWorldMatrix.m23 != oldLocalToWorldMatrix.m23 //|| //curLocalToWorldMatrix.m30 != oldLocalToWorldMatrix.m30 || //curLocalToWorldMatrix.m31 != oldLocalToWorldMatrix.m31 || //curLocalToWorldMatrix.m32 != oldLocalToWorldMatrix.m32 || //curLocalToWorldMatrix.m33 != oldLocalToWorldMatrix.m33 ) { node.hierarchyItem.LocalToWorldMatrix = curLocalToWorldMatrix; node.hierarchyItem.WorldToLocalMatrix = transform.worldToLocalMatrix; modifiedNodes.Add(node); } } if (modifiedNodes.Count > 0) { ChiselNodeHierarchyManager.NotifyTransformationChanged(modifiedNodes); ResetGridBounds(); // TODO: should only do this when rotating, not when moving } } }
public IEnumerator CompositeWithChildInScene1_MoveToScene2_CompositeWithChildOnlyExistsInScene2() { var scene2 = TestUtility.defaultScene; EditorSceneManager.SaveScene(scene2, TestUtility.tempFilename); var scene1 = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive); EditorSceneManager.SetActiveScene(scene1); var composite = TestUtility.CreateUndoableGameObjectWithComposite(); var compositeGameObject = composite.gameObject; var brush = TestUtility.CreateUndoableGameObjectWithBrush(); var brushGameObject = brush.gameObject; brush.transform.parent = composite.transform; Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist"); Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist"); Assert.AreEqual(0, CSGManager.TreeNodeCount, "Expected 0 TreeNodes to Exist"); yield return(null); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist"); Assert.AreEqual(3, CSGManager.TreeNodeCount, "Expected 3 TreeNodes to Exist"); Assert.AreEqual(scene1, composite.gameObject.scene); Assert.AreEqual(scene1, composite.hierarchyItem.Scene); Undo.MoveGameObjectToScene(compositeGameObject, scene2, "Move gameObject to different scene"); yield return(null); Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist"); Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist"); Assert.AreEqual(3, CSGManager.TreeNodeCount, "Expected 3 TreeNodes to Exist"); Assert.AreEqual(composite.hierarchyItem, brush.hierarchyItem.Parent); Assert.AreEqual(composite.NodeID, brush.hierarchyItem.Parent.Component.NodeID); Assert.AreEqual(composite.NodeID, brush.TopNode.Parent.NodeID); Assert.AreEqual(scene2, composite.gameObject.scene, "Composite is not part of expected scene"); Assert.AreEqual(scene2, composite.hierarchyItem.Scene, "Composite is not registered to expected scene"); Assert.AreEqual(scene2, brush.gameObject.scene, "Brush is not part of expected scene"); Assert.AreEqual(scene2, brush.hierarchyItem.Scene, "Brush is not registered to expected scene"); Assert.AreEqual(0, ChiselNodeHierarchyManager.RootCount(scene1)); Assert.AreEqual(1, ChiselNodeHierarchyManager.RootCount(scene2)); // make sure test runner doesn't puke on its own bugs EditorSceneManager.NewScene(NewSceneSetup.EmptyScene); }
public static void ForceUpdateNodeContents(SerializedObject serializedObject) { serializedObject.ApplyModifiedProperties(); foreach (var target in serializedObject.targetObjects) { var node = target as ChiselNode; if (!node) { continue; } ChiselNodeHierarchyManager.NotifyContentsModified(node); node.SetDirty(); } }
private static UnityEditor.UndoPropertyModification[] OnPostprocessModifications(UnityEditor.UndoPropertyModification[] modifications) { // Note: this is not always properly called // - when? can't remember? maybe prefab related? modifiedNodes.Clear(); processedTransforms.Clear(); for (int i = 0; i < modifications.Length; i++) { var currentValue = modifications[i].currentValue; var transform = currentValue.target as Transform; if (object.Equals(null, transform)) { continue; } if (processedTransforms.Contains(transform)) { continue; } var propertyPath = currentValue.propertyPath; if (!propertyPath.StartsWith("m_Local")) { continue; } processedTransforms.Add(transform); s_ChildNodes.Clear(); transform.GetComponentsInChildren <ChiselNode>(false, s_ChildNodes); if (s_ChildNodes.Count == 0) { continue; } if (s_ChildNodes[0] is ChiselModel) { continue; } for (int n = 0; n < s_ChildNodes.Count; n++) { modifiedNodes.Add(s_ChildNodes[n]); } } if (modifiedNodes.Count > 0) { ChiselNodeHierarchyManager.NotifyTransformationChanged(modifiedNodes); } return(modifications); }
public static void Rebuild() { UnityEngine.Profiling.Profiler.BeginSample("Rebuild"); try { var startTime = Time.realtimeSinceStartup; ChiselNodeHierarchyManager.Rebuild(); var csg_endTime = Time.realtimeSinceStartup; Debug.Log($"Full CSG rebuild done in {((csg_endTime - startTime) * 1000)} ms. "); } finally { UnityEngine.Profiling.Profiler.EndSample(); } }
//**// protected override void OnValidateInternal() { HandleDuplication(); if (!ValidNodes) { return; } UpdateGenerator(); UpdateBrushMeshInstances(); ChiselNodeHierarchyManager.NotifyContentsModified(this); base.OnValidateInternal(); }