Open TheMaverickProgrammer opened 11 years ago
I ended up creating an invisible mesh and the simulation runs now. However, I would still like to learn how to use the system to apply proper physics on a model based on shape. Any future advice would be welcome.
At the moment it is difficult to create a Physijs mesh with the obj loader, as the loader returns the mesh and not an object / material set. You could ignore the returned mesh and create a new Physijs one from its geometry and material(s).
That was what I really wanted to do, but how would I go about doing that?
You should be able to reuse the mesh's geometry
and material
properties when creating the Physijs mesh.
Everyone here's talking about creating an invisible mesh. Ideally I wouldn't have a mesh for graphics to begin with but maybe this is unavoidable. One way that works is to set physMaterial.visible = false
, where physMaterial
is from physMaterial = Physijs.createMaterial(...)
. Actually I believe visible
is inherited from the threejs material. Is this the best way?
On a related note, parenting is a nice way to keep your graphics mesh attached to your physics mesh...
var threeGeom = ...
var threeMaterial = ...
var threeObject = new THREE.Mesh(threeGeom, threeMaterial);
var physGeom = new THREE.CylinderGeometry(0.5, 0.5, 2.0);
var physMaterial = new Physijs.createMaterial(new THREE.MeshBasicMaterial({}), friction, restitution);
physMaterial.visible = false;
var physObject = new Physijs.CapsuleMesh(physGeom, physMaterial, mass);
//parents the complex graphics model to the simple collision geometry
physObject.add(threeObject);
//apply any offset transform between the graphics model and physics object
threeObject.position.y = -1.0;
//add the phys/three hierarchy to the scene
scene.add(physObject);
I'm very new to THREEjs and Physijs but so far it's been a blast to set everything up appropriately. However, I am struggling to apply physics to a custom model.
I'm using the ObjMTLLoader here: https://dl.dropboxusercontent.com/u/1333628/Code/obj_mtl_loader.js
But changes I made from THREE.Mesh to Physi.ConvexMesh are not working. My models suspend in mid-air. I read an issue where the programmer used an invisible box mesh over a graphical object to simulated physics and I'll go down this route if I absolutely have to but I would rather use the mesh given to my by the model.
https://dl.dropboxusercontent.com/u/1333628/Code/screenshot.png