Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gizmo fix #173

Merged
merged 3 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions editor/src/main/com/mbrlabs/mundus/editor/core/EditorScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public void changeProject(ProjectContext context) {

Gdx.graphics.setTitle(constructWindowTitle());
Mundus.INSTANCE.postEvent(new ProjectChangedEvent(context));
currentProject.currScene.onLoaded();
}

/**
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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()
}
Expand Down