Exemple #1
0
void CPrefabDlg::OnBnClickedNewPrefab()
{
	int nSelected = -1;
	POSITION p = m_listPrefabPackages.GetFirstSelectedItemPosition();
	while (p)
	{
		nSelected = m_listPrefabPackages.GetNextSelectedItem(p);
	}
	if (nSelected >= 0)
	{
		TCHAR szBuffer[1024];
		DWORD cchBuf(1024);
		LVITEM lvi;
		lvi.iItem = nSelected;
		lvi.iSubItem = 0;
		lvi.mask = LVIF_TEXT;
		lvi.pszText = szBuffer;
		lvi.cchTextMax = cchBuf;
		m_listPrefabPackages.GetItem(&lvi);
		m_selectedPackageName = szBuffer;
	}
	else
	{
		MessageBox("Please select a package!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION);
		return;
	}


	m_prefabNameDlg = CNew(CPrefabNameDlg);
	m_prefabNameDlg->SetInitialData(m_selectedPackageName, "\n", CFalse);
	if (IDOK == m_prefabNameDlg->DoModal())
		InsertItemToPrefabList(m_prefabNameDlg->GetNewName());

	CDelete(m_prefabNameDlg);
}
Exemple #2
0
CSkyDome::CSkyDome()
{
	Cpy (m_strImage, "\n");
	m_hasImage = CFalse;
	m_image = CNew( CImage );
    m_nameIndex = 0;
}
Exemple #3
0
void CPrefabDlg::OnBnClickedNewPackage()
{
	m_prefabNameDlg = CNew(CPrefabNameDlg);
	m_prefabNameDlg->SetInitialData("\n", "\n", CTrue);
	if( IDOK == m_prefabNameDlg->DoModal() )
		InsertItemToPackageList(m_prefabNameDlg->GetNewName());
	CDelete(m_prefabNameDlg);
}
Exemple #4
0
//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;
}
Exemple #5
0
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;
};
Exemple #6
0
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;
}
Exemple #7
0
void CPrefabDlg::OnBnClickedRenamePackage()
{
	int nSelected = -1;
	TCHAR szBuffer[1024];

	POSITION p = m_listPrefabPackages.GetFirstSelectedItemPosition();
	while (p)
	{
		nSelected = m_listPrefabPackages.GetNextSelectedItem(p);
	}
	if (nSelected >= 0)
	{
		DWORD cchBuf(1024);
		LVITEM lvi;
		lvi.iItem = nSelected;
		lvi.iSubItem = 0;
		lvi.mask = LVIF_TEXT;
		lvi.pszText = szBuffer;
		lvi.cchTextMax = cchBuf;
		m_listPrefabPackages.GetItem(&lvi);
		m_selectedPackageName = szBuffer;

		if (Cmp(szBuffer, "Vanda_Basics"))
		{
			MessageBox("You cannot rename this package", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION);
			return;
		}

	}
	else
	{
		MessageBox("Please select an item!", "Vanda Engine Error", MB_OK | MB_ICONINFORMATION);
		return;
	}
	CChar currentPackageName[MAX_NAME_SIZE];
	sprintf(currentPackageName, "%s", szBuffer);
	if (Cmp(g_currentPackageName, currentPackageName))
	{
		MessageBox("current open prefab belongs to selected package. Please close current prefab scene and try again.", "Vanda Engine Error", MB_OK | MB_ICONERROR);
		return;
	}

	//then fill it with the VScenes of the selected project
	for (CUInt i = 0; i < g_projects.size(); i++)
	{
		for (CUInt j = 0; j < g_projects[i]->m_sceneNames.size(); j++)
		{
			//find pkg file
			CChar pkgPath[MAX_NAME_SIZE];
			CChar sceneWithoutDot[MAX_NAME_SIZE];
			Cpy(sceneWithoutDot, g_projects[i]->m_sceneNames[j].c_str());
			GetWithoutDot(sceneWithoutDot);
			sprintf(pkgPath, "%s%s%s%s%s", g_projectsPath, g_projects[i]->m_name, "/", sceneWithoutDot, "/packages.pkg");
			//copy package names
			FILE *PackageFilePtr;
			PackageFilePtr = fopen(pkgPath, "rb");
			if (!PackageFilePtr)
			{
				CChar temp[MAX_NAME_SIZE];
				sprintf(temp, "%s%s%s", "Couldn't open the file '", pkgPath, "' to save data");
				MessageBox(temp, "Vanda Engine Error", MB_OK);
				ReleaseCapture();
				PrintInfo("Rename failed.", COLOR_RED);
				return;
			}
			CUInt size = -1;
			fread(&size, sizeof(CUInt), 1, PackageFilePtr);
			for (CUInt k = 0; k < size; k++)
			{
				CChar name[MAX_NAME_SIZE];
				CChar package_name[MAX_NAME_SIZE];
				CChar prefab_name[MAX_NAME_SIZE];
				//write prefab data
				fread(name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr);
				fread(package_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr);
				fread(prefab_name, sizeof(CChar), MAX_NAME_SIZE, PackageFilePtr);

				if (Cmp(package_name, m_selectedPackageName.c_str()))
				{
					CChar packageName[MAX_NAME_SIZE];
					sprintf(packageName, "This package is used by %s/%s.\nYou can not rename this package.", g_projects[i]->m_name, g_projects[i]->m_sceneNames[j].c_str());
					MessageBox(packageName, "Vanda Engine Error", MB_OK | MB_ICONERROR);
					fclose(PackageFilePtr);
					return;
				}
			}
			fclose(PackageFilePtr);
		}
	}

	m_prefabNameDlg = CNew(CPrefabNameDlg);
	m_prefabNameDlg->SetInitialData(m_selectedPackageName, "\n", CTrue, CTrue);
	if (IDOK == m_prefabNameDlg->DoModal())
	{
		m_listPrefabPackages.SetItemText(nSelected, 0, m_prefabNameDlg->GetNewName());

		CChar PackagePath[MAX_NAME_SIZE];
		HRESULT doc_result_package = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, PackagePath);
		if (doc_result_package != S_OK)
		{
			PrintInfo("\nCouldn't get the documents folder to write data", COLOR_RED);
			return;
		}
		else
		{
			Append(PackagePath, "/Vanda/Packages/");
		}
		CChar old_path[MAX_NAME_SIZE];
		CChar new_path[MAX_NAME_SIZE];
		sprintf(old_path, "%s%s", PackagePath, szBuffer);
		sprintf(new_path, "%s%s", PackagePath, m_prefabNameDlg->GetNewName());
		rename(old_path, new_path);

		//rename vpf files
		for (CUInt i = 0; i < g_prefabPackagesAndNames.size(); i++)
		{
			if (Cmp(g_prefabPackagesAndNames[i].front().c_str(), m_prefabNameDlg->GetNewName()))
			{
				for (CUInt j = 0; j < g_prefabPackagesAndNames[i].size(); j++)
				{
					if (j == 0)continue;
					CChar vpfOldPath[MAX_NAME_SIZE];
					sprintf(vpfOldPath, "%s%s%s%s%s%s%s%s%s", PackagePath, g_prefabPackagesAndNames[i].front().c_str(), "/", g_prefabPackagesAndNames[i][j].c_str(), "/", szBuffer, "_", g_prefabPackagesAndNames[i][j].c_str(), ".vpf");
					CChar vpfNewPath[MAX_NAME_SIZE];
					sprintf(vpfNewPath, "%s%s%s%s%s%s%s%s%s", PackagePath, g_prefabPackagesAndNames[i].front().c_str(), "/", g_prefabPackagesAndNames[i][j].c_str(), "/", g_prefabPackagesAndNames[i].front().c_str(), "_", g_prefabPackagesAndNames[i][j].c_str(), ".vpf");
					rename(vpfOldPath, vpfNewPath);
				}
				break;
			}
		}
		//rename the contents of PKG folder as well
		CChar PKG_old[MAX_URI_SIZE];
		CChar PKG_new[MAX_URI_SIZE];
		sprintf(PKG_old, "%s%s%s%s", PackagePath, "PKG/", szBuffer, ".pkg");
		sprintf(PKG_new, "%s%s%s%s", PackagePath, "PKG/", m_prefabNameDlg->GetNewName(), ".pkg");
		rename(PKG_old, PKG_new);

	}
	CDelete(m_prefabNameDlg);
}
Exemple #8
0
CVoid COctree::SplitNode8( COctree* parent )
{
	for( CUInt i = 0; i < 8; i++ )
	{
		CDelete( m_pSubNode[i] ); 
		m_pSubNode[i] = CNew( COctree );
		m_pSubNode[i]->m_pParent = parent;
		m_pSubNode[i]->SetLevel( m_level + 1 );

		//eTOP_RIGHT_FRONT
		if( i == eTOP_RIGHT_FRONT )
		{
			m_pSubNode[i]->SetDimentions( m_center, m_maxAABB );
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eTOP_RIGHT_FRONT_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eBOTTOM_RIGHT_FRONT )
		{
			CVec3f temp_min( m_center.x, m_center.y, m_minAABB.z );
			CVec3f temp_max( m_maxAABB.x, m_maxAABB.y, m_center.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );	
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eBOTTOM_RIGHT_FRONT_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );

		}
		else if( i == eBOTTOM_LEFT_BACK )
		{
			m_pSubNode[i]->SetDimentions( m_minAABB, m_center );
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eBOTTOM_LEFT_BACK_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eTOP_LEFT_BACK )
		{
			CVec3f temp_min( m_minAABB.x, m_minAABB.y, m_center.z );
			CVec3f temp_max( m_center.x, m_center.y, m_maxAABB.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eTOP_LEFT_BACK_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eBOTTOM_RIGHT_BACK )
		{
			CVec3f temp_min( m_center.x, m_minAABB.y, m_minAABB.z );
			CVec3f temp_max( m_maxAABB.x, m_center.y, m_center.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );	
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eBOTTOM_RIGHT_BACK_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eTOP_RIGHT_BACK )
		{
			CVec3f temp_min( m_center.x, m_minAABB.y, m_center.z );
			CVec3f temp_max( m_maxAABB.x, m_center.y, m_maxAABB.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );	
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eTOP_RIGHT_BACK_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eBOTTOM_LEFT_FRONT )
		{
			CVec3f temp_min( m_minAABB.x, m_center.y, m_minAABB.z );
			CVec3f temp_max( m_center.x, m_maxAABB.y, m_center.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );	
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eBOTTOM_LEFT_FRONT_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		else if( i == eTOP_LEFT_FRONT )
		{
			CVec3f temp_min( m_minAABB.x, m_center.y, m_center.z );
			CVec3f temp_max( m_center.x, m_maxAABB.y, m_maxAABB.z );
			m_pSubNode[i]->SetDimentions( temp_min, temp_max );
			CChar temp_name[MAX_NAME_SIZE];
			sprintf( temp_name, "%s%i", "octree_eTOP_LEFT_FRONT_level_", m_pSubNode[i]->m_level );
			m_pSubNode[i]->SetName( temp_name );
		}
		m_pSubNode[i]->AttachGeometriesToNode();
	}
}
Exemple #9
0
//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;
}