⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geometryinfo.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      return oldPrim;  } // End of getOldPrim  // Used by the Utility libraries other than the NormalGenerator.  // Informs the GeometryInfo object that the geometry need not  // be converted back to the original primitive before returning.  // For example, if a list of Fans is sent, converted to Triangles  // for normal generation, and then stripified by the Stripifyer,  // we want to make sure that GeometryInfo doesn't convert the  // geometry *back* to fans before creating the output GeometryArray.  void forgetOldPrim()  {      oldPrim = 0;      oldStripCounts = null;  } // End of forgetOldPrim  // We have changed the user's data from their original primitive  // type to TRIANGLE_ARRAY.  If this method is being called, it  // means we need to change it back (to try and hide from the user  // the fact that we've converted).  This usually happens when  // the user has used GeometryInfo for generating normals, but  // they are not Stripifying or Triangulating.  The function is  // called from getGeometryArray before creating the output data.  private void changeBackToOldPrim()  {      if (oldPrim != 0) {	  convertToIndexedTriangles();	  if (ng == null) ng = new NormalGenerator();	  ng.convertBackToOldPrim(this, oldPrim, oldStripCounts);	  oldPrim = 0;	  oldStripCounts = null;      }  } // End of changeBackToOldPrim  /**   * Convert the GeometryInfo object to have primitive type TRIANGLE_ARRAY   * and be indexed.   * @throws IllegalArgumentException if coordinate data is missing,   * if the index lists aren't all the   * same length, if an index list is set and the corresponding data   * list isn't set, if a data list is set and the corresponding   * index list is unset (unless all index lists are unset or in   * USE_COORD_INDEX_ONLY format),   * if StripCounts or ContourCounts is inconsistent with the current   * primitive, if the sum of the contourCounts array doesn't equal   * the length of the StripCounts array, or if the number of vertices   * isn't a multiple of three (for triangles) or four (for quads).   */  public void convertToIndexedTriangles()  {      int triangles = 0;            // This calls checkForBadData      indexify();            if (prim == TRIANGLE_ARRAY) return;            switch(prim) {	  	  case QUAD_ARRAY:	      	      coordinateIndices = expandQuad(coordinateIndices);	      if (colorIndices != null) colorIndices = expandQuad(colorIndices);	      if (normalIndices != null)		  normalIndices = expandQuad(normalIndices);	      for (int i = 0 ; i < texCoordSetCount ; i++)		  texCoordIndexSets[i] = expandQuad(texCoordIndexSets[i]);	      break;	      	  case TRIANGLE_FAN_ARRAY:	      // Count how many triangles are in the object	      for (int i = 0 ; i < stripCounts.length ; i++) {		  triangles += stripCounts[i] - 2;	      }	      	      coordinateIndices = expandTriFan(triangles, coordinateIndices);	      if (colorIndices != null)		  colorIndices = expandTriFan(triangles, colorIndices);	      if (normalIndices != null)		  normalIndices = expandTriFan(triangles, normalIndices);	      for (int i = 0 ; i < texCoordSetCount ; i++)		  texCoordIndexSets[i] = expandTriFan(triangles, 			      texCoordIndexSets[i]);	      break;	      	  case TRIANGLE_STRIP_ARRAY:	      // Count how many triangles are in the object	      for (int i = 0 ; i < stripCounts.length ; i++) {		  triangles += stripCounts[i] - 2;	      }	      	      coordinateIndices = expandTriStrip(triangles, coordinateIndices);	      if (colorIndices != null)		  colorIndices = expandTriStrip(triangles, colorIndices);	      if (normalIndices != null)		  normalIndices = expandTriStrip(triangles, normalIndices);	      for (int i = 0 ; i < texCoordSetCount ; i++)		  texCoordIndexSets[i] = expandTriStrip(triangles, 			      texCoordIndexSets[i]);	      break;	      	  case POLYGON_ARRAY:	      if (tr == null) tr = new Triangulator();	      tr.triangulate(this);	      break;      }            prim = TRIANGLE_ARRAY;      stripCounts = null;  } // End of convertToIndexedTriangles  /**   * Get the current primitive.  Some of the utilities may change the   * primitive type of the data stored in the GeometryInfo object   * (for example, the stripifyer will change it to TRIANGLE_STRIP_ARRAY).   */  public int getPrimitive()  {      return prim;  } // End of getPrimitive()  /**   * Set the current primitive.  Some of the utilities may change the   * primitive type of the data stored in the GeometryInfo object   * (for example, the stripifyer will change it to TRIANGLE_STRIP_ARRAY).   * But the user can't change the primitive type - it is set in the    * constructor.  Therefore, this method has package scope.   */  void setPrimitive(int primitive)  {      if ((prim >= TRIANGLE_ARRAY) && (prim <= POLYGON_ARRAY)) {	  prim = primitive;      } else {	  throw new IllegalArgumentException(		  J3dUtilsI18N.getString("GeometryInfo0"));      }  } // End of setPrimitive()  /**   * Sets the coordinates array.     * No data copying is done because a reference to user data is used.   */  public void setCoordinates(Point3f coordinates[])  {      this.coordinates = coordinates;  } // End of setCoordinates  /**   * Sets the coordinates array.   * The points are copied into the GeometryInfo object.   */  public void setCoordinates(Point3d coordinates[])  {      if (coordinates == null) this.coordinates = null;      else {	  this.coordinates = new Point3f[coordinates.length];	  for (int i = 0 ; i < coordinates.length ; i++) {	      this.coordinates[i] = new Point3f(		      (float)(coordinates[i].x),		      (float)(coordinates[i].y),		      (float)(coordinates[i].z));	  }      }  } // End of setCoordinates  /**   * Sets the coordinates array.   * The points are copied into the GeometryInfo object.   */  public void setCoordinates(float coordinates[])  {      if (coordinates == null) this.coordinates = null;      else {	  this.coordinates = new Point3f[coordinates.length / 3];	  for (int i = 0 ; i < this.coordinates.length ; i++) {	      this.coordinates[i] = new Point3f(coordinates[i * 3],		      				coordinates[i * 3 + 1],		      				coordinates[i * 3 + 2]);	  }      }  } // End of setCoordinates  /**   * Sets the coordinates array.   * The points are copied into the GeometryInfo object.   */  public void setCoordinates(double coordinates[])  {      if (coordinates == null) this.coordinates = null;      else {	  this.coordinates = new Point3f[coordinates.length / 3];	  for (int i = 0 ; i < coordinates.length / 3 ; i++) {	      this.coordinates[i] = new Point3f((float)coordinates[i * 3],					        (float)coordinates[i * 3 + 1],					        (float)coordinates[i * 3 + 2]);	  }      }  } // End of setCoordinates  /**   * Retrieves a reference to the coordinate array.   */  public Point3f[] getCoordinates()  {      return coordinates;  } // End of getCoordinates    /**   * Sets the colors array.   * No data copying is done because a reference to   * user data is used.   */  public void setColors(Color3f colors[])  {      colors3 = colors;      colors4 = null;  } // End of setColors    /**   * Sets the colors array.   * No data copying is done because a reference to   * user data is used.   */  public void setColors(Color4f colors[])  {      colors3 = null;      colors4 = colors;  } // End of setColors   /**   * Sets the colors array.   * The points are copied into the GeometryInfo object.   */  public void setColors(Color3b colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = new Color3f[colors.length];	  colors4 = null;	  for (int i = 0 ; i < colors.length ; i++) {	      colors3[i] = new Color3f((float) (colors[i].x & 0xff) / 255.0f,		      		       (float) (colors[i].y & 0xff) / 255.0f,		      		       (float) (colors[i].z & 0xff) / 255.0f);	  }      }  } // End of setColors   /**   * Sets the colors array.   * The points are copied into the GeometryInfo object.   */  public void setColors(Color4b colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = null;	  colors4 = new Color4f[colors.length];	  for (int i = 0 ; i < colors.length ; i++) {	      colors4[i] = new Color4f((float) (colors[i].x & 0xff) / 255.0f,		      		       (float) (colors[i].y & 0xff) / 255.0f,		      		       (float) (colors[i].z & 0xff) / 255.0f,		      		       (float) (colors[i].w & 0xff) / 255.0f);	  }      }  } // End of setColors   /**   * Sets the colors array.   * The points are copied into the GeometryInfo object, assuming   * 3 components (R, G, and B) per vertex.   */  public void setColors3(float colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = new Color3f[colors.length / 3];	  colors4 = null;	  for (int i = 0 ; i < colors.length / 3 ; i++) {	      colors3[i] = new Color3f(colors[i * 3],				       colors[i * 3 + 1],				       colors[i * 3 + 2]);	  }      }  } // End of setColors3   /**   * Sets the colors array.   * The points are copied into the GeometryInfo object, assuming   * 4 components (R, G, B, and A) per vertex.   */  public void setColors4(float colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = null;	  colors4 = new Color4f[colors.length / 4];	  for (int i = 0 ; i < colors.length / 4 ; i++) {	      colors4[i] = new Color4f(colors[i * 4],		      		       colors[i * 4 + 1],		      		       colors[i * 4 + 2],		      		       colors[i * 4 + 3]);	  }      }  } // End of setColors4   /**   * Sets the colors array.   * The points are copied into the GeometryInfo object, assuming   * 3 components (R, G, and B) per vertex.   */  public void setColors3(byte colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = new Color3f[colors.length / 3];	  colors4 = null;	  for (int i = 0 ; i < colors.length / 3 ; i++) {	      colors3[i] =		  new Color3f((float)(colors[i * 3] & 0xff) / 255.0f,		      	      (float)(colors[i * 3 + 1] & 0xff) / 255.0f,			      (float)(colors[i * 3 + 2] & 0xff) / 255.0f);	  }      }  } // End of setColors3  /**   * Sets the colors array.   * The points are copied into the GeometryInfo object, assuming   * 4 components (R, G, B, and A) per vertex.   */  public void setColors4(byte colors[])  {      if (colors == null) {	  colors3 = null;	  colors4 = null;      } else {	  colors3 = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -