简体   繁体   中英

javafx 3d Meshview rotation

i want to rotate the shaft of the motor , but have not managed to get the desired behavior.

motor model

the rotation i am getting is this one.

motor model

this is the code i am using where shaft is the MeshView i want to rotate:

    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();

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

this managed to show the effect i wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM