• 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 rlmattospt · Jun 07, 2012 at 11:02 PM · mesharraygenerateextrusion

Generate and extrude a mesh

Hello, I'm trying to create a script that reads an array of ints and, based on the numbers on it, generates a mesh and extrudes it when the number is not '0'.

For instance, if the array was: "1111110001101011000111111"

or (for a more visual-friendly example):

 1 1 1 1 1
 1 0 0 0 1
 1 0 1 0 1
 1 0 0 0 1
 1 1 1 1 1

The result I would want is this: http://oi49.tinypic.com/mbmn2h.jpg

I took a look in the procedural example but it didn't helped me much because it extrudes a mesh that is already shaped on the desired form. I'm trying to do a more generic mesh extruder. It simply reads the vector, creates a squared shaped mesh and extrudes it based on the numbers.

-edit- Any ideas on how to aproach this issue?

Thanks in advance.

Comment
Add comment · Show 2
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 MasterGalaxy · Jun 07, 2012 at 11:10 PM 0
Share

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.

avatar image rlmattospt · Jun 07, 2012 at 11:42 PM 0
Share

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?

2 Replies

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

Answer by Fattie · Jun 08, 2012 at 08:11 AM

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.

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 rlmattospt · Jun 08, 2012 at 02:54 PM 0
Share

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.

avatar image
1

Answer by Bunny83 · Jun 07, 2012 at 11:15 PM

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.

Comment
Add comment · Show 2 · 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 rlmattospt · Jun 07, 2012 at 11:38 PM 0
Share

Thanks, Reading again my question I guess it may lead to think that I'm asking for a script, although I'm not. $$anonymous$$y 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?

avatar image Bunny83 · Jun 08, 2012 at 12:22 AM 0
Share

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 Unity's $$anonymous$$esh class. 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.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best Way to Link Vertices into Mesh 0 Answers

How to load all vertices form multiple children of a game object in to one big array? 0 Answers

how to add list after removing some 1 Answer

creating a mesh and generating it's specific uvs 2 Answers

Generate a mesh from randomly positioned points 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges