Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 08:10:55 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)TextureLoader
Pages: [1]
Print
Author Topic: TextureLoader  (Read 3125 times)
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« on: 12. December 2006, 05:43:28 am »

So I'm updating my xith3d lib to the newest cooker version (12-12-06), and the textures no longer load properly. I've got my own object loading code, but I use TextureLoader.loadTexture(String file). Since its been a while since I've updated xith, I don't know if the functionality of this function has changed, or if theres an outstanding bug in it. Can anyone enlighten me?
Logged

"I like my method, what was my method again?" - Jon
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« Reply #1 on: 12. December 2006, 06:40:42 am »

So I found partial solution to this. I created this TextureStreamLocator

Code:
public class PackageTextureStreamLocator implements TextureStreamLocator {

public PackageTextureStreamLocator() {
super();
}

public InputStream openTextureStream(String name) {
return this.getClass().getClassLoader().getResourceAsStream(name);
}

public String getBaseDirName() {
// TODO Auto-generated method stub
return null;
}

}

First of all I didn't implement get Base Dir Name, since I don't know what this is suppose to return. If anyone can tell me I'd be much obliged to them.

Second, all though this properly loads the textures something else is wrong with my code. When I disable lighting they show up fine, however when I turn lighting back on, it looks as though the textures aren't there, or the lights no longer work.

I add the lights like so

Code:
      AmbientLightControl ambientLightNode = new AmbientLightControl(new Color3f(.1f, .1f, .1f));
      root.addChild(ambientLightNode);
     
      DirectionalLightControl directionalLight = new DirectionalLightControl(true,new Color3f(.8f,.8f,.8f),new Vector3f(1f,-2f,1f));
      root.addChild(directionalLight);
     
      PointLightControl pointLight = new PointLightControl(true, new Color3f(.7f,.7f,.7f),new Point3f(10f,20f,10f), new Point3f(.01f,.01f,.01f));
      root.addChild(pointLight);

I then enable lighting like so

Code:
RenderOptions options = new RenderOptions();
//options.setOption(Option.USE_SHADOWS,true);
options.setOption(Option.USE_LIGHTING,true);

window.getCanvasPeer().setRenderOptions(options);

Note that window.getCanvasPeer() returns the CanvasPeer.

Does anyone know why my lighting doesn't work?
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 12. December 2006, 12:19:13 pm »

So I found partial solution to this. I created this TextureStreamLocator

Code:
public class PackageTextureStreamLocator implements TextureStreamLocator {

public PackageTextureStreamLocator() {
super();
}

public InputStream openTextureStream(String name) {
return this.getClass().getClassLoader().getResourceAsStream(name);
}

public String getBaseDirName() {
// TODO Auto-generated method stub
return null;
}

}

First of all I didn't implement get Base Dir Name, since I don't know what this is suppose to return. If anyone can tell me I'd be much obliged to them.

Second, all though this properly loads the textures something else is wrong with my code. When I disable lighting they show up fine, however when I turn lighting back on, it looks as though the textures aren't there, or the lights no longer work.

You don't need to create your own TextureStreamLocator implementation. For your case it should be ok to use this:
Code:
TextureLoader.getInstance().addTextureStreamLocator( new TextureStreamLocatorURL( "my/class/path/to/textures/" ) ); // make sure to add the last slash!
TextureLoader.getInstance().getTexture( "myTex.png" );

I add the lights like so

Code:
      AmbientLightControl ambientLightNode = new AmbientLightControl(new Color3f(.1f, .1f, .1f));
      root.addChild(ambientLightNode);
     
      DirectionalLightControl directionalLight = new DirectionalLightControl(true,new Color3f(.8f,.8f,.8f),new Vector3f(1f,-2f,1f));
      root.addChild(directionalLight);
     
      PointLightControl pointLight = new PointLightControl(true, new Color3f(.7f,.7f,.7f),new Point3f(10f,20f,10f), new Point3f(.01f,.01f,.01f));
      root.addChild(pointLight);

I then enable lighting like so

Code:
RenderOptions options = new RenderOptions();
//options.setOption(Option.USE_SHADOWS,true);
options.setOption(Option.USE_LIGHTING,true);

window.getCanvasPeer().setRenderOptions(options);

Note that window.getCanvasPeer() returns the CanvasPeer.

Does anyone know why my lighting doesn't work?

This is an open bug, that I hope to find better with the help of your example. Thanks for the hint.

Marvin
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #3 on: 12. December 2006, 04:58:27 pm »

Why in the world "XXXXXXLightControl" Huh
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 12. December 2006, 08:01:13 pm »

Why in the world "XXXXXXLightControl" Huh

Wow, haven't seen this... So, why the hell... Wink
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #5 on: 12. December 2006, 08:16:15 pm »

See the code posted by Patheros.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 12. December 2006, 08:24:38 pm »

See the code posted by Patheros.

Yeah, I saw it in Patheros' code. I just wanted to support your point Wink.
Logged
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« Reply #7 on: 12. December 2006, 08:28:20 pm »

Why in the world "XXXXXXLightControl" Huh

I forget that even existed. They are just sub classes that implement an interface I use. All my nodes do. I did that a while back when I was iterating through the render graph and calling methods on each node.

Back to the texture loading, I forgot to mention I'm loading the textures from a jar. And as a side note: once deployed it will be using java web start.
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #8 on: 12. December 2006, 08:44:21 pm »

Why in the world "XXXXXXLightControl" Huh

I forget that even existed. They are just sub classes that implement an interface I use. All my nodes do. I did that a while back when I was iterating through the render graph and calling methods on each node.

Do you know the (new) traverse() method on each Node? I think it will help you with this.

Back to the texture loading, I forgot to mention I'm loading the textures from a jar. And as a side note: once deployed it will be using java web start.

What I told you above, is working exactly for loading from JAR.

Marvin
Logged
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« Reply #9 on: 12. December 2006, 09:41:29 pm »

This is an open bug, that I hope to find better with the help of your example. Thanks for the hint.

What exactly is the bug? Is there a work around; a way to make textures and lighting work?
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #10 on: 12. December 2006, 10:09:12 pm »

This is an open bug, that I hope to find better with the help of your example. Thanks for the hint.

What exactly is the bug? Is there a work around; a way to make textures and lighting work?

I'm currently figuring this out. Lighting isn't always broken. See MD2LoaderTest or DynamicLightingTest. Lighting works in each single Xith3DTest except Cal3DLoaderTest (and your program). So this bug is not too easy to find. But I will keep you updated.

So far I can say, that in Cal3DLoader Test the Lighting works for the first animation frame. If I switch off animating, Lighting keeps working. So it has anything to do with the Node replacement, which is done in the precomputed model.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic