Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Best solution to display 2D layer on top of 3D scene  (Read 2728 times)
0 Members and 1 Guest are viewing this topic.
Offline faldo1

Junior Newbie





« Posted 2012-05-09 11:15:12 »

Hello,

I write a little Java3D program and I need to display a 2D layer on top of my 3D scene with

- dynamic stats (FPF, memory usage, ...)
- dynamic hour (rendered as an analog watch).

I searched on the web and I think I would use a PlatformGeometry

So, I created the following structure

PlatformGeometry => TransformGroup => BranchGroup => Text2D

But I have to create/update the Text2D on every frame.

When I try to do that (add a Text2D as a Child of the BranchGroup), I get an error

javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node may be added

I get an equivalent error when I try to remove previous Text2D child from the BranchGroup.

I think I gave the needed capabilities to the BranchGroup.

_statsBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
_statsBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);


I also see I can remove the BranchGroup from the TransformGroup without getting any error. But, I don't think it's efficient on every frame to

- remove '2D stats' BranchGroup from '2D stats' TransformGroup
- create new '2D stats' BranchGroup
- create new Text2D and add it as child to '2D stats' BranchGroup
- add new '2D stats' BranchGroup to the '2D stats' TransformGroup.

So, what is the best solution ?

Thanks for all.

Offline ylliac

Junior Newbie





« Reply #1 - Posted 2012-05-09 12:02:36 »

Hi,

If you just have to update the text of the Text2D, setString() should be enough.

If you have to create another Text2D, the solution I see is :

- Detach the Text2DBranchGroup. This branchgroup should have the capability BranchGroup.ALLOW_DETACH, Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE and the parent node should have the capabilities Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE.
- Remove the Text2D from the Text2DBranchGroup. No exception will be thrown I think because the Text2DBranchGroup is no longer alive.
- Create a new Text2D and add it to the Text2DBranchGroup.
- Attach the Text2DBranchGroup to his last parent.

Regards,
Antoine
Offline faldo1

Junior Newbie





« Reply #2 - Posted 2012-05-09 13:06:39 »

Hello Antoine,

I tried what you said and it works. The Text2D is just a little bit blinking but it doesn't matter.

Thanks / merci

But I see a strange effect.

The z offset of my Text2DBranchGroup is -2
In my scene, there is a tree at z = -50

The Text2D in the Text2DBranchGroup is displayed on top of tree trunc, ok, but the tree leafs (transparent texture) are displayed on top Text2D  !

It seems there is a z-buffer bug between 3D scene and PlatformGeometry.

Maybe is it related to my clipping ?

mainView.setFrontClipDistance(0.4f);
mainView.setBackClipDistance(1200.0f);

I need these values to display near objects and very far away ones.

Any idea ?

Thanks
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.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (90 views)
2014-09-10 06:39:09

Tekkerue (44 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (48 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (37 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!