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

📄 geometryarraystate.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: GeometryArrayState.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistribution of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. * * $Revision: 1.4 $ * $Date: 2007/02/09 17:20:34 $ * $State: Exp $ */package com.sun.j3d.utils.scenegraph.io.state.javax.media.j3d;import java.io.*;import javax.media.j3d.GeometryArray;import javax.media.j3d.IndexedGeometryArray;import javax.media.j3d.GeometryStripArray;import javax.media.j3d.SceneGraphObject;import javax.vecmath.*;import com.sun.j3d.utils.scenegraph.io.retained.Controller;import com.sun.j3d.utils.scenegraph.io.retained.SymbolTableData;import javax.media.j3d.J3DBuffer;import com.sun.j3d.internal.ByteBufferWrapper;import com.sun.j3d.internal.BufferWrapper;import com.sun.j3d.internal.FloatBufferWrapper;import com.sun.j3d.internal.DoubleBufferWrapper;import com.sun.j3d.internal.ByteOrderWrapper;public abstract class GeometryArrayState extends GeometryState {    protected int vertexFormat;    protected int vertexCount;    protected int texCoordSetCount;    protected int[] texCoordSetMap;    private static final int FORMAT_NULL = 0;    private static final int FORMAT_BYTE = 1;    private static final int FORMAT_FLOAT = 2;    private static final int FORMAT_DOUBLE = 3;    private static final int FORMAT_3B = 4;    private static final int FORMAT_4B = 5;    private static final int FORMAT_2F = 6;    private static final int FORMAT_3F = 7;    private static final int FORMAT_4F = 8;    private static final int FORMAT_2D = 9;    private static final int FORMAT_3D = 10;        public GeometryArrayState( SymbolTableData symbol, Controller control ) {	super( symbol, control );    }    public void writeObject( DataOutput out ) throws IOException {        super.writeObject( out );        	boolean nio = (vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0;	if ( (vertexFormat & GeometryArray.INTERLEAVED)!=0 ) {	    if ( !(node instanceof IndexedGeometryArray) ) {		out.writeInt( ((GeometryArray)node).getInitialVertexIndex() );		if ( !(node instanceof GeometryStripArray) )		    out.writeInt( ((GeometryArray)node).getValidVertexCount() );	    }	    if ( nio ) {		FloatBufferWrapper x = new FloatBufferWrapper(		    ((GeometryArray)node).getInterleavedVertexBuffer());		float[] f = new float[x.limit()];		x.position( 0 );		x.get( f );		writeFloatArray( out, f );	    } else writeFloatArray( out, ((GeometryArray)node).getInterleavedVertices() );	} else {	    boolean byRef = (vertexFormat & GeometryArray.BY_REFERENCE) != 0;	    if ( !(node instanceof IndexedGeometryArray) ) {		if ( !byRef )		    out.writeInt( ((GeometryArray)node).getInitialVertexIndex() );		if ( !(node instanceof GeometryStripArray) )		    out.writeInt( ((GeometryArray)node).getValidVertexCount() );	    }	    if ( (vertexFormat & GeometryArray.COLOR_4)==GeometryArray.COLOR_4 ) {		//System.out.println("COLOR 4");		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			out.writeInt( ((GeometryArray)node).getInitialColorIndex() );		    }		    if ( nio ) {			J3DBuffer buf = ((GeometryArray)node).getColorRefBuffer();			switch( BufferWrapper.getBufferType( buf ) ) {			case BufferWrapper.TYPE_BYTE: {			    out.writeInt( FORMAT_BYTE );			    ByteBufferWrapper bb = new ByteBufferWrapper( buf );			    byte[] bytes = new byte[ bb.limit() ];			    bb.position( 0 );			    bb.get( bytes );			    out.writeInt( bytes.length );			    out.write( bytes );			}			break;			case BufferWrapper.TYPE_FLOAT: {			    out.writeInt( FORMAT_FLOAT );			    FloatBufferWrapper bb = new FloatBufferWrapper( buf );			    float[] floats = new float[ bb.limit() ];			    bb.position( 0 );			    bb.get( floats );			    writeFloatArray( out, floats );			}			break;			case BufferWrapper.TYPE_NULL: {			    out.writeInt( FORMAT_NULL );			}			break;			}		    } else if ( ((GeometryArray)node).getColorRef4f()!=null ) {			out.writeInt( FORMAT_4F );			Color4f[] colors = ((GeometryArray)node).getColorRef4f();			float[] data = new float[ colors.length*4 ];			for (int i = 0 ; i < colors.length ; i++) {			    data[ i*4+0 ] = colors[i].x;			    data[ i*4+1 ] = colors[i].y;			    data[ i*4+2 ] = colors[i].z;			    data[ i*4+3 ] = colors[i].w;			}			writeFloatArray( out, data );		    } else if ( ((GeometryArray)node).getColorRefFloat()!=null ) {			out.writeInt( FORMAT_FLOAT );			writeFloatArray( out, ((GeometryArray)node).getColorRefFloat() );		    } else if ( ((GeometryArray)node).getColorRefByte()!=null ) {			out.writeInt( FORMAT_BYTE );			byte[] colors = ((GeometryArray)node).getColorRefByte();			out.writeInt( colors.length );			out.write( colors );		    } else if ( ((GeometryArray)node).getColorRef4b()!=null ) {			out.writeInt( FORMAT_4B );			Color4b[] colors = ((GeometryArray)node).getColorRef4b();			out.writeInt( colors.length );			byte[] data = new byte[ colors.length*4 ];			for (int i = 0 ; i < colors.length ; i++) {			  data[ i*4+0 ] = colors[i].x;			  data[ i*4+1 ] = colors[i].y;			  data[ i*4+2 ] = colors[i].z;			  data[ i*4+3 ] = colors[i].w;			}			out.write( data );		    } else out.writeInt( FORMAT_NULL );		} else {		    byte[] colors = new byte[ vertexCount*4 ];		    ((GeometryArray)node).getColors( 0, colors );		    out.write( colors );		}	    } else if ((vertexFormat & GeometryArray.COLOR_3)==GeometryArray.COLOR_3 ) {		//System.out.println("COLOR 3");		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			out.writeInt( ((GeometryArray)node).getInitialColorIndex() );		    }		    if ( nio ) {			J3DBuffer buf = ((GeometryArray)node).getColorRefBuffer();			switch( BufferWrapper.getBufferType( buf ) ) {			case BufferWrapper.TYPE_BYTE: {			    out.writeInt( FORMAT_BYTE );			    ByteBufferWrapper bb = new ByteBufferWrapper( buf );			    byte[] bytes = new byte[ bb.limit() ];			    bb.position( 0 );			    bb.get( bytes );			    out.writeInt( bytes.length );			    out.write( bytes );			}			break;			case BufferWrapper.TYPE_FLOAT: {			    out.writeInt( FORMAT_FLOAT );			    FloatBufferWrapper bb = new FloatBufferWrapper( buf );			    float[] floats = new float[ bb.limit() ];			    bb.position( 0 );			    bb.get( floats );			    writeFloatArray( out, floats );			}			break;			case BufferWrapper.TYPE_NULL: {			    out.writeInt( FORMAT_NULL );			}			break;			}		    } else if ( ((GeometryArray)node).getColorRef3f()!=null ) {			out.writeInt( FORMAT_3F );			Color3f[] colors = ((GeometryArray)node).getColorRef3f();			float[] data = new float[ colors.length*3 ];			for (int i = 0 ; i < colors.length ; i++) {			    data[ i*3+0 ] = colors[i].x;			    data[ i*3+1 ] = colors[i].y;			    data[ i*3+2 ] = colors[i].z;			}			writeFloatArray( out, data );		    } else if ( ((GeometryArray)node).getColorRefFloat()!=null ) {			out.writeInt( FORMAT_FLOAT );			writeFloatArray( out, ((GeometryArray)node).getColorRefFloat() );		    } else if ( ((GeometryArray)node).getColorRefByte()!=null ) {			out.writeInt( FORMAT_BYTE );			byte[] colors = ((GeometryArray)node).getColorRefByte();			out.writeInt( colors.length );			out.write( colors );		    } else if ( ((GeometryArray)node).getColorRef3b()!=null ) {			out.writeInt( FORMAT_3B );			Color3b[] colors = ((GeometryArray)node).getColorRef3b();			out.writeInt( colors.length );			byte[] data = new byte[ colors.length*3 ];			for (int i = 0 ; i < colors.length ; i++) {			    data[ i*3+0 ] = colors[i].x;			    data[ i*3+1 ] = colors[i].y;			    data[ i*3+2 ] = colors[i].z;			}			out.write( data );		    } else out.writeInt( FORMAT_NULL );		} else {		    byte[] colors3 = new byte[ vertexCount*3 ];		    ((GeometryArray)node).getColors( 0, colors3 );		    out.write( colors3 );		}	    }	    if ((vertexFormat & GeometryArray.COORDINATES)!=0 ) {		//System.out.println("COORDS");		if ( byRef ) {		    if ( !(node instanceof IndexedGeometryArray) ) {			out.writeInt( ((GeometryArray)node).getInitialCoordIndex() );		    }		    if ( nio ) {			J3DBuffer buf = ((GeometryArray)node).getCoordRefBuffer();			switch( BufferWrapper.getBufferType( buf ) ) {			case BufferWrapper.TYPE_FLOAT: {			    out.writeInt( FORMAT_FLOAT );			    FloatBufferWrapper bb = new FloatBufferWrapper( buf );			    float[] floats = new float[ bb.limit() ];			    bb.position( 0 );			    bb.get( floats );			    writeFloatArray( out, floats );			}			break;			case BufferWrapper.TYPE_DOUBLE: {			    out.writeInt( FORMAT_DOUBLE );			    DoubleBufferWrapper bb = new DoubleBufferWrapper( buf );			    double[] doubles = new double[ bb.limit() ];			    bb.position( 0 );			    bb.get( doubles );			    writeDoubleArray( out, doubles );			}			break;			case BufferWrapper.TYPE_NULL: {			    out.writeInt( FORMAT_NULL );			}			break;			}		    } else if ( ((GeometryArray)node).getCoordRef3f()!=null ) {			out.writeInt( FORMAT_3F );			Point3f[] coords = ((GeometryArray)node).getCoordRef3f();			float[] data = new float[ coords.length*3 ];			for (int i = 0 ; i < coords.length ; i++) {			    data[ i*3+0 ] = coords[i].x;			    data[ i*3+1 ] = coords[i].y;			    data[ i*3+2 ] = coords[i].z;			}			writeFloatArray( out, data );		    } else if ( ((GeometryArray)node).getCoordRef3d()!=null ) {			out.writeInt( FORMAT_3D );			Point3d[] coords = ((GeometryArray)node).getCoordRef3d();			double[] data = new double[ coords.length*3 ];			for (int i = 0 ; i < coords.length ; i++) {			    data[ i*3+0 ] = coords[i].x;			    data[ i*3+1 ] = coords[i].y;			    data[ i*3+2 ] = coords[i].z;

⌨️ 快捷键说明

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