简体   繁体   English

如何在Java3D中更改ColorCube对象的颜色?

[英]How to change the color of a ColorCube object in Java3D?

Is there any way through which I can change the color/appearance of the cube. 有什么方法可以改变立方体的颜色/外观。 I tried to use the setAppearance() function but it makes no change. 我试图使用setAppearance()函数,但它没有任何变化。

A quick view of what I am doing: 快速查看我在做什么:

Appearance polygon1Appearance = new Appearance();    
Color3f color1 = new Color3f (1.0f, 1.0f, 0.0f); 
ColoringAttributes color1ca = new ColoringAttributes (color1, 1);
Color3f color2 = new Color3f (1.0f, 0.0f, 0.0f); 
ColoringAttributes color2ca = new ColoringAttributes (color2, 1);

Then before adding the cubes to the transform group I use cube.setAppearance(polygon1Appearance); 然后在将立方体添加到变换组之前,我使用cube.setAppearance(polygon1Appearance);

Later in a mouse event(using pick canvas) cube.setAppearance(polygon1Appearance); 稍后在鼠标事件中(使用pick canvas)cube.setAppearance(polygon1Appearance); does not make any change. 没有任何改变。

I wanted to ask if is it even possible to change appearance(color in my case) of a ColorCube? 我想询问是否甚至可以改变ColorCube的外观(我的颜色)? Please let me know if I can provide some other information related to the question. 如果我能提供与该问题相关的其他信息,请告诉我。

The colors are "hardcoded" in this class: https://github.com/hharrison/java3d-utils/blob/master/src/classes/share/com/sun/j3d/utils/geometry/ColorCube.java 这个类中的颜色是“硬编码的”: https//github.com/hharrison/java3d-utils/blob/master/src/classes/share/com/sun/j3d/utils/geometry/ColorCube.java

You can call ColorCube.getGeometry(), cast it as it is a QuadArray and call setColor or setColors(). 您可以调用ColorCube.getGeometry(),将其转换为QuadArray并调用setColor或setColors()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM