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

📄 geometryarraystate.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				colors[i].x = data[ i*3+0 ];				colors[i].y = data[ i*3+1 ];				colors[i].z = data[ i*3+2 ];			    }			    ((GeometryArray)node).setColorRef3f( 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_3B: {			    Color3b[] colors = new Color3b[ in.readInt() ];			    byte[] data = new byte[ colors.length*3 ];			    in.readFully( data );			    for (int i = 0 ; i < colors.length ; i++) {				colors[i].x = data[ i*3+0 ];				colors[i].y = data[ i*3+1 ];				colors[i].z = data[ i*3+2 ];			    }			    ((GeometryArray)node).setColorRef3b( colors );			}			break;			}		    }		} else {		    // Not by-reference		    byte[] colors = new byte[ vertexCount*3 ];		    in.readFully( colors );		    ((GeometryArray)node).setColors( 0, colors );		}	    }	    if ((vertexFormat & GeometryArray.COORDINATES)!=0 ) {		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			((GeometryArray)node).setInitialCoordIndex( in.readInt() );		    }		    if ( nio ) {			switch( in.readInt() ) {			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).setCoordRefBuffer( f.getJ3DBuffer() );			}			break;			case FORMAT_DOUBLE: {			    double[] doubles = readDoubleArray( in );			    ByteBufferWrapper b = 				ByteBufferWrapper.allocateDirect( doubles.length*4 );			    DoubleBufferWrapper f =				b.order( ByteOrderWrapper.nativeOrder() ).asDoubleBuffer();			    f.put( doubles );			    ((GeometryArray)node).setCoordRefBuffer( f.getJ3DBuffer() );			}			break;			}		    } else {			switch( in.readInt() ) {			case FORMAT_3F: {			    float[] data = readFloatArray( in );			    Point3f[] coords = new Point3f[ data.length/3 ];			    for (int i = 0 ; i < coords.length ; i++) {				coords[i].x = data[ i*3+0 ];				coords[i].y = data[ i*3+1 ];				coords[i].z = data[ i*3+2 ];			    }			    ((GeometryArray)node).setCoordRef3f( coords );			}			break;			case FORMAT_3D: {			    double[] data = readDoubleArray( in );			    Point3d[] coords = new Point3d[ data.length/3 ];			    for (int i = 0 ; i < coords.length ; i++) {				coords[i].x = data[ i*3+0 ];				coords[i].y = data[ i*3+1 ];				coords[i].z = data[ i*3+2 ];			    }			    ((GeometryArray)node).setCoordRef3d( coords );			}			break;			case FORMAT_FLOAT:			    ((GeometryArray)node).setCoordRefFloat( readFloatArray( in ) );			break;			case FORMAT_DOUBLE:			    ((GeometryArray)node).setCoordRefDouble( readDoubleArray( in ) );			break;			}		    }		} else {		    // Not by-reference		    float[] points = readFloatArray( in );		    ((GeometryArray)node).setCoordinates( 0, points );		}	    }	    if ((vertexFormat & GeometryArray.NORMALS)!=0) {		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			((GeometryArray)node).setInitialNormalIndex( in.readInt() );		    }		    if ( nio ) {			if ( in.readInt() == 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).setNormalRefBuffer( f.getJ3DBuffer() );			}		    } else {			switch( in.readInt() ) {			case FORMAT_3F: {			    float[] data = readFloatArray( in );			    Vector3f[] norms = new Vector3f[ data.length/3 ];			    for (int i = 0 ; i < norms.length ; i++) {				norms[i].x = data[ i*3+0 ];				norms[i].y = data[ i*3+1 ];				norms[i].z = data[ i*3+2 ];			    }			    ((GeometryArray)node).setNormalRef3f( norms );			}			break;			case FORMAT_FLOAT:			    ((GeometryArray)node).setNormalRefFloat( readFloatArray( in ) );			break;			}		    }		} else {		    // Not by-reference		    float[] normals = readFloatArray( in );		    ((GeometryArray)node).setNormals( 0, normals );		}	    }	    if (((vertexFormat & GeometryArray.TEXTURE_COORDINATE_2) != 0) ||		((vertexFormat & GeometryArray.TEXTURE_COORDINATE_3) != 0) ||		((vertexFormat & GeometryArray.TEXTURE_COORDINATE_4) != 0)) {		if ( byRef ) {		    for(int set=0; set<texCoordSetCount; set++) {			if ( !(node instanceof IndexedGeometryArray) ) {			    ((GeometryArray)node).setInitialTexCoordIndex( set, in.readInt() );			}			if ( nio ) {			    if ( in.readInt() == 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).setTexCoordRefBuffer( set,				    f.getJ3DBuffer() );			    }			} else {			    switch( in.readInt() ) {			    case FORMAT_2F: {				float[] data = readFloatArray( in );				TexCoord2f[] tcoords = new TexCoord2f[ data.length/2 ];				for (int i = 0 ; i < tcoords.length ; i++) {				    tcoords[i].x = data[ i*2+0 ];				    tcoords[i].y = data[ i*2+1 ];				}				((GeometryArray)node).setTexCoordRef2f( set, tcoords );			    }			    break;			    case FORMAT_3F: {				float[] data = readFloatArray( in );				TexCoord3f[] tcoords = new TexCoord3f[ data.length/3 ];				for (int i = 0 ; i < tcoords.length ; i++) {				    tcoords[i].x = data[ i*3+0 ];				    tcoords[i].y = data[ i*3+1 ];				    tcoords[i].z = data[ i*3+2 ];				}				((GeometryArray)node).setTexCoordRef3f( set, tcoords );			    }			    break;			    case FORMAT_FLOAT:				float[] tcoords = readFloatArray( in );				((GeometryArray)node).setTexCoordRefFloat( set, tcoords );			    break;			    }			}		    }		} else {		    // Not by-reference		    for(int set=0; set<texCoordSetCount; set++) {			float[] textureCoords = readFloatArray( in );			((GeometryArray)node).setTextureCoordinates( set, 0, textureCoords );		    }		}	    }	}    }    protected void writeConstructorParams( DataOutput out ) throws								IOException {	vertexCount = ((GeometryArray)node).getVertexCount();	vertexFormat = ((GeometryArray)node).getVertexFormat();        texCoordSetCount = ((GeometryArray)node).getTexCoordSetCount();        texCoordSetMap = new int[ ((GeometryArray)node).getTexCoordSetMapLength() ];                ((GeometryArray)node).getTexCoordSetMap( texCoordSetMap );        	out.writeInt(vertexCount);	out.writeInt(vertexFormat);        out.writeInt( texCoordSetCount );        out.writeInt( texCoordSetMap.length );        for(int i=0; i<texCoordSetMap.length; i++)            out.writeInt( texCoordSetMap[i] );        super.writeConstructorParams( out );    }    protected void readConstructorParams( DataInput in ) throws							IOException {       // Load VertexCount and format first beause       // SceneGraphObjectState will call createNode which       // requires them       vertexCount = in.readInt();       vertexFormat = in.readInt();       texCoordSetCount = in.readInt();       texCoordSetMap = new int[in.readInt()];       for(int i=0; i<texCoordSetMap.length; i++)           texCoordSetMap[i] = in.readInt();              super.readConstructorParams( in );    }        protected void writeDoubleArray( DataOutput out, double[] array ) throws IOException {        // Writing the array into a ByteArray in memory and then dumping        // the byte array to DataOutput with a single call is MUCH quicker        // than writing each double to DataOutput.                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();        DataOutputStream dataOut = new DataOutputStream( byteStream );        dataOut.writeInt( array.length );        for(int i=0; i<array.length; i++)            dataOut.writeDouble( array[i] );        dataOut.close();                out.writeInt( byteStream.size() );        out.write( byteStream.toByteArray() );    }        protected double[] readDoubleArray( DataInput in ) throws IOException {        byte[] buffer = new byte[ in.readInt() ];        in.readFully( buffer );        ByteArrayInputStream byteStream = new ByteArrayInputStream( buffer );        DataInputStream dataIn = new DataInputStream( byteStream );                double[] array = new double[ dataIn.readInt() ];        for(int i=0; i<array.length; i++)            array[i] = dataIn.readDouble();                dataIn.close();                return array;    }        protected void writeFloatArray( DataOutput out, float[] array ) throws IOException {        // Writing the array into a ByteArray in memory and then dumping        // the byte array to DataOutput with a single call is MUCH quicker        // than writing each float to DataOutput.                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();        DataOutputStream dataOut = new DataOutputStream( byteStream );        dataOut.writeInt( array.length );        for(int i=0; i<array.length; i++)            dataOut.writeFloat( array[i] );        dataOut.close();                out.writeInt( byteStream.size() );        out.write( byteStream.toByteArray() );    }        protected float[] readFloatArray( DataInput in ) throws IOException {        byte[] buffer = new byte[ in.readInt() ];        in.readFully( buffer );        ByteArrayInputStream byteStream = new ByteArrayInputStream( buffer );        DataInputStream dataIn = new DataInputStream( byteStream );                float[] array = new float[ dataIn.readInt() ];        for(int i=0; i<array.length; i++)            array[i] = dataIn.readFloat();                dataIn.close();                return array;    }}

⌨️ 快捷键说明

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