this.sunflow.parameter("color", null, new float [] {color.x, color.y, color.z});
}
this.sunflow.shader(appearanceName, "mirror");
} else if (texture != null) {
// Check shape transparency
TransparencyAttributes transparencyAttributes = appearance.getTransparencyAttributes();
float transparency;
if (transparencyAttributes != null
&& transparencyAttributes.getTransparency() > 0
&& !ignoreTransparency) {
transparency = 1 - transparencyAttributes.getTransparency();
} else {
transparency = 1;
}
TransparentTextureKey key = new TransparentTextureKey(texture, transparency);
String imagePath = this.textureImagesCache.get(key);
if (imagePath == null) {
if (texture.getUserData() instanceof URL && transparency == 1) {
imagePath = texture.getUserData().toString();
} else {
ImageComponent2D imageComponent = (ImageComponent2D)texture.getImage(0);
RenderedImage image = imageComponent.getRenderedImage();
if (transparency < 1) {
// Compute a partially transparent image
BufferedImage transparentImage = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D = (Graphics2D)transparentImage.getGraphics();
g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency));
g2D.drawRenderedImage(image, null);
g2D.dispose();
image = transparentImage;
}
File imageFile = OperatingSystem.createTemporaryFile("texture", ".png");
ImageIO.write(image, "png", imageFile);
imagePath = imageFile.getAbsolutePath();
}
this.textureImagesCache.put(key, imagePath);
}
Material material = appearance.getMaterial();
float shininess;
if (material != null
&& (shininess = material.getShininess()) > 1) {
if (silk) {
this.sunflow.parameter("diffuse.texture", imagePath);
Color3f color = new Color3f();
material.getSpecularColor(color);
float [] specularColor = new float [] {
(float)Math.sqrt(color.x) / 2, (float)Math.sqrt(color.y) / 2, (float)Math.sqrt(color.z) / 2};
this.sunflow.parameter("specular", null, specularColor);
this.sunflow.parameter("glossyness", (float)Math.pow(10, -Math.log(shininess) / Math.log(5)));
this.sunflow.parameter("samples", 1);
this.sunflow.shader(appearanceName, "uber");
} else {
this.sunflow.parameter("texture", imagePath);
this.sunflow.parameter("shiny", shininess / 512f);
this.sunflow.shader(appearanceName, "textured_shiny_diffuse");
}
} else {
this.sunflow.parameter("texture", imagePath);
this.sunflow.shader(appearanceName, "textured_diffuse");
}
} else {
Material material = appearance.getMaterial();
if (material != null) {
Color3f color = new Color3f();
material.getDiffuseColor(color);
float [] diffuseColor = new float [] {color.x, color.y, color.z};
TransparencyAttributes transparencyAttributes = appearance.getTransparencyAttributes();
if (transparencyAttributes != null
&& transparencyAttributes.getTransparency() > 0
&& !ignoreTransparency) {
if (material instanceof OBJMaterial
&& ((OBJMaterial)material).isOpticalDensitySet()) {
this.sunflow.parameter("eta", ((OBJMaterial)material).getOpticalDensity());
} else {
// Use glass ETA as default
this.sunflow.parameter("eta", 1.55f);
}
float transparency = 1 - transparencyAttributes.getTransparency();
this.sunflow.parameter("color", null,
new float [] {(1 - transparency) + transparency * diffuseColor [0],
(1 - transparency) + transparency * diffuseColor [1],
(1 - transparency) + transparency * diffuseColor [2]});
this.sunflow.parameter("absorption.color", null,