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);
            }
        }
예제 #2
0
        public static void ComplicatedSettings()
        {
            // Stair includes texture groups and non-grouped faces
            var shape = ShapeGenerator.CreateShape(ShapeType.Stair);

            foreach (var face in shape.faces)
            {
                AutoUnwrapSettings uv = face.uv;
                uv.anchor        = AutoUnwrapSettings.Anchor.LowerCenter;
                uv.fill          = AutoUnwrapSettings.Fill.Fit;
                uv.offset        = new Vector3(.2f, .2f);
                uv.rotation      = 32f;
                uv.scale         = new Vector2(1.2f, 3f);
                uv.swapUV        = true;
                uv.useWorldSpace = false;
                face.uv          = uv;
            }

            shape.ToMesh();
            shape.Refresh();
            shape.name += "-SettingGumbo";

#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);
        }
예제 #3
0
        public static void Anchor()
        {
            var anchors = Enum.GetValues(typeof(AutoUnwrapSettings.Anchor));

            foreach (var anchor in anchors)
            {
                var shape = ShapeGenerator.CreateShape(ShapeType.Cylinder);

                foreach (var face in shape.faces)
                {
                    AutoUnwrapSettings uv = face.uv;
                    uv.anchor = (AutoUnwrapSettings.Anchor)anchor;
                    face.uv   = uv;
                }

                shape.ToMesh();
                shape.Refresh();

                var name = shape.name + "-Anchor(" + anchor + ")";
                shape.name = name;

#if PB_CREATE_TEST_MESH_TEMPLATES
                TestUtility.SaveAssetTemplate(shape.mesh, name);
#endif

                Mesh template = TestUtility.GetAssetTemplate <Mesh>(name);
                TestUtility.AssertAreEqual(template, shape.mesh, message: name);
                UObject.DestroyImmediate(shape.gameObject);
            }
        }
예제 #4
0
    public static void RegisterComplete()
    {
        var cube      = ShapeFactory.Instantiate <Cube>();
        var duplicate = UnityEngine.Object.Instantiate(cube.gameObject).GetComponent <ProBuilderMesh>();

        duplicate.MakeUnique();

        TestUtility.AssertAreEqual(cube.mesh, duplicate.mesh);

        UnityEditor.Undo.RegisterCompleteObjectUndo(new[] { cube }, "Merge Vertices");
        cube.MergeVertices(new int[] { 0, 1 }, true);
        cube.ToMesh();
        cube.Refresh();

        Assert.IsFalse(TestUtility.MeshesAreEqual(cube.mesh, duplicate.mesh));

        UnityEditor.Undo.PerformUndo();

        // this is usually caught by UndoUtility
        cube.InvalidateCaches();

        cube.ToMesh();
        cube.Refresh();

        TestUtility.AssertAreEqual(duplicate.mesh, cube.mesh);

        UnityEngine.Object.DestroyImmediate(cube.gameObject);
        UnityEngine.Object.DestroyImmediate(duplicate.gameObject);
    }
예제 #5
0
        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);
        }
예제 #6
0
    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);
            }
        }
    }
예제 #7
0
    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
    }
예제 #8
0
        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);
        }
예제 #9
0
    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);
            }
        }
    }
예제 #10
0
        public void NewAndRemoveNodeConfigurationUsingFabricPackage()
        {
            LogHelper.Log("NewAndRemoveNodeConfigurationUsingFabricPackage");
            var fabricDataRoot = Path.Combine(baseDropPath, @"TestData");
            var fabricLogRoot  = Path.Combine(baseDropPath, @"TestLog");

            Directory.CreateDirectory(fabricDataRoot);
            string defaultDropPath     = Environment.ExpandEnvironmentVariables(Constants.FabricDropPath);
            var    clusterManifestPath = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.TestRootPath), "DevEnv-FiveNodes.xml");
            var    command             = new Command(Constants.NewNodeConfigurationCommand);

            command.Parameters.Add("ClusterManifestPath", clusterManifestPath);
            command.Parameters.Add("UsingFabricPackage");
            command.Parameters.Add("FabricPackageRoot", defaultDropPath);
            command.Parameters.Add("FabricDataRoot", fabricDataRoot);
            command.Parameters.Add("FabricLogRoot", fabricLogRoot);
            command.Parameters.Add("RunFabricHostServiceAsManual");
            TestCommon.Log(command);
            var pipeline = runspace.CreatePipeline();

            pipeline.Commands.Add(command);
            var result = pipeline.Invoke();

            TestCommon.Log(result);
            TestUtility.AssertAreEqual(1, result.Count);
            Assert.AreEqual("Manual", GetServiceStartupType(Constants.FabricHostSerivceName));
            using (var registry = Registry.LocalMachine.OpenSubKey(FabricConstants.FabricRegistryKeyPath))
            {
                Assert.IsNotNull(registry);
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricDataRoot), fabricDataRoot, true));
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricLogRoot), fabricLogRoot, true));
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricRoot), defaultDropPath, true));
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricBinRoot), Path.Combine(defaultDropPath, "bin"), true));
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricCodePath), Path.Combine(defaultDropPath, @"bin\fabric\fabric.code"), true));
            }

            command = new Command(Constants.RemoveNodeConfigurationCommand);
            command.Parameters.Add("DeleteLog");
            command.Parameters.Add("Force");
            command.Parameters.Add("UsingFabricPackage");
            TestCommon.Log(command);
            pipeline = runspace.CreatePipeline();
            pipeline.Commands.Add(command);
            result = pipeline.Invoke();
            TestCommon.Log(result);
            TestUtility.AssertAreEqual(1, result.Count);
            Assert.AreEqual("<null>", GetServiceStartupType(Constants.FabricHostSerivceName));
            using (var registry = Registry.LocalMachine.OpenSubKey(FabricConstants.FabricRegistryKeyPath))
            {
                Assert.IsNull(registry);
            }

            var folders = Directory.GetDirectories(fabricLogRoot);

            TestUtility.AssertAreEqual(1, folders.Length);
        }
