Author Topic: Textures: uv, st, argh!  (Read 5527 times)

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Textures: uv, st, argh!
« on: January 19, 2011, 10:46:48 am »
Hi!

I'm currently trying to bring some colors to my virtual worlds by adding textures. But I'm somewhat stuck.
I created a model & texture according to http://www.code5.ch/meckardt/tutorials/wings_textur.html (German)
and exported it as VRML. The exported stuff seems reasonable, even though I didn't check it manually.

Code: [Select]
#VRML V2.0 utf8
#Exported from Wings 3D 1.2
DEF cube1 Transform {
  children [
    Shape {
      appearance Appearance {
        material DEF cube1_auv Material {
          diffuseColor 1.0 1.0 1.0
          emissiveColor 0.0 0.0 0.0
          specularColor 1.0 1.0 1.0
          ambientIntensity 1.0
          transparency 0.0
          shininess 1.0
        }
        texture ImageTexture { url "PATH/TO/TEXTURE" }
      }
      geometry IndexedFaceSet {
        coord Coordinate { point [
          -3.032000000000004 -3.032000000000004 3.032000000000004,
          -3.032000000000004 3.032000000000004 3.032000000000004,
          3.032000000000004 3.032000000000004 3.032000000000004,
          3.032000000000004 -3.032000000000004 3.032000000000004,
          -3.032000000000004 -3.032000000000004 -3.032000000000004,
          -3.032000000000004 3.032000000000004 -3.032000000000004,
          3.032000000000004 3.032000000000004 -3.032000000000004,
          3.032000000000004 -3.032000000000004 -3.032000000000004 ] }
        coordIndex [
          0, 1, 4, -1,
          0, 3, 1, -1,
          0, 4, 3, -1,
          1, 2, 6, -1,
          1, 3, 2, -1,
          1, 5, 4, -1,
          1, 6, 5, -1,
          2, 3, 6, -1,
          3, 4, 7, -1,
          3, 7, 6, -1,
          4, 5, 6, -1,
          4, 6, 7, -1 ]
        texCoord TextureCoordinate { point [
          0.0 0.5540970937771938,
          0.0 1.0,
          2.7755575615628914e-17 0.7387961250362586,
          1.1102230246251565e-16 0.18469903125906445,
          0.18469903125906464 0.36939806251812923,
          0.18469903125906464 0.7387961250362585,
          0.18469903125906495 0.0,
          0.2612038749637414 1.0,
          0.2612038749637415 0.7387961250362587,
          0.36939806251812923 0.554097093777194,
          0.3693980625181294 0.1846990312590646,
          0.5540970937771938 0.7387961250362587,
          0.5540970937771941 5.551115123125783e-17,
          0.5540970937771941 0.36939806251812934,
          0.7387961250362585 0.5540970937771941,
          0.7387961250362587 0.18469903125906478 ] }
        texCoordIndex [
          4, 3, 10, -1,
          4, 9, 0, -1,
          4, 10, 9, -1,
          2, 8, 7, -1,
          0, 9, 5, -1,
          3, 6, 10, -1,
          2, 7, 1, -1,
          11, 9, 14, -1,
          9, 10, 13, -1,
          9, 13, 14, -1,
          10, 12, 15, -1,
          10, 15, 13, -1 ]
      }
    }
  ]
}

The VRML-Spec says, that the TextureCoordinate-Node contains st-coordinates. As far as I know, that differs from uv-coordinates by already being "height-aware".
But I'm not really an expert to this... Anyway, the triangles load fine, and i tried just to push the st-coords along with the vertices into jPCT. Obviously without much success.

I also had a short look at TextureInfo that seems to have a different purpose.

I should add, that I have to load the models myself into a different world model. jPCT pulls the vertices (and...) from there.
This is like this:
Code: [Select]
Object3D o = new Object3D(..);
o.addTriangle( t.vertices[0], (float)t.vertices[0].u, (float)t.vertices[0].v,
      t.vertices[1], (float)t.vertices[1].u, (float)t.vertices[1].v,
      t.vertices[2], (float)t.vertices[2].u, (float)t.vertices[2].v);

Any help/hint would be great!

Roland

PS: I tried to attach a screenshot, but I failed... hard to use these boards ;-)


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Textures: uv, st, argh!
« Reply #1 on: January 19, 2011, 10:55:08 am »
I was under the impression that st is just another word for uv...but i'm not 100% sure. Judging from the example you've posted, it looks like it though. What's the end result? Wrong texturing? Maybe they are defined in another space. Try to add something 1-s and/or 1-t instead.

BTW: TextureInfo can be used for the same thing but it doesn't have to if you have one texture layer only.

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Textures: uv, st, argh!
« Reply #2 on: January 19, 2011, 11:12:08 am »
Quote
I was under the impression that st is just another word for uv.
That's what I thought as well. I looked around and found this:
http://www.vrmlsite.com/aug96/spotlight/textures/textures.html

Quote
Try to add something 1-s and/or 1-t instead.
Tried it. (1-t) seems to be a small improvement. But I don't think that is the problem.

http://img146.imageshack.us/i/dice.png/
What you see should look like a dice... A single number on each side.
With (1-t), at least two sides seem correct.

Thank you for your time!
Roland

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Textures: uv, st, argh!
« Reply #3 on: January 19, 2011, 12:52:12 pm »
Ok, I just hand-checked the VRML. It makes complete sense, if it makes use of UV-coordinates. The Internet, by the way, has multiple opinions on uv/st coordinates.
I will just assume, that they are indeed equal and that I messed something up elsewhere.

I let you know, if I stumble upon something.

Roland



Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Textures: uv, st, argh!
« Reply #4 on: January 19, 2011, 02:00:34 pm »
Got it. So I think the st=uv equation is correct. At least, when you use Wings3d ;-)
What I got was a combination of two problems:

1. My Triangle-Class only stored references to the vertices. This caused the loader to override some uv-coordinates. Clearly my fault. Debugging is such a joy  :-\

2. As Egon suggested, the exporter seems to use a different coordinate system for the uv-stuff. Using (1-v) does the trick.

So Problem solved, Thanks a lot!

Roland

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Textures: uv, st, argh!
« Reply #5 on: January 19, 2011, 05:27:38 pm »
Great that you've solved it. For writing an importer, you might want to have a look at the constructor for an Object3D that takes bulk data ,%20float[],%20int[],%20int)]http://www.jpct.net/doc/com/threed/jpct/Object3D.html#Object3D(float[],%20float[],%20int[],%20int). It might speed up the whole task.

Offline rschwemm

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Textures: uv, st, argh!
« Reply #6 on: January 20, 2011, 01:54:04 pm »
I'm not sure about the speed up. I would have to convert my data types first and stuff them into arrays. I think I would just change where the processing is done.
Right now, I'm happy it works this way. My models are also rather primitive, so I currently don't have need.

But thanks for the hint, I'll keep it mind for the future :-)

Roland