Skip to content

Commit

Permalink
#123 Update IndirectLighting editor, update save history from Property
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 19, 2022
1 parent e0ea9e8 commit cf53f24
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 50 deletions.
3 changes: 2 additions & 1 deletion Projects/Editor/Source/CopyPaste/CCopyPaste.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace Skylicht
{
CComponentEditor::CComponentEditor() :
m_component(NULL),
m_gameObject(NULL)
m_gameObject(NULL),
m_changed(false)
{

}
Expand Down
6 changes: 6 additions & 0 deletions Projects/Editor/Source/Editor/Components/CComponentEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Skylicht
protected:
CComponentSystem* m_component;
CGameObject* m_gameObject;
bool m_changed;

public:
CComponentEditor();
Expand All @@ -57,6 +58,11 @@ namespace Skylicht

virtual void update() = 0;

bool isChanged()
{
return m_changed;
}

CComponentSystem* getComponent()
{
return m_component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Skylicht

void CTransformEditor::closeGUI()
{
m_changed = false;
m_component = NULL;
m_gameObject = NULL;
m_transform = NULL;
Expand All @@ -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<CTransformEuler*>(target);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -172,6 +176,7 @@ namespace Skylicht
pos.Z = value->get();
t->setPosition(pos);
g->setPosition(pos);
*changed = true;
}
}), true);

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -236,6 +243,7 @@ namespace Skylicht
rot.Z = value->get();
t->setRotation(rot);
g->setRotation(rot);
*changed = true;
}
}), true);

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -300,6 +310,7 @@ namespace Skylicht
scale.Z = value->get();
t->setScale(scale);
g->setScale(scale);
*changed = true;
}
}), true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ namespace Skylicht

CTransformEuler* m_transform;

bool m_skip;
bool m_skip;

public:
CTransformEditor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ namespace Skylicht
handle->setWorld(m_parentWorld);
handle->end();
changed = false;
m_selectID = "";
return;
}

Expand Down Expand Up @@ -226,6 +227,7 @@ namespace Skylicht
handle->setWorld(m_parentWorld);
handle->end();
m_cacheSelectedObjects.clear();
m_selectID = "";
return;
}

Expand Down
22 changes: 19 additions & 3 deletions Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,42 @@ namespace Skylicht

void CSpaceProperty::clearAllGroup()
{
bool changed = false;
std::vector<CGameObject*> objs;

for (SGroup* group : m_groups)
{
group->releaseObserver();
group->GroupUI->remove();
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ namespace Skylicht
}
else
{
selection->unSelect(obj);
propertyController->setProperty(NULL);
selection->unSelect(obj);
}
}
else if (node->isTagEntity())
Expand Down Expand Up @@ -990,7 +990,6 @@ namespace Skylicht
container = dynamic_cast<CContainerObject*>(gameObject->getParent());
CCopyPaste::getInstance()->paste(container);
}
m_spaceHierarchy->getController()->updateTreeNode(container);
}
}
else if (lastSelected->getType() == CSelectObject::Entity)
Expand All @@ -1011,7 +1010,6 @@ namespace Skylicht
container = dynamic_cast<CContainerObject*>(gameObject->getParent());
CCopyPaste::getInstance()->paste(container);
}
m_spaceHierarchy->getController()->updateTreeNode(container);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Skylicht
CATEGORY_COMPONENT(CIndirectLighting, "Indirect Lighting", "Indirect Lighting");

CIndirectLighting::CIndirectLighting() :
m_type(LightmapArray),
m_type(SH9),
m_autoSH(true)
{

Expand Down Expand Up @@ -112,6 +112,27 @@ namespace Skylicht

}

CObjectSerializable* CIndirectLighting::createSerializable()
{
CObjectSerializable* object = CComponentSystem::createSerializable();

CEnumProperty<EIndirectType>* enumType = new CEnumProperty<EIndirectType>(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<EIndirectType>("type", EIndirectType::SH9);
setIndirectLightingType(type);
}

void CIndirectLighting::setSH(core::vector3df* sh)
{
m_autoSH = false;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace Skylicht
{
LightmapArray,
VertexColor,
SH4,
SH9,
};

Expand All @@ -64,6 +63,10 @@ namespace Skylicht

virtual void updateComponent();

virtual CObjectSerializable* createSerializable();

virtual void loadSerializable(CObjectSerializable* object);

protected:

void addLightingData(CEntity* entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace Skylicht
{
LightmapArray,
VertexColor,
SH4,
SH9
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit cf53f24

Please sign in to comment.