What is the gizmo's position depending on?

I’m using CSG to cut meshes. Once they are cut the gizmo is displaced ( not in the center of the mesh).
I’ve tried this advice

HTML5 Game Devs Forum - HTML5GameDevs.com

and that one

none of them are working for me…

my PG: https://playground.babylonjs.com/#2VPMSK#3

the slice (cut) method is at the beginning - I’ve tried there the following

mesh.setPivotPoint(mesh.getBoundingInfo().boundingBox.centerWorld); (line 46)

but it’s not working. I just need to know what is the gizmo’s position depending on, so I can fix this.

1 Like

Hiya Issabln. I think it depends upon the center/pivot of the attachedMesh, but that is giving you problems, I see. Finding centers on CSG-result mesh… might be troublesome, without doing some type of boundingBox update, if needed. That’s the short answer. :slight_smile:

Wow, that #3 playground is complex. I cleaned it a little… removed physics for now, turned-on the SliceMesh function, reduced size of slicerBox, removed extra ground, and a few other things.

https://playground.babylonjs.com/#2VPMSK#7

Other helpers…SliceMesh func is not used for subtracting/intersecting with woodgrain board, but instead, for repeated clicking (doubleclicking) upon the woodgrain board… stacking gray slicerBoxes atop one another, until they turn brown, as best I can tell. :slight_smile: Issabln probably has many adjustments planned for SliceMesh function… but right now… I’m not real sure of its intended purpose.

The other MAIN issues… how to position gizmos, when to updateBoundingInfo and updateBoundingBoxes after CSG operations, etc… I’m just getting started, and I’m not very experienced. I can use all the helper help I can get. :slight_smile:

A smaller playground would sure make it easier to test, so maybe issabln and other helpers… can keep shrinking this playground until we can “see” the issue a bit better.

I would THINK that the gizmoManager .attachedMesh is somehow important, here, but after CSG operations happen, bounding boxes might need updating. I disabled line 54 in the #7 playground… but that is THE point of interest, I think. Issabln wants that gizmo to move-around, and re-center at various locations… AS the mouse-driven CSG changes… happen (I suspect).

When I turned-on SliceMesh() by setting line 57 var sliceBool = true;, the click-on-woodgrain to launch gizmo there… quit working… because a different “picker” gets activated on woodgrain board.

I wish I had more info, but not yet. I’ve never even THOUGHT ABOUT moving around a BJS gizmo… based-upon an ever-changing CSG shape’s “origin” (pivot point). Gruesome! :slight_smile: It makes my brain hurt. heh.

snip

I think I am a bad minecraft scene-maker. :slight_smile:

In short, I think maybe Issabln wants to attach the gizmo to the CSG adder/subtractor mesh… so IT can be positioned, rotated, and scaled… and then it is CSG- added/subtracted to/from the master mesh… to create a type of CSG-based master-mesh-editor. Cool. A modeler.

At other times, like when NOT in edit mode… Issabln wants the gizmo to attach to the NEW master mesh… at its new “volume center”. So, that is why master mesh MIGHT need some kind of boundingBox/boundingInfo update/re-calc (after the CSG edit)… before we try to find the master mesh center… and put the gizmo there.

Or, I could be wrong… by a mile. :slight_smile: Needs a function. refreshBoundingAreaAndPutGizmoAtNewCenter(anyCsgMeshResult, gizmo) :slight_smile:

2 Likes

Thanks for looking into my issue. Yes, as soon as i cut the mesh using csg the gizmo gets displaced. I thought the gizmo depends on the boundingBoxCenter, but I’m not sure anymore, because as you see, the bounding box is there as it should be (just around the actual mesh).

I’ve also tried playing aroung with the pivot, but that didn’t solve this either. I have to know what makes the gizmo’s position change? Is it the boundingBoxCenter? the pivot? or something else?

Here I got a more cleansed PG (all parts have headers, you can minimize the unimportant ones):

