PxScene* NpPhysics::createScene(const PxSceneDesc& desc)
{
	PX_CHECK_AND_RETURN_NULL(desc.isValid(), "Physics::createScene: desc.isValid() is false!");

	const PxTolerancesScale& scale = mPhysics.getTolerancesScale();
	const PxTolerancesScale& descScale = desc.getTolerancesScale();
	PX_UNUSED(scale);
	PX_UNUSED(descScale);
	PX_CHECK_AND_RETURN_NULL((descScale.length == scale.length) && (descScale.mass == scale.mass) && (descScale.speed == scale.speed), "Physics::createScene: PxTolerancesScale must be the same as used for creation of PxPhysics!");

	Ps::Mutex::ScopedLock lock(mSceneAndMaterialMutex);  // done here because scene constructor accesses profiling manager of the SDK

	NpScene* npScene = PX_NEW (NpScene)(desc);
	if(!npScene)
	{
		Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "Unable to create scene.");
		return NULL;
	}
	if(!npScene->getTaskManager())
	{
		Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "Unable to create scene. Task manager creation failed.");
		return NULL;
	}

	npScene->loadFromDesc(desc);

#if PX_SUPPORT_PVD
	if(mPvd)
	{
		npScene->mScene.getScenePvdClient().setPsPvd(mPvd);		
		mPvd->addClient(&npScene->mScene.getScenePvdClient());
	}
#endif

	if (!sendMaterialTable(*npScene) || !npScene->getScene().isValid())
	{
		PX_DELETE(npScene);
		Ps::getFoundation().error(PxErrorCode::eOUT_OF_MEMORY, __FILE__, __LINE__, "Unable to create scene.");
		return NULL;
	}

	mSceneArray.pushBack(npScene);
	return npScene;
}
Exemple #2
0
PxScene* NpPhysics::createScene(const PxSceneDesc& desc)
{
	PX_CHECK_AND_RETURN_NULL(desc.isValid(), "Physics::createScene: desc.isValid() is false!");

	const PxTolerancesScale& scale = mPhysics.getTolerancesScale();
	const PxTolerancesScale& descScale = desc.getTolerancesScale();
	PX_UNUSED(scale);
	PX_UNUSED(descScale);
	PX_CHECK_AND_RETURN_NULL((descScale.length == scale.length) && (descScale.mass == scale.mass) && (descScale.speed == scale.speed), "Physics::createScene: PxTolerancesScale must be the same as used for creation of PxPhysics!");

	Ps::Mutex::ScopedLock lock(mSceneAndMaterialMutex);  // done here because scene constructor accesses profiling manager of the SDK

	NpScene* npScene = PX_NEW (NpScene)(desc);
	if(!npScene)
	{
		Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "Unable to create scene.");
		return NULL;
	}
	if(!npScene->getTaskManager())
	{
		Ps::getFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__, "Unable to create scene. Task manager creation failed.");
		return NULL;
	}

	npScene->loadFromDesc(desc);

#if PX_SUPPORT_VISUAL_DEBUGGER
	if(mVisualDebugger->isConnected(true))
	{
		mVisualDebugger->setupSceneConnection(npScene->getScene());
		npScene->getScene().getSceneVisualDebugger().sendEntireScene();
	}
#endif

#ifdef PX_PS3
	for(PxU32 i=0;i<CmPS3ConfigInternal::SCENE_PARAM_SPU_MAX;i++)
	{
		npScene->getScene().setSceneParamInt((PxPS3ConfigParam::Enum)i, g_iPhysXSPUCount);
	}

	const PxU32 numFrictionBlocks = desc.nbContactDataBlocks/8;
	const PxU32 numNpCacheBlocks = desc.nbContactDataBlocks/8;
	const PxU32 numContactStreamBlocks = desc.nbContactDataBlocks/16;
	const PxU32 numConstraintBlocks = desc.nbContactDataBlocks - (numFrictionBlocks + numContactStreamBlocks + numNpCacheBlocks);

	npScene->getScene().setSceneParamInt(PxPS3ConfigParam::eMEM_CONSTRAINT_BLOCKS, numConstraintBlocks);
	npScene->getScene().setSceneParamInt(PxPS3ConfigParam::eMEM_FRICTION_BLOCKS, numFrictionBlocks);
	npScene->getScene().setSceneParamInt(PxPS3ConfigParam::eMEM_CONTACT_STREAM_BLOCKS, numContactStreamBlocks);
	npScene->getScene().setSceneParamInt(PxPS3ConfigParam::eMEM_NP_CACHE_BLOCKS, numNpCacheBlocks);
#endif

	if (!sendMaterialTable(*npScene) || !npScene->getScene().isValid())
	{
		PX_DELETE(npScene);
		Ps::getFoundation().error(PxErrorCode::eOUT_OF_MEMORY, __FILE__, __LINE__, "Unable to create scene.");
		return NULL;
	}

	mSceneArray.pushBack(npScene);
	return npScene;
}