diff --git a/application/application.pro b/application/application.pro
index 98a4716a..b576c7e7 100644
--- a/application/application.pro
+++ b/application/application.pro
@@ -145,20 +145,6 @@ SOURCES += sources/log_browser.cc
HEADERS += sources/log_browser_dialog.h
SOURCES += sources/log_browser_dialog.cc
SOURCES += sources/main.cc
-HEADERS += sources/material.h
-SOURCES += sources/material.cc
-HEADERS += sources/material_edit_widget.h
-SOURCES += sources/material_edit_widget.cc
-HEADERS += sources/material_layer.h
-SOURCES += sources/material_layer.cc
-HEADERS += sources/material_list_widget.h
-SOURCES += sources/material_list_widget.cc
-HEADERS += sources/material_manage_widget.h
-SOURCES += sources/material_manage_widget.cc
-HEADERS += sources/material_previews_generator.h
-SOURCES += sources/material_previews_generator.cc
-HEADERS += sources/material_widget.h
-SOURCES += sources/material_widget.cc
HEADERS += sources/mesh_generator.h
SOURCES += sources/mesh_generator.cc
HEADERS += sources/mesh_preview_images_generator.h
@@ -195,8 +181,6 @@ HEADERS += sources/skeleton_ik_mover.h
SOURCES += sources/skeleton_ik_mover.cc
HEADERS += sources/spinnable_toolbar_icon.h
SOURCES += sources/spinnable_toolbar_icon.cc
-HEADERS += sources/texture_generator.h
-SOURCES += sources/texture_generator.cc
HEADERS += sources/theme.h
SOURCES += sources/theme.cc
HEADERS += sources/toolbar_button.h
diff --git a/application/resources.qrc b/application/resources.qrc
index 478d27cc..3b78ef15 100644
--- a/application/resources.qrc
+++ b/application/resources.qrc
@@ -25,7 +25,6 @@
resources/toolbar_z_disabled.svg
resources/toolbar_radius.svg
resources/toolbar_radius_disabled.svg
- resources/material-demo-model.ds3
resources/model-addax.ds3
resources/model-banana.ds3
resources/model-bicycle.ds3
diff --git a/application/resources/material-demo-model.ds3 b/application/resources/material-demo-model.ds3
deleted file mode 100644
index 23a04e6d..00000000
Binary files a/application/resources/material-demo-model.ds3 and /dev/null differ
diff --git a/application/sources/document.cc b/application/sources/document.cc
index 656ed07e..5913b697 100644
--- a/application/sources/document.cc
+++ b/application/sources/document.cc
@@ -1,9 +1,8 @@
#include "document.h"
#include "image_forever.h"
-#include "material_previews_generator.h"
#include "mesh_generator.h"
#include "mesh_result_post_processor.h"
-#include "texture_generator.h"
+#include "uv_map_generator.h"
#include
#include
#include
@@ -1423,14 +1422,6 @@ bool Document::originSettled() const
return !qFuzzyIsNull(getOriginX()) && !qFuzzyIsNull(getOriginY()) && !qFuzzyIsNull(getOriginZ());
}
-const Material* Document::findMaterial(dust3d::Uuid materialId) const
-{
- auto it = materialMap.find(materialId);
- if (it == materialMap.end())
- return nullptr;
- return &it->second;
-}
-
void Document::setNodeCutRotation(dust3d::Uuid nodeId, float cutRotation)
{
auto node = nodeMap.find(nodeId);
@@ -1571,8 +1562,7 @@ void Document::setEditMode(DocumentEditMode mode)
}
void Document::toSnapshot(dust3d::Snapshot* snapshot, const std::set& limitNodeIds,
- DocumentToSnapshotFor forWhat,
- const std::set& limitMaterialIds) const
+ DocumentToSnapshotFor forWhat) const
{
if (DocumentToSnapshotFor::Document == forWhat || DocumentToSnapshotFor::Nodes == forWhat) {
std::set limitPartIds;
@@ -1640,8 +1630,6 @@ void Document::toSnapshot(dust3d::Snapshot* snapshot, const std::setrootComponent["children"] = children;
}
}
- if (DocumentToSnapshotFor::Document == forWhat || DocumentToSnapshotFor::Materials == forWhat) {
- for (const auto& materialId : materialIdList) {
- if (!limitMaterialIds.empty() && limitMaterialIds.find(materialId) == limitMaterialIds.end())
- continue;
- auto findMaterialResult = materialMap.find(materialId);
- if (findMaterialResult == materialMap.end()) {
- qDebug() << "Find material failed:" << materialId;
- continue;
- }
- auto& materialIt = *findMaterialResult;
- std::map material;
- material["id"] = materialIt.second.id.toString();
- material["type"] = "MetalRoughness";
- if (!materialIt.second.name.isEmpty())
- material["name"] = materialIt.second.name.toUtf8().constData();
- std::vector, std::vector>>> layers;
- for (const auto& layer : materialIt.second.layers) {
- std::vector> maps;
- for (const auto& mapItem : layer.maps) {
- std::map textureMap;
- textureMap["for"] = TextureTypeToString(mapItem.forWhat);
- textureMap["linkDataType"] = "imageId";
- textureMap["linkData"] = mapItem.imageId.toString();
- maps.push_back(textureMap);
- }
- std::map layerAttributes;
- if (!qFuzzyCompare((float)layer.tileScale, (float)1.0))
- layerAttributes["tileScale"] = std::to_string(layer.tileScale);
- layers.push_back({ layerAttributes, maps });
- }
- snapshot->materials.push_back(std::make_pair(material, layers));
- }
- }
if (DocumentToSnapshotFor::Document == forWhat) {
std::map canvas;
canvas["originX"] = std::to_string(getOriginX());
@@ -1787,49 +1742,6 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
std::set inversePartIds;
std::map oldNewIdMap;
- for (const auto& materialIt : snapshot.materials) {
- const auto& materialAttributes = materialIt.first;
- auto materialType = dust3d::String::valueOrEmpty(materialAttributes, "type");
- if ("MetalRoughness" != materialType) {
- qDebug() << "Unsupported material type:" << materialType;
- continue;
- }
- dust3d::Uuid oldMaterialId = dust3d::Uuid(dust3d::String::valueOrEmpty(materialAttributes, "id"));
- dust3d::Uuid newMaterialId = SnapshotSource::Import == source ? oldMaterialId : dust3d::Uuid::createUuid();
- oldNewIdMap[oldMaterialId] = newMaterialId;
- if (materialMap.end() == materialMap.find(newMaterialId)) {
- auto& newMaterial = materialMap[newMaterialId];
- newMaterial.id = newMaterialId;
- newMaterial.name = dust3d::String::valueOrEmpty(materialAttributes, "name").c_str();
- for (const auto& layerIt : materialIt.second) {
- MaterialLayer layer;
- auto findTileScale = layerIt.first.find("tileScale");
- if (findTileScale != layerIt.first.end())
- layer.tileScale = dust3d::String::toFloat(findTileScale->second);
- for (const auto& mapItem : layerIt.second) {
- auto textureTypeString = dust3d::String::valueOrEmpty(mapItem, "for");
- auto textureType = dust3d::TextureTypeFromString(textureTypeString.c_str());
- if (dust3d::TextureType::None == textureType) {
- qDebug() << "Unsupported texture type:" << textureTypeString;
- continue;
- }
- auto linkTypeString = dust3d::String::valueOrEmpty(mapItem, "linkDataType");
- if ("imageId" != linkTypeString) {
- qDebug() << "Unsupported link data type:" << linkTypeString;
- continue;
- }
- auto imageId = dust3d::Uuid(dust3d::String::valueOrEmpty(mapItem, "linkData"));
- MaterialMap materialMap;
- materialMap.imageId = imageId;
- materialMap.forWhat = textureType;
- layer.maps.push_back(materialMap);
- }
- newMaterial.layers.push_back(layer);
- }
- materialIdList.push_back(newMaterialId);
- emit materialAdded(newMaterialId);
- }
- }
std::map cutFaceLinkedIdModifyMap;
for (const auto& partKv : snapshot.parts) {
const auto newUuid = dust3d::Uuid::createUuid();
@@ -1895,9 +1807,6 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
const auto& hollowThicknessIt = partKv.second.find("hollowThickness");
if (hollowThicknessIt != partKv.second.end())
part.hollowThickness = dust3d::String::toFloat(hollowThicknessIt->second);
- const auto& materialIdIt = partKv.second.find("materialId");
- if (materialIdIt != partKv.second.end())
- part.materialId = oldNewIdMap[dust3d::Uuid(materialIdIt->second)];
part.countershaded = dust3d::String::isTrue(dust3d::String::valueOrEmpty(partKv.second, "countershaded"));
part.smooth = dust3d::String::isTrue(dust3d::String::valueOrEmpty(partKv.second, "smooth"));
newAddedPartIds.insert(part.id);
@@ -2054,9 +1963,6 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
for (const auto& edgeIt : newAddedEdgeIds) {
emit checkEdge(edgeIt);
}
-
- if (!snapshot.materials.empty())
- emit materialListChanged();
}
void Document::silentReset()
@@ -2068,8 +1974,6 @@ void Document::silentReset()
edgeMap.clear();
partMap.clear();
componentMap.clear();
- materialMap.clear();
- materialIdList.clear();
rootComponent = SkeletonComponent();
}
@@ -2244,29 +2148,31 @@ void Document::generateTexture()
m_isTextureObsolete = false;
- dust3d::Snapshot* snapshot = new dust3d::Snapshot;
- toSnapshot(snapshot);
+ auto object = std::make_unique(*m_postProcessedObject);
+
+ auto snapshot = std::make_unique();
+ toSnapshot(snapshot.get());
QThread* thread = new QThread;
- m_textureGenerator = new TextureGenerator(*m_postProcessedObject, snapshot);
+ m_textureGenerator = new UvMapGenerator(std::move(object), std::move(snapshot));
m_textureGenerator->moveToThread(thread);
- connect(thread, &QThread::started, m_textureGenerator, &TextureGenerator::process);
- connect(m_textureGenerator, &TextureGenerator::finished, this, &Document::textureReady);
- connect(m_textureGenerator, &TextureGenerator::finished, thread, &QThread::quit);
+ connect(thread, &QThread::started, m_textureGenerator, &UvMapGenerator::process);
+ connect(m_textureGenerator, &UvMapGenerator::finished, this, &Document::textureReady);
+ connect(m_textureGenerator, &UvMapGenerator::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start();
}
void Document::textureReady()
{
- updateTextureImage(m_textureGenerator->takeResultTextureColorImage());
- updateTextureNormalImage(m_textureGenerator->takeResultTextureNormalImage());
- updateTextureMetalnessImage(m_textureGenerator->takeResultTextureMetalnessImage());
- updateTextureRoughnessImage(m_textureGenerator->takeResultTextureRoughnessImage());
- updateTextureAmbientOcclusionImage(m_textureGenerator->takeResultTextureAmbientOcclusionImage());
+ updateTextureImage(m_textureGenerator->takeResultTextureColorImage().release());
+ updateTextureNormalImage(m_textureGenerator->takeResultTextureNormalImage().release());
+ updateTextureMetalnessImage(m_textureGenerator->takeResultTextureMetalnessImage().release());
+ updateTextureRoughnessImage(m_textureGenerator->takeResultTextureRoughnessImage().release());
+ updateTextureAmbientOcclusionImage(m_textureGenerator->takeResultTextureAmbientOcclusionImage().release());
delete m_resultTextureMesh;
- m_resultTextureMesh = m_textureGenerator->takeResultMesh();
+ m_resultTextureMesh = m_textureGenerator->takeResultMesh().release();
m_postProcessedObject->alphaEnabled = m_textureGenerator->hasTransparencySettings();
@@ -2486,21 +2392,6 @@ void Document::setPartDeformUnified(dust3d::Uuid partId, bool unified)
emit skeletonChanged();
}
-void Document::setPartMaterialId(dust3d::Uuid partId, dust3d::Uuid materialId)
-{
- auto part = partMap.find(partId);
- if (part == partMap.end()) {
- qDebug() << "Part not found:" << partId;
- return;
- }
- if (part->second.materialId == materialId)
- return;
- part->second.materialId = materialId;
- part->second.dirty = true;
- emit partMaterialIdChanged(partId);
- emit textureChanged();
-}
-
void Document::setPartRoundState(dust3d::Uuid partId, bool rounded)
{
auto part = partMap.find(partId);
@@ -2758,17 +2649,6 @@ bool Document::hasPastableNodesInClipboard() const
return false;
}
-bool Document::hasPastableMaterialsInClipboard() const
-{
- const QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
- if (mimeData->hasText()) {
- if (-1 != mimeData->text().indexOf("= 2;
@@ -2816,126 +2696,6 @@ void Document::checkExportReadyState()
emit exportReady();
}
-void Document::addMaterial(dust3d::Uuid materialId, QString name, std::vector layers)
-{
- auto findMaterialResult = materialMap.find(materialId);
- if (findMaterialResult != materialMap.end()) {
- qDebug() << "Material already exist:" << materialId;
- return;
- }
-
- dust3d::Uuid newMaterialId = materialId;
- auto& material = materialMap[newMaterialId];
- material.id = newMaterialId;
-
- material.name = name;
- material.layers = layers;
- material.dirty = true;
-
- materialIdList.push_back(newMaterialId);
-
- emit materialAdded(newMaterialId);
- emit materialListChanged();
- emit optionsChanged();
-}
-
-void Document::removeMaterial(dust3d::Uuid materialId)
-{
- auto findMaterialResult = materialMap.find(materialId);
- if (findMaterialResult == materialMap.end()) {
- qDebug() << "Remove a none exist material:" << materialId;
- return;
- }
- materialIdList.erase(std::remove(materialIdList.begin(), materialIdList.end(), materialId), materialIdList.end());
- materialMap.erase(findMaterialResult);
-
- emit materialListChanged();
- emit materialRemoved(materialId);
- emit optionsChanged();
-}
-
-void Document::setMaterialLayers(dust3d::Uuid materialId, std::vector layers)
-{
- auto findMaterialResult = materialMap.find(materialId);
- if (findMaterialResult == materialMap.end()) {
- qDebug() << "Find material failed:" << materialId;
- return;
- }
- findMaterialResult->second.layers = layers;
- findMaterialResult->second.dirty = true;
- emit materialLayersChanged(materialId);
- emit textureChanged();
- emit optionsChanged();
-}
-
-void Document::renameMaterial(dust3d::Uuid materialId, QString name)
-{
- auto findMaterialResult = materialMap.find(materialId);
- if (findMaterialResult == materialMap.end()) {
- qDebug() << "Find material failed:" << materialId;
- return;
- }
- if (findMaterialResult->second.name == name)
- return;
-
- findMaterialResult->second.name = name;
- emit materialNameChanged(materialId);
- emit materialListChanged();
- emit optionsChanged();
-}
-
-void Document::generateMaterialPreviews()
-{
- if (nullptr != m_materialPreviewsGenerator) {
- return;
- }
-
- QThread* thread = new QThread;
- m_materialPreviewsGenerator = new MaterialPreviewsGenerator();
- bool hasDirtyMaterial = false;
- for (auto& materialIt : materialMap) {
- if (!materialIt.second.dirty)
- continue;
- m_materialPreviewsGenerator->addMaterial(materialIt.first, materialIt.second.layers);
- materialIt.second.dirty = false;
- hasDirtyMaterial = true;
- }
- if (!hasDirtyMaterial) {
- delete m_materialPreviewsGenerator;
- m_materialPreviewsGenerator = nullptr;
- delete thread;
- return;
- }
-
- qDebug() << "Material previews generating..";
-
- m_materialPreviewsGenerator->moveToThread(thread);
- connect(thread, &QThread::started, m_materialPreviewsGenerator, &MaterialPreviewsGenerator::process);
- connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, this, &Document::materialPreviewsReady);
- connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, thread, &QThread::quit);
- connect(thread, &QThread::finished, thread, &QThread::deleteLater);
- thread->start();
-}
-
-void Document::materialPreviewsReady()
-{
- for (const auto& materialId : m_materialPreviewsGenerator->generatedPreviewMaterialIds()) {
- auto material = materialMap.find(materialId);
- if (material != materialMap.end()) {
- ModelMesh* resultPartPreviewMesh = m_materialPreviewsGenerator->takePreview(materialId);
- material->second.updatePreviewMesh(resultPartPreviewMesh);
- emit materialPreviewChanged(materialId);
- }
- }
-
- delete m_materialPreviewsGenerator;
- m_materialPreviewsGenerator = nullptr;
-
- qDebug() << "Material previews generation done";
-
- generateMaterialPreviews();
-}
-
bool Document::isMeshGenerating() const
{
return nullptr != m_meshGenerator;
diff --git a/application/sources/document.h b/application/sources/document.h
index 0c5b8809..8a890491 100644
--- a/application/sources/document.h
+++ b/application/sources/document.h
@@ -2,7 +2,6 @@
#define DUST3D_APPLICATION_DOCUMENT_H_
#include "debug.h"
-#include "material_layer.h"
#include "model_mesh.h"
#include "monochrome_mesh.h"
#include "theme.h"
@@ -165,7 +164,6 @@ public:
float cutRotation;
dust3d::CutFace cutFace;
dust3d::Uuid cutFaceLinkedId;
- dust3d::Uuid materialId;
dust3d::PartTarget target;
float colorSolubility;
float metalness;
@@ -338,10 +336,6 @@ public:
{
return cutRotationAdjusted() || cutFaceAdjusted() || hollowThicknessAdjusted();
}
- bool materialAdjusted() const
- {
- return !materialId.isNull();
- }
bool isEditVisible() const
{
return visible && !disabled;
@@ -364,7 +358,6 @@ public:
cutFaceLinkedId = other.cutFaceLinkedId;
componentId = other.componentId;
dirty = other.dirty;
- materialId = other.materialId;
target = other.target;
colorSolubility = other.colorSolubility;
countershaded = other.countershaded;
@@ -551,8 +544,7 @@ private:
std::set m_childrenIdSet;
};
-class MaterialPreviewsGenerator;
-class TextureGenerator;
+class UvMapGenerator;
class MeshGenerator;
class MeshResultPostProcessor;
@@ -561,40 +553,9 @@ public:
dust3d::Snapshot snapshot;
};
-class Material {
-public:
- Material()
- {
- }
- ~Material()
- {
- delete m_previewMesh;
- }
- dust3d::Uuid id;
- QString name;
- bool dirty = true;
- std::vector layers;
- void updatePreviewMesh(ModelMesh* previewMesh)
- {
- delete m_previewMesh;
- m_previewMesh = previewMesh;
- }
- ModelMesh* takePreviewMesh() const
- {
- if (nullptr == m_previewMesh)
- return nullptr;
- return new ModelMesh(*m_previewMesh);
- }
-
-private:
- Q_DISABLE_COPY(Material);
- ModelMesh* m_previewMesh = nullptr;
-};
-
enum class DocumentToSnapshotFor {
Document = 0,
- Nodes,
- Materials
+ Nodes
};
class Document : public QObject {
@@ -618,7 +579,6 @@ signals:
void partColorStateChanged(dust3d::Uuid partId);
void partCutRotationChanged(dust3d::Uuid partId);
void partCutFaceChanged(dust3d::Uuid partId);
- void partMaterialIdChanged(dust3d::Uuid partId);
void partChamferStateChanged(dust3d::Uuid partId);
void partTargetChanged(dust3d::Uuid partId);
void partColorSolubilityChanged(dust3d::Uuid partId);
@@ -638,12 +598,6 @@ signals:
void uncheckAll();
void checkNode(dust3d::Uuid nodeId);
void checkEdge(dust3d::Uuid edgeId);
- void materialAdded(dust3d::Uuid materialId);
- void materialRemoved(dust3d::Uuid materialId);
- void materialListChanged();
- void materialNameChanged(dust3d::Uuid materialId);
- void materialLayersChanged(dust3d::Uuid materialId);
- void materialPreviewChanged(dust3d::Uuid materialId);
void meshGenerating();
void postProcessing();
void textureGenerating();
@@ -706,9 +660,6 @@ public: // need initialize
public:
Document();
~Document();
- std::map materialMap;
- std::vector materialIdList;
-
bool undoable() const;
bool redoable() const;
bool hasPastableNodesInClipboard() const;
@@ -717,8 +668,7 @@ public:
bool isEdgeEditable(dust3d::Uuid edgeId) const;
void copyNodes(std::set nodeIdSet) const;
void toSnapshot(dust3d::Snapshot* snapshot, const std::set& limitNodeIds = std::set(),
- DocumentToSnapshotFor forWhat = DocumentToSnapshotFor::Document,
- const std::set& limitMaterialIds = std::set()) const;
+ DocumentToSnapshotFor forWhat = DocumentToSnapshotFor::Document) const;
void fromSnapshot(const dust3d::Snapshot& snapshot);
enum class SnapshotSource {
Unknown,
@@ -726,7 +676,6 @@ public:
Import
};
void addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSource source = SnapshotSource::Paste);
- const Material* findMaterial(dust3d::Uuid materialId) const;
ModelMesh* takeResultMesh();
MonochromeMesh* takeWireframeMesh();
ModelMesh* takePaintedMesh();
@@ -740,7 +689,6 @@ public:
void updateTextureMetalnessImage(QImage* image);
void updateTextureRoughnessImage(QImage* image);
void updateTextureAmbientOcclusionImage(QImage* image);
- bool hasPastableMaterialsInClipboard() const;
const dust3d::Object& currentPostProcessedObject() const;
bool isExportReady() const;
bool isPostProcessResultObsolete() const;
@@ -822,8 +770,6 @@ public slots:
void textureReady();
void postProcess();
void postProcessedMeshResultReady();
- void generateMaterialPreviews();
- void materialPreviewsReady();
void setPartSubdivState(dust3d::Uuid partId, bool subdived);
void setPartXmirrorState(dust3d::Uuid partId, bool mirrored);
void setPartDeformThickness(dust3d::Uuid partId, float thickness);
@@ -834,7 +780,6 @@ public slots:
void setPartCutRotation(dust3d::Uuid partId, float cutRotation);
void setPartCutFace(dust3d::Uuid partId, dust3d::CutFace cutFace);
void setPartCutFaceLinkedId(dust3d::Uuid partId, dust3d::Uuid linkedId);
- void setPartMaterialId(dust3d::Uuid partId, dust3d::Uuid materialId);
void setPartChamferState(dust3d::Uuid partId, bool chamfered);
void setPartTarget(dust3d::Uuid partId, dust3d::PartTarget target);
void setPartColorSolubility(dust3d::Uuid partId, float solubility);
@@ -852,10 +797,6 @@ public slots:
void silentReset();
void toggleSmoothNormal();
void enableWeld(bool enabled);
- void addMaterial(dust3d::Uuid materialId, QString name, std::vector);
- void removeMaterial(dust3d::Uuid materialId);
- void setMaterialLayers(dust3d::Uuid materialId, std::vector layers);
- void renameMaterial(dust3d::Uuid materialId, QString name);
void removeNode(dust3d::Uuid nodeId);
void removeEdge(dust3d::Uuid edgeId);
void removePart(dust3d::Uuid partId);
@@ -932,14 +873,13 @@ private:
int m_batchChangeRefCount = 0;
dust3d::Object* m_currentObject = nullptr;
bool m_isTextureObsolete = false;
- TextureGenerator* m_textureGenerator = nullptr;
+ UvMapGenerator* m_textureGenerator = nullptr;
bool m_isPostProcessResultObsolete = false;
MeshResultPostProcessor* m_postProcessor = nullptr;
dust3d::Object* m_postProcessedObject = new dust3d::Object;
ModelMesh* m_resultTextureMesh = nullptr;
unsigned long long m_textureImageUpdateVersion = 0;
bool m_smoothNormal = false;
- MaterialPreviewsGenerator* m_materialPreviewsGenerator = nullptr;
quint64 m_meshGenerationId = 0;
quint64 m_nextMeshGenerationId = 0;
void* m_generatedCacheContext = nullptr;
diff --git a/application/sources/document_saver.cc b/application/sources/document_saver.cc
index 1a7aebba..95f83bbc 100644
--- a/application/sources/document_saver.cc
+++ b/application/sources/document_saver.cc
@@ -39,17 +39,6 @@ void DocumentSaver::collectUsedResourceIds(const dust3d::Snapshot* snapshot,
dust3d::Uuid imageId = dust3d::Uuid(findImageIdString->second);
imageIds.insert(imageId);
}
- for (const auto& material : snapshot->materials) {
- for (auto& layer : material.second) {
- for (auto& mapItem : layer.second) {
- auto findImageIdString = mapItem.find("linkData");
- if (findImageIdString == mapItem.end())
- continue;
- dust3d::Uuid imageId = dust3d::Uuid(findImageIdString->second);
- imageIds.insert(imageId);
- }
- }
- }
}
bool DocumentSaver::save(const QString* filename,
diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc
index 96613b4b..7bb1f310 100644
--- a/application/sources/document_window.cc
+++ b/application/sources/document_window.cc
@@ -10,14 +10,13 @@
#include "horizontal_line_widget.h"
#include "image_forever.h"
#include "log_browser.h"
-#include "material_manage_widget.h"
#include "part_manage_widget.h"
#include "preferences.h"
#include "skeleton_graphics_widget.h"
#include "spinnable_toolbar_icon.h"
-#include "texture_generator.h"
#include "theme.h"
#include "updates_check_widget.h"
+#include "uv_map_generator.h"
#include "version.h"
#include
#include
@@ -270,21 +269,6 @@ DocumentWindow::DocumentWindow()
partsDocker->setWidget(m_partManageWidget);
addDockWidget(Qt::RightDockWidgetArea, partsDocker);
- QDockWidget* materialDocker = new QDockWidget(tr("Materials"), this);
- materialDocker->setAllowedAreas(Qt::RightDockWidgetArea);
- MaterialManageWidget* materialManageWidget = new MaterialManageWidget(m_document, materialDocker);
- materialDocker->setWidget(materialManageWidget);
- connect(materialManageWidget, &MaterialManageWidget::registerDialog, this, &DocumentWindow::registerDialog);
- connect(materialManageWidget, &MaterialManageWidget::unregisterDialog, this, &DocumentWindow::unregisterDialog);
- addDockWidget(Qt::RightDockWidgetArea, materialDocker);
- connect(materialDocker, &QDockWidget::topLevelChanged, [=](bool topLevel) {
- Q_UNUSED(topLevel);
- for (const auto& material : m_document->materialMap)
- emit m_document->materialPreviewChanged(material.first);
- });
-
- tabifyDockWidget(partsDocker, materialDocker);
-
partsDocker->raise();
QWidget* titleBarWidget = new QWidget;
@@ -431,13 +415,6 @@ DocumentWindow::DocumentWindow()
});
m_windowMenu->addAction(m_showPartsListAction);
- m_showMaterialsAction = new QAction(tr("Materials"), this);
- connect(m_showMaterialsAction, &QAction::triggered, [=]() {
- materialDocker->show();
- materialDocker->raise();
- });
- m_windowMenu->addAction(m_showMaterialsAction);
-
QMenu* dialogsMenu = m_windowMenu->addMenu(tr("Dialogs"));
connect(dialogsMenu, &QMenu::aboutToShow, [=]() {
dialogsMenu->clear();
@@ -667,15 +644,6 @@ DocumentWindow::DocumentWindow()
connect(m_document, &Document::zlockStateChanged, this, &DocumentWindow::updateZlockButtonState);
connect(m_document, &Document::radiusLockStateChanged, this, &DocumentWindow::updateRadiusLockButtonState);
- connect(m_document, &Document::materialAdded, this, [=](dust3d::Uuid materialId) {
- Q_UNUSED(materialId);
- m_document->generateMaterialPreviews();
- });
- connect(m_document, &Document::materialLayersChanged, this, [=](dust3d::Uuid materialId) {
- Q_UNUSED(materialId);
- m_document->generateMaterialPreviews();
- });
-
initializeShortcuts();
connect(this, &DocumentWindow::initialized, m_document, &Document::uiReady);
@@ -1088,7 +1056,7 @@ void DocumentWindow::exportGlbToFilename(const QString& filename)
}
QApplication::setOverrideCursor(Qt::WaitCursor);
dust3d::Object skeletonResult = m_document->currentPostProcessedObject();
- QImage* textureMetalnessRoughnessAmbientOcclusionImage = TextureGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage,
+ QImage* textureMetalnessRoughnessAmbientOcclusionImage = UvMapGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage,
m_document->textureRoughnessImage,
m_document->textureAmbientOcclusionImage);
GlbFileWriter glbFileWriter(skeletonResult, filename,
diff --git a/application/sources/document_window.h b/application/sources/document_window.h
index f9140b96..dcbdc273 100644
--- a/application/sources/document_window.h
+++ b/application/sources/document_window.h
@@ -144,7 +144,6 @@ private:
QMenu* m_windowMenu = nullptr;
QAction* m_showPartsListAction = nullptr;
QAction* m_showDebugDialogAction = nullptr;
- QAction* m_showMaterialsAction = nullptr;
QMenu* m_helpMenu = nullptr;
QAction* m_gotoHomepageAction = nullptr;
diff --git a/application/sources/material.cc b/application/sources/material.cc
deleted file mode 100644
index c5c1026c..00000000
--- a/application/sources/material.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "material.h"
-#include "image_forever.h"
-
-void initializeMaterialTexturesFromSnapshot(const dust3d::Snapshot& snapshot,
- const dust3d::Uuid& materialId,
- MaterialTextures& materialTextures,
- float& tileScale)
-{
- auto materialIdString = materialId.toString();
- for (const auto& materialItem : snapshot.materials) {
- if (materialIdString != dust3d::String::valueOrEmpty(materialItem.first, "id"))
- continue;
- for (const auto& layer : materialItem.second) {
- //FIXME: Only support one layer currently
- auto findTileScale = layer.first.find("tileScale");
- if (findTileScale != layer.first.end())
- tileScale = dust3d::String::toFloat(findTileScale->second);
- for (const auto& mapItem : layer.second) {
- auto textureType = dust3d::TextureTypeFromString(dust3d::String::valueOrEmpty(mapItem, "for").c_str());
- if (textureType != dust3d::TextureType::None) {
- int index = (int)textureType - 1;
- if (index >= 0 && index < (int)dust3d::TextureType::Count - 1) {
- if ("imageId" == dust3d::String::valueOrEmpty(mapItem, "linkDataType")) {
- auto imageIdString = dust3d::String::valueOrEmpty(mapItem, "linkData");
- materialTextures.textureImages[index] = ImageForever::get(dust3d::Uuid(imageIdString));
- }
- }
- }
- }
- break;
- }
- break;
- }
-}
diff --git a/application/sources/material.h b/application/sources/material.h
deleted file mode 100644
index b69357b5..00000000
--- a/application/sources/material.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef DUST3D_APPLICATION_MATERIAL_H_
-#define DUST3D_APPLICATION_MATERIAL_H_
-
-#include
-#include
-#include
-#include
-
-struct MaterialTextures {
- const QImage* textureImages[(int)dust3d::TextureType::Count - 1] = { nullptr };
-};
-
-void initializeMaterialTexturesFromSnapshot(const dust3d::Snapshot& snapshot,
- const dust3d::Uuid& materialId,
- MaterialTextures& materialTextures,
- float& tileScale);
-
-#endif
diff --git a/application/sources/material_edit_widget.cc b/application/sources/material_edit_widget.cc
deleted file mode 100644
index bcb7df51..00000000
--- a/application/sources/material_edit_widget.cc
+++ /dev/null
@@ -1,335 +0,0 @@
-#include "material_edit_widget.h"
-#include "document.h"
-#include "float_number_widget.h"
-#include "horizontal_line_widget.h"
-#include "image_forever.h"
-#include "theme.h"
-#include "version.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-ImagePreviewWidget* MaterialEditWidget::createMapButton()
-{
- ImagePreviewWidget* mapButton = new ImagePreviewWidget;
- mapButton->setFixedSize(Theme::partPreviewImageSize * 2, Theme::partPreviewImageSize * 2);
- updateMapButtonBackground(mapButton, nullptr);
- return mapButton;
-}
-
-QImage* MaterialEditWidget::pickImage()
-{
- QString fileName = QFileDialog::getOpenFileName(this, QString(), QString(),
- tr("Image Files (*.png *.jpg *.bmp)"))
- .trimmed();
- if (fileName.isEmpty())
- return nullptr;
- QImage* image = new QImage();
- if (!image->load(fileName))
- return nullptr;
- return image;
-}
-
-MaterialEditWidget::MaterialEditWidget(const Document* document, QWidget* parent)
- : QDialog(parent)
- , m_document(document)
-{
- setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
-
- m_layers.resize(1);
-
- m_previewWidget = new ModelWidget(this);
- m_previewWidget->setMinimumSize(128, 128);
- m_previewWidget->resize(512, 512);
- m_previewWidget->move(-128, -128);
- m_previewWidget->setNotGraphics(true);
-
- QFont nameFont;
- nameFont.setWeight(QFont::Light);
- nameFont.setBold(false);
-
- QGridLayout* mapLayout = new QGridLayout;
- int row = 0;
- int col = 0;
- for (int i = 1; i < (int)dust3d::TextureType::Count; i++) {
- QVBoxLayout* textureManageLayout = new QVBoxLayout;
-
- MaterialMap item;
- item.forWhat = (dust3d::TextureType)i;
- m_layers[0].maps.push_back(item);
-
- ImagePreviewWidget* imageButton = createMapButton();
- connect(imageButton, &ImagePreviewWidget::clicked, [=]() {
- QImage* image = pickImage();
- if (nullptr == image)
- return;
- m_layers[0].maps[(int)i - 1].imageId = ImageForever::add(image);
- updateMapButtonBackground(imageButton, image);
- delete image;
- emit layersAdjusted();
- });
-
- QLabel* nameLabel = new QLabel(tr(dust3d::TextureTypeToDispName(item.forWhat).c_str()));
- nameLabel->setFont(nameFont);
-
- QPushButton* eraser = new QPushButton(QChar(fa::eraser));
- Theme::initAwesomeToolButton(eraser);
-
- connect(eraser, &QPushButton::clicked, [=]() {
- m_layers[0].maps[(int)i - 1].imageId = dust3d::Uuid();
- updateMapButtonBackground(imageButton, nullptr);
- emit layersAdjusted();
- });
-
- QHBoxLayout* textureTitleLayout = new QHBoxLayout;
- textureTitleLayout->addWidget(eraser);
- textureTitleLayout->addWidget(nameLabel);
- textureTitleLayout->addStretch();
-
- textureManageLayout->addWidget(imageButton);
- textureManageLayout->addLayout(textureTitleLayout);
- m_textureMapButtons[i - 1] = imageButton;
-
- mapLayout->addLayout(textureManageLayout, row, col++);
- if (col == 2) {
- col = 0;
- row++;
- }
- }
-
- QVBoxLayout* rightLayout = new QVBoxLayout;
- rightLayout->addStretch();
- rightLayout->addLayout(mapLayout);
- rightLayout->addStretch();
-
- QHBoxLayout* paramtersLayout = new QHBoxLayout;
- paramtersLayout->setContentsMargins(256, 0, 0, 0);
- paramtersLayout->addStretch();
- paramtersLayout->addLayout(rightLayout);
-
- m_nameEdit = new QLineEdit;
- connect(m_nameEdit, &QLineEdit::textChanged, this, [=]() {
- m_unsaved = true;
- updateTitle();
- });
- QPushButton* saveButton = new QPushButton(tr("Save"));
- connect(saveButton, &QPushButton::clicked, this, &MaterialEditWidget::save);
- saveButton->setDefault(true);
-
- FloatNumberWidget* tileScaleWidget = new FloatNumberWidget;
- tileScaleWidget->setItemName(tr("Tile Scale"));
- tileScaleWidget->setRange(0.01, 1.0);
- tileScaleWidget->setValue(m_layers[0].tileScale);
-
- m_tileScaleSlider = tileScaleWidget;
-
- connect(tileScaleWidget, &FloatNumberWidget::valueChanged, [=](float value) {
- m_layers[0].tileScale = value;
- emit layersAdjusted();
- });
-
- QPushButton* tileScaleEraser = new QPushButton(QChar(fa::eraser));
- Theme::initAwesomeToolButton(tileScaleEraser);
-
- connect(tileScaleEraser, &QPushButton::clicked, [=]() {
- tileScaleWidget->setValue(1.0);
- });
-
- QHBoxLayout* tileScaleLayout = new QHBoxLayout;
- tileScaleLayout->addWidget(tileScaleEraser);
- tileScaleLayout->addWidget(tileScaleWidget);
- tileScaleLayout->addStretch();
-
- QHBoxLayout* baseInfoLayout = new QHBoxLayout;
- baseInfoLayout->addWidget(new QLabel(tr("Name")));
- baseInfoLayout->addWidget(m_nameEdit);
- baseInfoLayout->addStretch();
- baseInfoLayout->addWidget(saveButton);
-
- QVBoxLayout* mainLayout = new QVBoxLayout;
- mainLayout->addLayout(paramtersLayout);
- mainLayout->addStretch();
- mainLayout->addWidget(new HorizontalLineWidget());
- mainLayout->addLayout(tileScaleLayout);
- mainLayout->addLayout(baseInfoLayout);
-
- setLayout(mainLayout);
-
- connect(this, &MaterialEditWidget::layersAdjusted, this, &MaterialEditWidget::updatePreview);
- connect(this, &MaterialEditWidget::layersAdjusted, [=]() {
- m_unsaved = true;
- updateTitle();
- });
- connect(this, &MaterialEditWidget::addMaterial, document, &Document::addMaterial);
- connect(this, &MaterialEditWidget::renameMaterial, document, &Document::renameMaterial);
- connect(this, &MaterialEditWidget::setMaterialLayers, document, &Document::setMaterialLayers);
-
- updatePreview();
- updateTitle();
-}
-
-void MaterialEditWidget::updateMapButtonBackground(ImagePreviewWidget* button, const QImage* image)
-{
- if (nullptr == image)
- button->updateImage(QImage());
- else
- button->updateImage(*image);
-}
-
-void MaterialEditWidget::reject()
-{
- close();
-}
-
-void MaterialEditWidget::closeEvent(QCloseEvent* event)
-{
- if (m_unsaved && !m_closed) {
- QMessageBox::StandardButton answer = QMessageBox::question(this,
- APP_NAME,
- tr("Do you really want to close while there are unsaved changes?"),
- QMessageBox::Yes | QMessageBox::No,
- QMessageBox::No);
- if (answer != QMessageBox::Yes) {
- event->ignore();
- return;
- }
- }
- m_closed = true;
- hide();
- if (nullptr != m_materialPreviewsGenerator) {
- event->ignore();
- return;
- }
- event->accept();
-}
-
-QSize MaterialEditWidget::sizeHint() const
-{
- return QSize(0, 200);
-}
-
-MaterialEditWidget::~MaterialEditWidget()
-{
- Q_ASSERT(nullptr == m_materialPreviewsGenerator);
-}
-
-void MaterialEditWidget::updatePreview()
-{
- if (m_closed)
- return;
-
- if (nullptr != m_materialPreviewsGenerator) {
- m_isPreviewDirty = true;
- return;
- }
-
- m_isPreviewDirty = false;
-
- qDebug() << "Material preview generating..";
-
- QThread* thread = new QThread;
- m_materialPreviewsGenerator = new MaterialPreviewsGenerator();
- m_materialPreviewsGenerator->addMaterial(dust3d::Uuid(), m_layers);
- m_materialPreviewsGenerator->moveToThread(thread);
- connect(thread, &QThread::started, m_materialPreviewsGenerator, &MaterialPreviewsGenerator::process);
- connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, this, &MaterialEditWidget::previewReady);
- connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, thread, &QThread::quit);
- connect(thread, &QThread::finished, thread, &QThread::deleteLater);
- thread->start();
-}
-
-void MaterialEditWidget::previewReady()
-{
- m_previewWidget->updateMesh(m_materialPreviewsGenerator->takePreview(dust3d::Uuid()));
-
- delete m_materialPreviewsGenerator;
- m_materialPreviewsGenerator = nullptr;
-
- qDebug() << "Material preview generation done";
-
- if (m_closed) {
- close();
- return;
- }
-
- if (m_isPreviewDirty)
- updatePreview();
-}
-
-void MaterialEditWidget::setEditMaterialId(dust3d::Uuid materialId)
-{
- if (m_materialId == materialId)
- return;
-
- m_materialId = materialId;
- updateTitle();
-}
-
-void MaterialEditWidget::updateTitle()
-{
- if (m_materialId.isNull()) {
- setWindowTitle(applicationTitle(tr("New") + (m_unsaved ? "*" : "")));
- return;
- }
- const Material* material = m_document->findMaterial(m_materialId);
- if (nullptr == material) {
- qDebug() << "Find material failed:" << m_materialId;
- return;
- }
- setWindowTitle(applicationTitle(material->name + (m_unsaved ? "*" : "")));
-}
-
-void MaterialEditWidget::setEditMaterialName(QString name)
-{
- m_nameEdit->setText(name);
- updateTitle();
-}
-
-void MaterialEditWidget::setEditMaterialLayers(std::vector layers)
-{
- for (int i = 1; i < (int)dust3d::TextureType::Count; i++) {
- m_layers[0].maps[i - 1].imageId = dust3d::Uuid();
- }
- if (!layers.empty()) {
- for (const auto& layer : layers) {
- m_layers[0].tileScale = layer.tileScale;
- for (const auto& mapItem : layer.maps) {
- int index = (int)mapItem.forWhat - 1;
- if (index >= 0 && index < (int)dust3d::TextureType::Count - 1) {
- m_layers[0].maps[index].imageId = mapItem.imageId;
- }
- }
- }
- m_tileScaleSlider->setValue(m_layers[0].tileScale);
- }
- for (int i = 1; i < (int)dust3d::TextureType::Count; i++) {
- updateMapButtonBackground(m_textureMapButtons[i - 1], ImageForever::get(m_layers[0].maps[i - 1].imageId));
- }
- updatePreview();
-}
-
-void MaterialEditWidget::clearUnsaveState()
-{
- m_unsaved = false;
- updateTitle();
-}
-
-void MaterialEditWidget::save()
-{
- if (m_materialId.isNull()) {
- m_materialId = dust3d::Uuid::createUuid();
- emit addMaterial(m_materialId, m_nameEdit->text(), m_layers);
- } else if (m_unsaved) {
- emit renameMaterial(m_materialId, m_nameEdit->text());
- emit setMaterialLayers(m_materialId, m_layers);
- }
- clearUnsaveState();
-}
diff --git a/application/sources/material_edit_widget.h b/application/sources/material_edit_widget.h
deleted file mode 100644
index 63359f8a..00000000
--- a/application/sources/material_edit_widget.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef DUST3D_APPLICATION_MATERIAL_EDIT_WIDGET_H_
-#define DUST3D_APPLICATION_MATERIAL_EDIT_WIDGET_H_
-
-#include "float_number_widget.h"
-#include "image_preview_widget.h"
-#include "material_layer.h"
-#include "material_previews_generator.h"
-#include "model_widget.h"
-#include
-#include
-#include
-#include