Issue with Trigger Setup for .GLB model

I’m encountering an error while setting up a physics trigger for my model, without trigger setup code everything works fine when I add that I get this:

“TypeError: Cannot read properties of undefined (reading ‘setTrigger’)”. This occurs in the onSuccess callback of importMesh.

My code snippet is as follows:

(api.core/import-mesh "boss.glb" 
  (fn [new-meshes]
      (let [mesh (first new-meshes)
            shape (PhysicsShapeMesh. boss-mesh)
            tn (api.core/transform-node "boss-trigger")
            body (PhysicsBody. tn (j/get PhysicsMotionType :STATIC) false)]
        (j/assoc! shape :isTrigger true)
        (j/assoc! body :shape shape))))

CC @Cedric .
Could you reproduce that in the playground?

Could not repro the error, instead created PG that Trigger does not work for .GLB file. Check line 27 if block, change true/false. It works for else branch example.

PG: https://playground.babylonjs.com/#JUKXQD#5959

Using “MutantMesh” instead: https://playground.babylonjs.com/#JUKXQD#5960 console.logs show up.

But it is weird that the physics debugger does not show anything on the mutant :face_with_spiral_eyes:

Thanks that helped! One question, when using regular collision observable we get point attribute which indicates where in the world coordinate the collision happened (0, 1.2, 2.3), don’t we have the same for triggers?

@RaananW @Cedric Like @Joe_Kerr said I can not see wireframe when enabling physics debugger.

I’ve tried on too many different GLB models and could not apply physics body to them using (PhysicsShapeConvexHull, PhysicsShapeMesh).

PG: https://playground.babylonjs.com/#Z6SWJU#998

It is just a guess but maybe this is what throws off Havok. I would normalize (0 rotation, 1 scaling) the armature before exporting it to glb. Same for the Samba girl. There, too, is some weird scaling applied.

Could be, I created this PG: https://playground.babylonjs.com/#JUKXQD#5964, I can see the physics body but it is upside down.

Rotation and scaling did the trick! @Joe_Kerr here: https://playground.babylonjs.com/#JUKXQD#5967

It is the non-normlaized gltf root node: https://playground.babylonjs.com/#JUKXQD#5965

Baking will not work for rigged meshes though (afaik). I got it working by ensuring that, in Blender, the armature is normalized. Havok was fine with it then.

Can you double check? The model might be flipped now on x (I think). You need an asymmetrical model to check!

Yes model is flipped on x. You’re right I need asymmetrical model, thank you so much! I’ll experiment some stuff, if something is up, will update the thread.

1 Like

Maybe try scene.useRightHandedSystem = true so that the loaded glTF does not need a handedness conversion node?

1 Like