Physijs object goes through concaveMesh

1.1k views Asked by At

I've a problem that seems to be known: my "bounding" object doesn't collide with "floor" concaveMesh.

I already read that this issue could be caused by an error in scaling concaveMesh together with the model, so I exported my floor model scaled as I need it and after I applied a concaveMesh (as follow) but it doesn't work.

I red this: https://github.com/chandlerprall/Physijs/issues/102 and a lot of other things about this topic (Physijs Load model three.js collisions don't work and a similar) and I made the following code but nothing to do :(

I really don't understand why "bounding" goes through the floor.

Here my code:

Physijs.scripts.worker = './libs/chandlerprall-Physijs-7e3837b/physijs_worker.js';
Physijs.scripts.ammo = './examples/js/ammo.js';
var gravityVector = new THREE.Vector3( 0, -100, 0 );
//renderer
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setClearColor(0xffffff, 0);
renderer.setSize( window.innerWidth, window.innerHeight );
//canvas
var canvas = renderer.domElement;
canvas.setAttribute("width",  window.innerWidth);
canvas.setAttribute("height",  window.innerHeight);
document.body.appendChild( canvas );
var perspectiveCamera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight, 1, 200000);
//scene
var rttScene = new Physijs.Scene();

var bounding = new Physijs.SphereMesh(new THREE.SphereGeometry(100, 100, 100),
    Physijs.createMaterial(
        new THREE.MeshBasicMaterial({color: '#ff0000'}),
        1.0, // friction
        0.0 // restitution
        ),50 //mass
    );

bounding.position.set(200,1200,-5000);

loader.load("http://0.0.0.0:8000/Models/Isola/pavimento.js", function( geometry, materials){
    var groundMaterial = Physijs.createMaterial(new THREE.MeshFaceMaterial(materials),
        0.8, // friction
        0.2 // restitution
            );
    floor = new Physijs.ConcaveMesh(geometry,groundMaterial,0);
    floor.name = "pavimento";
    rttScene.add(floor);
    initScene();
    render();
 });

function initScene() {
    rttScene.setGravity(gravityVector);
    rttScene.add(envModel);
    rttScene.add(bounding);
    bounding.setAngularFactor(new THREE.Vector3(0, 0, 0));
    bounding.setCcdMotionThreshold( 0.1 );
    bounding.setCcdSweptSphereRadius( 1 );

    var ambientLight =  new THREE.AmbientLight(0xD9B775 ); 
    rttScene.add(ambientLight);

    var directionalLight = new THREE.DirectionalLight(0xc7af81);
    directionalLight.target.position.copy( rttScene.position );
    directionalLight.position.set(-550,1950,1950).normalize(); 
    directionalLight.intensity = 0.7;
    rttScene.add(directionalLight);

    perspectiveCamera.position.set(200,1200,-3000);
    perspectiveCamera.lookAt(bounding.position);
}

function render() {
    requestAnimationFrame(render);
    renderer.clear();
    rttScene.simulate();

    renderer.render(rttScene, perspectiveCamera);
    }

I also tried this into render() function:

var originPoint = bounding.position.clone();
var ray = new THREE.Raycaster(originPoint, new THREE.Vector3(0, -1, 0));
var collisionResults = ray.intersectObjects(rttScene.children)
if (collisionResults.length > 0) {
    console.log(collisionResults[0].distance);
}

In console i can read the distance between "bounding" and "floor". This should mean that floor exist as a collider but it doesn't stop bounding from falling. Why?

0

There are 0 answers