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

Method RecalculateBoundingSphere

trinity/Resources/TriGeometryRes.cpp:1366–1406  ·  view source on GitHub ↗

This entire function is sus. We should be able to compute this when we upload the mesh to the GPU, as it can never change unless the vertex data changes.

Source from the content-addressed store, hash-verified

1364
1365//This entire function is sus. We should be able to compute this when we upload the mesh to the GPU, as it can never change unless the vertex data changes.
1366void TriGeometryRes::RecalculateBoundingSphere()
1367{
1368 CCP_STATS_ZONE( __FUNCTION__ );
1369 USE_MAIN_THREAD_RENDER_CONTEXT();
1370
1371 for( auto& mesh : m_meshes )
1372 {
1373 //Try to get the vertex declaration elements
1374 Tr2VertexDefinition decl;
1375 if( mesh == nullptr || !Tr2EffectStateManager::GetVertexDeclarationElements( mesh->m_vertexDeclarationHandle, decl ) )
1376 {
1377 continue;
1378 }
1379
1380 uint32_t vertSize = mesh->m_bytesPerVertex;
1381
1382 //For now, we just compute the bounding sphere of the first LOD and ignore the lower LODs, assuming that they should fit in the highest quality LOD's bounding sphere.
1383 auto& lod = mesh->m_lods[0];
1384
1385
1386 //Get the vertex data of the
1387
1388 const uint8_t* pVertices;
1389 if( !lod->m_allocationsValid || FAILED( lod->m_vertexAllocation.MapForReading( pVertices, renderContext ) ) )
1390 {
1391 continue;
1392 }
1393 auto position = decl.Find( decl.POSITION, 0 );
1394
1395 // build a list of pointers to the positions
1396 std::vector<const Vector3*> points( lod->m_vertexCount );
1397 for( uint32_t p = 0; p < lod->m_vertexCount; ++p )
1398 {
1399 points[p] = (const Vector3*)&pVertices[p * vertSize + position->m_offset];
1400 }
1401
1402 // all is done in this recursive function
1403 BoundingSphereFromPoints( mesh->m_boundingSphere, &points[0], points.size() );
1404 lod->m_vertexAllocation.UnmapForReading( renderContext );
1405 }
1406}
1407
1408struct CalcBoundingBoxContext
1409{

Callers 4

RebuildCachedDataMethod · 0.80
RebuildBoundingSphereMethod · 0.80
RebuildCachedDataMethod · 0.80

Calls 5

BoundingSphereFromPointsFunction · 0.85
FindMethod · 0.80
sizeMethod · 0.80
MapForReadingMethod · 0.45
UnmapForReadingMethod · 0.45

Tested by

no test coverage detected