chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.77k stars 455 forks source link

Physi.js not working properly with loaded .json files. #286

Open mkorunoski opened 8 years ago

mkorunoski commented 8 years ago

Hey guys. I am building a 3D virtual guidance system for an university project. I am using Three.js and Physi.js for that. However there is a slight problem. Whenever I load a 3D model to the scene and wrap it with Physi.js's ConcaveMesh (or whatever xMesh for that matter), the player is not colliding well with it. The player is a Physijs.SphereMesh with attached camera and is working perfectly. The collision with other Physijs.xMeshes is as expected but when it comes to loaded models, it's nasty. First of all, the collision happens at totally different place, changes the player orientation and a lot of other bad things happen. Here is a code snippet of the loading process:

jsonLoader.load('objects/crate/crate.json', function (geometry, mat)
{                       
    var material = new THREE.MeshBasicMaterial({color: 0x0000ff});
    material.wireframe = true;
    var mesh = new Physijs.BoxMesh(geometry, material, 0);
    mesh.castShadow = true;                             
    scene.add(mesh);
    objects.push(mesh);
}, 'objects/crate/');

The model is created, textured, positioned in Maya and exported with the supplied plugins. No problem with rendering. This model is simple, but as the work progresses I will be having a lot of complex buildings and interiors, for which proper collision will be a must. Any help is appreciated and thank you in advance.