void Apex::Init(PxPhysics* physics, PxCooking* cooking, PxScene* scene) { mErrorCallback = ::new UserErrorCallback("ApexErrors.txt", "a",true, true); renderer = SampleRenderer::Renderer; m_renderResourceManager = new SampleApexRenderResourceManager(*renderer); NxApexSDKDesc apexDesc; NxApexCreateError errorCode; apexDesc.physXSDK = physics; apexDesc.cooking = cooking; apexDesc.outputStream = mErrorCallback; apexDesc.renderResourceManager = m_renderResourceManager; if(!apexDesc.isValid()) { return; } initialized = true; gApexSDK = NxCreateApexSDK(apexDesc, &errorCode); PX_ASSERT(gApexSDK); // Create the APEX scene NxApexSceneDesc apexSceneDesc; apexSceneDesc.scene = scene; if (!apexSceneDesc.isValid()) { return; } gApexScene = gApexSDK->createScene(apexSceneDesc); if (!gApexScene) { return; } }
bool Apex::Init(ID3D11Device* dev, ID3D11DeviceContext* devcon) { if(!InitPhysX()) return false; mDev = dev; mDevcon = devcon; // Init Apex static PxDefaultErrorCallback gDefaultErrorCallback; ZeusResourceCallback* rcallback = new ZeusResourceCallback(); NxApexSDKDesc apexDesc; apexDesc.outputStream = &gDefaultErrorCallback; apexDesc.resourceCallback = rcallback; apexDesc.physXSDK = mPhysics; apexDesc.cooking = mCooking; m_renderResourceManager = new ZeusRenderResourceManager(dev,devcon); apexDesc.renderResourceManager = m_renderResourceManager; if(apexDesc.isValid()) gApexSDK = NxCreateApexSDK(apexDesc); else return false; if(!gApexSDK) return false; // NxApexSceneDesc apexSceneDesc; // // Create the APEX scene... // // apexSceneDesc.scene = mScene[mCurrentScene]; // // if(apexSceneDesc.isValid()) // gApexScene[mCurrentScene] = gApexSDK->createScene(apexSceneDesc); // else // return false; // if(!gApexScene[mCurrentScene]) // return false; //gApexScene[mCurrentScene]->setLODResourceBudget(10000.f); //static const physx::PxU32 viewIDlookAtRightHand = gApexScene[mCurrentScene]->allocViewMatrix(physx::apex::ViewMatrixType::LOOK_AT_LH); //static const physx::PxU32 projIDperspectiveCubicRightHand = gApexScene[mCurrentScene]->allocProjMatrix(physx::apex::ProjMatrixType::USER_CUSTOMIZED); //gApexScene[mCurrentScene]->setUseViewProjMatrix(viewIDlookAtRightHand, projIDperspectiveCubicRightHand); return true; }
//////// GAME-LEVEL RIGID BODY PHYSICS STUFF /////// void InitGamePhys() { #if WITH_BOX2D FPhysicsIntegration2D::InitializePhysics(); #endif #if WITH_PHYSX // Do nothing if SDK already exists if(GPhysXFoundation != NULL) { return; } // Make sure LoadPhysXModules(); // Create Foundation GPhysXAllocator = new FPhysXAllocator(); FPhysXErrorCallback* ErrorCallback = new FPhysXErrorCallback(); GPhysXFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *GPhysXAllocator, *ErrorCallback); check(GPhysXFoundation); #if PHYSX_MEMORY_STATS // Want names of PhysX allocations GPhysXFoundation->setReportAllocationNames(true); #endif // Create profile manager GPhysXProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(GPhysXFoundation); check(GPhysXProfileZoneManager); // Create Physics PxTolerancesScale PScale; PScale.length = CVarToleranceScaleLength.GetValueOnGameThread(); PScale.mass = CVarTolerenceScaleMass.GetValueOnGameThread(); PScale.speed = CVarToleranceScaleSpeed.GetValueOnGameThread(); GPhysXSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *GPhysXFoundation, PScale, false, GPhysXProfileZoneManager); check(GPhysXSDK); GPhysCommandHandler = new FPhysCommandHandler(); FCoreUObjectDelegates::PreGarbageCollect.AddRaw(GPhysCommandHandler, &FPhysCommandHandler::Flush); // Init Extensions PxInitExtensions(*GPhysXSDK); #if WITH_VEHICLE PxInitVehicleSDK(*GPhysXSDK); #endif //Turn on PhysX 3.3 unified height field collision detection. //This approach shares the collision detection code between meshes and height fields such that height fields behave identically to the equivalent terrain created as a mesh. //This approach facilitates mixing the use of height fields and meshes in the application with no tangible difference in collision behavior between the two approaches PxRegisterUnifiedHeightFields(*GPhysXSDK); #if WITH_PHYSICS_COOKING || WITH_RUNTIME_PHYSICS_COOKING // Create Cooking PxCookingParams PCookingParams(PScale); PCookingParams.meshWeldTolerance = 0.1f; // Weld to 1mm precision PCookingParams.meshPreprocessParams = PxMeshPreprocessingFlags(PxMeshPreprocessingFlag::eWELD_VERTICES | PxMeshPreprocessingFlag::eREMOVE_UNREFERENCED_VERTICES | PxMeshPreprocessingFlag::eREMOVE_DUPLICATED_TRIANGLES); PCookingParams.targetPlatform = PxPlatform::ePC; //PCookingParams.meshCookingHint = PxMeshCookingHint::eCOOKING_PERFORMANCE; //PCookingParams.meshSizePerformanceTradeOff = 0.0f; GPhysXCooking = PxCreateCooking(PX_PHYSICS_VERSION, *GPhysXFoundation, PCookingParams); check(GPhysXCooking); #endif #if WITH_APEX // Build the descriptor for the APEX SDK NxApexSDKDesc ApexDesc; ApexDesc.physXSDK = GPhysXSDK; // Pointer to the PhysXSDK ApexDesc.cooking = GPhysXCooking; // Pointer to the cooking library ApexDesc.renderResourceManager = &GApexNullRenderResourceManager; // We will not be using the APEX rendering API, so just use a dummy render resource manager ApexDesc.resourceCallback = &GApexResourceCallback; // The resource callback is how APEX asks the application to find assets when it needs them // Create the APEX SDK NxApexCreateError ErrorCode; GApexSDK = NxCreateApexSDK(ApexDesc, &ErrorCode); check(ErrorCode == APEX_CE_NO_ERROR); check(GApexSDK); #if APEX_STATICALLY_LINKED // We need to instantiate the module if we have statically linked them // Otherwise all createModule functions will fail instantiateModuleDestructible(); #if WITH_APEX_CLOTHING instantiateModuleClothing(); #endif #if WITH_APEX_LEGACY instantiateModuleLegacy(); #endif #endif // 1 legacy module for all in APEX 1.3 // Load the only 1 legacy module #if WITH_APEX_LEGACY GApexModuleLegacy = GApexSDK->createModule("Legacy"); check(GApexModuleLegacy); #endif // WITH_APEX_LEGACY // Load APEX Destruction module GApexModuleDestructible = static_cast<NxModuleDestructible*>(GApexSDK->createModule("Destructible")); check(GApexModuleDestructible); // Set Destructible module parameters NxParameterized::Interface* ModuleParams = GApexModuleDestructible->getDefaultModuleDesc(); // ModuleParams contains the default module descriptor, which may be modified here before calling the module init function GApexModuleDestructible->init(*ModuleParams); // Disabling dynamic LOD GApexModuleDestructible->setLODEnabled(false); // Set chunk report for fracture effect callbacks GApexModuleDestructible->setChunkReport(&GApexChunkReport); GApexModuleDestructible->setMaxDynamicChunkIslandCount((physx::PxU32)FMath::Max(CVarAPEXMaxDestructibleDynamicChunkIslandCount.GetValueOnGameThread(), 0)); GApexModuleDestructible->setMaxChunkCount((physx::PxU32)FMath::Max(CVarAPEXMaxDestructibleDynamicChunkCount.GetValueOnGameThread(), 0)); GApexModuleDestructible->setSortByBenefit(CVarAPEXSortDynamicChunksByBenefit.GetValueOnGameThread() != 0); GApexModuleDestructible->setChunkReportSendChunkStateEvents(true); // APEX 1.3 to preserve 1.2 behavior GApexModuleDestructible->setUseLegacyDamageRadiusSpread(true); GApexModuleDestructible->setUseLegacyChunkBoundsTesting(true); #if WITH_APEX_CLOTHING // Load APEX Clothing module GApexModuleClothing = static_cast<NxModuleClothing*>(GApexSDK->createModule("Clothing")); check(GApexModuleClothing); // Set Clothing module parameters ModuleParams = GApexModuleClothing->getDefaultModuleDesc(); // Can be tuned for switching between more memory and more spikes. NxParameterized::setParamU32(*ModuleParams, "maxUnusedPhysXResources", 5); // If true, let fetch results tasks run longer than the fetchResults call. // Setting to true could not ensure same finish timing with Physx simulation phase NxParameterized::setParamBool(*ModuleParams, "asyncFetchResults", false); // ModuleParams contains the default module descriptor, which may be modified here before calling the module init function GApexModuleClothing->init(*ModuleParams); #endif //WITH_APEX_CLOTHING #endif // #if WITH_APEX #endif // WITH_PHYSX }