Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kahlerasse · Sep 29, 2021 at 09:22 PM · rotationquaternionnormalsprocedural mesh

Calculate Rotation based on mesh normals

i have a plane that i want to rotate to face a certain direction, but not using transform.rotation but by rotating the vertices. i already have the code for rotating mesh vertices arround a center :

         var path = GetPath();
         var angle = Quaternion.FromToRotation(mf.mesh.normals[0], path[0].rotation.eulerAngles);
         var center = mf.mesh.bounds.center;
 
         for (int i = 0; i < mf.mesh.vertices.Length; i++)
         {
             mf.mesh.vertices[i] = RotateVertex(center, mf.mesh.vertices[i], angle);
         }

         public Vector3 RotateVertex(Vector3 center, Vector3 vert, Quaternion angle)
         {
                // rotates the vertex
               vert = angle * (vert - center) + center;
               return vert;
         }


i only need to find a way to calculate the rotation of the mesh based on the direction and the mesh normals like this : alt text

screenshot-2021-09-29-221121.png (31.7 kB)
screenshot-2021-09-29-221051.png (42.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bdubbert · Sep 29, 2021 at 10:46 PM

Given only mesh normals you cannot calculate the rotation of the mesh fully, because you can always rotate the mesh about the normal and have a new mesh rotation but the same normal. You can calculate a mesh rotation by using Quaternion.LookRotation and feed in the normal. You will also have to feed in another vector, but you could feed in any vector that is orthogonal to the normal vector, because as I mentioned before there are really infinite rotations given a normal vector.


Also the order that you feed the vectors in depends on how your plane set up relative to the x/y/z axis. If "up" for the plane is in the same direction as the normals, then feed in the normal vector as up and the orthogonal vector as forward.


If you really want to get the ACTUAL EXACT rotation for the plane, you will need more information.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kahlerasse · Sep 30, 2021 at 06:40 AM 0
Share

is there a way to find out which way my mesh is facing so i can know how to rotate it ?

avatar image bdubbert kahlerasse · Sep 30, 2021 at 03:08 PM 0
Share

I suppose you could always look at the vertex data too... but I guess at this point I would be curious to know why you can't just use transform.rotation?


Anyway, if you really want to figure out the orientation of the plane you can look at the 3 vertices comprising the first triangle of your mesh. If you look at the vectors that represent the shorter of the two sides of the triangle, then you have 2 of your 3 local axes.


For example, say you know that the first triangle in your mesh always corresponds to the upper left corner of the plane (looking at it head on), and that the forward vector of the plane object is parallel with the normal of the plane. Then, looking at the triangle, you know that the two sides of the triangle will be the right and down vectors. Then, using the normal vector and down vector you can get the rotation using Quaternion.LookRotation.


This requires you to know some data about the plane before hand. How is the plane oriented with respect to its local axes (does the forward vector point normal to the plane or parallel)? Where is the first triangle in the mesh, and which sides of the triangle point in which directions? Once you figure this stuff out though then as long as you are always using the same mesh you can figure out the orientation of the mesh.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Comparing a quaternion to a contact point normal 0 Answers

Rotate Player to Match Surface Normal While Still Maintaining Y Rotation 0 Answers

Rotating with a preferred driection. 0 Answers

Rotating an object to equal normals of object below 1 Answer

How to handler rotation of a Gameobject while aligning it with normals 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges