The physics example showing ammo.js convex break, with file name physics_ammo_break.html
, demonstrates how to set a reference to a three.js object in ammo.js rigid body through setUserPointer()
and retrieved it later using getUserPointer()
. The implementation however sets the threejs object as a property of btVector3
with the btVector3
in turn passed to setUserPointer()
.
I understand why it is done like this (the whole emscripten binding stuff underlining ammo.js). However I noticed that directly setting the three.js object as a property of the ammo.js rigid body btRigidBody
without using setUserPointer()
also works and can be retrieve just as easy no need for getUserPointer()
.
We can change
var btVecUserData = new Ammo.btVector3( 0, 0, 0 );
btVecUserData.threeObject = object;
body.setUserPointer( btVecUserData );
located here in createDebrisFromBreakableObject()
to
body.threeObject = object;
and change
var threeObject0 = Ammo.castObject( rb0.getUserPointer(), Ammo.btVector3 ).threeObject;
var threeObject1 = Ammo.castObject( rb1.getUserPointer(), Ammo.btVector3 ).threeObject;
located here in updatePhysics()
to
var threeObject0 = rb0.threeObject;
var threeObject1 = rb1.threeObject;
This works based on the samples I’ve ran, though I will like to know if there is any potential issue with this change or is the earlier method more of a convention following how its done in bullet which is c++?
Has anyone observed this too?