jerome Posted May 6, 2015 Share Posted May 6, 2015 Hello, AFAIK, many users (and sometimes I) face the same rotation complex problem :they've a got a mesh, just created in its local space, and they want it somewhere else (quite easy with .position attributes) with another orientation. Another orientation is the problem. What does BJS do so far ?It provides many methods to rotate a mesh, it is to say, under the hood to set up the mesh world transformation matrix (translation, rotation, scale) and they apply it to get the result. But, usually, the user doesn't really know how much he has to rotate his mesh and relatively to what (translation and scaling are quite obvious, not rotations).He only knows that he wants his mesh at this final position with, say, its length aligned on the box-sphere axis, its width in the plane x0z and its depth facing this other mesh, etc.In other terms, the user usually knows the final result he wants and not how to get it. We can assume he knows then the new translated/rotated local system coordinates in the world : he knows the position of his mesh (the wanted new origin) and its orientation : 3 orthogonal vectors in the world describing the new mesh orientation (remember : the length aligned with box-sphere axis could be the new local X axis , etc ) So, since BJS is simple and powerful, maybe do we need some locate() function (any better name welcome) to set up the underlying rotation layers given a target orientation (axisX, axisY, axisZ) ? ex : I want a plane set at (5, 5, -2) with its width aligned with the (1, 2, 0) axis, let's call it a, and its length in the plane yOa.I definetly don't know how to rotate my plane to get this... so I'd like to do :var plane = BABYLON.CreatePlane("plane", 10.0, scene);// creates a plane as usualvar origin = new BABYLON.Vector3(5, 5, -2); // sets the target positionvar axisX = new BABYLON.Vector3(1, 2, 0); // sets 3 orthogonal axis to define the target orientation var axisY = BABYLON.Vector3.Cross(axisX, BABYLON.Axis.Z);var axisZ = BABYLON.Vector3.Cross(axisX, axisY);plane.locate(origin, axisX, axisY, axisZ); // locates the mesh at this position with this orientationI guess I could code this if someone would tell me please what is the BJS order for rotation matrices application under the hood :Rx * Ry * Rz ?Rz * Ry * Rx ?something else ? Not sure I'm very clear Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 6, 2015 Author Share Posted May 6, 2015 mmh...I guess I can do it without any rotations, just vector handling. As the translation aspect is quite obvious to everyone (mesh.position.x, y, z), do you think it is still worth passing an origin parameter ?So maybe the name locate() isn't pertinent ...mesh.turn(axis1, axis2, axis3); ?mesh.bear(axis1, axis2, axis3); ?mesh.changeAxis(axis1, axis2, axis3); ?mesh.pleasePositionHere(axis1, axis2, axis3); ?mesh.shutTheFckUpAndJustSetHereRightNow(axis1, axis2, axis3); ?any thoughts/prferences ? Quote Link to comment Share on other sites More sharing options...
dsman Posted May 6, 2015 Share Posted May 6, 2015 I had similar requirement. I had to write my own code for aligning a mesh relative to some other mesh. So if some magical function exist which can handle many scenario and wide range of shape of mesh to align with different type of mesh, it could be great. function could be called mesh.align() . But it is matter of debate what exact scope this method can have. I.e. what kind of shape can it support . (I did for my own code for aligning plane with plane. ) Quote Link to comment Share on other sites More sharing options...
jerome Posted May 6, 2015 Author Share Posted May 6, 2015 I would like to make it work for any mesh, as well for Vector3.It's not really about aligning things together although it would be useful to align things. It's more about :I have an initial mesh position/orientation.I know how I want it to be positioned/oriented, meaning I know the final axis.... but I don't know what rotation to apply from the original status to get my target status. So I just want my mesh to be set in the target status (known by 3 axis) without handling rotations, quaternions, parenting, all that stuff I don't understand.It's another perspective : it's not HOW I transform something to get a result, but only WHAT result I want to get directly. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 6, 2015 Share Posted May 6, 2015 Did you try mesh.lookAt ? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 6, 2015 Author Share Posted May 6, 2015 huuu... didn't even know this stuff existedI will check Quote Link to comment Share on other sites More sharing options...
jerome Posted May 6, 2015 Author Share Posted May 6, 2015 not the same... you need to know about angles with lookAt and initial constraint (mesh drawn facing the user)not the same need Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 6, 2015 Share Posted May 6, 2015 Just wanted to be sure Quote Link to comment Share on other sites More sharing options...
jerome Posted May 6, 2015 Author Share Posted May 6, 2015 I'll code a proto in the playground soon to introduce the stuffstill looking for a pertinent name if it solves Alby's box rotation problem, it will be a good POC Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 7, 2015 Author Share Posted May 7, 2015 redirecting now on rebase() topic :http://www.html5gamedevs.com/topic/14349-meshrebase/ 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.