Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 navx2810 · Jun 10, 2014 at 09:41 PM · mesh verticeschange colorvertice manipulation

Finding the Vertices that make a face

I am looking to change the vertex colors on each face of an object to the same color. To do this, I need to know which vertices make up the triangle face. I have tried using Mesh.triangles, but they do not seem to list the order in which each vertice makes a face. In fact when I assign it to an array they count from 0, 1, 2, 3, 4. . .

Is there a way that I can determine which vertices make up a face? Thank you.

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
2

Answer by Bunny83 · Jun 11, 2014 at 01:17 AM

In the past it was quite simple since a Mesh only contained triangles. So the indices are used in groups of 3 to define 1 triangle. Now a Mesh can contain quads, triangles, lines, linestrips or points.

The usual way (which does still work if the mesh contains triangles) is:

 //C#
 Vector3[] vertices = mesh.vertices;
 Color[] colors = mesh.colors;
 
 int[] indices = mesh.triangles;
 int triangleCount = indices.Length / 3;
 
 for (int i = 0; i < triangleCount; i++)
 {
     Vector3 V1 = vertices[indices[ i*3   ]];
     Vector3 V2 = vertices[indices[ i*3+1 ]];
     Vector3 V3 = vertices[indices[ i*3+2 ]];
     Color C1 = colors[indices[ i*3   ]];
     Color C2 = colors[indices[ i*3+1 ]];
     Color C3 = colors[indices[ i*3+1 ]];
     
     // [...]
     // apply changes and assign back
     
     vertices[indices[ i*3   ]] = V1;
     // [...]
 }
 // finally you have to assign the changed array(s) back
 mesh.vertices = vertices;
 mesh.colors = colors;

If your mesh contains Quads you might want to check a submeshes topology if it contains quads or triangles and then changen the above to read 4 indices per face instead of 3. Of course you have to use mesh.GetIndices instead of mesh.triangles in that case.

ps: If your triangle array just contains a gapless enumeration of numbers (0,1,2,3,4,5, ...), that just means that no vertex is shared between triangles. If you want to change the color of only one face that's actually a requirement. Otherwise, if a vertex is shared between two triangles, both triangles would be affected since they use the same position / color / normal ...

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

22 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

Related Questions

Why is transform.InverseTransformPoint().y offset? 0 Answers

Extrapolating float values from Perlin noise? 1 Answer

if I rotate an object, do they vertices of its mesh change? 1 Answer

Imported cube vertex count different than expected 1 Answer

how to decrease vertices number of a sprite 0 Answers


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