javafx - 与普通 Boxes 相比,JavaFX TriangleMesh 会导致大量开销/缓慢
问题描述
我的目标是在每一侧创建带有单独图像的盒子,我已经通过使用 TriangleMesh 创建盒子,并使用单个纹理将点映射到网格上来完成。
问题是我在创建这些 TriangleMesh 时遇到了沉重的开销(高内存、长加载时间和在世界上移动物体时速度慢),我不知道为什么完全如此,但这里有一些我的猜测。
我最初尝试使用总共 8 个点并在创建单个面时重用这些点,并包裹纹理,但由于某种原因,texcoords 不喜欢只使用 8 个点。当我查看 Box 的课程时,我发现他们和我一样使用 24 分,所以看来我们不能重复使用积分。
2.a 我将 3 张图像加载到 hbox 中,然后拍摄快照以映射坐标。我想知道快照是否会导致问题,或者像素数量是否存在问题。
2.b 当我尝试将多个堆叠在一起的盒子变成一个大盒子时,这进一步受到质疑,但它仍然有大量的缓慢,如果不是更多的话。我会拍摄 x 张图像的快照,然后将它们映射到这个大盒子上。即,如果我有 5x5x5,它将是一个盒子,每边映射 5 个图像。即使使用 1 个单一网格,它仍然会导致缓慢。如果我编辑导致质量变化的 imageView 的“fitWidth/fitHeight”,它会加快速度。对我来说,像素数量似乎是原因。问题是,如果我拍摄相同的图像并将它们相乘,为什么会导致速度变慢?特别是当做一个普通的盒子时,我使用的单张图像比其他图像有更多的像素,
我真的没有一个有效的例子,因为它被添加到一个已经工作的有数据的程序中,但如果需要,我会尝试创建一些东西。
我只是想弄清楚为什么要自己制作一个 TriangleMesh,它的代码与 Box 的代码相似,除了。
没有面部平滑组,但不确定是否重要。
我的人脸数组不同,有点困惑为什么他们有 24 个点但人脸数组只有 1-8
int[] faces = { 2, 2, 1, 1, 0, 0, //front 2, 2, 3, 3, 1, 1, 6, 6, 5, 5, 4, 4, //right 6, 6, 7, 7, 5, 5, 10, 10, 9, 9, 8, 8, //back 10, 10, 11, 11, 9, 9, 14, 14, 13, 13, 12, 12,//left 14 ,14, 15, 15, 13, 13, 18, 18, 17, 17, 16, 16,//top 18, 18, 19, 19, 17, 17, 22, 22, 21, 21, 20, 20, //bottom 22, 22, 23, 23, 21, 21`
- 我的 texCoords 是 6 组对,而不是这里的 1 组。
静态 TriangleMesh createMesh(float w, float h, float d) {
// NOTE: still create mesh for degenerated box
float hw = w / 2f;
float hh = h / 2f;
float hd = d / 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 texCoords[] = {0, 0, 1, 0, 1, 1, 0, 1};
// Specifies hard edges.
int faceSmoothingGroups[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
int faces[] = {
0, 0, 2, 2, 1, 1,
2, 2, 0, 0, 3, 3,
1, 0, 6, 2, 5, 1,
6, 2, 1, 0, 2, 3,
5, 0, 7, 2, 4, 1,
7, 2, 5, 0, 6, 3,
4, 0, 3, 2, 0, 1,
3, 2, 4, 0, 7, 3,
3, 0, 6, 2, 2, 1,
6, 2, 3, 0, 7, 3,
4, 0, 1, 2, 5, 1,
1, 2, 4, 0, 0, 3,
};
TriangleMesh mesh = new TriangleMesh(true);
mesh.getPoints().setAll(points);
mesh.getTexCoords().setAll(texCoords);
mesh.getFaces().setAll(faces);
mesh.getFaceSmoothingGroups().setAll(faceSmoothingGroups);
return mesh;
}
我还听说版本 9 对 3D 进行了改进。过去几天我一直在尝试将问题更新到 11(我之前尝试过 10,但我的很多代码需要修复),而 9 没有下载所以我想在尝试付出更多努力让 11 工作之前先问问它是否真的会改善这种情况,但我仍然想知道为什么 trianglmesh 相对而言如此缓慢。我可能最多可以制作 1000 个盒子。
谢谢
编辑:
我如何创建图像的示例。
public BoxMesh(width, height,depth, int stack)
{
float width = width;
float height = height;
float depth = depth
List<ImageView> imageList = new ArrayList();
imageList.add(new ImageView(new Image("file:"C:\\file1.jpg"));
HBox h = new HBox();
Image image = null;
for(int i = 0; i < stack; i++)
{
image = new Image("file:"C:\\file2.jpg");
ImageView iv = new ImageView(image);
iv.setFitWidth(image.getWidth()/2); //decreases quality to
iv.setFitHeight(image.getHeight()/2); //speed up program
h.getChildren().add(iv);
}
imageList.add(new ImageView(h.snapshot(null,null)));
VBox v = new VBox();
Image image = null;
for(int i = 0; i < stack; i++)
{
image = new Image("file:"C:\\file3.jpg");
ImageView iv = new ImageView(image);
iv.setFitWidth(image.getWidth()/2);
iv.setFitHeight(image.getHeight()/2);
v.getChildren().add(iv);
}
imageList.add(new ImageView(v.snapshot(null, null)));
PhongMaterial p = new PhongMaterial();
HBox hb = new HBox();
hb.getChildren().addAll(imageList);
WritableImage snapshot = hb.snapshot(null, null);
if(snapshot.isError())
{
System.out.println(snapshot.exceptionProperty().getValue());
}
p.setDiffuseMap(snapshot);
解决方案
推荐阅读
- redis - Redis Pub/Sub - 发布者也是订阅者?
- javascript - TypeError:WooCommerceRestApi 不是构造函数
- javascript - 在 puppeteer 中将函数传递给 evaluate()
- vue.js - 在 Nuxt 应用程序中为动态路由生成 xml 站点地图
- excel - 根据一个列中的唯一值和另一列中的最大重复值更新列
- python-3.x - 将列表添加到 DF 列
- python - 如何将大图像(800 MB)子集化为较小的图像以创建训练集?
- python-3.x - Sympy——简化并收集不同的变量以进行变量转换
- apache-spark - 以编程方式在 pyspark 中提交 jar
- ios - 导航控制器和标签栏控制器