public void EndCommit() { if (generatedBrushes == null) { return; } var bounds = BoundsUtilities.GetBounds(generatedBrushes); if (!bounds.IsEmpty()) { var center = bounds.Center - operationGameObject.transform.position; GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center); SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center); ControlMeshUtility.RebuildShapes(generatedBrushes); InternalCSGModelManager.Refresh(forceHierarchyUpdate: true); operationGameObject.transform.position += center; Undo.CollapseUndoOperations(undoGroupIndex); Cleanup(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) { Selection.objects = generatedGameObjects; } Reset(); } if (shapeCommitted != null) { shapeCommitted(); } }
public void EndCommit() { if (generatedBrushes == null) return; var bounds = BoundsUtilities.GetBounds(generatedBrushes); if (!bounds.IsEmpty()) {/* var center = bounds.Center - operationGameObject.transform.position; GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center); SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center); operationGameObject.transform.position += center;*/ ControlMeshUtility.RebuildShapes(generatedBrushes); var models = operationGameObject.GetComponentsInParent<CSGModel>(includeInactive: true); var model = models.Length == 0 ? null : models[0]; model.forceUpdate = true; InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); Undo.CollapseUndoOperations(undoGroupIndex); Cleanup(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) Selection.objects = generatedGameObjects; Reset(); } if (shapeCommitted != null) shapeCommitted(); }
private static bool TryGetSelectionBounds(out Bounds bounds) { bounds = default; var obj = Selection.activeGameObject; if (obj == null) { return(false); } var brushes = obj.GetComponentsInChildren <CSGBrush>(); if (brushes.Length > 0) { var csgBounds = BoundsUtilities.GetBounds(brushes); bounds = new Bounds() { center = csgBounds.Center, extents = csgBounds.Size * .5f, min = csgBounds.Min, max = csgBounds.Max }; return(true); } var renderers = obj.GetComponentsInChildren <Renderer>(); for (int i = 0; i < renderers.Length; i++) { if (i == 0) { bounds = renderers[i].bounds; } else { bounds.Encapsulate(renderers[i].bounds); } return(true); } bounds = new Bounds() { center = Selection.activeGameObject.transform.position, size = Vector3.one * 3f }; return(false); }