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 /
  • Help Room /
avatar image
0
Question by Cherno · Aug 06, 2014 at 02:03 AM · rotationvector3vertexprocedural mesh

Rotating procedurally generated meshes

I am creating voxel-based game (Minecraft etc.) and I was wondering how to rotate chunk parts that are more complex than simple squares, like the sides of a cube are.

For example, I created a staircase by manually constructing the mesh from code by giving the script the x,y,z coordinates of the virtual cube the staircase should appear in.

Now, how must I change the vertex coordinates of the staircase mesh so it gets rotated 90 degrees? Keep in mind that I can't just rotate the whole gameobject because the stairs would be part of a chunk's mesh.

Part of the code (creates vertices for one side of a very simple two-step staircase):

 List<Vector3> vertices = new List<Vector3>();
 
 
         int x = 4;
         int y = 0;
         int z = 3;
                 
             int angle = 0;//0 = 0 degrees, 1 = 90, and so on.
 
         vertices.Add(new Vector3(x, y, z));
         vertices.Add(new Vector3(x, y + 1, z));
         vertices.Add(new Vector3(x + 0.5f, y + 1, z));
         vertices.Add(new Vector3(x + 0.5f, y + 0.5f, z));
         vertices.Add(new Vector3(x + 1, y + 0.5f, z));
         vertices.Add(new Vector3(x + 1, y, z));


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

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by robertbu · Aug 06, 2014 at 06:04 PM

Untested on my part, but I think you can just do:

  • center - Vector3 around which you want to rotate the submesh

  • v - a vertex to rotate

  • q - a Quaternion representing the rotation you want to do


    v = q * (v - center) + center;

So cycle through the vertex positions in the submesh you want to rotate, and apply the above to each one.

Comment
Add comment · Show 3 · 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 Cherno · Aug 06, 2014 at 10:36 PM 0
Share

You are, once again, my hero! It worked flawlessly, and it's far easier than my idea of somehow converting each vertex position while building the mesh :) A million thanks! Now I can fill my dungeon with all sorts of procedurally generated scenery without having to use hundres of gameObjects.

The center variable is, for my script, just (x + 0.5f, y, z + 0.5f).

avatar image omi670 · Feb 24, 2018 at 06:02 PM 0
Share

Hello, this worked great for me aswell, but I was wondering If you could explain the maths behind it, I feel like I am cheating if i dont know how it works. Thanks!

avatar image yourecrippled · Apr 14 at 10:13 AM 0
Share
    public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
         {
             return Quaternion.Euler(angles) * (point - pivot) + pivot;
         }


It's the code he explained.

avatar image
0

Answer by BergOnTheJob · Jul 10, 2020 at 05:14 PM

If anyone is looking, this tool can rotate vertices of a mesh, and transform vertices using handle manipulation or directly entering the x,y,z coordinates of each vertex. https://assetstore.unity.com/packages/slug/166155

it also has a bunch of other tools to further model your staircase or any object's mesh.

Comment
Add comment · 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

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

24 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

Related Questions

Get angle between direction and plane 1 Answer

Help! Player script one step at a time add rotate and jump 1 Answer

Searching a function to get the rotation of one Vector3 in relation to another 1 Answer

Rotation Perpendicular to Line Segment 1 Answer

vector3 rotatetowards don't work 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