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 Kitboga · Mar 01, 2015 at 08:16 AM · meshblendersphere

Randomize Sphere & Smooth Vertex ( like in blender)

I'm looking to take a sphere mesh and randomize the height as well as smooth the vertex just like i'm able to do in blender (only I want to do this in C# within unity)

In blender when I have a sphere selected and click randomize, I am able to see different height and depth added to the sphere and there are no holes or problems.

My code:

 Mesh mesh = GetComponent<MeshFilter>().mesh;
 Vector3[] vertices = mesh.vertices;
 float [][] verticesArray;// = new float [vertices.Length][3];
 verticesArray = new float [vertices.Length][];
     
     int vertexCount = mesh.vertexCount;

     int j = 0;
     while (j < vertices.Length)
     {
         verticesArray[j] = new float [3];
         
     

         Vector3 vUp = Vector3.MoveTowards(vertices[j],Vector3.zero, .05f);

         vertices[j] = vUp * Random.Range(0.9f, 1.1f);

         
         j++;
     }

I'm trying to have the vertices move upwards (opposite of the direction towards the center) with some variation - but the sphere has a lot of gaps and is not smooth.

Please help !

Here is what is happening in Unity.... alt text

Here is what I'm trying to do in unity (the picture is while using blender)

desired_planet

planet.jpg (57.8 kB)
unity.jpg (66.5 kB)
Comment
Add comment · Show 2
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 tanoshimi · Mar 01, 2015 at 08:47 AM 0
Share

How do you mean "smooth"? Your desired result looks faceted - anything but smooth to me! Have you tried the procedural examples of mesh deformation?

avatar image Kitboga · Mar 02, 2015 at 12:06 AM 0
Share

Sorry for the confusion - i posted a picture of the result in unity. There are gaps in the sphere.

1 Reply

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

Answer by maccabbe · Mar 02, 2015 at 12:57 AM

It seems like you have multiple vertices in certain locations which is why the mesh appears to be tearing.

You can either

  1. Group together vertices that are in the same location and set all their new locations to the same position.

  2. Use perlin noise to generate the same value for vertices in the same location. It I had to take a guess, blender probably uses perlin noise for the picture you provided.

  3. Have only one vertex per position. However this would make flat shading difficult since vertices would be on multiple faces and can only have one normal.

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 Kitboga · Mar 02, 2015 at 12:59 AM 0
Share

Thanks for your input. Can you show via code how I could group vertices or achieve this ?

avatar image maccabbe · Mar 02, 2015 at 07:20 AM 0
Share
 void Randomize(Vector3[] verts){
     Dictionary<Vector3, List<int> > dictionary=new Dictionary<Vector3, List<int> >();
     for(int x=0; x<verts.Length; x++){
         if(!dictionary.Contains$$anonymous$$ey(verts[x])) {
             dictionary.Add(verts[x], new List<int>());
         }
         dictionary[verts[x]].Add(x);
     }
     foreach($$anonymous$$eyValuePair<Vector3, List<int>> pair in dictionary) {
         Vector3 newPos = pair.$$anonymous$$ey*Random.Range(0.9f, 1.1f);
         foreach(int i in pair.Value) { 
             verts[i]=newPos;
         }
     }
 }

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

2 People are following this question.

avatar image avatar image

Related Questions

Problems with importing Blender object 1 Answer

Object from blender having it's mesh changed when importing to unity 1 Answer

Blender Mesh rotation 3 Answers

Is there a way to replace blend files with fbx files in the Assets folder, but keep the mesh references? 0 Answers

Exporting files from blender to unity 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