MCPcopy Create free account
hub / github.com/carbonengine/trinity / SaveMeshToCMFFile

Method SaveMeshToCMFFile

trinity/Resources/TriGeometryRes.cpp:2504–2623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2502}
2503
2504bool TriGeometryRes::SaveMeshToCMFFile( TriGeometryResMeshData& mesh, const char* filename )
2505{
2506 USE_MAIN_THREAD_RENDER_CONTEXT();
2507
2508 if( mesh.m_vertexDeclarationHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION )
2509 {
2510 return false;
2511 }
2512
2513 auto& lod = mesh.m_lods[0];
2514
2515 if( !lod->m_allocationsValid )
2516 {
2517 return false;
2518 }
2519
2520 Tr2VertexDefinition decl;
2521 if( !Tr2EffectStateManager::GetVertexDeclarationElements( mesh.m_vertexDeclarationHandle, decl ) )
2522 {
2523 return false;
2524 }
2525
2526 cmf::MemoryAllocator allocator;
2527 cmf::BufferManager bufferAllocator( allocator );
2528 cmf::Span<cmf::VertexElement> cmfVertexDecl = allocator.AllocateSpan<cmf::VertexElement>( decl.m_items.size() );
2529
2530 if( !ConvertVertexDeclToCMF( decl, cmfVertexDecl, (uint32_t)cmfVertexDecl.size() ) )
2531 {
2532 return false;
2533 }
2534
2535 uint32_t vertexBufferSize = lod->m_vertexAllocation.GetSize();
2536 uint32_t vertexBufferStride = lod->m_vertexAllocation.GetStride();
2537 const void* pVertices;
2538 if( FAILED( lod->m_vertexAllocation.MapForReading( pVertices, renderContext ) ) )
2539 {
2540 return false;
2541 }
2542 ON_BLOCK_EXIT( [&] { lod->m_vertexAllocation.UnmapForReading( renderContext ); } );
2543
2544 uint32_t indexBufferSize = lod->m_indexAllocation.GetSize();
2545 uint32_t indexBufferStride = lod->m_indexAllocation.GetStride();
2546 const void* pIndices;
2547 if( FAILED( lod->m_indexAllocation.MapForReading( pIndices, renderContext ) ) )
2548 {
2549 return false;
2550 }
2551 ON_BLOCK_EXIT( [&] { lod->m_indexAllocation.UnmapForReading( renderContext ); } );
2552
2553
2554 cmf::Data cmfData;
2555 cmfData.meshes = allocator.AllocateSpan<cmf::Mesh>( 1 );
2556
2557 cmf::Mesh& cmfMesh = cmfData.meshes[0] = {};
2558 cmfMesh.name = allocator.AllocateString( mesh.m_name );
2559 cmfMesh.decl = cmfVertexDecl;
2560 cmfMesh.lods = allocator.AllocateSpan<cmf::MeshLod>( 1 );
2561 cmfMesh.areas = allocator.AllocateSpan<cmf::MeshArea>( lod->m_areas.size() );

Callers

nothing calls this directly

Calls 8

ConvertVertexDeclToCMFFunction · 0.85
fopen_sFunction · 0.85
sizeMethod · 0.80
AllocateStringMethod · 0.80
GetSizeMethod · 0.45
GetStrideMethod · 0.45
MapForReadingMethod · 0.45
UnmapForReadingMethod · 0.45

Tested by

no test coverage detected