public unsafe void CheckVertexLayout() { SkinnedMeshVertex smv; SkinnedMeshVertex *smvPtr = &smv; { Debug.Assert((long)&(smvPtr->BoneWeight) - (long)smvPtr == 0); Debug.Assert((long)&(smvPtr->BoneIndex) - (long)smvPtr == 16); } }
public static unsafe MeshBGFX CreateStaticSkinnedMeshFromBlobAsset(RendererBGFXInstance *inst, LitMeshRenderData meshData, SkinnedMeshRenderData skinnedData) { ushort * indices = (ushort *)meshData.Mesh.Value.Indices.GetUnsafePtr(); int nindices = meshData.Mesh.Value.Indices.Length; LitVertex * vertices = (LitVertex *)meshData.Mesh.Value.Vertices.GetUnsafePtr(); int nvertices = meshData.Mesh.Value.Vertices.Length; SkinnedMeshVertex *skinningdata = (SkinnedMeshVertex *)skinnedData.SkinnedMeshDataRef.Value.Vertices.GetUnsafePtr(); return(CreateStaticMesh(inst, indices, nindices, vertices, nvertices, skinningdata)); }
public static unsafe MeshBGFX CreateStaticMesh(RendererBGFXInstance *inst, ushort *indices, int nindices, LitVertex *vertices, int nvertices, SkinnedMeshVertex *skinningdata = null) { Assert.IsTrue(nindices > 0 && nvertices > 0 && nvertices <= ushort.MaxValue); bool hasSkinningData = skinningdata != null; #if ENABLE_DOTSRUNTIME_PROFILER ProfilerStats.AccumStats.memMeshCount.Accumulate(1); long bytes = nvertices * sizeof(LitVertex) + nindices * sizeof(ushort); if (hasSkinningData) { bytes += nvertices * sizeof(SkinnedMeshVertex); } ProfilerStats.AccumStats.memMesh.Accumulate(bytes); ProfilerStats.AccumStats.memReservedGFX.Accumulate(bytes); ProfilerStats.AccumStats.memUsedGFX.Accumulate(bytes); #endif if (hasSkinningData) { int litVertexSize = sizeof(LitVertex); int skinningVertexSize = sizeof(SkinnedMeshVertex); int totalVertexSize = litVertexSize + skinningVertexSize; byte *tmpBlock = (byte *)UnsafeUtility.Malloc(totalVertexSize * nvertices, 4, Allocator.Temp); UnsafeUtility.MemCpyStride(tmpBlock, totalVertexSize, vertices, litVertexSize, litVertexSize, nvertices); UnsafeUtility.MemCpyStride(tmpBlock + litVertexSize, totalVertexSize, skinningdata, skinningVertexSize, skinningVertexSize, nvertices); bgfx.Memory *bgfxMemory = RendererBGFXStatic.CreateMemoryBlock((byte *)tmpBlock, nvertices * totalVertexSize); UnsafeUtility.Free(tmpBlock, Allocator.Temp); return(new MeshBGFX { indexBufferHandle = bgfx.create_index_buffer(RendererBGFXStatic.CreateMemoryBlock((byte *)indices, nindices * 2), (ushort)bgfx.BufferFlags.None).idx, vertexBufferHandle = bgfx.create_vertex_buffer(bgfxMemory, &inst->m_litSkinnedVertexBufferDecl, (ushort)bgfx.BufferFlags.None).idx, indexCount = nindices, vertexCount = nvertices, maxIndexCount = nindices, maxVertexCount = nvertices, vertexLayoutHandle = inst->m_litSkinnedVertexBufferDeclHandle, isDynamic = false, vertexSize = totalVertexSize, }); } else { return(new MeshBGFX { indexCount = nindices, vertexCount = nvertices, maxIndexCount = nindices, maxVertexCount = nvertices, indexBufferHandle = bgfx.create_index_buffer(RendererBGFXStatic.CreateMemoryBlock((byte *)indices, nindices * 2), (ushort)bgfx.BufferFlags.None).idx, vertexLayoutHandle = inst->m_litVertexBufferDeclHandle, vertexBufferHandle = bgfx.create_vertex_buffer( RendererBGFXStatic.CreateMemoryBlock((byte *)vertices, nvertices * sizeof(LitVertex)), &inst->m_litVertexBufferDecl, (ushort)bgfx.BufferFlags.None).idx, isDynamic = false, vertexSize = sizeof(LitVertex), }); } }