Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Dan the Man · Aug 29, 2011 at 02:33 AM · meshverticesnormalsprocedural mesh

What's wrong with this simple mesh manipulation?

When I move some vertices around randomly, I end up with this:

alt text



 void Start() {
     Mesh mesh = GetComponent<MeshFilter>().mesh;
     Vector3[] vertices = mesh.vertices;
     Vector3[] normals = mesh.normals;
     
     for(int i = 0; i < vertices.Length; i++) {
         float rand = Random.Range(-0.1f, 0.1f);
         vertices[i].x += rand;
         vertices[i].y += rand;
         vertices[i].z += rand;
     }
     
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
 }


Am I missing something?

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

Answer by Owen-Reynolds · Aug 29, 2011 at 03:09 AM

If you print vertices.Length, you'll see it's 24 -- 4 for each face. The code is working perfectly. Each of the three verts at a corner is getting its own random shift.

Turns out graphics cards want to smooth-shade everything. When you make a hard-edge (a crease, in a modelling program) you're really splitting the verts on that edge. Seems a waste of verts, but every other way takes longer to draw. Technically, it's possible to set a model to no smooth-shading at all, but you have to specially redo the normals based on the order of the face array, which is too big a pain.

There's no easy pattern to find "same" verts: Debug.Log shows (0.5,0.5,0.5) occurs at indexes 2, 8 and 21, for example. I guess each time you change one, you could loop again to also change ones with the same values by that amount; with another array of bools to marked them as changed.

Comment
Add comment · Show 1 · 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 ina · Nov 02, 2011 at 08:12 AM 0
Share

graphics cards wanting to smooth-shade everything, is that true on mobile Android/iOS as well? (p.s. we have the same user avatar icon!)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Holes in procedural mesh 0 Answers

Creating a mesh out of a linerenderer - how do you convert revolved vertices set to triangles and uv's 1 Answer

Why does the default Unity sphere have duplicate vertices? 1 Answer

Unity is welding vertices when I enter Play mode 0 Answers

How to calculate normal direction for shared vertex position 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