c75 Posted January 13, 2016 Share Posted January 13, 2016 Guys, how can I rotate mesh perpendicular to selected face of another mesh? I know that I must use normal of picking element, but what's next? Ty Quote Link to comment Share on other sites More sharing options...
jerome Posted January 13, 2016 Share Posted January 13, 2016 perpendicular is not enough for information ... If you want the mesh2 to be perpendicular to some mesh1 face, you may tell us also how you want this mesh2 oriented ? looking at the screen ? looking at the sky ? etc Actually you may precise 2 other more axis (the picked normal is the first one). In your case, I would set 3 orthogonal axis (normal, Y, cross(normal, Y) if it's what you need) then I would use rotationFromAxis() to get the rotation to give to the mesh2. Please do a PG Quote Link to comment Share on other sites More sharing options...
c75 Posted January 13, 2016 Author Share Posted January 13, 2016 jerome, thank you for response. I made playgorund http://www.babylonjs-playground.com/#2C8LVE#1 but have problem with correct rotation it is best that mesh face to screen but it's not so important. Quote Link to comment Share on other sites More sharing options...
jerome Posted January 13, 2016 Share Posted January 13, 2016 Do you mean that you prefer the monkey looks towards the same direction of the mesh normal ? http://www.babylonjs-playground.com/#2C8LVE#2 Quote Link to comment Share on other sites More sharing options...
c75 Posted January 13, 2016 Author Share Posted January 13, 2016 no, must be perpendecular to face. I released it. but not sure it's correct algoritm (i'm like that monkey - brute the solution ) http://www.babylonjs-playground.com/#2C8LVE#4 Quote Link to comment Share on other sites More sharing options...
c75 Posted January 13, 2016 Author Share Posted January 13, 2016 and it's not working on rotated meshes http://www.babylonjs-playground.com/#2C8LVE#5 (try move over box) Quote Link to comment Share on other sites More sharing options...
jerome Posted January 13, 2016 Share Posted January 13, 2016 I don't get what you are try to achieve ... Imagine you just display Suzanne in its local (X,Y,Z) axis, ok ? Now, just figure out how you want these (X, Y, Z) according to each mesh facet. "Perpendicular" is not enough information to set (X, Y, Z) You could, for instance want : Z => facet normal Y => World Y ? or World Y projection on the facet normal ? or whatever ? only you know X => cross(Y, Z) Or anything else ... that's just an example c75 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 13, 2016 Share Posted January 13, 2016 I think the question is - why isn't the lovely Suzanne not straight on the box - see image The answer would be - the mesh is rotated. The normal is not rotated, it is the original normal. So you will just need to take the rotation of the mesh into account, and - tada Quote Link to comment Share on other sites More sharing options...
jerome Posted January 13, 2016 Share Posted January 13, 2016 not sure, in his last example, C75 computed a cross vector with from a mysterious axis (1, 1, 1) at the line 112 ... Quote Link to comment Share on other sites More sharing options...
c75 Posted January 14, 2016 Author Share Posted January 14, 2016 16 hours ago, jerome said: not sure, in his last example, C75 computed a cross vector with from a mysterious axis (1, 1, 1) at the line 112 ... Yes, that was random vector (bruted finding needful rotation), I tried to use lying mesh, and rotation formula became easier. Check it http://www.babylonjs-playground.com/#2C8LVE#6 and my final "clean" formula with standing Suzanne is here http://www.babylonjs-playground.com/#2C8LVE#7 But i'm still can't find solution to merge rotation of mesh and normal (@RaananW said about that). What methods I should use? Quote Link to comment Share on other sites More sharing options...
RaananW Posted January 14, 2016 Share Posted January 14, 2016 Hi, this is easily solved with quaternions : http://www.babylonjs-playground.com/#2C8LVE#8 Maybe some math wizards can help better with the rotation vector, but I find quaternion multiplication the easiest and the most understandable gri and c75 2 Quote Link to comment Share on other sites More sharing options...
c75 Posted January 14, 2016 Author Share Posted January 14, 2016 @RaananW super-thank you!!! I must read more about this 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.