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 chilunliu · Jan 23, 2014 at 03:40 PM · mesh verticesmesh manipulation

how to get all points along a mesh

Hi all; I have a problem at the moment in which I'm trying to get all the points along a mesh object I've created using a c# script. Any advise will be greatly received. Here is the screenshot of the mesh:

alt text

Code to do all this:

 using UnityEngine;
 using System.Collections;
 
 public class CreatePlaneMesh : MonoBehaviour {
 
     public float width = 50f;
     public float height = 50f;
 
     public Material mat; // material variabl
 
     // Use this for initialization
     void Start () {
         gameObject.AddComponent<MeshFilter>();
         MeshFilter mf = GetComponent<MeshFilter>();
         Mesh mesh = new Mesh();
         mf.mesh = mesh;
 
 
 
         //vertices
         Vector3[] vertices = new Vector3[4]; //create 4 slots to store vectors to create plane
 
         vertices[0] = new Vector3 (width, 0, 0);
         vertices[1] = new Vector3 (width, 0, height);
         vertices[2] = new Vector3 (0, 0, height);
         vertices[3] = new Vector3 (0, 0, 0);
 
         mesh.vertices = vertices;
 
         //get all vertex positions of the mesh object
         mesh = GetComponent<MeshFilter>().mesh;
         Vector3[] v = mesh.vertices;
         int i = 0; while (i < v.Length){
             v[i]+= Vector3.up * Time.deltaTime;
             i++;
         }

     vector3[] worldPOS = new Vector3[4];
             for(int j=0; j < 4; j++) {
             worldPOS = new vector3(transform.Transformpoint(verices[j])));
 }


         mesh.vertices = vertices;
         mesh.RecalculateBounds();
         //
 
         
         int[] indices = new int[6];
         
         indices[0] = 0; indices[1] = 3; indices[2] = 2;
         indices[3] = 0; indices[4] = 2; indices[5] = 1;
 
         mesh.SetIndices(indices, MeshTopology.Triangles, 0);
 
         gameObject.AddComponent<MeshRenderer>();
         MeshRenderer mr = GetComponent<MeshRenderer>();
         mr.material.color = Color.green;
         mesh.RecalculateNormals();


Error message: The type 'UnityEngine.Vector3' does not contain a constructor that takes '1' arguments

capture.png (22.4 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 Owen-Reynolds · Jan 23, 2014 at 03:55 PM 0
Share

What do you mean by "all the points"? You clearly have them all now, in lines 23-26.

Do you mean the verts in world space? In that case, just use the standard way: planeA.transformDirection(someVert);

avatar image chilunliu · Jan 23, 2014 at 06:28 PM 0
Share

I mean points by obtaining all the vertex positions in the world space as I'm looking to do some sub-dividing of spaces for a procedural terrain project I'm currently working on. So the idea would be to obtain a random position along one of the edges of the mesh and then find another random position on the opposite edge so I can draw a line to simulate the partitioning. The idea is to keep repeating the process until I have enclosed spaces in which I can place objects such as buildings, trees and so on. Thanks for your response, I will try your suggestion.

1 Reply

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

Answer by robertbu · Jan 23, 2014 at 06:33 PM

The verties in a mesh are in local coordinates. To convert local coordinaes to world coordinates use Transform.TransformPoint():

 Vector3 worldPos = transform.TransformPoint(v[i]);
Comment
Add comment · Show 8 · 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 chilunliu · Jan 23, 2014 at 06:48 PM 0
Share

Thank you very much robertbu.

avatar image Bunny83 · Jan 23, 2014 at 07:02 PM 0
Share

Is your question answered? If so please tick the answer as solution to mark this question as answered:
Tick an answer

avatar image chilunliu · Jan 24, 2014 at 10:48 AM 0
Share

I ran into an array out of index error then trying to insert the line into the code

avatar image robertbu · Jan 24, 2014 at 02:49 PM 0
Share

Can you edit your question to include he changed code? And can you include the error message from the console? Note that this line must be executed inside your 'while' loop for each point in the array. If you execute it outside the 'while' loop, then 'i' will be beyond the end of the array.

avatar image chilunliu · Jan 24, 2014 at 03:01 PM 0
Share

Question edited - lines 38-41. Error message at the bottom.

Show more comments

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

20 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

Related Questions

Animating the Mesh Morpher on function call. 0 Answers

Perlin Noise on Torus Terrain? 0 Answers

How to manipulate(flatten) the Mesh of an object 0 Answers

How to simulate drilling/welding/cutting a mesh? 1 Answer

Is it possible to enable Read/Write of a imported Mesh at Runtime? 0 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