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 8NeonBitGuy · Jul 10, 2014 at 06:22 PM · c#meshvector3random

Modify mesh problems

Hello, I've recently asked myself how could I make a random planet and my quick answer was modify the verts of a sphere randomly, but now, it is taking a lot of pain.

after some research this is my code:

     Mesh mesh;
     Vector3[] verts;
     Vector3[] normals;
     Vector3 WorldPosition;
     void Awake(){
         mesh = GetComponent<MeshFilter>().mesh;
         verts = mesh.vertices;
         normals = mesh.normals;
         for (int i=0; i<verts.Length; i++) {
             verts[i] += normals[i] * Random.Range(1f,1.2f);
         }
         mesh.vertices = verts;
         mesh.normals = normals;
         mesh.RecalculateNormals ();
         mesh.RecalculateBounds ();
         mesh.Optimize ();
     }

I use it on a sphere and a plane to check if its correct, in the plane it seems that there is no problem. Plane before and after code:

alt text alt text

But in the sphere something goes very wrong:

alt text alt text

it seems like the verts are duplicating or something weird, I tried Mesh.Clear() but that doesn't work.

Anyone have an idea how I can fix it?

Thanks

plane guay.jpg (191.4 kB)
plane modificado.jpg (194.8 kB)
Comment
Add comment · Show 4
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 robertbu · Jul 10, 2014 at 06:29 PM 0
Share

It appears that Unity's sphere does not always share vertices. I cannot think of a simple solution. Some ideas:

  • Detect all vertices that are equal or nearly equal, then redo the triangle indices so that only one of the equal vertices is used.

  • Detect when vertices are equal or nearly equal and do the same modification you are doing above to both.

  • Construct (or have some construct) a sphere that shares all vertices.

avatar image lukas_balaz · Jul 10, 2014 at 06:39 PM 0
Share

just go to 3ds max, c4d, blender or whatever, create new sphere, export it to .fbx and load in unity

avatar image 8NeonBitGuy · Jul 10, 2014 at 07:07 PM 0
Share

Thanks a lot guys, I tought it was the double vertices and I found a solution to it, first I modify a vert and then I check if there is the same vert.

avatar image lukas_balaz · Jul 11, 2014 at 10:26 AM 0
Share

but I think it is still better to export sphere from c4d, because double vertices can cause more troubles (if you want to do something with mesh)

1 Reply

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

Answer by 8NeonBitGuy · Jul 10, 2014 at 07:56 PM

After thinkin a few hours more this is my solution.

 for (int i=0; i<verts.Length; i++) {
             tempVert=verts[i];
             if(verts[i]!=initVerts[i]){ 
                 Debug.Log ("this vert has been already modified");
                 continue;
             }
             verts[i] += normals[i] * Random.Range(1f,1.2f);
             for(int j=0; j<verts.Length;j++){ 
                 if(i==j){ 
                     Debug.Log ("its the same vert");
                     continue;
                 }else{
                     if(verts[j] == (tempVert)){ 
                         Debug.Log ("Double vert");
                         verts[j]=verts[i];
                     }
                 }
             }
         }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How would you go about shaping terrain with scripting? (C#) 1 Answer

Bullet bounces off the wall 2 Answers

Trouble with Null Reference in Script 2 Answers

Having Trouble with Vector3.Angle 1 Answer

Array index is out of range 2 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