Commits

Anonymous committed 06aba82

Added MeshColliderComponent
Fixed bugs

Comments (0)

Files changed (9)

PolyMain/PolyMain.vcxproj

     <ClInclude Include="include\game\PolyLevelFileSerializerImpl1.h" />
     <ClInclude Include="include\game\PolyLevelManager.h" />
     <ClInclude Include="include\game\PolyLightComponent.h" />
+    <ClInclude Include="include\game\PolyMeshColliderComponent.h" />
     <ClInclude Include="include\game\PolyMeshComponent.h" />
     <ClInclude Include="include\game\PolyBoxColliderComponent.h" />
     <ClInclude Include="include\game\PolyPhysicsComponent.h" />
     <ClCompile Include="include\game\PolyLevelFileSerializerImpl1.cpp" />
     <ClCompile Include="include\game\PolyLevelManager.cpp" />
     <ClCompile Include="include\game\PolyLightComponent.cpp" />
+    <ClCompile Include="include\game\PolyMeshColliderComponent.cpp" />
     <ClCompile Include="include\game\PolyMeshComponent.cpp" />
     <ClCompile Include="include\game\PolyPhysicsComponent.cpp" />
     <ClCompile Include="include\game\PolyPhysicsDynamicComponent.cpp" />

PolyMain/PolyMain.vcxproj.filters

     <ClInclude Include="include\game\PolyBoxColliderComponent.h">
       <Filter>game\phyics</Filter>
     </ClInclude>
+    <ClInclude Include="include\game\PolyMeshColliderComponent.h">
+      <Filter>game\phyics</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="include\PolyPrerequisites.cpp" />
     <ClCompile Include="include\game\PolyBoxColliderComponent.cpp">
       <Filter>game\phyics</Filter>
     </ClCompile>
+    <ClCompile Include="include\game\PolyMeshColliderComponent.cpp">
+      <Filter>game\phyics</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="audio">

