~ubuntu-branches/ubuntu/saucy/sweethome3d/saucy

« back to all changes in this revision

Viewing changes to src/com/eteks/sweethome3d/j3d/Ground3D.java

  • Committer: Package Import Robot
  • Author(s): Gabriele Giacone
  • Date: 2012-06-16 12:45:35 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120616124535-voytck97kdxg3xfz
Tags: 3.5+dfsg-1
* New upstream release.
* Switch source and binary to xz compression.
* Bump Standards-Version to 3.9.3 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
package com.eteks.sweethome3d.j3d;
21
21
 
22
 
import java.awt.Color;
23
22
import java.awt.geom.Area;
24
23
import java.awt.geom.PathIterator;
25
24
import java.awt.geom.Point2D;
34
33
import java.util.TreeMap;
35
34
 
36
35
import javax.media.j3d.Appearance;
37
 
import javax.media.j3d.ColoringAttributes;
38
36
import javax.media.j3d.Shape3D;
39
37
import javax.media.j3d.Texture;
40
 
import javax.vecmath.Color3f;
 
38
import javax.media.j3d.TextureAttributes;
41
39
import javax.vecmath.Point3f;
42
40
import javax.vecmath.TexCoord2f;
43
41
 
48
46
import com.eteks.sweethome3d.model.Room;
49
47
import com.eteks.sweethome3d.model.Wall;
50
48
import com.sun.j3d.utils.geometry.GeometryInfo;
 
49
import com.sun.j3d.utils.geometry.NormalGenerator;
51
50
 
52
51
/**
53
52
 * Root of a the 3D ground.
63
62
   * Creates a 3D ground for the given <code>home</code>.
64
63
   */
65
64
  public Ground3D(Home home,
66
 
                  float groundOriginX,
67
 
                  float groundOriginY,
68
 
                  float groundWidth,
69
 
                  float groundDepth, 
 
65
                  float originX,
 
66
                  float originY,
 
67
                  float width,
 
68
                  float depth, 
70
69
                  boolean waitTextureLoadingEnd) {
71
70
    setUserData(home);
72
 
    this.originX = groundOriginX;
73
 
    this.originY = groundOriginY;
74
 
    this.width = groundWidth;
75
 
    this.depth = groundDepth;
 
71
    this.originX = originX;
 
72
    this.originY = originY;
 
73
    this.width = width;
 
74
    this.depth = depth;
76
75
 
77
 
    // Use coloring attributes for ground to avoid ground lighting
78
 
    ColoringAttributes groundColoringAttributes = new ColoringAttributes();
79
 
    groundColoringAttributes.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
80
 
    
81
76
    Appearance groundAppearance = new Appearance();
82
 
    groundAppearance.setColoringAttributes(groundColoringAttributes);
83
 
    groundAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
 
77
    groundAppearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
84
78
    groundAppearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
 
79
    TextureAttributes textureAttributes = new TextureAttributes();
 
80
    textureAttributes.setTextureMode(TextureAttributes.MODULATE);
 
81
    groundAppearance.setTextureAttributes(textureAttributes);
85
82
 
86
83
    final Shape3D groundShape = new Shape3D();
87
84
    groundShape.setAppearance(groundAppearance);
112
109
    Shape3D groundShape = (Shape3D)getChild(0);
113
110
    int currentGeometriesCount = groundShape.numGeometries();
114
111
    
115
 
    Color3f groundColor = new Color3f(new Color(home.getEnvironment().getGroundColor()));
116
112
    final Appearance groundAppearance = groundShape.getAppearance();
117
 
    groundAppearance.getColoringAttributes().setColor(groundColor);
118
113
    HomeTexture groundTexture = home.getEnvironment().getGroundTexture();
119
 
    if (groundTexture != null) {
 
114
    if (groundTexture == null) {
 
115
      int groundColor = home.getEnvironment().getGroundColor();
 
116
      groundAppearance.setMaterial(getMaterial(groundColor, groundColor, 0));
 
117
      groundAppearance.setTexture(null);
 
118
    } else {
 
119
      groundAppearance.setMaterial(getMaterial(DEFAULT_COLOR, DEFAULT_COLOR, 0));
120
120
      final TextureManager imageManager = TextureManager.getInstance();
121
121
      imageManager.loadTexture(groundTexture.getImage(), waitTextureLoadingEnd,
122
122
          new TextureManager.TextureObserver() {
124
124
                groundAppearance.setTexture(texture);
125
125
              }
126
126
            });
127
 
    } else {
128
 
      groundAppearance.setTexture(null);
129
127
    }
130
128
    
131
129
    Area areaRemovedFromGround = new Area();
157
155
    
158
156
    // Search all items at negative levels that could dig the ground 
159
157
    for (HomePieceOfFurniture piece : home.getFurniture()) {
160
 
      updateUndergroundAreas(undergroundAreas, piece.getLevel(), piece.getPoints(), null);
 
158
      if (piece.getStaircaseCutOutShape() == null) {
 
159
        updateUndergroundAreas(undergroundAreas, piece.getLevel(), piece.getPoints(), null);
 
160
      } else {
 
161
        updateUndergroundAreas(undergroundAreas, piece.getLevel(), null, ModelManager.getInstance().getAreaOnFloor(piece));
 
162
      }
161
163
    }
162
164
    Map<Level, Area> wallAreas = new HashMap<Level, Area>();
163
165
    for (Wall wall : home.getWalls()) {
265
267
    List<float [][]> areaPoints = new ArrayList<float [][]>();
266
268
    List<float []>   areaPartPoints  = new ArrayList<float[]>();
267
269
    float [] previousRoomPoint = null;
268
 
    for (PathIterator it = area.getPathIterator(null); !it.isDone(); ) {
 
270
    for (PathIterator it = area.getPathIterator(null, 1); !it.isDone(); ) {
269
271
      float [] roomPoint = new float[2];
270
272
      if (it.currentSegment(roomPoint) == PathIterator.SEG_CLOSE) {
271
273
        if (areaPartPoints.get(0) [0] == previousRoomPoint [0] 
381
383
    }
382
384
    geometryInfo.setStripCounts(stripCounts);
383
385
    geometryInfo.setContourCounts(contourCounts);
 
386
    new NormalGenerator(0).generateNormals(geometryInfo);
384
387
    groundShape.addGeometry(geometryInfo.getIndexedGeometryArray());
385
388
  }
386
389
 
424
427
    }
425
428
    geometryInfo.setStripCounts(stripCounts);
426
429
    geometryInfo.setContourCounts(contourCounts);
 
430
    new NormalGenerator(0).generateNormals(geometryInfo);
427
431
    groundShape.addGeometry(geometryInfo.getIndexedGeometryArray());
428
432
  }
429
433
}
 
434