UV Texturing

Started by mystara, July 11, 2007, 11:30:58 AM

Previous topic - Next topic

mystara

Hello,

Another newbie-ish question I'm afraid. Hopefully not too hard.

I have a fairly complex model in 3DS format and I'm trying to wrap a texture around it. Unless I'm much mistaken, I think I'm trying to do UV texturing.

I was under the impression from forum postings and javadocs that jpct is able to do this to some degree, and I've tried the following code:

Object3D[] bits = Loader.load3DS(filename, 10f);
Texture tex = new Texture("images/2.jpg");
texMan.addTexture("text", tex);
bits[0].setTexture("text");

bits[0].calcTextureWrap();
bits[0].recreateTextureCoords();
      
bits[0].rebuild();

As well as a number of variations (merging the Object3D[] together and applying the texture to that, applying the texture to each element of the Object3D[]) but without any luck. When the area is rendered, everything has the dummy (plain white) texture. I've called calcTextureWrap and recreateTextureCoords after setting the texture and before building it. I haven't got any envmapping stuff anywhere (which I understand would ruin things).

Have I made the faulty assumption that JPCT can do this for me? Or is it something I need to do in my model editor to make this work?

I'm rendering with openGL if that makes any difference :)

EgonOlsen

You can do it that way, but don't expect it to look too good (there are two wrapping-methods producing different results to try out). Why everything is white?...well, either your texture hasn't been loaded correctly (the console will say so) or your object isn't bit[0] only. What's the array's length in your example?

mystara

I've tried the regular wrap and the spherical wrap and they don't have much difference.

The console produces the output "Loading Texture...images/2.jpg" and doesn't seem to mention any kind of loading error, so I guess that's okay and bits.length returns 1.

One thing I do notice is that the shading of the model changes (without altering the lighting or any additional colours) as I try various textures. To me, this implies that the texture is being applied, but in an unusual way. Have I missed something, or is this a known effect of something silly I've done?

Or is this a possible effect of using wrapping so naively?

EgonOlsen

I can't spot somethign silly from the code that you've posted. Looks fine to me. Maybe you can create a basic test case that shows the problem?

mystara

Well, this comes back to my original problem - I'm wondering whether there could be something missing from my 3DS file. I know from messing around in Blender that there are particular steps I need to take (and haven't) to apply a texture directly there. So I was wondering if maybe there was something missing there.

Maybe if I could send you the 3DS file I'm using?

EgonOlsen

Yes, just send me the file.

EgonOlsen

Coord generation works using both method on this file. But for the non-spherical one, normals have to be generated, i.e. build() has to be called before calling calcTextureWrap(); I'll update the documention accordingly. Here's an example:


import com.threed.jpct.*;

public class Cave {
public static void main(String[] args) {
World w = new World();
FrameBuffer fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
fb.enableRenderer(IRenderer.RENDERER_OPENGL);
Object3D cave = Loader.load3DS("cave.3ds", 10)[0];

TextureManager tm = TextureManager.getInstance();
Texture vt = new Texture("bark1.jpg");
tm.addTexture("tx", vt);

cave.setTexture("tx");
cave.build();
cave.calcTextureWrapSpherical();
cave.recreateTextureCoords();

w.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, 400);
w.setAmbientLight(250, 250, 250);
w.addObject(cave);

while(!org.lwjgl.opengl.Display.isCloseRequested()) {

fb.clear();
w.renderScene(fb);
w.draw(fb);
fb.update();
fb.displayGLOnly();

cave.rotateY(0.02f);
cave.rotateX(0.01f);

try {
Thread.sleep(10);
} catch(Exception e) {}

}
fb.dispose();
}
}


hytparadisee

Quote from: EgonOlsen on July 11, 2007, 07:20:34 PMI'll update the documention accordingly.

This is well known as "Professionalism"! :D
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

mystara

Excellent, thanks very much!