Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by RyuMaster · Feb 25, 2013 at 12:07 AM · meshselectelement

Select mesh element

Hi! What is the approach to detect elements inside the mesh? Like, same to functionality that 3Ds Max Has - "select element"? I can think of some ways, but looping all over and looping all over seems more like workaround then solution to me, so before posting any of my pseudo code I'll gladly hear any advices on how to approach that task.

Comment
Add comment · Show 3
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 aldonaletto · Feb 25, 2013 at 12:28 AM 0
Share

Do you want to check if some object is inside a mesh or select a triangle in the mesh? If selecting a triangle, how do you want to define which triangle you want to select? Clicking it?

avatar image RyuMaster · Feb 25, 2013 at 12:37 AM 0
Share

What I want to do is store vertex indicies for every element, like:

backpockets [1,8,9,5,6.....] button [3,5,7,7,6]

So I want to think of some good algorithm which will irritate through mesh, detect elements, and store them thsi way

avatar image RyuMaster · Feb 25, 2013 at 08:58 PM 0
Share

Is someone ever searches this again, here is my solution:

 List<$$anonymous$$eshExtrusion.Edge> _borders = $$anonymous$$eshExtrusion.Build$$anonymous$$anifoldEdges(_mm);
                         Dictionary<int, Color32> _color$$anonymous$$eys = new Dictionary<int, Color32>();
 
 
 
 
                          while (_borders.Count > 0)
                          {
 
                              List<$$anonymous$$eshExtrusion.Edge> _takeusaway = new List<$$anonymous$$eshExtrusion.Edge>();
                              List<int> _candidates = new List<int>();
                              _candidates.Add(_borders[0].vertexIndex[0]);
                              List<int> _openNewSearches = new List<int>();
                              List<int> _searched = new List<int>();
                              Color32 _startingColor = new Color32((byte)(UnityEngine.Random.value * 255), (byte)(UnityEngine.Random.value * 255), (byte)(UnityEngine.Random.value * 255), 255);
 
 
                              while (_candidates.Count > 0)
                              {
                                  for (int p = 0; p < _candidates.Count; p++)
                                  {
                                      if (!_searched.Contains(_candidates[p]))
                                      {
                                          for (int s = 0; s < _borders.Count; s++)
                                          {
                                              //_openNewSearches.Add(_candidates[p]);
                                              if (!_openNewSearches.Contains(_borders[s].vertexIndex[1]))
                                              {
                                                  if (_borders[s].vertexIndex[0] == _candidates[p])
                                                  {
                                                      _openNewSearches.Add(_borders[s].vertexIndex[1]);
 
                                                      if (!_color$$anonymous$$eys.Contains$$anonymous$$ey(_borders[s].vertexIndex[1]))
                                                      {
                                                          _color$$anonymous$$eys.Add(_borders[s].vertexIndex[1], _startingColor);
                                                      }
 
                                                      if (!_takeusaway .Contains(_borders[s]))
                                                      {
                                                          _takeusaway .Add(_borders[s]);
                                                      }
 
 
                                                  }
                                              }
                                          }
 
                                          _searched.Add(_candidates[p]);
 
                                      }
 
 
                                  }
 
                                  _candidates = new List<int>();
                                  for (int g = 0; g < _openNewSearches.Count; g++)
                                  {
                                      _candidates.Add(_openNewSearches[g]);
                                  }
                                  _openNewSearches = new List<int>();
                              }
 
                              for (int i = 0; i < _takeusaway .Count; i++)
                              {
                                  _borders.Remove(_takeusaway [i]);
                              }
 
                          }

3 Replies

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

