I Need Help

BlitzMax Forums/MiniB3D Module/I Need Help

FBEpyon(Posted 2011) [#1]


Hello All,

Can you please help me; I'm trying to work on a new project and the picture that you see is one solid mesh with multiple Triangles, its kinda like MineCraft, but I'm at the point were I need to get tiled textures on each set of triangles.

I just need help with figuring out the UV mapping for this, it never looks right, I would show the code but I don't want to release it to the public unless I really need to. PLEASE HELP ME

Thanks,

Here is a Wire Frame picture...




ima747(Posted 2011) [#2]
what's wrong about it now, and how's it supposed to look when it's right?


SLotman(Posted 2011) [#3]
Even more: how are we supposed to help you without any code??? O_o


Kryzon(Posted 2011) [#4]
Do you have a picture of it textured so we can see what's wrong?

It's all in your quad-making code, when you create vertices. You need to map each quad as a square.

You decide which texture to use based on the quad's normal (the ones pointing up should receive a grass texture, the ones point sideways should receive a dirt texture).


FBEpyon(Posted 2011) [#5]
I'm trying to texture small cubes on one large mesh, using only certain images from one large texture.. I know uv mapping is involved, and as for code, I don't want to release anything due to to-many people in this world taking credit for others hard work.

I just need help with the UV Mapping... basically if I build the map using just all 1s in the array then I get one large cube, with no triangles in the middle it looks for the XX,YY,ZZ in the mesh and builds faces based on what is 1 or 0.

The first image shows what the map looks like when you set the array to 1 and 0 at random.

here is what i am trying to accomplish..



^^^^^^ MINE BELOW ^^^^^^^



http://forums.tigsource.com/index.php?topic=17106.0

Here is some other examples..

Last edited 2011

Last edited 2011

Last edited 2011


Kryzon(Posted 2011) [#6]
I'm trying to texture small cubes on one large mesh, using only certain images from one large texture..

That is known as Texture Atlasing, in case you want to look it up more.

I see that you are just correctly mapping the front polygons; the "length" polygons, the ones that are running back are just getting the same mapping as the front ones (hence their stretching).


It's something you gotta make more generic in your quad generation code.


ima747(Posted 2011) [#7]
each vertex has a U and a V value. Those are essentially X and and Y in PERCENTAGE, of the applied texture. It's not a pixel value because the texture applied is not directly related to the vertex/surface/mesh, and as such it's dimensions can't be known exactly. You have to crunch the percentages to get figure out where your pixel values land, and adjust the U/V for the vertex's to match.

Note also that since those are percentages you can go OVER 1 to cause repeating.


AdamRedwoods(Posted 2011) [#8]
I'm not quite sure what you're trying to do, but I'll throw an idea out here:

So perhaps you want to use TILING to create your large mesh. In other words, each block is a cube, and each cube has a certain texture on it.

If you start with individual small cubes, the UV mapping is easy, it's just the range (0.0,0.0) to (1.0,1.0) for each polygon face of the cube. And the vertexes are easy to assign as (0,0,0) to (1,1,1)

Now, IF you are trying to create a large, single mesh, THEN trying to UV map it, it's not going to be fun since you need to know the locations of each face and your range is not the easy (0,0,0) to (1,1,1) like an individual cube.

In miniB3D, it's quite easy to utilize a few cube entities into one main mesh, by using the ADDMESH command. So if you want to add a certain textured cube at say (10,5,8) to a large main mesh then you can:

''(did not test, wrote from memory)

Local meshToAdd:TMesh = CopyMesh(meshBlockYouWant)
meshToAdd.PositionMesh(10,5,8)
meshToAdd.AddMesh(mainlargemesh)
meshToAdd.PositionMesh(-10,-5,-8) ''since you are modifying the root mesh, reset the position to 0,0,0 so others can use it


Throw this in a loop feeding the positions of the blocks and you're done.

Last edited 2011


FBEpyon(Posted 2011) [#9]
Hello,

So I know were the textures land by the fact that I have a 256x256 images with 16x16 tiles and I only want to use 16x16 tiles I know the there are 16 tiles across and 16 tiles down, So using basic math I would do 16/256 which is were I get a percentage of 0.0625 which is equal to one tile. I was read above that I need to adjust the NX, NY, NZ well making the quads...? Is there any examples of doing this, I also want to set each tile to different terrain types, like Grass, Rock, Wall, etc.. I need to figure out how to tell the UV map which tiles to view at different values.. THATS were Im stuck.. PLEASE HELP

Thanks,

WILLIAM (aka FBEPYON)


Warner(Posted 2011) [#10]
You are now doing -> u=x and v=y
That works for the front side, but not the left/right side
For those sides, you have to do -> u=z and v=y instead


Kryzon(Posted 2011) [#11]
I was read above that I need to adjust the NX, NY, NZ well making the quads...?

You don't adjust the normals (that would give all sorts of lighting problems), but use them to figure out which texture the quad will have to use.
If the quad's normal points up ( [0,1,0] in an XYZ system), you know this quad needs a grass texture.
If the quad's normal points sideways ([X,0,Z], with X and Z being any value but the Y is necessarily zero so it doesn't point up), you know this quad needs a dirt texture (or at least a transition from grass to dirt).
If the quad's normal points downards ([0,-1,0]) then you know this quad needs a full dirt texture.
Since you can never be sure that normals are exactly 1.0, -1.0 or 0.0, always check for "bigger than" rather than "equal". So, for instance, when checking if something is -1.0 do a "< 0" comparison. This is related to precision.

Normals are stored in local mesh space. For the comparison I described you need to translate them to world coordinates by using TFormVector(NX, NY, NZ, Mesh, Null).

Example of what I said above:


This will make your terrain look like a minecraft one. It's one of many ways to code the texture assignment. You probably want something a bit more file-based, where you can paint the type of tiles you will use - the way I described is limited.

Last edited 2011


FBEpyon(Posted 2011) [#12]
@Warner

Yes I was doing it right acoording to what I have read... I got the fronts and side work now, but now I need to tell the face to only draw that one certain tile and repeat it were needed... does anyone know how to do that..? That's my main goal here...

@Kryzon

Can you please provide more information about what you are doing and how the TForms work...?

Last edited 2011


Warner(Posted 2011) [#13]
I don't understand the problem. Hopefully this example helps?


Last edited 2011


FBEpyon(Posted 2011) [#14]
Okay so I had my code posted, but I noticed something wrong, I will repost it when I get a chance..

Warner, thanks for the help I'm trying to figure out how to texture the other side, I really don't under the concept of what you are doing, but I will play with it some more..

Thanks All..

Last edited 2011


FBEpyon(Posted 2011) [#15]
Sorry DP,

I wanted to example a little more about what is going on with my engine and what I'm still trying to accomplish..

I thank you all for your help so far, but I bet if I example this a bit better than you might be able to help me better.

:THE IDEA:

What I have going is a 32x32x32 array...



Starting with a all false array I can change the location in the mesh to True and draw the block..

The block just uses a array of vertex already made within the same line of code above.



I build the array prier to everything and just do the AddTriangle based on wither or not the blocks are true or false. I if the block to the right is True then I don't draw the right side of the cube, and I keep testing each side.. So the example the Warner gave me doesn't work correctly.. I need to test the vertz, change the TestArray, clear the surface, and then update the chunk..

So I guess my main problem is testing the vertexes and changing the Texture Coords..

Does anyone have a answer for this...

Here is a picture of what I got so far, but its bleeding into the others..



Thanks...

Last edited 2011


FBEpyon(Posted 2011) [#16]


Hello all, I was able to get it to work finally, but I still have a few concerns.. there is bleeding from the other tiles on the sheet is there a way to get that to go away and to read exactly 16x16 tiles and not 18x18 or so...?

But let me know its going along nicely now...

Last edited 2011

Last edited 2011


Kryzon(Posted 2011) [#17]
This must have to do with the texel alignment from sampling.

Find the size of the width and height texels (they are square if your texture is square as well, or different if your texture is a rectangle).

Then subtract or add these values from all your mapping sides:
Local texelWidth:Float = 1.0/TextureWidth(atlas) 'Find horizontal texel size.
Local texelHeight:Float = 1.0/TextureHeight(atlas) 'Find vertical texel size.

'[...]

'When mapping each quad:
AddVertex(X,Y,Z, U + texelWidth, V + texelHeight) 'Top-left vert.
AddVertex(X,Y,Z, U - texelWidth, V + texelHeight) 'Top-right vert.
AddVertex(X,Y,Z, U + texelWidth, V - texelHeight) 'Bottom-left vert.
AddVertex(X,Y,Z, U - texelWidth, V - texelHeight) 'Bottom-right vert.

I hope it makes sense. What you're trying to do is diminish the rectangle you grab from the atlas texture by 2 texels horizontally (one from the left and one from right) and 2 texels vertically (one from top and one from bottom).
This should solve your bleeding.


SLotman(Posted 2011) [#18]
Does all 4 sides of the cubes have the same texture?

If so, why not use a LoadAnimTexture, and just set the *frame* for each cube...? Much easier than faffing about with UVW coords...

This way, you just have to make all coords (0,0), (0,1), (1,0), (1,1) and it will work.


Kryzon(Posted 2011) [#19]
It'd probably fix the UV problem, but then you get the overhead of having multiple frames, as internally MiniB3D extracts each frame from the file into a new texture, invalidating the purpose (and optimization) of having the frames gathered in an atlas.

EDIT: Good ol' trade-off situation...

Last edited 2011


FBEpyon(Posted 2011) [#20]
Kryzon :

Thanks, for the advice it worked great, Im just working on the Sectors now and controlling the blocks now that the rendering is working, I was playing with the PickCamera, and it seems to not update the in the Y access when adding new blocks to the mesh, must be a bug, but I'm going to try a few things with storing the x,y,z of the vertex in a seprate val and test things with a PickLine instead, but we will see what happens.

Slotman :

Thanks, for all your help as well..

Warner :

Thanks for all the examples as well, your texturing system works like a charm and is amazing that I only need one texture sheet now..

I will post more as things come in my worklog in the next few days..

Thanks All...

William (FBEpyon)


FBEpyon(Posted 2011) [#21]
DP Again,

I'm stuck again!!!

I'm trying to use the CameraPick command to add more cubes, but I can't seem to go above one in the Y direction anything else I can do...?

Thanks


Warner(Posted 2011) [#22]
Maybe you could create a small example that uses CreateCube() to demonstrate this picking problem.


FBEpyon(Posted 2011) [#23]
http://www.mediafire.com/?sdm28s9sdkpn7c9

That is what I have so far, the problem I'm having is getting the blocks to stack above one..

The Contorls:

Mouse 1 - Add a block
Mouse 2 - Delete block

Left Shift - move camera up
Space - move camera down

Mouse Rotates Camera...

Thanks...


Warner(Posted 2011) [#24]
When I try to run it, my computer hangs. Anyway, picking should not be limited to any range, so there must be something else wrong.
I would try and find out what is the center of the quad-face that a user picks. Then, add the normal of this quad to this location to find the location where the new cube should be.
pseudocode:
newx = picked_quad_center_x + picked_nx()
newy = picked_quad_center_y + picked_ny()
newz = picked_quad_center_z + picked_nz()



FBEpyon(Posted 2011) [#25]
Thanks Again Warner,

I will try this today, and see what happens..

I may have to rewrite some of my code because of a few limitations that I have been running into I program the game on my HP Labtop so that I know it can run on lower end machines, but I also have my i7 with the 1.5ghz video card that use to program on so there might be a few things working on that that don't work on others..

I will let you know thanks,

FBEpyon


FBEpyon(Posted 2011) [#26]
Hello Everyone..

My problems have been solved, with a little searching and brainstorming I was able to come up with the fastest way to get block information and delete and add, but most of this would not of happen if it wasn't for all your help..

Thanks for everything

FBEpyon...

Last edited 2011


FBEpyon(Posted 2011) [#27]
Hey Everyone one, I'm one step closer to getting this done..




FBEpyon(Posted 2011) [#28]
Hello Everyone..

I'm looking for help AGAIN sorry...

This time Im posting my code, I need help optimizing it..

HERE IT IS:

Removed due to not given credit...

Last edited 2011