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 467405342..baf185d5d 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,16 @@ 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); } + + /** + * 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()) { + 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 1c4b05f4d..669ad9b31 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 @@ -26,8 +26,6 @@ import com.mbrlabs.mundus.commons.scene3d.components.Component; import com.mbrlabs.mundus.commons.scene3d.components.CustomPropertiesComponent; 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; @@ -81,7 +79,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() }