diff --git a/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java b/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
index dbce50b..b98101b 100644
--- a/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
+++ b/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
@@ -229,18 +229,21 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
private void updatePieceOfFurnitureColorAndTexture(boolean waitTextureLoadingEnd) {
HomePieceOfFurniture piece = (HomePieceOfFurniture)getUserData();
Node filledModelNode = getFilledModelNode();
+ Clazz3823529 param = new Clazz3823529()
+ .withNode(filledModelNode)
+ .withShininess(piece.getShininess())
+ .withModifiedAppearances(new HashSet<Appearance>());
if (piece.getColor() != null) {
- setColorAndTexture(filledModelNode, piece.getColor(), null, piece.getShininess(), false,
- null, null, new HashSet<Appearance>());
+ param = param.withColor(piece.getColor());
} else if (piece.getTexture() != null) {
- setColorAndTexture(filledModelNode, null, piece.getTexture(), piece.getShininess(), waitTextureLoadingEnd,
- new Vector3f(piece.getWidth(), piece.getHeight(), piece.getDepth()), ModelManager.getInstance().getBounds(((Group)filledModelNode).getChild(0)),
- new HashSet<Appearance>());
- } else {
- // Set default material and texture of model
- setColorAndTexture(filledModelNode, null, null, piece.getShininess(), false,
- null, null, new HashSet<Appearance>());
+ param = param.withTexture(piece.getTexture())
+ .withWaitTextureLoadingEnd(waitTextureLoadingEnd)
+ .withPieceSize(new Vector3f(piece.getWidth(), piece.getHeight(), piece.getShininess()))
+ .withModelBounds(ModelManager.getInstance().getBounds(((Group)filledModelNode).getChild(0)));
}
+ // Set default material and texture of model
+ setColorAndTexture(param);
+
}
/**
@@ -541,24 +544,20 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
* Sets the material and texture attribute of all <code>Shape3D</code> children nodes of <code>node</code>
* from the given <code>color</code> and <code>texture</code>.
*/
- private void setColorAndTexture(Node node, Integer color,
- HomeTexture texture, Float shininess,
- boolean waitTextureLoadingEnd, Vector3f pieceSize,
- BoundingBox modelBounds, Set<Appearance> modifiedAppearances) {
- if (node instanceof Group) {
+ private void setColorAndTexture(Clazz3823529 param) {
+ Clazz3823529 tempParam = new Clazz3823529(param);
+ if (param.node instanceof Group) {
// Set material and texture of all children
- Enumeration<?> enumeration = ((Group)node).getAllChildren();
+ Enumeration<?> enumeration = ((Group)param.node).getAllChildren();
while (enumeration.hasMoreElements()) {
- setColorAndTexture((Node)enumeration.nextElement(), color,
- texture, shininess, waitTextureLoadingEnd, pieceSize,
- modelBounds, modifiedAppearances);
+ tempParam = tempParam.withNode((Node)enumeration.nextElement());
+ setColorAndTexture(tempParam);
}
- } else if (node instanceof Link) {
- setColorAndTexture(((Link)node).getSharedGroup(), color,
- texture, shininess, waitTextureLoadingEnd, pieceSize,
- modelBounds, modifiedAppearances);
- } else if (node instanceof Shape3D) {
- final Shape3D shape = (Shape3D)node;
+ } else if (param.node instanceof Link) {
+ tempParam = tempParam.withNode(((Link)param.node).getSharedGroup());
+ setColorAndTexture(tempParam);
+ } else if (param.node instanceof Shape3D) {
+ final Shape3D shape = (Shape3D)param.node;
String shapeName = (String)shape.getUserData();
// Change material and texture of all shapes that are not window panes
if (shapeName == null
@@ -566,53 +565,53 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
Appearance appearance = shape.getAppearance();
if (appearance == null) {
appearance = createAppearanceWithChangeCapabilities();
- ((Shape3D)node).setAppearance(appearance);
+ ((Shape3D)param.node).setAppearance(appearance);
}
// Check appearance wasn't already changed
- if (!modifiedAppearances.contains(appearance)) {
+ if (!param.modifiedAppearances.contains(appearance)) {
// Use appearance user data to store shape default material
DefaultMaterialAndTexture defaultMaterialAndTexture = (DefaultMaterialAndTexture)appearance.getUserData();
if (defaultMaterialAndTexture == null) {
defaultMaterialAndTexture = new DefaultMaterialAndTexture(appearance);
appearance.setUserData(defaultMaterialAndTexture);
}
- float materialShininess = shininess != null
- ? shininess.floatValue()
+ float materialShininess = param.shininess != null
+ ? param.shininess.floatValue()
: (appearance.getMaterial() != null
? appearance.getMaterial().getShininess() / 128f
: 0);
- if (color != null && defaultMaterialAndTexture.getTexture() == null) {
+ if (param.color != null && defaultMaterialAndTexture.getTexture() == null) {
// Change material if no default texture is displayed on the shape
// (textures always keep the colors of their image file)
- appearance.setMaterial(getMaterial(color, color, materialShininess));
+ appearance.setMaterial(getMaterial(param.color, param.color, materialShininess));
appearance.setTransparencyAttributes(defaultMaterialAndTexture.getTransparencyAttributes());
appearance.setPolygonAttributes(defaultMaterialAndTexture.getPolygonAttributes());
appearance.setTexCoordGeneration(defaultMaterialAndTexture.getTexCoordGeneration());
appearance.setTextureAttributes(defaultMaterialAndTexture.getTextureAttributes());
appearance.setTexture(null);
- } else if (color == null && texture != null) {
+ } else if (param.color == null && param.texture != null) {
// Change material to white then texture
appearance.setMaterial(getMaterial(DEFAULT_COLOR, DEFAULT_AMBIENT_COLOR, materialShininess));
Point3d lower = new Point3d();
- modelBounds.getLower(lower);
+ param.modelBounds.getLower(lower);
Point3d upper = new Point3d();
- modelBounds.getUpper(upper);
+ param.modelBounds.getUpper(upper);
float minimumSize = ModelManager.getInstance().getMinimumSize();
- float sx = pieceSize.x / (float)Math.max(upper.x - lower.x, minimumSize) / texture.getWidth();
- float sw = texture.isLeftToRightOriented()
+ float sx = param.pieceSize.x / (float)Math.max(upper.x - lower.x, minimumSize) / param.texture.getWidth();
+ float sw = param.texture.isLeftToRightOriented()
? (float)-lower.x * sx
: 0;
- float ty = pieceSize.y / (float)Math.max(upper.y - lower.y, minimumSize) / texture.getHeight();
- float tz = pieceSize.z / (float)Math.max(upper.z - lower.z, minimumSize) / texture.getHeight();
- float tw = texture.isLeftToRightOriented()
+ float ty = param.pieceSize.y / (float)Math.max(upper.y - lower.y, minimumSize) / param.texture.getHeight();
+ float tz = param.pieceSize.z / (float)Math.max(upper.z - lower.z, minimumSize) / param.texture.getHeight();
+ float tw = param.texture.isLeftToRightOriented()
? (float)(-lower.y * ty + upper.z * tz)
: 0;
TexCoordGeneration texCoordGeneration = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(sx, 0, 0, sw), new Vector4f(0, ty, -tz, tw));
appearance.setTexCoordGeneration(texCoordGeneration);
appearance.setTextureAttributes(MODULATE_TEXTURE_ATTRIBUTES);
- TextureManager.getInstance().loadTexture(texture.getImage(), waitTextureLoadingEnd,
+ TextureManager.getInstance().loadTexture(param.texture.getImage(), param.waitTextureLoadingEnd,
new TextureManager.TextureObserver() {
public void textureUpdated(Texture texture) {
if (TextureManager.getInstance().isTextureTransparent(texture)) {
@@ -625,10 +624,10 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
} else {
// Restore default material and texture
Material defaultMaterial = defaultMaterialAndTexture.getMaterial();
- if (defaultMaterial != null && shininess != null) {
+ if (defaultMaterial != null && param.shininess != null) {
defaultMaterial = (Material)defaultMaterial.cloneNodeComponent(true);
- defaultMaterial.setSpecularColor(new Color3f(shininess, shininess, shininess));
- defaultMaterial.setShininess(shininess * 128);
+ defaultMaterial.setSpecularColor(new Color3f(param.shininess, param.shininess, param.shininess));
+ defaultMaterial.setShininess(param.shininess * 128);
}
appearance.setMaterial(defaultMaterial);
appearance.setTransparencyAttributes(defaultMaterialAndTexture.getTransparencyAttributes());
@@ -638,7 +637,7 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
appearance.setTextureAttributes(defaultMaterialAndTexture.getTextureAttributes());
}
// Store modified appearances to avoid changing their values more than once
- modifiedAppearances.add(appearance);
+ param.modifiedAppearances.add(appearance);
}
}
}
@@ -867,4 +866,68 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
return this.textureAttributes;
}
}
+
+ private class Clazz3823529 {
+ public Node node;
+ public Integer color;
+ public HomeTexture texture;
+ public Float shininess;
+ public boolean waitTextureLoadingEnd;
+ public Vector3f pieceSize;
+ public BoundingBox modelBounds;
+ public Set<Appearance> modifiedAppearances;
+
+ Clazz3823529() {}
+
+ Clazz3823529(Clazz3823529 copy) {
+ this.node = copy.node;
+ this.color = copy.color;
+ this.texture = copy.texture;
+ this.shininess = copy.shininess;
+ this.waitTextureLoadingEnd = copy.waitTextureLoadingEnd;
+ this.pieceSize = copy.pieceSize;
+ this.modelBounds = copy.modelBounds;
+ this.modifiedAppearances = copy.modifiedAppearances;
+ }
+
+ Clazz3823529 withNode(Node node) {
+ this.node = node;
+ return this;
+ }
+
+ Clazz3823529 withColor(Integer color) {
+ this.color = color;
+ return this;
+ }
+
+ Clazz3823529 withTexture(HomeTexture texture) {
+ this.texture = texture;
+ return this;
+ }
+
+ Clazz3823529 withShininess(Float shininess) {
+ this.shininess = shininess;
+ return this;
+ }
+
+ Clazz3823529 withWaitTextureLoadingEnd(boolean waitTextureLoadingEnd) {
+ this.waitTextureLoadingEnd = waitTextureLoadingEnd;
+ return this;
+ }
+
+ Clazz3823529 withPieceSize(Vector3f pieceSize) {
+ this.pieceSize = pieceSize;
+ return this;
+ }
+
+ Clazz3823529 withModelBounds(BoundingBox modelBounds) {
+ this.modelBounds = modelBounds;
+ return this;
+ }
+
+ Clazz3823529 withModifiedAppearances(Set<Appearance> modifiedAppearances) {
+ this.modifiedAppearances = modifiedAppearances;
+ return this;
+ }
+ }
}
\ No newline at end of file