Skip to content

Commit cf64abc

Browse files
committed
Add "Remove override" option to destroy prefab override value
+ fix material missing UID + detect "_baseColor" as an sRGB suffix
1 parent 071fa8e commit cf64abc

8 files changed

Lines changed: 94 additions & 14 deletions

File tree

src/core/GameObject/GameObject.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,14 @@ namespace vg::core
318318
}
319319

320320
//--------------------------------------------------------------------------------------
321-
bool GameObject::ToggleOverride(const IObject * _object, const IProperty * _prop, bool _override)
321+
bool GameObject::EnablePropertyOverride(const IObject * _object, const IProperty * _prop, bool _override)
322+
{
323+
VG_ASSERT_NOT_IMPLEMENTED();
324+
return false;
325+
}
326+
327+
//--------------------------------------------------------------------------------------
328+
bool GameObject::DestroyDynamicOverride(const IObject * _object, const IProperty * _prop)
322329
{
323330
VG_ASSERT_NOT_IMPLEMENTED();
324331
return false;

src/core/GameObject/GameObject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ namespace vg::core
4747
IDynamicProperty * GetDynamicProperty (const IObject * _object, const IProperty * _prop) const override;
4848
bool CanOverrideProperty (const IObject * _object, const IProperty * _prop) const override;
4949
IDynamicProperty * CreateDynamicProperty (const IObject * _object, const IProperty * _prop) override;
50+
bool DestroyDynamicOverride (const IObject * _object, const IProperty * _prop) override;
5051
void OverrideGameObjectProperties(IGameObject * _gameObject, const IDynamicProperty * _dynProp) override;
51-
bool ToggleOverride (const IObject * _object, const IProperty * _prop, bool _override) override;
52+
bool EnablePropertyOverride (const IObject * _object, const IProperty * _prop, bool _override) override;
5253

5354
using Context = GameObjectUpdateContext;
5455

src/core/IGameObject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ namespace vg::core
6565
virtual IDynamicProperty * GetDynamicProperty (const IObject * _object, const IProperty * _prop) const = 0;
6666
virtual bool CanOverrideProperty (const IObject * _object, const IProperty * _prop) const = 0;
6767
virtual IDynamicProperty * CreateDynamicProperty (const IObject * _object, const IProperty * _prop) = 0;
68+
virtual bool DestroyDynamicOverride (const IObject * _object, const IProperty * _prop) = 0;
6869
virtual void OverrideGameObjectProperties (IGameObject * _gameObject, const IDynamicProperty * _dynProp) = 0;
69-
virtual bool ToggleOverride (const IObject * _object, const IProperty * _prop, bool _override) = 0;
70+
virtual bool EnablePropertyOverride (const IObject * _object, const IProperty * _prop, bool _override) = 0;
7071

7172
virtual void OnCollisionEnter (IGameObject * _other) = 0;
7273
virtual void OnCollisionStay (IGameObject * _other) = 0;

src/editor/ImGui/Window/ImGuiWindow.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,14 +2187,31 @@ namespace vg::editor
21872187
bool overriden = propContext.m_isPrefabOverride;
21882188
bool notOverriden = !overriden;
21892189

2190-
ImGui::MenuItem("Prefab override", nullptr, false, false);
2190+
ImGui::MenuItem("Prefab", nullptr, false, false);
21912191
ImGui::Separator();
21922192

2193-
if (ImGui::MenuItem("Use original value", nullptr, &notOverriden))
2194-
propContext.m_prefab->ToggleOverride(propContext.m_originalObject, propContext.m_originalProp, false);
2193+
bool overrideExists = propContext.m_prefab->GetDynamicProperty(propContext.m_originalObject, propContext.m_originalProp);
21952194

2196-
if (ImGui::MenuItem("Use override value", nullptr, &overriden))
2197-
propContext.m_prefab->ToggleOverride(propContext.m_originalObject, propContext.m_originalProp, true);
2195+
if (overrideExists)
2196+
{
2197+
if (ImGui::MenuItem("Use original value", nullptr, &notOverriden))
2198+
propContext.m_prefab->EnablePropertyOverride(propContext.m_originalObject, propContext.m_originalProp, false);
2199+
2200+
if (ImGui::MenuItem("Use override value", nullptr, &overriden))
2201+
propContext.m_prefab->EnablePropertyOverride(propContext.m_originalObject, propContext.m_originalProp, true);
2202+
2203+
ImGui::Separator();
2204+
if (ImGui::MenuItem("Remove override"))
2205+
{
2206+
propContext.m_prefab->EnablePropertyOverride(propContext.m_originalObject, propContext.m_originalProp, false);
2207+
propContext.m_prefab->DestroyDynamicOverride(propContext.m_originalObject, propContext.m_originalProp);
2208+
}
2209+
}
2210+
else
2211+
{
2212+
if (ImGui::MenuItem("Create override value"))
2213+
propContext.m_prefab->EnablePropertyOverride(propContext.m_originalObject, propContext.m_originalProp, true);
2214+
}
21982215

21992216
ImGui::EndDisabled();
22002217

@@ -2304,8 +2321,21 @@ namespace vg::editor
23042321

23052322
if (_propContext.m_propOverride)
23062323
{
2307-
((DynamicPropertyResource *)_propContext.m_propOverride)->SetValue(relativePath);
2308-
_propContext.m_propOverride->Enable(true);
2324+
switch (_propContext.m_propOverride->GetProperty()->GetType())
2325+
{
2326+
default:
2327+
{
2328+
VG_ASSERT(false);
2329+
}
2330+
break;
2331+
2332+
case PropertyType::Resource:
2333+
{
2334+
((DynamicPropertyResource *)_propContext.m_propOverride)->SetValue(relativePath);
2335+
_propContext.m_propOverride->Enable(true);
2336+
}
2337+
break;
2338+
}
23092339
}
23102340
_resource->SetResourcePath(relativePath);
23112341
}

