Author Topic: Re-use multi texturing  (Read 2796 times)

Offline IJs

  • byte
  • *
  • Posts: 2
    • View Profile
    • http://www.mtavc.com
Re-use multi texturing
« on: July 29, 2005, 12:46:40 pm »
I'm trying to create a dynamic loader for maps in Java using jPCT.
It reads a specific file format, that contains some sort of grid (including x,y,height and texture type) that can be used to generate the map.

The map itself is based on planes (for the ground) and blocks (for everything above ground level) with a pre-defined width and length. So every plane/block is equal in size, except from the height.

The problem here is the (multi) texturing.
Right now I'm having the map generator create a new Object3D whenever a new texture is used. The result is the following:

(Don't mind the gaps in the middle, they're just for testing)

As you can see, there are two kinds of textures. That means in this case two Object3D's have been generated, for each set of planes with the same texture.
I'm doing that because it's not possible to load multiple textures into one Object3D, when it's not created by the 3ds-loader.

Here's the real problem.
This solution is OK for planes. But once I start creating blocks, that should be able to have 5 different textures assigned to them (each side + top of it) it might get a little bit out of hand since I'll have to create 5 different Object3D's for 1 block.
I think I'll have pretty much blocks on the map, so creating 5 Object3D's for each block seems a waste of memory.

Or does jPCT have some sort of hidden multi-texturing function?

Now I thought of using 3DS files to use the multi-texturing feature of the 3ds-loader.
But let's say I'm using 1 3DS file with the block mesh in it, and pre-defined texture names (such as 'side', 'top', 'left', etc.).
I'll have to load the 3DS file whenever I want to create a new block. And since the 3DS file has pre-defined texture names ('side', 'top'), this means all blocks will get the same texture. Right?
Or maybe I'm able to assign different files to the same texture? Like this (simplified!):
Code: [Select]
//generation of block 1
obj3d.Load3DS("block.3ds");
texmanager.AddTexture("side","texture1.jpg");
// generation of block 2
obj3d.Load3DS("block.3ds");
texmanager.AddTexture("side","texture2.jpg");

But this probably means both blocks will have texture2.jpg as side-texture.

Any ideas?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re-use multi texturing
« Reply #1 on: July 29, 2005, 02:36:00 pm »
You can assign different textures to an Object3D with either the 3DS loader (as you you've already mentioned) or with the addTriangle(...)-method in Object3D. Because you are writing a loader, i assume that you are already using one of those. Simply change to one with a textureID as parameter and you should be fine.

Offline IJs

  • byte
  • *
  • Posts: 2
    • View Profile
    • http://www.mtavc.com
Re-use multi texturing
« Reply #2 on: July 29, 2005, 03:07:47 pm »
Code: [Select]
int addTriangle(SimpleVector vert1, float u, float v, SimpleVector vert2, float u2, float v2, SimpleVector vert3, float u3, float v3, int textureID)
          Adds a triangle to the object.


That's exactly what I needed.

Thanks very much!

btw jPCT is an excellent piece of work.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re-use multi texturing
« Reply #3 on: July 29, 2005, 03:42:09 pm »
BTW: If you want to modify existing objects' textures on a per polygon base, you can use the PolygonManager which you can obtain from an Object3D by calling getPolygonManager();