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
0
Question by iamthecoolguy11 · Dec 27, 2014 at 10:55 PM · c#voxelface

What is a simple way to make a voxel face?

Hi im trying to learn voxel and I keep looking at all these tuts and they are good but its to much going on at once to understand. So I was wondering if there was a very straightforward way to just make one simple face and put a material on it. The material would be a public variable that you set in unity. Thanks ahead of time :) o and one more thing c# lol

Comment
Add comment
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

1 Reply

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

Answer by jmgek · Dec 27, 2014 at 11:33 PM

So I would be able to pass you the code to make a simple polly and attach a material but your problem would not be solved. I have been working with procedural gen for about 2 months now and IT is HARD! the first thing you need to do is start learning vertex math, you need to know wheere a 3D point in space is in order to make your code both modular and easy to work with. I would start with a simple cube you can find almost on any tutorial. start with perimatives and then you can start making pollys. But again it is tough to do!

Comment
Add comment · Show 6 · 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 iamthecoolguy11 · Dec 27, 2014 at 11:52 PM 0
Share

i well figure the rest out I just want to know what part of the code is actually doing something the tuts a confusing because they add all kinds of extra stuff and don't explain what the code is doing so thats why I am asking just for one face with a material attached to it

avatar image jmgek · Dec 28, 2014 at 12:14 AM 1
Share

Yeah I know but it's not as simple as you think it is. You can make a simple polly easily with 10 lines of code with 3 verts but you need to understand how to make many. So you need to understand vertex math in order to loop and create pollys attached to pollys.You will need to understand the system inorder to make something out of it.

 void GenSquare(int x, int y, Vector2 texture)
     {
         float side = Random.Range (0.1f, 1f); 
 
         newVertices.Add( new Vector3 (x  , y  , 0 ));
         newVertices.Add( new Vector3 (x + side , y  , 0 ));
         newVertices.Add( new Vector3 (x + 1 , y-1 , 0 ));
         newVertices.Add( new Vector3 (x  , y-1 , 0 ));
         
         newTriangles.Add(squareCount*4);
         newTriangles.Add((squareCount*4)+1);
         newTriangles.Add((squareCount*4)+3);
         newTriangles.Add((squareCount*4)+1);
         newTriangles.Add((squareCount*4)+2);
         newTriangles.Add((squareCount*4)+3);
         
         newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit));
         newUV.Add(new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y + tUnit));
         newUV.Add(new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y));
         newUV.Add(new Vector2 (tUnit * texture.x, tUnit * texture.y));
         
         squareCount++;
         
     }
     
     void Update$$anonymous$$esh () {
         mesh.Clear ();
         mesh.vertices = newVertices.ToArray();
         mesh.triangles = newTriangles.ToArray();
         mesh.uv = newUV.ToArray();
         mesh.Optimize ();
         mesh.RecalculateNormals ();
         
         newVertices.Clear();
         newTriangles.Clear();
         newUV.Clear();
         squareCount=0;
         
         $$anonymous$$esh new$$anonymous$$esh = new $$anonymous$$esh();
         new$$anonymous$$esh.vertices = colVertices.ToArray();
         new$$anonymous$$esh.triangles = colTriangles.ToArray();
         col.shared$$anonymous$$esh= new$$anonymous$$esh;
         
         colVertices.Clear();
         colTriangles.Clear();
         colCount=0;
     }

 
avatar image iamthecoolguy11 · Dec 28, 2014 at 12:20 AM 0
Share

Thats fine can you add the variables to this script I well read it a few times to understand it.

avatar image jmgek · Dec 28, 2014 at 12:22 AM 1
Share
     public List<Vector3> newVertices = new List<Vector3>();
     public List<int> newTriangles = new List<int>();
     public List<Vector2> newUV = new List<Vector2>();
     
     public List<Vector3> colVertices = new List<Vector3>();
     public List<int> colTriangles = new List<int>();
     private int colCount;
     
     private $$anonymous$$esh mesh;
     private $$anonymous$$eshCollider col;
     
     private float tUnit = 0.25f;
     private Vector2 tStone = new Vector2 (1, 0);
     private Vector2 tGrass = new Vector2 (0, 1);
     
     
     public byte[,] blocks;
     private int squareCount;
     
     

avatar image iamthecoolguy11 · Dec 28, 2014 at 12:25 AM 0
Share

Thanks man this well help out a lot :)

Show more comments

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Grid based water system 0 Answers

Create a circle using cubes? 3 Answers

Huge C# Procedural Generation Errors. Why? 1 Answer


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