Package com.sun.j3d.loaders

Examples of com.sun.j3d.loaders.SceneBase


   * Returns the scene parsed from a Collada XML stream.
   */
  private Scene parseXMLStream(InputStream in,
                               URL baseUrl) throws IOException {
    try {
      SceneBase scene = new SceneBase();
      SAXParserFactory factory = SAXParserFactory.newInstance();
      factory.setValidating(false);
      SAXParser saxParser = factory.newSAXParser();
      saxParser.parse(in, new DAEHandler(scene, baseUrl));
      return scene;
View Full Code Here


    Point3f [] vertices = this.vertices.toArray(new Point3f [this.vertices.size()]);
    TexCoord2f [] textureCoodinates =
        this.textureCoodinates.toArray(new TexCoord2f [this.textureCoodinates.size()]);
    Vector3f [] normals = this.normals.toArray(new Vector3f [this.normals.size()]);
 
    SceneBase scene = new SceneBase();
    BranchGroup sceneRoot = new BranchGroup();
    scene.setSceneGroup(sceneRoot);
    for (Group group : this.groups.values()) {
      List<Geometry> geometries = group.getGeometry();
      if (geometries != null
          && !geometries.isEmpty()) {
        int i = 0;
        while (i < geometries.size()) {
          Geometry firstGeometry = geometries.get(i);         
          boolean firstGeometryHasTextureCoordinateIndices = firstGeometry.hasTextureCoordinateIndices();
          boolean firstFaceHasNormalIndices = (firstGeometry instanceof Face) && ((Face)firstGeometry).hasNormalIndices();
         
          String firstGeometryMaterial = firstGeometry.getMaterial();
          Appearance appearance = getAppearance(firstGeometryMaterial);
         
          // Search how many geometries share the same characteristics
          int max = i;
          while (++max < geometries.size()) {
            Geometry geometry = geometries.get(max);
            String material = geometry.getMaterial();
            if (geometry.getClass() != firstGeometry.getClass()
                || material == null && firstGeometryMaterial != null
                || material != null && getAppearance(material) != appearance
                || (firstGeometryHasTextureCoordinateIndices ^ geometry.hasTextureCoordinateIndices())
                || (firstFaceHasNormalIndices ^ ((firstGeometry instanceof Face) && ((Face)geometry).hasNormalIndices()))) {
              break;
            }
          }
         
          // Create indices arrays for the faces with an index between i and max
          int faceCount = max - i;
          int indexCount = 0;
          for (int j = 0; j < faceCount; j++) {
            indexCount += geometries.get(i + j).getVertexIndices().length;
          }
          int [] coordinatesIndices = new int [indexCount];
          int [] stripCounts = new int [faceCount];
          for (int j = 0, destIndex = 0; j < faceCount; j++) {
            int [] geometryVertexIndices = geometries.get(i + j).getVertexIndices();
            System.arraycopy(geometryVertexIndices, 0, coordinatesIndices, destIndex, geometryVertexIndices.length);
            stripCounts [j] = geometryVertexIndices.length;
            destIndex += geometryVertexIndices.length;
          }

          int [] textureCoordinateIndices = null;
          if (firstGeometryHasTextureCoordinateIndices) {
            textureCoordinateIndices = new int [indexCount];
            for (int j = 0, destIndex = 0; j < faceCount; j++) {
              int [] geometryTextureCoordinateIndices = geometries.get(i + j).getTextureCoordinateIndices();
              System.arraycopy(geometryTextureCoordinateIndices, 0, textureCoordinateIndices, destIndex, geometryTextureCoordinateIndices.length);
              destIndex += geometryTextureCoordinateIndices.length;
            }
          }

          GeometryArray geometryArray;
          if (firstGeometry instanceof Face) {
            GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
            geometryInfo.setCoordinates(vertices);
            geometryInfo.setCoordinateIndices(coordinatesIndices);
            geometryInfo.setStripCounts(stripCounts);
           
            if (firstGeometryHasTextureCoordinateIndices) {
              geometryInfo.setTextureCoordinateParams(1, 2);
              geometryInfo.setTextureCoordinates(0, textureCoodinates);
              geometryInfo.setTextureCoordinateIndices(0, textureCoordinateIndices);
            }
           
            if (firstFaceHasNormalIndices) {
              int [] normalIndices = new int [indexCount];
              for (int j = 0, destIndex = 0; j < faceCount; j++) {
                int [] faceNormalIndices = ((Face)geometries.get(i + j)).getNormalIndices();
                System.arraycopy(faceNormalIndices, 0, normalIndices, destIndex, faceNormalIndices.length);
                destIndex += faceNormalIndices.length;
              }
              geometryInfo.setNormals(normals);
              geometryInfo.setNormalIndices(normalIndices);
            } else {
              NormalGenerator normalGenerator = new NormalGenerator(Math.PI / 2);
              if (!group.isSmooth()) {
                normalGenerator.setCreaseAngle(0);
              }
              normalGenerator.generateNormals(geometryInfo);
            }
            geometryArray = geometryInfo.getGeometryArray(true, true, false);
          } else { // Line
            int format = IndexedGeometryArray.COORDINATES;
            if (firstGeometryHasTextureCoordinateIndices) {
              format |= IndexedGeometryArray.TEXTURE_COORDINATE_2;
            }
           
            // Use non indexed line array to avoid referencing the whole vertices
            geometryArray = new LineStripArray(coordinatesIndices.length, format, stripCounts);           
            for (int j = 0; j < coordinatesIndices.length; j++) {
              geometryArray.setCoordinate(j, vertices [coordinatesIndices [j]]);
            }
            if (firstGeometryHasTextureCoordinateIndices) {
              for (int j = 0; j < coordinatesIndices.length; j++) {
                geometryArray.setTextureCoordinate(0, j, textureCoodinates [textureCoordinateIndices [j]]);
              }
            }
          }
         
          // Clone appearance to avoid sharing it
          if (appearance != null) {
            appearance = (Appearance)appearance.cloneNodeComponent(false);
            // Create texture coordinates if geometry doesn't define its own coordinates
            // and appearance contains a texture
            if (!firstGeometryHasTextureCoordinateIndices
                && appearance.getTexture() != null) {
              appearance.setTexCoordGeneration(new TexCoordGeneration());
            }
          }
          Shape3D shape = new Shape3D(geometryArray, appearance);  
          sceneRoot.addChild(shape);
          scene.addNamedObject(group.getName() + (i == 0 ? "" : String.valueOf(i)), shape);
         
          i = max;
        }
      }
    }
View Full Code Here

/*      */     }
/*      */   }
/*      */
/*      */   private SceneBase makeScene()
/*      */   {
/* 1142 */     SceneBase scene = new SceneBase();
/* 1143 */     BranchGroup group = new BranchGroup();
/* 1144 */     scene.setSceneGroup(group);
/*      */
/* 1146 */     boolean gen_norms = (this.normList.isEmpty()) || (this.normIdxList.isEmpty()) || (this.normIdxList.size() != this.coordIdxList.size());
/*      */
/* 1148 */     boolean do_tex = (!this.texList.isEmpty()) && (!this.texIdxList.isEmpty()) && (this.texIdxList.size() == this.coordIdxList.size());
/*      */
/* 1152 */     this.coordArray = objectToPoint3Array(this.coordList);
/* 1153 */     if (!gen_norms) this.normArray = objectToVectorArray(this.normList);
/* 1154 */     if (do_tex) this.texArray = objectToTexCoord2Array(this.texList);
/*      */
/* 1156 */     convertToTriangles();
/*      */
/* 1164 */     if ((gen_norms) && (this.curSgroup != null)) {
/* 1165 */       smoothingGroupNormals();
/* 1166 */       gen_norms = false;
/*      */     }
/*      */
/* 1174 */     NormalGenerator ng = null;
/* 1175 */     if (gen_norms) ng = new NormalGenerator(this.radians);
/*      */
/* 1177 */     Stripifier strippy = null;
/* 1178 */     if ((this.flags & 0x200) != 0) strippy = new Stripifier();
/*      */
/* 1180 */     long t1 = 0L; long t2 = 0L; long t3 = 0L; long t4 = 0L;
/*      */
/* 1183 */     Iterator e = this.triGroups.keySet().iterator();
/* 1184 */     while (e.hasNext())
/*      */     {
/* 1186 */       String curname = (String)e.next();
/* 1187 */       ArrayList triList = (ArrayList)this.triGroups.get(curname);
/*      */
/* 1190 */       if (triList.size() > 0)
/*      */       {
/* 1192 */         GeometryInfo gi = new GeometryInfo(1);
/*      */
/* 1194 */         gi.setCoordinateIndices(groupIndices(this.coordIdxList, triList));
/* 1195 */         gi.setCoordinates(this.coordArray);
/*      */
/* 1197 */         if (do_tex) {
/* 1198 */           gi.setTextureCoordinateParams(1, 2);
/* 1199 */           gi.setTextureCoordinates(0, this.texArray);
/* 1200 */           gi.setTextureCoordinateIndices(0, groupIndices(this.texIdxList, triList));
/*      */         }
/*      */
/* 1204 */         if (gen_norms) {
/* 1205 */           if ((this.flags & 0x100) != 0) gi.reverse();
/* 1206 */           ng.generateNormals(gi);
/*      */         }
/*      */         else
/*      */         {
/* 1213 */           gi.setNormalIndices(groupIndices(this.normIdxList, triList));
/* 1214 */           gi.setNormals(this.normArray);
/* 1215 */           if ((this.flags & 0x100) != 0) gi.reverse();
/*      */         }
/*      */
/* 1218 */         if ((this.flags & 0x200) != 0) {
/* 1219 */           strippy.stripify(gi);
/*      */         }
/*      */
/* 1228 */         Shape3D shape = new Shape3D();
/*      */
/* 1230 */         shape.setGeometry(gi.getGeometryArray(true, true, false));
/*      */
/* 1232 */         String matName = (String)this.groupMaterials.get(curname);
/* 1233 */         this.materials.assignMaterial(matName, shape);
/*      */
/* 1235 */         group.addChild(shape);
/* 1236 */         scene.addNamedObject(curname, shape);
/*      */       }
/*      */
/*      */     }
/*      */
/* 1246 */     return scene;
View Full Code Here

/* 282 */     return this.scene;
/*     */   }
/*     */
/*     */   void constructScene()
/*     */   {
/* 296 */     this.scene = new SceneBase();
/*     */
/* 298 */     if ((this.loadFlags & 0x1) != 0) {
/* 299 */       addLights();
/* 300 */       addAmbient();
/*     */     }
View Full Code Here

TOP

Related Classes of com.sun.j3d.loaders.SceneBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.