예제 #11
0
        private static void ExecuteProcess(string command, string arguments = null, int expectExitCode = 0, int timeout = 600000)
        {
            var process = StartProcess(command, arguments);

            if (!process.WaitForExit(timeout))
            {
                process.Kill();
                Assert.Fail("process " + command + " " + arguments + " timeout");
            }

            TestUtility.AssertAreEqual(expectExitCode, process.ExitCode, "process exit code " + process.ExitCode + " should match expect " + expectExitCode);
        }
        public static void SetFillMode_IsAppliedToMesh([ValueSource("fillModeValues")] AutoUnwrapSettings.Fill fill)
        {
            var shape = ShapeGenerator.CreateShape(ShapeType.Sprite);

            Assume.That(shape, Is.Not.Null);

            try
            {
                var positions = shape.positionsInternal;

                // move it off center so that we can be sure fill/scale doesn't change the offset
                for (int i = 0; i < shape.vertexCount; i++)
                {
                    var p = positions[i];
                    p.x         *= .7f;
                    p.z         *= .4f;
                    p.x         += 1.5f;
                    p.z         += 1.3f;
                    positions[i] = p;
                }

                foreach (var face in shape.faces)
                {
                    AutoUnwrapSettings uv = face.uv;
                    uv.fill = (AutoUnwrapSettings.Fill)fill;
                    face.uv = uv;
                }

                shape.ToMesh();
                shape.Refresh();

                var name = shape.name + "-Fill(" + fill + ")";
                shape.name = name;

#if PB_CREATE_TEST_MESH_TEMPLATES
                TestUtility.SaveAssetTemplate(shape.mesh, name);
#endif

                Mesh template = TestUtility.GetAssetTemplate <Mesh>(name);
                TestUtility.AssertAreEqual(template, shape.mesh, message: name);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.ToString());
            }
            finally
            {
                UnityEngine.Object.DestroyImmediate(shape.gameObject);
            }
        }
예제 #13
0
        public void TestClusterManifestTest()
        {
            LogHelper.Log("TestClusterManifestTest");
            var pipeline = runspace.CreatePipeline();
            var command  = new Command(Constants.TestClusterManifestCommand);

            command.Parameters.Add("ClusterManifestPath", @"..\..\..\DevEnv-FiveNodes.xml");
            pipeline.Commands.Add(command);
            TestCommon.Log(command);
            var result = pipeline.Invoke();

            TestCommon.Log(result);
            TestUtility.AssertAreEqual(1, result.Count);
            Assert.IsTrue((bool)(result[0].ImmediateBaseObject));
        }