PolyMain/include/game/PolyBoxColliderComponent.cpp

 namespace Poly {
 	POLY_COMPONENT_BASE_IMPL(BoxColliderComponent, "BoxCollider", "BoxCollider");
 
-	BoxColliderComponent::BoxColliderComponent() {
+	BoxColliderComponent::BoxColliderComponent()
+	:	mOffset(Vector3::ZERO) {
 		mProperties.addProperty("BoxCollider/Extends", &mExtends);
-		mProperties.addProperty("BoxCollider/Offset", &mOffset);
+		mProperties.addProperty("BoxCollider/Offset", &mOffset, true);
 	}
 
 	void BoxColliderComponent::_notifyOtherComponentAdded(Component* other) {
 		physx::PxTransform transform = PhysicsUtil::convert(mOffset, Quaternion::IDENTITY);
 
 		PhysicsComponent* physicsC = static_cast<PhysicsComponent*>(other);
+
+		if(physicsC->rigidActor->getScene())
+			gEnv.physics->removeRigidBodyFromScene(mEntity.getScene(), physicsC->rigidActor);
+
 		physicsC->rigidActor->createShape(physx::PxBoxGeometry(mExtends.x, mExtends.y, mExtends.z), *defaultMaterial, transform);
+		gEnv.physics->addRigidBodyToScene(mEntity.getScene(), physicsC->rigidActor);
 	}
 }

PolyMain/include/game/PolyMeshColliderComponent.cpp

+/*
+    Copyright (c) Oliver 'SirPolly' Weitzel
+                                                                                  
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+                                                                                  
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+                                                                                  
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE. 
+    
+*/
+
+#include "PolyPrerequisites.h"
+#include "render/PolyRenderUtil.h"
+#include "physics/PolyPhysicsSystem.h"
+#include "PolyPhysicsComponent.h"
+
+#include "PolyMeshColliderComponent.h"
+
+
+namespace Poly {
+	POLY_COMPONENT_BASE_IMPL(MeshColliderComponent, "MeshCollider", "MeshCollider");
+
+	MeshColliderComponent::MeshColliderComponent() 
+	:	mOffset(Vector3::ZERO) {
+		mProperties.addProperty("MeshCollider/MeshName", &mMeshName);
+		mProperties.addProperty("MeshCollider/Offset", &mOffset, true);
+	}
+
+	void MeshColliderComponent::_notifyOtherComponentAdded(Component* other) {
+		if(other->getFamilyName() != PhysicsComponent::GetFamilyName())
+			return;
+
+		// Cook mesh
+		Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().getByName(mMeshName);
+		if(mesh.isNull()) {
+			POLY_LOG_WARNING("MeshCollider: Mesh '" << mMeshName << "' not found!");
+			return;
+		}
+
+		RenderMeshInfo meshInfo;
+		RenderUtil::getMeshInfo(mesh, meshInfo);
+
+		PhysicsCookingParams params;
+		physx::PxTriangleMesh* triMesh = gEnv.physics->createTriangleMesh(meshInfo, params);
+
+		// Create shape
+		physx::PxMaterial* defaultMaterial = gEnv.physics->getDefaultMaterial();
+
+		physx::PxTransform transform = PhysicsUtil::convert(mOffset, Quaternion::IDENTITY);
+
+		PhysicsComponent* physicsC = static_cast<PhysicsComponent*>(other);
+
+		if(physicsC->rigidActor->getScene())
+			gEnv.physics->removeRigidBodyFromScene(mEntity.getScene(), physicsC->rigidActor);
+
+		physicsC->rigidActor->createShape(physx::PxTriangleMeshGeometry(triMesh), *defaultMaterial, transform);
+		gEnv.physics->addRigidBodyToScene(mEntity.getScene(), physicsC->rigidActor);
+	}
+}

PolyMain/include/game/PolyMeshColliderComponent.h

+/*
+    Copyright (c) Oliver 'SirPolly' Weitzel
+                                                                                  
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+                                                                                  
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+                                                                                  
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE. 
+    
+*/
+
+#ifndef PolyMeshColliderComponent_h
+#define PolyMeshColliderComponent_h
+
+#include "PolyComponent.h"
+
+
+namespace Poly {
+	class _PolyExport MeshColliderComponent : public Component {
+	public:
+		MeshColliderComponent();
+
+		virtual void _notifyOtherComponentAdded(Component* other);
+
+		POLY_COMPONENT_BASE;
+
+	protected:
+		String mMeshName;
+		Vector3 mOffset;
+	};
+}
+
+#endif

PolyMain/include/game/PolyPhysicsDynamicComponent.cpp

 
 		rigidActor = rigidDynamic = gEnv.physics->createDynamicRigidBody(Vector3::ZERO, Quaternion::IDENTITY, entity);
 		rigidDynamic->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, mKinematic);
-
-		gEnv.physics->addRigidBodyToScene(mEntity.getScene(), rigidDynamic);
 	}
 
 	void PhysicsDynamicComponent::setKinetic(bool val) {

PolyMain/include/game/PolyPhysicsStaticComponent.cpp

 		PhysicsComponent::initialize(entity, values);
 
 		rigidActor = rigidStatic = gEnv.physics->createStaticRigidBody(Vector3::ZERO, Quaternion::IDENTITY, entity);
-
-		gEnv.physics->addRigidBodyToScene(entity.getScene(), rigidStatic);
 	}
 }

PolyMain/include/physics/PolyPhysicsSystem.cpp

 #include "game/PolyEntityManager.h"
 #include "game/PolyComponentManager.h"
 #include "game/PolyBoxColliderComponent.h"
+#include "game/PolyMeshColliderComponent.h"
 #include "game/PolyPhysicsDynamicComponent.h"
 #include "game/PolyPhysicsStaticComponent.h"
 #include "game/PolyCharacterControllerComponent.h"
 		gEnv.engine->addListener(this);
 
 		gEnv.componentMgr->addComponentType<BoxColliderComponent>();
+		gEnv.componentMgr->addComponentType<MeshColliderComponent>();
 		gEnv.componentMgr->addComponentType<PhysicsDynamicComponent>();
 		gEnv.componentMgr->addComponentType<PhysicsStaticComponent>();
 		gEnv.componentMgr->addComponentType<CharacterControllerComponent>();
 - Add threading library / build thread pool ontop of boost
 - Implement bucket Entity and/or EntityLogic updates
 
-- More features for EntityLogics: filter by exact type, filter by multiple types
+- More features for EntityLogics: filter by exact type, filter by multiple types
+
+- REMOVE DEPENDENCIES WHICH ARE TOO BIG (most of boost)
+
+- Remove all remains of scripting