public static CSGBrush CreateBrushInstanceInScene() { #if DEMO if (CSGBindings.BrushesAvailable() <= 0) { return(null); } #endif var lastUsedModelTransform = !SelectionUtility.LastUsedModel ? null : SelectionUtility.LastUsedModel.transform; if (lastUsedModelTransform == null) { lastUsedModelTransform = CreateModelInstanceInScene().transform; } var name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(lastUsedModelTransform, "Brush"); var gameObject = new GameObject(name); var brush = gameObject.AddComponent <CSGBrush>(); gameObject.transform.SetParent(lastUsedModelTransform, true); gameObject.transform.position = new Vector3(0.5f, 0.5f, 0.5f); // this aligns it's vertices to the grid BrushFactory.CreateCubeControlMesh(out brush.ControlMesh, out brush.Shape, Vector3.one); UnityEditor.Selection.activeGameObject = gameObject; Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); InternalCSGModelManager.Refresh(); InternalCSGModelManager.UpdateMeshes(); return(brush); }
public static CSGBrush CreateBrushInstanceInScene(MenuCommand command) { var parent = GetTransformForMenu(command); var lastUsedModelTransform = !SelectionUtility.LastUsedModel ? null : SelectionUtility.LastUsedModel.transform; if (lastUsedModelTransform == null && !parent) { lastUsedModelTransform = CreateModelInstanceInScene(parent).transform; parent = lastUsedModelTransform; } else if (!parent) { parent = lastUsedModelTransform; } var name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, "Brush"); var gameObject = new GameObject(name); var brush = gameObject.AddComponent <CSGBrush>(); gameObject.transform.SetParent(parent, true); gameObject.transform.position = new Vector3(0.5f, 0.5f, 0.5f); // this aligns it's vertices to the grid BrushFactory.CreateCubeControlMesh(out brush.ControlMesh, out brush.Shape, Vector3.one); UnityEditor.Selection.activeGameObject = gameObject; Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); InternalCSGModelManager.CheckForChanges(); InternalCSGModelManager.UpdateMeshes(); return(brush); }
public static CSGBrush CreateCubeBrush(Transform parent, string brushName, Vector3 size) { ControlMesh controlMesh; Shape shape; BrushFactory.CreateCubeControlMesh(out controlMesh, out shape, size); return(CreateBrush(parent, brushName, controlMesh, shape)); }
public static bool SetBrushCubeMesh(CSGBrush brush, Vector3 size) { if (!brush) { return(false); } ControlMesh controlMesh; Shape shape; BrushFactory.CreateCubeControlMesh(out controlMesh, out shape, size); brush.ControlMesh = controlMesh; brush.Shape = shape; if (brush.ControlMesh != null) { brush.ControlMesh.SetDirty(); } if (brush.Shape != null) { ShapeUtility.EnsureInitialized(brush.Shape); } return(true); }