Exemplo n.º 1
0
void SceneHelper::CollectTextures(const DAVA::NMaterial *material, DAVA::TexturesMap &textures, TexturesEnumerateMode mode)
{
    DAVA::uint32 texCount = material->GetTextureCount();
    for(DAVA::uint32 t = 0; t < texCount; ++t)
    {
        DAVA::FilePath texturePath = material->GetTexturePath(material->GetTextureName(t));
        if(!texturePath.IsEmpty() && SceneValidator::Instance()->IsPathCorrectForProject(texturePath)&&!NMaterial::IsRuntimeTexture(material->GetTextureName(t)))
        {
            if(mode == EXCLUDE_NULL)
            {
                DAVA::Texture *texture = material->GetTexture(t);
                if(texture && !texture->isRenderTarget)
                {
                    const DAVA::FilePath & path = texture->texDescriptor->pathname;

                    if(path != texturePath)
                    {
                        DAVA::Logger::Error("texture path: \"%s\"\n material (%s) path: \"%s\"\n", path.GetAbsolutePathname().c_str(), material->GetMaterialName().c_str(), texturePath.GetAbsolutePathname().c_str());
                        DVASSERT(path == texturePath);
                    }

                    textures[FILEPATH_MAP_KEY(path)] = texture;
                }
            }
            else if(mode == INCLUDE_NULL)
            {
                textures[FILEPATH_MAP_KEY(texturePath)] = material->GetTexture(t);
            }
            else
            {
                DVASSERT(0 && "Unknown enumeration mode");
            }
        }
    }
}
void CubeMapTextureBrowser::OnCreateCubemapClicked()
{
	QString fileName = QtFileDialog::getSaveFileName(this,
													tr("Create Cubemap Texture"),
													ui->textRootPath->text(),
													tr("Tex File (*.tex)"));
	
	if(!fileName.isNull())
	{
		CubemapEditorDialog dlg(this);
		FilePath fp = fileName.toStdString();
		
		DAVA::FilePath rootPath = fp.GetDirectory();
		dlg.InitForCreating(fp, rootPath);
		dlg.exec();
		
		QString path = rootPath.GetAbsolutePathname().c_str();
		ui->textRootPath->setText(path);
		int currentRow = ui->listTextures->currentRow();
		ReloadTexturesFromUI(path);
		
		if(ui->listTextures->count() > 0 &&
		   currentRow < ui->listTextures->count())
		{
			RestoreListSelection(currentRow);
		}
	}	
}
Exemplo n.º 3
0
void SceneValidator::ValidateLandscapeTexture(Landscape *landscape, Landscape::eTextureLevel texLevel, Set<String> &errorsLog)
{
	DAVA::FilePath landTexName = landscape->GetTextureName(texLevel);
	if(!IsTextureDescriptorPath(landTexName) &&
	   landTexName.GetAbsolutePathname().size() > 0)
	{
		landscape->SetTextureName(texLevel, TextureDescriptor::GetDescriptorPathname(landTexName));
	}

	ValidateTexture(landscape->GetTexture(texLevel), landscape->GetTextureName(texLevel), Format("Landscape. TextureLevel %d", texLevel), errorsLog);
}
Exemplo n.º 4
0
void SceneHelper::CollectDescriptors(DAVA::Set<DAVA::FilePath> &descriptors, const DAVA::FilePath &pathname)
{
	if(pathname.GetType() == FilePath::PATH_EMPTY)
		return;

	DVASSERT(pathname.IsEqualToExtension(TextureDescriptor::GetDescriptorExtension()));

	if(!pathname.IsEmpty() && SceneValidator::Instance()->IsPathCorrectForProject(pathname))
	{
		descriptors.insert(pathname);
	}
}
Exemplo n.º 5
0
void SceneUtils::AddFile(const DAVA::FilePath &sourcePath)
{
    String workingPathname = sourcePath.GetRelativePathname(dataSourceFolder);
    FilePath destinationPath = dataFolder + workingPathname;

    if(sourcePath != destinationPath)
    {
        DVASSERT(!sourcePath.IsEmpty());
        DVASSERT(!destinationPath.IsEmpty());

        filesForCopy[sourcePath] = destinationPath;
    }
}
Exemplo n.º 6
0
void FileListTest::RecursiveCopy(const DAVA::FilePath &src, const DAVA::FilePath &dst)
{
    DVASSERT(src.IsDirectoryPathname() && dst.IsDirectoryPathname());
    
    FileSystem::Instance()->CreateDirectory(dst, true);
    FileSystem::Instance()->CopyDirectory(src, dst);

    FileList fileList(src);
    for(int32 i = 0; i < fileList.GetCount(); ++i)
    {
        if(fileList.IsDirectory(i) && !fileList.IsNavigationDirectory(i))
        {
            RecursiveCopy(fileList.GetPathname(i), dst + (fileList.GetFilename(i) + "/"));
        }
    }
}
Exemplo n.º 7
0
void CubemapEditorDialog::InitForCreating(DAVA::FilePath& textureDescriptorPath, DAVA::FilePath& root)
{
	targetFile = textureDescriptorPath;
	editorMode = CubemapEditorDialog::eEditorModeCreating;
	rootPath = QString::fromStdString(root.GetAbsolutePathname());
	ui->legend->setVisible(true);
	
	faceChanged = false;
}
Exemplo n.º 8
0
void UnpackHelpDoc()
{
	DAVA::String editorVer =SettingsManager::GetValue(Settings::Internal_EditorVersion).AsString();
	DAVA::FilePath docsPath = FilePath(ResourceEditor::DOCUMENTATION_PATH);
	if(editorVer != RESOURCE_EDITOR_VERSION || !docsPath.Exists())
	{
		DAVA::Logger::Info("Unpacking Help...");
		DAVA::ResourceArchive * helpRA = new DAVA::ResourceArchive();
		if(helpRA->Open("~res:/Help.docs"))
		{
			DAVA::FileSystem::Instance()->DeleteDirectory(docsPath);
			DAVA::FileSystem::Instance()->CreateDirectory(docsPath, true);
			helpRA->UnpackToFolder(docsPath);
		}
		DAVA::SafeRelease(helpRA);
	}
	SettingsManager::SetValue(Settings::Internal_EditorVersion, VariantType(String(RESOURCE_EDITOR_VERSION)));
}
Exemplo n.º 9
0
void TextureBrowser::updateInfoConverted()
{
	if(NULL != curTexture && NULL != curDescriptor)
	{
		char tmp[1024];
		const char *formatStr = "Unknown";

		int datasize = 0;
		int filesize = 0;
		QSize imgSize(0, 0);

		if(curDescriptor->compression[curTextureView].format != DAVA::FORMAT_INVALID)
		{
			DAVA::FilePath compressedTexturePath = DAVA::GPUFamilyDescriptor::CreatePathnameForGPU(curDescriptor, curTextureView);
			filesize = QFileInfo(compressedTexturePath.GetAbsolutePathname().c_str()).size();
			formatStr = GlobalEnumMap<DAVA::PixelFormat>::Instance()->ToString(curDescriptor->compression[curTextureView].format);
			
			int w = curDescriptor->compression[curTextureView].compressToWidth;
			int h = curDescriptor->compression[curTextureView].compressToHeight;

			if(0 != w && 0 != h)
			{
				imgSize = QSize(w, h);
			}
			else
			{
				imgSize = QSize(curTexture->width, curTexture->height);
			}

			// get data size
			datasize = ImageTools::GetTexturePhysicalSize(curDescriptor, curTextureView);
		}

		sprintf(tmp, "Format\t: %s\nSize\t: %dx%d\nData size\t: %s\nFile size\t: %s", formatStr, imgSize.width(), imgSize.height(),
			SizeInBytesToString(datasize).c_str(),
			SizeInBytesToString(filesize).c_str());

		ui->labelConvertedFormat->setText(tmp);
	}
	else
	{
		ui->labelConvertedFormat->setText("");
	}
}
Exemplo n.º 10
0
void QtMainWindow::OpenLastProject()
{
    if(CommandLineManager::Instance() && !CommandLineManager::Instance()->IsCommandLineModeEnabled())
    {
        DAVA::FilePath projectPath = EditorSettings::Instance()->GetProjectPath();

        if(projectPath.IsEmpty())
        {
			projectPath = FilePath(ProjectManager::Instance()->ProjectOpenDialog().toStdString());
        }

        if(projectPath.IsEmpty())
		{
			QtLayer::Instance()->Quit();
		}
		else
		{
			ProjectManager::Instance()->ProjectOpen(QString(projectPath.GetAbsolutePathname().c_str()));
		}
    }
}
Exemplo n.º 11
0
void CubemapEditorDialog::InitForEditing(DAVA::FilePath& textureDescriptorPath, DAVA::FilePath& root)
{
	targetFile = textureDescriptorPath;
	editorMode = CubemapEditorDialog::eEditorModeEditing;
	rootPath = QString::fromStdString(root.GetAbsolutePathname());
	
	LoadCubemap(targetFile.GetAbsolutePathname().c_str());
	
	ui->buttonSave->setEnabled(false);
	ui->legend->setVisible(false);
	
	faceChanged = false;
}
Exemplo n.º 12
0
void CustomColorsSystem::SaveTexture(const DAVA::FilePath &filePath)
{
	if(filePath.IsEmpty())
		return;

	Sprite* customColorsSprite = drawSystem->GetCustomColorsProxy()->GetSprite();
	Texture* customColorsTexture = customColorsSprite->GetTexture();

	Image* image = customColorsTexture->CreateImageFromMemory(RenderState::RENDERSTATE_2D_BLEND);
    ImageSystem::Instance()->Save(filePath, image);
	SafeRelease(image);

	StoreSaveFileName(filePath);
	drawSystem->GetCustomColorsProxy()->ResetChanges();
}
Exemplo n.º 13
0
bool CustomColorsSystem::LoadTexture( const DAVA::FilePath &filePath, bool createUndo /* = true */ )
{
	if(filePath.IsEmpty())
		return false;

    Vector<Image*> images;
    ImageSystem::Instance()->Load(filePath, images);
	if(images.empty())
		return false;

	Image* image = images.front();
	if(image)
	{
		Texture* texture = Texture::CreateFromData(image->GetPixelFormat(),
												   image->GetData(),
												   image->GetWidth(),
												   image->GetHeight(),
												   false);
		Sprite* sprite = Sprite::CreateFromTexture(texture, 0, 0, texture->GetWidth(), texture->GetHeight());

		if (createUndo)
		{
			StoreOriginalState();
		}
		RenderManager::Instance()->SetRenderTarget(drawSystem->GetCustomColorsProxy()->GetSprite());
        
        Sprite::DrawState drawState;
		sprite->Draw(&drawState);
        
		RenderManager::Instance()->RestoreRenderTarget();
		AddRectToAccumulator(Rect(Vector2(0.f, 0.f), Vector2(texture->GetWidth(), texture->GetHeight())));

		SafeRelease(sprite);
		SafeRelease(texture);
		for_each(images.begin(), images.end(), SafeRelease<Image>);

		if (createUndo)
		{
			((SceneEditor2*)GetScene())->BeginBatch("Load custom colors texture");
			StoreSaveFileName(filePath);
			CreateUndoPoint();
			((SceneEditor2*)GetScene())->EndBatch();
		}
	}

    return true;
}
Exemplo n.º 14
0
bool CubeMapTextureBrowser::ValidateTextureAndFillThumbnails(DAVA::FilePath& fp,
									  DAVA::Vector<QImage*>& icons,
									  DAVA::Vector<QSize>& actualSize)
{
	bool result = true;
	
	int width = 0;
	int height = 0;
	DAVA::Vector<DAVA::String> faceNames;
	CubemapUtils::GenerateFaceNames(fp.GetAbsolutePathname(), faceNames);
	for(size_t i = 0; i < faceNames.size(); ++i)
	{
		QImage faceImage;
		if(!faceImage.load(faceNames[i].c_str())) //file must be present
		{
			result = false;
		}
	
		if(faceImage.width() != faceImage.height() || //file must be square and be power of 2
		   !IsPowerOf2(faceImage.width()))
		{
			result = false;
		}
				
		if(0 == i)
		{
			width = faceImage.width();
			height = faceImage.height();
		}
		else if(faceImage.width() != width || //all files should be the same size
				faceImage.height() != height)
		{
			result = false;
		}
		
		//scale image and put scaled version to an array
		QImage scaledFaceTemp = faceImage.scaled(FACE_IMAGE_SIZE, FACE_IMAGE_SIZE);
		QImage* scaledFace = new QImage(scaledFaceTemp);
		
		icons.push_back(scaledFace);
		actualSize.push_back(QSize(faceImage.width(), faceImage.height()));
	}
	
	return result;
}
Exemplo n.º 15
0
void SceneValidator::ValidateScene(Scene *scene, const DAVA::FilePath &scenePath, Set<String> &errorsLog)
{
    if(scene) 
    {
		DAVA::String tmp = scenePath.GetAbsolutePathname();
		size_t pos = tmp.find("/Data");
		if(pos != String::npos)
		{
			SetPathForChecking(tmp.substr(0, pos + 1));
		}

        ValidateSceneNode(scene, errorsLog);

        for (Set<Entity*>::iterator it = emptyNodesForDeletion.begin(); it != emptyNodesForDeletion.end(); ++it)
        {
            Entity * node = *it;
            if (node->GetParent())
            {
                node->GetParent()->RemoveNode(node);
            }
        }
        

		for (Set<Entity *>::iterator it = emptyNodesForDeletion.begin(); it != emptyNodesForDeletion.end(); ++it)
		{
			Entity *node = *it;
			SafeRelease(node);
		}

        emptyNodesForDeletion.clear();
    }
    else 
    {
        errorsLog.insert(String("Scene in NULL!"));
    }
}
Exemplo n.º 16
0
void SelectPathWidgetBase::SetOpenDialogDefaultPath(const DAVA::FilePath& path)
{
    openDialogDefaultPath = path.GetAbsolutePathname();
}
Exemplo n.º 17
0
DAVA::FilePath SceneUtils::GetNewFilePath(const DAVA::FilePath &oldPathname) const
{
	String workingPathname = oldPathname.GetRelativePathname(dataSourceFolder);
    return dataFolder + workingPathname;
}