javascriptthree.jsphysijsobjloader

Adding Physics to OBJ Model in ThreeJS


I am trying to use PhysiJS with ThreeJS. I have an OBJ model that I exported from Blender. When I load it with OBJLoader, I see that it is a BufferGeometry. I also notice that it is missing a vertices property, which is what PhysiJS looks for.

My ThreeJS version is r101. I would appreciate any suggestions. If there is a more suitable library, I am open to that too. I am also happy to provide any clarifications.


Solution

  • If you need to convert your BufferGeometry to Geometry, you can simply use the .fromBufferGeometry() method.

    // Called when your obj finishes loading
    onLoadComplete(obj) {
        var geom = new THREE.Geometry();
        geom.fromBufferGeometry(obj);
    
        // Now you'll have access to vertices
        console.log(geom.vertices);
    }