Answer by RyuMaster · Feb 25, 2013 at 09:45 PM

 List<MeshExtrusion.Edge> _borders = MeshExtrusion.BuildManifoldEdges(_mm);
                         Dictionary<int, Color32> _colorKeys = new Dictionary<int, Color32>();
 
 
 
 
                          while (_borders.Count > 0)
                          {
 
                              List<MeshExtrusion.Edge> _takeusaway = new List<MeshExtrusion.Edge>();
                              List<int> _candidates = new List<int>();
                              _candidates.Add(_borders[0].vertexIndex[0]);
                              List<int> _openNewSearches = new List<int>();
                              List<int> _searched = new List<int>();
                              Color32 _startingColor = new Color32((byte)(UnityEngine.Random.value * 255), (byte)(UnityEngine.Random.value * 255), (byte)(UnityEngine.Random.value * 255), 255);
 
 
                              while (_candidates.Count > 0)
                              {
                                  for (int p = 0; p < _candidates.Count; p++)
                                  {
                                      if (!_searched.Contains(_candidates[p]))
                                      {
                                          for (int s = 0; s < _borders.Count; s++)
                                          {
                                              //_openNewSearches.Add(_candidates[p]);
                                              if (!_openNewSearches.Contains(_borders[s].vertexIndex[1]))
                                              {
                                                  if (_borders[s].vertexIndex[0] == _candidates[p])
                                                  {
                                                      _openNewSearches.Add(_borders[s].vertexIndex[1]);
 
                                                      if (!_colorKeys.ContainsKey(_borders[s].vertexIndex[1]))
                                                      {
                                                          _colorKeys.Add(_borders[s].vertexIndex[1], _startingColor);
                                                      }
 
                                                      if (!_takeusaway .Contains(_borders[s]))
                                                      {
                                                          _takeusaway .Add(_borders[s]);
                                                      }
 
 
                                                  }
                                              }
                                          }
 
                                          _searched.Add(_candidates[p]);
 
                                      }
 
 
                                  }
 
                                  _candidates = new List<int>();
                                  for (int g = 0; g < _openNewSearches.Count; g++)
                                  {
                                      _candidates.Add(_openNewSearches[g]);
                                  }
                                  _openNewSearches = new List<int>();
                              }
 
                              for (int i = 0; i < _takeusaway .Count; i++)
                              {
                                  _borders.Remove(_takeusaway [i]);
                              }
 
                          }
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 friuns3 · Dec 07, 2013 at 12:36 AM 0
Share

Awesome! but seems it selects only edges? how to get all indices of element?

avatar image
0

Answer by Dante_CyberdeckGames · Mar 28, 2017 at 04:41 AM

I think this is a more straight forward solution, less code without pre-calculating edges. Explanation on my blog: http://dantefalcone.name/finding-linked-faces-elements-within-a-3d-model-mesh-with-unity3d-and-c/

 /// <summary>
 /// Given two faces, return whether they share any common vertices.
 /// </summary>
 /// <param name="faceA">Face represented as array of vertex indices.</param>
 /// <param name="faceB">Face represented as array of vertex indices.</param>
 /// <returns>bool - whether the faces are connected. </returns>
 bool IsConnected(int[] faceA, int[] faceB)
 {
     for (int i = 0; i < faceA.Length; i++)
         for (int j = 0; j < faceB.Length; j++)
             if (faceA[i] == faceB[j])
                 return true;
     return false;
 }
 
 /// <summary>
 /// Given a single triangle face of vertex indices, 
 /// returns a list of all the vertices of all linked faces.
 /// </summary>
 /// <param name="pickedTriangle">A known triangle to start search.</param>
 /// <param name="triangles">Triangle index list of all vertices in mesh.</param>
 /// <returns>List<int> - All triangle face indices that represent the surface element.</returns>
 public List<int> GetElement(int[] pickedTriangle, List<int> triangles)
 {
     // Create the return result list, 
     // starting with the current picked face
     List<int> result = new List<int>(pickedTriangle);
  
     // Iterate through the triangle list index buffer 
     // by triangle (iterations of 3)
     for (int i = 0; i < triangles.Count; i += 3)
     {
         // Select the (i)th triangle in the index buffer
         int[] curTriangle = new int[3] { 
             triangles[i], 
             triangles[i + 1], 
             triangles[i + 2] };
  
         // Check if faces are linked
         if (IsConnected(curTriangle, pickedTriangle))
         {
             // Recursively add all the linked faces to the result
             result.AddRange(GetElement(curTriangle, triangles));
         }
     }
  
     return result;
 }




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 indianalf · Jan 07, 2021 at 11:35 AM

Interesting but unfortunately the recursive call would iterate a billion times on complex objects so the connective test spot faces within a smoothing group only to extend by distances the time get quickly unacceptable ...

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

13 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

Related Questions

A node in a childnode? 1 Answer

Problem with non convex mesh colliders 4 Answers

Assign/add gameobject to LOD via script 1 Answer

C# Array of OtherArray's Meshes 1 Answer

Problems with Transform.Find and GameObject.find 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