Texturing Problem after creating a mesh

Blitz3D Forums/Blitz3D Beginners Area/Texturing Problem after creating a mesh

Hardcoal(Posted 2013) [#1]
Hi

Ive created a Flat Mesh from scratch

using Vertex and Triangles.

I can see the mesh after creation
but I dont manage to pain it or load texture by using EntityTexture
command.

What I mean is that i dont really understand when you create a Vertex
you have this U,V and W Values.
I dont know how to use them.

Any way all I want is that after creating a Flat Mesh (Using a single Surface)
and applying EntityTexture I expect to see the texture appears on the mesh.
but it doesnt.

Any way to do it easily without getting too deep.

Cheers


Stevie G(Posted 2013) [#2]
Set the UV's like so ...

mesh=CreateMesh()
s = CreateSurface(mesh)
AddVertex s,-1,0,1,0,0
AddVertex s,1,0,1,1,0
AddVertex s,1,0,-1,1,1
AddVertex s,-1,0,-1,0,1
AddTriangle s,0,1,2
AddTriangle s,2,3,0



_PJ_(Posted 2013) [#3]
U V and W are coordinates similar to X Y and Z, but they refer to the placement of the texture on the surface vertices.

Without UV values applied to vertices, textures cannot be applied to a surface, because there is no coordinate to tell where it should be drawn.

For example, a texture of 1024x512 pixels can be 'mapped' onto a square quad mesh such as the one Stevie G's code creates because the UV (I have never understood how W comes into it, or if it ever actually is used?) values for the vertices are set.

The AddTriangle command makes the square by joining the two triangles:

U
0 . . 1
______
| /| 1 V
| / | .
| / | .
|/___| 0

And the UV Coordinate values range from 0.0 to 1.0 which relate to the ratio of the Texture Width and the Ratio of the Texture Height

So because the shape created is square, yet the texture is rectangular, when the texture is applied to the quad, it will appear squashed across the width, because the Texture's 1024 pixels will be drawn to the sxame length as the 512 pixels of the textures height

If, alternatively, the UV Values were set to, say,

0 . . 0.5
______
| /| 1 V
| / | .
| / | .
|/___| 0

The texture will be applied in its correct dimensions, but only the first 512 pixels of its width will be drawn between the U=0 and U=0.5 coordinate - the same number of pixels as in the entire height V=0 to V=1

I hope this makes sense and helps, rather than just make things more complicated.
I realyl struggled with this concept for a LONG while but once you can grasp it, it is VERY useful and suprisingly simple!


Hardcoal(Posted 2013) [#4]
Pretty complicated for me to visualy grasp.
But ill experiment abit.

Thanks guys for putting time explain


Kryzon(Posted 2013) [#5]



Hardcoal(Posted 2013) [#6]
great kryzon

I still dont manage to apply i correctly on this code.

http://www.blitzbasic.com/Community/posts.php?topic=100770


jfk EO-11110(Posted 2013) [#7]
i don't know much about xors3d, but with blitz meshes you probably better create a brush, then texture the brush, then paint the mesh using the brush, instead of simply entitytexture the mesh.
You need however to set the UVs of the mesh first.


RemiD(Posted 2013) [#8]
I am not sure what you are trying to achieve, but if you only want to UVMap a quad or an approximately flat surface, it is really easy.

Think of the UV coords, which can be between 0.0 to 1.0 as a percentage of the texture.

For example if your texture measures 256 pixels (width) and 256 pixels (height), and if you set the UV coords of a vertex at U0.7525 and V0.3832, it means that it is as if the vertex will be positionned at PixelX = 256×0.7525=192 and PixelY = 256×0.3832=98.
Except it is the other way around, it is the texture which is positionned on the mesh.

For multiple surfaces, you will need different brushes.


Hardcoal(Posted 2013) [#9]
Remid. clear and simple explanation from you.
Im getting closer to understandinf this.
The truth im not too busy with that now.
Because i have more urgent tasks.
But ill get into it. So all the explanations are not in vain.