Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by dorpeleg · Aug 02, 2013 at 05:21 PM · meshproceduralverticesmesh-deformationvertice manipulation

Adding vertices to procedural mesh generator

Hello everyone.

This is going to be a little rough, so stay with me :)

Here is what I have currently working:

I have a mesh (generated with script) that is built like this:

 1------2
 |   /  |
 | /    |
 0------3

I've added 4 gameobjects around the mesh like this:

(light green are vertices, blue are gameobjects)

example1

When I drag a gameobject, I'm rebuilding the mesh to fit the new locations of the gameobjects.

This way, I'm getting a stretched out mesh.

#######################################################

The problem is, I don't want the mesh to be stretched.

I want to add more vertices when I drag the gameobjects around.

Something like this:

(light green are vertices, drak green are double vertices, blue are gameobjects, orange is the dragged gameobject)

example2

So the mesh should be built like this:

 1-----2/5-----6
 |   /  |   /  |
 |  /   |  /   |
 0-----3/4-----7

Imagine I'm dragging another gameobject:

(light green are vertices, drak green are double vertices, blue are gameobjects, orange is the dragged gameobject)

example3

So now the mesh should be built like this:

  9------10/13-------14
  |    /   |     /   |
  |   /    |    /    |
 1/8----2/5/11/12----6/15
  |   /    |     /   |
  |  /     |   /     |
  0-------3/4--------7

So here is where I'm struggling.

I have no clue how to go about managing the vertices (and triangles and uvs).

Any ideas, leads, scripts will be appreciated.

Thanks a lot!

Comment
Add comment · Show 9
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 AlucardJay · Aug 04, 2013 at 05:45 AM 0
Share

This is more about how you organize and store your data. If you know the size of your quad grid, and every quad has 4 verts/uvs/etc, and they are stored sequentially in lists, then you can find and modify any specific quad.

say I have a mesh with a grid of 4x4 quads, and I want to change the 2nd quad on the second row, that's the 6th quad in the lists of mesh attributes, so (its 5 as lists count from zero) :

 vert[ ( 5 * 4 ) ] = Vector3(...);
 vert[ ( 5 * 4 ) + 1 ] = Vector3(...);
 vert[ ( 5 * 4 ) + 2 ] = Vector3(...);
 vert[ ( 5 * 4 ) + 3 ] = Vector3(...);

Check my answer here for the same principle : http://answers.unity3d.com/questions/475795/rendering-permanent-trails-such-as-footsteps.html

avatar image dorpeleg · Aug 04, 2013 at 06:53 AM 0
Share

But I don't know the size of the grid, that's why I'm struggling with how to manage it.

The size of a quad is always 4verts, 4uvs and 6 tris.

But the Total size of the mesh (the quad grid) is changeable by the user (by dragging the gameobjects off the side of the mesh).

I was thinking about lists, but could not wrap my head around how to manage it correctly.

avatar image AlucardJay · Aug 04, 2013 at 07:01 AM 0
Share

hmm, if you know the absolute maximum size of the grid, you could use a 2D array of integers, and store the type of tile (eg 0 = empty, 1 = type1, 2 = type2, etc). Then just manage your whole world like a grid. When a piece is dragged into a grid position, update the 2D array and the mesh information.

avatar image AlucardJay · Aug 04, 2013 at 07:04 AM 0
Share

The only way I can see of doing it dynamically is to keep a list of vector tile positions and a list of tile types. (or you could use a Vector4, and use the w variable as the tile type). The order of this list would also be relative to the index position of the quad info in the mesh. Then every time you modify a tile, change the information at index position of the list, and modify the mesh data at index relative position.

avatar image dorpeleg · Aug 04, 2013 at 07:05 AM 0
Share

I don't want to create a grid because I'm also letting the user rotate the mesh he made (only on 1 axis of curse).

Thanks for helping btw :)

Show more comments

2 Replies

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

Answer by Bunny83 · Aug 04, 2013 at 10:56 AM

If i got you right you want something like this


I didn't use gameobjects as handles but dragging areas around the plane. You can even grab a corner (outside of the plane) to drag two directions at once.

Keep in mind that Unity has a vertex limit of 65000 which equals roundabout 127 x 127 tiles.

The scene has only two gameobjects. One with the camera (and a modified MouseOrbit script) and one with this script.

Comment
Add comment · Show 7 · 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 Bunny83 · Aug 04, 2013 at 10:58 AM 0
Share

ps: Use left mouse button to drag an edge, the middle mousebutton to rotate the camera and the mousewheel to zoom in / out

As additional information: I used the alphablended particle shader of Unity.

avatar image dorpeleg · Aug 04, 2013 at 11:15 AM 0
Share
  • for writing a script :)

I'm currently at work and this is a personal project, so i'll test it when I get home and get back to you.

Thanks!

avatar image dorpeleg · Aug 04, 2013 at 06:42 PM 0
Share

Well, I don't have time to Implant the script into my system (until the weekend).

But It works perfectly and the code doesn't seem to hard to understand, so implementing it shouldn't be too hard.

Thanks!

avatar image dorpeleg · Aug 09, 2013 at 01:33 PM 0
Share

Hey, I finally got some time to look more closely at the script.

There are few things I don't understand.

Can you explain the CalculateUV function?

I noticed you are passing it a random value, I'm guessing that is what cussing the tiles to appear at random positions on the mesh.

How can I lose the randomness?

What I want is, tell the script what part of the atlas I want it to display, and then it will tile that part on all of the mesh tiles.

So, if compering to the example you made, I will tell the script I want it to display the "TNT" tile.

So now, the mesh will be tiled completely with TNTs.

avatar image Bunny83 · Aug 11, 2013 at 12:42 AM 0
Share

Just saw your comment. I've updated my sample (script & webplayer).

The CalculateUV function actually just calulates an evenly distributed tile rect for a given index and x/y tile count. Dor example my sample texture has 16x16 tiles (x256). The function just takes the index and "splits" it up into x / y indices by calculate the modulo / division.

Since each tile is of equal size (1.0/16) the size of the rectangle is always the same, just the top-left corner is changing.

Show more comments
avatar image
0

Answer by Paulius-Liekis · Aug 03, 2013 at 09:31 PM

Simply google "procedural mesh generation unity". There are plenty of tutorials. You simply need to create array of vertices and indices and assign them to your mesh.

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 dorpeleg · Aug 04, 2013 at 06:56 AM 0
Share

Please see my comment to alucardj

I have no problem with creating meshs of any size, as long as I know the size, but in this case, I don't.

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

18 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Flattening a mesh by deforming it 0 Answers

mesh-morph scaling badly 1 Answer

reading vertices from a mesh always returns Vector3.zero 2 Answers

Subdivide mesh? 2 Answers

Direction of a mesh 2 Answers


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