From 9957988fc6077e36015f0f8e24e353482787b239 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Thu, 23 Nov 2017 15:24:19 +0000 Subject: [PATCH] scene graph node updates, editor history system updates --- Editor/AnimationWindow.cpp | 3 + Editor/DecalWindow.cpp | 3 + Editor/Editor.cpp | 181 ++++++++++++++++++++++++----------- Editor/EmitterWindow.cpp | 3 + Editor/ForceFieldWindow.cpp | 3 + Editor/LightWindow.cpp | 3 + Editor/MaterialWindow.cpp | 3 + Editor/MeshWindow.cpp | 3 + Editor/ObjectWindow.cpp | 3 + Editor/config.ini | 4 +- WickedEngine/wiTransform.cpp | 19 ++++ WickedEngine/wiTransform.h | 21 +--- 12 files changed, 172 insertions(+), 77 deletions(-) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index d5eabae52..896a5bc8a 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -216,6 +216,9 @@ AnimationWindow::~AnimationWindow() void AnimationWindow::SetArmature(Armature* armature) { + if (this->armature == armature) + return; + this->armature = armature; if (armature != nullptr) diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index e5ba762c5..bc12ac3c2 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -56,6 +56,9 @@ DecalWindow::~DecalWindow() void DecalWindow::SetDecal(Decal* decal) { + if (this->decal == decal) + return; + this->decal = decal; if (decal != nullptr) { diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 028f79b6e..74049c01f 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -123,7 +123,6 @@ enum HistoryOperationType { HISTORYOP_TRANSLATOR, HISTORYOP_DELETE, - HISTORYOP_PASTE, HISTORYOP_SELECTION, HISTORYOP_NONE }; @@ -1057,6 +1056,16 @@ void EditorComponent::Update(float dt) for (auto& x : selected) { *archive << x->transform->GetID(); + *archive << x->position; + *archive << x->normal; + *archive << x->subsetIndex; + *archive << x->distance; + } + *archive << savedParents.size(); + for (auto& x : savedParents) + { + *archive << x.first->GetID(); + *archive << x.second->GetID(); } if (picked->transform != nullptr) @@ -1071,7 +1080,7 @@ void EditorComponent::Update(float dt) break; } } - if (it == selected.end() && picked->transform != nullptr) + if (it == selected.end()) { selected.push_back(picked); savedParents.insert(pair(picked->transform, picked->transform->parent)); @@ -1082,65 +1091,14 @@ void EditorComponent::Update(float dt) EndTranslate(); ClearSelected(); selected.push_back(picked); - if (picked->transform != nullptr) - { - savedParents.insert(pair(picked->transform, picked->transform->parent)); - } + savedParents.insert(pair(picked->transform, picked->transform->parent)); } - EndTranslate(); - - if (picked->object != nullptr) - { - meshWnd->SetMesh(picked->object->mesh); - if (picked->subsetIndex >= 0 && picked->subsetIndex < (int)picked->object->mesh->subsets.size()) - { - Material* material = picked->object->mesh->subsets[picked->subsetIndex].material; - - materialWnd->SetMaterial(material); - - material->SetUserStencilRef(EDITORSTENCILREF_HIGHLIGHT); - } - if (picked->object->isArmatureDeformed()) - { - savedParents.erase(picked->object); - picked->transform = picked->object->mesh->armature; - savedParents.insert(pair(picked->transform, picked->transform->parent)); - animWnd->SetArmature(picked->object->mesh->armature); - } - } - else - { - meshWnd->SetMesh(nullptr); - materialWnd->SetMaterial(nullptr); - animWnd->SetArmature(nullptr); - } - - if (picked->light != nullptr) - { - } - lightWnd->SetLight(picked->light); - if (picked->decal != nullptr) - { - } - decalWnd->SetDecal(picked->decal); - if (picked->envProbe != nullptr) - { - } - envProbeWnd->SetProbe(picked->envProbe); - forceFieldWnd->SetForceField(picked->forceField); - BeginTranslate(); } else { - meshWnd->SetMesh(nullptr); - materialWnd->SetMaterial(nullptr); - lightWnd->SetLight(nullptr); - decalWnd->SetDecal(nullptr); - envProbeWnd->SetProbe(nullptr); - EndTranslate(); ClearSelected(); } @@ -1150,7 +1108,73 @@ void EditorComponent::Update(float dt) for (auto& x : selected) { *archive << x->transform->GetID(); + *archive << x->position; + *archive << x->normal; + *archive << x->subsetIndex; + *archive << x->distance; } + *archive << savedParents.size(); + for (auto& x : savedParents) + { + *archive << x.first->GetID(); + *archive << x.second->GetID(); + } + } + + // Update window data bindings... + if (selected.empty()) + { + objectWnd->SetObject(nullptr); + emitterWnd->SetObject(nullptr); + meshWnd->SetMesh(nullptr); + materialWnd->SetMaterial(nullptr); + lightWnd->SetLight(nullptr); + decalWnd->SetDecal(nullptr); + envProbeWnd->SetProbe(nullptr); + animWnd->SetArmature(nullptr); + } + else + { + wiRenderer::Picked* picked = selected.back(); + + assert(picked->transform != nullptr); + + if (picked->object != nullptr) + { + meshWnd->SetMesh(picked->object->mesh); + if (picked->subsetIndex >= 0 && picked->subsetIndex < (int)picked->object->mesh->subsets.size()) + { + Material* material = picked->object->mesh->subsets[picked->subsetIndex].material; + + materialWnd->SetMaterial(material); + + material->SetUserStencilRef(EDITORSTENCILREF_HIGHLIGHT); + } + if (picked->object->isArmatureDeformed()) + { + animWnd->SetArmature(picked->object->mesh->armature); + } + } + else + { + meshWnd->SetMesh(nullptr); + materialWnd->SetMaterial(nullptr); + animWnd->SetArmature(nullptr); + } + + if (picked->light != nullptr) + { + } + lightWnd->SetLight(picked->light); + if (picked->decal != nullptr) + { + } + decalWnd->SetDecal(picked->decal); + if (picked->envProbe != nullptr) + { + } + envProbeWnd->SetProbe(picked->envProbe); + forceFieldWnd->SetForceField(picked->forceField); objectWnd->SetObject(picked->object); emitterWnd->SetObject(picked->object); @@ -1716,13 +1740,13 @@ void ConsumeHistoryOperation(bool undo) } } break; - case HISTORYOP_PASTE: - break; case HISTORYOP_SELECTION: { EndTranslate(); ClearSelected(); + // Read selections states from archive: + list selectedBEFORE; size_t selectionCountBEFORE; *archive >> selectionCountBEFORE; @@ -1733,10 +1757,27 @@ void ConsumeHistoryOperation(bool undo) wiRenderer::Picked* sel = new wiRenderer::Picked; sel->transform = wiRenderer::getTransformByID(id); - //assert(sel->transform != nullptr); + assert(sel->transform != nullptr); + *archive >> sel->position; + *archive >> sel->normal; + *archive >> sel->subsetIndex; + *archive >> sel->distance; selectedBEFORE.push_back(sel); } + std::map savedParentsBEFORE; + size_t savedParentsCountBEFORE; + *archive >> savedParentsCountBEFORE; + for (size_t i = 0; i < savedParentsCountBEFORE; ++i) + { + uint64_t id1, id2; + *archive >> id1; + *archive >> id2; + + Transform* t1 = wiRenderer::getTransformByID(id1); + Transform* t2 = wiRenderer::getTransformByID(id2); + savedParentsBEFORE.insert(pair(t1, t2)); + } list selectedAFTER; size_t selectionCountAFTER; @@ -1748,19 +1789,41 @@ void ConsumeHistoryOperation(bool undo) wiRenderer::Picked* sel = new wiRenderer::Picked; sel->transform = wiRenderer::getTransformByID(id); - //assert(sel->transform != nullptr); + assert(sel->transform != nullptr); + *archive >> sel->position; + *archive >> sel->normal; + *archive >> sel->subsetIndex; + *archive >> sel->distance; selectedAFTER.push_back(sel); } + std::map savedParentsAFTER; + size_t savedParentsCountAFTER; + *archive >> savedParentsCountAFTER; + for (size_t i = 0; i < savedParentsCountAFTER; ++i) + { + uint64_t id1, id2; + *archive >> id1; + *archive >> id2; + + Transform* t1 = wiRenderer::getTransformByID(id1); + Transform* t2 = wiRenderer::getTransformByID(id2); + savedParentsAFTER.insert(pair(t1, t2)); + } + + + // Restore proper selection state: list* selectedCURRENT = nullptr; if (undo) { selectedCURRENT = &selectedBEFORE; + savedParents = savedParentsBEFORE; } else { selectedCURRENT = &selectedAFTER; + savedParents = savedParentsAFTER; } selected.insert(selected.end(), selectedCURRENT->begin(), selectedCURRENT->end()); @@ -1774,9 +1837,11 @@ void ConsumeHistoryOperation(bool undo) x->forceField = dynamic_cast(x->transform); } + BeginTranslate(); } break; case HISTORYOP_NONE: + assert(0); break; default: break; diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index a0545bd57..876c3b90d 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -269,6 +269,9 @@ EmitterWindow::~EmitterWindow() void EmitterWindow::SetObject(Object* obj) { + if (this->object == obj) + return; + // first try to turn off any debug readbacks for emitters: if (GetEmitter() != nullptr) { diff --git a/Editor/ForceFieldWindow.cpp b/Editor/ForceFieldWindow.cpp index acbb64987..e4274f6b1 100644 --- a/Editor/ForceFieldWindow.cpp +++ b/Editor/ForceFieldWindow.cpp @@ -101,6 +101,9 @@ ForceFieldWindow::~ForceFieldWindow() void ForceFieldWindow::SetForceField(ForceField* force) { + if (this->force == force) + return; + this->force = force; if (force != nullptr) diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 40443dc3b..88e2c11e0 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -197,6 +197,9 @@ LightWindow::~LightWindow() void LightWindow::SetLight(Light* light) { + if (this->light == light) + return; + this->light = light; if (light != nullptr) { diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index ce3db4808..6a2f51feb 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -405,6 +405,9 @@ MaterialWindow::~MaterialWindow() void MaterialWindow::SetMaterial(Material* mat) { + if (this->material == mat) + return; + if (material != nullptr) { material->SetUserStencilRef(0); diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index cadf779b9..7b2d23943 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -108,6 +108,9 @@ MeshWindow::~MeshWindow() void MeshWindow::SetMesh(Mesh* mesh) { + if (this->mesh == mesh) + return; + this->mesh = mesh; if (mesh != nullptr) { diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 830a063be..c541f9e98 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -233,6 +233,9 @@ ObjectWindow::~ObjectWindow() void ObjectWindow::SetObject(Object* obj) { + if (this->object == obj) + return; + object = obj; if (object != nullptr) diff --git a/Editor/config.ini b/Editor/config.ini index fcbe7ab01..db7591a73 100644 --- a/Editor/config.ini +++ b/Editor/config.ini @@ -1,7 +1,7 @@ enabled 1 x 0 y 0 -w 3840 -h 2160 +w 1920 +h 1080 fullscreen 0 borderless 1 \ No newline at end of file diff --git a/WickedEngine/wiTransform.cpp b/WickedEngine/wiTransform.cpp index 61b091391..709652443 100644 --- a/WickedEngine/wiTransform.cpp +++ b/WickedEngine/wiTransform.cpp @@ -3,6 +3,25 @@ #include +uint64_t Node::__Unique_ID_Counter = 0; + +Node::Node() { + name = ""; + ID = __Unique_ID_Counter; + __Unique_ID_Counter++; +} + + +std::string Node::GetLayerID() +{ + auto x = name.find_last_of('_'); + if (x != std::string::npos) + { + return name.substr(x + 1); + } + return ""; +} + void Node::Serialize(wiArchive& archive) { if (archive.IsReadMode()) diff --git a/WickedEngine/wiTransform.h b/WickedEngine/wiTransform.h index c73d9a65d..2879f56c0 100644 --- a/WickedEngine/wiTransform.h +++ b/WickedEngine/wiTransform.h @@ -6,31 +6,18 @@ class wiArchive; -static uint64_t __Unique_ID_Counter = 0; - struct Node { private: + static uint64_t __Unique_ID_Counter; uint64_t ID; public: std::string name; - Node() { - name = ""; - ID = __Unique_ID_Counter; - __Unique_ID_Counter++; - } + Node(); - - std::string GetLayerID() - { - auto x = name.find_last_of('_'); - if (x != std::string::npos) - { - return name.substr(x + 1); - } - return ""; - } + + std::string GetLayerID(); uint64_t GetID() { return ID; } void SetID(uint64_t newID) { ID = newID; }