예제 #1
0
    public void Loop()
    {
        BoneMain instance = BoneMain.GetInstance();

        count += countTime;
        float s = Mathf.Sin(count);
        float a = 0.3f * s;

        for (int i = 0; i < bones.Count; i++)
        {
            Matrix4x4 m = MatrixUtils.RotateY(a);
            bones [i].matrixBone = bones [i].matrixInit * m;
        }

        Bone.UpdateBone(bones[0], gmat);

        for (int i = 0; i < bones.Count; i++)
        {
            combMatArr[i] = bones[i].matrixComb;
        }

        int index = 0;

        for (int i = 0; i < 6; i++)
        {
            int idxBase = index * 3;
            int idx0    = idxBase + 0;
            int idx1    = idxBase + 1;
            int idx2    = idxBase + 2;

            Matrix4x4[] comb1 =
            {
                Matrix4x4.identity,
                Matrix4x4.identity,
                Matrix4x4.identity,
                Matrix4x4.identity
            };
            Matrix4x4 comb2 = Matrix4x4.zero;

            for (var j = 0; j < 3; j++)
            {
                int boneIdx   = index * 4 + j;
                int weightIdx = index * 3 + j;

                comb1[j] = MatrixUtils.MultiplyScalar(combMatArr[m_planeData.boneIndices[boneIdx]],
                                                      m_planeData.weights[weightIdx], comb1[j]);
            }

            // 1.0 - weight1 - weight2 - weight3
            float weight = 1.0f - (m_planeData.weights[index * 3 + 0] +
                                   m_planeData.weights[index * 3 + 1] +
                                   m_planeData.weights[index * 3 + 2]);
            comb1[3] = MatrixUtils.MultiplyScalar(combMatArr[m_planeData.boneIndices[index * 4 + 3]], weight, comb1[3]);

            for (int k = 0; k < 4; k++)
            {
                comb2 = MatrixUtils.Add(comb2, comb1 [k], comb2);
            }

            Vector3 pos = newPos [i];
            pos.x = m_planeData.position[idx0];
            pos.y = m_planeData.position[idx1];
            pos.z = m_planeData.position[idx2];

            pos            = comb2.MultiplyVector(pos);
            newVec [index] = pos;
            index++;
        }

        Matrix4x4 m2 = Matrix4x4.identity;

        m2.SetTRS(position, rot, scale);

        index = 0;
        for (int i = m_startIndex; i < m_startIndex + 12; i++)
        {
            Vector3 newVert = m2.MultiplyPoint3x4(newVec [m_planeData.index [index]] - pivot);
            instance.vertices [i] = newVert;
            instance.indices [i]  = i;
            index++;
        }
    }