I’m learning too. It’s starting to make sense. Here’s a discussion of gravity vs. force that corroborates your view.
It also appears that setLinearVelocity may not be an equivalent alternative because it can’t apply to a specific point such as center of mass. So to your point, perhaps a generalized applied acceleration equivalent to gravity would be:
// can numInstances be zero?
// either way, handle it with low runtime cost
// It may be prudent to extract mass and CoM into an array of arrays to avoid repeated getMassProperties
// use remainder of gravity not handled by the engine.
// here, engine would be -0.01 so the remainder is -9.8
const num = mesh.physicsBody.numInstances;
if (num == 0) {
var mp = mesh.physicsBody.getMassProperties();
mesh.physicsBody.applyForce( -9.8*mp.mass, mp.centerOfMass)
} else for(var i = 0; i < num; i+=1) {
var mp = mesh.physicsBody.getMassProperties(i);
mesh.physicsBody.applyForce(-9.8*mp.mass, mp.centerOfMass,i)
}
Edit: if CoM is local space and force is world space, will need to convert CoM from local to world coordinates.
Edit2: updated code per first edit and use supplied instance iterate function:
mesh.physicsBody.iterateOverAllInstances((body,i) => {
const mp = body.getMassProperties(i);
body.applyForce(-9.8*mp.mass, body.getObjectCenterWorld(i),i)
});
Or shorten to:
mesh.physicsBody.iterateOverAllInstances((body,i) =>
body.applyForce(-9.8*body.getMassProperties(i).mass, body.getObjectCenterWorld(i),i));
For an array of meshes:
meshArray.forEach((mesh)=>
mesh.physicsBody.iterateOverAllInstances((body,i) =>
body.applyForce(-9.8*body.getMassProperties(i).mass, body.getObjectCenterWorld(i),i)
)
)