public override ProBuilderMesh Build(bool preview = false) { return(ShapeGenerator.GeneratePlane( EditorUtility.newShapePivotLocation, s_Height, s_Width, s_HeightSegments, s_WidthSegments, s_Axis)); }
void Start() { // Generate a 50x50 plane with 25 subdivisions, facing up, with no smoothing applied. target = ShapeGenerator.GeneratePlane(PivotLocation.Center, travel, travel, 25, 25, Axis.Up); target.transform.position = new Vector3(travel * .5f, 0f, travel * .5f); // Rebuild the mesh (apply ProBuilderMesh data to UnityEngine.Mesh) target.ToMesh(); // Rebuild UVs, Colors, Collisions, Normals, and Tangents target.Refresh(); // Orient the camera in a good position Camera cam = Camera.main; cam.transform.position = new Vector3(25f, 40f, 0f); cam.transform.localRotation = Quaternion.Euler(new Vector3(65f, 0f, 0f)); }
public override ProBuilderMesh Build(bool preview = false) { return(ShapeGenerator.GeneratePlane(EditorUtility.newShapePivotLocation, 1, 1, 0, 0, s_Axis)); }
public static IEnumerator ExtrudeOrthogonally_OneElementManyTimes_NoYOffsetAccumulates() { // Generate single face plane var pb = ShapeGenerator.GeneratePlane(PivotLocation.Center, 1f, 1f, 0, 0, Axis.Up); try { pb.transform.position = Vector3.zero; pb.transform.rotation = Quaternion.identity; ProBuilderEditor.MenuOpenWindow(); EditorApplication.ExecuteMenuItem("Window/General/Scene"); var sceneView = UnityEngine.Resources.FindObjectsOfTypeAll <UnityEditor.SceneView>()[0]; sceneView.orthographic = true; sceneView.drawGizmos = false; sceneView.pivot = new Vector3(0, 0, 0); sceneView.rotation = Quaternion.AngleAxis(90f, Vector3.right); sceneView.size = 2.0f; sceneView.Focus(); var e = new Event(); e.type = EventType.MouseEnterWindow; sceneView.SendEvent(e); Assume.That(pb.facesInternal.Length, Is.EqualTo(1)); var face = pb.facesInternal[0]; // Select face var selectedFaces = new List <Face>(); selectedFaces.Add(face); Tools.current = Tool.Move; ProBuilderEditor.toolManager.SetSelectMode(SelectMode.Face); pb.SetSelectedFaces(selectedFaces); MeshSelection.SetSelection(pb.gameObject); // Center mouse position var bounds = SceneView.focusedWindow.rootVisualElement.worldBound; var mousePos = (bounds.size * 0.5f + bounds.position) + new Vector2Int(1, 1); e = new UnityEngine.Event() { type = EventType.MouseDown, mousePosition = mousePos, modifiers = EventModifiers.None, clickCount = 1, delta = Vector2.zero, }; sceneView.SendEvent(e); e = new UnityEngine.Event() { type = EventType.MouseUp, mousePosition = mousePos, modifiers = EventModifiers.None, clickCount = 0, delta = Vector2.zero, }; sceneView.SendEvent(e); yield return(null); const int k_ExtrudeCount = 100; for (int i = 0; i < k_ExtrudeCount; i++) { // Press down at the center of the face e = new UnityEngine.Event() { type = EventType.MouseDown, mousePosition = mousePos, modifiers = EventModifiers.None, clickCount = 1, delta = Vector2.zero, }; sceneView.SendEvent(e); // Do lateral 1px drag and release var mouseDelta = new Vector2(i % 2 == 0 ? 1f : -1f, 0f); mousePos += mouseDelta; e.type = EventType.MouseDrag; e.mousePosition = mousePos; e.modifiers = EventModifiers.Shift; e.clickCount = 0; e.delta = mouseDelta; sceneView.SendEvent(e); e.type = EventType.MouseUp; e.mousePosition = mousePos; e.delta = Vector2.zero; sceneView.SendEvent(e); yield return(null); } // Check that our face count is correct after all extrusions Assume.That(pb.facesInternal.Length, Is.EqualTo(k_ExtrudeCount * 4 + 1)); // We should have the last extruded face in selection var postExtrudeSelectedFaces = pb.GetSelectedFaces(); Assume.That(postExtrudeSelectedFaces.Length, Is.EqualTo(1)); var lastExtrudedFace = postExtrudeSelectedFaces[0]; var faceVertices = pb.GetVertices(lastExtrudedFace.indexes); // After many orthogonal extrusions, the last face should still be at y=0 coordinate for (int i = 0; i < faceVertices.Length; i++) { Assert.That(faceVertices[i].position.y, Is.EqualTo(0f)); } } finally { UObject.DestroyImmediate(pb.gameObject); } }
/// <summary> /// Build a starting point (in this case, a quad) /// </summary> void Start() { m_Mesh = ShapeGenerator.GeneratePlane(PivotLocation.Center, 1, 1, 0, 0, Axis.Up); m_Mesh.GetComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.defaultMaterial; m_LastExtrudedFace = m_Mesh.faces[0]; }