phongmaterial을 사용하여 메쉬 뷰 큐브에 이미지를 적용하려하지만 색상이없는 검은 색 큐브 만 화면에 표시됩니다. 그것은 Box와 큐브로 작업했지만 지금은 그것도 사용하지 않습니다.Javafx : 이미지가 메쉬보기에 적용되지 않음
또한 특정 큐브의 얼굴을 얻는 방법을 알려 줄 수 있습니까? 여기
내 코드입니다 :Rotate rxBox = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate ryBox = new Rotate(50, 0, 0, 0, Rotate.Y_AXIS);
Rotate rzBox = new Rotate(30, 0, 0, 0, Rotate.Z_AXIS);
@Override
public void start(Stage primaryStage) {
float hw = 100/2f;
float hh = 100/2f;
float hd = 100/2f;
float points[] = {
hw, hh, hd,
hw, hh, -hd,
hw, -hh, hd,
hw, -hh, -hd,
-hw, hh, hd,
-hw, hh, -hd,
-hw, -hh, hd,
-hw, -hh, -hd};
float tex[] = {
100, 0,
200, 0,
0, 100,
100, 100,
200, 100,
300, 100,
400, 100,
0, 200,
100, 200,
200, 200,
300, 200,
400, 200,
100, 300,
200, 300};
int faces[] = {
0, 10, 2, 5, 1, 9,
2, 5, 3, 4, 1, 9,
4, 7, 5, 8, 6, 2,
6, 2, 5, 8, 7, 3,
0, 13, 1, 9, 4, 12,
4, 12, 1, 9, 5, 8,
2, 1, 6, 0, 3, 4,
3, 4, 6, 0, 7, 3,
0, 10, 4, 11, 2, 5,
2, 5, 4, 11, 6, 6,
1, 9, 3, 4, 5, 8,
5, 8, 3, 4, 7, 3};
int[] facesSmoothingGroups = {0,0,1,1,2,2,3,3,4,4,5,5};
// URL resource = Main.class.getResource("DFv8z.png");
Image diffuseMap = new Image(Main.class.getResource("PCmIW.png").toExternalForm());
TriangleMesh mesh = new TriangleMesh();
mesh.getPoints().addAll(points);
mesh.getTexCoords().addAll(tex);
mesh.getFaces().addAll(faces);
// mesh.getFaceSmoothingGroups().addAll(facesSmoothingGroups);
Material cubeMaterial = new PhongMaterial(Color.TRANSPARENT, diffuseMap, null, null, null);
MeshView m = new MeshView(mesh);
m.getTransforms().addAll(rxBox, ryBox, rzBox);
m.setMaterial(cubeMaterial);
final Group g = new Group(m);
g.setTranslateX(400/2);
g.setTranslateY(400/2);
//g.setTranslateZ(400/2);
g.setRotationAxis(Rotate.Y_AXIS);
g.setRotationAxis(Rotate.X_AXIS);
//g.setRotationAxis(Rotate.Z_AXIS);
Scene scene = new Scene(g, 400, 400, Color.SKYBLUE);
primaryStage.setTitle("Hello World");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@Override
public void handle(MouseEvent event) {
// TODO Auto-generated method stub
}
}
안녕 jose, 이제 이미지가 잘 작동합니다. 하지만 주사위를 무작위로 굴릴 때 나는 위에있는 색상을 인쇄하고 싶습니다. 나는 얼굴을 돌려 보려고했지만 총 얼굴 수를 반환합니다. –
텍스처 좌표를 적절하게 스케일링하면 (0-1 사이) 올바르게 게시해야합니다. L (400) 또는 H (300)가 아닌 ** 100 ** **로 텍스쳐 좌표를 나눌 경우 _each_면 위에 그물을 얻습니다. –
faceSmoothingGroups를 사용하여 상단면을 추적하는 방법은 무엇입니까? –