Ejemplo n.º 1
0
        private JobHandle DeformJob(SpriteSkin spriteSkin, NativeArray <Vector3> deformedVertices)
        {
            var sprite            = spriteSkin.spriteRenderer.sprite;
            var bindPoses         = sprite.GetBindPoses();
            var boneWeights       = sprite.GetBoneWeights();
            var transformMatrices = new NativeArray <Matrix4x4>(spriteSkin.boneTransforms.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < spriteSkin.boneTransforms.Length; ++i)
            {
                transformMatrices[i] = spriteSkin.boneTransforms[i].localToWorldMatrix;
            }

            return(SpriteSkinUtility.Deform(sprite.GetVertexAttribute <Vector3>(VertexAttribute.Position), boneWeights, spriteSkin.transform.worldToLocalMatrix, bindPoses, transformMatrices, deformedVertices));
        }
        private void AssertDeformAABB(SpriteSkin spriteSkin, Bounds expectedBounds)
        {
            var deformedVertices = new NativeArray <Vector3>(spriteSkin.spriteRenderer.sprite.GetVertexCount(), Allocator.Persistent);
            var minMax           = new NativeArray <Vector3>(2, Allocator.Persistent);

            SpriteSkinUtility.CalculateBounds(deformedVertices, minMax, DeformJob(spriteSkin, deformedVertices)).Complete();

            var newBounds = new Bounds();

            newBounds.SetMinMax(minMax[0], minMax[1]);

            Assert.That(newBounds.center, Is.EqualTo(expectedBounds.center).Using(vec3Compare));
            Assert.That(newBounds.extents, Is.EqualTo(expectedBounds.extents).Using(vec3Compare));

            deformedVertices.Dispose();
            minMax.Dispose();
        }
Ejemplo n.º 3
0
        public void Deform_ThrowsException_WhenOutputVerticesLength_DoesNotMatch_VerticesLength()
        {
            var deformedVertices  = new NativeArray <Vector3>(1, Allocator.Persistent);
            var transformMatrices = new NativeArray <Matrix4x4>(m_SpriteSkin.boneTransforms.Length, Allocator.Persistent);

            Assert.Throws <InvalidOperationException>(
                () => {
                var sprite      = m_SpriteSkin.spriteRenderer.sprite;
                var bindPoses   = sprite.GetBindPoses();
                var boneWeights = sprite.GetBoneWeights();

                SpriteSkinUtility.Deform(sprite.GetVertexAttribute <Vector3>(VertexAttribute.Position), boneWeights, m_SpriteSkin.transform.worldToLocalMatrix, bindPoses, transformMatrices, deformedVertices);
            },
                "BoneTransforms should have same length as BindPoses");

            deformedVertices.Dispose();
            transformMatrices.Dispose();
        }
Ejemplo n.º 4
0
        public void Deform_ThrowsException_WhenBoneTransformLength_DoesNotMatch_BindPoseLength()
        {
            var outputVertices    = new NativeArray <float3>(m_SpriteSkin.spriteRenderer.sprite.GetVertexCount(), Allocator.Persistent);
            var transformMatrices = new NativeArray <float4x4>(1, Allocator.Temp);

            Assert.Throws <IndexOutOfRangeException>(
                () => {
                var sprite         = m_SpriteSkin.spriteRenderer.sprite;
                var boneWeights    = sprite.GetVertexAttribute <BoneWeight>(VertexAttribute.BlendWeight);
                var spriteVertices = sprite.GetVertexAttribute <Vector3>(UnityEngine.Rendering.VertexAttribute.Position).SliceWithStride <float3>();
                var influences     = sprite.GetVertexAttribute <BoneWeight>(UnityEngine.Rendering.VertexAttribute.BlendWeight);
                var bindPoses      = new NativeSlice <Matrix4x4>(sprite.GetBindPoses()).SliceWithStride <float4x4>();

                SpriteSkinUtility.Deform(m_SpriteSkin.transform.worldToLocalMatrix, spriteVertices, boneWeights, transformMatrices, bindPoses, outputVertices);
            },
                "BoneTransforms should have same length as BindPoses");

            outputVertices.Dispose();
            transformMatrices.Dispose();
        }
Ejemplo n.º 5
0
 private void DeformJob(SpriteSkin spriteSkin, NativeArray <Vector3> deformableVertices)
 {
     SpriteSkinUtility.Deform(spriteSkin.spriteRenderer.sprite, spriteSkin.transform.worldToLocalMatrix, m_SpriteSkin.boneTransforms, ref deformableVertices);
 }