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

Method CreatePrimitiveFromCMF

trinity/Tr2GrannyPrimitiveSet.cpp:256–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void Tr2GrannyPrimitiveSet::CreatePrimitiveFromCMF()
257{
258 if( !m_grannyRes )
259 {
260 return;
261 }
262
263 const cmf::Data* cmfData = m_grannyRes->GetCMFData();
264
265 if( !cmfData )
266 {
267 CCP_LOGERR( "Tr2GrannyLineSet::CreatePrimitive: '%s' not found or not a valid CMF file", m_grannyResPath.c_str() );
268 return;
269 }
270
271 uint32_t numVertices = 0;
272 uint32_t numIndices = 0;
273 std::vector<int32_t> meshIndices;
274 int32_t pickingIndex = -1;
275
276 // Sorting the meshes so the picking mesh is processed last
277 for( int32_t meshIx = 0; meshIx < cmfData->meshes.size(); meshIx++ )
278 {
279 auto mesh = cmfData->meshes[meshIx];
280
281 uint32_t meshIndexCount = cmf::GetStreamElementCount( mesh.lods[0].ib );
282 uint32_t meshTriangleCount = meshIndexCount / 3;
283
284 if( cmf::ToStdStringView( mesh.name ) == g_pickingMeshName )
285 {
286 m_pickingPrimitiveCount = meshTriangleCount;
287 pickingIndex = meshIx;
288 }
289 else
290 {
291 meshIndices.push_back( meshIx );
292 numIndices += meshIndexCount;
293 }
294 }
295
296 if( pickingIndex > -1 )
297 {
298 m_pickingIndexOffset = numIndices;
299 meshIndices.push_back( pickingIndex );
300 }
301
302 for( int32_t meshIx = 0; meshIx < cmfData->meshes.size(); meshIx++ )
303 {
304 auto mesh = cmfData->meshes[meshIndices[meshIx]];
305
306 uint32_t meshIndexCount = cmf::GetStreamElementCount( mesh.lods[0].ib );
307 uint32_t meshVertexCount = cmf::GetStreamElementCount( mesh.lods[0].vb );
308 uint32_t meshTriangleCount = meshIndexCount / 3;
309 m_primitiveCount += meshTriangleCount;
310
311 m_points.reserve( m_points.size() + meshVertexCount );
312 m_triangleIndices.reserve( m_triangleIndices.size() + meshIndexCount );
313 m_lineIndices.reserve( ( m_triangleIndices.size() + meshIndexCount ) * 2 );

Callers

nothing calls this directly

Calls 6

ReadCmfVertexAttributesFunction · 0.85
sizeMethod · 0.80
GetCMFViewDataMethod · 0.80
GetSectionMethod · 0.80
Vector3Class · 0.70
GetCMFDataMethod · 0.45

Tested by

no test coverage detected