Author Topic: How to add texture to textured object  (Read 2972 times)

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
How to add texture to textured object
« on: November 16, 2009, 04:43:13 pm »
Hello,

Is it possible to add additional texture to loaded 3ds object that already has some textures?

I see that there is a
Code: [Select]
public void setTexture(TextureInfo tInf) method, but it replaces all existing textures that are associated to the object and I do not see any methods that will be able to return texture list that is already assigned to object.

What I want to do is to add an additional texture that will be used as envmap (just like in viper example http://www.jpct.net/forum2/index.php/topic,988.0.html).

Thanks,
Wojtek

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to add texture to textured object
« Reply #1 on: November 16, 2009, 05:48:28 pm »
Depends on if the object actually uses multiple textures. If it doesn't, the setTexture-method in Object3D is sufficient. If it does, you have to use the PolygonManager to achieve this. Just iterate over each polygon, get the texture id and the u/v coordinated for each vertex, create a new TextureInfo with that, add you additional texture to it and  re-assign it using the PolygonManager. It's a bit awkward though.

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: How to add texture to textured object
« Reply #2 on: November 17, 2009, 05:17:45 pm »
Thank you for response. It works :)

Now I have another question. When I added the envmap image, I have lost the shadow effect. There are example screenshots.
The first is with glare effect, and the second is without:



Can you please explain me why the shadow effect disappeard, and if it is possible to have both effects at the same time?

I can add that right now I am not using the ShadowHelper class so this is a standard shadow effect.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to add texture to textured object
« Reply #3 on: November 17, 2009, 06:03:58 pm »
That's caused by the way the OpenGL rendering pipeline works. You can try to switch the texture stages when assigning the textures and set Config.glForceEnvMapToSecondStage to true.

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: How to add texture to textured object
« Reply #4 on: November 18, 2009, 12:03:18 am »
Thank you for your help once again. It works of course :)

There is a screenshot:

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: How to add texture to textured object
« Reply #5 on: December 13, 2009, 01:56:42 pm »
Hello,

I would like to ask if it is possible to get the list of textures that are assigned to given polygon?

The PolygonManager have void setPolygonTexture(int polyID, TextureInfo tInf) method where TextureInfo allows to add many textures to it,
and there is a int getPolygonTexture(int polyID) method that returns id of one texture, but I cannot find any method that will return a list of textures assigned to given polygon.

Thanks,
Wojtek

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to add texture to textured object
« Reply #6 on: December 13, 2009, 11:19:39 pm »
Currently, that's not possible. I'm going to add it to the PolygonManager.

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: How to add texture to textured object
« Reply #7 on: December 14, 2009, 12:05:23 am »
Ok, so i will hold that information in my classes for now.

Thanks,
Wojtek

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to add texture to textured object
« Reply #8 on: December 14, 2009, 09:09:44 pm »
I've uploaded the version (http://www.jpct.net/download/beta/jpct.jar) that has a getPolygonTextures()-method added to the PolygonManager. It's totally untested and the returned int[]-array may contain TextureManager.TEXTURE_NOTFOUND-ids for all unused stages. Once you encounter such a texture, you can break.

Please let me know if it works, because, as said, i haven't tested it at all.

Offline Wojtek

  • int
  • **
  • Posts: 62
    • View Profile
Re: How to add texture to textured object
« Reply #9 on: January 12, 2010, 11:19:34 pm »
Hello,

Excuse me that I have not replied earlier :(
I have tested that new method and it seems to work correctly.

Thanks,
Wojtek