Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Multiple objects in Java3D  (Read 2566 times)
0 Members and 1 Guest are viewing this topic.
Offline fernfreak

Junior Newbie




Java games rock!


« Posted 2005-09-06 16:27:35 »

Hi!

I'm rather new to Java3D, and I was wondering what the apropriate way to include multiple objects in a scene is.

Right now, I'm loading Shape3Ds for each of my entities and attaching them to a SimpleUniverse directly by means of BranchGroups (no hierachy). The entities are all represented by the same mesh, but each one loads a copy of the same mesh data, which isn't exactly a great thing. When I need them out of the scene, I detach their BranchGroup linkages.

While reading through the forum, I realise these practices are definitely not right.
I was wondering if i could store the geometry just once, then reference the mesh data each time I draw a copy of the mesh on screen?

thanks in advance for the help! Smiley
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2005-09-06 19:24:49 »

Distinguish between 'Node' and 'NodeComponent'. You can copy a subtree while keeping the NodeComponents as references w/o copy.

In FlyingGuns e.g. the subtrees provided by the loader are just replicated via cloneTree(). This gives a new subtree while meshes and textures stay the same.

http://cvs.sourceforge.net/viewcvs.py/drts/projects/threed/java3d/core/java/de/hardcode/threed/objects/

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline fernfreak

Junior Newbie




Java games rock!


« Reply #2 - Posted 2005-09-07 04:09:25 »

Thanks for the advice! I shall use that right away. Smiley
Just one other question though... if I clone a subtree per entity, is it apropriate for me to detach them from the universe in order to remove an entity, or is this an expensive operation?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2005-09-07 04:38:55 »

If you build the trees by hand the rule is you cant share a node, but you can share a Geometry object and Texture objects betrween multiple Shape3D nodes and thats where msot of your memory is loaded and used Smiley

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #4 - Posted 2005-09-07 10:50:49 »

Thanks for the advice! I shall use that right away. Smiley
Just one other question though... if I clone a subtree per entity, is it apropriate for me to detach them from the universe in order to remove an entity, or is this an expensive operation?

What other options exist than detaching? If the entity is no longer needed, detach it. Although I have no idea about the costs. (event propagation, bounds re-evaluation, renderer instruction).

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2005-09-07 11:26:11 »

You could hide it, then keep it in a pool for the next time you need one of those objects. When you need it, move it to the correct location and make it visible again.

From what I remember all that time ago, detaching used to be the thing that Java3D people worried about (I assumed overhead of recomputing bounds etc). However, in my tests at the time I didn't see a significant problem with it.

Kev

Offline endolf

JGO Knight


Medals: 7
Projects: 1


Current project release date: sometime in 3003


« Reply #6 - Posted 2005-09-07 13:08:16 »

Hi

I remeber having the problem, detaching objects would cause glitches, I'm guessing it was gc related, but didn't explore it, I did as kev suggests and moved the object somewhere it wouldn't be seen, and added it to a pool of objects to use later if I needed on.

Endolf

Offline fernfreak

Junior Newbie




Java games rock!


« Reply #7 - Posted 2005-09-08 15:43:49 »

Would it be viable for me, then, to frequently add and detach large numbers of objects in a game situation, say, rapid fire projectiles that need to be moved along their trajectory? I was wondering what would be the established way of doing this...

I really don't know about the inner workings of Java3D, but detaching does sound like it could be expensive, especially if Java is attempting to optimise the render using the tree...  but then again, wouldn't hiding the objects out of sight by drastically changing their position, force a recomputation of bounds and etc as well?
but in line with the object hiding idea, is there is a cheap way to toggle a visibility for a branch?

Nonetheless, I'll try out both in code (hiding and detaching) and post the results in case anyone's interested...

Thanks so much for all the kind responses and suggestions! Smiley
really appreciate all that effort ^^
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #8 - Posted 2005-09-08 16:23:36 »

You could hide it,

Sounds stupid, but how to?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2005-09-08 17:39:03 »

Set the Appearance->RenderingAttributes visibility flag.

http://download.java.net/media/java3d/javadoc/1.4.0-latest/javax/media/j3d/RenderingAttributes.html#setVisible(boolean)

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #10 - Posted 2005-09-09 10:17:45 »

Hm, appearences are per node? Is visibility inherited?

If not, this would be a problem for complex, deeply nested objects with many Shape3D?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #11 - Posted 2005-09-09 16:36:02 »

Yeah, it would be if you just used the nodes directly I guess. I generally wrapped up collections of Shape3D nodes representing things in the game in game specific objects derived from TransformGroups. So setting the visibility was pretty easy all in one go.

Kev

Offline Jeff

JGO Coder




Got any cats?


« Reply #12 - Posted 2005-09-12 09:50:12 »

There is one bug I know of that resulted in memory issues if you did a lot of attaching/detaching.  The J3D team knew about it.  Im not sure what the status was but I can check.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #13 - Posted 2005-09-12 09:50:38 »

ANother option btw is the Switch node.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline NVaidya

Junior Member




Java games rock!


« Reply #14 - Posted 2005-09-12 13:30:36 »

Yup, the Switch node is a particularly good option if you intend to re-use the scenegraph.

Detaching a BranchGroup isn't MT safe in Java3D. The workaround is to do it from within a Behavior - for example, by having a Behavior waking up on a BehaviorPost by doing a postId() to itself.

And, yes, there is still a very annoying memory leak issue with detaching a BranchGroup. The "hack" which seems to work fairly  well for me is to attach and immediately detach a BranchGroup after you detach your actual BranchGroup.

And Java3D still relies upon finalizers in certain parts of the API.....

Gravity Sucks !
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #15 - Posted 2005-09-14 21:24:09 »

Detaching a BranchGroup isn't MT safe in Java3D. The workaround is to do it from within a Behavior - for example, by having a Behavior waking up on a BehaviorPost by doing a postId() to itself.

Code sample?

I'm in luck that my whole game runs within a (the single existing) Behavior....

Quote
And, yes, there is still a very annoying memory leak issue with detaching a BranchGroup. The "hack" which seems to work fairly  well for me is to attach and immediately detach a BranchGroup after you detach your actual BranchGroup.

You mean attach/detach any other (empty?) instance of a BranchGroup?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline NVaidya

Junior Member




Java games rock!


« Reply #16 - Posted 2005-09-16 11:54:57 »

Code sample?

I'm in luck that my whole game runs within a (the single existing) Behavior....

A typical example is the AWT_Interaction/AWTInteractionBehavior.java available in the Java 3D demo bundle, in which the Id is posted from  the EDT to wake up the Behavior and trigger a call to the processStimulus(...) method wherein the code for BG detach can be handled.
Ah yes, having a single behavior makes it easier  ...!

Quote
You mean attach/detach any other (empty?) instance of a BranchGroup?

Yes, in my experience, and there is also a long neglected Issue filed on this, simply attaching and detaching an empty BG from the parent which just had one of its children removed, seems to clean up much of the associated leak.

Gravity Sucks !
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (46 views)
2014-04-15 18:08:23

BurntPizza (42 views)
2014-04-15 03:46:01

UprightPath (58 views)
2014-04-14 17:39:50

UprightPath (40 views)
2014-04-14 17:35:47

Porlus (56 views)
2014-04-14 15:48:38

tom_mai78101 (79 views)
2014-04-10 04:04:31

BurntPizza (138 views)
2014-04-08 23:06:04

tom_mai78101 (238 views)
2014-04-05 13:34:39

trollwarrior1 (199 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!