Page 1 of 1

texcord : how to apply a image to a mesh

Posted: Sat Jun 16, 2007 2:34 pm
by big_daddy2
i was wondering if u have an image how do u use a texcord with it?

Posted: Sun Jun 17, 2007 12:25 am
by Tedius
<h1>Fun with texcoords:</h1> by Tedius

I am guessing by the way you phrased your question that you may have a few steps to go before you are able to use texcoords successfully. But just in case, you or someone else is bound to find this useful. I am hoping you can make a simple mesh face. The code may look something like this:

Code: Select all

mesh
  vertex -16 75 0   #0
  vertex 16 75 0    #1
  vertex 16 75 24   #2
  vertex -16 75 24  #3

   face
    vertices 0 1 2 3
   endface
end
If you don't understand that, I dont blame you. Just stare at it for a while and you will eventually figure it out.

Take a picture such as http://images.bzflag.org/wtf.png and imagine that the bottom left corner is the point (0,0) and the upper right-hand corner is (1,1). Therefore, the four points we will refer to in texcoords are:
lower left -> 0 0
lower right -> 1 0
upper right -> 1 1
upper left -> 0 1

Below we will define the material as wtf, (I think it stands for wabbits taste funny), refer to the the material when we define the face, define the four corners as listed above, and then apply those corners to the vertices in the face. Here goes:

Code: Select all

material 
  name wtf
  addtexture http://images.bzflag.org/wtf.png
end
mesh
  vertex -16 75 0   #0
  vertex 16 75 0    #1
  vertex 16 75 24   #2
  vertex -16 75 24  #3

  texcoord 0 0  #0
  texcoord 1 0  #1
  texcoord 1 1  #2
  texcoord 0 1  #3
  face
    vertices 0 1 2 3
    texcoords 0 1 2 3
    matref wtf
  endface
end
Now your homework is to change the texcoord part. You can double it so you have a bunny on top of another like so:

Code: Select all

  texcoord 0 0  #0
  texcoord 1 0  #1
  texcoord 1 2  #2
  texcoord 0 2  #3
You can chop the bunny in half by putting in ".5" You can even skew the poor guy by putting in random numbers between 0 and 1 in those places.

mmm pancakes:

Code: Select all

texcoord .15 .5625  #0
  texcoord .625 .5625  #1
  texcoord .625 .857  #2
  texcoord .15 .857  #3
Edit: much apologies to big_daddy2. It turns out I underestimated him, he had no trouble with it at all.
Sorry, mate.

Posted: Sun Jun 17, 2007 5:30 am
by Grace F
You helped me out heaps though :D Cheers Tedius

Posted: Mon Jun 18, 2007 6:23 pm
by big_daddy2
ya my image is side ways with the code u gave me, how do i make it up and down instead?

Posted: Mon Jun 18, 2007 11:41 pm
by Tedius
Your texcoord should match up with the vertices. In my example, the vertices were listed in order from the lower left hand around to the upper left hand corner. If it is sideways, just switch your texcoords around like this:

Code: Select all

face 
    vertices 0 1 2 3 
    texcoords 1 2 3 0 
    matref wtf 
  endface 
or possibly this:

Code: Select all

face 
    vertices 0 1 2 3 
    texcoords 3 0 1 2
    matref wtf 
  endface 
[/code]

Posted: Tue Jun 19, 2007 4:02 pm
by big_daddy2
i did that and it is still side ways but the other way

Posted: Tue Jun 19, 2007 4:04 pm
by Winny
If you want a quick and dirty solution:

Put your image in a photo editor, and rotate it. I've done that a few times.

Posted: Wed Jun 20, 2007 8:22 pm
by TD-Linux
Hmm, I can't remember exactly how I got this to work for me. Just try ordering the texcoords different ways (keep them in numerical order kinda, just start at different numbers). I can't remember, but I think 0,0 on a texcoord is the upper left of a texture... that might be what is messing you up.