Re: Is it possible to give Texture to Furniture?
Code: Select all
private void deepUpdateMaterial(Node node) {
if (node instanceof Group) {
Group bg = (Group) node;
for (int i = 0; i < bg.numChildren(); i++) {
Node shape = bg.getChild(i);
deepUpdateMaterial(shape);
}
} else if (node instanceof Shape3D) {
Shape3D shape = (Shape3D) node;
Appearance material = shape.getAppearance();
if (material != null) {
shape.setAppearanceOverrideEnable(true);
String texture = null;
/*
Here, set the texture to whatever is to set
*/
if (texture != null) {
BufferedImage textureImage = null;
try {
textureImage = ImageIO.read(new URL(texture));
} catch (IOException ex) {
// Ignore images at other format
}
if (textureImage != null) {
TextureLoader textureLoader = new TextureLoader(textureImage, TextureLoader.GENERATE_MIPMAP | TextureLoader.BY_REFERENCE);
material.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
material.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
material.setTexture(textureLoader.getTexture());
}
}
}
}
}