javafx 3d Meshview轮换

时间:2016-03-07 19:12:49

标签: java javafx javafx-3d

我想旋转马达的轴,但没有设法达到预期的行为。

motor model

我得到的轮换就是这个。

motor model

这是我正在使用的代码,其中竖井是我要旋转的MeshView:

    Model3D motor = new Model3D("motor.obj");

    Map<String, MeshView> meshMapMotor = motor.getMapMeshes();
    Pane gpMotor = new Pane();

    for (Map.Entry<String, MeshView> entry : meshMapMotor.entrySet()) {
        String key = entry.getKey();
        MeshView value = entry.getValue();
        Rotate rot = new Rotate(180);
        rot.axisProperty().set(Rotate.Y_AXIS);
        value.getTransforms().add(rot);
        gpMotor.getChildren().add(value);
        System.out.println("name: " + key);

        if (key.equals("default (3)")) {
            shaft = value;
        }
    }
    gpMotor.setTranslateZ(7);
    Rotate rot = new Rotate(1);
    rot.axisProperty().set(new Point3D(0, 0, 1));
    shaft.getTransforms().add(rot);

    if (shaft != null) {
        KeyFrame shaftFrame = new KeyFrame(Duration.millis(100), new KeyValue(rot.angleProperty(), 360));
        motorRunning = new Timeline(shaftFrame);
        motorRunning.setCycleCount(Timeline.INDEFINITE);
        motorRunning.play();

    }

1 个答案:

答案 0 :(得分:1)

   Rotate rot = new Rotate(1);
    //rot.axisProperty().set(new Point3D(0, 0, 0));
    rot.setPivotX(0);
    rot.setPivotY(1.4);
    rot.setPivotZ(0);

这设法显示了我想要的效果。