Author Topic: Two Textures On Single-Part Model  (Read 5939 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Two Textures On Single-Part Model
« on: August 16, 2014, 04:34:35 pm »
Is there a way for me to assign two diffuse texture maps to a single-part model, much like 3ds max can do for object ids (say, a texture map just for the head, another one for the body)? I have some critical models that need this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #1 on: August 16, 2014, 04:57:21 pm »
Either export them as separate models or as one model that uses two textures. You then have to let the loader to the assignment by adding the textures with the proper namens before loading the mesh. You can't do it with setTexture, as you will have noticed.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #2 on: August 16, 2014, 05:00:43 pm »
I can't export as separate parts because it's a rigged model. I don't understand your second suggestion.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #3 on: August 16, 2014, 05:04:41 pm »
The loader assign texture to the mesh at load time. You don't have to use setTexture() for this. Their names in the TextureManager just have to match the names in the file. Like described here: http://www.jpct.net/wiki/index.php/Loading_models

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #4 on: August 16, 2014, 05:12:02 pm »
I have the exact same names, added to the TextureManager before the model, and my model is still being loaded texture-lessly.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #5 on: August 16, 2014, 05:17:42 pm »
I should mention that I'm using the software renderer in this case.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #6 on: August 16, 2014, 06:18:13 pm »
The renderer doesn't matter. If it doesn't assign the textures at load time, the names are not correct. Have a look at the log output, it should print out the names.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #7 on: August 16, 2014, 06:29:04 pm »
This is the log. No complaints about the texture:

Quote
Java version is: 1.7.0_25
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Software renderer (OpenGL mode) initialized
Loading Texture...QG1_body_Difuse.png
Software renderer disposed
Loading Texture...QG1_head-Difuse.png
Loading Texture...QG1_Weapons-difuse.png
Wrapping input stream in a BufferedInputStream
Is animatedGroup null? false
Adding Lightsource: 0
New WorldProcessor created using 1 thread(s) and granularity of 1!
Creating new world processor buffer for thread Thread-2

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #8 on: August 16, 2014, 06:33:29 pm »
That's just the loading of the textures, not of the model. At least not using jPCT's loaders. If this is a Bones object, then i can't comment on that. What i said about this topic applies to jPCT's Loader class only.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #9 on: August 16, 2014, 06:41:28 pm »
Arrrgh. I will repost it on the Bones board, then.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #10 on: August 17, 2014, 08:58:22 pm »
It turns out that although the head and body are merged in Max, Bones is getting them as separate objects. The problem should be done with, except for the fact that the texture coordinates are broken. The original textures are 2048x2048 in size. But at that size, after calling setTexture on both the head and the body, all I get is black (clearly because only the black part of the texture is being textured on the model). When I edit the textures to rescale them to 1024x1024, I get some of the non-black texture parts (albeit the wrong parts in the wrong places). The following textures are producing the following model:






Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #11 on: August 18, 2014, 09:35:15 am »
Just like raft mentioned in the other thread, a call to recreateTextureCoords() after assigning the new texture should actually help, given that the coordinates are correct. This is needed for the software renderer only, btw. The hardware ones don't need this call (it doesn't hurt though).

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Two Textures On Single-Part Model
« Reply #12 on: August 18, 2014, 01:09:00 pm »
But just like I mentioned there, I tried that and nothing changed. Besides, I'm not scaling the textures at runtime. I edited the files. And I'd rather not HAVE to edit them, but when unedited I only get black.

Your given isn't a given at all: the coordinates are not correct.
« Last Edit: August 18, 2014, 01:25:25 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #13 on: August 18, 2014, 03:15:06 pm »
"given that" means that it's a precondition. If the coordinates in the file are bogus already, no call to any method will be able to fix that.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two Textures On Single-Part Model
« Reply #14 on: August 18, 2014, 03:25:23 pm »
And I'd rather not HAVE to edit them, but when unedited I only get black.
Texture coordinates are normalized. It actually doesn't matter if you are using a 4*4 or a 4096*4096 texture, the coordinates will be the same for each. That doesn't fully apply to the software renderer, because it doesn't work with normalized coordinates internally. Instead, it creates an additional data set with coordinates that match the texture size. It does that at load time (with the assumption that the texture will be 256*256 because it doesn't know any better), at build()-time (with the dimensions of the texture currently assigned) and if you call recreateTextureCoords() (also with the texture currently assigned).
You might want to use a PolygonManager to print out the actual texture coordinates (the normalized ones...) to see how they look. Also make sure that clamping has been disabled (Texture.setClamping(true)) Edit: (Texture.setClamping(false)).

If nothing else helps: Have you tried to render it with the hardware renderer instead? The software renderer has a limitation regarding repeating textures, which might apply to models with texture coordinates far outside of the [0..1] interval.
« Last Edit: August 18, 2014, 03:37:14 pm by EgonOlsen »