www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: 9kaywun on August 14, 2012, 01:06:49 pm

Title: tile system?
Post by: 9kaywun on August 14, 2012, 01:06:49 pm
I need to implement a simple tile system into my 3d game client for npc/prop rendering.. I am using Primitives.getPlane(quad, scale) to generate a small region, but I can't figure out how I could go about making an imaginary 96x96 grid with textures rendered over it.
I have already written a method to load map data from a file and would render the scene like so <regionId, tileId, textureId>
I also would like to be able to not have any negative ids for tiles because it over complicates certain functions I intend on integrating server-sided in the future.
Title: Re: tile system?
Post by: EgonOlsen on August 14, 2012, 03:02:47 pm
I don't get the question...you want to create on object that consists of 96*96 quads? Or 96*96 individual quads? And what does this have to do with negative ids?
Title: Re: tile system?
Post by: Disastorm on August 15, 2012, 04:50:52 am
e3d, are you asking how to make a 96X96 tile board with each tile represented by a plane with a custom texture based on a map file?
Title: Re: tile system?
Post by: 9kaywun on August 15, 2012, 07:38:27 am
e3d, are you asking how to make a 96X96 tile board with each tile represented by a plane with a custom texture based on a map file?

Yes. Exactly.
Title: Re: tile system?
Post by: Disastorm on August 15, 2012, 08:13:45 pm
You can just read through the map file and for each entry create a tile in the appropriate location.  For example you can decide to have the first tile at 0,0(with arbitrary z value) then when you read the next tile you can place it at like 50,0 then 100,0 and make them have a width of 50. At some point then you also want to make the rows start going down so then you reset the x to 0 and increment the y and then continue incrementing the x again.
Title: Re: tile system?
Post by: 9kaywun on August 15, 2012, 08:47:16 pm
You can just read through the map file and for each entry create a tile in the appropriate location.  For example you can decide to have the first tile at 0,0(with arbitrary z value) then when you read the next tile you can place it at like 50,0 then 100,0 and make them have a width of 50. At some point then you also want to make the rows start going down so then you reset the x to 0 and increment the y and then continue incrementing the x again.

Much appreciated, Disastorm!
Title: Re: tile system?
Post by: 9kaywun on October 08, 2012, 09:52:57 pm
Realized that creating so many Object3D instances (1 per tile) is not very efficient... Is there another way I can go about rendering this? Such as rendering a plane, and mapping a specific texture to each "tile" in the x/y loop?
Title: Re: tile system?
Post by: EgonOlsen on October 08, 2012, 09:58:57 pm
The easiest thing might be to take your already existing tiles and merge into one large object by using Object3D.mergeAll(..). You can't modify them individually after that, of course...
Title: Re: tile system?
Post by: 9kaywun on October 08, 2012, 11:25:11 pm
The easiest thing might be to take your already existing tiles and merge into one large object by using Object3D.mergeAll(..). You can't modify them individually after that, of course...

Rebuild my region constructor.. Having a problem with the region looking like it did before. Not sure what I did wrong though?
Here is a picture to show the issue. Left side is a test app, sharing the renderer with the Game app (right) and using the old/new region systems.
(Image was too wide to use img tags, so here is the url)
http://i.troll.ws/3a10358e.png

and here's the code.. Maybe I am translating tiles wrong??
Code: [Select]
- removed
Title: Re: tile system?
Post by: EgonOlsen on October 08, 2012, 11:29:41 pm
The merging doesn't care about rotations and translation until you make them permanent. Try to add tiles[y].rotateMesh() and tiles[y].translateMesh() in your loop to make them permanent.
Title: Re: tile system?
Post by: 9kaywun on October 08, 2012, 11:33:35 pm
The merging doesn't care about rotations and translation until you make them permanent. Try to add tiles[y].rotateMesh() and tiles[y].translateMesh() in your loop to make them permanent.

That did flatten the tiles in the world space. Now I just have to position them properly on my end of the code.. Thanks, such hasty support is very much appreciated ;)