예제 #14
0
        public void NewNodeConfigurationTestInfrastructureManifest()
        {
            LogHelper.Log("NewNodeConfigurationTestInfrastructureManifest");
            CreateFabricHostSvc();
            var fabricDataRoot             = Path.Combine(baseDropPath, "Test Data");
            var fabricLogRoot              = Path.Combine(fabricDataRoot, "Log");
            var clusterManifestPath        = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.TestRootPath), "ClusterManifest-Server-Default.xml");
            var infrastructureManifestPath = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.TestRootPath), "InfrastructureManifest.xml");

            Directory.CreateDirectory(fabricDataRoot);
            var command = new Command(Constants.NewNodeConfigurationCommand);

            command.Parameters.Add("ClusterManifestPath", clusterManifestPath);
            command.Parameters.Add("InfrastructureManifestPath", infrastructureManifestPath);
            command.Parameters.Add("FabricDataRoot", fabricDataRoot);
            TestCommon.Log(command);
            var pipeline = runspace.CreatePipeline();

            pipeline.Commands.Add(command);
            var result = pipeline.Invoke();

            TestCommon.Log(result);
            TestUtility.AssertAreEqual(1, result.Count);

            using (var registry = Registry.LocalMachine.CreateSubKey(FabricConstants.FabricRegistryKeyPath))
            {
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricDataRoot), fabricDataRoot, true));
                Assert.AreEqual(0, string.Compare((string)registry.GetValue(Constants.FabricLogRoot), fabricLogRoot, true));
            }

            var targetFilePath = Path.Combine(fabricDataRoot, Constants.TargetInformationFileName);

            Assert.IsTrue(File.Exists(targetFilePath));
            using (var fileStream = File.Open(targetFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var xmlReader = XmlReader.Create(fileStream, new XmlReaderSettings()
                {
                    XmlResolver = null
                }))
                {
                    var serializer        = new XmlSerializer(typeof(TargetInformationType));
                    var targetInformation = (TargetInformationType)serializer.Deserialize(xmlReader);
                    Assert.AreEqual(0, string.Compare(clusterManifestPath, targetInformation.TargetInstallation.ClusterManifestLocation, true));
                    Assert.AreEqual(0, string.Compare(infrastructureManifestPath, targetInformation.TargetInstallation.InfrastructureManifestLocation, true));
                }
            }
        }
        public static void CubeSurvivesRoundTrip()
        {
            var pb = ShapeGenerator.CreateShape(ShapeType.Cube);

            try
            {
                var dup      = new GameObject().AddComponent <ProBuilderMesh>();
                var importer = new MeshImporter(dup);
                importer.Import(pb.gameObject);
                dup.ToMesh();
                dup.Refresh();
                TestUtility.AssertAreEqual(pb.mesh, dup.mesh, message: pb.name);
            }
            catch
            {
                UnityEngine.Object.DestroyImmediate(pb.gameObject);
            }
        }
예제 #16
0
        public void InvokeEncryptSecretTest()
        {
            LogHelper.Log("InvokeEncryptSecretTest");
            var command = new Command(Constants.InvokeEncryptSecretCommand);

            command.Parameters.Add("CertThumbPrint", "7812205a39d22376daa037f05aede3601a7e64bf");
            command.Parameters.Add("CertStoreLocation", X509Credentials.StoreNameDefault);
            command.Parameters.Add("Text", "!Password");
            TestCommon.Log(command);
            var pipeline = runspace.CreatePipeline();

            pipeline.Commands.Add(command);
            var result = pipeline.Invoke();

            TestCommon.Log(result);
            TestUtility.AssertAreEqual(1, result.Count);
            pipeline.Dispose();
        }
예제 #17
0
        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);
                }
            }
        }
예제 #18
0
        public static void FillMode()
        {
            var fillModes = Enum.GetValues(typeof(AutoUnwrapSettings.Fill));

            foreach (var fill in fillModes)
            {
                var shape     = ShapeGenerator.CreateShape(ShapeType.Sprite);
                var positions = shape.positionsInternal;

                // move it off center so that we can be sure fill/scale doesn't change the offset
                for (int i = 0; i < shape.vertexCount; i++)
                {
                    var p = positions[i];
                    p.x         *= .7f;
                    p.z         *= .4f;
                    p.x         += 1.5f;
                    p.z         += 1.3f;
                    positions[i] = p;
                }

                foreach (var face in shape.faces)
                {
                    AutoUnwrapSettings uv = face.uv;
                    uv.fill = (AutoUnwrapSettings.Fill)fill;
                    face.uv = uv;
                }

                shape.ToMesh();
                shape.Refresh();

                var name = shape.name + "-Fill(" + fill + ")";
                shape.name = name;

#if PB_CREATE_TEST_MESH_TEMPLATES
                TestUtility.SaveAssetTemplate(shape.mesh, name);
#endif

                Mesh template = TestUtility.GetAssetTemplate <Mesh>(name);
                TestUtility.AssertAreEqual(template, shape.mesh, message: name);
                UObject.DestroyImmediate(shape.gameObject);
            }
        }
        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);
            }
        }
예제 #20
0
    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 ImportCube_MatchesDefaultCube()
    {
        var pb = ShapeGenerator.CreateShape(ShapeType.Cube);

        try
        {
#pragma warning disable 612
            var dup      = new GameObject().AddComponent <ProBuilderMesh>();
            var importer = new MeshImporter(dup);
            importer.Import(pb.gameObject);
#pragma warning restore 612
            dup.ToMesh();
            dup.Refresh();
            TestUtility.AssertAreEqual(pb.mesh, dup.mesh, message: pb.name);
        }
        catch
        {
            UnityEngine.Object.DestroyImmediate(pb.gameObject);
        }
    }
