learn3d Posted December 11, 2017 Share Posted December 11, 2017 Hello, im new in Babylon and i have problems with my pivot points. I tried to rebuild it in a playground - my first question - why is the pivot not in the middle of the second cylinder? Its shown with a sphere at 0,0,0 https://playground.babylonjs.com/#RLT22Z Unfortunately my obj file doesnt save the pivot of my 3ds max object - so i tried to position it manually. After i positioned it up on the y axis and control the slider - the parent(cylinder01) and the world coordinates moves around my positioned pivot(cylinder02)... I wish i could show you the scene - but in playground the sliders didnt work. https://playground.babylonjs.com/#FG1ECQ I hope somebody can help me :/ Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 11, 2017 Share Posted December 11, 2017 Hi and welcome. I tried to rebuild it in a playground - my first question - why is the pivot not in the middle of the second cylinder? Its shown with a sphere at 0,0,0 You are positioning the sphere using cylinder02.getPivotPoint(); but as you haven't set the pivot point this returns 0 https://playground.babylonjs.com/#RLT22Z#3 Secondly using the developer tools inspection panel in the browser quickly shows these errors in the console ReferenceError: Cylinder01 is not defined ReferenceError: Cylinder02 is not defined You used c for your cylinder variables not C. https://playground.babylonjs.com/#FG1ECQ#1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 11, 2017 Share Posted December 11, 2017 Hi guys. I've been working this a bit, too... using the other playground. https://playground.babylonjs.com/#RLT22Z#2 In line 51, I try to set sphere position AT cylinder02 getAbsolutePosition() + getPivotPoint() (pp is 0,0,0) Not doing so well, am I? Position cylinder02's parent (which is cylinder01) back to 0,0,0 (disable lines 37/38), and the sphere locates to cylinder02 pivotpoint/position... perfectly. Does THAT seem normal? I thought getAbsolutePosition() could get a mesh.position value, no matter what parenting-hell was applied. Strange... maybe. Update: Oops, yep, thx @JohnK, I meant to link to #2. link fixed, now. Quote Link to comment Share on other sites More sharing options...
adam Posted December 11, 2017 Share Posted December 11, 2017 getPivotPoint should probably have an optional space param. Quote Link to comment Share on other sites More sharing options...
learn3d Posted December 12, 2017 Author Share Posted December 12, 2017 @JohnK Does it mean if i havent set a pivot point its automatically 0,0,0? Ok.. I can manually set them because i have only a few models in my scene and the 3ds max coordinates of the pivots. But the problem is now that my second playground works great(after C=c ;)) - but in my project the parents rotate when i change the slider of the childs - around the corrected pivot of the child... Is obj. the problem? @Wingnut No Log shows the correct position of cylinder02 :/ there must be a way to get the position Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 12, 2017 Share Posted December 12, 2017 1 hour ago, learn3d said: @Wingnut No Log shows the correct position of cylinder02 :/ there must be a way to get the position Yeah, I thought cylinder2.getAbsolutePosition() would do that, but it doesn't. I'm still puzzled, or confused (that's more likely) About the other stuff, you need to do a little study about "worldSpace" and "localSpace". Good reading on a rainy day. Here's a couple things that could be handy for you. mesh.bakeCurrentTransformIntoVertices(); Generally, no matter HOW a mesh is transformed (positioned, rotated, scaled)... this command "resets" all those values... back to default. poz 0 0 0, rot 0 0 0, scale 1 1 1 Experiment. Try moving a mesh sideways 10 units, call the bake, and move it back to previous location, and spin it. What did the pivotPoint/origin do? Did it shift sideways? yep. Rotate it in a renderLoop spinner.... like I did in my previous playground. (I spin nearly everything, to check pivotPoints/origins) You can "bake-in" rotations, positions, and scalings. Although possibly technically "illegal", mesh don't need to be set updatable... to do bakes. (I don't think). SPEAKING of pivotPoints and origins... read about the differences between those two things... IF there are some... in 3D Max help files. After you export a .babylon file... view it in Notepad, whateverPad, or an online JSON file viewer. See what exported... examine things. The 3D Max exporter is still in-dev, so perhaps stuff is done wrong, or uniquely, regarding the export of pivots and origins. Got parents set in Max, before export? Did that get exported? We recently added "transformNodes" to BJS, and although they promised to be impact-free, they COULD affect Max exports. (actually, unlikely, but bugs is bugs) Here's another little story. mesh.rotationQuaternion . That property is only added to BJS mesh, when needed. But some say.... working with Quaternion rotation... is NICE. And it is... if you can "feel it". Is 3D Max exporting its mesh... with .rotationQuaternions already installed? Probably not, but there may be a checkbox in the exporter screen. IF you decide to set a mesh.rotationQuaternion = BABYLON.Quaternion.Identity() ... or maybe .Zero() ... then you are ready for a brand new type of rotation command: cylinder02.rotate(new BABYLON.Vector3(0, 1, 0), .03, BABYLON.Space.LOCAL); // param1 is axes, param2 is amount, param3 is space (probably can use numeric 0 or 1 or 2, there). A quaternion localSpace Y-axis rotater. WOW! Once you have this, now you can do rotation experiments in LOCAL and WORLD space. For example, I think the above line... would work great on your slider. Remember... some mesh have .rotationQuaternion property already installed by something else, and some need one added... before that .rotate() thing works. Generally, when a .rotationQuaternion exists, AND has a value other-than .Identity(), then the .rotation property is ignored and not continuously value-updated. Mesh.rotation sort-of goes stupid. At least that is MY experience... but sometimes I'm bonkers. You can convert a Quat value... back to Euler angles, with... mesh.rotationQuaternion.toEulerAngles() or something like that. .rotate() has a sister method... .translate(). But no Quaternions are involved in .translate(), as far as I know. Still, it allows translation in either LOCAL or WORLD space. Lastly, I was recently fighting-with this same issue. I needed to get my pivot/origin... re-centered. "Squared-up". Local genius Adam... helped me here. Ok, that's just some assorted weird information... which might be important to you, now or soon. I hope I didn't say too many wrong things. Cya later. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 14, 2017 Share Posted December 14, 2017 Hi again. I built a little playground that compares position and getAbsolutePosition() on a single-line of inheritance. (child of child of child), etc. GetAbsolutePosition() seems to be doing things right, as best I understand its use. For a moment, a few posts ago, I had some doubts about getAbsolutePosition(), so I needed a fresh testing PG. Anyone, feel free to do edits and saves - do your own experiments, and have some fun with Babylon GUI at the same time. kbye again. Quote Link to comment Share on other sites More sharing options...
learn3d Posted December 18, 2017 Author Share Posted December 18, 2017 Hey Wingnut Thanks for all the tips. I read a lot about world/local space, rotation/position methods and euler/quaternion. I logged mesh.position, mesh.getAbsolutePosition(), mesh.getPivotPoint(); mesh.getAbsolutePivotPoint(), mesh.getPositionExpressedInLocalSpace() and rotate all the meshes(with and without child/parent). Got a better understanding buts its also still complicated. At this time everything is ok for me but of course i will come back to this thread again I cant imagine a situation for mesh.bakeCurrentTransformIntoVertices() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.