• 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 jvcraft87 · Nov 27, 2012 at 08:26 PM · proceduralprocedural mesh

Making a Procedural Cube Mesh

alt text

I'm attempting to make a procedural mesh on a cube. I only want the sides to have the mesh, not the top or bottom.

For the vertices I'm doing the following:

 // create the vertices array
 for ( int ptsIndex = 0; ptsIndex < numVerts; ptsIndex++ ){
 // x, y, z are generated here ...
 // blah, blah, blah

     switch ( ptsIndex % 4 ){
     case 0:
         verts[ ptsIndex ] = new Vector3( x + deltaValue, y, z - deltaValue );
         break;
     case 1:
         verts[ ptsIndex ] = new Vector3( x + deltaValue, y, z + deltaValue );
         break;
     case 2:
         verts[ ptsIndex ] = new Vector3( x - deltaValue, y, z + deltaValue );
         break;
     case 3:
         verts[ ptsIndex ] = new Vector3( x - deltaValue, y, z - deltaValue );
         break;
     }
 }

Then I create my triangle array:

 mesh.triangles = new int[]{ 0, 1, 5,
                             0, 4, 5,
                             1, 2, 6,
                             1, 5, 6,
                             2, 3, 7,
                             2, 6, 7,
                             3, 0, 4,
                             3, 7, 4 };

And finally assign everything:

     mesh.vertices = verts;
     mesh.triangles = tris;
         
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     mesh.Optimize();
 

Here is a screen shot of what I'm getting:

alt text

If any of you have any ideas on what I'm doing wrong I would love to hear it!

Thanks!

Jim

procedural_cube.png (5.4 kB)
procedural_cube_screenshot.png (18.1 kB)
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
2
Best Answer

Answer by flaviusxvii · Nov 27, 2012 at 08:32 PM

It's called Vertex Winding. The clock-wise counter-clockwise order of your verts will determine which direction is the front, in the absence of providing a normal vector.

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 jvcraft87 · Nov 27, 2012 at 08:35 PM 0
Share

Ah! So my normals on half my triangles are pointing "inward" because of the direction I'm listing my vertices?

avatar image flaviusxvii · Nov 27, 2012 at 08:39 PM 1
Share

Correct. Reverse any two verts on your backwards triangles and it'll correct the problem.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

UV problem on procedural mesh generation 1 Answer

Creating 3D representation of procedurally generated 2D tile map 1 Answer

Procedural animated mesh 1 Answer

Shared Meshes, do they auto-update? 0 Answers

How to apply PBR material to Procedurally generated Mesh? 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