fix the child position incorrect while parenting node; add camera focus func; treat icons to the asset and using AssetsManager::GetAsset to load it

This commit is contained in:
2026-02-17 21:38:43 +08:00
parent 2bbe332532
commit 99bbf1eb5a
29 changed files with 414 additions and 254 deletions

View File

@ -177,6 +177,7 @@ namespace Prism
// OpenScene("assets/scenes/FPSDemo.scene");
NewScene();
m_CurrentScene = m_RuntimeScene;
AssetEditorPanel::RegisterDefaultEditors();
FileSystem::StartWatching();
@ -804,11 +805,12 @@ namespace Prism
bool snap = Input::IsKeyPressed(Key::LEFT_CONTROL);
TransformComponent& entityTransform = selection.Entity.Transform();
// glm::mat4 transform = entityTransform.GetTransform();
glm::mat4 transform = m_CurrentScene->GetTransformRelativeToParent(selection.Entity);
float snapValue = GetSnapValue();
float snapValues[3] = { snapValue, snapValue, snapValue };
if (m_SelectionMode == SelectionMode::Entity)
{
glm::mat4 transform = entityTransform.GetTransform();
ImGuizmo::Manipulate(glm::value_ptr(m_EditorCamera.GetViewMatrix()),
glm::value_ptr(m_EditorCamera.GetProjectionMatrix()),
(ImGuizmo::OPERATION)m_GizmoType,
@ -822,16 +824,27 @@ namespace Prism
glm::vec3 translation, rotation, scale;
Math::DecomposeTransform(transform, translation,rotation,scale);
entityTransform.Translation = translation;
if (Entity parent = m_CurrentScene->FindEntityByUUID(selection.Entity.GetParentUUID()))
{
glm::vec3 parentTranslation, parentRotation, parentScale;
Math::DecomposeTransform(m_CurrentScene->GetTransformRelativeToParent(parent), parentTranslation, parentRotation, parentScale);
glm::vec3 deltaRotation = rotation - entityTransform.Rotation;
entityTransform.Rotation += deltaRotation;
entityTransform.Scale = scale;
glm::vec3 deltaRotation = (rotation - parentRotation) - entityTransform.Rotation;
entityTransform.Translation = translation - parentTranslation;
entityTransform.Rotation += deltaRotation;
entityTransform.Scale = scale;
}
else
{
glm::vec3 deltaRotation = rotation - entityTransform.Rotation;
entityTransform.Translation = translation;
entityTransform.Rotation += deltaRotation;
entityTransform.Scale = scale;
}
}
}else
{
glm::mat4 transformBase = entityTransform.GetTransform() * selection.Mesh->Transform;
glm::mat4 transformBase = transform * selection.Mesh->Transform;
ImGuizmo::Manipulate(glm::value_ptr(m_EditorCamera.GetViewMatrix()),
glm::value_ptr(m_EditorCamera.GetProjectionMatrix()),
(ImGuizmo::OPERATION)m_GizmoType,
@ -918,6 +931,15 @@ namespace Prism
case KeyCode::R:
m_GizmoType = ImGuizmo::OPERATION::SCALE;
break;
case KeyCode::F:
{
if (m_SelectionContext.size() == 0)
break;
Entity selectedEntity = m_SelectionContext[0].Entity;
m_EditorCamera.Focus(selectedEntity.Transform().Translation);
break;
}
}
}
@ -1068,6 +1090,7 @@ namespace Prism
m_SelectionContext.push_back(selection);
m_EditorScene->SetSelectedEntity(entity);
m_CurrentScene = m_EditorScene;
}
void EditorLayer::UpdateWindowTitle(const std::string &sceneName)
@ -1108,9 +1131,9 @@ namespace Prism
m_EditorScene->SetSelectedEntity(selectionContext.Entity);
}
void EditorLayer::OnEntityDeleted(Entity e)
void EditorLayer::OnEntityDeleted(const Entity e)
{
if (m_SelectionContext[0].Entity == e)
if (m_SelectionContext.size() > 0 && m_SelectionContext[0].Entity == e)
{
m_SelectionContext.clear();
m_EditorScene->SetSelectedEntity({});
@ -1164,6 +1187,7 @@ namespace Prism
m_EditorScene->SetSelectedEntity({});
m_SelectionContext.clear();
m_CurrentScene = m_EditorScene;
}
void EditorLayer::SaveScene()
@ -1213,6 +1237,7 @@ namespace Prism
m_RuntimeScene->OnRuntimeStart();
m_SceneHierarchyPanel->SetContext(m_RuntimeScene);
m_CurrentScene = m_RuntimeScene;
}
void EditorLayer::OnSceneStop()
@ -1226,6 +1251,7 @@ namespace Prism
m_SelectionContext.clear();
ScriptEngine::SetSceneContext(m_EditorScene);
m_SceneHierarchyPanel->SetContext(m_EditorScene);
m_CurrentScene = m_EditorScene;
}
float EditorLayer::GetSnapValue() const

View File

@ -61,7 +61,7 @@ namespace Prism
Scope<AssetsManagerPanel> m_AssetManagerPanel;
Scope<ObjectsPanel> m_ObjectsPanel;
Ref<Scene> m_ActiveScene;
Ref<Scene> m_CurrentScene;
Ref<Scene> m_RuntimeScene, m_EditorScene;
std::string m_SceneFilePath;

View File

@ -48,7 +48,7 @@ void main()
vec3 mappedColor = (mappedLuminance / luminance) * color* u_Exposure;
// Gamma correction.
o_Color = vec4(color, 1.0);
o_Color = vec4(mappedColor, 1.0);
#else
const float gamma = 2.2;
vec3 hdrColor = texture(u_SceneTexture, v_TexCoord).rgb;