Package com.sun.j3d.utils.compression

Source Code of com.sun.j3d.utils.compression.CompressionStream$IndexedByRefGeometryNIO

/*      */ package com.sun.j3d.utils.compression;
/*      */
/*      */ import com.sun.j3d.internal.BufferWrapper;
/*      */ import com.sun.j3d.internal.ByteBufferWrapper;
/*      */ import com.sun.j3d.internal.DoubleBufferWrapper;
/*      */ import com.sun.j3d.internal.FloatBufferWrapper;
/*      */ import com.sun.j3d.utils.geometry.GeometryInfo;
/*      */ import java.io.PrintStream;
/*      */ import java.util.Collection;
/*      */ import java.util.Iterator;
/*      */ import java.util.LinkedList;
/*      */ import javax.media.j3d.Appearance;
/*      */ import javax.media.j3d.Geometry;
/*      */ import javax.media.j3d.GeometryArray;
/*      */ import javax.media.j3d.GeometryStripArray;
/*      */ import javax.media.j3d.IndexedGeometryArray;
/*      */ import javax.media.j3d.IndexedGeometryStripArray;
/*      */ import javax.media.j3d.IndexedLineArray;
/*      */ import javax.media.j3d.IndexedLineStripArray;
/*      */ import javax.media.j3d.IndexedQuadArray;
/*      */ import javax.media.j3d.IndexedTriangleArray;
/*      */ import javax.media.j3d.IndexedTriangleFanArray;
/*      */ import javax.media.j3d.IndexedTriangleStripArray;
/*      */ import javax.media.j3d.J3DBuffer;
/*      */ import javax.media.j3d.LineArray;
/*      */ import javax.media.j3d.LineStripArray;
/*      */ import javax.media.j3d.Material;
/*      */ import javax.media.j3d.QuadArray;
/*      */ import javax.media.j3d.Shape3D;
/*      */ import javax.media.j3d.TriangleArray;
/*      */ import javax.media.j3d.TriangleFanArray;
/*      */ import javax.media.j3d.TriangleStripArray;
/*      */ import javax.vecmath.Color3f;
/*      */ import javax.vecmath.Color4f;
/*      */ import javax.vecmath.Point3d;
/*      */ import javax.vecmath.Point3f;
/*      */ import javax.vecmath.Point3i;
/*      */ import javax.vecmath.Vector3f;
/*      */
/*      */ public class CompressionStream
/*      */ {
/*      */   private static final boolean debug = false;
/*      */   private static final boolean benchmark = false;
/*      */   private static final boolean noMeshNormalSubstitution = true;
/*      */   static final int RESTART = 1;
/*      */   static final int REPLACE_MIDDLE = 2;
/*      */   static final int REPLACE_OLDEST = 3;
/*      */   static final int MESH_PUSH = 1;
/*      */   static final int NO_MESH_PUSH = 0;
/*      */   static final float ByteToFloatScale = 0.003921569F;
/*      */   int streamType;
/*      */   int vertexComponents;
/*      */   boolean vertexColors;
/*      */   boolean vertexColor3;
/*      */   boolean vertexColor4;
/*      */   boolean vertexNormals;
/*      */   boolean vertexTextures;
/*      */   boolean vertexTexture2;
/*      */   boolean vertexTexture3;
/*      */   boolean vertexTexture4;
/*  194 */   Point3d[] mcBounds = new Point3d[2];
/*      */
/*  199 */   Point3d[] ncBounds = new Point3d[2];
/*      */
/*  204 */   Point3i[] qcBounds = new Point3i[2];
/*      */
/*  209 */   double[] center = new double[3];
/*      */   double positionRangeMaximum;
/*      */   double scale;
/*      */   int positionQuant;
/*      */   int colorQuant;
/*      */   int normalQuant;
/*      */   boolean positionQuantChanged;
/*      */   boolean colorQuantChanged;
/*      */   boolean normalQuantChanged;
/*  272 */   int[] lastPosition = new int[3];
/*      */
/*  277 */   int[] lastColor = new int[4];
/*      */   int lastSextant;
/*      */   int lastOctant;
/*      */   int lastU;
/*      */   int lastV;
/*      */   boolean lastSpecialNormal;
/*      */   boolean firstPosition;
/*      */   boolean firstColor;
/*      */   boolean firstNormal;
/*      */   int byteCount;
/*      */   int vertexCount;
/*      */   int meshReferenceCount;
/*  341 */   MeshBuffer meshBuffer = new MeshBuffer();
/*      */   private Collection stream;
/*  350 */   private boolean lastElementColor = false;
/*  351 */   private boolean lastLastElementColor = false;
/*  352 */   private boolean lastElementNormal = false;
/*  353 */   private boolean lastLastElementNormal = false;
/*      */
/*  356 */   private Point3f p3f = new Point3f();
/*  357 */   private Color3f c3f = new Color3f();
/*  358 */   private Color4f c4f = new Color4f();
/*  359 */   private Vector3f n3f = new Vector3f();
/*      */
/*      */   private CompressionStream()
/*      */   {
/*  364 */     this.stream = new LinkedList();
/*      */
/*  366 */     this.byteCount = 0;
/*  367 */     this.vertexCount = 0;
/*  368 */     this.meshReferenceCount = 0;
/*      */
/*  370 */     this.mcBounds[0] = new Point3d((1.0D / 0.0D), (1.0D / 0.0D), (1.0D / 0.0D));
/*      */
/*  373 */     this.mcBounds[1] = new Point3d((-1.0D / 0.0D), (-1.0D / 0.0D), (-1.0D / 0.0D));
/*      */
/*  377 */     this.qcBounds[0] = new Point3i(2147483647, 2147483647, 2147483647);
/*      */
/*  380 */     this.qcBounds[1] = new Point3i(-2147483648, -2147483648, -2147483648);
/*      */
/*  385 */     this.ncBounds[0] = new Point3d();
/*  386 */     this.ncBounds[1] = new Point3d();
/*      */   }
/*      */
/*      */   CompressionStream(int streamType, int vertexComponents)
/*      */   {
/*  406 */     this();
/*  407 */     this.streamType = streamType;
/*  408 */     this.vertexComponents = getVertexComponents(vertexComponents);
/*      */   }
/*      */
/*      */   private int getVertexComponents(int vertexFormat)
/*      */   {
/*  415 */     int components = 0;
/*      */
/*  417 */     this.vertexColors = (this.vertexColor3 = this.vertexColor4 = this.vertexNormals = this.vertexTextures = this.vertexTexture2 = this.vertexTexture3 = this.vertexTexture4 = 0);
/*      */
/*  421 */     if ((vertexFormat & 0x2) != 0) {
/*  422 */       this.vertexNormals = true;
/*  423 */       components &= 2;
/*      */     }
/*      */
/*  427 */     if ((vertexFormat & 0x4) != 0) {
/*  428 */       this.vertexColors = true;
/*      */
/*  430 */       if ((vertexFormat & 0xC) != 0) {
/*  431 */         this.vertexColor4 = true;
/*  432 */         components &= 12;
/*      */       }
/*      */       else
/*      */       {
/*  436 */         this.vertexColor3 = true;
/*  437 */         components &= 4;
/*      */       }
/*      */
/*      */     }
/*      */
/*  442 */     if ((vertexFormat & 0x20) != 0) {
/*  443 */       this.vertexTextures = true;
/*  444 */       this.vertexTexture2 = true;
/*  445 */       components &= 32;
/*      */     }
/*  448 */     else if ((vertexFormat & 0x40) != 0) {
/*  449 */       this.vertexTextures = true;
/*  450 */       this.vertexTexture3 = true;
/*  451 */       components &= 64;
/*      */     }
/*  454 */     else if ((vertexFormat & 0x400) != 0) {
/*  455 */       this.vertexTextures = true;
/*  456 */       this.vertexTexture4 = true;
/*  457 */       components &= 1024;
/*      */     }
/*      */
/*  461 */     if (this.vertexTextures)
/*      */     {
/*  463 */       throw new UnsupportedOperationException("\ncompression of texture coordinates is not supported");
/*      */     }
/*      */
/*  466 */     return components;
/*      */   }
/*      */
/*      */   private int getStreamType(GeometryArray ga)
/*      */   {
/*  471 */     if (((ga instanceof TriangleStripArray)) || ((ga instanceof IndexedTriangleStripArray)) || ((ga instanceof TriangleFanArray)) || ((ga instanceof IndexedTriangleFanArray)) || ((ga instanceof TriangleArray)) || ((ga instanceof IndexedTriangleArray)) || ((ga instanceof QuadArray)) || ((ga instanceof IndexedQuadArray)))
/*      */     {
/*  480 */       return 2;
/*      */     }
/*  482 */     if (((ga instanceof LineArray)) || ((ga instanceof IndexedLineArray)) || ((ga instanceof LineStripArray)) || ((ga instanceof IndexedLineStripArray)))
/*      */     {
/*  487 */       return 1;
/*      */     }
/*      */
/*  490 */     return 0;
/*      */   }
/*      */
/*      */   void quantize(HuffmanTable huffmanTable)
/*      */   {
/*  524 */     this.positionQuant = 16;
/*  525 */     this.colorQuant = 9;
/*  526 */     this.normalQuant = 6;
/*      */
/*  531 */     this.center[0] = ((this.mcBounds[1].x + this.mcBounds[0].x) / 2.0D);
/*  532 */     this.center[1] = ((this.mcBounds[1].y + this.mcBounds[0].y) / 2.0D);
/*  533 */     this.center[2] = ((this.mcBounds[1].z + this.mcBounds[0].z) / 2.0D);
/*      */
/*  535 */     double xRange = this.mcBounds[1].x - this.mcBounds[0].x;
/*  536 */     double yRange = this.mcBounds[1].y - this.mcBounds[0].y;
/*  537 */     double zRange = this.mcBounds[1].z - this.mcBounds[0].z;
/*      */
/*  539 */     if (xRange > yRange)
/*  540 */       this.positionRangeMaximum = xRange;
/*      */     else {
/*  542 */       this.positionRangeMaximum = yRange;
/*      */     }
/*  544 */     if (zRange > this.positionRangeMaximum) {
/*  545 */       this.positionRangeMaximum = zRange;
/*      */     }
/*      */
/*  561 */     this.scale = (2.0D / this.positionRangeMaximum * 0.999969482421875D);
/*      */
/*  564 */     this.positionQuantChanged = (this.colorQuantChanged = this.normalQuantChanged = 1);
/*      */
/*  567 */     this.firstPosition = (this.firstColor = this.firstNormal = 1);
/*      */
/*  570 */     Iterator i = this.stream.iterator();
/*  571 */     while (i.hasNext()) {
/*  572 */       Object o = i.next();
/*      */
/*  574 */       if ((o instanceof CompressionStreamElement)) {
/*  575 */         ((CompressionStreamElement)o).quantize(this, huffmanTable);
/*      */
/*  579 */         this.lastLastElementColor = this.lastElementColor;
/*  580 */         this.lastLastElementNormal = this.lastElementNormal;
/*  581 */         this.lastElementColor = (this.lastElementNormal = 0);
/*      */
/*  583 */         if ((o instanceof CompressionStreamColor))
/*  584 */           this.lastElementColor = true;
/*  585 */         else if ((o instanceof CompressionStreamNormal)) {
/*  586 */           this.lastElementNormal = true;
/*      */         }
/*      */       }
/*      */     }
/*      */
/*  591 */     this.ncBounds[0].x = (this.qcBounds[0].x / 32768.0D);
/*  592 */     this.ncBounds[0].y = (this.qcBounds[0].y / 32768.0D);
/*  593 */     this.ncBounds[0].z = (this.qcBounds[0].z / 32768.0D);
/*      */
/*  595 */     this.ncBounds[1].x = (this.qcBounds[1].x / 32768.0D);
/*  596 */     this.ncBounds[1].y = (this.qcBounds[1].y / 32768.0D);
/*  597 */     this.ncBounds[1].z = (this.qcBounds[1].z / 32768.0D);
/*      */   }
/*      */
/*      */   void outputCommands(HuffmanTable huffmanTable, CommandStream outputBuffer)
/*      */   {
/*  624 */     int bnv = this.vertexNormals ? 1 : 0;
/*  625 */     int bcv = (this.vertexColor3) || (this.vertexColor4) ? 1 : 0;
/*  626 */     int cap = this.vertexColor4 ? 1 : 0;
/*      */
/*  628 */     int command = 0x18 | bnv;
/*  629 */     long data = bcv << 2 | cap << 1;
/*      */
/*  632 */     outputBuffer.addCommand(command, 8, data, 3);
/*      */
/*  635 */     huffmanTable.outputCommands(outputBuffer);
/*      */
/*  638 */     Iterator i = this.stream.iterator();
/*  639 */     while (i.hasNext()) {
/*  640 */       Object o = i.next();
/*  641 */       if ((o instanceof CompressionStreamElement)) {
/*  642 */         ((CompressionStreamElement)o).outputCommand(huffmanTable, outputBuffer);
/*      */       }
/*      */
/*      */     }
/*      */
/*  647 */     outputBuffer.end();
/*      */   }
/*      */
/*      */   int getByteCount()
/*      */   {
/*  656 */     return this.byteCount;
/*      */   }
/*      */
/*      */   int getVertexCount()
/*      */   {
/*  665 */     return this.vertexCount;
/*      */   }
/*      */
/*      */   int getMeshReferenceCount()
/*      */   {
/*  673 */     return this.meshReferenceCount;
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, int stripFlag)
/*      */   {
/*  805 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, (Color3f)null, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, int stripFlag)
/*      */   {
/*  818 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, (Color3f)null, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Color3f color, int stripFlag)
/*      */   {
/*  830 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, color, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Color4f color, int stripFlag)
/*      */   {
/*  842 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, color, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, Color3f color, int stripFlag)
/*      */   {
/*  856 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, color, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, Color4f color, int stripFlag)
/*      */   {
/*  870 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, color, stripFlag, 0));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, int stripFlag, int meshFlag)
/*      */   {
/*  882 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, (Color3f)null, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, int stripFlag, int meshFlag)
/*      */   {
/*  896 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, (Color3f)null, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Color3f color, int stripFlag, int meshFlag)
/*      */   {
/*  910 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, color, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Color4f color, int stripFlag, int meshFlag)
/*      */   {
/*  924 */     this.stream.add(new CompressionStreamVertex(this, pos, (Vector3f)null, color, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, Color3f color, int stripFlag, int meshFlag)
/*      */   {
/*  939 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, color, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, Color4f color, int stripFlag, int meshFlag)
/*      */   {
/*  954 */     this.stream.add(new CompressionStreamVertex(this, pos, norm, color, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addVertex(Point3f pos, Vector3f norm, Object color, int stripFlag, int meshFlag)
/*      */   {
/*  971 */     if (this.vertexColor3) {
/*  972 */       this.stream.add(new CompressionStreamVertex(this, pos, norm, (Color3f)color, stripFlag, meshFlag));
/*      */     }
/*      */     else
/*  975 */       this.stream.add(new CompressionStreamVertex(this, pos, norm, (Color4f)color, stripFlag, meshFlag));
/*      */   }
/*      */
/*      */   void addMeshReference(int stripFlag, int meshIndex)
/*      */   {
/*  986 */     this.stream.add(new MeshReference(stripFlag, meshIndex));
/*      */   }
/*      */
/*      */   void addColor(Color3f c3f)
/*      */   {
/*  994 */     this.stream.add(new CompressionStreamColor(this, c3f));
/*      */   }
/*      */
/*      */   void addColor(Color4f c4f)
/*      */   {
/* 1002 */     this.stream.add(new CompressionStreamColor(this, c4f));
/*      */   }
/*      */
/*      */   void addNormal(Vector3f n)
/*      */   {
/* 1010 */     this.stream.add(new CompressionStreamNormal(this, n));
/*      */   }
/*      */
/*      */   void addPositionQuantization(int value)
/*      */   {
/* 1021 */     this.stream.add(new PositionQuant(value));
/*      */   }
/*      */
/*      */   void addColorQuantization(int value)
/*      */   {
/* 1032 */     this.stream.add(new ColorQuant(value));
/*      */   }
/*      */
/*      */   void addNormalQuantization(int value)
/*      */   {
/* 1044 */     this.stream.add(new NormalQuant(value));
/*      */   }
/*      */
/*      */   private void getIndexArrays(GeometryArray ga, IndexArrays ia)
/*      */   {
/* 1165 */     IndexedGeometryArray iga = (IndexedGeometryArray)ga;
/*      */
/* 1167 */     int initialIndexIndex = iga.getInitialIndexIndex();
/* 1168 */     int indexCount = iga.getValidIndexCount();
/* 1169 */     int vertexFormat = iga.getVertexFormat();
/*      */
/* 1171 */     boolean useCoordIndexOnly = false;
/* 1172 */     if ((vertexFormat & 0x200) != 0)
/*      */     {
/* 1174 */       useCoordIndexOnly = true;
/*      */     }
/*      */
/* 1177 */     ia.positionIndices = new int[indexCount];
/* 1178 */     iga.getCoordinateIndices(initialIndexIndex, ia.positionIndices);
/*      */
/* 1180 */     if (this.vertexNormals) {
/* 1181 */       if (useCoordIndexOnly) {
/* 1182 */         ia.normalIndices = ia.positionIndices;
/*      */       }
/*      */       else {
/* 1185 */         ia.normalIndices = new int[indexCount];
/* 1186 */         iga.getNormalIndices(initialIndexIndex, ia.normalIndices);
/*      */       }
/*      */     }
/* 1189 */     if ((this.vertexColor3) || (this.vertexColor4))
/* 1190 */       if (useCoordIndexOnly) {
/* 1191 */         ia.colorIndices = ia.positionIndices;
/*      */       }
/*      */       else {
/* 1194 */         ia.colorIndices = new int[indexCount];
/* 1195 */         iga.getColorIndices(initialIndexIndex, ia.colorIndices);
/*      */       }
/*      */   }
/*      */
/*      */   private void getVertexIndices(int v, IndexArrays ia, VertexIndices vi)
/*      */   {
/* 1213 */     vi.pi = ia.positionIndices[v];
/* 1214 */     if (this.vertexNormals)
/* 1215 */       vi.ni = ia.normalIndices[v];
/* 1216 */     if (this.vertexColors)
/* 1217 */       vi.ci = ia.colorIndices[v];
/*      */   }
/*      */
/*      */   private void processVertexCopy(VertexCopy vc, int stripFlag)
/*      */   {
/* 1278 */     int r = this.meshBuffer.getMeshReference(vc.p);
/*      */
/* 1280 */     if ((r == -1) || ((this.vertexNormals) && (!vc.n.equals(this.meshBuffer.getNormal(r)))))
/*      */     {
/* 1284 */       addVertex(vc.p, vc.n, vc.c, stripFlag, 1);
/* 1285 */       this.meshBuffer.push(vc.p, vc.c, vc.n);
/*      */     }
/*      */     else {
/* 1288 */       if ((!this.vertexNormals) || (
/* 1292 */         (this.vertexColor3) && (!vc.c3.equals(this.meshBuffer.getColor3(r))))) {
/* 1293 */         addColor(vc.c3);
/*      */       }
/* 1295 */       else if ((this.vertexColor4) && (!vc.c4.equals(this.meshBuffer.getColor4(r)))) {
/* 1296 */         addColor(vc.c4);
/*      */       }
/* 1298 */       addMeshReference(stripFlag, r);
/*      */     }
/*      */   }
/*      */
/*      */   private void processIndexedVertexCopy(VertexCopy vc, VertexIndices vi, int stripFlag)
/*      */   {
/* 1306 */     int r = this.meshBuffer.getMeshReference(vi.pi);
/*      */
/* 1308 */     if ((r == -1) || ((this.vertexNormals) && (vi.ni != this.meshBuffer.getNormalIndex(r))))
/*      */     {
/* 1312 */       addVertex(vc.p, vc.n, vc.c, stripFlag, 1);
/* 1313 */       this.meshBuffer.push(vi.pi, vi.ci, vi.ni);
/*      */     }
/*      */     else {
/* 1316 */       if ((!this.vertexNormals) || (
/* 1320 */         (this.vertexColor3) && (vi.ci != this.meshBuffer.getColorIndex(r)))) {
/* 1321 */         addColor(vc.c3);
/*      */       }
/* 1323 */       else if ((this.vertexColor4) && (vi.ci != this.meshBuffer.getColorIndex(r))) {
/* 1324 */         addColor(vc.c4);
/*      */       }
/* 1326 */       addMeshReference(stripFlag, r);
/*      */     }
/*      */   }
/*      */
/*      */   void addGeometryArray(GeometryArray ga)
/*      */   {
/* 1821 */     int firstVertex = 0;
/* 1822 */     int validVertexCount = 0;
/* 1823 */     int vertexFormat = ga.getVertexFormat();
/* 1824 */     GeometryAccessor geometryAccessor = null;
/*      */
/* 1826 */     if (this.streamType != getStreamType(ga)) {
/* 1827 */       throw new IllegalArgumentException("GeometryArray has inconsistent dimensionality");
/*      */     }
/*      */
/* 1830 */     if (this.vertexComponents != getVertexComponents(vertexFormat)) {
/* 1831 */       throw new IllegalArgumentException("GeometryArray has inconsistent vertex components");
/*      */     }
/*      */
/* 1835 */     boolean NIO = (vertexFormat & 0x800) != 0;
/* 1836 */     boolean byRef = (vertexFormat & 0x80) != 0;
/* 1837 */     boolean interleaved = (vertexFormat & 0x100) != 0;
/* 1838 */     boolean indexedGeometry = ga instanceof IndexedGeometryArray;
/*      */
/* 1840 */     if (indexedGeometry)
/*      */     {
/* 1844 */       firstVertex = 0;
/* 1845 */       validVertexCount = ((IndexedGeometryArray)ga).getValidIndexCount();
/*      */     }
/*      */
/* 1848 */     if (!byRef)
/*      */     {
/* 1850 */       if (indexedGeometry) {
/* 1851 */         geometryAccessor = new IndexedByCopyGeometry(ga);
/*      */       }
/*      */       else {
/* 1854 */         firstVertex = 0;
/* 1855 */         validVertexCount = ga.getValidVertexCount();
/* 1856 */         geometryAccessor = new ByCopyGeometry(ga);
/*      */       }
/*      */     }
/* 1859 */     else if ((interleaved) && (NIO))
/*      */     {
/* 1861 */       if (indexedGeometry) {
/* 1862 */         geometryAccessor = new IndexedInterleavedGeometryNIO(ga);
/*      */       }
/*      */       else {
/* 1865 */         firstVertex = ga.getInitialVertexIndex();
/* 1866 */         validVertexCount = ga.getValidVertexCount();
/* 1867 */         geometryAccessor = new InterleavedGeometryNIO(ga);
/*      */       }
/*      */     }
/* 1870 */     else if ((interleaved) && (!NIO))
/*      */     {
/* 1872 */       if (indexedGeometry) {
/* 1873 */         geometryAccessor = new IndexedInterleavedGeometryFloat(ga);
/*      */       }
/*      */       else {
/* 1876 */         firstVertex = ga.getInitialVertexIndex();
/* 1877 */         validVertexCount = ga.getValidVertexCount();
/* 1878 */         geometryAccessor = new InterleavedGeometryFloat(ga);
/*      */       }
/*      */     }
/* 1881 */     else if ((!interleaved) && (NIO))
/*      */     {
/* 1883 */       if (indexedGeometry) {
/* 1884 */         geometryAccessor = new IndexedByRefGeometryNIO(ga);
/*      */       }
/*      */       else {
/* 1887 */         firstVertex = 0;
/* 1888 */         validVertexCount = ga.getValidVertexCount();
/* 1889 */         geometryAccessor = new ByRefGeometryNIO(ga);
/*      */       }
/*      */     }
/* 1892 */     else if ((!interleaved) && (!NIO))
/*      */     {
/* 1894 */       if (indexedGeometry) {
/* 1895 */         geometryAccessor = new IndexedByRefGeometry(ga);
/*      */       }
/*      */       else {
/* 1898 */         firstVertex = 0;
/* 1899 */         validVertexCount = ga.getValidVertexCount();
/* 1900 */         geometryAccessor = new ByRefGeometry(ga);
/*      */       }
/*      */
/*      */     }
/*      */
/* 1905 */     int stripCount = 0;
/* 1906 */     int[] stripCounts = null;
/* 1907 */     int constantStripLength = 0;
/* 1908 */     int replaceCode = 1;
/* 1909 */     boolean strips = false;
/* 1910 */     boolean implicitStrips = false;
/*      */
/* 1912 */     if (((ga instanceof TriangleStripArray)) || ((ga instanceof IndexedTriangleStripArray)) || ((ga instanceof LineStripArray)) || ((ga instanceof IndexedLineStripArray)))
/*      */     {
/* 1917 */       strips = true;
/* 1918 */       replaceCode = 3;
/*      */     }
/* 1921 */     else if (((ga instanceof TriangleFanArray)) || ((ga instanceof IndexedTriangleFanArray)))
/*      */     {
/* 1924 */       strips = true;
/* 1925 */       replaceCode = 2;
/*      */     }
/* 1928 */     else if (((ga instanceof QuadArray)) || ((ga instanceof IndexedQuadArray)))
/*      */     {
/* 1932 */       implicitStrips = true;
/* 1933 */       constantStripLength = 4;
/* 1934 */       replaceCode = 2;
/*      */     }
/*      */
/* 1939 */     if (strips) {
/* 1940 */       if (indexedGeometry)
/*      */       {
/* 1942 */         IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)ga;
/*      */
/* 1944 */         stripCount = igsa.getNumStrips();
/* 1945 */         stripCounts = new int[stripCount];
/* 1946 */         igsa.getStripIndexCounts(stripCounts);
/*      */       }
/*      */       else
/*      */       {
/* 1950 */         GeometryStripArray gsa = (GeometryStripArray)ga;
/*      */
/* 1952 */         stripCount = gsa.getNumStrips();
/* 1953 */         stripCounts = new int[stripCount];
/* 1954 */         gsa.getStripVertexCounts(stripCounts);
/*      */       }
/*      */
/*      */     }
/*      */
/* 1959 */     int v = firstVertex;
/* 1960 */     if (strips) {
/* 1961 */       for (int i = 0; i < stripCount; i++) {
/* 1962 */         geometryAccessor.processVertex(v++, 1);
/* 1963 */         for (int j = 1; j < stripCounts[i]; j++)
/* 1964 */           geometryAccessor.processVertex(v++, replaceCode);
/*      */       }
/*      */     }
/*      */     else {
/* 1968 */       if (implicitStrips) {
/* 1969 */         while (v < firstVertex + validVertexCount) {
/* 1970 */           geometryAccessor.processVertex(v++, 1);
/* 1971 */           for (int j = 1; j < constantStripLength; j++) {
/* 1972 */             geometryAccessor.processVertex(v++, replaceCode);
/*      */           }
/*      */         }
/*      */       }
/*      */
/* 1977 */       while (v < firstVertex + validVertexCount)
/* 1978 */         geometryAccessor.processVertex(v++, 1);
/*      */     }
/*      */   }
/*      */
/*      */   void print()
/*      */   {
/* 1987 */     System.out.println("\nstream has " + this.stream.size() + " entries");
/* 1988 */     System.out.println("uncompressed size " + this.byteCount + " bytes");
/* 1989 */     System.out.println("upper position bound: " + this.mcBounds[1].toString());
/* 1990 */     System.out.println("lower position bound: " + this.mcBounds[0].toString());
/* 1991 */     System.out.println("X, Y, Z centers (" + (float)this.center[0] + " " + (float)this.center[1] + " " + (float)this.center[2] + ")\n" + "scale " + (float)this.scale + "\n");
/*      */
/* 1997 */     Iterator i = this.stream.iterator();
/* 1998 */     while (i.hasNext())
/* 1999 */       System.out.println(i.next().toString() + "\n");
/*      */   }
/*      */
/*      */   public CompressionStream(int positionQuant, int colorQuant, int normalQuant, Shape3D[] shapes)
/*      */   {
/* 2054 */     this();
/*      */
/* 2057 */     if (shapes == null) {
/* 2058 */       throw new IllegalArgumentException("null Shape3D array");
/*      */     }
/* 2060 */     if (shapes.length == 0) {
/* 2061 */       throw new IllegalArgumentException("zero-length Shape3D array");
/*      */     }
/* 2063 */     if (shapes[0] == null) {
/* 2064 */       throw new IllegalArgumentException("Shape3D at index 0 is null");
/*      */     }
/* 2066 */     long startTime = 0L;
/*      */
/* 2069 */     Geometry g = shapes[0].getGeometry();
/* 2070 */     if (!(g instanceof GeometryArray)) {
/* 2071 */       throw new IllegalArgumentException("Shape3D at index 0 is not a GeometryArray");
/*      */     }
/*      */
/* 2074 */     GeometryArray ga = (GeometryArray)g;
/* 2075 */     this.streamType = getStreamType(ga);
/* 2076 */     this.vertexComponents = getVertexComponents(ga.getVertexFormat());
/*      */
/* 2079 */     addPositionQuantization(positionQuant);
/* 2080 */     addColorQuantization(colorQuant);
/* 2081 */     addNormalQuantization(normalQuant);
/*      */
/* 2084 */     for (int s = 0; s < shapes.length; s++)
/*      */     {
/* 2087 */       g = shapes[s].getGeometry();
/* 2088 */       if (!(g instanceof GeometryArray)) {
/* 2089 */         throw new IllegalArgumentException("Shape3D at index " + s + " is not a GeometryArray");
/*      */       }
/*      */
/* 2093 */       Appearance a = shapes[s].getAppearance();
/* 2094 */       if (a != null) {
/* 2095 */         Material m = a.getMaterial();
/* 2096 */         if (m != null) {
/* 2097 */           m.getDiffuseColor(this.c3f);
/* 2098 */           if (this.vertexColor4) {
/* 2099 */             this.c4f.set(this.c3f.x, this.c3f.y, this.c3f.z, 1.0F);
/* 2100 */             addColor(this.c4f);
/*      */           } else {
/* 2102 */             addColor(this.c3f);
/*      */           }
/*      */         }
/*      */       }
/*      */
/* 2107 */       addGeometryArray((GeometryArray)g);
/*      */     }
/*      */   }
/*      */
/*      */   public CompressionStream(Shape3D[] shapes)
/*      */   {
/* 2154 */     this(16, 9, 6, shapes);
/*      */   }
/*      */
/*      */   public CompressionStream(int positionQuant, int colorQuant, int normalQuant, GeometryInfo[] geometry)
/*      */   {
/* 2190 */     this();
/*      */
/* 2193 */     if (geometry == null) {
/* 2194 */       throw new IllegalArgumentException("null GeometryInfo array");
/*      */     }
/* 2196 */     if (geometry.length == 0) {
/* 2197 */       throw new IllegalArgumentException("zero-length GeometryInfo array");
/*      */     }
/*      */
/* 2200 */     if (geometry[0] == null) {
/* 2201 */       throw new IllegalArgumentException("GeometryInfo at index 0 is null");
/*      */     }
/*      */
/* 2204 */     long startTime = 0L;
/*      */
/* 2207 */     GeometryArray ga = geometry[0].getGeometryArray();
/* 2208 */     this.streamType = getStreamType(ga);
/* 2209 */     this.vertexComponents = getVertexComponents(ga.getVertexFormat());
/*      */
/* 2212 */     addPositionQuantization(positionQuant);
/* 2213 */     addColorQuantization(colorQuant);
/* 2214 */     addNormalQuantization(normalQuant);
/*      */
/* 2217 */     for (int i = 0; i < geometry.length; i++)
/*      */     {
/* 2219 */       addGeometryArray(geometry[i].getGeometryArray());
/*      */     }
/*      */   }
/*      */
/*      */   public CompressionStream(GeometryInfo[] geometry)
/*      */   {
/* 2256 */     this(16, 9, 6, geometry);
/*      */   }
/*      */
/*      */   public Point3d[] getModelBounds()
/*      */   {
/* 2269 */     Point3d[] bounds = new Point3d[2];
/* 2270 */     bounds[0] = new Point3d(this.mcBounds[0]);
/* 2271 */     bounds[1] = new Point3d(this.mcBounds[1]);
/* 2272 */     return bounds;
/*      */   }
/*      */
/*      */   public Point3d[] getNormalizedBounds()
/*      */   {
/* 2284 */     Point3d[] bounds = new Point3d[2];
/* 2285 */     bounds[0] = new Point3d(this.ncBounds[0]);
/* 2286 */     bounds[1] = new Point3d(this.ncBounds[1]);
/* 2287 */     return bounds;
/*      */   }
/*      */
/*      */   private class IndexedByRefGeometryNIO extends CompressionStream.ByRefGeometryNIO
/*      */   {
/* 1797 */     CompressionStream.IndexArrays ia = new CompressionStream.IndexArrays(null);
/* 1798 */     CompressionStream.VertexIndices vi = new CompressionStream.VertexIndices(null);
/*      */
/*      */     IndexedByRefGeometryNIO(GeometryArray ga) {
/* 1801 */       super(ga);
/* 1802 */       CompressionStream.this.getIndexArrays(ga, this.ia);
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1806 */       CompressionStream.this.getVertexIndices(v, this.ia, this.vi);
/* 1807 */       copyVertex(this.vi.pi, this.vi.ni, this.vi.ci, this.vc);
/* 1808 */       CompressionStream.this.processIndexedVertexCopy(this.vc, this.vi, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class ByRefGeometryNIO
/*      */     implements CompressionStream.GeometryAccessor
/*      */   {
/* 1663 */     CompressionStream.VertexCopy vc = new CompressionStream.VertexCopy(null);
/*      */
/* 1665 */     ByteBufferWrapper colorsB = null;
/* 1666 */     FloatBufferWrapper colorsF = null;
/* 1667 */     FloatBufferWrapper normals = null;
/* 1668 */     FloatBufferWrapper positionsF = null;
/* 1669 */     DoubleBufferWrapper positionsD = null;
/*      */
/* 1671 */     int initialPositionIndex = 0;
/* 1672 */     int initialNormalIndex = 0;
/* 1673 */     int initialColorIndex = 0;
/*      */
/*      */     ByRefGeometryNIO(GeometryArray ga)
/*      */     {
/* 1677 */       J3DBuffer buffer = ga.getCoordRefBuffer();
/* 1678 */       this.initialPositionIndex = ga.getInitialCoordIndex();
/*      */
/* 1680 */       switch (BufferWrapper.getBufferType(buffer)) {
/*      */       case 3:
/* 1682 */         this.positionsF = new FloatBufferWrapper(buffer);
/*      */
/* 1684 */         break;
/*      */       case 4:
/* 1686 */         this.positionsD = new DoubleBufferWrapper(buffer);
/*      */
/* 1688 */         break;
/*      */       default:
/* 1690 */         throw new IllegalArgumentException("\nposition buffer must be FloatBuffer or DoubleBuffer");
/*      */       }
/*      */
/* 1694 */       if (CompressionStream.this.vertexColors) {
/* 1695 */         buffer = ga.getColorRefBuffer();
/* 1696 */         this.initialColorIndex = ga.getInitialColorIndex();
/*      */
/* 1698 */         switch (BufferWrapper.getBufferType(buffer)) {
/*      */         case 2:
/* 1700 */           this.colorsB = new ByteBufferWrapper(buffer);
/*      */
/* 1702 */           break;
/*      */         case 3:
/* 1704 */           this.colorsF = new FloatBufferWrapper(buffer);
/*      */
/* 1706 */           break;
/*      */         default:
/* 1708 */           throw new IllegalArgumentException("\ncolor buffer must be ByteBuffer or FloatBuffer");
/*      */         }
/*      */
/*      */       }
/*      */
/* 1713 */       if (CompressionStream.this.vertexNormals) {
/* 1714 */         buffer = ga.getNormalRefBuffer();
/* 1715 */         this.initialNormalIndex = ga.getInitialNormalIndex();
/*      */
/* 1717 */         switch (BufferWrapper.getBufferType(buffer)) {
/*      */         case 3:
/* 1719 */           this.normals = new FloatBufferWrapper(buffer);
/*      */
/* 1721 */           break;
/*      */         default:
/* 1723 */           throw new IllegalArgumentException("\nnormal buffer must be FloatBuffer");
/*      */         }
/*      */       }
/*      */     }
/*      */
/*      */     void copyVertex(int pi, int ni, int ci, CompressionStream.VertexCopy vc)
/*      */     {
/* 1730 */       pi *= 3;
/* 1731 */       if (this.positionsF != null) {
/* 1732 */         vc.p = new Point3f(this.positionsF.get(pi + 0), this.positionsF.get(pi + 1), this.positionsF.get(pi + 2));
/*      */       }
/*      */       else
/*      */       {
/* 1737 */         vc.p = new Point3f((float)this.positionsD.get(pi + 0), (float)this.positionsD.get(pi + 1), (float)this.positionsD.get(pi + 2));
/*      */       }
/*      */
/* 1742 */       ni *= 3;
/* 1743 */       if (CompressionStream.this.vertexNormals) {
/* 1744 */         vc.n = new Vector3f(this.normals.get(ni + 0), this.normals.get(ni + 1), this.normals.get(ni + 2));
/*      */       }
/*      */
/* 1749 */       if (CompressionStream.this.vertexColor3) {
/* 1750 */         ci *= 3;
/* 1751 */         if (this.colorsB != null) {
/* 1752 */           vc.c3 = new Color3f((this.colorsB.get(ci + 0) & 0xFF) * 0.003921569F, (this.colorsB.get(ci + 1) & 0xFF) * 0.003921569F, (this.colorsB.get(ci + 2) & 0xFF) * 0.003921569F);
/*      */         }
/*      */         else
/*      */         {
/* 1758 */           vc.c3 = new Color3f(this.colorsF.get(ci + 0), this.colorsF.get(ci + 1), this.colorsF.get(ci + 2));
/*      */         }
/*      */
/* 1762 */         vc.c = vc.c3;
/*      */       }
/* 1764 */       else if (CompressionStream.this.vertexColor4) {
/* 1765 */         ci *= 4;
/* 1766 */         if (this.colorsB != null) {
/* 1767 */           vc.c4 = new Color4f((this.colorsB.get(ci + 0) & 0xFF) * 0.003921569F, (this.colorsB.get(ci + 1) & 0xFF) * 0.003921569F, (this.colorsB.get(ci + 2) & 0xFF) * 0.003921569F, (this.colorsB.get(ci + 3) & 0xFF) * 0.003921569F);
/*      */         }
/*      */         else
/*      */         {
/* 1774 */           vc.c4 = new Color4f(this.colorsF.get(ci + 0), this.colorsF.get(ci + 1), this.colorsF.get(ci + 2), this.colorsF.get(ci + 3));
/*      */         }
/*      */
/* 1779 */         vc.c = vc.c4;
/*      */       }
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1784 */       copyVertex(v + this.initialPositionIndex, v + this.initialNormalIndex, v + this.initialColorIndex, this.vc);
/*      */
/* 1788 */       CompressionStream.this.processVertexCopy(this.vc, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class IndexedByRefGeometry extends CompressionStream.ByRefGeometry
/*      */   {
/* 1643 */     CompressionStream.IndexArrays ia = new CompressionStream.IndexArrays(null);
/* 1644 */     CompressionStream.VertexIndices vi = new CompressionStream.VertexIndices(null);
/*      */
/*      */     IndexedByRefGeometry(GeometryArray ga) {
/* 1647 */       super(ga);
/* 1648 */       CompressionStream.this.getIndexArrays(ga, this.ia);
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1652 */       CompressionStream.this.getVertexIndices(v, this.ia, this.vi);
/* 1653 */       copyVertex(this.vi.pi, this.vi.ni, this.vi.ci, this.vc);
/* 1654 */       CompressionStream.this.processIndexedVertexCopy(this.vc, this.vi, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class ByRefGeometry
/*      */     implements CompressionStream.GeometryAccessor
/*      */   {
/* 1519 */     CompressionStream.VertexCopy vc = new CompressionStream.VertexCopy(null);
/*      */
/* 1521 */     byte[] colorsB = null;
/* 1522 */     float[] colorsF = null;
/* 1523 */     float[] normals = null;
/* 1524 */     float[] positionsF = null;
/* 1525 */     double[] positionsD = null;
/*      */
/* 1527 */     int initialPositionIndex = 0;
/* 1528 */     int initialNormalIndex = 0;
/* 1529 */     int initialColorIndex = 0;
/*      */
/*      */     ByRefGeometry(GeometryArray ga) {
/* 1532 */       this.positionsF = ga.getCoordRefFloat();
/*      */
/* 1536 */       this.positionsD = ga.getCoordRefDouble();
/*      */
/* 1540 */       if ((this.positionsF == null) && (this.positionsD == null)) {
/* 1541 */         throw new UnsupportedOperationException("\nby-reference access to Point3{d,f} arrays");
/*      */       }
/*      */
/* 1544 */       this.initialPositionIndex = ga.getInitialCoordIndex();
/*      */
/* 1546 */       if (CompressionStream.this.vertexColors) {
/* 1547 */         this.colorsB = ga.getColorRefByte();
/*      */
/* 1551 */         this.colorsF = ga.getColorRefFloat();
/*      */
/* 1555 */         if ((this.colorsB == null) && (this.colorsF == null)) {
/* 1556 */           throw new UnsupportedOperationException("\nby-reference access to Color{3b,3f,4b,4f} arrays");
/*      */         }
/*      */
/* 1559 */         this.initialColorIndex = ga.getInitialColorIndex();
/*      */       }
/*      */
/* 1562 */       if (CompressionStream.this.vertexNormals) {
/* 1563 */         this.normals = ga.getNormalRefFloat();
/*      */
/* 1567 */         if (this.normals == null) {
/* 1568 */           throw new UnsupportedOperationException("\nby-reference access to Normal3f array");
/*      */         }
/*      */
/* 1571 */         this.initialNormalIndex = ga.getInitialNormalIndex();
/*      */       }
/*      */     }
/*      */
/*      */     void copyVertex(int pi, int ni, int ci, CompressionStream.VertexCopy vc) {
/* 1576 */       pi *= 3;
/* 1577 */       if (this.positionsF != null) {
/* 1578 */         vc.p = new Point3f(this.positionsF[(pi + 0)], this.positionsF[(pi + 1)], this.positionsF[(pi + 2)]);
/*      */       }
/*      */       else
/*      */       {
/* 1583 */         vc.p = new Point3f((float)this.positionsD[(pi + 0)], (float)this.positionsD[(pi + 1)], (float)this.positionsD[(pi + 2)]);
/*      */       }
/*      */
/* 1588 */       ni *= 3;
/* 1589 */       if (CompressionStream.this.vertexNormals) {
/* 1590 */         vc.n = new Vector3f(this.normals[(ni + 0)], this.normals[(ni + 1)], this.normals[(ni + 2)]);
/*      */       }
/*      */
/* 1595 */       if (CompressionStream.this.vertexColor3) {
/* 1596 */         ci *= 3;
/* 1597 */         if (this.colorsB != null) {
/* 1598 */           vc.c3 = new Color3f((this.colorsB[(ci + 0)] & 0xFF) * 0.003921569F, (this.colorsB[(ci + 1)] & 0xFF) * 0.003921569F, (this.colorsB[(ci + 2)] & 0xFF) * 0.003921569F);
/*      */         }
/*      */         else
/*      */         {
/* 1604 */           vc.c3 = new Color3f(this.colorsF[(ci + 0)], this.colorsF[(ci + 1)], this.colorsF[(ci + 2)]);
/*      */         }
/*      */
/* 1608 */         vc.c = vc.c3;
/*      */       }
/* 1610 */       else if (CompressionStream.this.vertexColor4) {
/* 1611 */         ci *= 4;
/* 1612 */         if (this.colorsB != null) {
/* 1613 */           vc.c4 = new Color4f((this.colorsB[(ci + 0)] & 0xFF) * 0.003921569F, (this.colorsB[(ci + 1)] & 0xFF) * 0.003921569F, (this.colorsB[(ci + 2)] & 0xFF) * 0.003921569F, (this.colorsB[(ci + 3)] & 0xFF) * 0.003921569F);
/*      */         }
/*      */         else
/*      */         {
/* 1620 */           vc.c4 = new Color4f(this.colorsF[(ci + 0)], this.colorsF[(ci + 1)], this.colorsF[(ci + 2)], this.colorsF[(ci + 3)]);
/*      */         }
/*      */
/* 1625 */         vc.c = vc.c4;
/*      */       }
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1630 */       copyVertex(v + this.initialPositionIndex, v + this.initialNormalIndex, v + this.initialColorIndex, this.vc);
/*      */
/* 1634 */       CompressionStream.this.processVertexCopy(this.vc, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class IndexedInterleavedGeometryNIO extends CompressionStream.InterleavedGeometryNIO
/*      */   {
/* 1499 */     CompressionStream.IndexArrays ia = new CompressionStream.IndexArrays(null);
/* 1500 */     CompressionStream.VertexIndices vi = new CompressionStream.VertexIndices(null);
/*      */
/*      */     IndexedInterleavedGeometryNIO(GeometryArray ga) {
/* 1503 */       super(ga);
/* 1504 */       CompressionStream.this.getIndexArrays(ga, this.ia);
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1508 */       CompressionStream.this.getVertexIndices(v, this.ia, this.vi);
/* 1509 */       copyVertex(this.vi.pi, this.vi.ni, this.vi.ci, this.vc);
/* 1510 */       CompressionStream.this.processIndexedVertexCopy(this.vc, this.vi, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class InterleavedGeometryNIO extends CompressionStream.InterleavedGeometry
/*      */   {
/* 1448 */     FloatBufferWrapper fbw = null;
/*      */
/*      */     InterleavedGeometryNIO(GeometryArray ga) {
/* 1451 */       super(ga);
/* 1452 */       J3DBuffer buffer = ga.getInterleavedVertexBuffer();
/* 1453 */       if (BufferWrapper.getBufferType(buffer) == 3)
/*      */       {
/* 1455 */         this.fbw = new FloatBufferWrapper(buffer);
/*      */       }
/*      */       else
/* 1458 */         throw new IllegalArgumentException("\ninterleaved vertex buffer must be FloatBuffer");
/*      */     }
/*      */
/*      */     void copyVertex(int pi, int ni, int ci, CompressionStream.VertexCopy vc)
/*      */     {
/* 1465 */       int voffset = pi * this.vstride;
/* 1466 */       vc.p = new Point3f(this.fbw.get(voffset + this.poffset + 0), this.fbw.get(voffset + this.poffset + 1), this.fbw.get(voffset + this.poffset + 2));
/*      */
/* 1470 */       if (CompressionStream.this.vertexNormals) {
/* 1471 */         voffset = ni * this.vstride;
/* 1472 */         vc.n = new Vector3f(this.fbw.get(voffset + this.noffset + 0), this.fbw.get(voffset + this.noffset + 1), this.fbw.get(voffset + this.noffset + 2));
/*      */       }
/*      */
/* 1476 */       if (CompressionStream.this.vertexColor3) {
/* 1477 */         voffset = ci * this.vstride;
/* 1478 */         vc.c3 = new Color3f(this.fbw.get(voffset + this.coffset + 0), this.fbw.get(voffset + this.coffset + 1), this.fbw.get(voffset + this.coffset + 2));
/*      */
/* 1481 */         vc.c = vc.c3;
/*      */       }
/* 1483 */       else if (CompressionStream.this.vertexColor4) {
/* 1484 */         voffset = ci * this.vstride;
/* 1485 */         vc.c4 = new Color4f(this.fbw.get(voffset + this.coffset + 0), this.fbw.get(voffset + this.coffset + 1), this.fbw.get(voffset + this.coffset + 2), this.fbw.get(voffset + this.coffset + 3));
/*      */
/* 1489 */         vc.c = vc.c4;
/*      */       }
/*      */     }
/*      */   }
/*      */
/*      */   private class IndexedInterleavedGeometryFloat extends CompressionStream.InterleavedGeometryFloat
/*      */   {
/* 1428 */     CompressionStream.IndexArrays ia = new CompressionStream.IndexArrays(null);
/* 1429 */     CompressionStream.VertexIndices vi = new CompressionStream.VertexIndices(null);
/*      */
/*      */     IndexedInterleavedGeometryFloat(GeometryArray ga) {
/* 1432 */       super(ga);
/* 1433 */       CompressionStream.this.getIndexArrays(ga, this.ia);
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1437 */       CompressionStream.this.getVertexIndices(v, this.ia, this.vi);
/* 1438 */       copyVertex(this.vi.pi, this.vi.ni, this.vi.ci, this.vc);
/* 1439 */       CompressionStream.this.processIndexedVertexCopy(this.vc, this.vi, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private class InterleavedGeometryFloat extends CompressionStream.InterleavedGeometry
/*      */   {
/* 1383 */     float[] vdata = null;
/*      */
/*      */     InterleavedGeometryFloat(GeometryArray ga) {
/* 1386 */       super(ga);
/* 1387 */       this.vdata = ga.getInterleavedVertices();
/*      */     }
/*      */
/*      */     void copyVertex(int pi, int ni, int ci, CompressionStream.VertexCopy vc)
/*      */     {
/* 1392 */       int voffset = pi * this.vstride;
/* 1393 */       vc.p = new Point3f(this.vdata[(voffset + this.poffset + 0)], this.vdata[(voffset + this.poffset + 1)], this.vdata[(voffset + this.poffset + 2)]);
/*      */
/* 1397 */       if (CompressionStream.this.vertexNormals) {
/* 1398 */         voffset = ni * this.vstride;
/* 1399 */         vc.n = new Vector3f(this.vdata[(voffset + this.noffset + 0)], this.vdata[(voffset + this.noffset + 1)], this.vdata[(voffset + this.noffset + 2)]);
/*      */       }
/*      */
/* 1403 */       if (CompressionStream.this.vertexColor3) {
/* 1404 */         voffset = ci * this.vstride;
/* 1405 */         vc.c3 = new Color3f(this.vdata[(voffset + this.coffset + 0)], this.vdata[(voffset + this.coffset + 1)], this.vdata[(voffset + this.coffset + 2)]);
/*      */
/* 1408 */         vc.c = vc.c3;
/*      */       }
/* 1410 */       else if (CompressionStream.this.vertexColor4) {
/* 1411 */         voffset = ci * this.vstride;
/* 1412 */         vc.c4 = new Color4f(this.vdata[(voffset + this.coffset + 0)], this.vdata[(voffset + this.coffset + 1)], this.vdata[(voffset + this.coffset + 2)], this.vdata[(voffset + this.coffset + 3)]);
/*      */
/* 1416 */         vc.c = vc.c4;
/*      */       }
/*      */     }
/*      */   }
/*      */
/*      */   private abstract class InterleavedGeometry
/*      */     implements CompressionStream.GeometryAccessor
/*      */   {
/* 1336 */     CompressionStream.VertexCopy vc = new CompressionStream.VertexCopy(null);
/*      */
/* 1338 */     int vstride = 0;
/* 1339 */     int coffset = 0;
/* 1340 */     int noffset = 0;
/* 1341 */     int poffset = 0;
/* 1342 */     int tstride = 0;
/* 1343 */     int tcount = 0;
/*      */
/*      */     InterleavedGeometry(GeometryArray ga) {
/* 1346 */       if (CompressionStream.this.vertexTextures) {
/* 1347 */         if (CompressionStream.this.vertexTexture2) this.tstride = 2;
/* 1348 */         else if (CompressionStream.this.vertexTexture3) this.tstride = 3;
/* 1349 */         else if (CompressionStream.this.vertexTexture4) this.tstride = 4;
/*      */
/* 1351 */         this.tcount = ga.getTexCoordSetCount();
/* 1352 */         this.vstride += this.tcount * this.tstride;
/*      */       }
/*      */
/* 1355 */       if (CompressionStream.this.vertexColors) {
/* 1356 */         this.coffset = this.vstride;
/* 1357 */         if (CompressionStream.this.vertexColor3) this.vstride += 3; else {
/* 1358 */           this.vstride += 4;
/*      */         }
/*      */       }
/* 1361 */       if (CompressionStream.this.vertexNormals) {
/* 1362 */         this.noffset = this.vstride;
/* 1363 */         this.vstride += 3;
/*      */       }
/*      */
/* 1366 */       this.poffset = this.vstride;
/* 1367 */       this.vstride += 3;
/*      */     }
/*      */
/*      */     abstract void copyVertex(int paramInt1, int paramInt2, int paramInt3, CompressionStream.VertexCopy paramVertexCopy);
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1373 */       copyVertex(v, v, v, this.vc);
/* 1374 */       CompressionStream.this.processVertexCopy(this.vc, stripFlag);
/*      */     }
/*      */   }
/*      */
/*      */   private static class VertexCopy
/*      */   {
/* 1270 */     Object c = null;
/* 1271 */     Point3f p = null;
/* 1272 */     Vector3f n = null;
/* 1273 */     Color3f c3 = null;
/* 1274 */     Color4f c4 = null;
/*      */
/*      */     private VertexCopy()
/*      */     {
/*      */     }
/*      */
/*      */     VertexCopy(CompressionStream.1 x0)
/*      */     {
/* 1269 */       this();
/*      */     }
/*      */   }
/*      */
/*      */   private class IndexedByCopyGeometry extends CompressionStream.ByCopyGeometry
/*      */   {
/* 1225 */     CompressionStream.IndexArrays ia = new CompressionStream.IndexArrays(null);
/* 1226 */     CompressionStream.VertexIndices vi = new CompressionStream.VertexIndices(null);
/*      */
/*      */     IndexedByCopyGeometry(GeometryArray ga) {
/* 1229 */       super(ga, 0, ga.getVertexCount());
/* 1230 */       CompressionStream.this.getIndexArrays(ga, this.ia);
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1234 */       CompressionStream.this.getVertexIndices(v, this.ia, this.vi);
/* 1235 */       int r = CompressionStream.this.meshBuffer.getMeshReference(this.vi.pi);
/*      */
/* 1237 */       if ((r == -1) || ((CompressionStream.this.vertexNormals) && (this.vi.ni != CompressionStream.this.meshBuffer.getNormalIndex(r))))
/*      */       {
/* 1241 */         Point3f p = this.positions[this.vi.pi];
/* 1242 */         Vector3f n = CompressionStream.this.vertexNormals ? this.normals[this.vi.ni] : null;
/* 1243 */         Object c = CompressionStream.this.vertexColor4 ? this.colors4[this.vi.ci] : CompressionStream.this.vertexColor3 ? this.colors3[this.vi.ci] : null;
/*      */
/* 1246 */         CompressionStream.this.addVertex(p, n, c, stripFlag, 1);
/* 1247 */         CompressionStream.this.meshBuffer.push(this.vi.pi, this.vi.ci, this.vi.ni);
/*      */       }
/*      */       else {
/* 1250 */         if ((!CompressionStream.this.vertexNormals) || (
/* 1254 */           (CompressionStream.this.vertexColor3) && (this.vi.ci != CompressionStream.this.meshBuffer.getColorIndex(r)))) {
/* 1255 */           CompressionStream.this.addColor(this.colors3[this.vi.ci]);
/*      */         }
/* 1257 */         else if ((CompressionStream.this.vertexColor4) && (this.vi.ci != CompressionStream.this.meshBuffer.getColorIndex(r))) {
/* 1258 */           CompressionStream.this.addColor(this.colors4[this.vi.ci]);
/*      */         }
/* 1260 */         CompressionStream.this.addMeshReference(stripFlag, r);
/*      */       }
/*      */     }
/*      */   }
/*      */
/*      */   private static class VertexIndices
/*      */   {
/*      */     int pi;
/*      */     int ni;
/*      */     int ci;
/*      */
/*      */     private VertexIndices()
/*      */     {
/*      */     }
/*      */
/*      */     VertexIndices(CompressionStream.1 x0)
/*      */     {
/* 1204 */       this();
/*      */     }
/*      */   }
/*      */
/*      */   private static class IndexArrays
/*      */   {
/* 1155 */     int[] colorIndices = null;
/* 1156 */     int[] normalIndices = null;
/* 1157 */     int[] positionIndices = null;
/*      */
/*      */     private IndexArrays()
/*      */     {
/*      */     }
/*      */
/*      */     IndexArrays(CompressionStream.1 x0)
/*      */     {
/* 1154 */       this();
/*      */     }
/*      */   }
/*      */
/*      */   private class ByCopyGeometry
/*      */     implements CompressionStream.GeometryAccessor
/*      */   {
/* 1076 */     Point3f[] positions = null;
/* 1077 */     Vector3f[] normals = null;
/* 1078 */     Color3f[] colors3 = null;
/* 1079 */     Color4f[] colors4 = null;
/*      */
/*      */     ByCopyGeometry(GeometryArray ga) {
/* 1082 */       this(ga, ga.getInitialVertexIndex(), ga.getValidVertexCount());
/*      */     }
/*      */
/*      */     ByCopyGeometry(GeometryArray ga, int firstVertex, int validVertexCount)
/*      */     {
/* 1088 */       this.positions = new Point3f[validVertexCount];
/* 1089 */       for (int i = 0; i < validVertexCount; i++) {
/* 1090 */         this.positions[i] = new Point3f();
/*      */       }
/* 1092 */       ga.getCoordinates(firstVertex, this.positions);
/*      */
/* 1094 */       if (CompressionStream.this.vertexNormals) {
/* 1095 */         this.normals = new Vector3f[validVertexCount];
/* 1096 */         for (i = 0; i < validVertexCount; i++) {
/* 1097 */           this.normals[i] = new Vector3f();
/*      */         }
/* 1099 */         ga.getNormals(firstVertex, this.normals);
/*      */       }
/*      */
/* 1102 */       if (CompressionStream.this.vertexColor3) {
/* 1103 */         this.colors3 = new Color3f[validVertexCount];
/* 1104 */         for (i = 0; i < validVertexCount; i++) {
/* 1105 */           this.colors3[i] = new Color3f();
/*      */         }
/* 1107 */         ga.getColors(firstVertex, this.colors3);
/*      */       }
/* 1109 */       else if (CompressionStream.this.vertexColor4) {
/* 1110 */         this.colors4 = new Color4f[validVertexCount];
/* 1111 */         for (i = 0; i < validVertexCount; i++) {
/* 1112 */           this.colors4[i] = new Color4f();
/*      */         }
/* 1114 */         ga.getColors(firstVertex, this.colors4);
/*      */       }
/*      */     }
/*      */
/*      */     public void processVertex(int v, int stripFlag) {
/* 1119 */       Point3f p = this.positions[v];
/* 1120 */       int r = CompressionStream.this.meshBuffer.getMeshReference(p);
/*      */
/* 1122 */       if ((r == -1) || ((CompressionStream.this.vertexNormals) && (!this.normals[v].equals(CompressionStream.this.meshBuffer.getNormal(r)))))
/*      */       {
/* 1126 */         Vector3f n = CompressionStream.this.vertexNormals ? this.normals[v] : null;
/* 1127 */         Object c = CompressionStream.this.vertexColor4 ? this.colors4[v] : CompressionStream.this.vertexColor3 ? this.colors3[v] : null;
/*      */
/* 1130 */         CompressionStream.this.addVertex(p, n, c, stripFlag, 1);
/* 1131 */         CompressionStream.this.meshBuffer.push(p, c, n);
/*      */       }
/*      */       else {
/* 1134 */         if ((!CompressionStream.this.vertexNormals) || (
/* 1138 */           (CompressionStream.this.vertexColor3) && (!this.colors3[v].equals(CompressionStream.this.meshBuffer.getColor3(r)))))
/*      */         {
/* 1140 */           CompressionStream.this.addColor(this.colors3[v]);
/*      */         }
/* 1142 */         else if ((CompressionStream.this.vertexColor4) && (!this.colors4[v].equals(CompressionStream.this.meshBuffer.getColor4(r))))
/*      */         {
/* 1144 */           CompressionStream.this.addColor(this.colors4[v]);
/*      */         }
/* 1146 */         CompressionStream.this.addMeshReference(stripFlag, r);
/*      */       }
/*      */     }
/*      */   }
/*      */
/*      */   private static abstract interface GeometryAccessor
/*      */   {
/*      */     public abstract void processVertex(int paramInt1, int paramInt2);
/*      */   }
/*      */
/*      */   private class MeshReference extends CompressionStreamElement
/*      */   {
/*      */     int stripFlag;
/*      */     int meshIndex;
/*      */
/*      */     MeshReference(int stripFlag, int meshIndex)
/*      */     {
/*  747 */       this.stripFlag = stripFlag;
/*  748 */       this.meshIndex = meshIndex;
/*  749 */       CompressionStream.this.meshReferenceCount += 1;
/*      */     }
/*      */
/*      */     void quantize(CompressionStream s, HuffmanTable t)
/*      */     {
/*  755 */       CompressionStreamVertex v = CompressionStream.this.meshBuffer.getVertex(this.meshIndex);
/*  756 */       CompressionStream.this.lastPosition[0] = v.xAbsolute;
/*  757 */       CompressionStream.this.lastPosition[1] = v.yAbsolute;
/*  758 */       CompressionStream.this.lastPosition[2] = v.zAbsolute;
/*      */
/*  762 */       if ((v.color != null) && (!CompressionStream.this.lastElementColor) && ((!CompressionStream.this.lastElementNormal) || (!CompressionStream.this.lastLastElementColor)))
/*      */       {
/*  764 */         CompressionStream.this.lastColor[0] = v.color.rAbsolute;
/*  765 */         CompressionStream.this.lastColor[1] = v.color.gAbsolute;
/*  766 */         CompressionStream.this.lastColor[2] = v.color.bAbsolute;
/*  767 */         CompressionStream.this.lastColor[3] = v.color.aAbsolute;
/*      */       }
/*      */
/*  772 */       if ((v.normal != null) && (!CompressionStream.this.lastElementNormal) && ((!CompressionStream.this.lastElementColor) || (!CompressionStream.this.lastLastElementNormal)))
/*      */       {
/*  774 */         CompressionStream.this.lastSextant = v.normal.sextant;
/*  775 */         CompressionStream.this.lastOctant = v.normal.octant;
/*  776 */         CompressionStream.this.lastU = v.normal.uAbsolute;
/*  777 */         CompressionStream.this.lastV = v.normal.vAbsolute;
/*  778 */         CompressionStream.this.lastSpecialNormal = v.normal.specialNormal;
/*      */       }
/*      */     }
/*      */
/*      */     void outputCommand(HuffmanTable t, CommandStream outputBuffer) {
/*  783 */       int command = 32;
/*  784 */       long data = this.stripFlag & 0x1;
/*      */
/*  786 */       command |= (this.meshIndex & 0xF) << 1 | this.stripFlag >> 1;
/*  787 */       outputBuffer.addCommand(command, 8, data, 1);
/*      */     }
/*      */
/*      */     public String toString() {
/*  791 */       return "meshReference: stripFlag " + this.stripFlag + " meshIndex " + this.meshIndex;
/*      */     }
/*      */   }
/*      */
/*      */   private class ColorQuant extends CompressionStreamElement
/*      */   {
/*      */     int value;
/*      */
/*      */     ColorQuant(int value)
/*      */     {
/*  727 */       this.value = value;
/*      */     }
/*      */
/*      */     void quantize(CompressionStream s, HuffmanTable t) {
/*  731 */       CompressionStream.this.colorQuant = this.value;
/*  732 */       CompressionStream.this.colorQuantChanged = true;
/*      */     }
/*      */
/*      */     public String toString() {
/*  736 */       return "colorQuant: " + this.value;
/*      */     }
/*      */   }
/*      */
/*      */   private class NormalQuant extends CompressionStreamElement
/*      */   {
/*      */     int value;
/*      */
/*      */     NormalQuant(int value)
/*      */     {
/*  707 */       this.value = value;
/*      */     }
/*      */
/*      */     void quantize(CompressionStream s, HuffmanTable t) {
/*  711 */       CompressionStream.this.normalQuant = this.value;
/*  712 */       CompressionStream.this.normalQuantChanged = true;
/*      */     }
/*      */
/*      */     public String toString() {
/*  716 */       return "normalQuant: " + this.value;
/*      */     }
/*      */   }
/*      */
/*      */   private class PositionQuant extends CompressionStreamElement
/*      */   {
/*      */     int value;
/*      */
/*      */     PositionQuant(int value)
/*      */     {
/*  683 */       this.value = value;
/*      */     }
/*      */
/*      */     void quantize(CompressionStream s, HuffmanTable t) {
/*  687 */       CompressionStream.this.positionQuant = this.value;
/*  688 */       CompressionStream.this.positionQuantChanged = true;
/*      */
/*  691 */       CompressionStream.this.scale = (2.0D / CompressionStream.this.positionRangeMaximum * (((1 << this.value - 1) - 1) / (1 << this.value - 1)));
/*      */     }
/*      */
/*      */     public String toString()
/*      */     {
/*  696 */       return "positionQuant: " + this.value;
/*      */     }
/*      */   }
/*      */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.utils.compression.CompressionStream
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.utils.compression.CompressionStream$IndexedByRefGeometryNIO

TOP
Copyright © 2018 www.massapi.com. 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.