Ejemplo n.º 1
0
void NpArticulation::release()
{
	NP_WRITE_CHECK(getOwnerScene());

	NpPhysics::getInstance().notifyDeletionListenersUserRelease(this, userData);

	//!!!AL TODO: Order should not matter in this case. Optimize by having a path which does not restrict release to leaf links or
	//      by using a more advanced data structure
	PxU32 idx = 0;
	while(mArticulationLinks.size())
	{
		idx = idx % mArticulationLinks.size();

		if (mArticulationLinks[idx]->getNbChildren() == 0)
		{
			mArticulationLinks[idx]->releaseInternal();  // deletes joint, link and removes link from list
		}
		else
		{
			idx++;
		}
	}

	NpScene* npScene = getAPIScene();
	if(npScene)
	{
		npScene->getScene().removeArticulation(getArticulation());

		npScene->removeFromArticulationList(*this);
	}

	mArticulationLinks.clear();

	mArticulation.destroy();
}
Ejemplo n.º 2
0
void VisualDebugger::sendEntireSDK()
{
	NpPhysics& npPhysics = NpPhysics::getInstance();
	mPvdConnection->createInstance( (PxPhysics*)&npPhysics );
	npPhysics.getPvdConnectionManager()->setIsTopLevelUIElement( &npPhysics, true );
	mMetaDataBinding.sendAllProperties( *mPvdConnection, npPhysics );

#define SEND_BUFFER_GROUP( type, name ) {					\
		Ps::Array<type*> buffers;							\
		PxU32 numBuffers = npPhysics.getNb##name();			\
		buffers.resize(numBuffers);							\
		npPhysics.get##name(buffers.begin(), numBuffers);	\
		for(PxU32 i = 0; i < numBuffers; i++)				\
			increaseReference(buffers[i]);					\
	}

	SEND_BUFFER_GROUP( PxMaterial, Materials );
	SEND_BUFFER_GROUP( PxTriangleMesh, TriangleMeshes );
	SEND_BUFFER_GROUP( PxConvexMesh, ConvexMeshes );
	SEND_BUFFER_GROUP( PxHeightField, HeightFields );

#if PX_USE_CLOTH_API
	SEND_BUFFER_GROUP( PxClothFabric, ClothFabrics );
