gpt4 book ai didi

java - Java3D 改变形状的颜色

转载 作者:行者123 更新时间:2023-12-02 04:44:16 25 4
gpt4 key购买 nike

我只是想将用 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;
}

最佳答案

你永远不会将你的外观应用到圆柱体上

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

关于java - Java3D 改变形状的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com