diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-05-11 21:58:23 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-05-11 21:58:23 +0400 |
commit | ede20c166a4fcaedaaf5c5392d00e3a99ecc8ad2 (patch) | |
tree | d3aa15cd27cffd73bb970ea58c898ddc56c21532 | |
parent | d3dd1da8d429ea72ad42afe4b34692c345ef8c78 (diff) |
- Charlie provided a work-around for some armature related crashes
- fixed some Bullet raycasting (hitfraction was not properly updated for static meshes)
- removed some cvs tags in Bullet's BMF _Font files (they keep on conflicting when duplicated in different repositories)
- set default linearsleepingtreshold explicitly
13 files changed, 110 insertions, 40 deletions
diff --git a/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.cpp b/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.cpp index 812ffa391dd..4775db1b1c1 100644 --- a/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.cpp +++ b/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.cpp @@ -258,19 +258,20 @@ void CollisionWorld::RayTest(const SimdVector3& rayFromWorld, const SimdVector3& } - virtual void ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) + virtual float ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) { - LocalShapeInfo shapeInfo; + CollisionWorld::LocalShapeInfo shapeInfo; shapeInfo.m_shapePart = partId; shapeInfo.m_triangleIndex = triangleIndex; - LocalRayResult rayResult + CollisionWorld::LocalRayResult rayResult (m_collisionObject, &shapeInfo, hitNormalLocal, hitFraction); - m_resultCallback->AddSingleResult(rayResult); + return m_resultCallback->AddSingleResult(rayResult); + } @@ -294,4 +295,4 @@ void CollisionWorld::RayTest(const SimdVector3& rayFromWorld, const SimdVector3& } } -}
\ No newline at end of file +} diff --git a/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.h b/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.h index 22e82082c65..1d1249ec88e 100644 --- a/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.h +++ b/extern/bullet/Bullet/CollisionDispatch/CollisionWorld.h @@ -94,6 +94,9 @@ public: ///RayResultCallback is used to report new raycast results struct RayResultCallback { + virtual ~RayResultCallback() + { + } float m_closestHitFraction; bool HasHit() { diff --git a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp index 36764ac3191..7032a863a54 100644 --- a/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp +++ b/extern/bullet/Bullet/CollisionDispatch/ConvexConcaveCollisionAlgorithm.cpp @@ -194,8 +194,10 @@ float ConvexConcaveCollisionAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* ,B { } - virtual void ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) + virtual float ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) { + //todo: handle ccd here + return 0.f; } }; diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.cpp index fc4a533b225..209d9612bfd 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.cpp +++ b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.cpp @@ -87,11 +87,11 @@ void TriangleRaycastCallback::ProcessTriangle(SimdVector3* triangle,int partId, if ( dist_a > 0 ) { - ReportHit(triangleNormal,distance,partId,triangleIndex); + m_hitFraction = ReportHit(triangleNormal,distance,partId,triangleIndex); } else { - ReportHit(-triangleNormal,distance,partId,triangleIndex); + m_hitFraction = ReportHit(-triangleNormal,distance,partId,triangleIndex); } } } diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h index c58fa202fc8..463c576c57e 100644 --- a/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h +++ b/extern/bullet/Bullet/NarrowPhaseCollision/RaycastCallback.h @@ -34,7 +34,7 @@ public: virtual void ProcessTriangle(SimdVector3* triangle, int partId, int triangleIndex); - virtual void ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) = 0; + virtual float ReportHit(const SimdVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex ) = 0; }; diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp index b8ce09729c2..043d5be802e 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsController.cpp @@ -31,7 +31,7 @@ class BP_Proxy; float gDeactivationTime = 2.f; bool gDisableDeactivation = false; -float gLinearSleepingTreshold = 0.4f; +float gLinearSleepingTreshold = 0.8f; float gAngularSleepingTreshold = 1.0f; #include "Dynamics/MassProps.h" diff --git a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index 7afd7bf8fc5..cb4adc77d76 100644 --- a/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/extern/bullet/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -1529,7 +1529,9 @@ void CcdPhysicsEnvironment::UpdateAabbs(float timeStep) shapeinterface->CalculateTemporalAabb(body->getCenterOfMassTransform(), - body->getLinearVelocity(),body->getAngularVelocity(), + body->getLinearVelocity(), + //body->getAngularVelocity(), + SimdVector3(0.f,0.f,0.f),//no angular effect for now //body->getAngularVelocity(), timeStep,minAabb,maxAabb); diff --git a/source/blender/src/usiblender.c b/source/blender/src/usiblender.c index 8bfa493364a..ccc32c33a6e 100644 --- a/source/blender/src/usiblender.c +++ b/source/blender/src/usiblender.c @@ -397,6 +397,7 @@ int BIF_read_homefile(void) } else { success = BKE_read_file_from_memory(datatoc_B_blend, datatoc_B_blend_size, NULL); } + BLI_clean(scestr); strcpy(G.sce, scestr); diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h index af0212d77a8..aafc8271dd6 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.h +++ b/source/gameengine/Converter/BL_ArmatureObject.h @@ -77,6 +77,7 @@ public: /// Returns the bone length. The end of the bone is in the local y direction. float GetBoneLength(Bone* bone) const; + virtual int GetGameObjectType() { return OBJ_ARMATURE; } protected: Object *m_objArma; struct bArmature *m_armature; diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index bc2352d713e..20498167021 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -300,6 +300,9 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, { CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(); ccdPhysEnv->setDebugDrawer(new BlenderDebugDraw()); + ccdPhysEnv->setDeactivationLinearTreshold(0.8f); // default, can be overridden by Python + ccdPhysEnv->setDeactivationAngularTreshold(1.0f); // default, can be overridden by Python + //todo: get a button in blender ? //disable / enable debug drawing (contact points, aabb's etc) //ccdPhysEnv->setDebugMode(1); diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index f57201ba59d..aed1d87b929 100644 --- a/source/gameengine/GameLogic/SCA_IObject.h +++ b/source/gameengine/GameLogic/SCA_IObject.h @@ -116,7 +116,13 @@ public: // here come the python forwarded methods virtual PyObject* _getattr(const STR_String& attr); + + virtual int GetGameObjectType() {return -1;} + typedef enum ObjectTypes { + OBJ_ARMATURE=0 + }ObjectTypes; + }; #endif //SCA_IOBJECT_H diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 1f37f07902e..bdeffd79a60 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -732,43 +732,92 @@ void KX_Scene::NewRemoveObject(class CValue* gameobj) void KX_Scene::ReplaceMesh(class CValue* gameobj,void* meshobj) { - KX_GameObject* newobj = (KX_GameObject*) gameobj; - RAS_MeshObject* mesh = (RAS_MeshObject*) meshobj; + KX_GameObject* newobj = static_cast<KX_GameObject*>(gameobj); + RAS_MeshObject* mesh = static_cast<RAS_MeshObject*>(meshobj); + + const STR_String origMeshName = newobj->GetMesh(0)->GetName(); + + if( !newobj || !mesh ) + { + std::cout << "warning: invalid object, mesh will not be replaced" << std::endl; + return; + } newobj->RemoveMeshes(); newobj->AddMesh(mesh); - if (newobj->m_isDeformable && mesh->m_class == 1) { - Object* blendobj = (struct Object*)m_logicmgr->FindBlendObjByGameObj(newobj); - Object* oldblendobj = (struct Object*)m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName()); - - if (blendobj->parent && blendobj->parent->type == OB_ARMATURE && - blendobj->partype==PARSKEL && - ((Mesh*)blendobj->data)->dvert) + bool isDeformer = (newobj->m_isDeformable && mesh->m_class == 1); + if(isDeformer) + { + /* FindBlendObjByGameObj() can return 0... + In the case of 0 here, + the replicated object that is calling this function + is some how not in the map. (which is strange because it's added) + So we will search the map by the first mesh name + to try to locate it there. If its still not found + spit some message rather than crash + */ + Object* blendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameObj(newobj)); + Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName())); + + bool parSkin = blendobj && blendobj->parent && blendobj->parent->type == OB_ARMATURE && blendobj->partype==PARSKEL; + bool releaseParent = true; + KX_GameObject* parentobj = newobj->GetParent(); + + + // lookup by mesh name if blendobj is 0 + if( !blendobj && parentobj ) { - // FIXME: should the old m_pDeformer be deleted? - // it shouldn't be a problem to delete it now. - // if we are constructing this on the fly like here, - // make sure to release newobj->GetParent(), and things will run shipshape - delete static_cast<BL_DeformableGameObject*>( newobj )->m_pDeformer; - - BL_SkinDeformer* skindeformer = new BL_SkinDeformer( - oldblendobj, blendobj, - static_cast<BL_SkinMeshObject*>(mesh), - true, // release ref count to BL_ArmatureObject, leak otherwise - static_cast<BL_ArmatureObject*>(newobj->GetParent()) - ); - static_cast<BL_DeformableGameObject*>( newobj )->m_pDeformer = skindeformer; + blendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(origMeshName)); + + // replace the mesh on the parent armature + if( blendobj ) + parSkin = parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE; + + // can't do it + else + std::cout << "warning: child object for " << parentobj->GetName().ReadPtr() + << " not found, and can't create!" << std::endl; } - else if (((Mesh*)blendobj->data)->dvert) { - BL_MeshDeformer* meshdeformer = new BL_MeshDeformer(oldblendobj, (BL_SkinMeshObject*)mesh ); - // FIXME: should the old m_pDeformer be deleted? - // delete ((BL_DeformableGameObject*)newobj)->m_pDeformer - ((BL_DeformableGameObject*)newobj)->m_pDeformer = meshdeformer; + if( blendobj && oldblendobj ) + { + isDeformer = (static_cast<Mesh*>(blendobj->data)->dvert != 0); + BL_DeformableGameObject* deformIter =0; + + // armature parent + if( parSkin && isDeformer ) + { + deformIter = static_cast<BL_DeformableGameObject*>( newobj ); + delete deformIter->m_pDeformer; + + BL_SkinDeformer* skinDeformer = new BL_SkinDeformer( + oldblendobj, blendobj, + static_cast<BL_SkinMeshObject*>(mesh), + true, + static_cast<BL_ArmatureObject*>( parentobj ) + ); + releaseParent= false; + deformIter->m_pDeformer = skinDeformer; + } + + // normal deformer + if( !parSkin && isDeformer) + { + deformIter = static_cast<BL_DeformableGameObject*>( newobj ); + delete deformIter->m_pDeformer; + + BL_MeshDeformer* meshdeformer = new BL_MeshDeformer( + oldblendobj, static_cast<BL_SkinMeshObject*>(mesh) + ); + + deformIter->m_pDeformer = meshdeformer; + } } + // release parent reference if its not being used + if( releaseParent && parentobj) + parentobj->Release(); } - newobj->Bucketize(); } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 7afd7bf8fc5..cb4adc77d76 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -1529,7 +1529,9 @@ void CcdPhysicsEnvironment::UpdateAabbs(float timeStep) shapeinterface->CalculateTemporalAabb(body->getCenterOfMassTransform(), - body->getLinearVelocity(),body->getAngularVelocity(), + body->getLinearVelocity(), + //body->getAngularVelocity(), + SimdVector3(0.f,0.f,0.f),//no angular effect for now //body->getAngularVelocity(), timeStep,minAabb,maxAabb); |