#endif

	mPvdConnection->flush();
	PxU32 numScenes = npPhysics.getNbScenes();
	for(PxU32 i = 0; i < numScenes; i++)
	{
		NpScene* npScene = npPhysics.getScene(i);
		Scb::Scene& scbScene = npScene->getScene();

		scbScene.getSceneVisualDebugger().sendEntireScene();
	}
}
Ejemplo n.º 3
0
void NpConstraint::setConstraintFunctions(PxConstraintConnector& n, const PxConstraintShaderTable& shaders)
{
	mConstraint.getScConstraint().setConstraintFunctions(n, shaders);
	
	//update mConnectorArray, since mActor0 or mActor1 should be in external reference
	bool bNeedUpdate = false;
	if(mActor0)
	{
		NpActor& npActor = NpActor::getFromPxActor(*mActor0);
		if(npActor.findConnector(NpConnectorType::eConstraint, this) == 0xffffffff)
		{
			bNeedUpdate = true;	
			npActor.addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 0: Constraint already added");
		}
	}

	if(mActor1)
	{
		NpActor& npActor = NpActor::getFromPxActor(*mActor1);
		if(npActor.findConnector(NpConnectorType::eConstraint, this) == 0xffffffff)
		{
			bNeedUpdate = true;	
			npActor.addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 1: Constraint already added");
		}
	}

	if(bNeedUpdate)
	{
		NpScene* newScene = getSceneFromActors(mActor0, mActor1);
		NpScene* oldScene = getNpScene();

		if (oldScene != newScene)
		{
			if (oldScene)
			{
				oldScene->removeFromConstraintList(*this);
				oldScene->getScene().removeConstraint(getScbConstraint());
			}
			if (newScene)
			{
				newScene->addToConstraintList(*this);
				newScene->getScene().addConstraint(getScbConstraint());
			}
		}
	}
}
Ejemplo n.º 4
0
void NpConstraint::setActors(PxRigidActor* actor0, PxRigidActor* actor1)
{
	NP_WRITE_CHECK(getNpScene());

	PX_CHECK_AND_RETURN((actor0 && !actor0->is<PxRigidStatic>()) || (actor1 && !actor1->is<PxRigidStatic>()), "PxConstraint: at least one actor must be non-static");
	PX_SIMD_GUARD;

	if(mActor0)
		NpActor::getFromPxActor(*mActor0).removeConnector(*mActor0, NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 0: Constraint already added");
	if(mActor1)
		NpActor::getFromPxActor(*mActor1).removeConnector(*mActor1, NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 1: Constraint already added");

	if(actor0)
		NpActor::getFromPxActor(*actor0).addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 0: Constraint already added");
	if(actor1)
		NpActor::getFromPxActor(*actor1).addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 1: Constraint already added");

	mActor0 = actor0;
	mActor1 = actor1;

	NpScene* newScene = getSceneFromActors(actor0, actor1);
	NpScene* oldScene = getNpScene();

	if (oldScene != newScene)
	{
		if (oldScene)
		{
			oldScene->removeFromConstraintList(*this);
			oldScene->getScene().removeConstraint(getScbConstraint());
		}

		getScbConstraint().setBodies(getScbRigidObject(actor0), getScbRigidObject(actor1));

		if (newScene)
		{
			newScene->addToConstraintList(*this);
			newScene->getScene().addConstraint(getScbConstraint());
		}
	}
	else
		getScbConstraint().setBodies(getScbRigidObject(actor0), getScbRigidObject(actor1));
}
Ejemplo n.º 5
0
void VisualDebugger::updateScenesPvdConnection()
{
	NpPhysics& npPhysics = NpPhysics::getInstance();
	PxU32 numScenes = npPhysics.getNbScenes();
	for(PxU32 i = 0; i < numScenes; i++)
	{
		NpScene* npScene = npPhysics.getScene(i);
		Scb::Scene& scbScene = npScene->getScene();
		setupSceneConnection(scbScene);
	}
}
Ejemplo n.º 6
0
void VisualDebugger::updateScenesPvdConnection()
{
	NpPhysics& npPhysics = NpPhysics::getInstance();
	PxU32 numScenes = npPhysics.getNbScenes();
	for(PxU32 i = 0; i < numScenes; i++)
	{
		NpScene* npScene = npPhysics.getScene(i);
		Scb::Scene& scbScene = npScene->getScene();
		setupSceneConnection(scbScene);
		npScene->getSingleSqCollector().clearGeometryArrays();
		npScene->getBatchedSqCollector().clearGeometryArrays();
	}
}
Ejemplo n.º 7
0
void VisualDebugger::setCreateContactReports(bool value)
{
	if ( isConnected() )
	{
		NpPhysics& npPhysics = NpPhysics::getInstance();
		PxU32 numScenes = npPhysics.getNbScenes();
		for(PxU32 i = 0; i < numScenes; i++)
		{
			NpScene* npScene = npPhysics.getScene(i);
			Scb::Scene& scbScene = npScene->getScene();
			scbScene.getSceneVisualDebugger().setCreateContactReports(value);
		}
	}
}
Ejemplo n.º 8
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_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;
}
Ejemplo n.º 9
0
void NpConstraint::release()
{
	NpScene* npScene = getNpScene();
	NP_WRITE_CHECK(npScene);

	NpPhysics::getInstance().notifyDeletionListenersUserRelease(this, NULL);

	if(mActor0)
		NpActor::getFromPxActor(*mActor0).removeConnector(*mActor0, NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 0: Constraint already added");
	if(mActor1)
		NpActor::getFromPxActor(*mActor1).removeConnector(*mActor1, NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 1: Constraint already added");

	if (npScene)
	{
		npScene->removeFromConstraintList(*this);
		npScene->getScene().removeConstraint(getScbConstraint());
	}

	mConstraint.destroy();
}
void NpArticulationLink::releaseInternal()
{
	NpPhysics::getInstance().notifyDeletionListenersUserRelease(this, userData);

	NpArticulationLinkT::release();

	mRoot->removeLinkFromList(*this);

	if (mParent)
		mParent->removeFromChildList(*this);

	if (mInboundJoint)
		mInboundJoint->release();

	NpScene* npScene = NpActor::getAPIScene(*this);
	if (npScene)
		npScene->getScene().removeActor(mBody, true, false);

	mBody.destroy();
}
Ejemplo n.º 11
0
void VisualDebugger::sendEntireSDK()
{
	PVD::PvdCommLayerError error;
	error = mPvdConnection->beginFrame();
	
	NpPhysics& npPhysics = NpPhysics::getInstance();
	error = mPvdConnection->createInstance(PvdClassKeys::PhysicsSDK+1, PX_PROFILE_POINTER_TO_U64(&npPhysics), PVD::EInstanceUIFlags::TopLevel);
	mMetaDataBinding.sendAllProperties( mPvdConnection, &npPhysics );
	createGroups();

#define SEND_BUFFER_GROUP( type, name ) {					\
		Ps::Array<type*> buffers;							\
		PxU32 numBuffers = npPhysics.getNb##name();			\
		buffers.resize(numBuffers);							\
		npPhysics.get##name(buffers.begin(), numBuffers);	\
		for(PxU32 i = 0; i < numBuffers; i++)				\
			increaseReference(buffers[i]);					\
	}
	SEND_BUFFER_GROUP( PxTriangleMesh, TriangleMeshes );
	SEND_BUFFER_GROUP( PxConvexMesh, ConvexMeshes );
	SEND_BUFFER_GROUP( PxHeightField, HeightFields );
	SEND_BUFFER_GROUP( PxHeightField, HeightFields );


	
	//Ensure that all the instances and class descriptions created so far
	//are available to the rest of the system.
	error = mPvdConnection->flush();

	PxU32 numScenes = npPhysics.getNbScenes();
	for(PxU32 i = 0; i < numScenes; i++)
	{
		NpScene* npScene = npPhysics.getScene(i);
		Scb::Scene& scbScene = npScene->getScene();

		scbScene.getSceneVisualDebugger().sendEntireScene();
	}

	error = mPvdConnection->endFrame();
	error = mPvdConnection->flush();
}
Ejemplo n.º 12
0
NpConstraint::NpConstraint(PxRigidActor* actor0, PxRigidActor* actor1, PxConstraintConnector& connector, const PxConstraintShaderTable& shaders, PxU32 dataSize)
:	PxConstraint(PxConcreteType::eCONSTRAINT, PxBaseFlag::eOWNS_MEMORY)
,	mActor0		(actor0)
,	mActor1		(actor1)
,	mConstraint	(connector, shaders, dataSize)
,	mIsDirty	(true)
{
	
	mConstraint.setFlags(shaders.flag);
	if(actor0)
		NpActor::getFromPxActor(*actor0).addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 0: Constraint already added");
	if(actor1)
		NpActor::getFromPxActor(*actor1).addConnector(NpConnectorType::eConstraint, this, "PxConstraint: Add to rigid actor 1: Constraint already added");

	NpScene* s = getSceneFromActors(actor0, actor1);
	if (s)
	{
		s->addToConstraintList(*this);
		s->getScene().addConstraint(mConstraint);
	}
}
Ejemplo n.º 13
0
void VisualDebugger::setVisualDebuggerFlag(PxVisualDebuggerFlags::Enum flag, bool value)
{
	if(value)
		mFlags |= PxU32(flag);
	else
		mFlags &= ~PxU32(flag);
	//This has been a bug against the debugger for some time,
	//changing this flag doesn't always change the sending-contact-reports behavior.
	if ( flag == PxVisualDebuggerFlags::eTRANSMIT_CONTACTS )
	{
		if ( isConnected() )
		{
			NpPhysics& npPhysics = NpPhysics::getInstance();
			PxU32 numScenes = npPhysics.getNbScenes();
			for(PxU32 i = 0; i < numScenes; i++)
			{
				NpScene* npScene = npPhysics.getScene(i);
				Scb::Scene& scbScene = npScene->getScene();
				scbScene.getSceneVisualDebugger().setCreateContactReports(value);
			}
		}
	}
}
Ejemplo n.º 14
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;
}