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

Method GetBounds

trinity/Tr2MeshBase.cpp:249–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249CcpMath::AxisAlignedBox Tr2MeshBase::GetBounds( const Matrix* boneTransforms, const int32_t* meshBindingIndices, size_t boneCount, const Tr2MorphTargetAnimationData* morphTargets, size_t morphTargetsCount ) const
250{
251 if( boneTransforms )
252 {
253 if( auto geometry = GetGeometryResource() )
254 {
255 TriGeometryResMeshData* meshData = geometry->GetMeshData( m_meshIndex );
256 TriGeometryResLodData* lod = geometry->GetMeshLod( m_meshIndex, 0 );
257
258 if( !m_jointMappingAnimRig.empty() )
259 {
260 // for old character stuff
261 boneCount = m_jointMappingAnimRig.size();
262 meshBindingIndices = (const int32_t*)m_jointMappingAnimRig.data();
263 }
264
265 if( meshData && boneCount > 0 )
266 {
267 auto aabb = CcpMath::AxisAlignedBox();
268 for( size_t i = 0; i < boneCount; ++i )
269 {
270 auto& joint = meshData->m_jointBindings[i];
271 auto& m = boneTransforms[meshBindingIndices[i]];
272
273 Vector3 rightMin = m.GetX() * joint.m_obbMin.x;
274 Vector3 upMin = m.GetY() * joint.m_obbMin.y;
275 Vector3 forwardMin = m.GetZ() * joint.m_obbMin.z;
276 Vector3 rightMax = m.GetX() * joint.m_obbMax.x;
277 Vector3 upMax = m.GetY() * joint.m_obbMax.y;
278 Vector3 forwardMax = m.GetZ() * joint.m_obbMax.z;
279 Vector3 translation = m.GetTranslation();
280
281 Vector3 a;
282 a.x = min( rightMin.x, rightMax.x ) + min( upMin.x, upMax.x ) + min( forwardMin.x, forwardMax.x ) + translation.x;
283 a.y = min( rightMin.y, rightMax.y ) + min( upMin.y, upMax.y ) + min( forwardMin.y, forwardMax.y ) + translation.y;
284 a.z = min( rightMin.z, rightMax.z ) + min( upMin.z, upMax.z ) + min( forwardMin.z, forwardMax.z ) + translation.z;
285 aabb.IncludePoint( a );
286
287 Vector3 b;
288 b.x = max( rightMin.x, rightMax.x ) + max( upMin.x, upMax.x ) + max( forwardMin.x, forwardMax.x ) + translation.x;
289 b.y = max( rightMin.y, rightMax.y ) + max( upMin.y, upMax.y ) + max( forwardMin.y, forwardMax.y ) + translation.y;
290 b.z = max( rightMin.z, rightMax.z ) + max( upMin.z, upMax.z ) + max( forwardMin.z, forwardMax.z ) + translation.z;
291 aabb.IncludePoint( b );
292 }
293
294 float morphDeformation = 0.f;
295 for( size_t i = 0; i < morphTargetsCount; i++ )
296 {
297 auto morph = morphTargets[i];
298 CCP_ASSERT_M( morph.m_index < lod->m_morphTargetDeformationAmounts.size(), "Tr2MeshBase::GetBounds: morph.m_index is too large!" );
299 morphDeformation += lod->m_morphTargetDeformationAmounts[morph.m_index] * morph.m_weight;
300 }
301 aabb.Grow( morphDeformation );
302
303 return m_boundsAdjustment.AdjustBounds( aabb );
304 }
305 }
306 }

Callers 4

GetDynamicBoundingBoxMethod · 0.45
GetBatchesMethod · 0.45
GetBoundingBoxMethod · 0.45

Calls 10

GetMeshDataMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80
GetTranslationMethod · 0.80
GrowMethod · 0.80
AdjustBoundsMethod · 0.80
GetMeshLodMethod · 0.45
GetXMethod · 0.45
GetYMethod · 0.45
GetZMethod · 0.45

Tested by

no test coverage detected