gpt4 book ai didi

java - 有没有办法在javafx中显示从meshview到平面绘图的uv?

转载 作者:行者123 更新时间:2023-12-02 18:12:33 24 4
gpt4 key购买 nike

有没有办法在 gui 上显示 uv 坐标,如 blender blender uv

最佳答案

显示路径的 uv 坐标

uv coords javafx没有内置的 gui 对象,但我们可以创建一个带有路径的自定义对象。我们可以从 faces[] 检索紫外线指数网格对象并获取 texcoords[] 中的值

这是一个您可以尝试的单一 javafx 应用程序。据我所知,无法从 Shape3D 对象获取网格实例,因此这仅适用于 meshview 对象中的 trianglefaces 自定义网格。我无法设置 mesh.fxml 因为它会溢出字符限制。

应用程序.java

public class App extends Application {

@Override
public void start(Stage stage) throws IOException {
Image uvImage = new Image("/uv.jpg");

PerspectiveCamera pc = new PerspectiveCamera(true);
pc.setTranslateZ(-6);
MeshView mv = loadMeshView();
PhongMaterial pm = new PhongMaterial();
pm.setDiffuseMap(uvImage);
mv.setMaterial(pm);
Group group3d = new Group(pc, mv);

RotateTransition animation = new RotateTransition(Duration.seconds(4), mv);
animation.setInterpolator(Interpolator.LINEAR);
animation.setAxis(Rotate.Y_AXIS);
animation.setByAngle(360);
animation.setCycleCount(100);


animation.play();
SubScene subScene = new SubScene(group3d, 400, 400, true, SceneAntialiasing.BALANCED);
subScene.setFill(Color.AQUAMARINE);
subScene.setCamera(pc);

ImageView imageView = new ImageView(uvImage);
imageView.setFitHeight(400);
imageView.setFitWidth(400);
Group groupUv = new Group(imageView);

makeUvLines(groupUv, mv);
Text u = new Text("U");
Text v = new Text("V");
v.setTranslateY(200);
v.setTranslateX(-20);
u.setTranslateX(200);
u.setTranslateY(420);

Line uLine = new Line(0, 0, 0, 400);
Polygon uArrow = new Polygon(0, 0, 8, 8, -8, 8);
Polygon vArrow = new Polygon(400, 400, 392, 408, 392, 392);

Line vLine = new Line(0, 400, 400, 400);

Pane ap = new Pane(groupUv, uLine, vLine, uArrow, vArrow, u, v);
ap.setPrefSize(400, 400);
ap.setMaxSize(400, 400);
ap.setStyle("-fx-background-color:yellow");
HBox.setHgrow(ap, Priority.NEVER);

HBox hb = new HBox(subScene, ap);
hb.setSpacing(30);
hb.setAlignment(Pos.CENTER);

var scene = new Scene(hb, 800, 600);
stage.setTitle("JavaFX UV Visualizer");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch();
}

private void makeUvLines(Group groupUv, MeshView meshView) {
TriangleMesh mesh = (TriangleMesh) meshView.getMesh();

int[] faces = mesh.getFaces().toArray(new int[mesh.getFaces().size()]);
float[] texCoords = mesh.getTexCoords().toArray(new float[mesh.getTexCoords().size()]);

for (int i = 0; i < faces.length; i++) {
float scale = 400;
float startU = texCoords[2 * faces[i + 1]];
float startV = texCoords[((2 * faces[i + 1]) + 1)];

float u1 = texCoords[2 * faces[i + 3]];
float v1 = texCoords[((2 * faces[i + 3]) + 1)];

float endU = texCoords[2 * faces[i + 5]];
float endV = texCoords[((2 * faces[i + 5]) + 1)];

Path p = new Path(
new MoveTo(startU * scale, startV * scale),
new LineTo(u1 * scale, v1 * scale),
new LineTo(endU * scale, endV * scale),
new ClosePath()
);
p.setStroke(Color.ORANGE);
p.setFill(Color.color(0.1, 0.3, 0.1, 0.7));
groupUv.getChildren().add(p);

i += 5;
}

}

private MeshView loadMeshView() throws IOException {
FXMLLoader loader = new FXMLLoader(App.class.getResource("/mesh.fxml"));
loader.load();
MeshView meshView = loader.getRoot();

return meshView;
}

}

uv.jpg uv test image

关于java - 有没有办法在javafx中显示从meshview到平面绘图的uv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72080631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com