Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
2
Question by CookieSteve · Jan 27, 2017 at 09:50 AM · meshpositionverticesmeshfilterworldpos

Getting the world position of mesh vertices?

I have some simple mesh objects in my scene, and I want to obtain the position of each vertex in them. So far, I have the following code to do so.

 MeshFilter mf = cube.GetComponent<MeshFilter>();
 for (int i = 0; i < mf.mesh.vertices.length; i++)
 {
         Vector3 v = mf.mesh.vertices[i];
         ...

The problem is that this only obtains the local position of each vertex according to the unmodified mesh. (i.e., cubes will have vertices at (0.5, 0.5, 0.5), (-0.5, 0.5, 0.5), (-0.5, -0.5, 0.5) etc... no matter where the cube is in the scene.)

Is there any way to obtain the world position of these vertices instead of this useless local position?

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
17
Best Answer

Answer by IgorAherne · Jan 27, 2017 at 10:16 AM

Don't be so harsh, they are not useless )

 Matrix 4x4 localToWorld = transform.localToWorldMatrix;
 
 for(int i = 0; i<mf.mesh.vertices.Length; ++i){
       Vector3 world_v = localToWorld.MultiplyPoint3x4(mf.mesh.vertices[i]);
 }

More about matrices here

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 CookieSteve · Jan 27, 2017 at 10:32 AM 1
Share

Works like a charm. Thank you!

avatar image douglasdaquino · Apr 03, 2019 at 02:10 AM 1
Share

you sir, just saved my life! I was going crazy trying to spawn things at vertices positions, now I can do it! Really really appreciate you sharing your knowledge :D

avatar image
3

Answer by robert878 · May 29, 2018 at 04:07 PM

Or use Vector3 worldPt = transform.TransformPoint(meshVert);

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 naklow12 · Sep 18, 2020 at 07:49 AM 0
Share

Actually not worked like the comment which is voted for answer.

avatar image timebenter · Sep 26, 2021 at 07:24 AM 0
Share

According to the Unity Documentation, this "Transforms position from local space to world space." So I think this is a better answer.

Transform.TransformPoint

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

74 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

Related Questions

Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer

MeshCollider is not getting updated when adding vertex to mesh 1 Answer

Is it possible to make vertices defined by a mesh and mesh filters animating? 0 Answers

NullReferenceException on assigning vector3 to mesh.vertices - no effect on assignment? 1 Answer

Generated Mesh Triangles not Being Made/Visible? 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