Comments and answers for "Generate and extrude a mesh"
http://answers.unity.com/questions/264204/generate-and-extrude-a-mesh.html
The latest comments and answers for the question "Generate and extrude a mesh"Comment by rlmattospt on rlmattospt's answer
http://answers.unity.com/comments/264529/view.html
I was actually thinking about it.
We have a script that makes that to create the level.
I could just switch the prefabs for ground and walls to very low-poly ones and intantiate them. It would still be a little heavier then what I was looking for, but it is simple enough and does the job.
I think I will go with that aproach.
Thank you all for the help. All the answers were very helpfull.Fri, 08 Jun 2012 14:54:01 GMTrlmattosptAnswer by Fattie
http://answers.unity.com/answers/264401/view.html
There is an unbelievably simple way to do this.
It is almost impossible you would go about actually building mesh on the fly to achieve this incredibly simple need.
Here is the method:
1) Make yourself A BOX.
2) If there is a "1" there, use this Unity command: "Instantiate"
I hope this has helped.Fri, 08 Jun 2012 08:11:29 GMTFattieComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/264281/view.html
I know you said *you are about* to create a script, but a lot people here just expect to get a complete script they can copy & paste ;)
You should first get familiar with <a href="http://unity3d.com/support/documentation/ScriptReference/Mesh.html">Unity's Mesh class</a>. Unity uses indexed triangles exclusively. That means you have one vertex array and one index array. The vertex array is made up of several arrays in Unity. They are vertices, normals, tangents, uv, uv2 and colors. The index array is the triangles array. You don't need all vertices arrays, only those that are required by the shader you want to use.
The index array contains integer values that are indices into the vertex array. The indices count is always a multiple of 3 because you need always 3 vertices to form a triangle ;)
So if you have a triangles array with these values: 0,1,2, 0,2,3
It will create 2 triangles which share the vertex 0 and 2, so they form a quad if the vertices are aranges in a square.Fri, 08 Jun 2012 00:22:49 GMTBunny83Comment by rlmattospt
http://answers.unity.com/comments/264267/view.html
Is there a way to know in which oreder I'm reading the vertices?
For instance if I create the first 4:
. .
. .
How can I know that the next two I create will be concted with the rightmost two?Thu, 07 Jun 2012 23:42:57 GMTrlmattosptComment by rlmattospt on rlmattospt's answer
http://answers.unity.com/comments/264261/view.html
Thanks,
Reading again my question I guess it may lead to think that I'm asking for a script, although I'm not.
My question is to know some aproach to the issue (wich fortunately you gave!).
About your answer: to create an triangle is it something simmilar to OpenGL where you create, for instance 3 vertices an it closes a triangle? Or there are some function that creates a face based on the vertices you pass as reference?Thu, 07 Jun 2012 23:38:12 GMTrlmattosptAnswer by Bunny83
http://answers.unity.com/answers/264244/view.html
It depends on how optimised you want it. If you "extrude" square by square you will have a lot unnecessary triangles in between. It would be much simpler to create the mesh from scratch based on your array.
There is no easy solution for this problem / task. You have to do it yourself. Don't ask others to write scripts for you. If you have a specific problem, ask a question.
If you want to do a simple square by square extrude, just do it like this:
I guess you have this plane mesh you've showed in the left picture:
- go through all squares in the mesh (2 triangles)
- use the number from your array to determine if you want to extrude the triangle or not
- delete the 2 triangles of the square (remove the 6 indices).
- Duplicate the 4 vertices and move them upwards.
- Create the vertices for the sides (the same positions as the others but with other normal vectors)
- create your 10 triangles (5 x 2)
But again, it's propably even simpler to create it from scratch based on your array.Thu, 07 Jun 2012 23:15:47 GMTBunny83Comment by MasterGalaxy
http://answers.unity.com/comments/264238/view.html
The big issue is that you have to create vertices, but you extrude faces... In other words, each number here would represent 4 vertices.
Each set of 4 vertices would make a square. If you want it in a perfect square, you can use array.length to get the length and square root it until you get a non-whole number, then go by rows of the previous whole-number. Hope that helped at least a little.Thu, 07 Jun 2012 23:10:11 GMTMasterGalaxy