private static SubScene createSubScene(
      String title, Node node, Paint fillPaint, Camera camera, boolean msaa) {
    Group root = new Group();

    PointLight light = new PointLight(Color.WHITE);
    light.setTranslateX(50);
    light.setTranslateY(-300);
    light.setTranslateZ(-400);
    PointLight light2 = new PointLight(Color.color(0.6, 0.3, 0.4));
    light2.setTranslateX(400);
    light2.setTranslateY(0);
    light2.setTranslateZ(-400);

    AmbientLight ambientLight = new AmbientLight(Color.color(0.2, 0.2, 0.2));
    node.setRotationAxis(new Point3D(2, 1, 0).normalize());
    node.setTranslateX(180);
    node.setTranslateY(180);
    root.getChildren().addAll(setTitle(title), ambientLight, light, light2, node);

    SubScene subScene =
        new SubScene(
            root, 500, 400, true, msaa ? SceneAntialiasing.BALANCED : SceneAntialiasing.DISABLED);
    subScene.setFill(fillPaint);
    subScene.setCamera(camera);

    return subScene;
  }
예제 #2
0
  public void buildSubscene() {
    root = new Group();

    subScene = new SubScene(root, viewwidth, viewheight, true, SceneAntialiasing.BALANCED);
    subScene.setFill(Color.TRANSPARENT);

    Camera camera = new PerspectiveCamera();
    subScene.setCamera(camera);

    initializeParam();
  }
 public void layoutContent(boolean applyCSS) {
   if (scrollPane != null) {
     try {
       if (applyCSS) {
         contentSubScene.getRoot().applyCss();
       }
       scrollPane.layout();
       layoutException = null;
     } catch (RuntimeException x) {
       layoutException = x;
     }
   }
 }
예제 #4
0
  public Cutaway(SubScene scene, double width, double height) {
    // Make sure "world" is a group
    assert scene.getRoot().getClass().equals(Group.class);

    setFillWidth(true);
    setPrefSize(width, height + controlSize);
    setMaxSize(width, height + controlSize);
    this.setBorder(
        new Border(
            new BorderStroke(
                Color.DARKKHAKI,
                BorderStrokeStyle.SOLID,
                new CornerRadii(25),
                new BorderWidths(5))));

    Rectangle closeSquare = new Rectangle(controlSize, controlSize, Color.LIGHTCORAL);
    closeSquare.setOnMouseClicked(
        (MouseEvent me) -> {
          this.fireEvent(new CloseCutawayEvent(this));
        });
    Circle dragCircle = new Circle(controlSize / 2, Color.STEELBLUE);

    HBox top = new HBox(20, closeSquare, dragCircle);
    dragCircle.setVisible(false);
    StackPane.setAlignment(closeSquare, Pos.TOP_RIGHT);
    StackPane.setMargin(closeSquare, new Insets(50));

    top.setBackground(
        new Background(
            new BackgroundFill(Color.KHAKI, new CornerRadii(20, 20, 0, 0, false), Insets.EMPTY)));

    top.setAlignment(Pos.TOP_RIGHT);

    top.setOnMousePressed(
        (MouseEvent me) -> {
          cutawayPosX = me.getSceneX();
          cutawayPosY = me.getSceneY();
          cutawayOldX = me.getSceneX();
          cutawayOldY = me.getSceneY();
        });
    top.setOnMouseDragged(
        (MouseEvent me) -> {
          cutawayOldX = cutawayPosX;
          cutawayOldY = cutawayPosY;
          cutawayPosX = me.getSceneX();
          cutawayPosY = me.getSceneY();
          cutawayDeltaX = (cutawayPosX - cutawayOldX);
          cutawayDeltaY = (cutawayPosY - cutawayOldY);
          setTranslateX(getTranslateX() + cutawayDeltaX);
          setTranslateY(getTranslateY() + cutawayDeltaY);
        });

    getChildren().addAll(top, imageView);

    worldToView = (Group) scene.getRoot();

    camera.setNearClip(0.1);
    camera.setFarClip(15000.0);
    camera.setTranslateZ(-1500);
    params.setCamera(camera);

    params.setDepthBuffer(true);
    params.setFill(Color.rgb(0, 0, 0, 0.5));

    viewTimer =
        new AnimationTimer() {
          @Override
          public void handle(long now) {
            redraw();
          }
        };
    setOnMouseEntered(
        e -> {
          requestFocus();
        });
  }
  private void adjustWorkspace() {
    final Bounds backgroundBounds, extensionBounds;

    final Object userSceneGraph;
    if (fxomDocument == null) {
      userSceneGraph = null;
    } else {
      userSceneGraph = fxomDocument.getSceneGraphRoot();
    }
    if ((userSceneGraph instanceof Node) && (layoutException == null)) {
      final Node rootNode = (Node) userSceneGraph;

      final Bounds rootBounds = rootNode.getLayoutBounds();

      if (rootBounds.isEmpty()
          || (rootBounds.getWidth() == 0.0)
          || (rootBounds.getHeight() == 0.0)) {
        backgroundBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
        extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
      } else {
        final double scale;
        if ((rootBounds.getDepth() > 0) && autoResize3DContent) {
          // Content is 3D
          final double scaleX = AUTORESIZE_SIZE / rootBounds.getWidth();
          final double scaleY = AUTORESIZE_SIZE / rootBounds.getHeight();
          final double scaleZ = AUTORESIZE_SIZE / rootBounds.getDepth();
          scale = Math.min(scaleX, Math.min(scaleY, scaleZ));
        } else {
          scale = 1.0;
        }
        contentGroup.setScaleX(scale);
        contentGroup.setScaleY(scale);
        contentGroup.setScaleZ(scale);

        final Bounds contentBounds = rootNode.localToParent(rootBounds);
        backgroundBounds =
            new BoundingBox(
                0.0,
                0.0,
                contentBounds.getMinX() + contentBounds.getWidth(),
                contentBounds.getMinY() + contentBounds.getHeight());

        final Bounds unclippedRootBounds = computeUnclippedBounds(rootNode);
        assert unclippedRootBounds.getHeight() != 0.0;
        assert unclippedRootBounds.getWidth() != 0.0;
        assert rootNode.getParent() == contentGroup;

        final Bounds unclippedContentBounds = rootNode.localToParent(unclippedRootBounds);
        extensionBounds = computeExtensionBounds(backgroundBounds, unclippedContentBounds);
      }
    } else {
      backgroundBounds = new BoundingBox(0.0, 0.0, 320.0, 150.0);
      extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
    }

    backgroundPane.setPrefWidth(backgroundBounds.getWidth());
    backgroundPane.setPrefHeight(backgroundBounds.getHeight());
    extensionRect.setX(extensionBounds.getMinX());
    extensionRect.setY(extensionBounds.getMinY());
    extensionRect.setWidth(extensionBounds.getWidth());
    extensionRect.setHeight(extensionBounds.getHeight());

    contentSubScene.setWidth(contentGroup.getLayoutBounds().getWidth());
    contentSubScene.setHeight(contentGroup.getLayoutBounds().getHeight());
  }
 public void setThemeStyleSheet(String themeStyleSheet) {
   assert themeStyleSheet != null;
   contentSubScene.setUserAgentStylesheet(themeStyleSheet);
 }