Below is the Marble Tower sample linked from the Babylon.js Feature Demos page.
Marble Tower ammo.js Demo
This sample uses ammo.js for physics.
I wanted to know if there was a Havok version of this, but I haven’t been able to find one.
Anyone know if there is a sample for the Havok version?
I tried to port from ammo.js to Havok following the rules below.
However, the attempt did not work because I could not figure out how to do some of the replacements.
I need to do more research on Havok and Physics API v2.
There is a shapetype for the convex hull.
and for the noimpostor, you can combine multiple shapes using the shape container.
also xxx.physicsImpostor ⇒ xxx.physicsAggregate no, but you can get the physicsBody from the mesh or transform
I have tried to figure out the gimmick of the rocker but it still seems to take a while. I will look into it again over the weekend.
I tried to port from HingeJoint to HingeConstraint but I still don’t understand what the difference is between the arguments.
Perhaps I need to look into the differences in functionality between the different versions.
Hi - im trying to migrate to havok - running into this same question. Using ammo, i had:
a) create a physicsroot mesh
b) created a collider (sphere or box)
c) added my mesh and the collider to the physicsroot
d) added the NoImpostor to the physicsroot.
Cedric, i’m not totally following your suggestion above. What would be the migration to the following code for the no-imposter part?
myCollider = BABYLON.CreateSphere("myCollider");
myCollider.physicsImpostor = new BABYLON.PhysicsAggregate(myCollider, BABYLON.PhysicsShapeType.SPHERE, {'mass': 0, 'friction': friction,'restitution': restitution}, this.scene);
let physicsRoot = new BABYLON.Mesh("physicsRoot_"+ myMesh.name, this.scene);
physicsRoot.addChild(myMesh);
physicsRoot.addChild(myCollider);
physicsRoot.physicsImpostor = new BABYLON.PhysicsImpostor(physicsRoot, BABYLON.PhysicsImpostor.NoImpostor, {'mass': mass, 'friction': friction,'restitution': restitution}, this.scene);
so the new approach is:
a) create a physics shape
b) bind that shape to the mesh *
so my new code is:
this._gravityCheckList.forEach(function(mesh_name) {
let mymesh = this.scene.getMeshByName(mesh_name);
this.addBody(mymesh);
}.bind(this));
//Add body
Enviro.prototype.addBody = function(mesh) {
const shape = new BABYLON.PhysicsShapeConvexHull(
mesh, // mesh from which to produce the convex hull
this.scene // scene of the shape
);
this.bindBodyShape(mesh, shape);
if (this.debug){
this.viewer = new BABYLON.Debug.PhysicsViewer(this.scene); //debug physics
this.viewer.showBody(mesh.physicsBody);
}
}
//bind body to shape
Enviro.prototype.bindBodyShape = function(mesh, shape) {
this.mlog.log('Enviro-bindBodyShape', {'mesh':mesh}, 6);
let physicsMaterial = { friction: 0.2, restitution: 0.3 };
var body = new BABYLON.PhysicsBody(
mesh,
BABYLON.PhysicsMotionType.DYNAMIC,
false,
this.scene
);
shape.material = physicsMaterial;
body.shape = shape;
body.setMassProperties({
mass: 1,
});
}
Just wanted to say that I really like your idea of reviving this historical demo and re-use it to introduce Havok.
I think the base of this demo deserves it and would do for a nice ‘remake’.
So, I’d like to thank you for your efforts and then,… just, let me know when it’s ready
Has anyone managed to create a working example of the Marble Tower with Havok Physics?
I am trying to do this myself but I cannot get the wheel animation to work when Physics in enabled. If you use the Inspector and disable Physics in this example, the animation works.
Does anyone know how to resolve this so the animation works when the wheel has a Physics Aggregate?
You notice that the wheel is trying to move but I think this is because gravity is being applied to it. If you increase the mass of the Wheel Aggregate and wait for the wheel to break away, it still doesn’t rotate so I don’t think gravity is the reason for the animation issue.
It’s not exactly the same as the animation, but I did get the wheel moving again by setting its motion type to ANIMATED and setting an angular velocity on it: Marble Tower with Havok Physics | Babylon.js Playground (babylonjs.com). However, for some reason this tanks the FPS hard… @eoin why would that be happening?
Thanks for this. However, I have I the same issue with the FPS but I did find if you dispose of the tower, supports and track it runs great. I am not sure why thought? Is collision causing any issues? See https://playground.babylonjs.com/#GJBMF9#2
It still doesn’t explain why the normal animation to make the wheel move doesn’t work though.
Hopefully, @Cedric and @eoin might be able to provide some assistance with this and also to help get the rocker to operate also.
I am learning both Babylon and Havok so any help with this would be appreciated.
So, a couple of things going on here; the reason the animation isn’t having an effect is because the wheel PhysicsBody with disablePreStep = true, so the transform from the animation isn’t being copied to the physics.
However, I’d recommend against setting transforms on static bodies like that, as it leads to artifacts - for example, if you look at the original marble tower, you can see the marbles penetrating the wheel and sometimes going through it. Making the wheel kinematic and animating it is definitely the right way to go.
Unfortunately, the reason for the FPS drop is that we end up doing a complicated mesh-mesh collision, looking for triangles with triggers - in Havok, it’s possible to have individual triangles with trigger shapes, but we haven’t exposed this in Babylon (it’s not really that useful, since it’s much better to make the whole mesh a trigger) and the underlying engine doesn’t know. We need to fix this bug, but until then, it’s best to just prevent the wheel from colliding with the rest of the terrain using a collision filter.
I’ve added that filter and finished up the remaining parts of that demo. What was left to do was make a CONTAINER shape for the rocker and add the individual meshes, then finish creating the constraint which attached the rocker to the tower.
Thanks so much. I will spend some time reviewing your changes as soon as I can. In the meantime, just a couple of observations. I noticed the marbles were running off the side of the tracks and so missing the wheel but having increased the friction on the marble aggregate, this has solved the issue. I also noticed that when the scene first loads and I move around, the wheel stalls and then starts again and then eventually runs normally. is that to be expected and if so, what is the reason for this?
That is not expected, no. The wheel body is going to sleep; it’s rotating quite slowly (~18 degrees / second) which is just on the boundary of our sleeping threshold. Can work around by making it spin a little faster, so on line 124, just increase the “0.1” to something larger:
wheelAggregate.body.setAngularVelocity(
new BABYLON.Vector3(Math.PI * 0.15,0,0)
);
Really, though, we should make animated bodies go to sleep only when they’re hardly moving at all. Will get a fix into the next plugin update.