TextureDescriptor *TextureDescriptor::CreateFromFile(const FilePath &filePathname) { if(filePathname.IsEmpty() || filePathname.GetType() == FilePath::PATH_IN_MEMORY) return NULL; FilePath descriptorPathname = GetDescriptorPathname(filePathname); TextureDescriptor *descriptor = new TextureDescriptor(); bool loaded = descriptor->Load(descriptorPathname); if(!loaded) { Logger::Error("[TextureDescriptor::CreateFromFile(]: there are no descriptor file (%s).", descriptorPathname.GetAbsolutePathname().c_str()); SafeRelease(descriptor); return NULL; } return descriptor; }
void CubemapEditorDialog::SaveCubemap(const QString& path) { FilePath filePath(path.toStdString()); DAVA::uint8 faceMask = GetFaceMask(); //copy file to the location where .tex will be put. Add suffixes to file names to distinguish faces String fileNameWithoutExtension = filePath.GetFilename(); String extension = filePath.GetExtension(); fileNameWithoutExtension.replace(fileNameWithoutExtension.find(extension), extension.size(), ""); for(int i = 0 ; i < CubemapUtils::GetMaxFaces(); ++i) { if(!facePath[i].isNull()) { FilePath faceFilePath = filePath; faceFilePath.ReplaceFilename(fileNameWithoutExtension + CubemapUtils::GetFaceNameSuffix(CubemapUtils::MapUIToFrameworkFace(i)) + "." + CubemapUtils::GetDefaultFaceExtension()); DAVA::String targetFullPath = faceFilePath.GetAbsolutePathname().c_str(); if(facePath[i] != targetFullPath.c_str()) { if(QFile::exists(targetFullPath.c_str())) { int answer = ShowQuestion("File overwrite", "File " + targetFullPath + " already exist. Do you want to overwrite it with " + facePath[i].toStdString(), MB_FLAG_YES | MB_FLAG_NO, MB_FLAG_NO); if(MB_FLAG_YES == answer) { bool removeResult = QFile::remove(targetFullPath.c_str()); if(!removeResult) { ShowErrorDialog("Failed to copy texture " + facePath[i].toStdString() + " to " + targetFullPath.c_str()); return; } } else { continue; } } bool copyResult = QFile::copy(facePath[i], targetFullPath.c_str()); if(!copyResult) { ShowErrorDialog("Failed to copy texture " + facePath[i].toStdString() + " to " + targetFullPath); return; } } ClickableQLabel* faceLabel = GetLabelForFace(i); if(faceLabel->GetRotation() != 0) { QTransform transform; transform.rotate(faceLabel->GetRotation()); QImage qimg(targetFullPath.c_str()); QImage rotatedImage = qimg.transformed(transform); rotatedImage.save(targetFullPath.c_str()); faceLabel->SetRotation(0); } } } TextureDescriptor* descriptor = new TextureDescriptor(); bool descriptorReady = false; if(filePath.Exists()) { descriptorReady = descriptor->Load(filePath); } if(!descriptorReady) { descriptor->SetDefaultValues(); descriptor->drawSettings.wrapModeS = descriptor->drawSettings.wrapModeT = Texture::WRAP_CLAMP_TO_EDGE; } descriptor->dataSettings.faceDescription = faceMask; descriptor->Save(filePath); SafeDelete(descriptor); QMessageBox::information(this, "Cubemap texture save result", "Cubemap texture was saved successfully!"); }