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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by valeriobulla · Nov 05, 2013 at 12:47 AM · texturemeshproceduraluvtile

How to texture walls in procedurally generated mesh?

I'm trying to make a simple tile engine for my game.

I have some basic experience with 2D but I never programmed in 3D before... I read that creating too many objects is not optimal and since the game's going to have some big maps, I decided to render the randomly generated world and levels using single meshes rather than creating one object per tile. I started with quill18's tutorial on youtube and I'm using the code as a base to develop the engine and learn more about Unity and 3D programming in general.

Now, I've rewritten most of that code and I managed to correctly generate the mesh the way I want it... triangles, uvs, normals and lighting seems to be fine as well. There are no shared vertices, every vertex must have its own normal for lighting to work properly, so basically every corner has duplicates.

The only thing I couldn't figure out is how to deal with wall textures.

Here's what I have so far:

Top View

Side View

and the code to generate the texture:

 void BuildTexture() {
     
     int texWidth = ( size_x ) * tileResolution;
     int texHeight = ( size_z ) * tileResolution;
     Texture2D texture = new Texture2D( texWidth, texHeight );
     
     // turn the tileset texture into an array
     Color[][] tiles = ChopUpTiles();

     for( int z = 0; z < size_z; z++ ) {
         for( int x = 0; x < size_x; x++ ) {
             Color[] p = tiles[ map.GetType( x, z ) ];
             texture.SetPixels ( x * tileResolution,
                                 z * tileResolution,
                                 tileResolution,
                                 tileResolution,
                                 p );
         }
     }
     
     texture.filterMode = FilterMode.Point;
     texture.Apply();
     
     MeshRenderer mesh_renderer = GetComponent<MeshRenderer>();
     mesh_renderer.sharedMaterial.mainTexture = texture;
     
     Debug.Log ("Texture done!");
 }
 
 Color[][] ChopUpTiles() {
     int numTilesPerRow = terrainTiles.width / tileResolution;
     int numRows = terrainTiles.height / tileResolution;
     Color[][] tiles = new Color[ numTilesPerRow * numRows ][];
     
     for( int y = 0; y < numRows; y++ ) {
         for( int x = 0; x < numTilesPerRow; x++ ) {
         tiles[ y * numTilesPerRow + x ] = terrainTiles.GetPixels(
                                               x * tileResolution,
                                               y * tileResolution,
                                               tileResolution,
                                               tileResolution);
         }
     }
     return tiles;
 }

where size_x and size_z are the number of tiles in that axis, tileResolution is the resolution of every tile in the tileset (e.g. it's 16 for 16 x 16 pixels)

To be honest I'm having trouble understanding the walls' texturing process... I understood what it takes to texture a flat mesh using a tileset, but this is where I got lost. What I'd like to achieve is a way to texture the walls correctly (e.g. maybe with the 'W' tile texture repeating vertically).

Every single tutorial / guide / documentation always textures pretty simple objects and never touches something like this, so I'm looking for some pointers.

top.png (59.2 kB)
side.png (30.7 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

Answer by javert · Nov 05, 2013 at 01:15 AM

try to make a cube in blender and use the UV MAP

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 valeriobulla · Nov 05, 2013 at 03:50 PM 0
Share

Not entirely sure how this would help me :)

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

16 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

Related Questions

"Baking" to 2d UV Map? 1 Answer

Assigning UV Map to model at runtime 0 Answers

How do I go about texturing a flat-shaded generated mesh? 1 Answer

Applying UV to plane mesh is pixel imperfect. 0 Answers

Realtime mesh deformation or texturing 0 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