int CScriptBind_Physics::RegisterExplosionCrack(IFunctionHandler *pH,const char *sGeometryFile,int nIdMaterial )
{
	IStatObj *pObj = gEnv->p3DEngine->LoadStatObj( sGeometryFile,"#ForceBreakable",NULL,false);
	if (!pObj || pObj->IsDefaultObject())
	{
		ScriptWarning( "<RegisterExplosionCrack> Object file %s not found",sGeometryFile );
		return pH->EndFunction();
	}
	pObj->AddRef();
	Vec3 vtx[3] = { pObj->GetHelperPos("1"),pObj->GetHelperPos("2"),pObj->GetHelperPos("3") };
	//@TODO: restore it.
	m_pPhysicalWorld->GetGeomManager()->RegisterCrack( pObj->GetPhysGeom()->pGeom,vtx,0 );
	return pH->EndFunction();
}
int CScriptBind_Physics::RegisterExplosionShape(IFunctionHandler *pH,const char *sGeometryFile,float fSize,int nIdMaterial,float fProbability,
																								const char *sSplintersFile, float fSplintersOffset, const char *sSplintersCloudEffect)
{
	//////////////////////////////////////////////////////////////////////////
	// Remove all this.
	//////////////////////////////////////////////////////////////////////////
	IStatObj *pObj = gEnv->p3DEngine->LoadStatObj( sGeometryFile,"#ForceBreakable",NULL,false );
	if (!pObj || pObj->IsDefaultObject())
	{
		ScriptWarning( "<RegisterExplosionShape> Object file %s not found",sGeometryFile );
		return pH->EndFunction();
	}
	pObj->AddRef();
	pObj->GetIndexedMesh(true); // prepare idxMesh now 

	if(sSplintersFile && *sSplintersFile!=0)			// if sSplintersFile was specified
	{
		IStatObj *pSplinters = gEnv->p3DEngine->LoadStatObj(sSplintersFile,NULL,NULL,false);
		if (pSplinters)
		{
			pObj->SetSubObjectCount(pObj->GetSubObjectCount()+1);
			IStatObj::SSubObject *pSubObj = pObj->GetSubObject(pObj->GetSubObjectCount()-1);
			pSubObj->nType = STATIC_SUB_OBJECT_MESH;
			pSubObj->bHidden = true;
			pSubObj->name = "splinters";
			(pSubObj->pStatObj = pSplinters)->AddRef();
			pSubObj->helperSize.x = fSplintersOffset;
			nIdMaterial |= 1<<16;

			if (*sSplintersCloudEffect)
			{
				pSplinters->SetSubObjectCount(pSplinters->GetSubObjectCount()+1);
				pSplinters->SetFlags(pSplinters->GetFlags() & ~STATIC_OBJECT_COMPOUND);
				pSubObj = pSplinters->GetSubObject(pSplinters->GetSubObjectCount()-1);
				pSubObj->nType = STATIC_SUB_OBJECT_DUMMY;
				pSubObj->bHidden = true;
				pSubObj->name = "splinters_cloud";
				pSubObj->properties = sSplintersCloudEffect;
			}
		}
	}

	phys_geometry *pPhysGeom = pObj->GetPhysGeom();
	if (pPhysGeom)
	{
		m_pPhysicalWorld->AddExplosionShape( pPhysGeom->pGeom,fSize,nIdMaterial,fProbability );
	}
	return pH->EndFunction();
}
//------------------------------------------------------------------------
bool CVehicleDamageBehaviorDetachPart::MovePartToTheNewEntity(IEntity* pTargetEntity, CVehiclePartBase* pPartBase)
{
	if (!pPartBase)
		return false;

	IEntity* pVehicleEntity = m_pVehicle->GetEntity();
	CRY_ASSERT(pVehicleEntity);

	assert(m_detachedEntityId == pTargetEntity->GetId());

	IStatObj	*pStatObj =  pPartBase->GetStatObj();
	if(pStatObj)
	{
		pStatObj->AddRef();
	}
	m_detachedStatObjs.push_back(TPartObjectPair(pPartBase, pStatObj));

	// place the geometry on the new entity
	int slot = pTargetEntity->SetStatObj(pStatObj, -1, true, pPartBase->GetMass());

	const Matrix34& partTM = pPartBase->GetWorldTM();
	Matrix34 localTM = pTargetEntity->GetWorldTM().GetInverted() * partTM;
	pTargetEntity->SetSlotLocalTM(slot, localTM);

	pPartBase->SetStatObj(NULL);

	TVehiclePartVector& parts = m_pVehicle->GetParts();

	const CVehiclePartBase::TVehicleChildParts& children = pPartBase->GetChildParts();
	for (CVehiclePartBase::TVehicleChildParts::const_iterator ite = children.begin(), end = children.end(); ite != end; ++ite)
	{
		MovePartToTheNewEntity(pTargetEntity, (*ite));
	}

	return true;
}