[SOLVED] Scale a cube mesh without scaling its texture?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
bull
Posts: 36
Joined: Wed Sep 12, 2007 8:49 am
Location: s1Ng4p0R3

[SOLVED] Scale a cube mesh without scaling its texture?

Post by bull »

I'm creating a 3D roguelike game where the dungeon is randomly generated. If I represent each 'tile' of the wall by a cube mesh, the rendering speed is too slow even when I use bitplane's CBatchingMesh.
So I decided to use a scaled up cube mesh for adjacent 'tiles' and the speed improved a lot. The problem is: It's texture also get scaled up and it looks ugly.

I know I can mess with the UV of the vertices, but I don't know how to set it correctly by code. I only know how to do UV mapping in modellers, however the dungeon is randomly generated :( .

Please help. I need specific code to show how the UV of all 8 vertices should be set up so that the texture keeps its original size when applied to the cube. Just assume that the texture's dimension is w*h .
Last edited by bull on Wed Jul 30, 2008 12:49 pm, edited 1 time in total.
My name is bull, for we are many ...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You can't setup tiled texture coords on a simple cube, you basically need a plane broken up into segments so that each segment can have 0-1

Code: Select all

-----
| | |
-----
| | |
-----
| | |
-----

rather than
-----
|   |
|   |
|   |
-----
Or you can probably use the texture matrix to tile the texture by scaling it down or something. I've not used the texture matrix before so check the docs for it (use the .chm in Irrlicht/docs and use the the search function it provides)
Image Image Image
bull
Posts: 36
Joined: Wed Sep 12, 2007 8:49 am
Location: s1Ng4p0R3

Post by bull »

Thanks JP. I'll try editing the texture matrix.

Edit:
It works!
Image

There's still some error(circled area). I guess I will have to use different materials for different faces.

Btw, please ignore the confusing minimap. I still cannot control the third party dungeon generator. It creates a maze, not a simple dungeon :( .
My name is bull, for we are many ...
Post Reply