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

Move model batch from sceneGraph to scene #10

Merged
merged 1 commit into from
Apr 14, 2022
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
12 changes: 12 additions & 0 deletions commons/src/main/com/mbrlabs/mundus/commons/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.mbrlabs.mundus.commons.assets.TerrainAsset;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class Scene implements Disposable {
public GameObject currentSelection;

public PerspectiveCamera cam;
public ModelBatch batch;

public Scene() {
environment = new MundusEnvironment();
Expand All @@ -69,6 +71,16 @@ public Scene() {
sceneGraph = new SceneGraph(this);
}

public void render() {
render(Gdx.graphics.getDeltaTime());
}

public void render(float delta) {
batch.begin(cam);
sceneGraph.render(delta);
batch.end();
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.mbrlabs.mundus.commons.scene3d;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Array;
import com.mbrlabs.mundus.commons.Scene;

Expand All @@ -30,7 +29,6 @@ public class SceneGraph {
protected GameObject root;

public Scene scene;
public ModelBatch batch;

private GameObject selected;

Expand All @@ -41,16 +39,10 @@ public SceneGraph(Scene scene) {
this.scene = scene;
}

public void render() {
render(Gdx.graphics.getDeltaTime());
}

public void render(float delta) {
batch.begin(scene.cam);
for (GameObject go : root.getChildren()) {
go.render(delta);
}
batch.end();
}

public void update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ModelInstance getModelInstance() {
@Override
public void render(float delta) {
modelInstance.transform.set(gameObject.getTransform());
gameObject.sceneGraph.batch.render(modelInstance, gameObject.sceneGraph.scene.environment, shader);
gameObject.sceneGraph.scene.batch.render(modelInstance, gameObject.sceneGraph.scene.environment, shader);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setShader(Shader shader) {

@Override
public void render(float delta) {
gameObject.sceneGraph.batch.render(terrain.getTerrain(), gameObject.sceneGraph.scene.environment, shader);
gameObject.sceneGraph.scene.batch.render(terrain.getTerrain(), gameObject.sceneGraph.scene.environment, shader);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion editor/src/main/com/mbrlabs/mundus/editor/Editor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.mbrlabs.mundus.editor

import com.badlogic.gdx.ApplicationListener
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter
import com.badlogic.gdx.graphics.Color
Expand Down Expand Up @@ -121,7 +122,7 @@ class Editor : Lwjgl3WindowAdapter(), ApplicationListener,
}

sg.update()
sg.render()
sg.render(Gdx.graphics.deltaTime)

toolManager.render()
compass.render(batch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public ProjectContext createProject(String name, String folder) {
scene.environment.setFog(new Fog());
scene.setId(newProjectContext.obtainID());
SceneManager.saveScene(newProjectContext, scene);
scene.sceneGraph.batch = modelBatch;
scene.sceneGraph.scene.batch = modelBatch;

// save .pro file
newProjectContext.scenes.add(scene.getName());
Expand Down Expand Up @@ -334,9 +334,9 @@ public EditorScene loadScene(ProjectContext context, String sceneName) throws Fi

EditorScene scene = SceneConverter.convert(sceneDTO, context.assetManager.getAssetMap());
scene.skybox = SkyboxBuilder.createDefaultSkybox();
scene.batch = modelBatch;

SceneGraph sceneGraph = scene.sceneGraph;
sceneGraph.batch = modelBatch;
for (GameObject go : sceneGraph.getGameObjects()) {
initGameObject(context, go);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void encodeRaypickColorId() {

@Override
public void renderPick() {
gameObject.sceneGraph.batch.render(modelInstance, Shaders.INSTANCE.getPickerShader());
gameObject.sceneGraph.scene.batch.render(modelInstance, Shaders.INSTANCE.getPickerShader());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void encodeRaypickColorId() {

@Override
public void renderPick() {
gameObject.sceneGraph.batch.render(terrain.getTerrain(), Shaders.INSTANCE.getPickerShader());
gameObject.sceneGraph.scene.batch.render(terrain.getTerrain(), Shaders.INSTANCE.getPickerShader());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public GameObject pick(EditorScene scene, int screenX, int screenY) {
}

private void renderPickableScene(SceneGraph sceneGraph) {
sceneGraph.batch.begin(sceneGraph.scene.cam);
sceneGraph.scene.batch.begin(sceneGraph.scene.cam);
for (GameObject go : sceneGraph.getGameObjects()) {
renderPickableGameObject(go);
}
sceneGraph.batch.end();
sceneGraph.scene.batch.end();
}

private void renderPickableGameObject(GameObject go) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ToolHandlePicker() {

public ToolHandle pick(ToolHandle[] handles, EditorScene scene, int screenX, int screenY) {
begin(scene.viewport);
renderPickableScene(handles, scene.sceneGraph.batch, scene.cam);
renderPickableScene(handles, scene.batch, scene.cam);
end();
Pixmap pm = getFrameBufferPixmap(scene.viewport);

Expand Down