Using export from clara.io with three.js and physijs

659 Views Asked by At

I have a scene I exported from clara.io, and I can import it in a three.js scene. I modified MateiralLoader and ObjectLoader to add textures loading, but I'm facing a problem, cause I'd like to replace the standard meshes by physical meshes. I tried changing THREE.Mesh in ObjectLoader.js by Physijs.BoxMesh (most of the scene consists in cubes).

The meshes actually display correctly, no error in console, but there's no physics attached to it, no collision. I thought maybe because the clara.io export are geometry and not just CubeGeometry, it might be a problem for physijs... I don't know, and I didn't find anything related. Could you maybe just give a direction for me to search? Thanks!

Here are samples of my code:

The script to export from clara.io, given on their website:

var loader = new THREE.ObjectLoader();
loader.load("zebra.json",function ( obj ) {
  scene.add( obj );
});

So I modified ObjectLoader from three.js: at line 287, in the case of loading a Mesh, i tried replacing this:

object = new THREE.Mesh( geometry, material );

By this:

object = new Physijs.BoxMesh( geometry, material );

And I also tried:

object = new Physijs.ConvexMesh( geometry, material );

Or:

object = new Physijs.ConcaveMesh( geometry, material );

I never gets physics (especially collisions) working, although the objects are well displayed in the scene. But collisions work well with for example a cube created directly from the script, using THREE.BoxGeometry, then using it with Physijs.BoxMesh.

2

There are 2 best solutions below

0
On BEST ANSWER

Actually, it turns out I was exporting the whole scene at first, from clara.io, and I was adding this scene into the scene I already had in my scripts. And in this case, the children displays but no physics, even if all scenes are Physijs scenes. If I add only the children of the imported scene, it kind of works, although now I have problems with positioning, but that's another topic.

0
On

It may be best to share a code example of the problem. Also for arbitrary mesh data, you can use Physijs.ConvexMesh.