📄 controller.java
字号:
return ret; } /** * Associate the name with the scene graph object */ public void addNamedObject( String name, SceneGraphObject object ) { symbolTable.addNamedObject( name, object ); } /** * Return the SceneGraphObject associated with the name */ public SceneGraphObject getNamedObject( String name ) throws NamedObjectException, ObjectNotLoadedException { return symbolTable.getNamedObject( name ); } /** * Get all the names of the named objects */ public String[] getNames() { return symbolTable.getNames(); } /** * Write a serializable object to the current file position, proceeded by * the size of the object */ public void writeSerializedData( DataOutput dataOutput, java.io.Serializable userData ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream objOut = new ObjectOutputStream( out ); objOut.writeObject( userData ); out.close(); byte[] bytes = out.toByteArray(); dataOutput.writeInt( bytes.length ); if (bytes.length!=0) dataOutput.write( bytes ); } public Object readSerializedData( DataInput dataInput ) throws IOException { int size = dataInput.readInt(); Object userData = null; if (size!=0) { byte[] bytes = new byte[size]; dataInput.readFully( bytes ); ByteArrayInputStream in = new ByteArrayInputStream( bytes ); J3dIOObjectInputStream objIn = new J3dIOObjectInputStream( in ); try { userData = objIn.readObject(); objIn.close(); } catch( ClassNotFoundException e ) { System.out.println("WARNING: Unable to load UserData"); System.out.println("Class missing "+e); objIn.close(); } } return userData; } /** * Skip past the user data object */ public void skipUserData( DataInput dataInput ) throws IOException { int size = dataInput.readInt(); dataInput.skipBytes( size ); } public void writeColor3f( DataOutput out, Color3f color ) throws IOException { out.writeFloat( color.x ); out.writeFloat( color.y ); out.writeFloat( color.z ); } public Color3f readColor3f( DataInput in ) throws IOException { return new Color3f( in.readFloat(), in.readFloat(), in.readFloat() ); } public void writeColor4f( DataOutput out, Color4f vec ) throws IOException { writeTuple4f( out, vec ); } public Color4f readColor4f( DataInput in ) throws IOException { return (Color4f)readTuple4f( in, new Color4f() ); } public void writePoint3f( DataOutput out, Point3f pt ) throws IOException { writeTuple3f( out, pt ); } public Point3f readPoint3f( DataInput in ) throws IOException { return (Point3f)readTuple3f( in, new Point3f() ); } public void writePoint3d( DataOutput out, Point3d pt ) throws IOException { writeTuple3d( out, pt ); } public Point3d readPoint3d( DataInput in ) throws IOException { return (Point3d)readTuple3d( in, new Point3d() ); } public void writeVector3f( DataOutput out, Vector3f vec ) throws IOException { writeTuple3f( out, vec ); } public Vector3f readVector3f( DataInput in ) throws IOException { return (Vector3f)readTuple3f( in, new Vector3f() ); } public void writeVector4d( DataOutput out, Vector4d vec ) throws IOException { writeTuple4d( out, vec ); } public Vector4d readVector4d( DataInput in ) throws IOException { return (Vector4d)readTuple4d( in, new Vector4d() ); } public void writeVector4f( DataOutput out, Vector4f vec ) throws IOException { writeTuple4f( out, vec ); } public Vector4f readVector4f( DataInput in ) throws IOException { return (Vector4f)readTuple4f( in, new Vector4f() ); } public void writeQuat4f( DataOutput out, Quat4f vec ) throws IOException { writeTuple4f( out, vec ); } public Quat4f readQuat4f( DataInput in ) throws IOException { return (Quat4f)readTuple4f( in, new Quat4f() ); } public void writeMatrix4d( DataOutput out, Matrix4d m ) throws IOException { for(int r=0; r<4; r++) for(int c=0; c<4; c++) out.writeDouble( m.getElement( r, c )); } public Matrix4d readMatrix4d( DataInput in ) throws IOException { double elements[] = new double[16]; for(int c=0; c<16; c++) elements[ c ] = in.readDouble(); return new Matrix4d(elements); } public void writeTuple3f( DataOutput out, Tuple3f tuple ) throws IOException { out.writeFloat( tuple.x ); out.writeFloat( tuple.y ); out.writeFloat( tuple.z ); } public Tuple3f readTuple3f( DataInput in, Tuple3f tuple ) throws IOException { tuple.x = in.readFloat(); tuple.y = in.readFloat(); tuple.z = in.readFloat(); return tuple; } public void writeTuple3d( DataOutput out, Tuple3d tuple ) throws IOException { out.writeDouble( tuple.x ); out.writeDouble( tuple.y ); out.writeDouble( tuple.z ); } public Tuple3d readTuple3d( DataInput in, Tuple3d tuple ) throws IOException { tuple.x = in.readDouble(); tuple.y = in.readDouble(); tuple.z = in.readDouble(); return tuple; } public void writeTuple4d( DataOutput out, Tuple4d tuple ) throws IOException { out.writeDouble( tuple.x ); out.writeDouble( tuple.y ); out.writeDouble( tuple.z ); out.writeDouble( tuple.w ); } public Tuple4d readTuple4d( DataInput in, Tuple4d tuple ) throws IOException { tuple.x = in.readDouble(); tuple.y = in.readDouble(); tuple.z = in.readDouble(); tuple.w = in.readDouble(); return tuple; } public void writeTuple4f( DataOutput out, Tuple4f tuple ) throws IOException { out.writeFloat( tuple.x ); out.writeFloat( tuple.y ); out.writeFloat( tuple.z ); out.writeFloat( tuple.w ); } public Tuple4f readTuple4f( DataInput in, Tuple4f tuple ) throws IOException { tuple.x = in.readFloat(); tuple.y = in.readFloat(); tuple.z = in.readFloat(); tuple.w = in.readFloat(); return tuple; } public void writeTransform3D( DataOutput out, Transform3D tran ) throws IOException { Matrix4d matrix = new Matrix4d(); tran.get( matrix ); writeMatrix4d( out, matrix ); } public Transform3D readTransform3D( DataInput in ) throws IOException { Transform3D ret = new Transform3D(); ret.set( readMatrix4d( in )); return ret; } public void writeBounds( DataOutput out, Bounds bounds ) throws IOException { if (bounds==null) { out.writeInt( 0 ); } else if (bounds instanceof BoundingBox) { out.writeInt( 1 ); // Type Point3d p = new Point3d(); ((BoundingBox)bounds).getLower( p ); writePoint3d( out, p ); ((BoundingBox)bounds).getUpper( p ); writePoint3d( out, p ); } else if (bounds instanceof BoundingSphere) { out.writeInt( 2 ); // Type Point3d p = new Point3d(); ((BoundingSphere)bounds).getCenter( p ); writePoint3d( out, p ); out.writeDouble( ((BoundingSphere)bounds).getRadius() ); } else if (bounds instanceof BoundingPolytope ) { out.writeInt( 3 ); // Type Vector4d[] planes = new Vector4d[ ((BoundingPolytope)bounds).getNumPlanes() ]; ((BoundingPolytope)bounds).getPlanes( planes ); out.writeInt( planes.length ); for(int i=0; i<planes.length; i++) writeVector4d( out, planes[i] ); } else { throw new IOException( "Unsupported bounds class "+bounds.getClass().getName() ); } } public Bounds readBounds( DataInput in ) throws IOException { Bounds bounds; switch( in.readInt() ) { case 0: bounds = null; break; case 1: bounds = new BoundingBox( readPoint3d(in), readPoint3d(in) ); break; case 2: bounds = new BoundingSphere( readPoint3d(in), in.readDouble() ); break; case 3: Vector4d[] planes = new Vector4d[ in.readInt() ]; for(int i=0; i<planes.length; i++) planes[i] = readVector4d( in ); bounds = new BoundingPolytope(planes); break; default: throw new SGIORuntimeException("Unrecognised bounds class"); } return bounds; } /** * Get the current file 'pointer' location. */ public abstract long getFilePointer(); public abstract void close() throws IOException; /** * Indicates to SceneGraphObjectState that it should use the * Java3D core superclass for any tree nodes whose classes are * not in the classpath during a load. */ public boolean useSuperClassIfNoChildClass() { return useSuperClass; } /** * Returns the imageCompression to be used * IMAGE_COMPRESSION_NONE, IMAGE_COMPRESSION_GZIP, IMAGE_COMPRESSION_JPEG */ public int getImageCompression() { return imageCompression; } /** * An ObjectInputStream that uses a different classLoader */ class J3dIOObjectInputStream extends ObjectInputStream { public J3dIOObjectInputStream( java.io.InputStream in ) throws IOException { super(in); } protected Class resolveClass( java.io.ObjectStreamClass desc ) throws IOException, ClassNotFoundException { return getClass().forName( desc.getName(), true, classLoader ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -