void UpdateBones()
        {
            var s1   = Vector3.one;
            var data = new GPUBone[bones.Count];

            var offset = transform.localToWorldMatrix;

            for (int i = 0, n = bones.Count; i < n; i++)
            {
                var local   = locals[i];  // initial local transform
                var global  = globals[i]; // initial global transform
                var current = bones[i];   // current transform

                var bone = new GPUBone(global.T, global.R, global.S);

                // var curLocalM = Matrix4x4.TRS(current.transform.localPosition, current.transform.localRotation, current.transform.localScale);
                // var diff = (curLocalM * local.IM);

                var curGlobalM = Matrix4x4.TRS(current.transform.position, current.transform.rotation, current.transform.lossyScale);
                var diff       = ((offset.inverse * curGlobalM) * local.IM);

                offset        = offset * (diff * local.M);
                bone.combined = offset * global.IM;
                data[i]       = bone;
            }
            boneBuffer.SetData(data);
        }
        void DebugBones()
        {
            var bones = new GPUBone[boneBuffer.count];

            boneBuffer.GetData(bones);
            for (int i = 0, n = bones.Length; i < n; i++)
            {
                var bone = bones[i];
                var r    = bone.rotation;
                if (
                    float.IsNaN(r.m00) ||
                    float.IsNaN(r.m01) ||
                    float.IsNaN(r.m02) ||
                    float.IsNaN(r.m03) ||
                    float.IsNaN(r.m10) ||
                    float.IsNaN(r.m11) ||
                    float.IsNaN(r.m12) ||
                    float.IsNaN(r.m13) ||
                    float.IsNaN(r.m20) ||
                    float.IsNaN(r.m21) ||
                    float.IsNaN(r.m22) ||
                    float.IsNaN(r.m23) ||
                    float.IsNaN(r.m30) ||
                    float.IsNaN(r.m31) ||
                    float.IsNaN(r.m32) ||
                    float.IsNaN(r.m33)
                    )
                {
                    Debug.Log(r);
                }
            }
        }
Exemple #3
0
        protected override GPUBone[] BuildBones()
        {
            CheckInit();

            var vertices = mesh.vertices;
            var bones    = new GPUBone[instancesCount * boneCount];
            var rot      = transform.rotation;
            var scale    = transform.lossyScale;

            for (int y = 0; y < instancesCount; y++)
            {
                var ioffset = y * boneCount;
                for (int x = 0; x < boneCount; x++)
                {
                    var p = new Vector3(center.x, max.y - unitLength * x, center.z);
                    bones[ioffset + x] = new GPUBone(transform.TransformPoint(p), rot, scale);
                }
            }

            return(bones);
        }
Exemple #4
0
        protected override GPUBone[] BuildBones()
        {
            var     bounds = mesh.bounds;
            Vector3 min = bounds.min, max = bounds.max;
            var     unit     = (max.y - min.y) / (boneCount - 1);
            var     vertices = mesh.vertices;

            var bones = new GPUBone[instancesCount * boneCount];
            var rot   = transform.rotation;
            var scale = transform.lossyScale;

            for (int y = 0; y < instancesCount; y++)
            {
                var ioffset = y * boneCount;
                for (int x = 0; x < boneCount; x++)
                {
                    var p = new Vector3(bounds.center.x, max.y - unit * x, bounds.center.z);
                    // keep world offset transform
                    bones[ioffset + x] = new GPUBone(transform.TransformPoint(p), rot, scale);
                }
            }

            return(bones);
        }