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 SoftNormalsAreSoft() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { foreach (var face in pb.faces) { face.smoothingGroup = 1; } pb.ToMesh(); pb.Refresh(); Vector3[] normals = pb.GetNormals(); foreach (var common in pb.sharedVertices) { int[] arr = common.arrayInternal; Vector3 nrm = normals[arr[0]]; for (int i = 1, c = arr.Length; i < c; i++) { Assert.AreEqual(nrm, normals[arr[i]]); } } } } }
public IEnumerator DefaultUnwrapParamsDoNotOverlap() { var lightmapMode = Lightmapping.giWorkflowMode; try { Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; Lightmapping.started += LightmappingStarted; if (Lightmapping.completed == null) { Lightmapping.completed = LightmappingCompleted; } else { Lightmapping.completed += LightmappingCompleted; } Setup(); float x = -10f; using (var shapes = new TestUtility.BuiltInPrimitives()) { SceneModeUtility.SetStaticFlags(shapes.Select(it => it.gameObject).ToArray(), (int)StaticEditorFlags.LightmapStatic, true); foreach (ProBuilderMesh mesh in shapes) { mesh.transform.position = new Vector3(x, 0f, 0f); x += mesh.mesh.bounds.size.x + .5f; mesh.Optimize(true); } Lightmapping.BakeAsync(); while (!s_FinishedBaking) { yield return(null); } LogAssert.NoUnexpectedReceived(); } } finally { Lightmapping.started -= LightmappingStarted; Lightmapping.completed -= LightmappingCompleted; Lightmapping.giWorkflowMode = lightmapMode; Cleanup(); } }
public static void MeshAttributesAreValidOnInit() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { Assert.NotNull(pb.positionsInternal, pb.name); Assert.NotNull(pb.facesInternal, pb.name); Assert.NotNull(pb.texturesInternal, pb.name); Assert.NotNull(pb.sharedVerticesInternal, pb.name); Assert.NotNull(pb.sharedTextures, pb.name); } } }
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 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 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 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 SoftNormalsAreNormalized() { using (var shapes = new TestUtility.BuiltInPrimitives()) { foreach (var pb in (IEnumerable <ProBuilderMesh>)shapes) { foreach (var face in pb.faces) { face.smoothingGroup = 1; } pb.Refresh(RefreshMask.Normals); Vector3[] normals = pb.GetNormals(); foreach (var nrm in normals) { Assert.AreEqual(1f, nrm.magnitude, k_NormalCompareEpsilon, pb.name); } } } }
public static void DeleteRandomFace() { using (var shapes = new TestUtility.BuiltInPrimitives()) { } }