yuccai

Parent/Child transformation

Recommended Posts

Hello,

 

I have a problem with parent/child transformation.

I have two meshes. I'd like to apply a rotation to one mesh, then define this mesh as parent and the other as child. But the child is also rotate.

 

I wish to know how to rotate the parent without moving the child before assigning the parent relation.

 

Thanks

Share this post


Link to post
Share on other sites

Welcome to the forum, yuccai!  Good to have you with us!  And hello to you, as well, Deltakosh!  ;)

 

To clarify if I may, once the parenting is done and the child has rotated to match the parent... rotate the child itself back to its original rotation.  (Loosely quoting Deltakosh, rotate it the opposite way(s) until it returns to its original un-rotated state/condition/attitude.)  :)  (Doesn't English suck?)

 

yuccai - 'by default' means... that this behavior is normal for parent-child relationships.  Rotation is one of the normal characteristics (default properties) that is handed-down from parent to child.

 

http://www.babylonjs.com/playground/#1W3CLH#1

 

(That's our cool 'playground', yuccai.  Its a neat place to play with scenes online, live.  Change stuff and hit Run again, see it happen before your very eyes!  I put some code into it... that applies to your questions.)

 

Hot newbie tip of the day:  BABYLON.Vector3(someXvalue, someYvalue, someZvalue)... has three main uses:  positions, rotations, and directions.  Position and rotation are mostly used on mesh and FreeCameras, and direction is mostly used on lights.  ArcRotateCameras are orbital and a bit strange. They use .alpha and .beta property values... which are single floats indicating radians of orbit.  Lighting colors and material colors... often use BABYLON.Color3(someREDvalue, someGREENvalue, someBLUEvalue).  Color3 values are floats that tend to range from 0-6, (oddly enough).  Vector3 values can be from negative anyfloat to positive anyfloat (no limits)... but when used for rotations, there is no need to go outside of the range from negative 6.283 to positive 6.283 .  When a Vector3 is used for a direction, its values can be anyfloats, but often they are 'normalized' so that each value is in the range of negative 1 to positive 1.

 

Ok, sorry for interrupting... but I saw a potential communications gap happening here, and I wanted to add to the confusion.  :)  Party on!

Share this post


Link to post
Share on other sites

Hi,

 

A mesh always has its parent rotation, the only way for doing what you want is to explain the child transform matrix into the parent space in order to keep is previous position.

 

Here the code you probably have : http://jsfiddle.net/MaxenceBrasselet/ywcz5/5/

 

In this jsFiddle when you click on the button you just create the parent relation, so the child object move because its position, rotation and scale are now explain in the parent space (before theire was explained into the world space).

 

Here the code to change the transform : http://jsfiddle.net/MaxenceBrasselet/ywcz5/9/

 

In this example, if you click on "applyParent" button you will se that nothing seems to be done, but if you look the scene.meshes array, you will see that the child cube has parent cube as parent.

 

I explain what I've done by commenting the code, I think its what you need.

 

If you have any question, do not hesitate to contact me.

 

I hope it could be helpful.

Share this post


Link to post
Share on other sites

Thank you for all these answers !

 

Thanks to you i understand better how Babylon works. But in my case I can't move the child and I have to find an other to solution to my issue.

 

Thank you very much

Share this post


Link to post
Share on other sites

I don't understand why you still have a problem.

 

Why the child cannot be moved ?
 

Because in my second demo you can see that the child does not move when you set it a parent.

 

Can you please detail your problem (thus the community can help you and it could be helpful to future users).

 

Thanks you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.