public void CheckWeights()
        {
            int        chainCountPerBone = 3;
            int        bonesCount        = 3;
            float      length            = 100f;
            Quaternion rotation          = Quaternion.Euler(0f, 180f, 0);
            var        go = GenerateGO();

            var meshGen = new RopeMeshChainGenerator();

            meshGen.SourceObject  = go;
            meshGen.StepRotation  = rotation;
            meshGen.ChainsPerBone = chainCountPerBone;

            var result = meshGen.Create(1f, length, bonesCount, false);

            var weights = result.mesh.boneWeights;

            int chainCount  = (chainCountPerBone - 1) * (bonesCount - 1) + 1;
            int orVertCount = go.GetComponent <MeshFilter>().sharedMesh.vertexCount;

            Assert.AreEqual(chainCount * orVertCount, weights.Length);

            AssertWeights(weights, 0 * orVertCount, orVertCount, 0, 1, 1f, 0f);
            AssertWeights(weights, 1 * orVertCount, orVertCount, 0, 1, .5f, .5f);
            AssertWeights(weights, 2 * orVertCount, orVertCount, 0, 1, 0f, 1f);

            AssertWeights(weights, 2 * orVertCount, orVertCount, 1, 2, 1f, 0f);
            AssertWeights(weights, 3 * orVertCount, orVertCount, 1, 2, .5f, .5f);
            AssertWeights(weights, 4 * orVertCount, orVertCount, 1, 2, 0f, 1f);
        }
Exemple #2
0
        private void DrawPanelMeshGeneratorChain()
        {
            RopeMeshChainGenerator meshGenerator = _meshGenerator as RopeMeshChainGenerator;

            if (meshGenerator == null)
            {
                meshGenerator  = new RopeMeshChainGenerator();
                _meshGenerator = meshGenerator;
            }
            meshGenerator.SourceObject  = (GameObject)EditorGUILayout.ObjectField(meshGenerator.SourceObject, typeof(GameObject), true);
            meshGenerator.ChainsPerBone = EditorGUILayout.IntField("Chains per bone", meshGenerator.ChainsPerBone);
            meshGenerator.Scale         = EditorGUILayout.FloatField("Scale", meshGenerator.Scale);

            _initialRotation = EditorGUILayout.Vector3Field("Initial rotation", _initialRotation);
            meshGenerator.InitialRotation = Quaternion.Euler(_initialRotation);

            _stepRotation = EditorGUILayout.Vector3Field("Step rotation", _stepRotation);
            meshGenerator.StepRotation = Quaternion.Euler(_stepRotation);

            if (meshGenerator.SourceObject != null)
            {
                var renderer = meshGenerator.SourceObject.GetComponent <Renderer>();
                if (renderer == null)
                {
                    throw new ArgumentException("No renderer found");
                }
                meshGenerator.Materials = renderer.sharedMaterials;
            }
            else
            {
                meshGenerator.Materials = null;
            }
        }
        public void CheckVertices()
        {
            int        chainCountPerBone = 3;
            int        bonesCount        = 2;
            float      length            = 100f;
            Quaternion rotation          = Quaternion.Euler(0f, 180f, 0);
            var        go = GenerateGO();

            var meshGen = new RopeMeshChainGenerator();

            meshGen.SourceObject  = go;
            meshGen.StepRotation  = rotation;
            meshGen.ChainsPerBone = chainCountPerBone;

            var result = meshGen.Create(1f, length, bonesCount, false);

            int   chainCount = (chainCountPerBone - 1) * (bonesCount - 1) + 1;
            float chainStep  = length / (chainCount - 1);

            CheckVertexes(go, result.mesh, rotation, chainCount, chainStep);
        }
        public void CheckColors32()
        {
            int        chainCountPerBone = 3;
            int        bonesCount        = 2;
            float      length            = 100f;
            Quaternion rotation          = Quaternion.Euler(0f, 180f, 0);
            var        go = GenerateGO();

            var meshGen = new RopeMeshChainGenerator();

            meshGen.SourceObject  = go;
            meshGen.StepRotation  = rotation;
            meshGen.ChainsPerBone = chainCountPerBone;

            var result = meshGen.Create(1f, length, bonesCount, false);

            int chainCount = (chainCountPerBone - 1) * (bonesCount - 1) + 1;

            var colorsOld = new List <Color32>(go.GetComponent <MeshFilter>().sharedMesh.colors32);
            var colorsNew = new List <Color32>(result.mesh.colors32);

            CheckDataDupls <Color32>(chainCount, colorsOld, colorsNew);
        }
        public void CheckVertexLength()
        {
            int        chainCountPerBone = 3;
            Quaternion rotation          = Quaternion.identity;
            var        go = GenerateGO();

            var meshGen = new RopeMeshChainGenerator();

            meshGen.SourceObject = go;


            meshGen.StepRotation = rotation;

            meshGen.ChainsPerBone = chainCountPerBone;

            int bonesCount = 2;
            var result     = meshGen.Create(1f, 100f, bonesCount, false);

            var oldMeshVertices = go.GetComponent <MeshFilter>().sharedMesh.vertices;
            var newMeshVertices = result.mesh.vertices;
            int chainCount      = (chainCountPerBone - 1) * (bonesCount - 1) + 1;

            Assert.AreEqual(oldMeshVertices.Length * chainCount, newMeshVertices.Length);
        }