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 unity_user_12345 · May 28, 2015 at 06:31 AM · mecanimverticesweight

Color different Mesh vertices

I have a human mesh connected with an fbx animation file using Humanoid Mecanim. What I want to do is how to know the vertex groups, meaning the group of different vertices assigned to different limbs. Then I want to color each group of vertices with a certain color. For example, right hand will be red, left hand will be blue, head will be yellow,....etc. If anyone could please advise how this can be done in Unity using coding?

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

Answer by Ravart · May 28, 2015 at 09:46 AM

Since you kindly asked inside an old thread of mine, I will give you a straight answer, but it's not that easy ;)

Firstly you require a Shader that shows VertexColors, otherwise you wont see a thing!

Secondly, to color a Vertex (Each point in your Mesh is a Vertex), you have to access the Mesh (GetCompenent().mesh) and get the Colors (mesh.colors[], is an array). Get the index of the vertex and set color to an color of your choice at picked index.

For detecting submeshes (== vertex groups!!! what you called vertex groups is called "weights") inside your mesh you have to check the Triangles (mesh.triangles[]). Its a bit tricky since Triangles look different, depending if it's just one single submesh (therefore just one mesh) or contains many submeshes. Best google for Triangles⋐meshes.

Lastly, to gain information about your limbs(referred to as Joints), you access the Bones (mesh.bones or something like that). Inside a Bone is a Joint-Index and a Bone-Weight. Remember, one vertex can be affected by four joints, therefore you have the check the value of the weight (descripes how strongly the Joint affects the Vertex). Pick the index of the strongest weight and you have your limb.

Be careful, you could modify your mesh, therefore I recommend using the PlayMode.

Cheers

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 unity_user_12345 · May 28, 2015 at 12:39 PM 0
Share

Thanks for your answer, I'm really thankful for your kind assistance. I already made a shader that shows the vertexcolors and I can color the whole mesh. I'm asking if you could assist me on how I can detect submeshes, as I only have one mesh (representing the human body)?

avatar image Ravart · May 28, 2015 at 01:42 PM 0
Share

I can send you my code snippet regarding triangles and submeshes, though it's on my home-computer.

To check the number of submeshes, do "int i = mesh.sub$$anonymous$$eshCount;"

$$anonymous$$esh is just an container, therefore you never know if its one single submesh or many. Just imagine, you split any face and save it as own submesh, you won't notice a difference compared to a solid mesh. The reason for submeshes, they are important for tiled textures, otherwise you encounter problems with the UVs or if you require two different materials. Guess there are a lot of reasons to use submeshes. But you never know, therefore best check and store the triangles.

I re$$anonymous$$d you, to get your bones/limbs you don't require triangles, unless you want to get the polygroups/submesh (for example you wish to swap the head, taken your head is a polygroup/submesh)!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Animation is moving my object instead of deforming it 1 Answer

What is best way to do biped ragdoll dismemberment? 0 Answers

How to superimpose two animations using the animator? 0 Answers

Turn off root motion for a specific animation 4 Answers

mecanim and rigidbody gravity effect doesnt 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