public void Extrude_Face_CreatesValidGeometry( [ValueSource("shapeTypes")] ShapeType shape, [ValueSource("extrudeMethods")] ExtrudeMethod extrudeMethod, [ValueSource("extrudeDistance")] float distance) { var mesh = ShapeGenerator.CreateShape(shape); try { int initialVertexCount = mesh.vertexCount; Face face = mesh.facesInternal[m_Random.Next(0, mesh.facesInternal.Length)]; mesh.Extrude(new Face[] { face }, extrudeMethod, distance); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(mesh.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, mesh.vertexCount); } catch (Exception e) { Debug.LogError(e.ToString()); } finally { if (mesh != null) { Object.DestroyImmediate(mesh.gameObject); } } }
public static void ExtrudeAllFaces_FaceNormal([ValueSource("shapeTypes")] ShapeType shape) { var mesh = ShapeGenerator.CreateShape(shape); try { mesh.Extrude(mesh.facesInternal, ExtrudeMethod.FaceNormal, .5f); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(mesh.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); TestUtility.AssertAreEqual(template, mesh.mesh, message: mesh.name); } catch (Exception e) { Debug.LogError(e.ToString()); } finally { if (mesh != null) { Object.DestroyImmediate(mesh.gameObject); } } }
public static void Extrude_MultipleEdges_CreatesValidGeometry() { var pb = ShapeGenerator.CreateShape(ShapeType.Cube); try { int vertexCount = pb.vertexCount; UnityEngine.ProBuilder.Edge[] edges = new UnityEngine.ProBuilder.Edge[pb.faceCount]; for (int i = 0; i < pb.faceCount; i++) { edges[i] = pb.facesInternal[i].edgesInternal[m_Random.Next(0, pb.facesInternal[i].edgesInternal.Length)]; } // as group, enable manifold extrude Assert.IsFalse(pb.Extrude(edges, .5f, true, false) != null, "Do not allow manifold edge extrude"); Assert.IsTrue(pb.Extrude(edges, .5f, true, true) != null, "Do allow manifold edge extrude"); pb.ToMesh(); pb.Refresh(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(vertexCount + edges.Length * 4, pb.vertexCount); } finally { UObject.DestroyImmediate(pb.gameObject); } }
public static void DeleteRandomFace_CreatesValidMesh([ValueSource("shapeTypes")] ShapeType shape) { var mesh = ShapeGenerator.CreateShape(shape); try { var face = mesh.facesInternal[s_Random.Next(0, mesh.faceCount)]; int vertexCount = mesh.vertexCount; int faceVertexCount = face.distinctIndexes.Count; mesh.DeleteFace(face); mesh.ToMesh(); mesh.Refresh(); TestUtility.AssertMeshAttributesValid(mesh.mesh); Assert.AreEqual(mesh.vertexCount, vertexCount - faceVertexCount); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
public static void ConnectEdges_MatchesTemplate([ValueSource("shapeTypes")] ShapeType shapeType) { var mesh = ShapeGenerator.CreateShape(shapeType); Assume.That(mesh, Is.Not.Null); try { var face = mesh.facesInternal[0]; mesh.Connect(new Edge[] { face.edgesInternal[0], face.edgesInternal[1] }); mesh.ToMesh(); mesh.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif TestUtility.AssertMeshAttributesValid(mesh.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); Assert.IsNotNull(template); TestUtility.AssertMeshesAreEqual(template, mesh.mesh); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
public static void DeleteFirstFace_CreatesValidMesh([ValueSource("shapeTypes")] ShapeType shape) { var mesh = ShapeGenerator.CreateShape(shape); try { var face = mesh.facesInternal.FirstOrDefault(); mesh.DeleteFace(face); mesh.ToMesh(); mesh.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif TestUtility.AssertMeshAttributesValid(mesh.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); Assert.IsNotNull(template); TestUtility.AssertAreEqual(template, mesh.mesh); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
public static void BridgeTri() { var cube = ShapeGenerator.CreateShape(ShapeType.Cube); cube.DeleteFace(cube.faces[0]); var holes = ElementSelection.FindHoles(cube, cube.sharedVerticesInternal.Select(x => x[0])); Assert.AreEqual(1, holes.Count, "found exactly 1 hole"); var bridgedFace = cube.Bridge(holes[0][0], holes[0][1]); Assert.IsNotNull(bridgedFace); Assert.AreEqual(3, bridgedFace.edgesInternal.Length); cube.ToMesh(); cube.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(cube.mesh, cube.name); #endif TestUtility.AssertMeshAttributesValid(cube.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(cube.name); Assert.IsNotNull(template); TestUtility.AssertAreEqual(template, cube.mesh); UnityEngine.Object.DestroyImmediate(cube); }
public static void LocalSpaceOffsetAndRotate() { var shape = ShapeGenerator.CreateShape(ShapeType.Stair); foreach (var face in shape.faces) { AutoUnwrapSettings uv = face.uv; uv.offset += new Vector2(.3f, .5f); uv.rotation = 35f; face.uv = uv; } shape.ToMesh(); shape.Refresh(); TestUtility.AssertMeshAttributesValid(shape.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(shape.mesh, shape.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(shape.name); TestUtility.AssertAreEqual(template, shape.mesh, message: shape.name); UObject.DestroyImmediate(shape.gameObject); }
public void ShapeGenerator_MatchesTemplate([ValueSource("shapeTypes")] ShapeType type) { ProBuilderMesh pb = ShapeGenerator.CreateShape(type); Assume.That(pb, Is.Not.Null); #if PB_CREATE_TEST_MESH_TEMPLATES // save a template mesh. the mesh is saved in a the Templates folder with the path extracted from: // Templates/{Asset Type}/{CallingFilePathRelativeToTests}/{MethodName}/{AssetName}.asset // note - pb_DestroyListener will not let pb_Object destroy meshes backed by an asset, so there's no need // to set `dontDestroyOnDelete` in the editor. TestUtility.SaveAssetTemplate(pb.GetComponent <MeshFilter>().sharedMesh, type.ToString()); #else try { TestUtility.AssertMeshAttributesValid(pb.mesh); // Loads an asset by name from the template path. See also pb_TestUtility.GetTemplatePath Mesh template = TestUtility.GetAssetTemplate <Mesh>(type.ToString()); Assert.IsTrue(TestUtility.AssertAreEqual(template, pb.mesh), type.ToString() + " value-wise mesh comparison"); } finally { Object.DestroyImmediate(pb.gameObject); } #endif }
public static void ExtrudeAllFaces_IndividualFaces([ValueSource("m_AvailableShapeTypes")] Type shape) { var mesh = ShapeFactory.Instantiate(shape); try { int vertexCountBeforeExtrude = mesh.vertexCount; mesh.Extrude(mesh.facesInternal, ExtrudeMethod.IndividualFaces, .5f); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); Assert.AreNotEqual(vertexCountBeforeExtrude, mesh.vertexCount); TestUtility.AssertMeshAttributesValid(mesh.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); TestUtility.AssertAreEqual(template, mesh.mesh, message: mesh.name); } catch (Exception e) { Debug.LogError(e.ToString()); } finally { if (mesh != null) { Object.DestroyImmediate(mesh.gameObject); } } }
public static void ExtrudeFaceMultipleTimes() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (ProBuilderMesh pb in shapes) { int initialVertexCount = pb.vertexCount; UnityEngine.ProBuilder.Face face = pb.facesInternal[m_Random.Next(0, pb.facesInternal.Length)]; pb.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.FaceNormal, 1f); pb.ToMesh(); pb.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, pb.vertexCount); initialVertexCount = pb.vertexCount; pb.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.VertexNormal, 1f); pb.ToMesh(); pb.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, pb.vertexCount); initialVertexCount = pb.vertexCount; pb.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.IndividualFaces, 1f); pb.ToMesh(); pb.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, pb.vertexCount); } } }
public static void DeleteAllFaces() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { pb.DeleteFaces(pb.facesInternal); pb.ToMesh(); pb.Refresh(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(pb.vertexCount, 0); } } }
public static void DeleteRandomFace() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { var face = pb.facesInternal[s_Random.Next(0, pb.faceCount)]; int vertexCount = pb.vertexCount; int faceVertexCount = face.distinctIndexes.Count; pb.DeleteFace(face); pb.ToMesh(); pb.Refresh(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(pb.vertexCount, vertexCount - faceVertexCount); } } }
public static void Extrude_Face_MultipleTimes_CreatesValidGeometry([ValueSource("shapeTypes")] ShapeType shape) { var mesh = ShapeGenerator.CreateShape(shape); try { int initialVertexCount = mesh.vertexCount; UnityEngine.ProBuilder.Face face = mesh.facesInternal[m_Random.Next(0, mesh.facesInternal.Length)]; mesh.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.FaceNormal, 1f); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(mesh.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, mesh.vertexCount); initialVertexCount = mesh.vertexCount; mesh.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.VertexNormal, 1f); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(mesh.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, mesh.vertexCount); initialVertexCount = mesh.vertexCount; mesh.Extrude(new UnityEngine.ProBuilder.Face[] { face }, ExtrudeMethod.IndividualFaces, 1f); mesh.ToMesh(); mesh.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(mesh.mesh); Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, mesh.vertexCount); } catch (Exception e) { Debug.LogError(e.ToString()); } finally { if (mesh != null) { Object.DestroyImmediate(mesh.gameObject); } } }
public static void ExtrudeAllFaces_VertexNormal() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { pb.Extrude(pb.facesInternal, ExtrudeMethod.VertexNormal, .5f); pb.ToMesh(); pb.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(pb.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(pb.mesh, pb.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(pb.name); TestUtility.AssertAreEqual(template, pb.mesh, message: pb.name); } } }
public static void SetOffsetAndRotate_InLocalSpace_IsAppliedToMesh( [ValueSource("offsetRotationShapes")] ShapeType shape, [ValueSource("offsetValues")] Vector2 offset, [ValueSource("rotationValues")] float rotation) { var mesh = ShapeGenerator.CreateShape(shape); Assume.That(mesh, Is.Not.Null); try { foreach (var face in mesh.faces) { AutoUnwrapSettings uv = face.uv; uv.offset += new Vector2(.3f, .5f); uv.rotation = 35f; face.uv = uv; } mesh.ToMesh(); mesh.Refresh(); TestUtility.AssertMeshAttributesValid(mesh.mesh); string templateName = shape.ToString() + "offset: " + offset.ToString() + " rotation: " + rotation; #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif Mesh template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); TestUtility.AssertAreEqual(template, mesh.mesh, message: mesh.name); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
public static void DeleteFirstFace() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { var face = pb.facesInternal.FirstOrDefault(); pb.DeleteFace(face); pb.ToMesh(); pb.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(pb.mesh, pb.name); #endif TestUtility.AssertMeshAttributesValid(pb.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(pb.name); Assert.IsNotNull(template); TestUtility.AssertAreEqual(template, pb.mesh); } } }
static void ExtrudeSingleFace(ExtrudeMethod method, float distance = 1f) { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { int initialVertexCount = pb.vertexCount; UnityEngine.ProBuilder.Face face = pb.facesInternal[m_Random.Next(0, pb.facesInternal.Length)]; pb.Extrude(new UnityEngine.ProBuilder.Face[] { face }, method, 1f); pb.ToMesh(); pb.Refresh(); LogAssert.NoUnexpectedReceived(); TestUtility.AssertMeshAttributesValid(pb.mesh); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(pb.mesh, pb.name); #endif Assert.AreEqual(initialVertexCount + face.edgesInternal.Length * 4, pb.vertexCount); } } }
public static void CollapseToCenter_MatchesTemplate() { var cube = ShapeFactory.Instantiate <Cube>(); cube.MergeVertices(new[] { 0, 1 }); cube.ToMesh(); cube.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(cube.mesh, cube.name); #endif TestUtility.AssertMeshAttributesValid(cube.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(cube.name); Assert.IsNotNull(template); TestUtility.AssertAreEqual(template, cube.mesh); UnityEngine.Object.DestroyImmediate(cube); }
public static void Connect2Edges() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var mesh in (IEnumerable <ProBuilderMesh>)shapes) { var face = mesh.facesInternal[0]; mesh.Connect(new ProBuilder.Edge[] { face.edgesInternal[0], face.edgesInternal[1] }); mesh.ToMesh(); mesh.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(mesh.mesh, mesh.name); #endif TestUtility.AssertMeshAttributesValid(mesh.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(mesh.name); Assert.IsNotNull(template); TestUtility.AssertMeshesAreEqual(template, mesh.mesh); } } }
public static void DeleteAllFaces_CreatesValidMesh([ValueSource("shapeTypes")] ShapeType shape) { var mesh = ShapeGenerator.CreateShape(shape); try { mesh.DeleteFaces(mesh.facesInternal); mesh.ToMesh(); mesh.Refresh(); TestUtility.AssertMeshAttributesValid(mesh.mesh); Assert.AreEqual(mesh.vertexCount, 0); } catch (System.Exception e) { Debug.LogError(e.ToString()); } finally { UnityEngine.Object.DestroyImmediate(mesh.gameObject); } }
public static void CollapseToFirst_MatchesTemplate() { var cube = ShapeGenerator.CreateShape(ShapeType.Cube); var res = cube.MergeVertices(new[] { 0, 1 }, true); Assert.AreEqual(3, res); cube.ToMesh(); cube.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(cube.mesh, cube.name); #endif TestUtility.AssertMeshAttributesValid(cube.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(cube.name); Assert.IsNotNull(template); TestUtility.AssertAreEqual(template, cube.mesh); Object.DestroyImmediate(cube); }
public static void SubdivideFirstFace_CreatesValidMesh([ValueSource("shapeTypes")] Type shape) { var pb = ShapeFactory.Instantiate(shape); try { var faceCount = pb.faceCount; var face = pb.facesInternal.FirstOrDefault(); Subdivision.Subdivide(pb, new Face[] { face }); pb.ToMesh(); pb.Refresh(); TestUtility.AssertMeshIsValid(pb); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.That(faceCount, Is.LessThan(pb.faceCount)); } finally { UObject.DestroyImmediate(pb.gameObject); } }
public static void Extrude_OneEdge_CreatesValidGeometry() { var pb = ShapeFactory.Instantiate <Cube>(); try { int vertexCount = pb.vertexCount; Edge[] edges = new UnityEngine.ProBuilder.Edge[1]; Face face = pb.facesInternal[m_Random.Next(0, pb.faceCount)]; edges[0] = face.edgesInternal[m_Random.Next(0, face.edgesInternal.Length)]; // as group, enable manifold extrude Assert.IsFalse(pb.Extrude(edges, .5f, true, false) != null, "Do not allow manifold edge extrude"); Assert.IsTrue(pb.Extrude(edges, .5f, true, true) != null, "Do allow manifold edge extrude"); pb.ToMesh(); pb.Refresh(); TestUtility.AssertMeshAttributesValid(pb.mesh); Assert.AreEqual(vertexCount + edges.Length * 4, pb.vertexCount); } finally { UObject.DestroyImmediate(pb.gameObject); } }
public static void SubdivideFirstFace_CreatesValidMesh([ValueSource("shapeTypes")] ShapeType shape) { var pb = ShapeGenerator.CreateShape(shape); try { var face = pb.facesInternal.FirstOrDefault(); Subdivision.Subdivide(pb, new ProBuilder.Face[] { face }); pb.ToMesh(); pb.Refresh(); #if PB_CREATE_TEST_MESH_TEMPLATES TestUtility.SaveAssetTemplate(pb.mesh, pb.name); #endif TestUtility.AssertMeshAttributesValid(pb.mesh); var template = TestUtility.GetAssetTemplate <Mesh>(pb.name); Assert.IsNotNull(template); TestUtility.AssertMeshesAreEqual(template, pb.mesh); } finally { UObject.DestroyImmediate(pb.gameObject); } }