MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / newMesh

Method newMesh

deps/physx/physx/samples/samplevehicle/SampleVehicle.cpp:428–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428void SampleVehicle::newMesh(const RAWMesh& data)
429{
430 if(LOAD_TYPE_LOOPTHELOOP==gLoadType)
431 {
432 PxMaterial* saved = mMaterial;
433 mMaterial = mStandardMaterials[SURFACE_TYPE_TARMAC];
434 PhysXSample::newMesh(data);
435 mMaterial = saved;
436 }
437 else if(LOAD_TYPE_VEHICLE==gLoadType)
438 {
439 PxU32 carPart=0xffffffff;
440 if(0==Ps::strcmp(data.mName,gCarPartNames[CAR_PART_CHASSIS]))
441 {
442 carPart=CAR_PART_CHASSIS;
443
444 //Find the min and max of the set of verts.
445 PxVec3 min(PX_MAX_F32,PX_MAX_F32,PX_MAX_F32);
446 PxVec3 max(-PX_MAX_F32,-PX_MAX_F32,-PX_MAX_F32);
447 for(PxU32 i=0;i<data.mNbVerts;i++)
448 {
449 min.x=PxMin(min.x,data.mVerts[i].x);
450 min.y=PxMin(min.y,data.mVerts[i].y);
451 min.z=PxMin(min.z,data.mVerts[i].z);
452 max.x=PxMax(max.x,data.mVerts[i].x);
453 max.y=PxMax(max.y,data.mVerts[i].y);
454 max.z=PxMax(max.z,data.mVerts[i].z);
455 }
456
457 //Make sure the chassis has an aabb that is centred at (0,0,0).
458 //This just makes it a lot easier to set the centre of mass offset relative to the centre of the actor.
459 gChassisMeshTransform=(min+max)*0.5f;
460
461 //Make sure wheel offsets are symmetric (they are not quite symmetric left to right or front to back).
462 gWheelCentreOffsets4[CAR_PART_FRONT_LEFT_WHEEL].x=-gWheelCentreOffsets4[CAR_PART_FRONT_RIGHT_WHEEL].x;
463 gWheelCentreOffsets4[CAR_PART_REAR_LEFT_WHEEL].x=-gWheelCentreOffsets4[CAR_PART_REAR_RIGHT_WHEEL].x;
464 gWheelCentreOffsets4[CAR_PART_FRONT_LEFT_WHEEL].y=gWheelCentreOffsets4[CAR_PART_REAR_LEFT_WHEEL].y;
465 gWheelCentreOffsets4[CAR_PART_FRONT_RIGHT_WHEEL].y=gWheelCentreOffsets4[CAR_PART_REAR_RIGHT_WHEEL].y;
466
467 //Make an adjustment so that the the centre of the four wheels is at the origin.
468 //Again, this just makes it a lot easier to set the centre of mass because we have a known point
469 //that represents the origin. Also, it kind of makes sense that the default centre of mass is at the
470 //centre point of the wheels.
471 PxF32 wheelOffsetZ=0;
472 for(PxU32 i=0;i<=CAR_PART_REAR_RIGHT_WHEEL;i++)
473 {
474 wheelOffsetZ+=gWheelCentreOffsets4[i].z;
475 }
476 wheelOffsetZ*=0.25f;
477 gChassisMeshTransform.z+=wheelOffsetZ;
478
479 //Reposition the mesh verts.
480 PxVec3* verts = const_cast<PxVec3*>(data.mVerts);
481 for(PxU32 i=0;i<data.mNbVerts;i++)
482 {
483 verts[i]-=gChassisMeshTransform;
484 }
485

Callers

nothing calls this directly

Calls 7

strcmpFunction · 0.85
PxMinFunction · 0.85
PxMaxFunction · 0.85
createChassisConvexMeshFunction · 0.85
createWheelConvexMeshFunction · 0.85
getTransformMethod · 0.80
reportErrorMethod · 0.45

Tested by

no test coverage detected