示例#1
0
            /// <summary>
            /// outData = lhs - rhs;
            /// </summary>
            public static void Subtract(ShapeKeyData lhs, ShapeKeyData rhs, ShapeKeyData outData)
            {
                Vector3[] outVerts = outData.vertices;
                Vector3[] outNorms = outData.normals;
                Vector4[] outTangs = outData.tangents;
                Vector3[] lhsVerts = lhs.vertices;
                Vector3[] lhsNorms = lhs.normals;
                Vector4[] lhsTangs = lhs.tangents;
                Vector3[] rhsVerts = rhs.vertices;
                Vector3[] rhsNorms = rhs.normals;
                Vector4[] rhsTangs = rhs.tangents;

                int vcnt        = outData.Count;
                int outNormsLen = outNorms.Length;
                int outTangsLen = outTangs.Length;

                for (int i = 0; i < vcnt; ++i)
                {
                    outVerts[i] = lhsVerts[i] - rhsVerts[i];
                }

                for (int i = 0; i < outNormsLen; ++i)
                {
                    outNorms[i] = lhsNorms[i] - rhsNorms[i];
                }

                for (int i = 0; i < outTangsLen; ++i)
                {
                    outTangs[i] = lhsTangs[i] - rhsTangs[i];
                }
            }
示例#2
0
            public static ShapeKeyData New(float weight, ShapeKeyMorphSO basisSO)
            {
                ShapeKeyData d = new ShapeKeyData();

                //int vcnt = m.vertexCount;

                d.basisSO = basisSO;

                Mesh m = basisSO.GetMesh();

                d.vertices = m.vertices;
                d.normals  = m.normals;
                d.tangents = m.tangents;

                d.weight = weight;

                return(d);
            }
示例#3
0
            public static void Lerp(ShapeKeyData lhs, ShapeKeyData rhs, float leftWeight, float targetWeight, ShapeKeyData outData)
            {
                Dbg.Assert(outData != null && outData.IsValid(lhs.Count), "ShapeKeyData.Lerp: output data is not initialized");

                int vcnt = lhs.Count;

                bool hasNormals  = (outData.normals.Length == vcnt);
                bool hasTangents = (outData.tangents.Length == vcnt);

                float t = Mathf.InverseLerp(leftWeight, rhs.weight, targetWeight);

                // Lerp [THIS PART is PAINPOINT of PERFORMANCE!]
                Vector3[] outVerts = outData.vertices;
                Vector3[] outNorms = outData.normals;
                Vector4[] outTangs = outData.tangents;
                Vector3[] lhsVerts = lhs.vertices;
                Vector3[] lhsNorms = lhs.normals;
                Vector4[] lhsTangs = lhs.tangents;
                Vector3[] rhsVerts = rhs.vertices;
                Vector3[] rhsNorms = rhs.normals;
                Vector4[] rhsTangs = rhs.tangents;

                for (int i = 0; i < vcnt; ++i)
                {
                    outVerts[i] = Vector3.Lerp(lhsVerts[i], rhsVerts[i], t);
                }

                if (hasNormals)
                {
                    for (int i = 0; i < vcnt; ++i)
                    {
                        outNorms[i] = Vector3.Lerp(lhsNorms[i], rhsNorms[i], t);
                    }
                }
                if (hasTangents)
                {
                    for (int i = 0; i < vcnt; ++i)
                    {
                        outTangs[i] = Vector4.Lerp(lhsTangs[i], rhsTangs[i], t);
                    }
                }
            }
示例#4
0
            public void Copy(ShapeKeyData rhs)
            {
                Dbg.Assert(this.vertices.Length == rhs.vertices.Length, "ShapeKeyData.Copy: vertices cnt: {0}!={1}", vertices.Length, rhs.vertices.Length);
                Dbg.Assert(this.normals.Length == rhs.normals.Length, "ShapeKeyData.Copy: normals cnt: {0}!={1}", normals.Length, rhs.normals.Length);
                Dbg.Assert(this.tangents.Length == rhs.tangents.Length, "ShapeKeyData.Copy: tangents cnt: {0}!={1}", tangents.Length, rhs.tangents.Length);

                for (int i = 0; i < vertices.Length; ++i)
                {
                    this.vertices[i] = rhs.vertices[i];
                }
                for (int i = 0; i < normals.Length; ++i)
                {
                    this.normals[i] = rhs.normals[i];
                }
                for (int i = 0; i < tangents.Length; ++i)
                {
                    this.tangents[i] = rhs.tangents[i];
                }

                this.weight = rhs.weight;

                this.basisSO = rhs.basisSO;
            }
示例#5
0
 /// <summary>
 /// given two ShapeKeyDeformSO structures, and a interpolate t,
 /// generate the output data and fill the ShapeKeyData structure;
 /// </summary>
 public static void Lerp(ShapeKeyData lhs, ShapeKeyData rhs, float targetWeight, ShapeKeyData outData)
 {
     Lerp(lhs, rhs, lhs.weight, targetWeight, outData);
 }
示例#6
0
 private static void _InitVertices_Diff(Mesh m, ShapeKeyData basisShape)
 {
     throw new NotImplementedException();
 }