So I am having trouble putting smaller boxes into a bigger one(container). I tried to get the coordinates of a vertex from a box and put the other in that position. Here is the code I tried:
Shape3D backShape = ((Box) buildShape(x, y, z)).getShape(Box.RIGHT);
GeometryArray geo=(GeometryArray)backShape.getGeometry();
float[] position=new float[3];
geo.getCoordinate(0, position);
System.out.println(position[0]+" "+position[1]+" "+position[2]);
Vector3f pp = new Vector3f (position[0],position[1], position[2]);
Color3f c1=new Color3f(0.7f, .15f, .15f);
Color3f c2=new Color3f(0.7f, .15f, .15f);
Color3f[] c=(Color3f[]) new Color3f[20] ;
c[0] =new Color3f(Color.getHSBColor(20.f, 30f, 2.f));
c[1] =new Color3f(Color.BLUE);
c[2] =new Color3f(Color.YELLOW);
c[3] =new Color3f(Color.GREEN);
c[4] =new Color3f(Color.WHITE);
c[5] =new Color3f(Color.CYAN);
c[6] =new Color3f(Color.LIGHT_GRAY);
c[7] =new Color3f(Color.PINK);
c[8] =new Color3f(Color.RED);
c[9] =new Color3f(Color.DARK_GRAY);
c[10] =new Color3f(Color.MAGENTA);
c[11] =new Color3f(Color.getHSBColor(0.2f, 0.15f, 2.f));
c[11] =new Color3f(Color.getHSBColor(0.8f, 0.1f, 15.f));
c[13] =new Color3f(Color.ORANGE);
c[11] =new Color3f(Color.getHSBColor(1.f, 0.8f, 2.f));
for (int i=0; i<boxes.size(); i++) {
Transform3D transform = new Transform3D();
transform.setTranslation(pp);
Box ProductBox = addProductBox(boxes.get(i).dimension.get("length"),boxes.get(i).dimension.get("breadth")
,boxes.get(i).dimension.get("height"),c1, c2,c[i],c[i]);
Transform3D rotateCube = new Transform3D();
rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
TransformGroup rotationGroup = new TransformGroup(rotateCube);
TransformGroup TranslateGroup = new TransformGroup(transform);
TranslateGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
rotationGroup.addChild(ProductBox);
TranslateGroup.addChild(rotationGroup);
nodeRoot.addChild(TranslateGroup);
Shape3D shape = ProductBox.getShape(Box.FRONT);
GeometryArray g=(GeometryArray)shape.getGeometry();
position[0]-= boxes.get(i).dimension.get("length")+0.15f;
System.out.println(position[0]+" "+position[1]+" "+position[2]);
Vector3f pp2 = new Vector3f (position[0],position[1],position[2]);
pp=pp2;
c[i]=c[i+1];
}
I succeeded in positioning all the boxes in the container by substracting the length from position[0] in each iteration. But the boxes are not lined up. I attached an image showing what I have done so far: here
I have this simple program. Say you have a Shape3D shape:
GeometryArray ge=(GeometryArray)shape.getGeometry();
double[] cc1=new double[3];
ge.getCoordinate(0, cc1);
System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]);
ge.getCoordinate(1, cc1);
System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]);
This way I can get the coordinates of shape. You have to be well positioned into 3D space to understand. You have to experiment by positioning your object (one only at first).