EDIT: I realized that the gizmo stays in the position of the first box (the one that gets cut the first), what I mean with “stays in the position”, it stays always the same distance away from the cut meshes as the distance the center of the first box to them, know what I mean? See here:

  1. nothing cut - gizmo in center

  2. a cut on left side - no matter which part I select the gizmo stays in the former center ( that of the first box):

  3. drag left box to the left - gizmo stays at the same distance to the former center

Yeah absolutely, I would update it myself if I knew what exactly needs to be updated :slight_smile: ,
because as I said I already tried this one :

mesh.setPivotPoint(mesh.getBoundingInfo().boundingBox.centerWorld);

Cool. Umm… I could only find two update/refresh to bounding things…

On Mesh: Mesh - Babylon.js Documentation (refreshBoundingInfo)

On BoundingBox Gizmos: BoundingBoxGizmo - Babylon.js Documentation (updateBoundingBox)

I’m not sure if either of those are pertinent, but I thought I should show them to you. I’m not very experienced with this area. Maybe others will comment.

1 Like

You can see here that setting a pivot does not change the relative position of a gizmo https://www.babylonjs-playground.com/#3RTT8P#75. The pivot has been changed (to a position shown by the red sphere) yet the gizmo is still placed at the centre of the cube (yellow sphere).

@MarianG seems to have a solution to positioning a gizmo How can I move position gizmo axis? but as I am a very slow learner his solution is hidden to me within all the code of the PG he references. Perhaps he will help out by showing how the gizmo can be position to the red sphere in the PG I gave above.

2 Likes

Hi guys.
Yes, I found a temporary solution.
Sory for unnecesarely code, I tried to clear it a little bit.
So we have this - https://www.babylonjs-playground.com/#LLL145#13 - line 19-22

  1. take center of bounding box. - 19
  2. set position on it (most of the time this position the object in the midle of scene) - 20
  3. bake transforms - 21
  4. set position of object back to initial position. - 22
    Just this. Nothing more.Cheers:beers:
4 Likes

Thanks man. I’ve seen your example already and tried it…Must have made some mistakes back then.

:+1:

1 Like

@MarianG’s shake’n’bake. :slight_smile: Alright!

Hey, just a little reminder for us pivot/origin wranglers:

  • 2nd arg of setPivotMatrix() - a boolean to set… “move mesh or keep in same position”.

also…

  • 2nd arg of setPivotPoint() - “space static” :slight_smile: BABYLON.Space.WORLD or BABYLON.Space.LOCAL

You can easily test those options… in lines 49/50 of JohnK’s demo (new version)… here.

Probably not pertinent at all, but I wanted to maintain my reputation for posting unnecessarily on already-solved threads. :microphone::cowboy_hat_face:

2 Likes

I don’t know, what has changed, but the same code doesn’t work anymore. Now the gizmo gets the right position, but the mesh itself jumps to the zero point (?) . It worked before…Do You have an idea why this is the case?

this is the function where I use your code (l. 330)

 var updateGizmo = function(mesh) {
      var oldPivotTranslation = mesh.getBoundingInfo().boundingBox.centerWorld.clone();
        mesh.position.set(-oldPivotTranslation.x, -oldPivotTranslation.y, -oldPivotTranslation.z);        
        mesh.bakeCurrentTransformIntoVertices();
        mesh.position.set(oldPivotTranslation.x, oldPivotTranslation.y, oldPivotTranslation.z); 
  }

and I’m calling it on the two meshes that result when I cut a mesh in the SliceMesh function (l.46, 47). The bug gets obvious when You call it only on one of them.

//updateGizmo(meshSliceSub)
updateGizmo(meshSliceInt)

I have no ideea. But my example from above is still working, strange that your is no more work.
Ping @sebavan maybe he has an ideea about what was changed :slight_smile:

PS; I tried to run your pg with the previous version: 4.0.3 but I got some ‘… is not a constructor’ errors. @Deltakosh can you please check if this is expected or it has to do with the last change on playground ui? Thank you

This should work…Let me see that :slight_smile: