MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / buildPhysicsRep

Method buildPhysicsRep

Engine/source/forest/forestCell.cpp:432–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432void ForestCell::buildPhysicsRep( Forest *forest )
433{
434 AssertFatal( isLeaf(), "ForestCell::buildPhysicsRep() - This shouldn't be called on non-leaf cells!" );
435
436 bool isServer = forest->isServerObject();
437
438 // Already has a PhysicsBody, if it needed to be rebuilt it would
439 // already be null.
440 if ( mPhysicsRep[ isServer ] )
441 return;
442
443 if ( !PHYSICSMGR )
444 return;
445
446 PhysicsCollision *colShape = NULL;
447
448 // If we can steal the collision shape from the server-side cell
449 // then do so as it saves us alot of cpu time and memory.
450 if ( mPhysicsRep[ 1 ] )
451 {
452 colShape = mPhysicsRep[ 1 ]->getColShape();
453 }
454 else
455 {
456 // We must pass a sphere to buildPolyList but it is not used.
457 const static SphereF dummySphere( Point3F::Zero, 0 );
458
459 // Step thru them and build collision data.
460 ForestItemVector::iterator itemItr = mItems.begin();
461 ConcretePolyList polyList;
462 for ( ; itemItr != mItems.end(); itemItr++ )
463 {
464 const ForestItem &item = *itemItr;
465 const ForestItemData *itemData = item.getData();
466
467 // If not collidable don't need to build anything.
468 if ( !itemData->mCollidable )
469 continue;
470
471 // TODO: When we add breakable tree support this is where
472 // we would need to store their collision data seperately.
473
474 item.buildPolyList( &polyList, item.getWorldBox(), dummySphere );
475
476 // TODO: Need to support multiple collision shapes
477 // for really big forests at some point in the future.
478 }
479
480 if ( !polyList.isEmpty() )
481 {
482 colShape = PHYSICSMGR->createCollision();
483 if ( !colShape->addTriangleMesh( polyList.mVertexList.address(),
484 polyList.mVertexList.size(),
485 polyList.mIndexList.address(),
486 polyList.mIndexList.size() / 3,
487 MatrixF::Identity ) )
488 {
489 SAFE_DELETE( colShape );

Callers 1

updateCollisionMethod · 0.45

Calls 15

isServerObjectMethod · 0.80
getColShapeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getDataMethod · 0.45
buildPolyListMethod · 0.45
getWorldBoxMethod · 0.45
isEmptyMethod · 0.45
createCollisionMethod · 0.45
addTriangleMeshMethod · 0.45
addressMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected