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 /
  • Help Room /
avatar image
0
Question by thefoofighter · Mar 18, 2017 at 06:53 PM · meshgameobjectsverticesprocedural meshlooping

Issue with Modifying Vertices of multiple Game objects

Hi,

I have a script which loads a mesh and basically outputs a game object per triangle. That part works great.

Now I am trying to add noise to these individual Game object triangles vertices in Update() only for my vertices to take the vertices previous positions and add the noise to that.

What I want it to do is only ever add the noise to the original vertex positions which were set in Start() and come from the original meshes triangles vertices.

If i pause The game before running i see that the first frame does exactly what i want, but i notice that the triangles disappear into space as the game updates.

To keep the question short I will only post the update loop since I am fairly sure that is where the issue lies.

The code is a little bit of a mess at the moment as its all wip so please excuse it, Also I am fairly new to Unity and rusty in general at C#

void Update() { // Generate some Noise to apply to vertices later setNoise();

     // Loop over all Triangle Game Objects
     for (int i = 0; i < _triangles.Length; i++)
     {
         // Grab the Mesh Component
         _triangleMeshFilter = _triangles[i].GetComponent<MeshFilter>();
         Mesh mesh = _triangleMeshFilter.mesh;
         Vector3[] triangleVerts = new Vector3[3];

         // Set the vertices to a temporay array
         triangleVerts = mesh.vertices;

         // Loop over the vertices in the GameObject (Should only be three)
         for (int j = 0; j < triangleVerts.Length; j++)
         {
             // Set a Color to the UV locations of the Vertices
             Color tri_Noise = texture.GetPixelBilinear(mesh.uv[j].x, mesh.uv[j].y);

             // The temporay vertex array is modified by multiplying the Color value by the current vertex values
             var temp = triangleVerts[j];
             triangleVerts[j] = Vector3.Scale(temp, new Vector3(tri_Noise.r, tri_Noise.g, tri_Noise.b));
         }

         // Set the actual mesh vertices to updated vertices
         mesh.vertices = triangleVerts;
     }
 }

What I have tried so far to no avail is:

I have created a giant vertex array when i create the triangle initially and then looped over that in the update instead. this was messed up somehow but the vertices did not fly into space.

I copied the array of triangle Gameobjects into a new array in Start() and used that as the lookup in Update() for every loop of triangle objects

I am assuming that the issue is here:

 triangleVerts = mesh.vertices;

Am I missing something really simple or is this just not possible?

Here is a link to a sample scene incase I am not very Clear above. Click pause before play and you will see what i expect to always see, A Cube with noise applies and distorted. But if you continue it disappears into the abyss

Thank you for any help you can give :)

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

0 Replies

· Add your reply
  • Sort: 

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

99 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Some triangles are black on a mesh generated by script 1 Answer

Shared or Non-shared Vertices for mesh generation? 0 Answers

Procedural Mesh Problems 0 Answers

How is a Mesh Built? 1 Answer

How can I identify the location of mesh triangles at run time? (Procedural Generation) 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