Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. diff --git a/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java b/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
  2. index dbce50b..b98101b 100644
  3. --- a/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
  4. +++ b/src/main/java/com/eteks/sweethome3d/j3d/HomePieceOfFurniture3D.java
  5. @@ -229,18 +229,21 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  6.    private void updatePieceOfFurnitureColorAndTexture(boolean waitTextureLoadingEnd) {
  7.      HomePieceOfFurniture piece = (HomePieceOfFurniture)getUserData();
  8.      Node filledModelNode = getFilledModelNode();
  9. +    Clazz3823529 param = new Clazz3823529()
  10. +           .withNode(filledModelNode)
  11. +           .withShininess(piece.getShininess())
  12. +           .withModifiedAppearances(new HashSet<Appearance>());
  13.      if (piece.getColor() != null) {
  14. -      setColorAndTexture(filledModelNode, piece.getColor(), null, piece.getShininess(), false,
  15. -          null, null, new HashSet<Appearance>());
  16. +       param = param.withColor(piece.getColor());
  17.      } else if (piece.getTexture() != null) {
  18. -      setColorAndTexture(filledModelNode, null, piece.getTexture(), piece.getShininess(), waitTextureLoadingEnd,
  19. -          new Vector3f(piece.getWidth(), piece.getHeight(), piece.getDepth()), ModelManager.getInstance().getBounds(((Group)filledModelNode).getChild(0)),
  20. -          new HashSet<Appearance>());
  21. -    } else {
  22. -      // Set default material and texture of model
  23. -      setColorAndTexture(filledModelNode, null, null, piece.getShininess(), false,
  24. -          null, null, new HashSet<Appearance>());
  25. +       param = param.withTexture(piece.getTexture())
  26. +               .withWaitTextureLoadingEnd(waitTextureLoadingEnd)
  27. +               .withPieceSize(new Vector3f(piece.getWidth(), piece.getHeight(), piece.getShininess()))
  28. +               .withModelBounds(ModelManager.getInstance().getBounds(((Group)filledModelNode).getChild(0)));
  29.      }
  30. +   // Set default material and texture of model
  31. +   setColorAndTexture(param);
  32. +    
  33.    }
  34.  
  35.    /**
  36. @@ -541,24 +544,20 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  37.     * Sets the material and texture attribute of all <code>Shape3D</code> children nodes of <code>node</code>
  38.     * from the given <code>color</code> and <code>texture</code>.
  39.     */
  40. -  private void setColorAndTexture(Node node, Integer color,
  41. -                                  HomeTexture texture, Float shininess,
  42. -                                  boolean waitTextureLoadingEnd, Vector3f pieceSize,
  43. -                                  BoundingBox modelBounds, Set<Appearance> modifiedAppearances) {
  44. -    if (node instanceof Group) {
  45. +  private void setColorAndTexture(Clazz3823529 param) {
  46. +    Clazz3823529 tempParam = new Clazz3823529(param);
  47. +    if (param.node instanceof Group) {
  48.        // Set material and texture of all children
  49. -      Enumeration<?> enumeration = ((Group)node).getAllChildren();
  50. +      Enumeration<?> enumeration = ((Group)param.node).getAllChildren();
  51.        while (enumeration.hasMoreElements()) {
  52. -        setColorAndTexture((Node)enumeration.nextElement(), color,
  53. -            texture, shininess, waitTextureLoadingEnd, pieceSize,
  54. -            modelBounds, modifiedAppearances);
  55. +         tempParam = tempParam.withNode((Node)enumeration.nextElement());
  56. +        setColorAndTexture(tempParam);
  57.        }
  58. -    } else if (node instanceof Link) {
  59. -      setColorAndTexture(((Link)node).getSharedGroup(), color,
  60. -          texture, shininess, waitTextureLoadingEnd, pieceSize,
  61. -          modelBounds, modifiedAppearances);
  62. -    } else if (node instanceof Shape3D) {
  63. -      final Shape3D shape = (Shape3D)node;
  64. +    } else if (param.node instanceof Link) {
  65. +       tempParam = tempParam.withNode(((Link)param.node).getSharedGroup());
  66. +      setColorAndTexture(tempParam);
  67. +    } else if (param.node instanceof Shape3D) {
  68. +      final Shape3D shape = (Shape3D)param.node;
  69.        String shapeName = (String)shape.getUserData();
  70.        // Change material and texture of all shapes that are not window panes
  71.        if (shapeName == null
  72. @@ -566,53 +565,53 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  73.          Appearance appearance = shape.getAppearance();
  74.          if (appearance == null) {
  75.            appearance = createAppearanceWithChangeCapabilities();
  76. -          ((Shape3D)node).setAppearance(appearance);
  77. +          ((Shape3D)param.node).setAppearance(appearance);
  78.          }
  79.          
  80.          // Check appearance wasn't already changed
  81. -        if (!modifiedAppearances.contains(appearance)) {
  82. +        if (!param.modifiedAppearances.contains(appearance)) {
  83.            // Use appearance user data to store shape default material
  84.            DefaultMaterialAndTexture defaultMaterialAndTexture = (DefaultMaterialAndTexture)appearance.getUserData();
  85.            if (defaultMaterialAndTexture == null) {
  86.              defaultMaterialAndTexture = new DefaultMaterialAndTexture(appearance);
  87.              appearance.setUserData(defaultMaterialAndTexture);
  88.            }
  89. -          float materialShininess = shininess != null
  90. -              ? shininess.floatValue()
  91. +          float materialShininess = param.shininess != null
  92. +              ? param.shininess.floatValue()
  93.                : (appearance.getMaterial() != null
  94.                    ? appearance.getMaterial().getShininess() / 128f
  95.                    : 0);
  96. -          if (color != null && defaultMaterialAndTexture.getTexture() == null) {
  97. +          if (param.color != null && defaultMaterialAndTexture.getTexture() == null) {
  98.              // Change material if no default texture is displayed on the shape
  99.              // (textures always keep the colors of their image file)
  100. -            appearance.setMaterial(getMaterial(color, color, materialShininess));
  101. +            appearance.setMaterial(getMaterial(param.color, param.color, materialShininess));
  102.              appearance.setTransparencyAttributes(defaultMaterialAndTexture.getTransparencyAttributes());
  103.              appearance.setPolygonAttributes(defaultMaterialAndTexture.getPolygonAttributes());
  104.              appearance.setTexCoordGeneration(defaultMaterialAndTexture.getTexCoordGeneration());
  105.              appearance.setTextureAttributes(defaultMaterialAndTexture.getTextureAttributes());
  106.              appearance.setTexture(null);
  107. -          } else if (color == null && texture != null) {            
  108. +          } else if (param.color == null && param.texture != null) {            
  109.              // Change material to white then texture
  110.              appearance.setMaterial(getMaterial(DEFAULT_COLOR, DEFAULT_AMBIENT_COLOR, materialShininess));
  111.              Point3d lower = new Point3d();
  112. -            modelBounds.getLower(lower);
  113. +            param.modelBounds.getLower(lower);
  114.              Point3d upper = new Point3d();
  115. -            modelBounds.getUpper(upper);
  116. +            param.modelBounds.getUpper(upper);
  117.              float minimumSize = ModelManager.getInstance().getMinimumSize();
  118. -            float sx = pieceSize.x / (float)Math.max(upper.x - lower.x, minimumSize) / texture.getWidth();
  119. -            float sw = texture.isLeftToRightOriented()  
  120. +            float sx = param.pieceSize.x / (float)Math.max(upper.x - lower.x, minimumSize) / param.texture.getWidth();
  121. +            float sw = param.texture.isLeftToRightOriented()  
  122.                  ? (float)-lower.x * sx  
  123.                  : 0;
  124. -            float ty = pieceSize.y / (float)Math.max(upper.y - lower.y, minimumSize) / texture.getHeight();
  125. -            float tz = pieceSize.z / (float)Math.max(upper.z - lower.z, minimumSize) / texture.getHeight();
  126. -            float tw = texture.isLeftToRightOriented()  
  127. +            float ty = param.pieceSize.y / (float)Math.max(upper.y - lower.y, minimumSize) / param.texture.getHeight();
  128. +            float tz = param.pieceSize.z / (float)Math.max(upper.z - lower.z, minimumSize) / param.texture.getHeight();
  129. +            float tw = param.texture.isLeftToRightOriented()  
  130.                  ? (float)(-lower.y * ty + upper.z * tz)
  131.                  : 0;
  132.              TexCoordGeneration texCoordGeneration = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
  133.                  TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(sx, 0, 0, sw), new Vector4f(0, ty, -tz, tw));
  134.              appearance.setTexCoordGeneration(texCoordGeneration);
  135.              appearance.setTextureAttributes(MODULATE_TEXTURE_ATTRIBUTES);
  136. -            TextureManager.getInstance().loadTexture(texture.getImage(), waitTextureLoadingEnd,
  137. +            TextureManager.getInstance().loadTexture(param.texture.getImage(), param.waitTextureLoadingEnd,
  138.                  new TextureManager.TextureObserver() {
  139.                      public void textureUpdated(Texture texture) {
  140.                        if (TextureManager.getInstance().isTextureTransparent(texture)) {
  141. @@ -625,10 +624,10 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  142.            } else {
  143.              // Restore default material and texture
  144.              Material defaultMaterial = defaultMaterialAndTexture.getMaterial();
  145. -            if (defaultMaterial != null && shininess != null) {
  146. +            if (defaultMaterial != null && param.shininess != null) {
  147.                defaultMaterial = (Material)defaultMaterial.cloneNodeComponent(true);
  148. -              defaultMaterial.setSpecularColor(new Color3f(shininess, shininess, shininess));
  149. -              defaultMaterial.setShininess(shininess * 128);
  150. +              defaultMaterial.setSpecularColor(new Color3f(param.shininess, param.shininess, param.shininess));
  151. +              defaultMaterial.setShininess(param.shininess * 128);
  152.              }
  153.              appearance.setMaterial(defaultMaterial);
  154.              appearance.setTransparencyAttributes(defaultMaterialAndTexture.getTransparencyAttributes());
  155. @@ -638,7 +637,7 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  156.              appearance.setTextureAttributes(defaultMaterialAndTexture.getTextureAttributes());
  157.            }
  158.            // Store modified appearances to avoid changing their values more than once
  159. -          modifiedAppearances.add(appearance);
  160. +          param.modifiedAppearances.add(appearance);
  161.          }
  162.        }
  163.      }
  164. @@ -867,4 +866,68 @@ public class HomePieceOfFurniture3D extends Object3DBranch {
  165.        return this.textureAttributes;
  166.      }
  167.    }
  168. +  
  169. +  private class Clazz3823529 {
  170. +     public Node node;
  171. +     public Integer color;
  172. +     public HomeTexture texture;
  173. +     public Float shininess;
  174. +     public boolean waitTextureLoadingEnd;
  175. +     public Vector3f pieceSize;
  176. +     public BoundingBox modelBounds;
  177. +     public Set<Appearance> modifiedAppearances;
  178. +    
  179. +     Clazz3823529() {}
  180. +    
  181. +     Clazz3823529(Clazz3823529 copy) {
  182. +         this.node = copy.node;
  183. +         this.color = copy.color;
  184. +         this.texture = copy.texture;
  185. +         this.shininess = copy.shininess;
  186. +         this.waitTextureLoadingEnd = copy.waitTextureLoadingEnd;
  187. +         this.pieceSize = copy.pieceSize;
  188. +         this.modelBounds = copy.modelBounds;
  189. +         this.modifiedAppearances = copy.modifiedAppearances;
  190. +     }
  191. +    
  192. +     Clazz3823529 withNode(Node node) {
  193. +         this.node = node;
  194. +         return this;
  195. +     }
  196. +    
  197. +     Clazz3823529 withColor(Integer color) {
  198. +         this.color = color;
  199. +         return this;
  200. +     }
  201. +    
  202. +     Clazz3823529 withTexture(HomeTexture texture) {
  203. +         this.texture = texture;
  204. +         return this;
  205. +     }
  206. +    
  207. +     Clazz3823529 withShininess(Float shininess) {
  208. +         this.shininess = shininess;
  209. +         return this;
  210. +     }
  211. +    
  212. +     Clazz3823529 withWaitTextureLoadingEnd(boolean waitTextureLoadingEnd) {
  213. +         this.waitTextureLoadingEnd = waitTextureLoadingEnd;
  214. +         return this;
  215. +     }
  216. +    
  217. +     Clazz3823529 withPieceSize(Vector3f pieceSize) {
  218. +         this.pieceSize = pieceSize;
  219. +         return this;
  220. +     }
  221. +    
  222. +     Clazz3823529 withModelBounds(BoundingBox modelBounds) {
  223. +         this.modelBounds = modelBounds;
  224. +         return this;
  225. +     }
  226. +    
  227. +     Clazz3823529 withModifiedAppearances(Set<Appearance> modifiedAppearances) {
  228. +         this.modifiedAppearances = modifiedAppearances;
  229. +         return this;
  230. +     }
  231. +  }
  232.  }
  233. \ No newline at end of file