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

📄 geometryarraystate.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			}			writeDoubleArray( out, data );		    } else if ( ((GeometryArray)node).getCoordRefFloat()!=null ) {			out.writeInt( FORMAT_FLOAT );			writeFloatArray( out, ((GeometryArray)node).getCoordRefFloat() );		    } else if ( ((GeometryArray)node).getCoordRefDouble()!=null ) {			out.writeInt( FORMAT_DOUBLE );			writeDoubleArray( out, ((GeometryArray)node).getCoordRefDouble() );		    } else out.writeInt( FORMAT_NULL );		} else {		    float[] points = new float[ vertexCount*3 ];		    ((GeometryArray)node).getCoordinates( 0, points );		    writeFloatArray( out, points );		}	    }	    if ((vertexFormat & GeometryArray.NORMALS)!=0) {		//System.out.println("NORMALS");		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			out.writeInt( ((GeometryArray)node).getInitialNormalIndex() );		    }		    if ( nio ) {			J3DBuffer buf = ((GeometryArray)node).getNormalRefBuffer();			if ( BufferWrapper.getBufferType( buf )==BufferWrapper.TYPE_NULL )			    out.writeInt( FORMAT_NULL );			else {			    out.writeInt( FORMAT_FLOAT );			    FloatBufferWrapper bb = new FloatBufferWrapper( buf );			    float[] floats = new float[ bb.limit() ];			    bb.position( 0 );			    bb.get( floats );			    writeFloatArray( out, floats );			}		    } else if ( ((GeometryArray)node).getNormalRef3f()!=null ) {			out.writeInt( FORMAT_3F );			Vector3f[] norms = ((GeometryArray)node).getNormalRef3f();			float[] data = new float[ norms.length*3 ];			for (int i = 0 ; i < norms.length ; i++) {			    data[ i*3+0 ] = norms[i].x;			    data[ i*3+1 ] = norms[i].y;			    data[ i*3+2 ] = norms[i].z;			}			writeFloatArray( out, data );		    } else if ( ((GeometryArray)node).getNormalRefFloat()!=null ) {		        out.writeInt( FORMAT_FLOAT );			writeFloatArray( out, ((GeometryArray)node).getNormalRefFloat() );		    } else out.writeInt( FORMAT_NULL );		} else {		    float[] normals = new float[ vertexCount*3 ];		    ((GeometryArray)node).getNormals( 0, normals );		    writeFloatArray( out, normals );		}	    }	    if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2)!=0) {		//System.out.println("TEXTURE COORDS 2");		for(int set=0; set<texCoordSetCount; set++) {		    if ( byRef ) {			if ( !(node instanceof IndexedGeometryArray) ) {			    out.writeInt( ((GeometryArray)node).getInitialTexCoordIndex( set ) );			}			if ( nio ) {			    J3DBuffer buf = ((GeometryArray)node).getTexCoordRefBuffer( set );			    if ( BufferWrapper.getBufferType( buf )==BufferWrapper.TYPE_NULL )				out.writeInt( FORMAT_NULL );			    else {				out.writeInt( FORMAT_FLOAT );				FloatBufferWrapper bb = new FloatBufferWrapper( buf );				float[] floats = new float[ bb.limit() ];				bb.position( 0 );				bb.get( floats );				writeFloatArray( out, floats );			    }			} else if ( ((GeometryArray)node).getTexCoordRef2f(set)!=null ) {			    out.writeInt( FORMAT_2F );			    TexCoord2f[] tcoords = ((GeometryArray)node).getTexCoordRef2f(set);			    float[] data = new float[ tcoords.length*2 ];			    for (int i = 0 ; i < tcoords.length ; i++) {				data[ i*2+0 ] = tcoords[i].x;				data[ i*2+1 ] = tcoords[i].y;			    }			    writeFloatArray( out, data );			} else if ( ((GeometryArray)node).getTexCoordRefFloat(set)!=null ) {			    out.writeInt( FORMAT_FLOAT );			    writeFloatArray( out, ((GeometryArray)node).getTexCoordRefFloat(set) );			} else out.writeInt( FORMAT_NULL );		    } else {			float[] textureCoords = new float[ vertexCount*2 ];			((GeometryArray)node).getTextureCoordinates( set, 0, textureCoords );			writeFloatArray( out, textureCoords );		    }		}	    } else if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3)!=0) {		//System.out.println("TEXTURE COORDS 3");		for(int set=0; set<texCoordSetCount; set++) {		    if ( byRef ) {			if ( !(node instanceof IndexedGeometryArray) ) {			    out.writeInt( ((GeometryArray)node).getInitialTexCoordIndex( set ) );			}			if ( nio ) {			    J3DBuffer buf = ((GeometryArray)node).getTexCoordRefBuffer( set );			    if ( BufferWrapper.getBufferType( buf )==BufferWrapper.TYPE_NULL )				out.writeInt( FORMAT_NULL );			    else {				out.writeInt( FORMAT_FLOAT );				FloatBufferWrapper bb = new FloatBufferWrapper( buf );				float[] floats = new float[ bb.limit() ];				bb.position( 0 );				bb.get( floats );				writeFloatArray( out, floats );			    }			} else if ( ((GeometryArray)node).getTexCoordRef3f(set)!=null ) {			    out.writeInt( FORMAT_3F );			    TexCoord3f[] tcoords = ((GeometryArray)node).getTexCoordRef3f(set);			    float[] data = new float[ tcoords.length*3 ];			    for (int i = 0 ; i < tcoords.length ; i++) {				data[ i*3+0 ] = tcoords[i].x;				data[ i*3+1 ] = tcoords[i].y;				data[ i*3+2 ] = tcoords[i].z;			    }			    writeFloatArray( out, data );			} else if ( ((GeometryArray)node).getTexCoordRefFloat(set)!=null ) {			    out.writeInt( FORMAT_FLOAT );			    writeFloatArray( out, ((GeometryArray)node).getTexCoordRefFloat(set) );			} else out.writeInt( FORMAT_NULL );		    } else {			float[] textureCoords = new float[ vertexCount*3 ];			((GeometryArray)node).getTextureCoordinates( set, 0, textureCoords );			writeFloatArray( out, textureCoords );		    }		}	    } else if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4)!=0) {		//System.out.println("TEXTURE COORDS 4");		for(int set=0; set<texCoordSetCount; set++) {		    if ( byRef ) {			if ( !(node instanceof IndexedGeometryArray) ) {			    out.writeInt( ((GeometryArray)node).getInitialTexCoordIndex( set ) );			}			if ( nio ) {			    J3DBuffer buf = ((GeometryArray)node).getTexCoordRefBuffer( set );			    if ( BufferWrapper.getBufferType( buf )==BufferWrapper.TYPE_NULL )				out.writeInt( FORMAT_NULL );			    else {				out.writeInt( FORMAT_FLOAT );				FloatBufferWrapper bb = new FloatBufferWrapper( buf );				float[] floats = new float[ bb.limit() ];				bb.position( 0 );				bb.get( floats );				writeFloatArray( out, floats );			    }			// There is no TexCoordRef4f			} else if ( ((GeometryArray)node).getTexCoordRefFloat(set)!=null ) {			    out.writeInt( FORMAT_FLOAT );			    writeFloatArray( out, ((GeometryArray)node).getTexCoordRefFloat(set) );			} else out.writeInt( FORMAT_NULL );		    } else {			float[] textureCoords = new float[ vertexCount*4 ];			((GeometryArray)node).getTextureCoordinates( set, 0, textureCoords );			writeFloatArray( out, textureCoords );		    }		}	    }	}    }    public void readObject( DataInput in ) throws IOException {        super.readObject( in );	boolean nio = (vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0;	if ( (vertexFormat & GeometryArray.INTERLEAVED)!=0 ) {	    if ( !(node instanceof IndexedGeometryArray) )  {		((GeometryArray)node).setInitialVertexIndex( in.readInt() );		if ( !(node instanceof GeometryStripArray) ) 		    ((GeometryArray)node).setValidVertexCount( in.readInt() );	    }	    if ( nio ) {		float[] floats = readFloatArray( in );		ByteBufferWrapper b = 		    ByteBufferWrapper.allocateDirect( floats.length*4 );		FloatBufferWrapper f =		    b.order( ByteOrderWrapper.nativeOrder() ).asFloatBuffer();		f.put( floats );		((GeometryArray)node).setInterleavedVertexBuffer( f.getJ3DBuffer() );	    } else ((GeometryArray)node).setInterleavedVertices( readFloatArray( in ) );	} else {	    boolean byRef = (vertexFormat & GeometryArray.BY_REFERENCE) != 0;	    // We MUST check for COLOR_4 before we check for COLOR_3,	    // because the COLOR_3 test will pass for COLOR_4 objects	    	    if ( !(node instanceof IndexedGeometryArray) ) {		if ( !byRef )		    ((GeometryArray)node).setInitialVertexIndex( in.readInt() );		if ( !(node instanceof GeometryStripArray) )		    ((GeometryArray)node).setValidVertexCount( in.readInt() );	    }	    if ( (vertexFormat & GeometryArray.COLOR_4)==GeometryArray.COLOR_4 ) {		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			((GeometryArray)node).setInitialColorIndex( in.readInt() );		    }		    if ( nio ) {			switch( in.readInt() ) {			case FORMAT_BYTE: {			    byte[] bytes = new byte[ in.readInt() ];			    in.readFully( bytes );			    ByteBufferWrapper b =				ByteBufferWrapper.allocateDirect( bytes.length );			    b.put( bytes );			    ((GeometryArray)node).setColorRefBuffer( b.getJ3DBuffer() );			}			break;			case FORMAT_FLOAT: {			    float[] floats = readFloatArray( in );			    ByteBufferWrapper b = 				ByteBufferWrapper.allocateDirect( floats.length*4 );			    FloatBufferWrapper f =				b.order( ByteOrderWrapper.nativeOrder() ).asFloatBuffer();			    f.put( floats );			    ((GeometryArray)node).setColorRefBuffer( f.getJ3DBuffer() );			}			break;			}		    } else {			switch( in.readInt() ) {			case FORMAT_4F: {			    float[] data = readFloatArray( in );			    Color4f[] colors = new Color4f[ data.length/4 ];			    for (int i = 0 ; i < colors.length ; i++) {				colors[i].x = data[ i*4+0 ];				colors[i].y = data[ i*4+1 ];				colors[i].z = data[ i*4+2 ];				colors[i].w = data[ i*4+3 ];			    }			    ((GeometryArray)node).setColorRef4f( colors );			}			break;			case FORMAT_FLOAT:			    ((GeometryArray)node).setColorRefFloat( readFloatArray( in ) );			break;			case FORMAT_BYTE: {			    byte[] data = new byte[ in.readInt() ];			    in.readFully( data );			    ((GeometryArray)node).setColorRefByte( data );			}			break;			case FORMAT_4B: {			    Color4b[] colors = new Color4b[ in.readInt() ];			    byte[] data = new byte[ colors.length*4 ];			    in.readFully( data );			    for (int i = 0 ; i < colors.length ; i++) {				colors[i].x = data[ i*4+0 ];				colors[i].y = data[ i*4+1 ];				colors[i].z = data[ i*4+2 ];				colors[i].w = data[ i*4+3 ];			    }			    ((GeometryArray)node).setColorRef4b( colors );			}			break;			}		    }		} else {		    // Not by-reference		    byte[] colors = new byte[ vertexCount*4 ];		    in.readFully( colors );		    ((GeometryArray)node).setColors( 0, colors );		}	    } else if ((vertexFormat & GeometryArray.COLOR_3)==GeometryArray.COLOR_3 ) {		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			((GeometryArray)node).setInitialColorIndex( in.readInt() );		    }		    if ( nio ) {			switch( in.readInt() ) {			case FORMAT_BYTE: {			    byte[] bytes = new byte[ in.readInt() ];			    in.readFully( bytes );			    ByteBufferWrapper b =				ByteBufferWrapper.allocateDirect( bytes.length );			    b.put( bytes );			    ((GeometryArray)node).setColorRefBuffer( b.getJ3DBuffer() );			}			break;			case FORMAT_FLOAT: {			    float[] floats = readFloatArray( in );			    ByteBufferWrapper b = 				ByteBufferWrapper.allocateDirect( floats.length*4 );			    FloatBufferWrapper f =				b.order( ByteOrderWrapper.nativeOrder() ).asFloatBuffer();			    f.put( floats );			    ((GeometryArray)node).setColorRefBuffer( f.getJ3DBuffer() );			}			break;			}		    } else {			switch( in.readInt() ) {			case FORMAT_3F: {			    float[] data = readFloatArray( in );			    Color3f[] colors = new Color3f[ data.length/3 ];			    for (int i = 0 ; i < colors.length ; i++) {

⌨️ 快捷键说明

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