| 293 | } |
| 294 | |
| 295 | bool MeshAccessor::UpdateMesh(MeshBase* mesh, bool calculateBounds) |
| 296 | { |
| 297 | CHECK_RETURN(mesh, true); |
| 298 | constexpr int32 IB = (int32)MeshBufferType::Index; |
| 299 | constexpr int32 VB0 = (int32)MeshBufferType::Vertex0; |
| 300 | constexpr int32 VB1 = (int32)MeshBufferType::Vertex1; |
| 301 | constexpr int32 VB2 = (int32)MeshBufferType::Vertex2; |
| 302 | |
| 303 | uint32 vertices = 0, triangles = 0; |
| 304 | const void* ibData = nullptr; |
| 305 | bool use16BitIndexBuffer = false; |
| 306 | Array<const void*, FixedAllocation<3>> vbData; |
| 307 | Array<GPUVertexLayout*, FixedAllocation<3>> vbLayout; |
| 308 | vbData.Resize(3); |
| 309 | vbLayout.Resize(3); |
| 310 | vbData.SetAll(nullptr); |
| 311 | vbLayout.SetAll(nullptr); |
| 312 | if (_data[VB0].IsValid()) |
| 313 | { |
| 314 | vbData[0] = _data[VB0].Get(); |
| 315 | vbLayout[0] = _layouts[VB0]; |
| 316 | vertices = _data[VB0].Length() / _layouts[VB0]->GetStride(); |
| 317 | } |
| 318 | if (_data[VB1].IsValid()) |
| 319 | { |
| 320 | vbData[1] = _data[VB1].Get(); |
| 321 | vbLayout[1] = _layouts[VB1]; |
| 322 | vertices = _data[VB1].Length() / _layouts[VB1]->GetStride(); |
| 323 | } |
| 324 | if (_data[VB2].IsValid()) |
| 325 | { |
| 326 | vbData[2] = _data[VB2].Get(); |
| 327 | vbLayout[2] = _layouts[VB2]; |
| 328 | vertices = _data[VB2].Length() / _layouts[VB2]->GetStride(); |
| 329 | } |
| 330 | if (_data[IB].IsValid() && _formats[IB] != PixelFormat::Unknown) |
| 331 | { |
| 332 | ibData = _data[IB].Get(); |
| 333 | use16BitIndexBuffer = _formats[IB] == PixelFormat::R16_UInt; |
| 334 | triangles = _data[IB].Length() / PixelFormatExtensions::SizeInBytes(_formats[IB]) / 3; |
| 335 | } |
| 336 | |
| 337 | if (mesh->Init(vertices, triangles, vbData, ibData, use16BitIndexBuffer, vbLayout)) |
| 338 | return true; |
| 339 | |
| 340 | if (calculateBounds) |
| 341 | { |
| 342 | // Calculate mesh bounds |
| 343 | BoundingBox bounds; |
| 344 | auto positionStream = Position(); |
| 345 | CHECK_RETURN(positionStream.IsValid(), true); |
| 346 | if (positionStream.IsLinear(PixelFormat::R32G32B32_Float)) |
| 347 | { |
| 348 | Span<byte> positionData = positionStream.GetData(); |
| 349 | BoundingBox::FromPoints((const Float3*)positionData.Get(), positionData.Length() / sizeof(Float3), bounds); |
| 350 | } |
| 351 | else |
| 352 | { |
nothing calls this directly
no test coverage detected