| 36 | namespace |
| 37 | { |
| 38 | bool UpdateMesh(MeshBase* mesh, uint32 vertexCount, uint32 triangleCount, PixelFormat indexFormat, const Float3* vertices, const void* triangles, const Int4* blendIndices, const Float4* blendWeights, const Float3* normals, const Float3* tangents, const Float2* uvs, const Color32* colors) |
| 39 | { |
| 40 | auto model = mesh->GetModelBase(); |
| 41 | CHECK_RETURN(model && model->IsVirtual(), true); |
| 42 | CHECK_RETURN(triangles && vertices, true); |
| 43 | MeshAccessor accessor; |
| 44 | |
| 45 | // Index Buffer |
| 46 | { |
| 47 | if (accessor.AllocateBuffer(MeshBufferType::Index, triangleCount, indexFormat)) |
| 48 | return true; |
| 49 | auto indexStream = accessor.Index(); |
| 50 | ASSERT(indexStream.IsLinear(indexFormat)); |
| 51 | indexStream.SetLinear(triangles); |
| 52 | } |
| 53 | |
| 54 | // Vertex Buffer |
| 55 | { |
| 56 | GPUVertexLayout::Elements vb0elements; |
| 57 | vb0elements.Add({ VertexElement::Types::Position, 0, 0, 0, PixelFormat::R32G32B32_Float }); |
| 58 | if (normals) |
| 59 | { |
| 60 | vb0elements.Add({ VertexElement::Types::Normal, 0, 0, 0, PixelFormat::R10G10B10A2_UNorm }); |
| 61 | if (tangents) |
| 62 | vb0elements.Add({ VertexElement::Types::Tangent, 0, 0, 0, PixelFormat::R10G10B10A2_UNorm }); |
| 63 | } |
| 64 | vb0elements.Add({ VertexElement::Types::BlendIndices, 0, 0, 0, PixelFormat::R8G8B8A8_UInt }); |
| 65 | vb0elements.Add({ VertexElement::Types::BlendWeights, 0, 0, 0, PixelFormat::R8G8B8A8_UNorm }); |
| 66 | if (uvs) |
| 67 | vb0elements.Add({ VertexElement::Types::TexCoord, 0, 0, 0, PixelFormat::R16G16_Float }); |
| 68 | if (colors) |
| 69 | vb0elements.Add({ VertexElement::Types::Color, 0, 0, 0, PixelFormat::R8G8B8A8_UNorm }); |
| 70 | |
| 71 | GPUVertexLayout* vb0layout = GPUVertexLayout::Get(vb0elements); |
| 72 | if (accessor.AllocateBuffer(MeshBufferType::Vertex0, vertexCount, vb0layout)) |
| 73 | return true; |
| 74 | |
| 75 | auto positionStream = accessor.Position(); |
| 76 | ASSERT(positionStream.IsLinear(PixelFormat::R32G32B32_Float)); |
| 77 | positionStream.SetLinear(vertices); |
| 78 | if (normals) |
| 79 | { |
| 80 | auto normalStream = accessor.Normal(); |
| 81 | if (tangents) |
| 82 | { |
| 83 | auto tangentStream = accessor.Tangent(); |
| 84 | for (uint32 i = 0; i < vertexCount; i++) |
| 85 | { |
| 86 | const Float3 normal = normals[i]; |
| 87 | const Float3 tangent = tangents[i]; |
| 88 | Float3 n; |
| 89 | Float4 t; |
| 90 | RenderTools::CalculateTangentFrame(n, t, normal, tangent); |
| 91 | normalStream.SetFloat3(i, n); |
| 92 | tangentStream.SetFloat4(i, t); |
| 93 | } |
| 94 | } |
| 95 | else |
no test coverage detected