Collision detection on Gizmo Manager

Say, I have a ‘3D space’ within an Axis Aligned Bounding Box that should not be exceeded. I’m using a Gizmo Manager to move my mesh, but I don’t want my mesh to go outside that bound.

I managed to do that by checking if the mesh is inside the bounding box each time its world matrix is changed (by calling registerAfterWorldMatrixUpdate), but it would mess up the gizmo drag behavior if the camera angle is not placed right. And I don’t quite like the ‘hacky’ way it is to get this working.

https://playground.babylonjs.com/#QCQU6G#2

Try to play with the z-axis gizmo (the blue one), it will start screwing up if you drag your pointer too far from the sphere.

Also, is there a way to control the gizmo manager so that I can decide whether or not the ‘drag’ is valid (like a predicate, but for dragging after evaluating its to-be position)? Or, is it faster to just implement a drag behavior manually? If so, how?

Thanks in advance!

Pinging our gizmos overlord @Cedric

1 Like

Hi @Madaoism

I check that first thing in the morning and I’ll let you know when I find something useful.

1 Like

Hi @Madaoism

I’ve fixed the issue! No more jittering. I only did it for X axis but it will work for Y and Z as well.
https://playground.babylonjs.com/#QCQU6G#3
I only change the observable to add the function to.

Let me know if you find another issue :slight_smile:

1 Like

Hi @Cedric ,

I have tried that but it doesn’t really work that well in my project. The jittering is even worse when I hooked up to the drag behavior observable. I’m on the NPM version 4.0.3. It might be because my project is quite complex/heavy compared to just a sphere and a plane, especially with all the APIs and react elements hooked onto it. Unfortunately I can’t really show a demo as it is commercial.

My main concern is the drag behavior when the axis is close to parallel to the camera angle; it doesn’t behave in expected ways when you pull it towards the horizon.

Is it safe to just clear out the drag behavior and write manual ones for my app?

It’s not exactly what I got.
Can you provide a small video capture of the behavior you have?
It might be because of precision. If two vectors are almost colinear then a small amount of pixel will result in an imprecise world delta.

Alright. I will see if I can upload something, but most likely not as my manager won’t be too happy with it. Meanwhile I will be working on some other issues; I will make another reply if I have further inquiries.

Thanks!

1 Like