/* */ package com.sun.j3d.utils.geometry;
/* */
/* */ import com.sun.j3d.internal.ByteBufferWrapper;
/* */ import com.sun.j3d.internal.ByteOrderWrapper;
/* */ import com.sun.j3d.internal.FloatBufferWrapper;
/* */ import com.sun.j3d.internal.J3dUtilsI18N;
/* */ import java.util.HashMap;
/* */ import javax.media.j3d.GeometryArray;
/* */ import javax.media.j3d.IndexedGeometryArray;
/* */ import javax.media.j3d.IndexedQuadArray;
/* */ import javax.media.j3d.IndexedTriangleArray;
/* */ import javax.media.j3d.IndexedTriangleFanArray;
/* */ import javax.media.j3d.IndexedTriangleStripArray;
/* */ import javax.media.j3d.QuadArray;
/* */ import javax.media.j3d.TriangleArray;
/* */ import javax.media.j3d.TriangleFanArray;
/* */ import javax.media.j3d.TriangleStripArray;
/* */ import javax.vecmath.Color3b;
/* */ import javax.vecmath.Color3f;
/* */ import javax.vecmath.Color4b;
/* */ import javax.vecmath.Color4f;
/* */ import javax.vecmath.Point2f;
/* */ import javax.vecmath.Point3d;
/* */ import javax.vecmath.Point3f;
/* */ import javax.vecmath.TexCoord2f;
/* */ import javax.vecmath.TexCoord3f;
/* */ import javax.vecmath.TexCoord4f;
/* */ import javax.vecmath.Tuple2f;
/* */ import javax.vecmath.Tuple3f;
/* */ import javax.vecmath.Tuple4f;
/* */ import javax.vecmath.Vector3f;
/* */
/* */ public class GeometryInfo
/* */ {
/* */ public static final int TRIANGLE_ARRAY = 1;
/* */ public static final int QUAD_ARRAY = 2;
/* */ public static final int TRIANGLE_FAN_ARRAY = 3;
/* */ public static final int TRIANGLE_STRIP_ARRAY = 4;
/* */ public static final int POLYGON_ARRAY = 5;
/* */ private int prim;
/* */ private static final int DEBUG = 0;
/* 168 */ private Point3f[] coordinates = null;
/* 169 */ private Color3f[] colors3 = null;
/* 170 */ private Color4f[] colors4 = null;
/* 171 */ private Vector3f[] normals = null;
/* 172 */ private Object[][] texCoordSets = (Object[][])null;
/* */
/* 174 */ private int[] coordinateIndices = null;
/* 175 */ private int[] colorIndices = null;
/* 176 */ private int[] normalIndices = null;
/* 177 */ private int[][] texCoordIndexSets = (int[][])null;
/* */
/* 179 */ private int[] texCoordSetMap = null;
/* 180 */ private int texCoordSetCount = 0;
/* 181 */ private int texCoordDim = 0;
/* */
/* 183 */ private int[] stripCounts = null;
/* 184 */ private int[] contourCounts = null;
/* */
/* 186 */ private Triangulator tr = null;
/* 187 */ private NormalGenerator ng = null;
/* */
/* 189 */ private int oldPrim = 0;
/* 190 */ private int[] oldStripCounts = null;
/* */
/* 192 */ private boolean coordOnly = false;
/* */
/* */ public GeometryInfo(int primitive)
/* */ {
/* 207 */ if ((primitive >= 1) && (primitive <= 5))
/* 208 */ this.prim = primitive;
/* */ else
/* 210 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo0"));
/* */ }
/* */
/* */ public GeometryInfo(GeometryArray ga)
/* */ {
/* 228 */ GeometryInfoGenerator.create(this, ga);
/* */ }
/* */
/* */ public void reset(int primitive)
/* */ {
/* 244 */ if ((primitive >= 1) && (primitive <= 5))
/* 245 */ this.prim = primitive;
/* */ else {
/* 247 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo0"));
/* */ }
/* */
/* 251 */ this.coordinates = null;
/* 252 */ this.colors3 = null;
/* 253 */ this.colors4 = null;
/* 254 */ this.normals = null;
/* */
/* 256 */ this.coordinateIndices = null;
/* 257 */ this.colorIndices = null;
/* 258 */ this.normalIndices = null;
/* */
/* 260 */ this.stripCounts = null;
/* 261 */ this.contourCounts = null;
/* */
/* 263 */ this.oldPrim = 0;
/* 264 */ this.oldStripCounts = null;
/* */
/* 266 */ this.texCoordDim = 0;
/* 267 */ this.texCoordSetCount = 0;
/* 268 */ this.texCoordSets = ((Object[][])null);
/* 269 */ this.texCoordIndexSets = ((int[][])null);
/* 270 */ this.texCoordSetMap = null;
/* */
/* 272 */ this.coordOnly = false;
/* */ }
/* */
/* */ public void reset(GeometryArray ga)
/* */ {
/* 284 */ GeometryInfoGenerator.create(this, ga);
/* */ }
/* */
/* */ private int[] expandQuad(int[] indices)
/* */ {
/* 294 */ int[] triangles = new int[indices.length / 4 * 6];
/* */
/* 296 */ for (int i = 0; i < indices.length / 4; i++) {
/* 297 */ triangles[(i * 6 + 0)] = indices[(i * 4)];
/* 298 */ triangles[(i * 6 + 1)] = indices[(i * 4 + 1)];
/* 299 */ triangles[(i * 6 + 2)] = indices[(i * 4 + 2)];
/* 300 */ triangles[(i * 6 + 3)] = indices[(i * 4)];
/* 301 */ triangles[(i * 6 + 4)] = indices[(i * 4 + 2)];
/* 302 */ triangles[(i * 6 + 5)] = indices[(i * 4 + 3)];
/* */ }
/* */
/* 305 */ return triangles;
/* */ }
/* */
/* */ private int[] expandTriFan(int numTris, int[] indices)
/* */ {
/* 315 */ int[] triangles = new int[numTris * 3];
/* 316 */ int p = 0;
/* 317 */ int base = 0;
/* 318 */ for (int f = 0; f < this.stripCounts.length; f++) {
/* 319 */ for (int t = 0; t < this.stripCounts[f] - 2; t++) {
/* 320 */ triangles[(p++)] = indices[base];
/* 321 */ triangles[(p++)] = indices[(base + t + 1)];
/* 322 */ triangles[(p++)] = indices[(base + t + 2)];
/* */ }
/* 324 */ base += this.stripCounts[f];
/* */ }
/* 326 */ return triangles;
/* */ }
/* */
/* */ private int[] expandTriStrip(int numTris, int[] indices)
/* */ {
/* 336 */ int[] triangles = new int[numTris * 3];
/* */
/* 338 */ int p = 0;
/* 339 */ int base = 0;
/* 340 */ for (int s = 0; s < this.stripCounts.length; s++) {
/* 341 */ for (int t = 0; t < this.stripCounts[s] - 2; t++)
/* */ {
/* 345 */ if (t % 2 == 0) {
/* 346 */ triangles[(p++)] = indices[(base + t + 0)];
/* 347 */ triangles[(p++)] = indices[(base + t + 1)];
/* 348 */ triangles[(p++)] = indices[(base + t + 2)];
/* */ } else {
/* 350 */ triangles[(p++)] = indices[(base + t + 0)];
/* 351 */ triangles[(p++)] = indices[(base + t + 2)];
/* 352 */ triangles[(p++)] = indices[(base + t + 1)];
/* */ }
/* */ }
/* 355 */ base += this.stripCounts[s];
/* */ }
/* */
/* 358 */ return triangles;
/* */ }
/* */
/* */ void rememberOldPrim()
/* */ {
/* 369 */ this.oldPrim = this.prim;
/* 370 */ this.oldStripCounts = this.stripCounts;
/* */ }
/* */
/* */ int getOldPrim()
/* */ {
/* 379 */ return this.oldPrim;
/* */ }
/* */
/* */ void forgetOldPrim()
/* */ {
/* 393 */ this.oldPrim = 0;
/* 394 */ this.oldStripCounts = null;
/* */ }
/* */
/* */ private void changeBackToOldPrim()
/* */ {
/* 408 */ if (this.oldPrim != 0) {
/* 409 */ convertToIndexedTriangles();
/* 410 */ if (this.ng == null) this.ng = new NormalGenerator();
/* 411 */ this.ng.convertBackToOldPrim(this, this.oldPrim, this.oldStripCounts);
/* 412 */ this.oldPrim = 0;
/* 413 */ this.oldStripCounts = null;
/* */ }
/* */ }
/* */
/* */ public void convertToIndexedTriangles()
/* */ {
/* 435 */ int triangles = 0;
/* */
/* 438 */ indexify();
/* */
/* 440 */ if (this.prim == 1) return;
/* */
/* 442 */ switch (this.prim)
/* */ {
/* */ case 2:
/* 446 */ this.coordinateIndices = expandQuad(this.coordinateIndices);
/* 447 */ if (this.colorIndices != null) this.colorIndices = expandQuad(this.colorIndices);
/* 448 */ if (this.normalIndices != null)
/* 449 */ this.normalIndices = expandQuad(this.normalIndices);
/* 450 */ for (int i = 0; i < this.texCoordSetCount; i++)
/* 451 */ this.texCoordIndexSets[i] = expandQuad(this.texCoordIndexSets[i]);
/* 452 */ break;
/* */ case 3:
/* 456 */ for (int i = 0; i < this.stripCounts.length; i++) {
/* 457 */ triangles += this.stripCounts[i] - 2;
/* */ }
/* */
/* 460 */ this.coordinateIndices = expandTriFan(triangles, this.coordinateIndices);
/* 461 */ if (this.colorIndices != null)
/* 462 */ this.colorIndices = expandTriFan(triangles, this.colorIndices);
/* 463 */ if (this.normalIndices != null)
/* 464 */ this.normalIndices = expandTriFan(triangles, this.normalIndices);
/* 465 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 466 */ this.texCoordIndexSets[i] = expandTriFan(triangles, this.texCoordIndexSets[i]);
/* */ }
/* 468 */ break;
/* */ case 4:
/* 472 */ for (int i = 0; i < this.stripCounts.length; i++) {
/* 473 */ triangles += this.stripCounts[i] - 2;
/* */ }
/* */
/* 476 */ this.coordinateIndices = expandTriStrip(triangles, this.coordinateIndices);
/* 477 */ if (this.colorIndices != null)
/* 478 */ this.colorIndices = expandTriStrip(triangles, this.colorIndices);
/* 479 */ if (this.normalIndices != null)
/* 480 */ this.normalIndices = expandTriStrip(triangles, this.normalIndices);
/* 481 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 482 */ this.texCoordIndexSets[i] = expandTriStrip(triangles, this.texCoordIndexSets[i]);
/* */ }
/* 484 */ break;
/* */ case 5:
/* 487 */ if (this.tr == null) this.tr = new Triangulator();
/* 488 */ this.tr.triangulate(this);
/* */ }
/* */
/* 492 */ this.prim = 1;
/* 493 */ this.stripCounts = null;
/* */ }
/* */
/* */ public int getPrimitive()
/* */ {
/* 505 */ return this.prim;
/* */ }
/* */
/* */ void setPrimitive(int primitive)
/* */ {
/* 519 */ if ((this.prim >= 1) && (this.prim <= 5))
/* 520 */ this.prim = primitive;
/* */ else
/* 522 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo0"));
/* */ }
/* */
/* */ public void setCoordinates(Point3f[] coordinates)
/* */ {
/* 535 */ this.coordinates = coordinates;
/* */ }
/* */
/* */ public void setCoordinates(Point3d[] coordinates)
/* */ {
/* 546 */ if (coordinates == null) { this.coordinates = null;
/* */ } else {
/* 548 */ this.coordinates = new Point3f[coordinates.length];
/* 549 */ for (int i = 0; i < coordinates.length; i++)
/* 550 */ this.coordinates[i] = new Point3f((float)coordinates[i].x, (float)coordinates[i].y, (float)coordinates[i].z);
/* */ }
/* */ }
/* */
/* */ public void setCoordinates(float[] coordinates)
/* */ {
/* 566 */ if (coordinates == null) { this.coordinates = null;
/* */ } else {
/* 568 */ this.coordinates = new Point3f[coordinates.length / 3];
/* 569 */ for (int i = 0; i < this.coordinates.length; i++)
/* 570 */ this.coordinates[i] = new Point3f(coordinates[(i * 3)], coordinates[(i * 3 + 1)], coordinates[(i * 3 + 2)]);
/* */ }
/* */ }
/* */
/* */ public void setCoordinates(double[] coordinates)
/* */ {
/* 585 */ if (coordinates == null) { this.coordinates = null;
/* */ } else {
/* 587 */ this.coordinates = new Point3f[coordinates.length / 3];
/* 588 */ for (int i = 0; i < coordinates.length / 3; i++)
/* 589 */ this.coordinates[i] = new Point3f((float)coordinates[(i * 3)], (float)coordinates[(i * 3 + 1)], (float)coordinates[(i * 3 + 2)]);
/* */ }
/* */ }
/* */
/* */ public Point3f[] getCoordinates()
/* */ {
/* 603 */ return this.coordinates;
/* */ }
/* */
/* */ public void setColors(Color3f[] colors)
/* */ {
/* 615 */ this.colors3 = colors;
/* 616 */ this.colors4 = null;
/* */ }
/* */
/* */ public void setColors(Color4f[] colors)
/* */ {
/* 628 */ this.colors3 = null;
/* 629 */ this.colors4 = colors;
/* */ }
/* */
/* */ public void setColors(Color3b[] colors)
/* */ {
/* 640 */ if (colors == null) {
/* 641 */ this.colors3 = null;
/* 642 */ this.colors4 = null;
/* */ } else {
/* 644 */ this.colors3 = new Color3f[colors.length];
/* 645 */ this.colors4 = null;
/* 646 */ for (int i = 0; i < colors.length; i++)
/* 647 */ this.colors3[i] = new Color3f((colors[i].x & 0xFF) / 255.0F, (colors[i].y & 0xFF) / 255.0F, (colors[i].z & 0xFF) / 255.0F);
/* */ }
/* */ }
/* */
/* */ public void setColors(Color4b[] colors)
/* */ {
/* 662 */ if (colors == null) {
/* 663 */ this.colors3 = null;
/* 664 */ this.colors4 = null;
/* */ } else {
/* 666 */ this.colors3 = null;
/* 667 */ this.colors4 = new Color4f[colors.length];
/* 668 */ for (int i = 0; i < colors.length; i++)
/* 669 */ this.colors4[i] = new Color4f((colors[i].x & 0xFF) / 255.0F, (colors[i].y & 0xFF) / 255.0F, (colors[i].z & 0xFF) / 255.0F, (colors[i].w & 0xFF) / 255.0F);
/* */ }
/* */ }
/* */
/* */ public void setColors3(float[] colors)
/* */ {
/* 686 */ if (colors == null) {
/* 687 */ this.colors3 = null;
/* 688 */ this.colors4 = null;
/* */ } else {
/* 690 */ this.colors3 = new Color3f[colors.length / 3];
/* 691 */ this.colors4 = null;
/* 692 */ for (int i = 0; i < colors.length / 3; i++)
/* 693 */ this.colors3[i] = new Color3f(colors[(i * 3)], colors[(i * 3 + 1)], colors[(i * 3 + 2)]);
/* */ }
/* */ }
/* */
/* */ public void setColors4(float[] colors)
/* */ {
/* 709 */ if (colors == null) {
/* 710 */ this.colors3 = null;
/* 711 */ this.colors4 = null;
/* */ } else {
/* 713 */ this.colors3 = null;
/* 714 */ this.colors4 = new Color4f[colors.length / 4];
/* 715 */ for (int i = 0; i < colors.length / 4; i++)
/* 716 */ this.colors4[i] = new Color4f(colors[(i * 4)], colors[(i * 4 + 1)], colors[(i * 4 + 2)], colors[(i * 4 + 3)]);
/* */ }
/* */ }
/* */
/* */ public void setColors3(byte[] colors)
/* */ {
/* 733 */ if (colors == null) {
/* 734 */ this.colors3 = null;
/* 735 */ this.colors4 = null;
/* */ } else {
/* 737 */ this.colors3 = new Color3f[colors.length / 3];
/* 738 */ this.colors4 = null;
/* 739 */ for (int i = 0; i < colors.length / 3; i++)
/* 740 */ this.colors3[i] = new Color3f((colors[(i * 3)] & 0xFF) / 255.0F, (colors[(i * 3 + 1)] & 0xFF) / 255.0F, (colors[(i * 3 + 2)] & 0xFF) / 255.0F);
/* */ }
/* */ }
/* */
/* */ public void setColors4(byte[] colors)
/* */ {
/* 757 */ if (colors == null) {
/* 758 */ this.colors3 = null;
/* 759 */ this.colors4 = null;
/* */ } else {
/* 761 */ this.colors3 = null;
/* 762 */ this.colors4 = new Color4f[colors.length / 4];
/* 763 */ for (int i = 0; i < colors.length / 4; i++)
/* 764 */ this.colors4[i] = new Color4f((colors[(i * 4)] & 0xFF) / 255.0F, (colors[(i * 4 + 1)] & 0xFF) / 255.0F, (colors[(i * 4 + 2)] & 0xFF) / 255.0F, (colors[(i * 4 + 3)] & 0xFF) / 255.0F);
/* */ }
/* */ }
/* */
/* */ public Object[] getColors()
/* */ {
/* 783 */ if (this.colors3 != null) return this.colors3;
/* 784 */ return this.colors4;
/* */ }
/* */
/* */ public int getNumColorComponents()
/* */ {
/* 796 */ if (this.colors3 != null) return 3;
/* 797 */ if (this.colors4 != null) return 4;
/* 798 */ return 0;
/* */ }
/* */
/* */ public void setNormals(Vector3f[] normals)
/* */ {
/* 810 */ this.normals = normals;
/* */ }
/* */
/* */ public void setNormals(float[] normals)
/* */ {
/* 821 */ if (normals == null) { this.normals = null;
/* */ } else {
/* 823 */ this.normals = new Vector3f[normals.length / 3];
/* 824 */ for (int i = 0; i < this.normals.length; i++)
/* 825 */ this.normals[i] = new Vector3f(normals[(i * 3)], normals[(i * 3 + 1)], normals[(i * 3 + 2)]);
/* */ }
/* */ }
/* */
/* */ public Vector3f[] getNormals()
/* */ {
/* 839 */ return this.normals;
/* */ }
/* */
/* */ public void setTextureCoordinateParams(int numSets, int dim)
/* */ {
/* 875 */ if (dim == 2)
/* 876 */ this.texCoordSets = new TexCoord2f[numSets][];
/* 877 */ else if (dim == 3)
/* 878 */ this.texCoordSets = new TexCoord3f[numSets][];
/* 879 */ else if (dim == 4)
/* 880 */ this.texCoordSets = new TexCoord4f[numSets][];
/* */ else {
/* 882 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo9"));
/* */ }
/* */
/* 885 */ this.texCoordIndexSets = new int[numSets][];
/* 886 */ this.texCoordDim = dim;
/* 887 */ this.texCoordSetCount = numSets;
/* */ }
/* */
/* */ public int getTexCoordSetCount()
/* */ {
/* 905 */ return this.texCoordSetCount;
/* */ }
/* */
/* */ public int getNumTexCoordComponents()
/* */ {
/* 926 */ return this.texCoordDim;
/* */ }
/* */
/* */ public void setTexCoordSetMap(int[] map)
/* */ {
/* 942 */ this.texCoordSetMap = map;
/* */ }
/* */
/* */ public int[] getTexCoordSetMap()
/* */ {
/* 954 */ return this.texCoordSetMap;
/* */ }
/* */
/* */ public void setTextureCoordinates(int texCoordSet, TexCoord2f[] texCoords)
/* */ {
/* 972 */ if (this.texCoordDim != 2) {
/* 973 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo15"));
/* */ }
/* 975 */ if ((texCoordSet >= this.texCoordSetCount) || (texCoordSet < 0)) {
/* 976 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo18"));
/* */ }
/* */
/* 979 */ this.texCoordSets[texCoordSet] = texCoords;
/* */ }
/* */
/* */ /** @deprecated */
/* */ public void setTextureCoordinates(Point2f[] texCoords)
/* */ {
/* 995 */ this.texCoordSetCount = 1;
/* 996 */ this.texCoordDim = 2;
/* 997 */ this.texCoordSets = new TexCoord2f[1][];
/* 998 */ if (texCoords != null) {
/* 999 */ TexCoord2f[] tex = new TexCoord2f[texCoords.length];
/* 1000 */ for (int i = 0; i < texCoords.length; i++)
/* 1001 */ tex[i] = new TexCoord2f(texCoords[i]);
/* 1002 */ this.texCoordSets[0] = tex;
/* */ }
/* */ }
/* */
/* */ public void setTextureCoordinates(int texCoordSet, TexCoord3f[] texCoords)
/* */ {
/* 1021 */ if (this.texCoordDim != 3) {
/* 1022 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo16"));
/* */ }
/* 1024 */ if ((texCoordSet >= this.texCoordSetCount) || (texCoordSet < 0)) {
/* 1025 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo18"));
/* */ }
/* */
/* 1028 */ this.texCoordSets[texCoordSet] = texCoords;
/* */ }
/* */
/* */ /** @deprecated */
/* */ public void setTextureCoordinates(Point3f[] texCoords)
/* */ {
/* 1044 */ this.texCoordSetCount = 1;
/* 1045 */ this.texCoordDim = 3;
/* 1046 */ this.texCoordSets = new TexCoord3f[1][];
/* 1047 */ if (texCoords != null) {
/* 1048 */ TexCoord3f[] tex = new TexCoord3f[texCoords.length];
/* 1049 */ for (int i = 0; i < texCoords.length; i++)
/* 1050 */ tex[i] = new TexCoord3f(texCoords[i]);
/* 1051 */ this.texCoordSets[0] = tex;
/* */ }
/* */ }
/* */
/* */ public void setTextureCoordinates(int texCoordSet, TexCoord4f[] texCoords)
/* */ {
/* 1069 */ if (this.texCoordDim != 4) {
/* 1070 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo17"));
/* */ }
/* 1072 */ if ((texCoordSet >= this.texCoordSetCount) || (texCoordSet < 0)) {
/* 1073 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo18"));
/* */ }
/* */
/* 1076 */ this.texCoordSets[texCoordSet] = texCoords;
/* */ }
/* */
/* */ public void setTextureCoordinates(int texCoordSet, float[] texCoords)
/* */ {
/* 1097 */ if (texCoords.length % this.texCoordDim != 0) {
/* 1098 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo2"));
/* */ }
/* */
/* 1102 */ if (this.texCoordDim == 2) {
/* 1103 */ TexCoord2f[] tcoords = new TexCoord2f[texCoords.length / 2];
/* 1104 */ for (int i = 0; i < tcoords.length; i++) {
/* 1105 */ tcoords[i] = new TexCoord2f(texCoords[(i * 2)], texCoords[(i * 2 + 1)]);
/* */ }
/* 1107 */ setTextureCoordinates(texCoordSet, tcoords);
/* 1108 */ } else if (this.texCoordDim == 3) {
/* 1109 */ TexCoord3f[] tcoords = new TexCoord3f[texCoords.length / 3];
/* 1110 */ for (int i = 0; i < tcoords.length; i++) {
/* 1111 */ tcoords[i] = new TexCoord3f(texCoords[(i * 3)], texCoords[(i * 3 + 1)], texCoords[(i * 3 + 2)]);
/* */ }
/* */
/* 1114 */ setTextureCoordinates(texCoordSet, tcoords);
/* 1115 */ } else if (this.texCoordDim == 4) {
/* 1116 */ TexCoord4f[] tcoords = new TexCoord4f[texCoords.length / 4];
/* 1117 */ for (int i = 0; i < tcoords.length; i++) {
/* 1118 */ tcoords[i] = new TexCoord4f(texCoords[(i * 4)], texCoords[(i * 4 + 1)], texCoords[(i * 4 + 2)], texCoords[(i * 4 + 3)]);
/* */ }
/* */
/* 1122 */ setTextureCoordinates(texCoordSet, tcoords);
/* */ } else {
/* 1124 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo21"));
/* */ }
/* */ }
/* */
/* */ /** @deprecated */
/* */ public void setTextureCoordinates2(float[] texCoords)
/* */ {
/* 1143 */ this.texCoordSetCount = 1;
/* 1144 */ this.texCoordDim = 2;
/* 1145 */ this.texCoordSets = new TexCoord2f[1][];
/* 1146 */ setTextureCoordinates(0, texCoords);
/* */ }
/* */
/* */ /** @deprecated */
/* */ public void setTextureCoordinates3(float[] texCoords)
/* */ {
/* 1163 */ this.texCoordSetCount = 1;
/* 1164 */ this.texCoordDim = 3;
/* 1165 */ this.texCoordSets = new TexCoord3f[1][];
/* 1166 */ setTextureCoordinates(0, texCoords);
/* */ }
/* */
/* */ public Object[] getTextureCoordinates(int texCoordSet)
/* */ {
/* 1186 */ if ((texCoordSet >= this.texCoordSetCount) || (texCoordSet < 0)) {
/* 1187 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo18"));
/* */ }
/* 1189 */ return this.texCoordSets[texCoordSet];
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Object[] getTextureCoordinates()
/* */ {
/* 1207 */ return this.texCoordSets[0];
/* */ }
/* */
/* */ public void setCoordinateIndices(int[] coordinateIndices)
/* */ {
/* 1218 */ this.coordinateIndices = coordinateIndices;
/* */ }
/* */
/* */ public int[] getCoordinateIndices()
/* */ {
/* 1250 */ return this.coordinateIndices;
/* */ }
/* */
/* */ public void setColorIndices(int[] colorIndices)
/* */ {
/* 1261 */ this.colorIndices = colorIndices;
/* */ }
/* */
/* */ public int[] getColorIndices()
/* */ {
/* 1293 */ return this.colorIndices;
/* */ }
/* */
/* */ public void setNormalIndices(int[] normalIndices)
/* */ {
/* 1304 */ this.normalIndices = normalIndices;
/* */ }
/* */
/* */ public int[] getNormalIndices()
/* */ {
/* 1337 */ return this.normalIndices;
/* */ }
/* */
/* */ public void setTextureCoordinateIndices(int texCoordSet, int[] texIndices)
/* */ {
/* 1354 */ if ((texCoordSet >= this.texCoordSetCount) || (texCoordSet < 0)) {
/* 1355 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo18"));
/* */ }
/* */
/* 1359 */ this.texCoordIndexSets[texCoordSet] = texIndices;
/* */ }
/* */
/* */ /** @deprecated */
/* */ public void setTextureCoordinateIndices(int[] texIndices)
/* */ {
/* 1375 */ if (this.texCoordSetCount > 1) {
/* 1376 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo1"));
/* */ }
/* 1378 */ this.texCoordIndexSets = new int[1][];
/* 1379 */ this.texCoordIndexSets[0] = texIndices;
/* */ }
/* */
/* */ public int[] getTextureCoordinateIndices(int texCoordSet)
/* */ {
/* 1414 */ return this.texCoordIndexSets[texCoordSet];
/* */ }
/* */
/* */ /** @deprecated */
/* */ public int[] getTextureCoordinateIndices()
/* */ {
/* 1428 */ if (this.texCoordIndexSets == null) return null;
/* 1429 */ return this.texCoordIndexSets[0];
/* */ }
/* */
/* */ public void setStripCounts(int[] stripCounts)
/* */ {
/* 1447 */ this.stripCounts = stripCounts;
/* */ }
/* */
/* */ public int[] getStripCounts()
/* */ {
/* 1478 */ return this.stripCounts;
/* */ }
/* */
/* */ public void setContourCounts(int[] contourCounts)
/* */ {
/* 1493 */ this.contourCounts = contourCounts;
/* */ }
/* */
/* */ public int[] getContourCounts()
/* */ {
/* 1503 */ return this.contourCounts;
/* */ }
/* */
/* */ int[] getListIndices(Object[] list)
/* */ {
/* 1514 */ int[] indices = new int[list.length];
/* */
/* 1518 */ HashMap table = new HashMap(list.length);
/* */
/* 1521 */ for (int i = 0; i < list.length; i++)
/* */ {
/* 1524 */ Integer idx = (Integer)table.get(list[i]);
/* */
/* 1526 */ if (idx == null)
/* */ {
/* 1528 */ indices[i] = i;
/* */
/* 1531 */ table.put(list[i], new Integer(i));
/* */ }
/* */ else
/* */ {
/* 1535 */ indices[i] = idx.intValue();
/* */ }
/* */ }
/* */
/* 1539 */ return indices;
/* */ }
/* */
/* */ public void indexify(boolean useCoordIndexOnly)
/* */ {
/* 1609 */ checkForBadData();
/* */
/* 1611 */ if (useCoordIndexOnly)
/* */ {
/* 1613 */ if (this.coordOnly) return;
/* */
/* 1616 */ indexify(false);
/* */
/* 1623 */ int numLists = 1;
/* 1624 */ if (this.colorIndices != null) numLists++;
/* 1625 */ if (this.normalIndices != null) numLists++;
/* 1626 */ numLists += this.texCoordSetCount;
/* */
/* 1629 */ int n = this.coordinateIndices.length;
/* 1630 */ IndexRow[] ir = new IndexRow[n];
/* */
/* 1632 */ for (int i = 0; i < n; i++) {
/* 1633 */ ir[i] = new IndexRow(numLists);
/* 1634 */ int j = 0;
/* 1635 */ ir[i].set(j++, this.coordinateIndices[i]);
/* 1636 */ if (this.colorIndices != null) ir[i].set(j++, this.colorIndices[i]);
/* 1637 */ if (this.normalIndices != null) ir[i].set(j++, this.normalIndices[i]);
/* 1638 */ for (int k = 0; k < this.texCoordSetCount; k++) {
/* 1639 */ ir[i].set(j++, this.texCoordIndexSets[k][i]);
/* */ }
/* */
/* */ }
/* */
/* 1644 */ int[] coordOnlyIndices = getListIndices(ir);
/* */
/* 1647 */ int[] newInd = new int[coordOnlyIndices.length];
/* 1648 */ ir = (IndexRow[])compactData(coordOnlyIndices, ir, newInd);
/* 1649 */ coordOnlyIndices = newInd;
/* */
/* 1654 */ Point3f[] newCoords = new Point3f[ir.length];
/* 1655 */ Color3f[] newColors3 = null;
/* 1656 */ Color4f[] newColors4 = null;
/* 1657 */ Vector3f[] newNormals = null;
/* 1658 */ Object[][] newTexCoordSets = (Object[][])null;
/* 1659 */ if (this.colors3 != null) newColors3 = new Color3f[ir.length];
/* 1660 */ else if (this.colors4 != null) newColors4 = new Color4f[ir.length];
/* 1661 */ if (this.normals != null) newNormals = new Vector3f[ir.length];
/* 1662 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1663 */ if (this.texCoordDim == 2) {
/* 1664 */ if (i == 0) newTexCoordSets = new TexCoord2f[this.texCoordSetCount][];
/* 1665 */ newTexCoordSets[i] = new TexCoord2f[ir.length];
/* 1666 */ } else if (this.texCoordDim == 3) {
/* 1667 */ if (i == 0) newTexCoordSets = new TexCoord3f[this.texCoordSetCount][];
/* 1668 */ newTexCoordSets[i] = new TexCoord3f[ir.length];
/* 1669 */ } else if (this.texCoordDim == 4) {
/* 1670 */ if (i == 0) newTexCoordSets = new TexCoord4f[this.texCoordSetCount][];
/* 1671 */ newTexCoordSets[i] = new TexCoord4f[ir.length];
/* */ }
/* */
/* */ }
/* */
/* 1676 */ n = ir.length;
/* 1677 */ for (int i = 0; i < n; i++) {
/* 1678 */ int j = 0;
/* 1679 */ newCoords[i] = this.coordinates[ir[i].get(j++)];
/* 1680 */ if (this.colors3 != null)
/* 1681 */ newColors3[i] = this.colors3[ir[i].get(j++)];
/* 1682 */ else if (this.colors4 != null) {
/* 1683 */ newColors4[i] = this.colors4[ir[i].get(j++)];
/* */ }
/* 1685 */ if (this.normals != null) newNormals[i] = this.normals[ir[i].get(j++)];
/* 1686 */ for (int k = 0; k < this.texCoordSetCount; k++) {
/* 1687 */ newTexCoordSets[k][i] = this.texCoordSets[k][ir[i].get(j++)];
/* */ }
/* */
/* */ }
/* */
/* 1692 */ this.coordinates = newCoords;
/* 1693 */ this.colors3 = newColors3;
/* 1694 */ this.colors4 = newColors4;
/* 1695 */ this.normals = newNormals;
/* 1696 */ this.texCoordSets = newTexCoordSets;
/* 1697 */ this.coordinateIndices = coordOnlyIndices;
/* 1698 */ this.colorIndices = null;
/* 1699 */ this.normalIndices = null;
/* 1700 */ this.texCoordIndexSets = new int[this.texCoordSetCount][];
/* */
/* 1702 */ this.coordOnly = true;
/* 1703 */ } else if (this.coordOnly)
/* */ {
/* 1708 */ int n = this.coordinateIndices.length;
/* 1709 */ if ((this.colors3 != null) || (this.colors4 != null)) {
/* 1710 */ this.colorIndices = new int[n];
/* 1711 */ for (int i = 0; i < n; i++) this.colorIndices[i] = this.coordinateIndices[i];
/* */ }
/* 1713 */ if (this.normals != null) {
/* 1714 */ this.normalIndices = new int[n];
/* 1715 */ for (int i = 0; i < n; i++) this.normalIndices[i] = this.coordinateIndices[i];
/* */ }
/* 1717 */ this.texCoordIndexSets = new int[this.texCoordSetCount][];
/* 1718 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1719 */ this.texCoordIndexSets[i] = new int[n];
/* 1720 */ for (int j = 0; j < n; j++) {
/* 1721 */ this.texCoordIndexSets[i][j] = this.coordinateIndices[j];
/* */ }
/* */ }
/* 1724 */ this.coordOnly = false;
/* */ }
/* */ else
/* */ {
/* 1728 */ if (this.coordinateIndices != null) return;
/* */
/* 1730 */ this.coordinateIndices = getListIndices(this.coordinates);
/* */
/* 1732 */ if (this.colors3 != null) this.colorIndices = getListIndices(this.colors3);
/* 1733 */ else if (this.colors4 != null) this.colorIndices = getListIndices(this.colors4);
/* */
/* 1735 */ if (this.normals != null) this.normalIndices = getListIndices(this.normals);
/* */
/* 1737 */ this.texCoordIndexSets = new int[this.texCoordSetCount][];
/* 1738 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1739 */ this.texCoordIndexSets[i] = getListIndices(this.texCoordSets[i]);
/* */ }
/* */
/* 1742 */ this.coordOnly = false;
/* */ }
/* */ }
/* */
/* */ public void indexify()
/* */ {
/* 1763 */ indexify(false);
/* */ }
/* */
/* */ Object[] allocateArray(Object[] data, int num)
/* */ {
/* 1784 */ Object[] newData = null;
/* 1785 */ if ((data instanceof Point3f[]))
/* 1786 */ newData = new Point3f[num];
/* 1787 */ else if ((data instanceof Vector3f[]))
/* 1788 */ newData = new Vector3f[num];
/* 1789 */ else if ((data instanceof Color3f[]))
/* 1790 */ newData = new Color3f[num];
/* 1791 */ else if ((data instanceof Color4f[]))
/* 1792 */ newData = new Color4f[num];
/* 1793 */ else if ((data instanceof TexCoord2f[]))
/* 1794 */ newData = new TexCoord2f[num];
/* 1795 */ else if ((data instanceof TexCoord3f[]))
/* 1796 */ newData = new TexCoord3f[num];
/* 1797 */ else if ((data instanceof TexCoord4f[]))
/* 1798 */ newData = new TexCoord4f[num];
/* 1799 */ else if ((data instanceof IndexRow[]))
/* */ {
/* 1801 */ newData = new IndexRow[num];
/* */ } else throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo9"));
/* */
/* 1804 */ return newData;
/* */ }
/* */
/* */ private Object[] compactData(int[] indices, Object[] data, int[] newInd)
/* */ {
/* 1826 */ Object[] newData = null;
/* */
/* 1832 */ int numUnique = 0;
/* 1833 */ int[] translationTable = new int[data.length];
/* 1834 */ for (int i = 0; i < indices.length; i++) {
/* 1835 */ if (translationTable[indices[i]] == 0)
/* */ {
/* 1837 */ numUnique++;
/* 1838 */ translationTable[indices[i]] = 1;
/* */ }
/* */
/* */ }
/* */
/* 1845 */ newData = allocateArray(data, numUnique);
/* 1846 */ int newIdx = 0;
/* 1847 */ for (int i = 0; i < translationTable.length; i++) {
/* 1848 */ if (translationTable[i] != 0) {
/* 1849 */ newData[newIdx] = data[i];
/* 1850 */ translationTable[i] = (newIdx++);
/* */ }
/* */
/* */ }
/* */
/* 1856 */ for (int i = 0; i < indices.length; i++) {
/* 1857 */ newInd[i] = translationTable[indices[i]];
/* */ }
/* 1859 */ return newData;
/* */ }
/* */
/* */ public void compact()
/* */ {
/* 1882 */ checkForBadData();
/* */
/* 1885 */ if (this.coordinateIndices == null) return;
/* */
/* 1888 */ if (this.coordOnly) return;
/* */
/* 1890 */ int[] newInd = new int[this.coordinateIndices.length];
/* 1891 */ this.coordinates = ((Point3f[])compactData(this.coordinateIndices, this.coordinates, newInd));
/* */
/* 1893 */ this.coordinateIndices = newInd;
/* */
/* 1895 */ if (this.colorIndices != null) {
/* 1896 */ newInd = new int[this.colorIndices.length];
/* 1897 */ if (this.colors3 != null)
/* 1898 */ this.colors3 = ((Color3f[])compactData(this.colorIndices, this.colors3, newInd));
/* 1899 */ else if (this.colors4 != null)
/* 1900 */ this.colors4 = ((Color4f[])compactData(this.colorIndices, this.colors4, newInd));
/* 1901 */ this.colorIndices = newInd;
/* */ }
/* */
/* 1904 */ if (this.normalIndices != null) {
/* 1905 */ newInd = new int[this.normalIndices.length];
/* 1906 */ this.normals = ((Vector3f[])compactData(this.normalIndices, this.normals, newInd));
/* 1907 */ this.normalIndices = newInd;
/* */ }
/* */
/* 1910 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1911 */ newInd = new int[this.texCoordIndexSets[i].length];
/* 1912 */ this.texCoordSets[i] = compactData(this.texCoordIndexSets[i], this.texCoordSets[i], newInd);
/* */
/* 1914 */ this.texCoordIndexSets[i] = newInd;
/* */ }
/* */ }
/* */
/* */ private void checkForBadData()
/* */ {
/* 1924 */ boolean badData = false;
/* */
/* 1929 */ if (this.coordinates == null) {
/* 1930 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo3"));
/* */ }
/* */
/* 1937 */ if ((this.colors3 == null) && (this.colors4 == null) && (this.colorIndices != null)) {
/* 1938 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo4"));
/* */ }
/* 1940 */ if ((this.normals == null) && (this.normalIndices != null)) {
/* 1941 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo11"));
/* */ }
/* */
/* 1947 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1948 */ if (this.texCoordSets[i] == null) {
/* 1949 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo10"));
/* */ }
/* */
/* */ }
/* */
/* 1956 */ boolean texInds = false;
/* 1957 */ if (this.texCoordIndexSets != null) {
/* 1958 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1959 */ if (this.texCoordIndexSets[i] != null) texInds = true;
/* */ }
/* */ }
/* 1962 */ if ((this.coordinateIndices != null) || (this.colorIndices != null) || (this.normalIndices != null) || (texInds))
/* */ {
/* 1968 */ if (this.coordinateIndices == null) badData = true;
/* 1969 */ else if (this.coordOnly) {
/* 1970 */ if ((this.colorIndices != null) || (this.normalIndices != null) || (texInds == true))
/* */ {
/* 1973 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo20"));
/* */ }
/* */ }
/* 1976 */ else if (((this.colors3 != null) || (this.colors4 != null)) && (this.colorIndices == null))
/* 1977 */ badData = true;
/* 1978 */ else if ((this.normals != null) && (this.normalIndices == null)) badData = true;
/* 1979 */ else if ((this.texCoordSetCount > 0) && (!texInds)) badData = true;
/* 1980 */ if (badData) throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo19"));
/* */
/* */ }
/* */
/* 1987 */ if ((this.coordinateIndices != null) && (!this.coordOnly)) {
/* 1988 */ if (((this.colors3 != null) || (this.colors4 != null)) && (this.colorIndices.length != this.coordinateIndices.length))
/* */ {
/* 1990 */ badData = true;
/* 1991 */ } else if ((this.normals != null) && (this.normalIndices.length != this.coordinateIndices.length))
/* */ {
/* 1993 */ badData = true;
/* */ }
/* */ else {
/* 1996 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 1997 */ if (this.texCoordIndexSets[i].length != this.coordinateIndices.length) {
/* 1998 */ badData = true;
/* 1999 */ break;
/* */ }
/* */ }
/* */ }
/* 2003 */ if (badData) {
/* 2004 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo5"));
/* */ }
/* */
/* */ }
/* */
/* 2012 */ if ((this.prim == 4) || (this.prim == 3) || (this.prim == 5))
/* */ {
/* 2015 */ if (this.stripCounts == null) badData = true;
/* */ }
/* 2016 */ else if (this.stripCounts != null) badData = true;
/* 2017 */ if (badData)
/* 2018 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo6"));
/* 2024 */ int count;
/* */ int count;
/* 2024 */ if (this.coordinateIndices == null) count = this.coordinates.length; else {
/* 2025 */ count = this.coordinateIndices.length;
/* */ }
/* */
/* 2032 */ if ((this.prim == 4) || (this.prim == 3) || (this.prim == 5))
/* */ {
/* 2035 */ int sum = 0;
/* 2036 */ for (int i = 0; i < this.stripCounts.length; i++) {
/* 2037 */ sum += this.stripCounts[i];
/* */ }
/* 2039 */ if (sum != count) {
/* 2040 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo7"));
/* */ }
/* */ }
/* 2043 */ else if (this.prim == 1) {
/* 2044 */ if (count % 3 != 0) {
/* 2045 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo12"));
/* */ }
/* */ }
/* 2048 */ else if ((this.prim == 2) &&
/* 2049 */ (count % 4 != 0)) {
/* 2050 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo13"));
/* */ }
/* */
/* 2058 */ if (this.prim == 5) {
/* 2059 */ if (this.contourCounts != null) {
/* 2060 */ int c = 0;
/* 2061 */ for (int i = 0; i < this.contourCounts.length; i++)
/* 2062 */ c += this.contourCounts[i];
/* 2063 */ if (c != this.stripCounts.length) {
/* 2064 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo8"));
/* */ }
/* */ }
/* */
/* */ }
/* 2069 */ else if (this.contourCounts != null)
/* 2070 */ throw new IllegalArgumentException(J3dUtilsI18N.getString("GeometryInfo14"));
/* */ }
/* */
/* */ public void unindexify()
/* */ {
/* 2093 */ checkForBadData();
/* 2094 */ if (this.coordinateIndices != null)
/* */ {
/* 2096 */ if (this.coordOnly) indexify(false);
/* */
/* 2098 */ this.coordinates = ((Point3f[])unindexifyData(this.coordinates, this.coordinateIndices));
/* */
/* 2100 */ this.coordinateIndices = null;
/* */
/* 2102 */ if (this.colors3 != null)
/* 2103 */ this.colors3 = ((Color3f[])unindexifyData(this.colors3, this.colorIndices));
/* 2104 */ else if (this.colors4 != null) {
/* 2105 */ this.colors4 = ((Color4f[])unindexifyData(this.colors4, this.colorIndices));
/* */ }
/* 2107 */ this.colorIndices = null;
/* */
/* 2109 */ if (this.normals != null) {
/* 2110 */ this.normals = ((Vector3f[])unindexifyData(this.normals, this.normalIndices));
/* 2111 */ this.normalIndices = null;
/* */ }
/* */
/* 2114 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 2115 */ this.texCoordSets[i] = unindexifyData(this.texCoordSets[i], this.texCoordIndexSets[i]);
/* */ }
/* 2117 */ this.texCoordIndexSets = new int[this.texCoordSetCount][];
/* */ }
/* */ }
/* */
/* */ private Object[] unindexifyData(Object[] data, int[] index)
/* */ {
/* 2130 */ Object[] newData = allocateArray(data, index.length);
/* 2131 */ for (int i = 0; i < index.length; i++) {
/* 2132 */ newData[i] = data[index[i]];
/* */ }
/* 2134 */ return newData;
/* */ }
/* */
/* */ private int getVertexFormat()
/* */ {
/* 2144 */ int vertexFormat = 1;
/* */
/* 2146 */ if (this.colors3 != null) vertexFormat |= 4;
/* 2147 */ else if (this.colors4 != null) vertexFormat |= 12;
/* */
/* 2149 */ if (this.normals != null) vertexFormat |= 2;
/* */
/* 2151 */ if (this.texCoordDim == 2)
/* 2152 */ vertexFormat |= 32;
/* 2153 */ else if (this.texCoordDim == 3)
/* 2154 */ vertexFormat |= 64;
/* 2155 */ else if (this.texCoordDim == 4) {
/* 2156 */ vertexFormat |= 1024;
/* */ }
/* 2158 */ return vertexFormat;
/* */ }
/* */
/* */ private int getVertexCount()
/* */ {
/* 2168 */ int vertexCount = this.coordinates.length;
/* */
/* 2170 */ if (this.colors3 != null) {
/* 2171 */ if (this.colors3.length > vertexCount) vertexCount = this.colors3.length;
/* */ }
/* 2172 */ else if ((this.colors4 != null) &&
/* 2173 */ (this.colors4.length > vertexCount)) vertexCount = this.colors4.length;
/* */
/* 2176 */ if ((this.normals != null) &&
/* 2177 */ (this.normals.length > vertexCount)) vertexCount = this.normals.length;
/* */
/* 2181 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 2182 */ if (this.texCoordSets[i].length > vertexCount) {
/* 2183 */ vertexCount = this.texCoordSets[i].length;
/* */ }
/* */ }
/* 2186 */ return vertexCount;
/* */ }
/* */
/* */ private float[] vecmathToFloat(Object[] ar)
/* */ {
/* 2199 */ if ((ar[0] instanceof Tuple2f)) {
/* 2200 */ float[] p = new float[ar.length * 2];
/* 2201 */ Tuple2f[] a = (Tuple2f[])ar;
/* 2202 */ for (int i = 0; i < ar.length; i++) {
/* 2203 */ p[(i * 2)] = a[i].x;
/* 2204 */ p[(i * 2 + 1)] = a[i].y;
/* */ }
/* 2206 */ return p;
/* 2207 */ }if ((ar[0] instanceof Tuple3f)) {
/* 2208 */ float[] p = new float[ar.length * 3];
/* 2209 */ Tuple3f[] a = (Tuple3f[])ar;
/* 2210 */ for (int i = 0; i < ar.length; i++) {
/* 2211 */ p[(i * 3)] = a[i].x;
/* 2212 */ p[(i * 3 + 1)] = a[i].y;
/* 2213 */ p[(i * 3 + 2)] = a[i].z;
/* */ }
/* 2215 */ return p;
/* 2216 */ }if ((ar[0] instanceof Tuple4f)) {
/* 2217 */ float[] p = new float[ar.length * 4];
/* 2218 */ Tuple4f[] a = (Tuple4f[])ar;
/* 2219 */ for (int i = 0; i < ar.length; i++) {
/* 2220 */ p[(i * 4)] = a[i].x;
/* 2221 */ p[(i * 4 + 1)] = a[i].y;
/* 2222 */ p[(i * 4 + 2)] = a[i].z;
/* 2223 */ p[(i * 4 + 3)] = a[i].w;
/* */ }
/* 2225 */ return p;
/* */ }
/* 2227 */ return null;
/* */ }
/* */
/* */ private void fillIn(GeometryArray ga, boolean byRef, boolean interleaved, boolean nio)
/* */ {
/* 2239 */ if (interleaved)
/* */ {
/* 2241 */ int wpv = 3;
/* 2242 */ if (this.normals != null) wpv += 3;
/* 2243 */ if (this.colors3 != null) wpv += 3;
/* 2244 */ else if (this.colors4 != null) wpv += 4;
/* 2245 */ wpv += this.texCoordSetCount * this.texCoordDim;
/* */
/* 2248 */ float[] d = new float[wpv * this.coordinates.length];
/* */
/* 2251 */ int offset = 0;
/* 2252 */ for (int i = 0; i < this.coordinates.length; i++) {
/* 2253 */ if (this.texCoordDim == 2)
/* 2254 */ for (int j = 0; j < this.texCoordSetCount; j++) {
/* 2255 */ d[(offset++)] = ((TexCoord2f)this.texCoordSets[j][i]).x;
/* 2256 */ d[(offset++)] = ((TexCoord2f)this.texCoordSets[j][i]).y;
/* */ }
/* 2258 */ else if (this.texCoordDim == 3)
/* 2259 */ for (int j = 0; j < this.texCoordSetCount; j++) {
/* 2260 */ d[(offset++)] = ((TexCoord3f)this.texCoordSets[j][i]).x;
/* 2261 */ d[(offset++)] = ((TexCoord3f)this.texCoordSets[j][i]).y;
/* 2262 */ d[(offset++)] = ((TexCoord3f)this.texCoordSets[j][i]).z;
/* */ }
/* 2264 */ else if (this.texCoordDim == 4) {
/* 2265 */ for (int j = 0; j < this.texCoordSetCount; j++) {
/* 2266 */ d[(offset++)] = ((TexCoord4f)this.texCoordSets[j][i]).x;
/* 2267 */ d[(offset++)] = ((TexCoord4f)this.texCoordSets[j][i]).y;
/* 2268 */ d[(offset++)] = ((TexCoord4f)this.texCoordSets[j][i]).z;
/* 2269 */ d[(offset++)] = ((TexCoord4f)this.texCoordSets[j][i]).w;
/* */ }
/* */ }
/* */
/* 2273 */ if (this.colors3 != null) {
/* 2274 */ d[(offset++)] = this.colors3[i].x;
/* 2275 */ d[(offset++)] = this.colors3[i].y;
/* 2276 */ d[(offset++)] = this.colors3[i].z;
/* 2277 */ } else if (this.colors4 != null) {
/* 2278 */ d[(offset++)] = this.colors4[i].x;
/* 2279 */ d[(offset++)] = this.colors4[i].y;
/* 2280 */ d[(offset++)] = this.colors4[i].z;
/* 2281 */ d[(offset++)] = this.colors4[i].w;
/* */ }
/* */
/* 2284 */ if (this.normals != null) {
/* 2285 */ d[(offset++)] = this.normals[i].x;
/* 2286 */ d[(offset++)] = this.normals[i].y;
/* 2287 */ d[(offset++)] = this.normals[i].z;
/* */ }
/* */
/* 2290 */ d[(offset++)] = this.coordinates[i].x;
/* 2291 */ d[(offset++)] = this.coordinates[i].y;
/* 2292 */ d[(offset++)] = this.coordinates[i].z;
/* */ }
/* */
/* 2295 */ if (nio) {
/* 2296 */ ByteBufferWrapper b = ByteBufferWrapper.allocateDirect(d.length * 4);
/* 2297 */ FloatBufferWrapper f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* */
/* 2299 */ f.put(d);
/* 2300 */ ga.setInterleavedVertexBuffer(f.getJ3DBuffer()); } else {
/* 2301 */ ga.setInterleavedVertices(d);
/* */ } } else if (nio)
/* */ {
/* 2304 */ ByteBufferWrapper b = ByteBufferWrapper.allocateDirect(this.coordinates.length * 4 * 3);
/* */
/* 2306 */ FloatBufferWrapper f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* */
/* 2308 */ f.put(vecmathToFloat(this.coordinates));
/* 2309 */ ga.setCoordRefBuffer(f.getJ3DBuffer());
/* */
/* 2311 */ if (this.colors3 != null) {
/* 2312 */ b = ByteBufferWrapper.allocateDirect(this.colors3.length * 4 * 3);
/* 2313 */ f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* 2314 */ f.put(vecmathToFloat(this.colors3));
/* 2315 */ ga.setColorRefBuffer(f.getJ3DBuffer());
/* 2316 */ } else if (this.colors4 != null) {
/* 2317 */ b = ByteBufferWrapper.allocateDirect(this.colors4.length * 4 * 4);
/* 2318 */ f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* 2319 */ f.put(vecmathToFloat(this.colors4));
/* 2320 */ ga.setColorRefBuffer(f.getJ3DBuffer());
/* */ }
/* */
/* 2323 */ if (this.normals != null) {
/* 2324 */ b = ByteBufferWrapper.allocateDirect(this.normals.length * 4 * 3);
/* 2325 */ f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* 2326 */ f.put(vecmathToFloat(this.normals));
/* 2327 */ ga.setNormalRefBuffer(f.getJ3DBuffer());
/* */ }
/* */
/* 2330 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 2331 */ b = ByteBufferWrapper.allocateDirect(this.texCoordSets[i].length * 4 * this.texCoordDim);
/* */
/* 2333 */ f = b.order(ByteOrderWrapper.nativeOrder()).asFloatBuffer();
/* 2334 */ f.put(vecmathToFloat(this.texCoordSets[i]));
/* 2335 */ ga.setTexCoordRefBuffer(i, f.getJ3DBuffer());
/* */ }
/* 2337 */ } else if (byRef)
/* */ {
/* 2340 */ ga.setCoordRefFloat(vecmathToFloat(this.coordinates));
/* 2341 */ if (this.colors3 != null) ga.setColorRefFloat(vecmathToFloat(this.colors3));
/* 2342 */ else if (this.colors4 != null) ga.setColorRefFloat(vecmathToFloat(this.colors4));
/* 2343 */ if (this.normals != null) ga.setNormalRefFloat(vecmathToFloat(this.normals));
/* 2344 */ for (int i = 0; i < this.texCoordSetCount; i++)
/* 2345 */ ga.setTexCoordRefFloat(i, vecmathToFloat(this.texCoordSets[i]));
/* */ }
/* */ else {
/* 2348 */ ga.setCoordinates(0, this.coordinates);
/* 2349 */ if (this.colors3 != null) ga.setColors(0, this.colors3);
/* 2350 */ else if (this.colors4 != null) ga.setColors(0, this.colors4);
/* 2351 */ if (this.normals != null) ga.setNormals(0, this.normals);
/* 2352 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 2353 */ if (this.texCoordDim == 2)
/* 2354 */ ga.setTextureCoordinates(i, 0, (TexCoord2f[])this.texCoordSets[i]);
/* 2355 */ else if (this.texCoordDim == 3)
/* 2356 */ ga.setTextureCoordinates(i, 0, (TexCoord3f[])this.texCoordSets[i]);
/* 2357 */ else if (this.texCoordDim == 4) {
/* 2358 */ ga.setTextureCoordinates(i, 0, (TexCoord4f[])this.texCoordSets[i]);
/* */ }
/* */ }
/* */ }
/* */
/* 2363 */ if (this.coordinateIndices != null) {
/* 2364 */ IndexedGeometryArray iga = null;
/* 2365 */ iga = (IndexedGeometryArray)ga;
/* 2366 */ iga.setCoordinateIndices(0, this.coordinateIndices);
/* 2367 */ if (!this.coordOnly) {
/* 2368 */ if (this.colorIndices != null) iga.setColorIndices(0, this.colorIndices);
/* 2369 */ if (this.normalIndices != null) iga.setNormalIndices(0, this.normalIndices);
/* 2370 */ for (int i = 0; i < this.texCoordSetCount; i++)
/* 2371 */ iga.setTextureCoordinateIndices(i, 0, this.texCoordIndexSets[i]);
/* */ }
/* */ }
/* */ }
/* */
/* */ public void recomputeIndices()
/* */ {
/* 2401 */ boolean remember = this.coordOnly;
/* */
/* 2404 */ unindexify();
/* 2405 */ indexify(remember);
/* */ }
/* */
/* */ private void reverseList(int[] list)
/* */ {
/* 2418 */ if (list == null) return;
/* */
/* 2420 */ for (int i = 0; i < list.length / 2; i++) {
/* 2421 */ int t = list[i];
/* 2422 */ list[i] = list[(list.length - i - 1)];
/* 2423 */ list[(list.length - i - 1)] = t;
/* */ }
/* */ }
/* */
/* */ public void reverse()
/* */ {
/* 2450 */ indexify();
/* 2451 */ reverseList(this.stripCounts);
/* 2452 */ reverseList(this.oldStripCounts);
/* 2453 */ reverseList(this.contourCounts);
/* 2454 */ reverseList(this.coordinateIndices);
/* 2455 */ reverseList(this.colorIndices);
/* 2456 */ reverseList(this.normalIndices);
/* 2457 */ for (int i = 0; i < this.texCoordSetCount; i++)
/* 2458 */ reverseList(this.texCoordIndexSets[i]);
/* */ }
/* */
/* */ public boolean getUseCoordIndexOnly()
/* */ {
/* 2473 */ return this.coordOnly;
/* */ }
/* */
/* */ public void setUseCoordIndexOnly(boolean useCoordIndexOnly)
/* */ {
/* 2498 */ this.coordOnly = useCoordIndexOnly;
/* */ }
/* */
/* */ public GeometryArray getGeometryArray(boolean byRef, boolean interleaved, boolean nio)
/* */ {
/* 2527 */ checkForBadData();
/* */
/* 2529 */ if (this.prim == 5) {
/* 2530 */ if (this.tr == null) this.tr = new Triangulator();
/* 2531 */ this.tr.triangulate(this); } else {
/* 2532 */ changeBackToOldPrim();
/* */ }
/* 2534 */ unindexify();
/* */
/* 2536 */ int vertexFormat = getVertexFormat();
/* 2537 */ if (nio) vertexFormat |= 2176;
/* */
/* 2539 */ if (interleaved) vertexFormat |= 384;
/* */
/* 2541 */ if (byRef) vertexFormat |= 128;
/* */
/* 2543 */ int vertexCount = this.coordinates.length;
/* */
/* 2547 */ if ((this.texCoordSetCount > 0) && (this.texCoordSetMap == null)) {
/* 2548 */ this.texCoordSetCount = 1;
/* 2549 */ this.texCoordSetMap = new int[1];
/* 2550 */ this.texCoordSetMap[0] = 0;
/* */ }
/* */
/* 2554 */ GeometryArray ga = null;
/* 2555 */ switch (this.prim) {
/* */ case 1:
/* 2557 */ TriangleArray ta = new TriangleArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap);
/* */
/* 2559 */ ga = ta;
/* 2560 */ break;
/* */ case 2:
/* 2563 */ QuadArray qa = new QuadArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap);
/* */
/* 2565 */ ga = qa;
/* 2566 */ break;
/* */ case 4:
/* 2569 */ TriangleStripArray tsa = new TriangleStripArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.stripCounts);
/* */
/* 2572 */ ga = tsa;
/* 2573 */ break;
/* */ case 3:
/* 2576 */ TriangleFanArray tfa = new TriangleFanArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.stripCounts);
/* */
/* 2579 */ ga = tfa;
/* */ }
/* */
/* 2583 */ fillIn(ga, byRef, interleaved, nio);
/* */
/* 2585 */ return ga;
/* */ }
/* */
/* */ public GeometryArray getGeometryArray()
/* */ {
/* 2609 */ return getGeometryArray(false, false, false);
/* */ }
/* */
/* */ public IndexedGeometryArray getIndexedGeometryArray(boolean compact, boolean byRef, boolean interleaved, boolean useCoordIndexOnly, boolean nio)
/* */ {
/* 2648 */ indexify(useCoordIndexOnly);
/* */
/* 2650 */ if (compact) compact();
/* */
/* 2652 */ if (this.prim == 5) {
/* 2653 */ if (this.tr == null) this.tr = new Triangulator();
/* 2654 */ this.tr.triangulate(this); } else {
/* 2655 */ changeBackToOldPrim();
/* */ }
/* 2657 */ if ((useCoordIndexOnly) && (!this.coordOnly))
/* */ {
/* 2660 */ boolean canUseCoordIndexOnly = true;
/* */
/* 2662 */ if (this.coordinateIndices != null)
/* */ {
/* 2664 */ if ((this.colorIndices != null) && (this.colorIndices.length != this.coordinateIndices.length))
/* */ {
/* 2666 */ canUseCoordIndexOnly = false;
/* */ }
/* 2668 */ if ((this.normalIndices != null) && (this.normalIndices.length != this.coordinateIndices.length))
/* */ {
/* 2670 */ canUseCoordIndexOnly = false;
/* */ }
/* 2672 */ for (int i = 0; i < this.texCoordSetCount; i++) {
/* 2673 */ if ((this.texCoordIndexSets[i] != null) && (this.texCoordIndexSets[i].length != this.coordinateIndices.length))
/* */ {
/* 2675 */ canUseCoordIndexOnly = false;
/* 2676 */ break;
/* */ }
/* */ }
/* 2679 */ if ((canUseCoordIndexOnly) && ((this.colorIndices != null) || (this.normalIndices != null) || (this.texCoordSetCount > 0)))
/* */ {
/* 2685 */ for (i = 0; i < this.coordinateIndices.length; i++) {
/* 2686 */ int indexValue = this.coordinateIndices[i];
/* */
/* 2689 */ if ((this.colorIndices != null) && (this.colorIndices[i] != indexValue))
/* */ {
/* 2691 */ canUseCoordIndexOnly = false;
/* 2692 */ break;
/* */ }
/* 2694 */ if ((this.normalIndices != null) && (this.normalIndices[i] != indexValue))
/* */ {
/* 2696 */ canUseCoordIndexOnly = false;
/* 2697 */ break;
/* */ }
/* 2699 */ for (int j = 0; j < this.texCoordSetCount; j++) {
/* 2700 */ if ((this.texCoordIndexSets[j] != null) && (this.texCoordIndexSets[j][i] != indexValue))
/* */ {
/* 2702 */ canUseCoordIndexOnly = false;
/* 2703 */ break;
/* */ }
/* */ }
/* */ }
/* */ }
/* */ }
/* 2709 */ this.coordOnly = canUseCoordIndexOnly;
/* */ }
/* */
/* 2712 */ int vertexFormat = getVertexFormat();
/* 2713 */ if (nio) vertexFormat |= 2176;
/* */
/* 2715 */ if (interleaved) vertexFormat |= 384;
/* */
/* 2717 */ if (byRef) vertexFormat |= 128;
/* 2718 */ if (this.coordOnly) vertexFormat |= 512;
/* */
/* 2720 */ int vertexCount = getVertexCount();
/* */
/* 2722 */ if ((this.texCoordSetCount > 0) && (this.texCoordSetMap == null)) {
/* 2723 */ this.texCoordSetCount = 1;
/* 2724 */ this.texCoordSetMap = new int[1];
/* 2725 */ this.texCoordSetMap[0] = 0;
/* */ }
/* */
/* 2732 */ IndexedGeometryArray ga = null;
/* */
/* 2734 */ switch (this.prim) {
/* */ case 1:
/* 2736 */ IndexedTriangleArray ta = new IndexedTriangleArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.coordinateIndices.length);
/* */
/* 2739 */ ga = ta;
/* 2740 */ break;
/* */ case 2:
/* 2743 */ IndexedQuadArray qa = new IndexedQuadArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.coordinateIndices.length);
/* */
/* 2746 */ ga = qa;
/* 2747 */ break;
/* */ case 4:
/* 2749 */ IndexedTriangleStripArray tsa = new IndexedTriangleStripArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.coordinateIndices.length, this.stripCounts);
/* */
/* 2752 */ ga = tsa;
/* 2753 */ break;
/* */ case 3:
/* 2756 */ IndexedTriangleFanArray tfa = new IndexedTriangleFanArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap, this.coordinateIndices.length, this.stripCounts);
/* */
/* 2759 */ ga = tfa;
/* */ }
/* */
/* 2764 */ fillIn(ga, byRef, interleaved, nio);
/* */
/* 2766 */ return ga;
/* */ }
/* */
/* */ public IndexedGeometryArray getIndexedGeometryArray(boolean compact)
/* */ {
/* 2792 */ return getIndexedGeometryArray(compact, false, false, false, false);
/* */ }
/* */
/* */ public IndexedGeometryArray getIndexedGeometryArray()
/* */ {
/* 2816 */ return getIndexedGeometryArray(false, false, false, false, false);
/* */ }
/* */
/* */ private class IndexRow
/* */ {
/* */ int[] val;
/* */ int size;
/* */ private static final int HASHCONST = -1161889074;
/* */
/* */ public int hashCode()
/* */ {
/* 1552 */ int bits = 0;
/* 1553 */ for (int i = 0; i < this.size; i++) {
/* 1554 */ bits ^= bits * -1161889074 << 2;
/* */ }
/* 1556 */ return bits;
/* */ }
/* */
/* */ public boolean equals(Object obj)
/* */ {
/* 1561 */ for (int i = 0; i < this.size; i++) {
/* 1562 */ if (((IndexRow)obj).get(i) != this.val[i]) return false;
/* */ }
/* 1564 */ return true;
/* */ }
/* */
/* */ public int get(int index)
/* */ {
/* 1569 */ return this.val[index];
/* */ }
/* */
/* */ public void set(int index, int value)
/* */ {
/* 1574 */ this.val[index] = value;
/* */ }
/* */
/* */ IndexRow(int numColumns)
/* */ {
/* 1579 */ this.size = numColumns;
/* 1580 */ this.val = new int[this.size];
/* */ }
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.geometry.GeometryInfo
* JD-Core Version: 0.6.2
*/