Fixing trimesh precision
This commit is contained in:
parent
9b446f1cc3
commit
88967e4001
8 changed files with 23 additions and 4 deletions
|
@ -35,8 +35,6 @@
|
|||
@author AndreaCatania
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define bulletnew(cl) \
|
||||
new cl
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ void CollisionObjectBullet::setupBulletCollisionObject(btCollisionObject *p_coll
|
|||
bt_collision_object->setUserIndex(type);
|
||||
// Force the enabling of collision and avoid problems
|
||||
set_collision_enabled(collisionsEnabled);
|
||||
p_collisionObject->setCollisionFlags(p_collisionObject->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
}
|
||||
|
||||
void CollisionObjectBullet::add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) {
|
||||
|
|
|
@ -34,11 +34,19 @@
|
|||
#include "bullet_types_converter.h"
|
||||
#include "collision_object_bullet.h"
|
||||
#include "rigid_body_bullet.h"
|
||||
#include <BulletCollision/CollisionDispatch/btInternalEdgeUtility.h>
|
||||
|
||||
/**
|
||||
@author AndreaCatania
|
||||
*/
|
||||
|
||||
bool godotContactAddedCallback(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) {
|
||||
if (!colObj1Wrap->getCollisionObject()->getCollisionShape()->isCompound()) {
|
||||
btAdjustInternalEdgeContacts(cp, colObj1Wrap, colObj0Wrap, partId1, index1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GodotFilterCallback::test_collision_filters(uint32_t body0_collision_layer, uint32_t body0_collision_mask, uint32_t body1_collision_layer, uint32_t body1_collision_mask) {
|
||||
return body0_collision_layer & body1_collision_mask || body1_collision_layer & body0_collision_mask;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
|
||||
class RigidBodyBullet;
|
||||
|
||||
/// This callback is injected inside bullet server and allow me to smooth contacts against trimesh
|
||||
bool godotContactAddedCallback(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1);
|
||||
|
||||
/// This class is required to implement custom collision behaviour in the broadphase
|
||||
struct GodotFilterCallback : public btOverlapFilterCallback {
|
||||
static bool test_collision_filters(uint32_t body0_collision_layer, uint32_t body0_collision_mask, uint32_t body1_collision_layer, uint32_t body1_collision_mask);
|
||||
|
|
|
@ -321,7 +321,8 @@ void RigidBodyBullet::main_shape_resetted() {
|
|||
void RigidBodyBullet::reload_body() {
|
||||
if (space) {
|
||||
space->remove_rigid_body(this);
|
||||
space->add_rigid_body(this);
|
||||
if (get_main_shape())
|
||||
space->add_rigid_body(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "bullet_utilities.h"
|
||||
#include "shape_owner_bullet.h"
|
||||
|
||||
#include <BulletCollision/CollisionDispatch/btInternalEdgeUtility.h>
|
||||
#include <BulletCollision/CollisionShapes/btConvexPointCloudShape.h>
|
||||
#include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
|
||||
#include <btBulletCollisionCommon.h>
|
||||
|
@ -358,7 +359,8 @@ ConcavePolygonShapeBullet::ConcavePolygonShapeBullet() :
|
|||
ConcavePolygonShapeBullet::~ConcavePolygonShapeBullet() {
|
||||
if (meshShape) {
|
||||
delete meshShape->getMeshInterface();
|
||||
delete meshShape;
|
||||
delete meshShape->getTriangleInfoMap();
|
||||
bulletdelete(meshShape);
|
||||
}
|
||||
faces = PoolVector<Vector3>();
|
||||
}
|
||||
|
@ -380,6 +382,7 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) {
|
|||
if (meshShape) {
|
||||
/// Clear previous created shape
|
||||
delete meshShape->getMeshInterface();
|
||||
delete meshShape->getTriangleInfoMap();
|
||||
bulletdelete(meshShape);
|
||||
}
|
||||
int src_face_count = faces.size();
|
||||
|
@ -407,6 +410,8 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) {
|
|||
const bool useQuantizedAabbCompression = true;
|
||||
|
||||
meshShape = bulletnew(btBvhTriangleMeshShape(shapeInterface, useQuantizedAabbCompression));
|
||||
btTriangleInfoMap *triangleInfoMap = new btTriangleInfoMap();
|
||||
btGenerateInternalEdgeInfo(meshShape, triangleInfoMap);
|
||||
} else {
|
||||
meshShape = NULL;
|
||||
ERR_PRINT("The faces count are 0, the mesh shape cannot be created");
|
||||
|
|
|
@ -597,6 +597,7 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) {
|
|||
godotFilterCallback = bulletnew(GodotFilterCallback);
|
||||
gCalculateCombinedRestitutionCallback = &calculateGodotCombinedRestitution;
|
||||
gCalculateCombinedFrictionCallback = &calculateGodotCombinedFriction;
|
||||
gContactAddedCallback = &godotContactAddedCallback;
|
||||
|
||||
dynamicsWorld->setWorldUserInfo(this);
|
||||
|
||||
|
|
|
@ -65,6 +65,8 @@ class SpaceBullet;
|
|||
class SoftBodyBullet;
|
||||
class btGjkEpaPenetrationDepthSolver;
|
||||
|
||||
extern ContactAddedCallback gContactAddedCallback;
|
||||
|
||||
class BulletPhysicsDirectSpaceState : public PhysicsDirectSpaceState {
|
||||
GDCLASS(BulletPhysicsDirectSpaceState, PhysicsDirectSpaceState)
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue