圆柱体JavaFX上的图像缩放
我想做的是在Java3D中缩放圆柱体上的图像。到目前为止,我的代码如下所示。我不知道如何使图像不覆盖整个圆柱体圆柱体JavaFX上的图像缩放,java,javafx-8,Java,Javafx 8,我想做的是在Java3D中缩放圆柱体上的图像。到目前为止,我的代码如下所示。我不知道如何使图像不覆盖整个圆柱体 package javafxapplication2; import javafx.application.Application; import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.scene.Group; imp
package javafxapplication2;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class EarthCylinder extends Application {
double anchorX, anchorY;
private double anchorAngleX = 0;
private double anchorAngleY = 0;
private final DoubleProperty angleX = new SimpleDoubleProperty(0);
private final DoubleProperty angleY = new SimpleDoubleProperty(0);
PerspectiveCamera scenePerspectiveCamera = new PerspectiveCamera(false);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Remove this line once dirtyopts bug is fixed for 3D primitive
System.setProperty("prism.dirtyopts", "false");
launch(args);
}
@Override
public void start(Stage primaryStage) {
Image diffuseMap
= new Image(EarthCylinder.class
.getResource("download.jpg")
.toExternalForm());
PhongMaterial material = new PhongMaterial();
material.setDiffuseMap(diffuseMap);
final Cylinder cylinder = new Cylinder(200, 400);
cylinder.setMaterial(material);
final Group parent = new Group(cylinder);
parent.setTranslateX(450);
parent.setTranslateY(450);
parent.setTranslateZ(0);
Rotate xRotate;
Rotate yRotate;
parent.getTransforms().setAll(
xRotate = new Rotate(0, Rotate.X_AXIS),
yRotate = new Rotate(0, Rotate.Y_AXIS));
xRotate.angleProperty().bind(angleX);
yRotate.angleProperty().bind(angleY);
final Group root = new Group();
root.getChildren().add(parent);
final Scene scene = new Scene(root, 900, 900, true);
scene.setFill(Color.BLACK);
scene.setOnMousePressed(event -> {
anchorX = event.getSceneX();
anchorY = event.getSceneY();
anchorAngleX = angleX.get();
anchorAngleY = angleY.get();
});
scene.setOnMouseDragged(event -> {
angleX.set(anchorAngleX - (anchorY - event.getSceneY()));
angleY.set(anchorAngleY + anchorX - event.getSceneX());
});
PointLight pointLight = new PointLight(Color.WHITE);
pointLight.setTranslateX(400);
pointLight.setTranslateY(400);
pointLight.setTranslateZ(-3000);
scene.setCamera(scenePerspectiveCamera);
root.getChildren().addAll(pointLight, scenePerspectiveCamera);
primaryStage.setScene(scene);
primaryStage.show();
}
}
上述代码的结果如下所示:
An可能会有所帮助。但是,圆柱体会自动为其包含的
形状3d
(即,为形状3d
的几何体创建纹理坐标。我的问题是,您必须手动从圆柱体
获取形状3d
,然后从形状3d
获取几何体
,然后从几何体
获取几何体
,最后使用类似的东西(如果您发布了MCVE,我会尝试一下)谢谢您的回复,将上传完整的代码哦,对不起。那是个误会。这个问题不是关于Java3D(),而是关于JavaFX。(虽然,很明显,他们在为JavaFX创建3D-API时采用了Java3D中的许多元素;-)。好吧,快速浏览一下API和代码,似乎真的没有官方的方法来更改圆柱体的纹理坐标。那太令人恼火了。当然可以手动创建圆柱体几何体(),但这不是必需的。我很好奇是否有人找到了一个合适的答案…是的,这真的很烦人。我找到了一种方法,添加另一个具有不同高度和半径+1的圆柱体。我在图像中添加了一些空白,以确保图像的缩放正确。谢谢你的帮助!