Skip to main content

A BranchGroup object with multiple parents

3 replies [Last post]
prubio
Offline
Joined: 2006-02-14

Is this possible? I want to create a scene that must be rendered in two different Frames (two different Canvas3D). How can I do this? Both Frames must show the same scene (the same BranchGroup).

I can't do this with SimpleUniverse class, but with VirtualUniverse class...

Help me, please.

Thank you.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nitro
Offline
Joined: 2004-09-12

You can just add new Canvas3D to your current View object. you can get it from your simple universe by:
[code]
SimpleUniverse u=new SimpleUniverse();
u.getViewer().getView().addCanvas3D(secondCanvas3d);
[/code]

prubio
Offline
Joined: 2006-02-14

Thank you, 'nitro'.

I'm trying to share the main SimpleUniverse (rendered in Frame1) with another SimpleUniverse (rendered in Frame2). I'm using the suggested method:

universe1.getViewer().getView().addCanvas3D(secondCanvas3d);

It works! But... Obvially, both universes shares the same view transforms. Could I make differents view transforms for these universes? I suppose that the answer is 'no', because i've programmed:

universe2 = universe1;

Maybe there is a better way to do this.

I'm waiting for your answers.

Thank you.

nitro
Offline
Joined: 2004-09-12

You can create a new ViewPlatform add id to your viewBranch under a separate TransformGroup and add the second view there.
Here is an example when not using SimpleUniverse:

[code]
public TransformGroup createView(Canvas3D canvas) {
canvas.setMinimumSize(new Dimension(0, 0));

View view = new View();
view.setFrontClipPolicy(View.VIRTUAL_EYE);
view.setBackClipPolicy(View.VIRTUAL_EYE);

ViewPlatform vp = new ViewPlatform();
view.attachViewPlatform(vp);

tg = new TransformGroup();
DefaultCapabilites.setDefaultCapabilities(tg);
tg.addChild(vp);

PhysicalBody pb = new PhysicalBody();
view.setPhysicalBody(pb);

PhysicalEnvironment pe = new PhysicalEnvironment();
view.setPhysicalEnvironment(pe);

view.addCanvas3D(canvas);
return tg;
}

//somewher in your code

BranchGroup viewBranch=new BranchGroup();
Canvas3D c1=new Canvas3D(...);
Canvas3D c2=new Canvas3D(...);
TransformGroup tgv1=createView(c1)
viewBranch.addChild(tgv1);
TransformGroup tgv2=createView(c2)
viewBranch.addChild(tgv2);
//add your canvases wherever you wan't
//change the tg's to your required position.
//For example you could add two TranslateBehaviours that
//operates on tgv1 and one on tgv2 afterwards you can
//enable them when the the respective cans3d gets focus

[/code]

[Besides do not create two universes for the same scene.]