public static ComputeBuffer CreateSkinnedAnimationComputeBuffer(this SkinnedMeshRenderer skinnedMeshRenderer, Animator animator, AnimationClip animationClip, out int framesCount)
        {
            AnimatorStateInfo aniStateInfo = animator.GetCurrentAnimatorStateInfo(0);

            Mesh  bakedMesh    = new Mesh();
            float sampleTime   = 0;
            float perFrameTime = 0;

            framesCount  = Mathf.ClosestPowerOfTwo((int)(animationClip.frameRate * animationClip.length));
            perFrameTime = animationClip.length / framesCount;

            int vertexCount = skinnedMeshRenderer.sharedMesh.vertexCount;

            Vector4[] vertexAnimationData = new Vector4[vertexCount * framesCount];
            for (int i = 0; i < framesCount; i++)
            {
                animator.Play(aniStateInfo.shortNameHash, 0, sampleTime);
                animator.Update(0f);

                skinnedMeshRenderer.BakeMesh(bakedMesh);

                for (int j = 0; j < vertexCount; j++)
                {
                    Vector3 vertex = bakedMesh.vertices[j];
                    vertexAnimationData[(j * framesCount) + i] = vertex;
                }

                sampleTime += perFrameTime;
            }

            ComputeBuffer vertexAnimationBuffer = new ComputeBuffer(vertexCount * framesCount, sizeof(float) * 4);

            vertexAnimationBuffer.SetData(vertexAnimationData.Clone() as Vector4[]);
            return(vertexAnimationBuffer);
        }
Beispiel #2
0
        public void Vector4Clone()
        {
            tlog.Debug(tag, $"Vector4Clone START");

            using (Vector4 vec = new Vector4(20, 20, 20, 20))
            {
                var testingTarget = vec.Clone();
                Assert.IsNotNull(testingTarget, "should be not null");
                Assert.IsInstanceOf <Vector4>(testingTarget, "should be an instance of testing target class!");
            }

            tlog.Debug(tag, $"Vector4Clone END (OK)");
        }
Beispiel #3
0
        /// <summary>
        /// Transforms a poly with the provided matrix
        /// </summary>
        public static Vector4[] Transform(Matrix mat, Vector4[] poly)
        {
            Vector4[] ret = (Vector4[])poly.Clone();
            Vector4.Transform(ret, ref mat, ret);

            return ret;
        }