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

📄 compressionstream.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		vc.c = vc.c4 ;	    }	}	public void processVertex(int v, int stripFlag) {	    copyVertex(v + initialPositionIndex,		       v + initialNormalIndex,		       v + initialColorIndex, vc) ;	    processVertexCopy(vc, stripFlag) ;	}    }    /**     * This class implements the GeometryAccessor interface for indexed     * non-interleaved geometry arrays accessed with by-reference semantics.     */    private class IndexedByRefGeometry extends ByRefGeometry {	IndexArrays ia = new IndexArrays() ;	VertexIndices vi = new VertexIndices() ;	IndexedByRefGeometry(GeometryArray ga) {	    super(ga) ;	    getIndexArrays(ga, ia) ;	}	public void processVertex(int v, int stripFlag) {	    getVertexIndices(v, ia, vi) ;	    copyVertex(vi.pi, vi.ni, vi.ci, vc) ;	    processIndexedVertexCopy(vc, vi, stripFlag) ;	}    }    /**     * This class implements the GeometryAccessor interface for     * non-interleaved geometry arrays accessed with NIO.     */    private class ByRefGeometryNIO implements GeometryAccessor {	VertexCopy vc = new VertexCopy() ;	ByteBufferWrapper   colorsB    = null ;	FloatBufferWrapper  colorsF    = null ;	FloatBufferWrapper  normals    = null ;	FloatBufferWrapper  positionsF = null ;	DoubleBufferWrapper positionsD = null ;	int initialPositionIndex = 0 ;	int initialNormalIndex   = 0 ;	int initialColorIndex    = 0 ;	ByRefGeometryNIO(GeometryArray ga) {	    J3DBuffer buffer ;	    buffer = ga.getCoordRefBuffer() ;	    initialPositionIndex = ga.getInitialCoordIndex() ;	    switch (BufferWrapper.getBufferType(buffer)) {	    case BufferWrapper.TYPE_FLOAT:		positionsF = new FloatBufferWrapper(buffer) ;		if (debug) System.out.println("float positions buffer") ;		break ;	    case BufferWrapper.TYPE_DOUBLE:		positionsD = new DoubleBufferWrapper(buffer) ;		if (debug) System.out.println("double positions buffer") ;		break ;	    default:		throw new IllegalArgumentException		    ("\nposition buffer must be FloatBuffer or DoubleBuffer") ;	    }	    if (vertexColors) {		buffer = ga.getColorRefBuffer() ;		initialColorIndex = ga.getInitialColorIndex() ;				switch (BufferWrapper.getBufferType(buffer)) {		case BufferWrapper.TYPE_BYTE:		    colorsB = new ByteBufferWrapper(buffer) ;		    if (debug) System.out.println("byte colors buffer") ;		    break ;		case BufferWrapper.TYPE_FLOAT:		    colorsF = new FloatBufferWrapper(buffer) ;		    if (debug) System.out.println("float colors buffer") ;		    break ;		default:		    throw new IllegalArgumentException			("\ncolor buffer must be ByteBuffer or FloatBuffer") ;		}	    }	    if (vertexNormals) {		buffer = ga.getNormalRefBuffer() ;		initialNormalIndex = ga.getInitialNormalIndex() ;		switch (BufferWrapper.getBufferType(buffer)) {		case BufferWrapper.TYPE_FLOAT:		    normals = new FloatBufferWrapper(buffer) ;		    if (debug) System.out.println("float normals buffer") ;		    break ;		default:		    throw new IllegalArgumentException			("\nnormal buffer must be FloatBuffer") ;		}	    }	}	void copyVertex(int pi, int ni, int ci, VertexCopy vc) {	    pi *= 3 ;	    if (positionsF != null) {		vc.p = new Point3f(positionsF.get(pi + 0),				   positionsF.get(pi + 1),				   positionsF.get(pi + 2)) ;	    }	    else {		vc.p = new Point3f((float)positionsD.get(pi + 0),				   (float)positionsD.get(pi + 1),				   (float)positionsD.get(pi + 2)) ;	    }	    ni *= 3 ;	    if (vertexNormals) {		vc.n = new Vector3f(normals.get(ni + 0),				    normals.get(ni + 1),				    normals.get(ni + 2)) ;	    }	    if (vertexColor3) {		ci *= 3 ;		if (colorsB != null) {		    vc.c3 = new Color3f			((colorsB.get(ci + 0) & 0xff) * ByteToFloatScale,			 (colorsB.get(ci + 1) & 0xff) * ByteToFloatScale,			 (colorsB.get(ci + 2) & 0xff) * ByteToFloatScale) ;		}		else {		    vc.c3 = new Color3f(colorsF.get(ci + 0),					colorsF.get(ci + 1),					colorsF.get(ci + 2)) ;		}		vc.c = vc.c3 ;	    }	    else if (vertexColor4) {		ci *= 4 ;		if (colorsB != null) {		    vc.c4 = new Color4f			((colorsB.get(ci + 0) & 0xff) * ByteToFloatScale,			 (colorsB.get(ci + 1) & 0xff) * ByteToFloatScale,			 (colorsB.get(ci + 2) & 0xff) * ByteToFloatScale,			 (colorsB.get(ci + 3) & 0xff) * ByteToFloatScale) ;		}		else {		    vc.c4 = new Color4f(colorsF.get(ci + 0),					colorsF.get(ci + 1),					colorsF.get(ci + 2),					colorsF.get(ci + 3)) ;		}		vc.c = vc.c4 ;	    }	}	public void processVertex(int v, int stripFlag) {	    copyVertex(v + initialPositionIndex,		       v + initialNormalIndex,		       v + initialColorIndex, vc) ;	    processVertexCopy(vc, stripFlag) ;	}    }    /**     * This class implements the GeometryAccessor interface for     * non-interleaved indexed geometry arrays accessed with NIO.     */    private class IndexedByRefGeometryNIO extends ByRefGeometryNIO {	IndexArrays ia = new IndexArrays() ;	VertexIndices vi = new VertexIndices() ;	IndexedByRefGeometryNIO(GeometryArray ga) {	    super(ga) ;	    getIndexArrays(ga, ia) ;	}	public void processVertex(int v, int stripFlag) {	    getVertexIndices(v, ia, vi) ;	    copyVertex(vi.pi, vi.ni, vi.ci, vc) ;	    processIndexedVertexCopy(vc, vi, stripFlag) ;	}    }    /**     * Convert a GeometryArray to compression stream elements and add them to     * this stream.     *     * @param ga GeometryArray to convert     * @exception IllegalArgumentException if GeometryArray has a     * dimensionality or vertex format inconsistent with the CompressionStream     */    void addGeometryArray(GeometryArray ga) {	int firstVertex = 0 ;	int validVertexCount = 0 ;	int vertexFormat = ga.getVertexFormat() ;	GeometryAccessor geometryAccessor = null ;	if (streamType != getStreamType(ga))	    throw new IllegalArgumentException		("GeometryArray has inconsistent dimensionality") ;	if (vertexComponents != getVertexComponents(vertexFormat))	    throw new IllegalArgumentException		("GeometryArray has inconsistent vertex components") ;	// Set up for vertex data access semantics.	boolean NIO = (vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0 ;	boolean byRef = (vertexFormat & GeometryArray.BY_REFERENCE) != 0 ;	boolean interleaved = (vertexFormat & GeometryArray.INTERLEAVED) != 0 ;	boolean indexedGeometry = ga instanceof IndexedGeometryArray ;	if (indexedGeometry) {	    if (debug) System.out.println("indexed") ;	    // Index arrays will be copied such that valid indices start at	    // offset 0 in the copied arrays.	    firstVertex = 0 ;	    validVertexCount = ((IndexedGeometryArray)ga).getValidIndexCount() ;	}	if (!byRef) {	    if (debug) System.out.println("by-copy") ;	    if (indexedGeometry) {		geometryAccessor = new IndexedByCopyGeometry(ga) ;	    }	    else {		firstVertex = 0 ;		validVertexCount = ga.getValidVertexCount() ;		geometryAccessor = new ByCopyGeometry(ga) ;	    }	}	else if (interleaved && NIO) {	    if (debug) System.out.println("interleaved NIO") ;	    if (indexedGeometry) {		geometryAccessor = new IndexedInterleavedGeometryNIO(ga) ;	    }	    else {		firstVertex = ga.getInitialVertexIndex() ;		validVertexCount = ga.getValidVertexCount() ;		geometryAccessor = new InterleavedGeometryNIO(ga) ;	    }	}	else if (interleaved && !NIO) {	    if (debug) System.out.println("interleaved") ;	    if (indexedGeometry) {		geometryAccessor = new IndexedInterleavedGeometryFloat(ga) ;	    }	    else {		firstVertex = ga.getInitialVertexIndex() ;		validVertexCount = ga.getValidVertexCount() ;		geometryAccessor = new InterleavedGeometryFloat(ga) ;	    }	}	else if (!interleaved && NIO) {	    if (debug) System.out.println("non-interleaved NIO") ;	    if (indexedGeometry) {		geometryAccessor = new IndexedByRefGeometryNIO(ga) ;	    }	    else {		firstVertex = 0 ;		validVertexCount = ga.getValidVertexCount() ;		geometryAccessor = new ByRefGeometryNIO(ga) ;	    }	}	else if (!interleaved && !NIO) {	    if (debug) System.out.println("non-interleaved by-ref") ;	    if (indexedGeometry) {		geometryAccessor = new IndexedByRefGeometry(ga) ;	    }	    else {		firstVertex = 0 ;		validVertexCount = ga.getValidVertexCount() ;		geometryAccessor = new ByRefGeometry(ga) ;	    }	}	// Set up for topology.	int stripCount = 0 ;	int stripCounts[] = null ;	int constantStripLength = 0 ;	int replaceCode = RESTART ;	boolean strips = false ;	boolean implicitStrips = false ;	if (ga instanceof TriangleStripArray ||	    ga instanceof IndexedTriangleStripArray ||	    ga instanceof LineStripArray ||	    ga instanceof IndexedLineStripArray) {	    strips = true ;	    replaceCode = REPLACE_OLDEST ;	    if (debug) System.out.println("strips") ;	}	else if (ga instanceof TriangleFanArray ||		 ga instanceof IndexedTriangleFanArray) {	    	    strips = true ;	    replaceCode = REPLACE_MIDDLE ;	    if (debug) System.out.println("fans") ;	}	else if (ga instanceof QuadArray ||		 ga instanceof IndexedQuadArray) {	    // Handled as fan arrays with 4 vertices per fan.	    implicitStrips = true ;	    constantStripLength = 4 ;	    replaceCode = REPLACE_MIDDLE ;	    if (debug) System.out.println("quads") ;	}	// Get strip counts.	if (strips) {	    if (indexedGeometry) {		IndexedGeometryStripArray igsa ;		igsa = (IndexedGeometryStripArray)ga ;		stripCount = igsa.getNumStrips() ;		stripCounts = new int[stripCount] ;		igsa.getStripIndexCounts(stripCounts) ;	    } else {		GeometryStripArray gsa ;		gsa = (GeometryStripArray)ga ;		stripCount = gsa.getNumStrips() ;		stripCounts = new int[stripCount] ;		gsa.getStripVertexCounts(stripCounts) ;	    }	}	// Build the compression stream for this shape's geometry.	int v = firstVertex ;	if (strips) {	    for (int i = 0 ; i < stripCount ; i++) {		geometryAccessor.processVertex(v++, RESTART) ;		for (int j = 1 ; j < stripCounts[i] ; j++) {		    geometryAccessor.processVertex(v++, replaceCode) ;		}	    }	}	else if (implicitStrips) {	    while (v < firstVertex + validVertexCount) {		geometryAccessor.processVertex(v++, RESTART) ;		for (int j = 1 ; j < constantStripLength ; j++) {		    geometryAccessor.processVertex(v++, replaceCode) ;		}	    }	}	else {	    while (v < firstVertex + validVertexCount) {		geometryAccessor.processVertex(v++, RESTART) ;	    }	}    }    /**     * Print the stream to standard output.     */    void print() {	System.out.println("\nstream has " + stream.size() + " entries") ;	System.out.println("uncompressed size " + byteCount + " bytes") ;	System.out.println("upper position bound: " + mcBounds[1].toString()) ;	System.out.println("lower position bound: " + mcBounds[0].toString()) ;	System.out.println("X, Y, Z centers (" +			   ((float)center[0]) + " " +			   ((float)center[1]) + " " +			   ((float)center[2]) + ")\n" +			   "scale " + ((float)scale) + "\n") ;	Iterator i = stream.iterator() ;	while (i.hasNext()) {	    System.out.println(i.next().toString() + "\n") ;	}    }    ////////////////////////////////////////////////////////////////////////////    //									      //    // The following constructors and methods are currently the only public   //    // members of this class.  All other members are subject to revision.     //    //									      //    ////////////////////////////////////////////////////////////////////////////    /**     * Creates a CompressionStream from an array of Shape3D scene graph     * objects.  These Shape3D objects may only consist of a GeometryArray     * component and an optional Appearance component.  The resulting stream     * may be used as input to the GeometryCompressor methods.<p>     *     * Each Shape3D in the array must be of the same dimensionality (point,     * line, or surface) and have the same vertex format as the others.     * Texture coordinates are ignored.<p>     *     * If a color is specified in the material attributes for a Shape3D then     * that color is added to the CompressionStream as the current global     * color.  Subsequent colors as well as any colors bundled with vertices     * will override it.  Only the material diffuse colors are used; all other     * appearance attributes are ignored.<p>     *     * @param positionQuant     * number of bits to quantize each position's X, Y,     * and Z components, ranging from 1 to 16     *     * @param colorQuant     * number of bits to quantize each color's R, G, B, and     * alpha components, ranging from 2 to 16     *     * @pa

⌨️ 快捷键说明

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