jPCT - a 3d engine for Java => Support => Topic started by: mystara on July 11, 2007, 11:30:58 am

Title: UV Texturing
Post by: mystara on July 11, 2007, 11:30:58 am

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);


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 :)
Title: Re: UV Texturing
Post by: EgonOlsen on July 11, 2007, 02:37:29 pm
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?
Title: Re: UV Texturing
Post by: mystara on July 11, 2007, 04:15:31 pm
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?
Title: Re: UV Texturing
Post by: EgonOlsen on July 11, 2007, 04:28:21 pm
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?
Title: Re: UV Texturing
Post by: mystara on July 11, 2007, 05:45:40 pm
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?
Title: Re: UV Texturing
Post by: EgonOlsen on July 11, 2007, 05:46:23 pm
Yes, just send me the file.
Title: Re: UV Texturing
Post by: EgonOlsen on July 11, 2007, 07:20:34 pm
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:

Code: [Select]
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);
Object3D cave = Loader.load3DS("cave.3ds", 10)[0];

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


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

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



try {
} catch(Exception e) {}


Title: Re: UV Texturing
Post by: hytparadisee on July 11, 2007, 07:31:22 pm
I'll update the documention accordingly.

This is well known as "Professionalism"! :D
Title: Re: UV Texturing
Post by: mystara on July 11, 2007, 11:32:10 pm
Excellent, thanks very much!