My goal is to create Boxes with individual images on each side, which I have been completing by using a TriangleMesh to create the boxes, and using a single texture to map the points over the Mesh.
The issue is that I have been experiencing heavy overhead (high ram, long load times and slowness when moving objects in the world) from creating these TriangleMesh, and I'm not sure why fully, but here are a few of my guesses.
I initially tried to use a total of 8 points and reuse the points when creating the individual faces, and wrap the textures, but for some reason the texcoords did not like using only 8 points. As I look at Box's class I see they use 24 points as well as I do, so it seems we cannot reuse points.
2.a I am loading the 3 images into an hbox and then taking a snapshot to then map the coordinates. I am wondering if somehow snapshot is causing issues, or if there is some issue with the amount of pixels.
2.b This further comes into question when I tried turning multiple boxes that were stacked together into one large box and it still having a ton of slowness, if not more. I would take a snapshot of x number of images and then map them onto this one big Box. i.e., if I had 5x5x5 it would be one box with 5 images mapped on each side. Even with 1 single mesh it still causes slowness. It speeds up if I edit the "fitWidth/fitHeight" of the imageView which causes a quality change. To me, it seems like the pixel amounts are the cause. The thing is, if I'm taking the same images and just multiplying them, why is it causing slowness? Especially since when doing a normal box, the single image I was using had more pixels than the other images, so I would think it would be faster by doing the trianglemesh myself.
I don't really have a working example since this was added to an already working program that has data, but I will try to create something if need be.
I'm just trying to figure out why making a TriangleMesh on my own, which has similar code to the Box's code except.
without the face smoothing group, but not sure that matters.
My face array is different, and a bit confused why they have 24 points but the face array only goes from 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`
- My texCoords are 6 sets of pairs instead of the 1 set here.
static 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;
}
I also had heard that there were improvements to 3D with Version 9. I have been trying to update the past few days to 11 with issues (I had tried 10 before but a lot of my code needed fixings), and 9 isn't downloading so I wanted to ask before trying to put in more effort to get 11 working if it will in fact improve the situation, but I am still wondering why trianglmesh is so slowed comparatively. I'm maybe making 1000 boxes max.
Thank you
EDIT:
Example of how I create the images.
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);