src/engine/GameObject/Prefab/PrefabGameObject.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ namespace vg::engine
8888
return createDynamicProperty(_object, _prop);
8989
}
9090

91+
//--------------------------------------------------------------------------------------
92+
bool PrefabGameObject::DestroyDynamicOverride(const IObject * _object, const IProperty * _prop)
93+
{
94+
return destroyDynamicProperty(_object, _prop);
95+
}
96+
9197
//--------------------------------------------------------------------------------------
9298
core::DynamicPropertyList * PrefabGameObject::getDynamicPropertyList(const core::IObject * _object) const
9399
{
@@ -344,6 +350,38 @@ namespace vg::engine
344350
}
345351
}
346352

353+
//--------------------------------------------------------------------------------------
354+
bool PrefabGameObject::destroyDynamicProperty(const core::IObject * _object, const core::IProperty * _prop)
355+
{
356+
if (auto * propList = getDynamicPropertyList(_object))
357+
{
358+
for (uint i = 0; i < propList->m_properties.size(); ++i)
359+
{
360+
auto & prop = propList->m_properties[i];
361+
if (prop->GetName() == _prop->GetName())
362+
{
363+
propList->m_properties.erase(propList->m_properties.begin() + i);
364+
365+
if (propList->m_properties.size() == 0)
366+
{
367+
for (uint i = 0; i < m_dynamicProperties.size(); ++i)
368+
{
369+
if (m_dynamicProperties[i] == propList)
370+
{
371+
m_dynamicProperties.erase(m_dynamicProperties.begin() + i);
372+
return true;
373+
}
374+
}
375+
}
376+
377+
return true;
378+
}
379+
}
380+
}
381+
382+
return false;
383+
}
384+
347385
//--------------------------------------------------------------------------------------
348386
core::DynamicProperty * PrefabGameObject::createDynamicProperty(const core::IObject * _object, const core::IProperty * _prop)
349387
{
@@ -756,7 +794,7 @@ namespace vg::engine
756794
// _override = true => Enable property override, Set to Override value
757795
// _override = false => Disable property override, Reset to original value
758796
//--------------------------------------------------------------------------------------
759-
bool PrefabGameObject::ToggleOverride(const IObject * _object, const IProperty * _prop, bool _override)
797+
bool PrefabGameObject::EnablePropertyOverride(const IObject * _object, const IProperty * _prop, bool _override)
760798
{
761799
if (_override)
762800
{

src/engine/GameObject/Prefab/PrefabGameObject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ namespace vg::engine
4545
core::IDynamicProperty * GetDynamicProperty (const core::IObject * _object, const core::IProperty * _prop) const override;
4646
bool CanOverrideProperty (const core::IObject * _object, const core::IProperty * _prop) const override;
4747
core::IDynamicProperty * CreateDynamicProperty (const core::IObject * _object, const core::IProperty * _prop) override;
48+
bool DestroyDynamicOverride (const core::IObject * _object, const core::IProperty * _prop) override;
4849
void OverrideGameObjectProperties(core::IGameObject * _gameObject, const core::IDynamicProperty * _dynProp) override;
49-
bool ToggleOverride (const core::IObject * _object, const core::IProperty * _prop, bool _override) override;
50+
bool EnablePropertyOverride (const core::IObject * _object, const core::IProperty * _prop, bool _override) override;
5051

5152
private:
5253
core::DynamicPropertyList * getDynamicPropertyList (const core::IObject * _object) const;
@@ -55,6 +56,7 @@ namespace vg::engine
5556
core::DynamicProperty * getDynamicProperty (const core::IObject * _object, const core::IProperty * _prop) const;
5657
bool canOverrideProperty (const core::IObject * _object, const core::IProperty * _prop) const;
5758
core::DynamicProperty * createDynamicProperty (const core::IObject * _object, const core::IProperty * _prop);
59+
bool destroyDynamicProperty (const core::IObject * _object, const core::IProperty * _prop);
5860

5961
void patchPrefabGameObjectUIDs (const core::IObject * _root, core::IObject * _object);
6062

src/engine/Resource/Material/MaterialResource.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace vg::engine
4040
//--------------------------------------------------------------------------------------
4141
MaterialResource::~MaterialResource()
4242
{
43-
43+
UnregisterUID();
4444
}
4545

4646
//--------------------------------------------------------------------------------------
@@ -71,6 +71,7 @@ namespace vg::engine
7171
{
7272
// Create the material, textures aren't loaded yet
7373
object->CreateRendererMaterial();
74+
object->RegisterUID();
7475
return object;
7576
}
7677
}

src/engine/Resource/Texture/TextureResourceMeta.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace vg::engine
2727
super(_name, _parent)
2828
{
2929
string lowerName = tolower(_name);
30-
if (string::npos != lowerName.find("_albedo") || string::npos != lowerName.find("_diffuse"))
30+
if (string::npos != lowerName.find("_albedo") || string::npos != lowerName.find("_diffuse") || string::npos != lowerName.find("_basecolor"))
3131
this->m_importSettings.m_sRGB = true;
3232
else
3333
this->m_importSettings.m_sRGB = false;

0 commit comments

Comments
 (0)