BoundingBoxGizmo with adaptive scalePivot based on ctrl/opt key

Hi folks, I’ve recently improved our BoundingBoxGizmo based scaling feature to support center based mirrored scaling when ctrl/opt is pressed and the default one-sided scaling when it’s not.

One limitation though is that it only applies the scalePivot going forward and not retroactively. In many apps, the scale would automatically be recomputed and applied when ctrl/opt is (un)pressed to reflect the scaling change as if the key was (un)pressed all along. You can see a video below, the issue is shown at the end when we toggle ctrl/opt while dragging.

I’ve tried to track the initial position and scale, compute the delta when the key and pressed, and apply changes to the mesh manually, but it breaks and seems to conflict with some internal mesh tracking (maybe _anchorMesh?)

So i’m wondering if this is something that can be implemented in userland, or if this should be considered a feature request. Tagging @Cedric as I understand you’re the master of gizmos.

happy-petting-gif

Take care :victory_hand:

To be absolutely clear, this is the behavior I’m trying to implement:

I think it makes the most sense to add the feature in onScaleBoxDragObservable . That’s where the _anchorMesh position is changed. So keeping its position and changing the scale would result in expected manipulation.It needs proper testing as missing 1 node in the hiearchy would break transforms or add jittering. Anyway, I’d start looking in that code block and would not try to do it in user land.

1 Like

Thanks for the quick reply. I’ll try to give it a go and report back.

And how do you see the control of the behavior? It it a new option? Is it default behavior? How would you handle backward compatibility?

It’s a new feature that doesn’t break back compat. If ctrl is pressed then there is this new behavior. Otherwise nothing changes.

1 Like

perfect, thanks

I just recalled, I asked because it conflicts with scalePivot. I’m guessing if scalePivot is set, we don’t apply changes, and if it’s null we do.

Here we go! My first feature PR is up :face_holding_back_tears:

@Cedric I’ve left a TODO with a question and would love pointers on how to approach the incrementalSnap case.

1 Like

Heads up @Cedric I found a bug in my PR! See it in this playground

I’m trying to find a fix, but wanted to give a heads up early.

Update: so it seems that the scaling impacts position on top of dimensions, we didn’t realize before because the position was the origin, so it scaled 0 :person_facepalming:. I’ve tried to debug it over an hour but made not much progress, except it seems to only happen on the first scaling drag, subsequently it works as expected.

It’s late here, I’ll try again tomorrow.

1 Like

Here we go, this PR should fix the issue

Sorry for missing that in the first place

3 Likes

confirm it’s fixed in my app now :tada:

1 Like