www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: cyberkilla on December 12, 2006, 08:40:52 pm

Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 08:40:52 pm
Hello everyone! I have managed to achieve this quite well....

My problem is, Im not sure how it would scale in terms of speed.

Please, please do me the huge favour of reading this through. My deadline is christmas, and its drawing dangerously near:O

(http://rpwar.com/forum/Attachments/testycool.png)

I currently have all tiles and objects(including npcs) in zordered linked list.
I draw the full list, including the models in the right order.

Unfortunately, I cant really cache the 3d models when its their turn to be rendered. It uses way too much memory. So, I must render them each time they are needed.

I have implemented a "dirty rectangles" system, so only the objects(tiles/npcs/etc) that intersect a dirty rectangle will be redrawn.

Here are the steps in order...IGNORING DIRTY RECTS:)

-Iterate through map objects, painting each at the right location...
-If its a tile, then paint a tile...
-If its an avatar(npc/player), then render model to 200x200 framebuffer,
with a MAGENTA background. Create new image with MAGENTA set to TRANSPARENT. Paint onto main backbuffer.


Now, that works. It really does. The problem is it seems like a lot of trouble. Is there any ways I can improve this?

Is faster/possible to make the map into some kind of 3d object itself, dynamically?
Is it possible to set the framebuffer jpct renders onto transparent, to cut out an extra step?

Also, how on earth could I have several different avatars?
I would think a separate world for each model would work perfectly,
but is it too memory intensive?

Thank you in advance for this!


BTW: My FPS is ~80 when im not painting anything new, but drops to
~30 when im in fullscreenmode, and moving my character.
In window mode, im lucky if i get 18, and its only ONE character:(.
Title: 2D Isometric Maps With 3D Models...
Post by: Mizuki Takase on December 12, 2006, 09:03:06 pm
Wow, your project looks really awesome! I miss the great video games like Crusader: No Remorse... Anyway!!


Quote
Is faster/possible to make the map into some kind of 3d object itself, dynamically?

Are your tiles small pieces of mesh? If so, then I would guess yes. I would assume that you can probably merge them all into one big Object3D map or so after translating the tiles before merging.

Quote
Is it possible to set the framebuffer jpct renders onto transparent, to cut out an extra step?

Why do you have to render your avatar onto a secondary framebuffer, set the alpha transparency and then placing that onto the main framebuffer? That sounds really tasking!

Quote
Also, how on earth could I have several different avatars?
I would think a separate world for each model would work perfectly,
but is it too memory intensive?

Several different avatars? I would guess to have different 3d meshes...
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 09:10:06 pm
Thank you:) Yes! I like Crusader too!:D

My tiles are 2D images. The dimensions are 48x24, and tiles with height
go up in increments of 15px.


I need to draw to another bufferedimage, because I NEED the model to have a TRANSPARENT background, so it can be drawn onto the map:)
I use MAGENTA as the background color, because its least used in my models:)
If I could get the thing to be transparent itself, OR PERHAPS get jpct
to render STRAIGHT ONTO my bufferedimage?

Is it possible to do that?:P


The models are 3D, and thats it:).
I currently set the camera and lights to a roughly isometric angle,
and make them look at the models center. This also happens to be the (0,0) of the world space, i think.

If I were to draw several different characters,  id have to keep moving the camera and lights(might be slow), or maybe you can hide all but the current model im rendering by setting them to totally transparent.

The other, probably easier way, might be to make a new world for each object, but i would imagine id be frowned on by people here;).
Title: 2D Isometric Maps With 3D Models...
Post by: Mizuki Takase on December 12, 2006, 09:18:24 pm
Hold the presses~! Have you ever considered making a lot of planes of your tiles and then use Object3D.setBillboarding(boolean mode)? Billboarding is something where the texture will always face the camera or so....

Oh, Object3D also have setVisibility(boolean). As quoted from the javadoc,
Quote
Sets the object to visible/invisible. Invisible objects won't be processed/rendered at all.
That sounds like something you wanted...
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 09:23:34 pm
No, I havent! I didnt know that feature was implemented in jpct!:D

The problem is, however:

How to make planes.
How to stack them so they look as they do now, with 2d drawing.
Is it faster than 2d, even in software render mode?
And, last, but not least....

