Ejemplo n.º 1
0
mEResult mC3dbReader::Read3dbFileData( mCScene & a_sceneDest, mCIOStreamBinary & a_streamSource )
{
    a_sceneDest.Clear();
    mCString strSceneName = dynamic_cast< mCFileStream * >( &a_streamSource ) ? g_GetFileNameNoExt( dynamic_cast< mCFileStream * >( &a_streamSource )->GetFileName() ) : "";
    if ( a_streamSource.ReadString() != "3db" )
    {
        MI_ERROR( mCConverterError, EBadFormat, "Invalid .3db file." );
        return mEResult_False;
    }
    MIFloat const f_Angle = a_streamSource.ReadFloat();
    MIUInt uChunkCount = a_streamSource.ReadU32();
    for ( MIUInt uNextChunk = a_streamSource.Tell(); uChunkCount--; a_streamSource.Seek( uNextChunk ) )
    {
        EChunkID enuChunkID = static_cast< EChunkID >( a_streamSource.ReadI32() );
        MIUInt const uVersionMin = a_streamSource.ReadU32();
        uNextChunk += a_streamSource.ReadU32() + 12;
        if ( EVersion < uVersionMin )
            continue;
        switch ( enuChunkID )
        {
        case EChunkID_Material:
            ReadMaterialChunk( a_sceneDest, a_streamSource );
            break;
        case EChunkID_TexMap:
            ReadTexMapChunk( a_sceneDest, a_streamSource );
            break;
        case EChunkID_Node:
            ReadNodeChunk( a_sceneDest, a_streamSource );
            break;
        case EChunkID_Mesh:
            ReadMeshChunk( a_sceneDest, a_streamSource );
            break;
        case EChunkID_Skin:
            ReadSkinChunk( a_sceneDest, a_streamSource );
        }
    }
    if ( f_Angle != -1.0f )
        for ( MIUInt u = a_sceneDest.GetNumNodes(); u--; )
            if ( a_sceneDest.GetNodeAt( u )->HasMesh() )
                a_sceneDest.AccessNodeAt( u )->AccessMesh()->CalcVNormalsByAngle( f_Angle );
    a_sceneDest.IdentifyBones();
    a_sceneDest.SetName( strSceneName );
    return mEResult_Ok;
}
Ejemplo n.º 2
0
int C3DSLoader::ReadEditChunk(tChunk& pEditChunk)
{
	//get a fresh working chunk
	tChunk currentChunk={0};

	//read the sub chunks until we find the end of the parent chunk
	while(pEditChunk.bytesRead < pEditChunk.length)
	{
		//Read the next chunk
		ReadChunk(currentChunk);

		switch(currentChunk.ID)
		{
		case EDIT_MATERIAL:
			//cout<<"found Material Chunk"<<endl;
			ReadMaterialChunk(currentChunk);
			break;
		case EDIT_OBJECT:
			//cout<<"found Object Chunk"<<endl;
			//read the name of the object
			char strName[255];
			currentChunk.bytesRead+=GetString(strName);
			{
			C3DMesh mesh(strName);
			//We have read in the name of the object
			//now we are going to read its data
			ReadObjectChunk(currentChunk,mesh);
			m_pModel->m_vMeshes.push_back(mesh);
			}
			break;
		default:
			currentChunk.bytesRead+=fread(m_iBuffer,1,currentChunk.length-currentChunk.bytesRead,m_FilePointer);
			break;
		}//end switch
 
		//Just read and discard unknown or unwanted chunks
		pEditChunk.bytesRead+=currentChunk.bytesRead;
	}//end while
	return 0;
}//end ReadEditChunk
Ejemplo n.º 3
0
mEResult mCMaxReader::ReadInMaxFileData( mCScene & a_sceneDest, mCMaxFileStream & a_streamSource )
{
    MIInt const iMinVersion = 1;
    MIInt const iVersion = 1;
    mCVariant rootVariant;
    a_sceneDest.Clear();
    if ( a_streamSource.ReadPersistentGlobal( "_extendedSaveData", rootVariant ) != mEResult_Ok )
    {
        MI_ERROR( mCConverterError, EBadFormat, "Invalid .gmax file. The file might have been saved without Extended Saving enabled." );
        return mEResult_False;
    }
    for ( ; ; )
    {
        mTArray< mCVariant > arrChunkVariants;
        if ( rootVariant.SwapData( arrChunkVariants ) != mEResult_Ok )
            break;
        for ( MIUInt u = 0, ue = arrChunkVariants.GetCount(); u != ue; ++u )
        {
            mTArray< mCVariant > arrChunk;
            if ( arrChunkVariants[ u ].SwapData( arrChunk ) != mEResult_Ok )
                break;
            if ( arrChunk.GetCount() < 3 )
                break;
            MIInt iChunkMinVersion = 0;
            MIInt iChunkVersion = 0;
            mCString strChunkName;
            arrChunk[ 0 ].SwapData( iChunkMinVersion );
            arrChunk[ 1 ].SwapData( iChunkVersion );
            arrChunk[ 2 ].SwapData( strChunkName );
            strChunkName.ToLower();
            if ( ( iChunkVersion < iMinVersion ) || ( iVersion < iChunkMinVersion ) )
                continue;
            if ( strChunkName == "material" )
            {
                ReadMaterialChunk( arrChunk, a_sceneDest );
            }
            else if ( strChunkName == "node" )
            {
                ReadNodeChunk( arrChunk, a_sceneDest );
            }
            else if ( strChunkName == "mesh" )
            {
                ReadMeshChunk( arrChunk, a_sceneDest );
            }
            else if ( strChunkName == "skin" )
            {
                ReadSkinChunk( arrChunk, a_sceneDest );
            }
            else
            {
                break;
            }
        }
        a_sceneDest.IdentifyBones();
        a_sceneDest.SetName( g_GetFileNameNoExt( a_streamSource.GetFileName() ) );
        mCVariant::CondenseMemory();
        return mEResult_Ok;
    }
    MI_ERROR( mCConverterError, EBadFormat, "Unknown Extended Saving version." );
    return mEResult_False;
}