2

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.

Daniel Hong
  • 93
  • 1
  • 7

1 Answers1

2

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);
}
M -
  • 26,908
  • 11
  • 49
  • 81
  • `geom` is in the format that I like. But when I pass it into `Physijs.ConcaveMesh`, I get a script error. Is it because `THREE.Geometry` is an abstract class? – Daniel Hong Feb 22 '19 at 00:43
  • I'm not sure what parameters Physijs is expecting, but sounds like you should be passing a `Mesh`, not a geometry. Something like `var mesh = new THREE.Mesh(geom, mat); Physijs.ConcaveMesh(mesh);`, maybe? Have you looked at the source code in their examples? – M - Feb 22 '19 at 00:54
  • Source code snippet: `Physijs.ConcaveMesh = function( geometry, material, mass ) { ... }` . If `THREE.Geometry` is not abstract, I can figure out the rest. – Daniel Hong Feb 22 '19 at 01:00
  • I found out what's wrong. I accidentally mistook one of my test geometries for material. Your code works after all :) . Thank you so much! – Daniel Hong Feb 22 '19 at 05:05