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 /
  • Help Room /
avatar image
0
Question by DaedricWolf19 · Nov 22, 2015 at 08:04 PM · meshverticestrianglesfacetriangle

Getting face of mesh when you already have one tri

I currently have a setup where the user can select one tri of a face of a mesh but i want my program to find the other tri and thus have the entire face.

Currently i was trying to compare my current points with the vertices table and find two matching points that both tri's share and the missing one so i could have a whole face but it doesn't seem to work. Here's my code.

Find tri selected(WORKS):

  void Update()
     {
        
         Ray ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
 
       
         RaycastHit hit = new RaycastHit();
        
         if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity))
         {
          
             Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.red);
     
 
             if (Input.GetMouseButtonDown(0))
             {
                int ind = hit.triangleIndex;
                hitTransform = hit.collider.transform;
                Debug.Log("Hit tri index is " + ind * 3);
 
                 SelectFace(hit);
             }
         }
     }
 
     void SelectTriangle(RaycastHit hit)
     {
         int ind = hit.triangleIndex;
         Vector3 point0 = vertices[triangles[ind * 3]];
         Vector3 point1 = vertices[triangles[ind * 3 + 1]];
         Vector3 point2 = vertices[triangles[ind * 3 + 2]];
 
         point0 = hitTransform.TransformPoint(point0);
         point1 = hitTransform.TransformPoint(point1);
         point2 = hitTransform.TransformPoint(point2);
 
        
         Debug.DrawLine(point0, point1, Color.red);
         Debug.DrawLine(point1, point2, Color.red);
         Debug.DrawLine(point0, point2, Color.red);
     }

Select Face(NOT WORKING):

    void SelectFace(RaycastHit hit)
     {
         int ind = hit.triangleIndex;
         Vector3 point0 = vertices[triangles[ind * 3]];
         Vector3 point1 = vertices[triangles[ind * 3 + 1]];
         Vector3 point2 = vertices[triangles[ind * 3 + 2]];
         Vector3 point3 = new Vector3(0,0,0);
         
 
         for(int i = 0; i < triangleCount; i++)
         {
             int pointCount = 0;
             bool point0t = false, point1t = false, point2t = false;
 
             Vector3 V1 = vertices[triangles[i * 3]];
             Vector3 V2 = vertices[triangles[i * 3 + 1]];
             Vector3 V3 = vertices[triangles[i * 3 + 2]]; 
 
             List<Vector3> al = new List<Vector3>();
   
 
             al.Add(V1);
             al.Add(V2);
             al.Add(V3);
 
 
 
             if (al.Contains(point0))
             {
                 pointCount += 1;
                 point0t = true;
 
                 Debug.Log("CONTAINS POINT 0");
             }
 
             if (al.Contains(point1))
             {
                 pointCount += 1;
                 point1t = true;
 
                 Debug.Log("CONTAINS POINT 1");
             }
 
             if (al.Contains(point2))
             {
                 pointCount += 1;
                 point2t = true;
 
                 Debug.Log("CONTAINS POINT 2");
             }
 
             if(pointCount == 2)
             {
                 Debug.Log("MATCH");
 
             }
 
 
             if (point0t == false)
             {
                 point3 = point0;
             }
 
             if (point1t == false)
             {
                 point3 = point1;
             }
 
             if (point2t == false)
             {
                 point3 = point2;
             }
 
           
             // Debug.Log(point3);
         }
         // Debug.Log(point3);
         point0 = hitTransform.TransformPoint(point0);
         point1 = hitTransform.TransformPoint(point1);
         point2 = hitTransform.TransformPoint(point2);
         point3 = hitTransform.TransformPoint(point3);
 
         Debug.DrawLine(point0, point3, Color.red);
         Debug.DrawLine(point1, point3, Color.red);
         Debug.DrawLine(point2, point3, Color.red);
 
         Debug.DrawLine(point0, point1, Color.red);
         Debug.DrawLine(point1, point2, Color.red);
     }

Any help would be appreciated, thanks! :)

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

0 Replies

· Add your reply
  • Sort: 

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

36 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 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

How is a Mesh Built? 1 Answer

How can I identify the location of mesh triangles at run time? (Procedural Generation) 1 Answer

URGENT How to get triangles of mesh in world space? 0 Answers

Generating Mesh using Points 1 Answer

How can I remove shooted mesh of object? 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