改变形状Java3D的颜色

时间:2015-04-22 18:31:05

标签: java colors java-3d

我只是想用Java3D将我创建的圆柱的颜色改为黄色而不是标准的灰色/黑色。我的代码似乎是正确的,但是整个时间形状仍然是黑色的,这里是:

protected BranchGroup createSphere(/*Color color*/) {
        BranchGroup bg = new BranchGroup();
        bg.setCapability(BranchGroup.ALLOW_DETACH);

        Appearance app = new Appearance();
        Color3f color = new Color3f(Color.yellow);
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

        app.setMaterial(new Material(color, black, color, white, 70f));

        bg.addChild(new com.sun.j3d.utils.geometry.Cylinder());
        bg.setUserData("Sphere");
        return bg;
    }

1 个答案:

答案 0 :(得分:2)

您永远不会将外观应用于圆柱

Cylinder myCylinder = new com.sun.j3d.utils.geometry.Cylinder();
myCylinder.setAppearance(app);
bg.addChild(myCylinder);