How do I move the models now?:D I mean, I KNOW that one tile is 24x48,
and that I can move to then next, based on those dimensions.

How do I figure out the equivalent in 3d space? I  must admit, ive not wrapped my head around this:P
Title: 2D Isometric Maps With 3D Models...
Post by: Mizuki Takase on December 12, 2006, 09:29:42 pm
Ah~~ I keep on editting my own replies too slowly... Anyway!

I wanted to move Object3D stuff in 3d space and Egon told me this... http://www.jpct.net/forum/viewtopic.php?t=607&highlight=project

To make a plane, Primitives.getPlane(int quads, float scale) would help...

Shameless ad of my silly project.. Its supposed to be like Strider2 or Castlevania:Symphony of the Night... http://www.cs.uno.edu/~tvle/hotaru/New%20Text%20Document.htm
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 09:43:26 pm
Quote from: "Mizuki Takase"
Hold the presses~! Have you ever considered making a lot of planes of your tiles and then use Object3D.setBillboarding(boolean mode)? Billboarding is something where the texture will always face the camera or so....

Oh, Object3D also have setVisibility(boolean). As quoted from the javadoc,
Quote
Sets the object to visible/invisible. Invisible objects won't be processed/rendered at all.
That sounds like something you wanted...


That will be very,very helpful! Thank you for pointing that out:).
Thats one less problem.
Title: 2D Isometric Maps With 3D Models...
Post by: athanazio on December 12, 2006, 09:43:38 pm
I tried something with the planes... but got out of memory on that
http://www.jpct.net/forum/viewtopic.php?t=190&start=375

any ideas ?
Title: 2D Isometric Maps With 3D Models...
Post by: Mizuki Takase on December 12, 2006, 09:51:25 pm
To athanazio: I saw that, but was tooo scared to touch it with a stick...

Your code seems normal to me... Instead of constantly making a new plane with Primitives.getPlane(SQUARE_SIZE, 1); why not Object3D.cloneObject()? I hope that helps...
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 09:54:02 pm
Quote from: "athanazio"
I tried something with the planes... but got out of memory on that
http://www.jpct.net/forum/viewtopic.php?t=190&start=375

any ideas ?


Hmm, no idea, but i bet I get an out of memory:D
My biggest map so far is just over 4,000 tiles:)
Title: 2D Isometric Maps With 3D Models...
Post by: EgonOlsen on December 12, 2006, 10:03:20 pm
Don't create an object per tile. That's too much...as you've already noticed. Create the landscape as one single object out of single triangles (by using addTriangle) or create a plane of that size/tiling and manipulate that using an IVertexController as rolz suggested. In your code (if i've understood that correctly at first glance), you are are creating 50*50=2500 objects with 50*50*2=5000 polygons each, i.e. 12m polygons...a bit too much, isn't it?
Title: 2D Isometric Maps With 3D Models...
Post by: Mizuki Takase on December 12, 2006, 10:08:48 pm
Since addtriangle() sounds too complicated, I wanted to know if its okay to recursively create an instance Plane object and merge that onto the bigger shape and pray that the Java garbage collector to handle the memory stuff? athanazio posted code for that, and I was hoping that is not a bad solution...
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 10:11:06 pm
Any idea what I could do Egon? I am assuming you are speaking
to athanazio in that last post?

I am unsure it would be worth putting the tiles as billboarded planes,
as I need in excess of 8,000 in some cases.
Surely 2D is the way to go for me? Wouldnt it be faster to draw?
Especially considering I plan only to use Software Rendering:).


Is there any tricks for getting 3d models onto bufferedimages,
with the background transparent?
Everything I say sounds confusing:)

At the minute, im pretending that the render is a 2d sprite with a MAGENTA background, which i set all MAGENTA pixels to transparent.