예제 #22
0
        public static void DuplicateMesh_ApplyColor_MatchesTemplate()
        {
            var cube = ShapeGenerator.CreateShape(ShapeType.Cube);
            var dup  = UObject.Instantiate(cube.gameObject).GetComponent <ProBuilderMesh>();

            dup.SetFaceColor(dup.faces[0], Color.blue);

            dup.ToMesh();
            dup.Refresh();

#if PB_CREATE_TEST_MESH_TEMPLATES
            TestUtility.SaveAssetTemplate(dup.mesh, dup.name);
#endif
            var compare = TestUtility.GetAssetTemplate <Mesh>(dup.name);

            TestUtility.AssertAreEqual(compare, dup.mesh);

            UObject.DestroyImmediate(cube);
            UObject.DestroyImmediate(dup);
        }
예제 #23
0
        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);
                }
            }
        }
예제 #24
0
        public static void CopyWithVerifyIsUnique()
        {
            var original = ShapeGenerator.CreateShape(ShapeType.Cube);
            var copy     = UObject.Instantiate(original);

            try
            {
                // optimize after instantiate because Instantiate runs mesh through serialization, introducing tiny rounding
                // errors in some fields. by comparing the results post-serialization we get a more accurate diff
                original.Optimize();
                EditorUtility.SynchronizeWithMeshFilter(copy);
                Assert.AreNotEqual(copy, original, "GameObject references are equal");
                Assert.IsFalse(ReferenceEquals(copy.mesh, original.mesh), "Mesh references are equal");
                TestUtility.AssertAreEqual(original.mesh, copy.mesh);
            }
            finally
            {
                UObject.DestroyImmediate(original.gameObject);
                UObject.DestroyImmediate(copy.gameObject);
            }
        }
예제 #25
0
        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 SetAnchor_IsAppliedToMesh([ValueSource("anchorValues")] AutoUnwrapSettings.Anchor anchor)
        {
            var mesh = ShapeGenerator.CreateShape(ShapeType.Cube);

            Assume.That(mesh, Is.Not.Null);

            try
            {
                foreach (var face in mesh.faces)
                {
                    AutoUnwrapSettings uv = face.uv;
                    uv.anchor = anchor;
                    face.uv   = uv;
                }

                mesh.ToMesh();
                mesh.Refresh();

                var name = mesh.name + "-Anchor(" + anchor + ")";
                mesh.name = name;

#if PB_CREATE_TEST_MESH_TEMPLATES
                TestUtility.SaveAssetTemplate(mesh.mesh, name);
#endif

                Mesh template = TestUtility.GetAssetTemplate <Mesh>(name);
                TestUtility.AssertAreEqual(template, mesh.mesh, message: name);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.ToString());
            }
            finally
            {
                UnityEngine.Object.DestroyImmediate(mesh.gameObject);
            }
        }
        public static void SetWorldSpace_IsAppliedToMesh()
        {
            // Stair includes texture groups and non-grouped faces
            var shape = ShapeGenerator.CreateShape(ShapeType.Stair);

            foreach (var face in shape.faces)
            {
                AutoUnwrapSettings uv = face.uv;
                uv.useWorldSpace = true;
                face.uv          = uv;
            }

            shape.ToMesh();
            shape.Refresh();
            shape.name += "-UV-World-Space";

#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);
        }
예제 #28
0
    public static void DetachFaceUndoTest()
    {
        var cube      = ShapeFactory.Instantiate <Cube>();
        var duplicate = UnityEngine.Object.Instantiate(cube.gameObject).GetComponent <ProBuilderMesh>();

        duplicate.MakeUnique();

        // Select the mesh
        MeshSelection.SetSelection(cube.gameObject);
        MeshSelection.OnObjectSelectionChanged();
        Assume.That(MeshSelection.selectedObjectCount, Is.EqualTo(1));

        // Select a face
        cube.SetSelectedFaces(new Face[] { cube.facesInternal[0] });
        Assume.That(cube.selectedFacesInternal.Length, Is.EqualTo(1));

        // Perform `Detach Faces` action
        var detachAction = new DetachFaces();
        var result       = detachAction.PerformAction();

        Assume.That(result.status, Is.EqualTo(ActionResult.Status.Success));

        UnityEditor.Undo.PerformUndo();

        // this is usually caught by UndoUtility
        cube.InvalidateCaches();

        cube.ToMesh();
        cube.Refresh();

        // After undo, previously edited mesh should match the duplicate
        TestUtility.AssertAreEqual(duplicate.mesh, cube.mesh);

        UnityEngine.Object.DestroyImmediate(cube.gameObject);
        UnityEngine.Object.DestroyImmediate(duplicate.gameObject);
    }