?? load3ds.java
字號:
if ( ca == null )
{
ca = new ColoringAttributes();
}
switch ( mode )
{
case 0: // Wireframe (not used in 3DSMax?)
style = PolygonAttributes.POLYGON_LINE;
break;
case 2: // Metal - use this for rendering points.
style = PolygonAttributes.POLYGON_POINT;
break;
case 1: // Constant
style = PolygonAttributes.POLYGON_FILL;
ca.setShadeModel( ColoringAttributes.SHADE_FLAT );
break;
case 3: // Phong
default:
style = PolygonAttributes.POLYGON_FILL;
ca.setShadeModel( ColoringAttributes.NICEST );
break;
}
if ( verbosity > 2 )
{
System.out.println( "== Shading: " + mode + ", style = " + style );
}
pa.setPolygonMode( style );
mat.setPolygonAttributes( pa );
mat.setColoringAttributes( ca );
break;
case S3D_MAT_WIRE: // Another way of enforcing wireframe
PolygonAttributes pat = mat.getPolygonAttributes();
pat.setPolygonMode( PolygonAttributes.POLYGON_LINE );
if ( verbosity > 2 )
{
System.out.println( "== Wireframe" );
}
break;
case S3D_MAT_WIRESIZE: // Wireframe line width
float width = readFloat( in );
LineAttributes la = mat.getLineAttributes();
if ( la == null )
{
la = new LineAttributes();
}
la.setLineWidth( width );
mat.setLineAttributes( la );
if ( verbosity > 2 )
{
System.out.println( "== Wire width: " + width );
}
break;
case S3D_MAT_TWO_SIDE: // Face culling
PolygonAttributes pat2 = mat.getPolygonAttributes();
pat2.setCullFace( PolygonAttributes.CULL_NONE );
if ( verbosity > 2 )
{
System.out.println( "== Two sided" );
}
break;
case S3D_MAT_TEXMAP: // Image for texture map
float matPercent = readPercentage( in ) * 100;
String imageName = path + readMatName( in );
System.out.println( "Loading texture map '" + imageName + "' (" +
matPercent + "%)" );
if ( new java.io.File( imageName ).exists() == false )
{
System.out.println( "** Can't find image '" + imageName + "'" );
imageName = null;
}
else
{
Texture textureMap = new TextureLoader( imageName, component ).getTexture();
if ( textureMap == null )
{
System.out.println( "** Texturing has been disabled" );
}
if ( verbosity > 1 )
{
System.out.println( "== Texturing: " + textureMap.getEnable() );
System.out.println( "== MipMapMode: " + textureMap.getMipMapMode() );
}
//textureMap.setMinFilter( Texture.BASE_LEVEL_POINT );
//textureMap.setMagFilter( Texture.BASE_LEVEL_POINT );
mat.setTexture( textureMap );
TextureAttributes texA = mat.getTextureAttributes();
if ( texA == null )
{
texA = new TextureAttributes();
}
mat.setTextureAttributes( texA );
}
break;
case S3D_TEX_VERTS: // 2D Texture coordinates
processTextureCoordinates( in );
break;
case S3D_NAMED_OBJECT: // Start of 3DS object
if ( surfacesCreated == false )
{
createUnsmoothedFaces();
prepareForNewObject();
}
String objectName = readName( in );
if ( hiddenObject( objectName ) )
{
skipChunk( in, length - objectName.length() - 1 );
System.out.println( "(Skipping hidden object '" + objectName + "')" );
break;
}
System.out.println( "Processing object '" + objectName + "'" );
object = new SharedGroup();
shape = new Shape3D();
processChunk( in );
if ( verbosity > 1 )
{
System.out.println( "== Adding shape to transform group" );
}
object.addChild( shape );
if ( verbosity > 1 )
{
System.out.println( "== Adding object to list of shared objects" );
}
objectTable.put( objectName, object );
break;
case S3D_POINT_ARRAY: // Vertex list
processPointArray( in );
break;
case S3D_FACE_ARRAY: // Face list
processFaceArray( in );
break;
case S3D_MSH_MAT_GROUP: // Materials used by object
processMaterial( in );
break;
case S3D_SMOOTH_GROUP: // List of surfaces
processSmoothGroup( in );
prepareForNewObject();
break;
case S3D_MESH_MATRIX: // Object transform
processMeshMatrix( in );
break;
case S3D_POINT_FLAG_ARRAY: // Not much use to us
case S3D_PIVOT: // Unused
skipChunk( in, length );
break;
default:
if ( verbosity > 0 )
{
System.out.println( "TAG: 0x" + Integer.toHexString( tag ) +
" LEN: " + length );
}
skipChunk( in, length );
break;
}
}
//
// Skip over the current chunk, i.e. we are not interested in it.
//
void skipChunk( RandomAccessFile in, int length )
throws IOException
{
int bytesToSkip = length - 6;
if ( bytesToSkip > 0 )
{
in.skipBytes( bytesToSkip );
}
}
//
// S3D_OBJ_HIDDEN doesn't seem to be set by 3DSMax, so
// objects that have names beginning with '$' are taken
// as hidden.
//
boolean hiddenObject( String name )
{
return name.charAt( 0 ) == '$';
}
//
// Defines an instance of an object.
//
void processLink( RandomAccessFile in )
throws IOException
{
nodeName = readName( in );
int flags1 = readUnsignedShort( in );
int flags2 = readUnsignedShort( in );
int dummy = readUnsignedShort( in );
if ( verbosity > 2 )
{
System.out.println( "== Link for object '" + nodeName + "': 0x" +
Integer.toHexString( flags1 ) + ", 0x" +
Integer.toHexString( flags2 ) + ", 0x" +
Integer.toHexString( dummy ) );
}
}
//
// Processed out of curiosity!
//
void processNodeID( RandomAccessFile in )
throws IOException
{
int id = readUnsignedShort( in );
if ( verbosity > 1 )
{
System.out.println( "== NodeID: " + id );
}
}
//
// Lookup an object by <name>.
//
SharedGroup findObject( String name )
{
return (SharedGroup)objectTable.get( name );
}
//
// Take the last position specified in this keyframe list
// as the initial position of the object.
//
void processPosTrackTag( RandomAccessFile in )
throws IOException
{
int dummy, keys, i;
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
keys = readUnsignedShort( in );
dummy = readUnsignedShort( in );
for ( i = 0; i < keys; i++ )
{
dummy = readUnsignedShort( in );
dummy = readInt( in );
//
// Reverse the Y and Z coordinates, negate Z coordinates
//
float x = readFloat( in ), y = readFloat( in ), z = readFloat( in );
translation = new Vector3f( x, z, -y );
// translation = new Vector3f( x, y, z );
if ( verbosity > 0 )
{
System.out.println( " Position: " + translation );
}
}
}
//
// Take the last orientation specified in this keyframe list
// as the initial orientation of the object.
//
void processRotTrackTag( RandomAccessFile in )
throws IOException
{
int dummy, keys, i;
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
keys = readUnsignedShort( in );
dummy = readUnsignedShort( in );
for ( i = 0; i < keys; i++ )
{
dummy = readUnsignedShort( in );
dummy = readInt( in );
float rot = readFloat( in );
float x = readFloat( in );
float y = readFloat( in );
float z = readFloat( in );
//
// Convert the orientation between 3DS and
// Java3D coordinate systems.
//
AxisAngle4f axes = new AxisAngle4f( x, y, z, -rot );
Matrix4f m = new Matrix4f();
Matrix4f rm = new Matrix4f( );
m.set( axes );
rm.rotX( (float)-Math.PI / 2 );
orientation = new Matrix4f();
orientation.mul( rm, m );
if ( verbosity > 0 )
{
System.out.println( " Rotation: " + orientation );
}
}
}
//
// Take the last scale specified in this keyframe list
// as the initial scale of the object. Also take this
// as the queue to finish instancing the object.
//
void processSclTrackTag( RandomAccessFile in )
throws IOException
{
int dummy, keys, i;
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
dummy = readUnsignedShort( in );
keys = readUnsignedShort( in );
dummy = readUnsignedShort( in );
for ( i = 0; i < keys; i++ )
{
dummy = readUnsignedShort( in );
dummy = readInt( in );
//
// Reverse the Y and Z coordinates
//
float x = readFloat( in ), y = readFloat( in ), z = readFloat( in );
scale = new Vector3f( x, z, y );
if ( verbosity > 0 )
{
System.out.println( " Scale : " + scale );
}
}
if ( hiddenObject( nodeName ) )
{
return;
}
Matrix4f m = new Matrix4f();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -