public void BreakTypeRelation() { // Brushes retain knowledge of what they were made from, so it's easy to adjust the side count on a prism // for example, while retaining some of its transform information. If you start cutting away at a prism // using the clip tool for instance, it should stop tracking it as following the initial form brushType = PrimitiveBrushType.Custom; }
private void DrawBrushButton(PrimitiveBrushType brushType, PrimitiveBrushType?activeType, GUIStyle brushButtonStyle, GUIStyle labelStyle, int width, int height, bool shortMode) { GUI.enabled = !activeType.HasValue || activeType.Value != brushType; if (GUILayout.Button(new GUIContent(" ", SabreCSGResources.GetButtonTexture(brushType)), brushButtonStyle, GUILayout.Width(width), GUILayout.Height(height))) { ChangeBrushesToType(brushType); } Rect lastRect = GUILayoutUtility.GetLastRect(); string name = brushType.ToString(); if (brushType == PrimitiveBrushType.IcoSphere) { name = "Ico"; } if (shortMode && brushType == PrimitiveBrushType.Cylinder) { name = "Cyl"; } if (shortMode && brushType == PrimitiveBrushType.Capsule) { name = "Cap"; } GUI.Label(lastRect, name, labelStyle); }
/// <summary> /// Gets an icon for a primitive brush to be displayed on a button /// </summary> /// <returns>The icon texture.</returns> /// <param name="brushType">Primitive Brush type.</param> public static Texture2D GetButtonTexture(PrimitiveBrushType brushType) { if (brushType == PrimitiveBrushType.Prism) { return(ButtonPrismTexture); } else if (brushType == PrimitiveBrushType.Cylinder) { return(ButtonCylinderTexture); } else if (brushType == PrimitiveBrushType.Sphere || brushType == PrimitiveBrushType.IcoSphere) { return(ButtonSphereTexture); } else if (brushType == PrimitiveBrushType.Cone) { return(ButtonConeTexture); } else if (brushType == PrimitiveBrushType.Capsule) { return(ButtonCapsuleTexture); } else { return(ButtonCubeTexture); } }
static void CreatePrimitiveBrush(PrimitiveBrushType brushType) { Vector3 position = GetPositionForNewBrush(); GameObject newBrushObject = csgModel.CreateBrush(brushType, position); // Set the selection to the new object Selection.activeGameObject = newBrushObject; Undo.RegisterCreatedObjectUndo(newBrushObject, "Create Brush"); }
public GameObject CreateBrush(PrimitiveBrushType brushType) { GameObject brushObject = new GameObject("AppliedBrush"); brushObject.transform.parent = this.transform; PrimitiveBrush primitiveBrush = brushObject.AddComponent <PrimitiveBrush>(); primitiveBrush.BrushType = brushType; primitiveBrush.ResetPolygons(); return(brushObject); }
void EnsureWellFormed() { if (polygons == null || polygons.Length == 0) { // Reset custom brushes back to a cube if (brushType == PrimitiveBrushType.Custom) { brushType = PrimitiveBrushType.Cube; } ResetPolygons(); } }
/// <summary> /// Creates a brush under the CSG Model with the specified attributes. /// </summary> /// <returns>The created game object.</returns> /// <param name="brushType">Brush type.</param> /// <param name="localPosition">Local position of the brush's transform</param> /// <param name="localSize">Local bounds size of the brush (Optional, defaults to 2,2,2).</param> /// <param name="localRotation">Local rotation of the brush (Optional, defaults to identity quaternion).</param> /// <param name="material">Material to apply to all faces, (Optional, defaults to null for default material).</param> /// <param name="csgMode">Whether the brush is additive or subtractive (Optional, defaults to additive).</param> /// <param name="brushName">Name for the game object (Optional, defaults to "AppliedBrush").</param> public GameObject CreateBrush(PrimitiveBrushType brushType, Vector3 localPosition, Vector3 localSize = default(Vector3), Quaternion localRotation = default(Quaternion), Material material = null, CSGMode csgMode = CSGMode.Add, string brushName = null) { GameObject brushObject; if (!string.IsNullOrEmpty(brushName)) { brushObject = new GameObject(brushName); } else { brushObject = new GameObject(""); } brushObject.transform.localScale = this.transform.lossyScale; brushObject.transform.parent = this.transform; brushObject.transform.localPosition = localPosition; if (localRotation != default(Quaternion)) { brushObject.transform.localRotation = localRotation; } PrimitiveBrush primitiveBrush = brushObject.AddComponent <PrimitiveBrush>(); primitiveBrush.BrushType = brushType; primitiveBrush.Mode = csgMode; primitiveBrush.ResetPolygons(); if (localSize != default(Vector3) && localSize != new Vector3(2, 2, 2)) { BrushUtility.Resize(primitiveBrush, localSize); } else { // Resize automatically invalidates a brush with changed polygons set, if no resize took place we still need to make sure it happens primitiveBrush.Invalidate(true); } if (material != null) { SurfaceUtility.SetAllPolygonsMaterials(primitiveBrush, material); } return(brushObject); }
static void CreateBrush(PrimitiveBrushType brushType) { GameObject newBrushObject = csgModel.CreateBrush(brushType, Vector3.zero); if (SceneView.lastActiveSceneView != null) { Transform cameraTransform = SceneView.lastActiveSceneView.camera.transform; Ray ray = new Ray(cameraTransform.position, cameraTransform.forward); List <PolygonRaycastHit> hits = csgModel.RaycastBrushesAll(ray); if (hits.Count > 0) { Vector3 newPosition = hits[0].Point; // Back a unit, since the brush is around 2 units in each dimensions newPosition += hits[0].Normal; if (CurrentSettings.PositionSnappingEnabled) { float snapDistance = CurrentSettings.PositionSnapDistance; newPosition = MathHelper.RoundVector3(newPosition, snapDistance); newBrushObject.transform.position = newPosition; } } else { Vector3 newPosition = SceneView.lastActiveSceneView.pivot; if (CurrentSettings.PositionSnappingEnabled) { float snapDistance = CurrentSettings.PositionSnapDistance; newPosition = MathHelper.RoundVector3(newPosition, snapDistance); newBrushObject.transform.position = newPosition; } } } newBrushObject.GetComponent <Brush>().Invalidate(true); // Set the selection to the new object Selection.activeGameObject = newBrushObject; Undo.RegisterCreatedObjectUndo(newBrushObject, "Create Brush"); }
private void ChangeBrushesToType(PrimitiveBrushType newType) { Undo.RecordObjects(targets, "Change Brush Type"); PrimitiveBrush[] brushes = BrushTargets.Cast <PrimitiveBrush>().ToArray(); foreach (PrimitiveBrush brush in brushes) { Bounds localBounds = brush.GetBounds(); brush.BrushType = newType; brush.ResetPolygons(); if (localBounds.size != new Vector3(2, 2, 2)) { BrushUtility.Resize(brush, localBounds.size); } else { brush.Invalidate(true); } } }
/// <summary> /// Creates a brush under the CSG Model with the specified attributes. /// </summary> /// <returns>The created game object.</returns> /// <param name="brushType">Brush type.</param> /// <param name="localPosition">Local position of the brush's transform</param> /// <param name="localSize">Local bounds size of the brush (Optional, defaults to 2,2,2).</param> /// <param name="localRotation">Local rotation of the brush (Optional, defaults to identity quaternion).</param> /// <param name="material">Material to apply to all faces, (Optional, defaults to null for default material).</param> /// <param name="csgMode">Whether the brush is additive or subtractive (Optional, defaults to additive).</param> /// <param name="brushName">Name for the game object (Optional, defaults to "AppliedBrush").</param> public GameObject CreateBrush(PrimitiveBrushType brushType, Vector3 localPosition, Vector3 localSize = default(Vector3), Quaternion localRotation = default(Quaternion), Material material = null, CSGMode csgMode = CSGMode.Add, string brushName = null) { GameObject brushObject; if (!string.IsNullOrEmpty(brushName)) { brushObject = new GameObject(brushName); } else { brushObject = new GameObject("AppliedBrush"); } brushObject.transform.parent = this.transform; brushObject.transform.localPosition = localPosition; if (localRotation != default(Quaternion)) { brushObject.transform.localRotation = localRotation; } PrimitiveBrush primitiveBrush = brushObject.AddComponent <PrimitiveBrush>(); primitiveBrush.BrushType = brushType; primitiveBrush.Mode = csgMode; primitiveBrush.ResetPolygons(); if (localSize != default(Vector3) && localSize != new Vector3(2, 2, 2)) { BrushUtility.Resize(primitiveBrush, localSize); // primitiveBrush.Invalidate(true); } if (material != null) { SurfaceUtility.SetAllPolygonsMaterials(primitiveBrush, material); } return(brushObject); }
public void DrawBrushTypeField() { PrimitiveBrushType[] selectedTypes = BrushTargets.Select(item => item.BrushType).ToArray(); if(overridenBrushType.HasValue) { selectedTypes = new PrimitiveBrushType[] { overridenBrushType.Value }; } PrimitiveBrushType? newType = SabreGUILayout.EnumPopupMixed("Brush Type", selectedTypes); if(newType.HasValue) { overridenBrushType = newType; if(newType.Value == PrimitiveBrushType.Prism) { EditorGUILayout.PropertyField(prismSideCountProp); } } if (GUILayout.Button("Reset Polygons")) { Undo.RecordObjects(targets, "Reset Polygons"); foreach (var thisBrush in targets) { if(overridenBrushType.HasValue) { ((PrimitiveBrush)thisBrush).BrushType = overridenBrushType.Value; } ((PrimitiveBrush)thisBrush).ResetPolygons(); ((PrimitiveBrush)thisBrush).Invalidate(); } overridenBrushType = null; } }
public void CreateBrush(PrimitiveBrushType brushType) { GameObject brushObject = new GameObject("AppliedBrush"); brushObject.transform.parent = this.transform; PrimitiveBrush primitiveBrush = brushObject.AddComponent<PrimitiveBrush>(); primitiveBrush.BrushType = brushType; primitiveBrush.ResetPolygons(); Selection.activeGameObject = brushObject; // primitiveBrush.Material = AssetDatabase.LoadMainAssetAtPath("Assets/Textures/AngryBotsTextures/Materials/WallPanel_E.mat") as Material; }
/// <summary> /// Brushes retain knowledge of what they were made from, so it's easy to adjust the side count on a prism for example, while retaining some of its transform information. If you start cutting away at a prism using the clip tool for instance, it should stop tracking it as following the initial form. This method allows you to tell the brush it is no longer tracking a base form. /// </summary> public void BreakTypeRelation() { brushType = PrimitiveBrushType.Custom; }
public void DrawBrushTypeField() { GUILayout.BeginHorizontal(); PrimitiveBrushType[] selectedTypes = BrushTargets.Select(item => item.BrushType).ToArray(); if (overridenBrushType.HasValue) { selectedTypes = new PrimitiveBrushType[] { overridenBrushType.Value }; } PrimitiveBrushType?newType = SabreGUILayout.EnumPopupMixed("Brush Type", selectedTypes); if (newType.HasValue) { overridenBrushType = newType; if (newType.Value == PrimitiveBrushType.Prism) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(prismSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } else if (newType.Value == PrimitiveBrushType.Cylinder) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(cylinderSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } else if (newType.Value == PrimitiveBrushType.Sphere) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(sphereSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } } if (GUILayout.Button("Reset Polygons")) { Undo.RecordObjects(targets, "Reset Polygons"); foreach (var thisBrush in targets) { if (overridenBrushType.HasValue) { ((PrimitiveBrush)thisBrush).BrushType = overridenBrushType.Value; } ((PrimitiveBrush)thisBrush).ResetPolygons(); ((PrimitiveBrush)thisBrush).Invalidate(true); } overridenBrushType = null; } GUILayout.EndHorizontal(); if (GUILayout.Button("Shell")) { List <GameObject> newSelection = new List <GameObject>(); foreach (var thisBrush in targets) { GameObject newObject = ((PrimitiveBrush)thisBrush).Duplicate(); Polygon[] polygons = newObject.GetComponent <PrimitiveBrush>().GetPolygons(); VertexUtility.DisplacePolygons(polygons, -CurrentSettings.PositionSnapDistance); Bounds newBounds = newObject.GetComponent <PrimitiveBrush>().GetBounds(); // Verify the new geometry if (GeometryHelper.IsBrushConvex(polygons) && newBounds.GetSmallestExtent() > 0) { Undo.RegisterCreatedObjectUndo(newObject, "Shell"); newSelection.Add(newObject); } else { // Produced a concave brush, delete it and pretend nothing happened GameObject.DestroyImmediate(newObject); Debug.LogWarning("Could not shell " + thisBrush.name + " as shelled geometry would not be valid. Try lowering Pos Snapping and attempt Shell again."); } } if (newSelection.Count > 0) { Selection.objects = newSelection.ToArray(); } } }
void EnsureWellFormed() { if (polygons == null || polygons.Length == 0) { // Reset custom brushes back to a cube if(brushType == PrimitiveBrushType.Custom) { brushType = PrimitiveBrushType.Cube; } ResetPolygons(); } }