如何设置Canvas3D背景颜色?

时间:2012-03-09 17:43:21

标签: canvas background java-3d

我有一个Canvas3D类的应用程序用于绘制三维对象。默认情况下,画布背景为黑色。我想改变它,但我不知道怎么做。我从互联网上找到了一段代码,但它不起作用。这是代码:

        setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    canvas = new Canvas3D(config);


    JPanel centerPanel = new JPanel(new GridLayout(1, 1));
    centerPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    centerPanel.add(canvas);

    universe = new SimpleUniverse(canvas);

    Background newBk = new Background(new Color3f(Color.WHITE)); 
    newBk.setApplicationBounds(new BoundingSphere(new Point3d(0f,0f,0f), 100)); 
    canvas.getGraphicsContext3D().setBackground(newBk);

你会对这个问题感到满意吗?

提前致谢。

1 个答案:

答案 0 :(得分:3)

Background background = new Background(new Color3f(1f,0,0));
BoundingSphere sphere = new BoundingSphere(new Point3d(0,0,0), 100000);
background.setApplicationBounds(sphere);
viewingPlatform.addChild(background);