Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Change a Triangle's Submesh

Discussion in 'Scripting' started by an, Jan 10, 2014.

  1. an

    an

    Joined:
    Oct 6, 2009
    Posts:
    146
    Dear CommUnity,

    I simply want to change the submesh a given triangle belongs to, in order to assign a different material.
    Do you have any idea what to do?

    My current approach is to add the triangle to the new submesh:
    1. retrieve all triangles of the new submesh (GetTriangles)
    2. add the given triangle to those triangles
    3. reassign the triangles to the new submesh (SetTriangles).

    It works, but unfortunately the 'old' triangle persists, so now i've got 2 triangles.
    Therefore, I have to further delete the triangle from the old submesh

    4. retrieve all triangles of the old submesh (GetTriangles)
    5. remove the given triangle from those
    6. reassign the triangles to the old submesh(SetTriangles)

    But as you can see, it's seems kind of too much for such a simple task, moreover the manual triangle array deletion gets really messy as the indices shift etc.


    I'm sure there's a simpler way to handle this relatively easy task!

    Thanks so much
     
    Last edited: Jan 10, 2014
  2. an

    an

    Joined:
    Oct 6, 2009
    Posts:
    146
    *shameless crying-for-help selfbump*
     
  3. mmerlange

    mmerlange

    Joined:
    Jan 22, 2013
    Posts:
    9
    Hum, I'm now messing with the same stuff. Did you find a clever way?
    Thks,
    Michael