Probably faster to do some sort of bit masking.
Title: 2D Isometric Maps With 3D Models...
Post by: EgonOlsen on December 12, 2006, 10:15:06 pm
I don't see where in his code he's doing this  :?: To me, it looks like as if he's just adding 5000 polygons in form of a 50*50 plane 2500 times into that array. Creating an object out of single triangles actually isn't that hard. There should be some code for this in the terrain-example in that old 0.96zip that's still available here: http://www.jpct.net/download/jpctapi_096.zip (This is just for demonstration purpose...the rest of this stuff is outdated...don't use it).
Title: 2D Isometric Maps With 3D Models...
Post by: EgonOlsen on December 12, 2006, 10:17:02 pm
@cyberkilla: I've to think about this a little...i'm not in the position to give a good answer for this now, i'm afraid.
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 12, 2006, 10:18:25 pm
Quote from: "EgonOlsen"
@cyberkilla: I've to think about this a little...i'm not in the position to give a good answer for this now, i'm afraid.


No problem. I realise its something that is rarely done.
It do not know why, however, because it is a fantastic way of
permitting detailed maps with a tiny polygon count:)
Title: 2D Isometric Maps With 3D Models...
Post by: athanazio on December 12, 2006, 10:44:06 pm
Egon, learned a lot from the sample that you said to look at, but I'm still missing how to add diffetent textures for pieces of the map.... any idea ?
Title: 2D Isometric Maps With 3D Models...
Post by: EgonOlsen on December 13, 2006, 12:53:15 pm
Quote from: "cyberkilla"

No problem. I realise its something that is rarely done.
It do not know why, however, because it is a fantastic way of
permitting detailed maps with a tiny polygon count:)
I took the time to read this over....and i would basically stick with what you are doing atm. Just make sure that your tiles are being hardware accelerated by making them "compatible" images. If you don't know what this means...the Buggaroo-sources (my 4k submission for this year's contest) do this, just have a look at the a(int mode, JFrame w, int wi,int hi, Color col)-method: http://www.jpct.net/4k/buggaroo/Buggaroo.java
Creating a new image every time seems quite expensive. I suggest to create a BufferedImage instead and refill its pixel data with the one from the framebuffer. You can't make these images "compatible" because you are accessing the pixels directly but as long as not 1000 avatars are on screen, this shouldn't matter. And as Mizuki mentioned, you can use one World and make only one object visible at a time to render it.
Title: 2D Isometric Maps With 3D Models...
Post by: cyberkilla on December 13, 2006, 04:27:23 pm
Aha! Well, this is good to know:)
Actually, I have each tile stored as a VolatileImage,
and the backbuffer is a buffered image.

They are all using createCompatible, but you have reminded me of a major mistake!
The function I made for quickly creating bufferedimages makes them ALWAYS bitmasked. And ive read a thousand times that bufferedimages with any transparency are not sped up as much as their opaque counterparts. In fact, I read last night that an opaque bufferedimage is a separate subclass of bufferedimage:).

I also found "getOutputBuffer()" which works for me, but just incase, I use "getType()" to make sure its compatible.

Since Microsoft is no longer leaving JVM1.1 on their browsers, and
forcing a lot of people to upgrade soon, I dont think JVM1.1 is a major concern for me. It is always nice to support it though.

My point is, I can use the actual backbuffer to make the transparent image. Its still creating a new instance every time it's painted,
but it is better than the 2 new instances I had to do before this.

Thank you Egon:)


EDIT:
Im using Swing for the gui you see, and to stop the need for repaints,
I have set the components to ignorerepaints, switched off the repaint manager, and now use a bufferStrategy.

The only problem is, we are talking about another backbuffer here.
I cant just paint the map to this backbuffer for some reason, because
it goes blank every time:) Ill figure it out eventually;)






Quote from: "EgonOlsen"
Quote from: "cyberkilla"

No problem. I realise its something that is rarely done.
It do not know why, however, because it is a fantastic way of
permitting detailed maps with a tiny polygon count:)
I took the time to read this over....and i would basically stick with what you are doing atm. Just make sure that your tiles are being hardware accelerated by making them "compatible" images. If you don't know what this means...the Buggaroo-sources (my 4k submission for this year's contest) do this, just have a look at the a(int mode, JFrame w, int wi,int hi, Color col)-method: http://www.jpct.net/4k/buggaroo/Buggaroo.java
Creating a new image every time seems quite expensive. I suggest to create a BufferedImage instead and refill its pixel data with the one from the framebuffer. You can't make these images "compatible" because you are accessing the pixels directly but as long as not 1000 avatars are on screen, this shouldn't matter. And as Mizuki mentioned, you can use one World and make only one object visible at a time to render it.