MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DownloadBuffer

Method DownloadBuffer

Source/Engine/Graphics/Models/Mesh.cpp:455–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453};
454
455MArray* Mesh::DownloadBuffer(bool forceGpu, MTypeObject* resultType, int32 typeI)
456{
457 // [Deprecated in v1.10]
458 ScopeLock lock(GetModelBase()->Locker);
459
460 // Get vertex buffers data from the mesh (CPU or GPU)
461 MeshAccessor accessor;
462 MeshBufferType bufferTypes[1] = { MeshBufferType::Vertex0 };
463 switch ((InternalBufferType)typeI)
464 {
465 case InternalBufferType::VB1:
466 bufferTypes[0] = MeshBufferType::Vertex1;
467 break;
468 case InternalBufferType::VB2:
469 bufferTypes[0] = MeshBufferType::Vertex2;
470 break;
471 }
472 if (accessor.LoadMesh(this, forceGpu, ToSpan(bufferTypes, 1)))
473 return nullptr;
474 auto positionStream = accessor.Position();
475 auto texCoordStream = accessor.TexCoord();
476 auto lightmapUVsStream = accessor.TexCoord(1);
477 auto normalStream = accessor.Normal();
478 auto tangentStream = accessor.Tangent();
479 auto colorStream = accessor.Color();
480 auto count = GetVertexCount();
481
482 // Convert into managed array
483 MArray* result = MCore::Array::New(MCore::Type::GetClass(INTERNAL_TYPE_OBJECT_GET(resultType)), count);
484 void* managedArrayPtr = MCore::Array::GetAddress(result);
485 switch ((InternalBufferType)typeI)
486 {
487PRAGMA_DISABLE_DEPRECATION_WARNINGS
488 case InternalBufferType::VB0:
489 CHECK_RETURN(positionStream.IsValid(), nullptr);
490 for (int32 i = 0; i < count; i++)
491 {
492 auto& dst = ((VB0ElementType*)managedArrayPtr)[i];
493 dst.Position = positionStream.GetFloat3(i);
494 }
495 break;
496 case InternalBufferType::VB1:
497 for (int32 i = 0; i < count; i++)
498 {
499 auto& dst = ((VB1ElementType*)managedArrayPtr)[i];
500 if (texCoordStream.IsValid())
501 dst.TexCoord = texCoordStream.GetFloat2(i);
502 if (normalStream.IsValid())
503 dst.Normal = normalStream.GetFloat3(i);
504 if (tangentStream.IsValid())
505 dst.Tangent = tangentStream.GetFloat4(i);
506 if (lightmapUVsStream.IsValid())
507 dst.LightmapUVs = lightmapUVsStream.GetFloat2(i);
508 }
509 break;
510 case InternalBufferType::VB2:
511 if (colorStream.IsValid())
512 {

Callers

nothing calls this directly

Calls 15

GetModelBaseFunction · 0.85
GetAddressFunction · 0.85
PositionMethod · 0.80
TexCoordMethod · 0.80
NormalMethod · 0.80
TangentMethod · 0.80
GetVertexCountFunction · 0.70
ToSpanFunction · 0.50
NewFunction · 0.50
GetClassFunction · 0.50
Color32Class · 0.50
LoadMeshMethod · 0.45

Tested by

no test coverage detected