From 781a049ad7b1b6b67b9c03e3fd078b0a17047c19 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 10 May 2023 17:16:12 -0400 Subject: [PATCH 1/2] Gizmo fixes --- .../mbrlabs/mundus/editor/core/EditorScene.java | 12 ++++++++++++ .../editor/core/converter/GameObjectConverter.java | 3 --- .../mundus/editor/core/project/ProjectManager.java | 2 ++ .../mundus/editor/ui/gizmos/GizmoManager.kt | 14 +++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java b/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java index 467405342..71b4eb499 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java @@ -21,8 +21,11 @@ import com.badlogic.gdx.utils.viewport.Viewport; import com.mbrlabs.mundus.commons.Scene; import com.mbrlabs.mundus.commons.scene3d.GameObject; +import com.mbrlabs.mundus.commons.scene3d.components.Component; import com.mbrlabs.mundus.commons.scene3d.components.TerrainComponent; import com.mbrlabs.mundus.commons.utils.NestableFrameBuffer; +import com.mbrlabs.mundus.editor.Mundus; +import com.mbrlabs.mundus.editor.events.ComponentAddedEvent; /** * @author Marcus Brummer @@ -47,4 +50,13 @@ protected void initFrameBuffers(int width, int height) { fboWaterRefraction = new NestableFrameBuffer(Pixmap.Format.RGB888, width, height, true); fboDepthRefraction = new NestableFrameBuffer(Pixmap.Format.RGB888, width, height, true); } + + public void onLoaded() { + // Post component added events for all components in the scene now that it is loaded + for (GameObject gameObject : sceneGraph.getGameObjects()) { + for (Component component : gameObject.getComponents()) { + Mundus.INSTANCE.postEvent(new ComponentAddedEvent(component)); + } + } + } } diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/converter/GameObjectConverter.java b/editor/src/main/com/mbrlabs/mundus/editor/core/converter/GameObjectConverter.java index d872ed724..001939716 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/converter/GameObjectConverter.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/converter/GameObjectConverter.java @@ -24,8 +24,6 @@ import com.mbrlabs.mundus.commons.scene3d.SceneGraph; import com.mbrlabs.mundus.commons.scene3d.components.Component; import com.mbrlabs.mundus.commons.scene3d.components.LightComponent; -import com.mbrlabs.mundus.editor.Mundus; -import com.mbrlabs.mundus.editor.events.ComponentAddedEvent; import com.mbrlabs.mundus.editor.scene3d.components.PickableModelComponent; import com.mbrlabs.mundus.editor.scene3d.components.PickableTerrainComponent; import com.mbrlabs.mundus.editor.scene3d.components.PickableWaterComponent; @@ -74,7 +72,6 @@ public static GameObject convert(GameObjectDTO dto, SceneGraph sceneGraph, if (dto.getLightComponent() != null) { LightComponent component = PickableLightComponentConverter.convert(dto.getLightComponent(), go); go.getComponents().add(component); - Mundus.INSTANCE.postEvent(new ComponentAddedEvent(component)); } // recursively convert children diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java b/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java index 6316a4648..111375947 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java @@ -409,6 +409,7 @@ public void changeProject(ProjectContext context) { Gdx.graphics.setTitle(constructWindowTitle()); Mundus.INSTANCE.postEvent(new ProjectChangedEvent(context)); + currentProject.currScene.onLoaded(); } /** @@ -518,6 +519,7 @@ public void changeScene(ProjectContext projectContext, String sceneName) { Gdx.graphics.setTitle(constructWindowTitle()); Mundus.INSTANCE.postEvent(new SceneChangedEvent()); + projectContext.currScene.onLoaded(); } catch (FileNotFoundException e) { e.printStackTrace(); Log.error(TAG, e.getMessage()); diff --git a/editor/src/main/com/mbrlabs/mundus/editor/ui/gizmos/GizmoManager.kt b/editor/src/main/com/mbrlabs/mundus/editor/ui/gizmos/GizmoManager.kt index e2c40defd..f65938aef 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/ui/gizmos/GizmoManager.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/ui/gizmos/GizmoManager.kt @@ -9,6 +9,7 @@ import com.mbrlabs.mundus.commons.scene3d.components.LightComponent import com.mbrlabs.mundus.editor.Mundus import com.mbrlabs.mundus.editor.events.ComponentAddedEvent import com.mbrlabs.mundus.editor.events.ComponentRemovedEvent +import com.mbrlabs.mundus.editor.events.ProjectChangedEvent import com.mbrlabs.mundus.editor.events.SceneChangedEvent import com.mbrlabs.mundus.editor.events.SceneGraphChangedEvent @@ -21,7 +22,10 @@ import com.mbrlabs.mundus.editor.events.SceneGraphChangedEvent class GizmoManager : ComponentAddedEvent.ComponentAddedListener, ComponentRemovedEvent.ComponentRemovedListener, SceneGraphChangedEvent.SceneGraphChangedListener, - SceneChangedEvent.SceneChangedListener { + SceneChangedEvent.SceneChangedListener, + ProjectChangedEvent.ProjectChangedListener { + + private lateinit var camera: Camera private lateinit var decalBatch: DecalBatch @@ -85,6 +89,14 @@ class GizmoManager : ComponentAddedEvent.ComponentAddedListener, } override fun onSceneChanged(event: SceneChangedEvent) { + clearGizmos() + } + + override fun onProjectChanged(event: ProjectChangedEvent) { + clearGizmos() + } + + private fun clearGizmos() { for (gizmo in gizmos) { gizmo.dispose() } From 5b553ca6f64df1c18ef83fe4edd86950ab1f952d Mon Sep 17 00:00:00 2001 From: James Date: Wed, 10 May 2023 17:25:36 -0400 Subject: [PATCH 2/2] Update changes --- editor/CHANGES | 1 + .../src/main/com/mbrlabs/mundus/editor/core/EditorScene.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/editor/CHANGES b/editor/CHANGES index 46151e889..1bb397367 100644 --- a/editor/CHANGES +++ b/editor/CHANGES @@ -16,6 +16,7 @@ - Fix selection after model delete - Fix temporary files not deleted on model import - Fix reset import model dialog on close +- Fix Gizmos not adding and removing on Project/Scene changes - Change scene camera to be base camera class - Duplicate materials from inspector - Show brush selection diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java b/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java index 71b4eb499..baf185d5d 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java @@ -51,6 +51,9 @@ protected void initFrameBuffers(int width, int height) { fboDepthRefraction = new NestableFrameBuffer(Pixmap.Format.RGB888, width, height, true); } + /** + * Call this when the scene is loaded and is now the current active scene. + */ public void onLoaded() { // Post component added events for all components in the scene now that it is loaded for (GameObject gameObject : sceneGraph.getGameObjects()) {