This discussion is archived
0 Replies Latest reply: Aug 4, 2010 7:05 AM by 843799 RSS

Can't set Shade GOURAUD on imported Obj models

843799 Newbie
Currently Being Moderated
Hi,

I'm importing an obj model, but I can't get the shading model to be Gouraud. It's always flat.

Here is a short code snippet where I try to make the model use Gouraud shading:

ObjectFile objectFile = new ObjectFile();
Scene scene = null;
try {
scene = objectFile.load(filepath);
}
(...) // catch block

Hashtable allReferences = scene.getNamedObjects();
Enumeration enumeration = allReferences.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
Appearance appearance = new Appearance();
ColoringAttributes coloringAttributes = new ColoringAttributes();
coloringAttributes.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
appearance.setColoringAttributes(coloringAttributes);
Material material = new Material();
material.setDiffuseColor(1f, 1f, 1f);
appearance.setMaterial(material);
if (allReferences.get(key) instanceof Shape3D) {
Shape3D ref = (Shape3D) allReferences.get(key);
ref.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);
ref.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
ref.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
ref.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_READ);
ref.setAppearance(appearance);
}
}

Thanks in advance