Hi,
I’m running into some problems changing the color of a Shape3D. My Shape3D is a simple rectangle, implemented like:
public class Box extends Shape3D {
public Box() {
super();
// Set capabilities.
this.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
this.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
// Draw a rectangle.
QuadArray array = new QuadArray(4,QuadArray.COORDINATES | QuadArray.COLOR_3);
array.setCoordinate(0,new Point3d(-1,-1,0));
array.setCoordinate(1,new Point3d(1,-1,0));
array.setCoordinate(2,new Point3d(1,1,0));
array.setCoordinate(3,new Point3d(-1,1,0));
for (int i = 0; i < 3; i++) {
array.setColor(i, navyblue);
}
this.setGeometry(array);
}
}
With the above code, I’ve created a navy-blue box. I’ve tried changing the color of the box to red by using this method:
private void applyColor(Shape3D s3d, Color3f color) {
Appearance ap;
ap = new Appearance();
ap.setCapability(Appearance.ALLOW_MATERIAL_READ);
ap.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
ap.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
ap.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
ap.setCapability(Appearance.ALLOW_TEXGEN_WRITE);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Material m = new Material(color, black, color, black, 1.0f);
m.setCapability(Material.ALLOW_COMPONENT_READ);
ap.setMaterial(m);
s3d.setAppearance(ap);
}
When I try to use this method by calling “applyColor(anInstanceOfTheBox, red);” however, the box doesn’t change color and stays navy-blue.
Does anyone know what I’m leaving out or doing wrong?
Thanks,
DAT