protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            m_UniqueSpriteComponents.Clear();
            EntityManager.GetAllUniqueSharedComponentData(m_UniqueSpriteComponents);

            var spriteComponentCount = m_UniqueSpriteComponents.Count;
            var returnHandle         = inputDeps;

            for (var i = 0; i < spriteComponentCount; i++)
            {
                var spriteComponent = m_UniqueSpriteComponents[i];
                var sprite          = spriteComponent.Value;
                var entityCount     = 0;

                if (sprite != null)
                {
                    m_ComponentGroup.SetFilter(spriteComponent);
                    var filteredEntities = m_ComponentGroup.ToEntityArray(Allocator.TempJob);

                    entityCount = filteredEntities.Length;
                    if (entityCount > 0)
                    {
                        var skinJob = new SkinJob
                        {
                            entities           = filteredEntities,
                            vertices           = sprite.GetVertexAttribute <Vector3>(UnityEngine.Rendering.VertexAttribute.Position).SliceWithStride <float3>(),
                            boneWeights        = sprite.GetVertexAttribute <BoneWeight>(UnityEngine.Rendering.VertexAttribute.BlendWeight),
                            bindPoses          = new NativeSlice <Matrix4x4>(sprite.GetBindPoses()).SliceWithStride <float4x4>(),
                            localToWorldArray  = m_ComponentGroup.ToComponentDataArray <WorldToLocal>(Allocator.TempJob),
                            boneTransformArray = GetBufferFromEntity <BoneTransform>(),
                            deformedArray      = GetBufferFromEntity <Vertex>()
                        };

                        returnHandle = skinJob.Schedule(entityCount, 4, returnHandle);
                    }
                    else
                    {
                        filteredEntities.Dispose();
                    }
                }
            }

            var system = World.GetOrCreateSystem <EndPresentationEntityCommandBufferSystem>();

            system.AddJobHandleForProducer(returnHandle);

            return(returnHandle);
        }
Exemple #2
0
        internal static JobHandle Deform(NativeSlice <Vector3> inputVertices, NativeArray <BoneWeight> boneWeights, Matrix4x4 worldToLocalMatrix,
                                         NativeArray <Matrix4x4> bindPoses, NativeArray <Matrix4x4> transformMatrices, NativeArray <Vector3> outputVertices)
        {
            if (bindPoses.Length != transformMatrices.Length)
            {
                throw new InvalidOperationException("Invalid TransformMatrices array length.");
            }
            if (boneWeights.Length != inputVertices.Length)
            {
                throw new InvalidOperationException("Invalid BoneWeight array length");
            }
            if (outputVertices.Length != inputVertices.Length)
            {
                throw new InvalidOperationException("Invalid output Vertices array length");
            }

            var skinningMatrices = new NativeArray <Matrix4x4>(transformMatrices.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var boneJob = new BoneJob()
            {
                rootInv   = worldToLocalMatrix,
                bindPoses = bindPoses,
                bones     = transformMatrices,
                output    = skinningMatrices
            };

            var skinJob = new SkinJob()
            {
                influenceCount = 4,
                influences     = boneWeights,
                vertices       = inputVertices,
                bones          = skinningMatrices,
                output         = outputVertices
            };

            return(skinJob.Schedule(boneJob.Schedule()));
        }