- Home /
Duplicate and separate triangles from a mesh
I have an icosphere class that I'm trying to use as a grid of sorts (Think Civilization on a sphere). I can create and subdivide the icosphere already and I have a stored List of the vertices and triangles.
Where I'm running into trouble is separating those triangles and making each into its own "Tile" gameObject that can have its own parameters and material.
I would try something as simple as:
public List tiles;
foreach( var tri in triIndex ) {
tiles.AddTile( new Tile( tri.v1, tri.v2, tri.v3 ));
}
...but I can't use "new" to create MonoBehaviour inheritors, and I need that functionality.
If anyone has a solution, or can offer any wisdom at all, it would be greatly appreciated.
Answer by robertbu · May 14, 2014 at 04:17 AM
You don't really give me enough code here to parse what you are doing and what you want to do. Assuming that 'Tile' is a component, you can do something like:
GameObject go = new GameObject();
Tile tile = go.AddComponent<Tile>();
tile.SetVertices(tri.v1, tri.v2, tri.ve);
tiles.Add(tile);
SetVertices() is a method you'd have to write for the Tile class. Note you would also have to change the first line to:
public List<Tile> tiles = new List<Tile>();
Again this is just a guess based on incomplete information about your problem.
This actually ended up being exactly what I needed to do, although for some reason I had to set each of my vertices individually as trying to do so with a function threw a null pointer reference error.
Thank you so much for your help.
Your answer
Follow this Question
Related Questions
How to colorize a face of a Mesh 0 Answers
Weird triangle indexing problem 1 Answer
Procedural Cylinder Generation 2 Answers
Procedural generated mesh problem 1 Answer
A node in a childnode? 1 Answer