ParadoxMaster Posted November 19, 2018 Share Posted November 19, 2018 Guys, I need help. How to turn the mesh towards the point given by the vector? What method of rotation is needed here? Rotations is my weakness.. Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 19, 2018 Share Posted November 19, 2018 Is the face a vector ? If yes, then what you can do is - First find the new direction; this can be achieved by doing (some coord - face vector) After that you have find the angle between the old face vector and the new vector found by step 1. Use this angle to rotate the object mesh Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Author Share Posted November 19, 2018 4 minutes ago, ssaket said: Is the face a vector ? If yes, then what you can do is - First find the new direction; this can be achieved by doing (some coord - face vector) After that you have find the angle between the old face vector and the new vector found by step 1. Use this angle to rotate the object mesh Face is just initial direction of my object without rotation (front side of my mesh). I do not sure understand how i can get the vector of this direction. Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 19, 2018 Share Posted November 19, 2018 Use (some coord - position vector of object) to find the new direction, then using face normal's direction vector as old face vector , find the angle between them. Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Author Share Posted November 19, 2018 1 minute ago, ssaket said: Use (some coord - position vector of object) to find the new direction, then using face normal's direction vector as old face vector , find the angle between them. Thanks! I'll try it now Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Author Share Posted November 19, 2018 44 minutes ago, ssaket said: Use (some coord - position vector of object) to find the new direction, then using face normal's direction vector as old face vector , find the angle between them. Not so fast.. I can't get it. I do not understand how to get face normal's direction vector.. I need to create Vertex Normal's Data? And the function for calculating angle between Vectors has a third parameter, it is not clear what should be in it.. There is a playground: https://www.babylonjs-playground.com/#ADGVAT#1 Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 19, 2018 Share Posted November 19, 2018 Hello, I thought you know the face direction; well anyways, in the skull example, first task would be to figure out the direction which we know is the face. As of now, I use pickInfo to find the index. Here check it out https://www.babylonjs-playground.com/#ADGVAT#2 You need to click on the face first then it will rotate to sphere's position. Edit: for skull mesh, the front normal index is 49731(approx.), if you have this you can't skip the pickInfo part, here https://www.babylonjs-playground.com/#ADGVAT#3 Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Author Share Posted November 19, 2018 21 minutes ago, ssaket said: Hello, I thought you know the face direction; well anyways, in the skull example, first task would be to figure out the direction which we know is the face. As of now, I use pickInfo to find the index. Here check it out https://www.babylonjs-playground.com/#ADGVAT#2 You need to click on the face first then it will rotate to sphere's position. Edit: for skull mesh, the front normal index is 49731(approx.), if you have this you can't skip the pickInfo part, here https://www.babylonjs-playground.com/#ADGVAT#3 Thanks, this way really works. But the use of FacetData seems to me to be overcomplicated ... Is there really no simpler way, for example, using the initial rotation value (put it initially in the direction of the axis) . In my project, the mesh should move between different points and always look in the direction of its movement. Maybe I'm using something wrong. Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 19, 2018 Share Posted November 19, 2018 Not sure ! It won't be accurate also, 0 by default. How would you figure out the angle? 10 minutes ago, ParadoxMaster said: for example, using the initial rotation value (put it initially in the direction of the axis) Meanwhile you can try these resources - https://www.babylonjs-playground.com/#1YTZAC#3 https://doc.babylonjs.com/how_to/pivot https://doc.babylonjs.com/how_to/how_to_use_facetdata Quote Link to comment Share on other sites More sharing options...
JohnK Posted November 19, 2018 Share Posted November 19, 2018 You may find this useful https://www.babylonjs-playground.com/#E0KDHN as well which rotates the mesh using lookAt EDIT 21/12/2018 A bug in lookAt, to do with z -direction, was corrected in BJS 4.0 making the correct version of the above PG for version 4.0 and above https://www.babylonjs-playground.com/#E0KDHN#2 ParadoxMaster and ssaket 2 Quote Link to comment Share on other sites More sharing options...
ParadoxMaster Posted November 19, 2018 Author Share Posted November 19, 2018 7 hours ago, JohnK said: You may find this useful https://www.babylonjs-playground.com/#E0KDHN as well which rotates the mesh using lookAt Amazing! So simple. This is done in just one short line of code. skull.lookAt(some_coord); https://www.babylonjs-playground.com/#ADGVAT#5 Thanks very much! 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.