在javafx 8中剥皮自定义3D立方体

我试图通过使用以下代码将一个皮肤添加到一个立方体,但皮肤根本不起作用。 我测试了它是否会添加到一个默认的立方体,它会(但重复每一面的完整图像,而不是环绕它,这就是为什么我要制作一个自定义的立方体,以防止这种情况)。 任何帮助将不胜感激。

private void buildGraphics() { Image dieImage = new Image(getClass().getResourceAsStream("images/die.gif")); PhongMaterial material = new PhongMaterial(); material.setDiffuseMap(dieImage); material.setSpecularColor(Color.RED); 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 }; TriangleMesh mesh = new TriangleMesh(); mesh.getPoints().addAll(points); mesh.getTexCoords().addAll(tex); mesh.getFaces().addAll(faces); MeshView box = new MeshView(mesh); box.setMaterial(material); graphicGroup.getChildren().add(box); Box box2 = new Box(100, 100, 100); box2.setTranslateX(150); box2.setMaterial(material); graphicGroup.getChildren().add(box2); world.getChildren().add(graphicGroup); } 

你是对的……我也一直在玩基本的形状……比如Capsule,Height Maps,Torus等……

texCoords是一种痛苦,但在做更复杂的形状时,面孔更是一种痛苦。

正如您所评论的那样,texCoords应该是矩形图像的0.0(0%)和1.0(100%)之间的值

我仍然无法弄清楚我的texcoords for the Torus …

我仍然认为幕后的人需要摆脱他们建立TriangleMesh的系统。

Point3D对于Points []非常有意义,但是他们使用float [] ……与texCoords相同…… Point2D会更好地适应imho .. Faces []还可以…因为它很简单整数[]…

我甚至可能只是创建一个以这种方式处理事物的SimpleMesh类……无论如何,很高兴你想出来了。