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 techspy · Apr 11, 2016 at 08:11 AM · mesh-deformationvertice manipulation

Deform shared vertices only on a planee

This is my first post here, i just moved from NeoAxis. i've been searching and trying for hours and im stuck. i have a cube-sphere made from 6 planes. i am deforming the planes using this code -

C# code aPlane.transform.aPoint(vertices[i]).normalized * this.radius + (randomFloat));

this gives me rather large gaps where my planes join. my question is, how can i separate between shared and non-shared vertices, adding the randomfloat to shared/non-edge vertices.

psedo code would be

C# code

Vector3[] vertices = mesh.vertices; //maybe add int[] tris = mesh.triangles? if (vertice is shared) add randomfloat; else deform without randomfloat;

im quite certain i need to create an array and add triangle vertices and check if the vertices belong to one triangle or two/more triangles.

Everything is generated from code and this is for a hobby project. i already have planet generators from the Asset store but if i use those i might as well just slap together Asset store content and put my name on it.

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 Eno-Khaon · Apr 11, 2016 at 09:17 AM

For reference, Unity's mesh optimization works by separating out numerous fields: vertices, normals, colors, tangents and uvs are all contained in arrays of equal size; there's one of each of those per vertex. Then, triangles are stored in an integer array in groups of three, with those integers acting as a guide for a corresponding vertex.

In the case of a cube shape, you'll likely have 12 triangles (2 per face, 6 faces). Beyond that, you have a choice to make with a model...

Because vertices and normals are shared 1:1, you can either have fewer vertices with rounded corners from interpolation between the normals or you can have more vertices with hard edges. Therefore, a 6-sided cube with rounded normals (to loosely resemble a sphere) would have as few as 8 vertices, a typical 24 vertices, or a maximum of 36 vertices, by having no duplicate vertices, individual faces in groups of 4, or individual triangles with 6 per face respectively.

That said, no matter the vertex count, you'll always have a 36-size array for triangles for a cube, in order to accommodate all 12 triangles.

With all of that in mind, it should be reasonably easy enough to determine which vertices share a location, but the triangle array can't help you here. Because you'll always have 36 triangle array entries on a cube, you can't tell the difference between any two variants of a cube. But if it looks like a cube and has hard edges, you can likely assume that two or more vertices share the same position.

Therefore, in order to manipulate their positions, you'll need to run through the array and find which vertices do share a position (i.e. v[x] == v[y]). Caching the results would likely involve an array of arrays (or a class/struct containing said array, etc.), due to the possibility of a variable array size per reused vertex position.

Once you've found matches, give them a collective normal by adding their normals together, then dividing by the number of vertices sharing the position (and normalize the result). Now, you have your new displacement normal to apply to each of those vertices shared at that position (which could also be applied to the same class/struct containing the array of vertices sharing a position).

By association, going back to another detail, this also means that any vertex in the mesh which doesn't share a position with another vertex is unique (barring extreme circumstances where the mesh has extraneous vertices with no connections). If a vertex is determined to have not shared a position with any other vertex, then you can generally assume that displacement of that vertex will not leave any holes (again, unless the mesh had construction problems in the first place).

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 techspy · Apr 12, 2016 at 09:54 AM 0
Share

I'm sorry about the poor formatting, I posted from a mobile phone.

I managed to get as far as using a class to store each vertex position, normals and uv data by creating a new instance of my custom class object. Beefore i got to comparing vertex values I got a suggestion from elsewhere to use a Noise function and get rid of my random float and the results were not so bad. To quote D$$anonymous$$Gregory from StackExchange, " Seed the noise lookup with the original position of your vertex. Since shared vertices have the same position, they'll get the same displacement, keeping them tightly joined."

For educational purposes, I am going to complete your suggested solution and report back my results.

avatar image Eno-Khaon techspy · Apr 12, 2016 at 10:11 AM 0
Share

That's certainly an option for an approach, as well. Using a structured pseudo-randomization (i.e. noise) will return reliable values based on input, so you would definitely see identical results for each vertex in matching positions.

Relying on that alone, however, would not account for the original objective of ai$$anonymous$$g for a combined set of normals for a reliable position offset. Unless you're strictly working from a basis of pushing vertices away from a defined center (basically, supporting only spherical shapes), it may be very challenging to find a scheme which can reliably simulate the same effect you would get from modifying vertex positions based on their normals.

Either way, a noise function would provide a very reliable and reproducible displacement with greater consistency and smoothness than pure randomization would offer, so that's certainly handy to make use of.

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

Adding vertices to procedural mesh generator 2 Answers

Flattening a mesh by deforming it 0 Answers

Selectively deform a mesh by dragging? 0 Answers

Can I assign multiple UV's coordinates for a vertex? 1 Answer

Mesh Deformation Help (Or other means of creating small scale destruction) 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