diff --git a/Projects/Editor/Source/CopyPaste/CCopyPaste.cpp b/Projects/Editor/Source/CopyPaste/CCopyPaste.cpp index 84e4f09fa..f1d7eb3ab 100644 --- a/Projects/Editor/Source/CopyPaste/CCopyPaste.cpp +++ b/Projects/Editor/Source/CopyPaste/CCopyPaste.cpp @@ -103,7 +103,8 @@ namespace Skylicht // update on GUI editor if (hierarchyController != NULL && gameObject != NULL && parentNode != NULL) { - hierarchyController->addToTreeNode(sceneController->buildHierarchyData(gameObject, parentNode)); + GUI::CTreeNode* node = hierarchyController->addToTreeNode(sceneController->buildHierarchyData(gameObject, parentNode)); + node->collapse(false); } } } diff --git a/Projects/Editor/Source/Editor/Components/CComponentEditor.cpp b/Projects/Editor/Source/Editor/Components/CComponentEditor.cpp index c1de8ba12..0fc965920 100644 --- a/Projects/Editor/Source/Editor/Components/CComponentEditor.cpp +++ b/Projects/Editor/Source/Editor/Components/CComponentEditor.cpp @@ -31,7 +31,8 @@ namespace Skylicht { CComponentEditor::CComponentEditor() : m_component(NULL), - m_gameObject(NULL) + m_gameObject(NULL), + m_changed(false) { } diff --git a/Projects/Editor/Source/Editor/Components/CComponentEditor.h b/Projects/Editor/Source/Editor/Components/CComponentEditor.h index 1ddadad94..6a3d553d1 100644 --- a/Projects/Editor/Source/Editor/Components/CComponentEditor.h +++ b/Projects/Editor/Source/Editor/Components/CComponentEditor.h @@ -37,6 +37,7 @@ namespace Skylicht protected: CComponentSystem* m_component; CGameObject* m_gameObject; + bool m_changed; public: CComponentEditor(); @@ -57,6 +58,11 @@ namespace Skylicht virtual void update() = 0; + bool isChanged() + { + return m_changed; + } + CComponentSystem* getComponent() { return m_component; diff --git a/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.cpp b/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.cpp index 41e207a10..56841f9ca 100644 --- a/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.cpp +++ b/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.cpp @@ -57,6 +57,7 @@ namespace Skylicht void CTransformEditor::closeGUI() { + m_changed = false; m_component = NULL; m_gameObject = NULL; m_transform = NULL; @@ -81,6 +82,7 @@ namespace Skylicht void CTransformEditor::initGUI(CComponentSystem* target, CSpaceProperty* ui) { + m_changed = false; m_component = target; m_gameObject = target->getGameObject(); m_transform = dynamic_cast(target); @@ -139,7 +141,7 @@ namespace Skylicht ui->addNumberInput(layout, L"Y", &Y, 0.01f); ui->addNumberInput(layout, L"Z", &Z, 0.01f); - X.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + X.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -148,10 +150,11 @@ namespace Skylicht pos.X = value->get(); t->setPosition(pos); g->setPosition(pos); + *changed = true; } }), true); - Y.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + Y.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -160,10 +163,11 @@ namespace Skylicht pos.Y = value->get(); t->setPosition(pos); g->setPosition(pos); + *changed = true; } }), true); - Z.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + Z.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -172,6 +176,7 @@ namespace Skylicht pos.Z = value->get(); t->setPosition(pos); g->setPosition(pos); + *changed = true; } }), true); @@ -203,7 +208,7 @@ namespace Skylicht t->setRotation(rot * core::RADTODEG); }), true); - RotateX.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + RotateX.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -212,10 +217,11 @@ namespace Skylicht rot.X = value->get(); t->setRotation(rot); g->setRotation(rot); + *changed = true; } }), true); - RotateY.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + RotateY.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -224,10 +230,11 @@ namespace Skylicht rot.Y = value->get(); t->setRotation(rot); g->setRotation(rot); + *changed = true; } }), true); - RotateZ.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + RotateZ.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -236,6 +243,7 @@ namespace Skylicht rot.Z = value->get(); t->setRotation(rot); g->setRotation(rot); + *changed = true; } }), true); @@ -267,7 +275,7 @@ namespace Skylicht t->setScale(scale); }), true); - ScaleX.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + ScaleX.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -276,10 +284,11 @@ namespace Skylicht scale.X = value->get(); t->setScale(scale); g->setScale(scale); + *changed = true; } }), true); - ScaleY.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + ScaleY.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -288,10 +297,11 @@ namespace Skylicht scale.Y = value->get(); t->setScale(scale); g->setScale(scale); + *changed = true; } }), true); - ScaleZ.addObserver(new CObserver([t = m_transform, g = m_gizmos](ISubject* subject, IObserver* from) + ScaleZ.addObserver(new CObserver([t = m_transform, g = m_gizmos, changed = &m_changed](ISubject* subject, IObserver* from) { if (from != g) { @@ -300,6 +310,7 @@ namespace Skylicht scale.Z = value->get(); t->setScale(scale); g->setScale(scale); + *changed = true; } }), true); diff --git a/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.h b/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.h index 9bbe7be5e..be7624c19 100644 --- a/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.h +++ b/Projects/Editor/Source/Editor/Components/Transform/CTransformEditor.h @@ -52,7 +52,8 @@ namespace Skylicht CTransformEuler* m_transform; - bool m_skip; + bool m_skip; + public: CTransformEditor(); diff --git a/Projects/Editor/Source/Editor/Gizmos/Transform/CTransformGizmos.cpp b/Projects/Editor/Source/Editor/Gizmos/Transform/CTransformGizmos.cpp index be265f278..5c422a1f0 100644 --- a/Projects/Editor/Source/Editor/Gizmos/Transform/CTransformGizmos.cpp +++ b/Projects/Editor/Source/Editor/Gizmos/Transform/CTransformGizmos.cpp @@ -184,6 +184,7 @@ namespace Skylicht handle->setWorld(m_parentWorld); handle->end(); changed = false; + m_selectID = ""; return; } @@ -226,6 +227,7 @@ namespace Skylicht handle->setWorld(m_parentWorld); handle->end(); m_cacheSelectedObjects.clear(); + m_selectID = ""; return; } diff --git a/Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp b/Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp index 7b0182a61..06223d8bb 100644 --- a/Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp +++ b/Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp @@ -146,6 +146,9 @@ namespace Skylicht void CSpaceProperty::clearAllGroup() { + bool changed = false; + std::vector objs; + for (SGroup* group : m_groups) { group->releaseObserver(); @@ -153,19 +156,32 @@ namespace Skylicht if (group->AssetOwner) group->AssetOwner->closeGUI(); if (group->Owner) + { + if (group->Owner->isChanged()) + { + // need save history + CGameObject* obj = group->Owner->getGameObject(); + if (std::find(objs.begin(), objs.end(), obj) == objs.end()) + objs.push_back(obj); + changed = true; + } + group->Owner->closeGUI(); + } if (group->EntityDataOwner) group->EntityDataOwner->closeGUI(); delete group; } - m_groups.clear(); + // save modify history + if (changed && objs.size() > 0) + CSceneController::getInstance()->getHistory()->saveModifyHistory(objs); + // delete editor components for (CComponentEditor* editor : m_releaseComponents) - { delete editor; - } m_releaseComponents.clear(); + m_groups.clear(); } void CSpaceProperty::update() diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp index 8d4795a37..b4615d916 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp @@ -788,8 +788,8 @@ namespace Skylicht } else { - selection->unSelect(obj); propertyController->setProperty(NULL); + selection->unSelect(obj); } } else if (node->isTagEntity()) @@ -990,7 +990,6 @@ namespace Skylicht container = dynamic_cast(gameObject->getParent()); CCopyPaste::getInstance()->paste(container); } - m_spaceHierarchy->getController()->updateTreeNode(container); } } else if (lastSelected->getType() == CSelectObject::Entity) @@ -1011,7 +1010,6 @@ namespace Skylicht container = dynamic_cast(gameObject->getParent()); CCopyPaste::getInstance()->paste(container); } - m_spaceHierarchy->getController()->updateTreeNode(container); } } } diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.cpp b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.cpp index 176bcdade..7d8bb8200 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.cpp +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.cpp @@ -37,7 +37,7 @@ namespace Skylicht CATEGORY_COMPONENT(CIndirectLighting, "Indirect Lighting", "Indirect Lighting"); CIndirectLighting::CIndirectLighting() : - m_type(LightmapArray), + m_type(SH9), m_autoSH(true) { @@ -112,6 +112,27 @@ namespace Skylicht } + CObjectSerializable* CIndirectLighting::createSerializable() + { + CObjectSerializable* object = CComponentSystem::createSerializable(); + + CEnumProperty* enumType = new CEnumProperty(object, "type", m_type); + enumType->addEnumString("Lightmap", EIndirectType::LightmapArray); + enumType->addEnumString("Vertex Color", EIndirectType::VertexColor); + enumType->addEnumString("SH9", EIndirectType::SH9); + object->addAutoRelease(enumType); + + return object; + } + + void CIndirectLighting::loadSerializable(CObjectSerializable* object) + { + CComponentSystem::loadSerializable(object); + + EIndirectType type = object->get("type", EIndirectType::SH9); + setIndirectLightingType(type); + } + void CIndirectLighting::setSH(core::vector3df* sh) { m_autoSH = false; @@ -146,11 +167,6 @@ namespace Skylicht data->Type = CIndirectLightingData::LightmapArray; data->LightmapTexture = m_lightmap; } - else if (m_type == SH4) - { - data->Type = CIndirectLightingData::SH4; - data->SH = m_sh; - } else if (m_type == SH9) { data->Type = CIndirectLightingData::SH9; diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.h b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.h index 54f6f59a6..b7485e36f 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.h +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLighting.h @@ -38,7 +38,6 @@ namespace Skylicht { LightmapArray, VertexColor, - SH4, SH9, }; @@ -64,6 +63,10 @@ namespace Skylicht virtual void updateComponent(); + virtual CObjectSerializable* createSerializable(); + + virtual void loadSerializable(CObjectSerializable* object); + protected: void addLightingData(CEntity* entity); diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h index 344b2e186..85e811d40 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingData.h @@ -35,7 +35,6 @@ namespace Skylicht { LightmapArray, VertexColor, - SH4, SH9 }; diff --git a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp index 25f1c7873..c0eadfec1 100644 --- a/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp +++ b/Projects/Skylicht/Engine/Source/IndirectLighting/CIndirectLightingSystem.cpp @@ -51,7 +51,8 @@ namespace Skylicht { CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex); if (lightData != NULL && - *lightData->AutoSH && (lightData->Type == CIndirectLightingData::SH4 || lightData->Type == CIndirectLightingData::SH9)) + *lightData->AutoSH && + lightData->Type == CIndirectLightingData::SH9) { CWorldTransformData* transformData = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); if (transformData->NeedValidate || lightData->Init) diff --git a/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.cpp b/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.cpp index c0fc4163c..6b2704e97 100644 --- a/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.cpp +++ b/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.cpp @@ -37,7 +37,7 @@ namespace Skylicht { } - void CShaderSH::OnSetConstants(CShader *shader, SUniform *uniform, IMaterialRenderer* matRender, bool vertexShader) + void CShaderSH::OnSetConstants(CShader* shader, SUniform* uniform, IMaterialRenderer* matRender, bool vertexShader) { switch (uniform->Type) { @@ -54,7 +54,7 @@ namespace Skylicht } } - void CShaderSH::setSH9(core::vector3df *sh) + void CShaderSH::setSH9(core::vector3df* sh) { memset(s_sh9, 0, sizeof(float) * 9 * 4); @@ -66,17 +66,4 @@ namespace Skylicht s_sh9[i * 4 + 3] = 1.0f; } } - - void CShaderSH::setSH4(core::vector3df *sh) - { - memset(s_sh9, 0, sizeof(float) * 4 * 4); - - for (int i = 0; i < 4; i++) - { - s_sh9[i * 4] = sh[i].X; - s_sh9[i * 4 + 1] = sh[i].Y; - s_sh9[i * 4 + 2] = sh[i].Z; - s_sh9[i * 4 + 3] = 1.0f; - } - } } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.h b/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.h index ce25a391f..2c0d05b98 100644 --- a/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.h +++ b/Projects/Skylicht/Engine/Source/Material/Shader/ShaderCallback/CShaderSH.h @@ -38,11 +38,9 @@ namespace Skylicht virtual ~CShaderSH(); - virtual void OnSetConstants(CShader *shader, SUniform *uniform, IMaterialRenderer* matRender, bool vertexShader); + virtual void OnSetConstants(CShader* shader, SUniform* uniform, IMaterialRenderer* matRender, bool vertexShader); public: - static void setSH9(core::vector3df *sh); - - static void setSH4(core::vector3df *sh); + static void setSH9(core::vector3df* sh); }; } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp index 994c23474..206fc95cc 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CMeshRenderer.cpp @@ -114,8 +114,6 @@ namespace Skylicht { if (lightingData->Type == CIndirectLightingData::SH9) CShaderSH::setSH9(lightingData->SH); - else if (lightingData->Type == CIndirectLightingData::SH4) - CShaderSH::setSH4(lightingData->SH); } driver->setTransform(video::ETS_WORLD, transforms[i]->World); diff --git a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp index 3757999d1..a3fa2f8ff 100644 --- a/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp +++ b/Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMeshRenderer.cpp @@ -113,8 +113,6 @@ namespace Skylicht { if (lightingData->Type == CIndirectLightingData::SH9) CShaderSH::setSH9(lightingData->SH); - else if (lightingData->Type == CIndirectLightingData::SH4) - CShaderSH::setSH4(lightingData->SH); } CSkinnedMesh* mesh = (CSkinnedMesh*)renderMeshData->getMesh();