CBool CScene::Load( CChar * fileName, CBool reportWarningsAndErrors, CBool readFromBuffer ) { if ( fileName == NULL ) return CFalse; CChar * nameOnly = GetAfterPath( fileName ); SetName( nameOnly ); // Instantiate the reference implementation m_collada = new DAE; PrintInfo( "\n" ); PrintInfo( _T("\n========Importing new external scene========"), COLOR_BLUE ); numErrors = numWarnings = 0; domCOLLADA *dom; if( readFromBuffer ) { ///////////////////////////////////////////////////////////////// //zip path CChar zipPath[MAX_NAME_SIZE]; Cpy( zipPath, fileName ); GetWithoutDot( zipPath ); Append(zipPath, ".zip" ); //file name inside zip file CChar fileNameInZip[MAX_NAME_SIZE]; Cpy( fileNameInZip, GetAfterPath( fileName ) ); //Uncompress zip file std::string buffer = ReadZipFile( zipPath, fileNameInZip ); //res = m_collada->load( "", buffer.c_str() ); dom = m_collada->openFromMemory( "", buffer.c_str() ); /////////////////////////////////////////////////////////////// } else { // load with full path //res = m_collada->load( fileName ); dom = m_collada->open(fileName); } //if (res != DAE_OK) //{ // PrintInfo(_T("\nCScene::Load > Error loading the COLLADA file:") + CString(fileName), COLOR_RED ); // delete m_collada; // m_collada = NULL; //if( reportWarningsAndErrors ) //{ // char tempReport[MAX_NAME_SIZE];; // sprintf( tempReport, "%s - fatal error (s)", nameOnly ); // PrintInfo2( tempReport, COLOR_RED ); //} // return CFalse; //} PrintInfo( _T("\nCOLLADA_DOM Runtime database initialized from" ) ); PrintInfo( _T("'") + CString( fileName ), COLOR_RED_GREEN ); //PrintInfo( _T("nameOnly: '") + (CString)nameOnly + _T( "'\n" ) ); //domCOLLADA *dom = m_collada->getDom(nameOnly); //if ( !dom ) // dom = m_collada->getDom( fileName); if ( !dom ) { PrintInfo( _T("\nCScene::Load > COLLADA File loaded to the dom, but query for the dom assets failed "), COLOR_RED ); PrintInfo( _T("\nCScene::Load > COLLADA Load Aborted! "), COLOR_RED ); delete m_collada; m_collada = NULL; if( reportWarningsAndErrors ) { char tempReport[MAX_NAME_SIZE];; sprintf( tempReport, "\n%s - Fatal error (s)", nameOnly ); PrintInfo( tempReport, COLOR_RED ); } return CFalse; } CInt ret = 0; //PrintInfo("Begin Conditioning\n"); //ret = kmzcleanup(m_collada, true); //if (ret) // PrintInfo("kmzcleanup complete\n"); ret = Triangulate(m_collada); if (ret) PrintInfo("\nTriangulate complete"); //ret = deindexer(m_collada); //if (ret) // PrintInfo("deindexer complete\n"); //PrintInfo("Finish Conditioning\n"); // Need to now get the asset tag which will determine what vector x y or z is up. Typically y or z. if ( dom->getAsset()->getUp_axis() ) { domAsset::domUp_axis *up = dom->getAsset()->getUp_axis(); switch( up->getValue() ) { case UPAXISTYPE_X_UP: PrintInfo(_T("\nWarning!X is Up Data and Hiearchies must be converted!") ); PrintInfo(_T("\nConversion to X axis Up isn't currently supported!") ); PrintInfo(_T("\nCOLLADA defaulting to Y Up") ); numWarnings +=1; //CRender.SetUpAxis(eCYUp); break; case UPAXISTYPE_Y_UP: PrintInfo( _T("\nY Axis is Up for this file...COLLADA set to Y Up ") ); //CRender.SetUpAxis(eCYUp); break; case UPAXISTYPE_Z_UP: PrintInfo( _T("\nZ Axis is Up for this file ") ); PrintInfo( _T("\nAll Geometries and Hiearchies converted!"), COLOR_YELLOW ) ; numWarnings +=1; //CRender.SetUpAxis(eCZUp); break; default: break; } } strcpy( m_fileName, fileName ); strcpy( m_pureFileName, nameOnly ); // Load all the image libraries //for ( CUInt i = 0; i < dom->getLibrary_images_array().getCount(); i++) //{ // ReadImageLibrary( dom->getLibrary_images_array()[i] ); //} CBool success = CFalse; /* CChar *cfxBinFilename = ReadCfxBinaryFilename( dom->getExtra_array() ); if ( cfxBinFilename != NULL ) { cfxLoader::setBinaryLoadRemotePath( BasePath ); success = (CBool) cfxLoader::loadMaterialsAndEffectsFromBinFile(cfxBinFilename, cfxMaterials, cfxEffects, cgContext); assert(success); } else { */ //success = ( CBool ) cfxLoader::loadMaterialsAndEffects( m_collada, m_cfxMaterials, m_cfxEffects, m_cgContext ); //assert(success); /*}*/ // Load all the effect libraries //for ( CUInt i = 0; i < dom->getLibrary_effects_array().getCount(); i++) //{ // ReadEffectLibrary( dom->getLibrary_effects_array()[i] ); //} //// Load all the material libraries //for ( CUInt i = 0; i < dom->getLibrary_materials_array().getCount(); i++) //{ // ReadMaterialLibrary( dom->getLibrary_materials_array()[i] ); //} // Load all the animation libraries for ( CUInt i = 0; i < dom->getLibrary_animations_array().getCount(); i++) { ReadAnimationLibrary( dom->getLibrary_animations_array()[i] ); m_hasAnimation = CTrue; } //Load all animation clips for ( CUInt i = 0; i < dom->getLibrary_animation_clips_array().getCount(); i++) { ReadAnimationClipLibrary( dom->getLibrary_animation_clips_array()[i] ); } //If there's no clip in COLLADA file, try to create a default clip if( m_numClips == 0 && dom->getLibrary_animations_array().getCount() > 0 ) { //Create a default clip and attach all the animations to this clip PrintInfo( "\nAdding default animation clip..." ); CAnimationClip * newAnimClip = CNew(CAnimationClip); //CAssert("No memory\n", newAnimClip!=NULL); newAnimClip->SetName( "defaultClip" ); newAnimClip->SetIndex(0); newAnimClip->SetStart(0.0); CFloat endTime = 0.0; for(CUInt i=0; i<m_animations.size(); i++) { CAnimation * anim = m_animations[i]; PrintInfo( "\nAttaching animation ' ", COLOR_WHITE );PrintInfo( anim->GetName(), COLOR_RED_GREEN ); PrintInfo( " ' to the default animation clip", COLOR_WHITE ); anim->SetClipTarget( newAnimClip ); newAnimClip->m_animations.push_back( anim ); if( anim->GetEndTime() > endTime ) endTime = anim->GetEndTime(); } newAnimClip->SetEnd((CDouble)endTime); m_numClips = 1; m_animationClips.push_back( newAnimClip ); } // Find the scene we want daeElement* defaultScene = dom->getScene()->getInstance_visual_scene()->getUrl().getElement(); domAsset::domUp_axis *up = dom->getAsset()->getUp_axis(); switch( up->getValue() ) { case UPAXISTYPE_X_UP: upAxis = eCXUp; break; case UPAXISTYPE_Y_UP: upAxis = eCYUp; break; case UPAXISTYPE_Z_UP: upAxis = eCZUp; break; default: break; } if(defaultScene) ReadScene( (domVisual_scene *)defaultScene, upAxis ); if (m_collada) { delete m_collada; m_collada = 0; } if( reportWarningsAndErrors ) { char tempReport[MAX_NAME_SIZE]; COLORREF color; if( numErrors > 0 ) color = COLOR_RED; else if (numWarnings > 0 ) color = COLOR_YELLOW; else color = COLOR_GREEN; sprintf( tempReport, "\n%s - %i error (s), %i warning (s)", nameOnly, numErrors, numWarnings ); PrintInfo( tempReport, color ); totalErrors += numErrors; totalWarnings += numWarnings; } return CTrue; }
MessageRef ReadZipFile(const char * fileName, bool loadData) { FileDataIO fio(muscleFopen(fileName, "rb")); return ReadZipFile(fio, loadData); }