Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
4
Question by JackMini36 · Dec 05, 2014 at 02:09 PM · c#mesh3dpointspolygon

create a polygon mesh from a set of points

I have a set of points (empty objects), and I want to create a polygon based on their position. I tried the Triangulator class but when I use more than 4 points, I get weird results. Is there any other way to accomplish this?

I have also been looking on creating a spline of empty objects and create the mesh based on them and my desired width from center, but again with no luck.

I am looking for a solution for any of the above approaches. Here is a screenshot of the points. alt text

road-points.jpg (88.8 kB)
Comment
Add comment · Show 5
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 komodor · Dec 05, 2014 at 02:28 PM 0
Share

do you need to use it in runtime on in editor ?

actually the secont question ... do you need to make the road only? like quads only ?

avatar image JackMini36 · Dec 05, 2014 at 02:31 PM 0
Share

I dont need the mesh to be generated in editor, just in runtime. But I will set up the points in editor like the picture.

avatar image JackMini36 · Dec 05, 2014 at 02:35 PM 0
Share

@komodor Actually I need to re-do the road system, because the 3D designer that did the city, did ALL the roads as one objects, so I can not apply AI and road detection easily. I need to know on which specific road my car is.

avatar image komodor · Dec 05, 2014 at 02:36 PM 0
Share

and the road/quad ... is it like ... 2 lines of points you want to connect with triangles (2 triangles make the road block panel) ? because this is pretty simple to generate, even crossroards, but i am not sure with complicated shapes

avatar image JackMini36 · Dec 05, 2014 at 02:39 PM 0
Share

well this is what I am trying to accomplish, but the shape of the 2 lines will not be always a rectangle. The points will shape polygons in the shape of roads (just without curves)

1 Reply

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

Answer by komodor · Dec 05, 2014 at 02:40 PM

well:

http://docs.unity3d.com/ScriptReference/Mesh.html

this is what u need to master, generally you have to generate the mesh by defining points, triangles, colors and uvs (i guess the last two aren't so important now and you will understand it)

vertices are the points you have (coordinates are local to the mesh pivot)

triangles is 3x longer then vertices array and it's array of INDEXES from the vertices array (not values)

and then u just give those two arrays to the mesh (after clearing the mesh or creating new)

 Mesh mesh = GetComponent<MeshFilter>().mesh;
         mesh.Clear();
         mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0)};
         mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)};
         mesh.triangles = new int[] {0, 1, 2};
Comment
Add comment · Show 1 · 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 JackMini36 · Dec 05, 2014 at 02:47 PM 1
Share

Thank you, this is really helpful. These are all very new to me but I think I understand now. Well, I will give it a try.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do i access the MeshExtrusion.cs from Unity's PE? 1 Answer

Mesh creation by code not working? 0 Answers

How do i have a Vector3[] position be in another Vector3[] position (That Updates)?? 1 Answer

How do i cast mesh like a linerenderer? 0 Answers

How do i make an object move around a 3D mesh? 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