Jump to content

How to set the pivot point of CSG generated mesh to the mesh center?


gzlock
 Share

Recommended Posts

code: http://www.babylonjs-playground.com/#Y5561T

The green object was generated from CSG (BoxA.intersect(BoxB)) and the pivot point was inherited from BoxA.

So I want to let the pivot point of the new object reset to the center.

I tested 

NewMesh.setPivotMatrix(BABYLON.Matrix.Translation(0, 0, 0));

but the pivot point still stay in place.

How to do it by easy way?

Link to comment
Share on other sites

Yeah, sorry.  I tired some things last night... but failed.   I tried assorted aimless commands.  https://www.babylonjs-playground.com/#Y5561T#2

Wingnut fail.  :(

I have another project that needs pPoint center-up of some imported-from-3dsMax mesh.  So far, I have failed for those, too.

I don't have a solution, dag-nabbit.  hmm.   Hopefully, smarter people than I... will respond, soon.  *scratch scratch*

Link to comment
Share on other sites

Yeah, sorry.  I tried some stuff... failed.  [#2]

I have another project that needs pPoint center-up of some imported-from-3dsMax mesh. I failed for those, too.

In that project, the mesh need to keep their pivotPoint/Origin offsets... because they are part of a bigger model.

But I need to clone the mesh, and center up the pivots... for use in "View a single part of master model" -feature.

In #3 version of your playground,  lines 60-164 is demo code of the many things I have tried... in that other project.

You can probably ignore lines 66-67.  I was told that was a way to make non-updatable mesh... BE updatable.  Having myClone be updatable and geometryUnigue()... is important for trying vertex position-kind shifting/moving (not yet tried). 

I'm not sure if simple pivotPoint/Origin adjusting... needs mesh to be set updatable or not.  But, just in case, you can see twin "true" at the ends of lines 16/17... the lines that make your CSG source mesh.  No joy.

I don't have a solution, darnit.  Hopefully, smarter people than I... will respond, soon.  *scratch scratch*

Link to comment
Share on other sites

Hi @gzlock and welcome to the forum from me. Have been quiet busy the last couple of days so even though I saw your problem had things to finish before I could have a go.

First of all check out these pages from the documentation

http://doc.babylonjs.com/how_to/pivots

http://doc.babylonjs.com/how_to/pivot#how-to-use-a-pivot-as-a-center-of-rotation and the first PG that goes with it

Secondly using CSG will set a local origin in an unknown place and certainly not at the center of the triangle. The actual center of the triangle would involve finding the intersection of its medians again difficult. You can use the center of the bounding box as an approximation to the center of the triangle. Here we seen the bounding box around the green mesh.

Putting all this together gives

https://www.babylonjs-playground.com/#Y5561T#4 which I hope sets you up for what you want.

Link to comment
Share on other sites

You guys ROCK!  Hey, it worked for my other project, too.  YAY!!! 

Wanna hear a stupid story?  I have about 6-8 hours into trying to solve that other project pivot re-centering.  I had a little white box at scene.origin (0,0,0).  I kept trying things, trying to get this damned pivot-offset mesh... to land perfectly upon that white box.... indicating success.

Unfortunately, I didn't have a code line that set mesh.position to 0,0,0.  I wasn't NOTICING the correction in pivot points... because I was judging success upon landing the mesh perfectly onto the white box.  Well, if ya never put the mesh AT the white box... then you're an idiot.  And that was the case... with me.  Yikes, am I stupid sometimes!

So, forum question-asker... RESCUES forum-helper.  hehe.   Cool!

What the heck, I'm not complaining AT ALL!  :)  PARTY!!!

Link to comment
Share on other sites

  • RaananW changed the title to How to set the pivot point of CSG generated mesh to the mesh center?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...