if ( chunk. ID!= (short) Groups. C_PRIMARY )
{
throw new FormatException ( "Not a proper 3DS file." );
}
ProcessChunk ( chunk );
}
finally
{
if (reader!= null) reader. Close ();
if (file!= null) file. Close ();
}
}
#endregion
#region Helper methods
void ProcessChunk ( ThreeDSChunk chunk )
{
while ( tesRead < chunk. Length )
{
ThreeDSChunk child = new ThreeDSChunk ( reader );
switch ((Groups) child. ID)
{
case Groups. C_VERSION:
version = reader. ReadInt32 ();
tesRead += 4;
break;
case Groups. C_OBJECTINFO:
break;
case Groups. C_MATERIAL:
ProcessMaterialChunk ( child );
break;
case Groups. C_OBJECT:
ProcessString ( child );
Entity e = ProcessObjectChunk ( child );
e. CalculateNormals ();
model. Entities. Add ( e );
break;
default:
SkipChunk ( child );
break;
}
tesRead += tesRead;
}
}
void ProcessMaterialChunk ( ThreeDSChunk chunk )
{
string name = string. Empty;
Material m = new Material ();
while ( tesRead < chunk. Length )
{
ThreeDSChunk child = new ThreeDSChunk ( reader );
switch ((Groups) child. ID)
{
case Groups. C_MATNAME:
name = ProcessString ( child );
break;
case Groups. C_MATAMBIENT:
m. Ambient = ProcessColorChunk ( child );
break;
case Groups. C_MATDIFFUSE:
m. Diffuse = ProcessColorChunk ( child );
break;
case Groups. C_MATSPECULAR:
m. Specular = ProcessColorChunk ( child );
|
Из за большого объема этот материал размещен на нескольких страницах:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |


