0

I am trying to create a "custom widget" (extends HBox) which renders 3D graphics.

The problem is that all the examples I see for setting the camera, show how to do it on the main "scene", which belongs to the main window.

I don't want any relation to the main Window, I want it to be an independent widget.

Is it anyway possible to do that?

I'll be glad if you can share some code example, as I feel pretty lost with it...

SomethingSomething
  • 11,491
  • 17
  • 68
  • 126
  • 4
    I've never tried this, but try wrapping your content in a [`SubScene`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/SubScene.html). You can set a camera of your choosing on the `SubScene`, and client code can add it to any other scene graph. – James_D Aug 04 '16 at 17:26

1 Answers1

0

I am not quite sure if I understood you correctly, but if you want the camera to be transformable, you can insert it into the Scene Graph where ever you want. You can add it to a group node like this:

Group someGroup = new Group();
PerspectiveCamera camera = new PerspectiveCamera();
someGroup.getChildren().add(camera);

Scene s = new Scene(someGroup);
s.setCamera(camera);

When you now move the Group node the camera moves as well. You can add the camera to any Group node you want, but I am not sure what happens when you put it into a Group node that uses LayoutManagement like HBox.

The important thing is you always have to add the camera to the Scene that it is in.

Jhonny007
  • 1,698
  • 1
  • 13
  • 33