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 WilliamFerdinand · Jan 21, 2017 at 08:53 AM · mesharrayscript.vertices

Isolation of different vertices on a mesh

Hi, I have an icosphere (imported from blender) and I made an array of its 42 vertices. My question is how can I program the mesh to where the vertices can be manipulated/programmed individually. Can this be done by using the array or is there another function used to do this. I searched the Manuel and API and didn't find much insight on this so are there any videos or other documentation that is related to this form of programming. Thank you for your time.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 21, 2017 at 09:12 AM

You edit the vertices as you want, and then assign the array back to Mesh.vertices.

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

Answer by slammin · Jan 22, 2017 at 08:13 AM

Every mesh has a MeshFilter. To access a GameObject's MeshFilter, use

MeshFilter mf = GetComponent< MeshFilter >();

Note that the code I'm providing might be incomplete depending on your circumstances.

Once you have the MeshFilter, you can access the MeshFilter's mesh's vertices and triangles:

mf.mesh.vertices

mf.mesh.triangles

It's probably best to copy these arrays into new arrays using the CopyTo command, the new arrays having respective lengths of mesh.vertices.length and mesh.triangles.length. Remember that the vertex array is a Vector3[] and the triangles array is an int[]. Let me re-iterate -- it's probably best that you create a copy of the original arrays (vertices and triangles) just so you don't lose the original data and then create one or more more set of arrays (vertices and triangles) that you can edit and assign to the mesh.

mf.mesh.vertices.CopyTo(array to copy to, 0); mf.mesh.triangles.CopyTo(array to copy to, 0);

The vertex array (mf.mesh.vertices) is all of the vertices that compose the mesh. The tricky part is the triangle array (mf.mesh.triangles) which defines the triangles by pointing to specific vertices in the vertex array. Every triangle is composed of three points (three specific vertices in the vertex array). Therefore, the first triangle in the triangle array is defined by the first three entries (0, 1, 2) the second triangle is defined by the second three entries (3, 4, 5) and so on. If the first triangle is defined by the 3rd, 9th, and 12th vertex in the vertex array, then,

triangles array = (3,9,12,...);

Note that the order in which vertices are defined (clockwise or counterclockwise) is important as it determines which way the face of the triangle will be visible.

Once you are done editing the vertex array and triangles array you have to re-assign these two arrays to the mesh:

mf.mesh.Clear();

mf.mesh.vertices = the new vertex array;

mf.mesh.triangles = the new triangle array;

mf.mesh.RecalculateBounds();

mf.mesh.RecalculateNormals();

That is just the basics of it for a non-rotating, non-moving mesh. If you actually are creating a UI that can push and pull vertices, that is on you. To select vertices when left clicking on them you might want to create invisible spheres that are on each vertex and then useRaycasts to determine which sphere you are hovering over. Use input methods to determine when you left click and then you should be able to isolate which vertex you clicked on. There's some code to it. Hope I answered your question.

Good luck!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to assign mesh.vertices ToList linq extension 1 Answer

Multiple Meshes 0 Answers

How do I get rid of intersecting vertices between two gameobjects? 0 Answers

Altering specified vertices on a mesh 0 Answers

Assigning new Mesh Vertices 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