protected void ConvertMeshRenderDataToDynamicMeshData(EntityCommandBuffer ecb, Entity smrEntity, SkinnedMeshRenderer smr, bool needSkinningData) { if (smr.dynamicMesh != Entity.Null) { return; } Entity meshEntity = smr.sharedMesh; Entity dynamicMeshEntity = ecb.CreateEntity(); smr.dynamicMesh = dynamicMeshEntity; ecb.SetComponent(smrEntity, smr); if (EntityManager.HasComponent <LitMeshRenderData>(meshEntity)) { LitMeshRenderData litMeshRenderData = EntityManager.GetComponentData <LitMeshRenderData>(meshEntity); ref LitMeshData litMeshData = ref litMeshRenderData.Mesh.Value; int indicesCount = litMeshData.Indices.Length; int verticesCount = litMeshData.Vertices.Length; DynamicMeshData dmd = new DynamicMeshData { Dirty = true, IndexCapacity = indicesCount, VertexCapacity = verticesCount, NumIndices = indicesCount, NumVertices = verticesCount, UseDynamicGPUBuffer = true, CopyFrom = needSkinningData ? meshEntity : Entity.Null }; ecb.AddComponent(dynamicMeshEntity, dmd); DynamicBuffer <DynamicLitVertex> dlvBuffer = ecb.AddBuffer <DynamicLitVertex>(dynamicMeshEntity); dlvBuffer.ResizeUninitialized(verticesCount); void *verticesPtr = litMeshData.Vertices.GetUnsafePtr(); byte *dlvBufferPtr = (byte *)dlvBuffer.GetUnsafePtr(); int vertexSize = UnsafeUtility.SizeOf <LitVertex>(); UnsafeUtility.MemCpy(dlvBufferPtr, verticesPtr, verticesCount * vertexSize); DynamicBuffer <DynamicIndex> diBuffer = ecb.AddBuffer <DynamicIndex>(dynamicMeshEntity); diBuffer.ResizeUninitialized(indicesCount); void *indicesPtr = litMeshData.Indices.GetUnsafePtr(); void *dlBufferPtr = diBuffer.GetUnsafePtr(); int indexSize = UnsafeUtility.SizeOf <DynamicIndex>(); UnsafeUtility.MemCpy(dlBufferPtr, indicesPtr, indicesCount * indexSize); }
public bool IsValidFor(DynamicMeshData dmd) { if (!IsValid()) { return(false); } if (dmd.UseDynamicGPUBuffer != isDynamic) { return(false); } if (dmd.IndexCapacity != maxIndexCount) { return(false); } if (dmd.VertexCapacity != maxVertexCount) { return(false); } return(true); }