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 eric_c · Dec 07, 2012 at 05:09 AM · meshdirectionvertexsweeptestpositon

Sweep for vertex positions?

Hi, I wrote a script that would find the position and direction of the vertices of a mesh. How do I do somewhat like a 360 sweep from the player's position to arrange the positions of vertices from 0 to 360 degrees?

 function Update () 
 {
     var wallVerts = target.GetComponent.<MeshFilter>().mesh.vertices;
     var wallVertLength = wallVerts.length;
     
     for (var i:int=0;i<wallVertLength;i++)
     {
 
         var vertPos = target.transform.TransformPoint(wallVerts[i]);
         var dir = (vertPos - transform.position).normalized;
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 eric_c · Dec 07, 2012 at 08:13 AM 0
Share

Seems like there's no other way rather than doing it the long way. I'm trying to sort the vertices in a clockwise manner so that I can use the information to "fill" the vertices with tris properly rather than having them form in completely random patterns each time I return the array.

avatar image Fattie · Dec 11, 2012 at 02:37 PM 0
Share

can't help on this one, good luck EricC !

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 08, 2012 at 10:31 AM

I'm also a bit lost on this question. Just sorting the vertices in a circle around one axis won't help you to generate a proper mesh. Do you have already your triangle list? Do you just want to make a blend-in-animation?

Anyway, sorting (no matter what) requires you to have a value you can sort on. In your case you need the angle from a certain start direction. Since we are in 3D you have to sort around one axis first. So to do the angle calculation i would "project" the direction to an axis aligned plane (x-z-plane for example so you rotate yround the y-axis)

 import System.Collections.Generic;
 
 class SortVertex
 {
     var index : int;
     var angle : float;
 }

 static function compare(A : SortVertex, B : SortVertex) : int
 {
     return A.angle.CompareTo(B.angle);
 }


 function DoIt()
 {
     var wallVerts = target.GetComponent.<MeshFilter>().mesh.vertices;
     var wallVertLength = wallVerts.length;
     var wallVertValues = new List.<SortVertex>(wallVertLength);
     
     for (var i = 0; i < wallVertLength; i++)
     {
         var vertPos = target.transform.TransformPoint(wallVerts[i]);
         var dir = (vertPos - transform.position);
         dir.y = 0.0f;
         dir.Normalize();
         var V = Mathf.Atan2(dir.z, dir.x);
         var SV = new SortVertex();
         SV.index = i;
         SV.value = angle;
         wallVertValues.Add(SV);
     }
     wallVertValues.Sort(compare);

     for (var vert in wallVertValues)
     {
         var P = wallVerts[vert.index];
         // Process the vertices here in a sorted manner
     }
 }

Note: Sorting, expecially a lot elements, can become quite slow. You should prepare the data once and save it somehow.

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

11 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

Related Questions

Create a Wireframe Shader with Shader Forge 1 Answer

Mesh breaks apart when using vertex displacement with shadergraph. 3 Answers

Reding from Mesh.colors doesn't display vertex colors of fbx 0 Answers

when I try to move the vertices of a cube a face disapears though the vertices stay intact 1 Answer

Access skinned 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