在 Java3D 中将较小的盒子加载到较大的盒子中

Loading smaller boxes into a bigger one in Java3D

所以我无法将较小的盒子放入较大的盒子(容器)。我试图从一个盒子中获取一个顶点的坐标并将另一个放在那个位置。这是我试过的代码:

 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];
    }

我通过在每次迭代中从 position[0] 中减去长度,成功地定位了容器中的所有框。但是箱子没有排成一行。 我附上了一张图片,显示了我到目前为止所做的事情: here

我有这个简单的程序。假设您有一个 Shape3D 形状:

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]);

这样我就可以得到形状的坐标。你必须很好地进入 3D space 才能理解。您必须通过定位您的对象(一开始只有一个)来进行试验。