CVoid CWater::SetDuDvMap( CChar* fileName ) { Cpy( m_strDuDvMap, fileName ); CImage* image = GetWaterImage( GetAfterPath( m_strDuDvMap ) ); if( image == NULL ) { image = CNew (CImage); CTexture::LoadDDSTexture( image, m_strDuDvMap, NULL ); image->SetName( GetAfterPath( m_strDuDvMap ) ); g_waterImages.push_back( image ); } else { //CChar temp[MAX_NAME_SIZE]; //sprintf( temp, "\n%s%s%s", "Image '", GetAfterPath(m_strDuDvMap), "' already exists." ); //PrintInfo( temp, COLOR_YELLOW ); } m_dudvMapImg = image; };
//CBool CTexture::LoadTargaTexture( CImage * texObj, CChar* name, CChar* sceneFileName ) //{ // //attache the sceneFileName path( without the dea file ) to the texture name // CChar pathName[MAX_NAME_SIZE]; // // if( sceneFileName ) //To deal with Collada files. // { // CChar * texName = GetAfterPath( name ); //don't know if it's required? Maybe the name in collada file has no path // //strcpy( pathName , sceneFileName ); // //CChar *removeExtra = GetAfterPath( pathName ); // //removeExtra[0] = 0; // //strcat( pathName, texName ); // CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; // Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName ); // GetWithoutDot( g_currentVSceneNameWithoutDot ); // // sprintf( pathName, "%s%s%s%s", "assets/vscenes/", g_currentVSceneNameWithoutDot, "/Textures/", texName ); // } // else //To load independent targa files(not specified in a collada file ) // strcpy( pathName, name ); // // ILuint imageId; // ilGenImages(1, &imageId); // ilBindImage(imageId); // // //PrintInfo( _T( "Reading Image : " ) ); // //PrintInfo( _T( "'" ) + CString( pathName ) + _T("'\n"), COLOR_RED_BLUE ); // // // Read in the image file into DevIL. // if (!ilLoadImage(pathName)) { // // ERROR // ilDeleteImages(1, &imageId); // MessageBox( NULL, _T("CTexture::LoadTargaTexture > Couldn't load the targa file\n"), _T( "VandaEngine Error"), MB_OK ); // return false; // } // else { // texObj->SetWidth( ilGetInteger(IL_IMAGE_WIDTH) ); // texObj->SetHeight( ilGetInteger(IL_IMAGE_HEIGHT) ); // // CUChar* imageData; // CInt imageSize; // // imageSize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * ilGetInteger(IL_IMAGE_CHANNELS); // imageData = (CUChar*)malloc( imageSize ); // // if( ilGetInteger(IL_IMAGE_CHANNELS) == 3 ) // texObj->SetFormat( TGA_TRUECOLOR_24 ); // else if ( ilGetInteger(IL_IMAGE_CHANNELS) == 4 ) // texObj->SetFormat( TGA_TRUECOLOR_32 ); // // memcpy( imageData , ilGetData() , imageSize ); // texObj->SetImageData( imageData ); // ilDeleteImages(1, &imageId); // } // CreateTargaTexture( texObj ); // // return CTrue; //} // CBool CTexture::LoadDDSTexture( CImage * texObj, CChar* name, CChar* sceneFileName ) { //attache the sceneFileName path( without the dea file ) to the texture name CChar pathName[MAX_NAME_SIZE]; if( sceneFileName ) //To deal with Collada files. { CChar * texName = GetAfterPath( name ); //replace %20 with space using std::string std::string s(texName); size_t i = 0; for (;;) { i = s.find("%20", i); if (i == string::npos) { break; } s.replace(i, 3, " "); } strcpy(texName, s.c_str()); sprintf( pathName, "%s%s", g_pathProperties.m_meshDiffuseTexturePath, texName ); } else //To load independent dds files(not specified in a collada file ) strcpy( pathName, name ); ifstream file(pathName, ios::binary); if (! file) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "%s%s%s", "CTexture::LoadDDSTexture > Couldn't open the DDS file '", pathName, "'" ); MessageBoxA( NULL, temp, "VandaEngine Error", MB_OK ); return false; } CDDS *m_ddsImage = CNew( CDDS ); if (! m_ddsImage->LoadFile(file)) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "%s%s%s", "CTexture::LoadDDSTexture > Couldn't load the DDS file '", pathName, "'" ); MessageBoxA( NULL, temp, "VandaEngine Error", MB_OK ); return false; } texObj->SetWidth( (CInt32)m_ddsImage->GetWidth() ); texObj->SetHeight( (CInt32)m_ddsImage->GetHeight() ); if( m_ddsImage->m_alphaChannel) texObj->SetFormat(TGA_TRUECOLOR_32); else texObj->SetFormat(TGA_TRUECOLOR_24); CreateDDSTexture( texObj, m_ddsImage ); return CTrue; }
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; }
BOOL CVandaEngine1App::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); SetRegistryKey(_T("Vanda Engine 1")); CVandaEngine1Dlg dlg; m_pMainWnd = &dlg; ex_pVandaEngine1Dlg = &dlg; AfxInitRichEdit2(); CCommandLineInfo oInfo; ParseCommandLine(oInfo); // DON'T display a new MDI child window during startup!!! //oInfo.m_nShellCommand = CCommandLineInfo::FileNothing; //if (!ProcessShellCommand(oInfo)) // return FALSE; if(!oInfo.m_strFileName.IsEmpty()) { g_openVINFile = CTrue; Cpy( g_fileNameInCommandLine, oInfo.m_strFileName.GetBuffer( oInfo.m_strFileName.GetLength() ) ); oInfo.m_strFileName.ReleaseBuffer(); std::string fullStr( GetCommandLine() ); std::string subStr; subStr.append( "''" ); subStr.append(oInfo.m_strFileName.GetString()); subStr.append( "''" ); std::string tempStr = fullStr.substr( 0, fullStr.length() - subStr.length() ); CChar tempStrChar[MAX_NAME_SIZE]; Cpy( tempStrChar, tempStr.c_str() ); CChar* afterPath = GetAfterPath( tempStrChar ); std::string afterPathStr( afterPath); std::string finalStr = tempStr.substr(0, tempStr.length() - afterPathStr.length() - 1); finalStr.erase(0, 1); SetCurrentDirectory( finalStr.c_str() ); } INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } return FALSE; }
//CBool CTexture::LoadTargaTexture( CImage * texObj, CChar* name, CChar* sceneFileName ) //{ // //attache the sceneFileName path( without the dea file ) to the texture name // CChar pathName[MAX_NAME_SIZE]; // // if( sceneFileName ) //To deal with COLLADA files. // { // CChar * texName = GetAfterPath( name ); //don't know if it's required? Maybe the name in collada file has no path // //strcpy( pathName , sceneFileName ); // //CChar *removeExtra = GetAfterPath( pathName ); // //removeExtra[0] = 0; // //strcat( pathName, texName ); // //save functions. it should be copies in WIN32 Project as well // CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; // Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName ); // GetWithoutDot( g_currentVSceneNameWithoutDot ); // // sprintf( pathName, "%s%s%s%s", "assets/vscenes/", g_currentVSceneNameWithoutDot, "/Textures/", texName ); // // } // else //To load independent targa files(not specified in a collada file ) // strcpy( pathName, name ); // // ILuint imageId; // ilGenImages(1, &imageId); // ilBindImage(imageId); // // PrintInfo( _T( "\nReading Image : " ) ); // PrintInfo( _T( "'" ) + CString( pathName ) + _T("'"), COLOR_RED_GREEN ); // // // Read in the image file into DevIL. // if (!ilLoadImage(pathName)) { // // ERROR // ilDeleteImages(1, &imageId); // CChar temp[MAX_NAME_SIZE]; // sprintf( temp, "\nError! CTexture::LoadTargaTexture > Couldn't load the targa file: '%s'", pathName ); // PrintInfo( temp, COLOR_RED ); // numErrors += 1; // // return false; // } // else { // texObj->SetWidth( ilGetInteger(IL_IMAGE_WIDTH) ); // texObj->SetHeight( ilGetInteger(IL_IMAGE_HEIGHT) ); // // CUChar* imageData; // CInt imageSize; // // imageSize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * ilGetInteger(IL_IMAGE_CHANNELS); // imageData = (CUChar*)malloc( imageSize ); // // if( ilGetInteger(IL_IMAGE_CHANNELS) == 3 ) // texObj->SetFormat( TGA_TRUECOLOR_24 ); // else if ( ilGetInteger(IL_IMAGE_CHANNELS) == 4 ) // texObj->SetFormat( TGA_TRUECOLOR_32 ); // // memcpy( imageData , ilGetData() , imageSize ); // texObj->SetImageData( imageData ); // ilDeleteImages(1, &imageId); // } // PrintInfo( "\nCreating Texture '" ); // PrintInfo(pathName, COLOR_RED_GREEN); // PrintInfo( "' "); // // CreateTargaTexture( texObj ); // // return CTrue; //} // CBool CTexture::LoadDDSTexture( CImage * texObj, CChar* name, CChar* sceneFileName, CBool reportError ) { //attache the sceneFileName path( without the dea file ) to the texture name CChar pathName[MAX_NAME_SIZE]; if( sceneFileName ) //To deal with COLLADA files. { CChar * texName = NULL; if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { texName = CNewData(CChar,MAX_NAME_SIZE); Cpy( texName, name ); } else { texName = GetAfterPath( name ); } GetWithoutDot( texName); Append( texName, ".dds" ); //replace %20 with space using std::string std::string s(texName); size_t i = 0; for (;;) { i = s.find("%20", i); if (i == string::npos) { break; } s.replace(i, 3, " "); } if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { s.begin(); size_t i = 0; for (;;) { i = s.find("file:/", i); if (i == string::npos) { break; } s.replace(i, 6, ""); } } strcpy(texName, s.c_str()); if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor) { strcpy( pathName, texName ); CDelete(texName); } else { CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE]; Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName ); GetWithoutDot( g_currentVSceneNameWithoutDot ); sprintf( pathName, "%s%s%s%s", g_VScenePath, g_currentVSceneNameWithoutDot, "/Textures/", texName ); } } else //To load independent dds files(not specified in a collada file ) strcpy( pathName, name ); ifstream file(pathName, ios::binary); if (! file ) { if( reportError ) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName ); PrintInfo( temp, COLOR_RED ); numErrors += 1; } return false; } CDDS *m_ddsImage = CNew( CDDS ); if (! m_ddsImage->LoadFile(file) ) { if( reportError ) { CChar temp[MAX_NAME_SIZE]; sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName ); PrintInfo( temp, COLOR_RED ); numErrors += 1; } return false; } texObj->SetWidth( (CInt32)m_ddsImage->GetWidth() ); texObj->SetHeight( (CInt32)m_ddsImage->GetHeight() ); if( m_ddsImage->m_alphaChannel) texObj->SetFormat(TGA_TRUECOLOR_32); else texObj->SetFormat(TGA_TRUECOLOR_24); PrintInfo( "\nCreating Texture ' " ); PrintInfo(pathName, COLOR_RED_GREEN); PrintInfo( " '"); CreateDDSTexture( texObj, m_ddsImage ); return CTrue; }