-
Notifications
You must be signed in to change notification settings - Fork 22
Runtime usage
James edited this page Aug 21, 2023
·
17 revisions
To use this library in your gradle project, add the version number and jitpack repository information to your root build.gradle
file:
allprojects {
ext {
...
mundusVersion = 'v0.5.0'
gltfVersion = '2.1.0' // Only needed if targeting HTML, version should match what Mundus uses
}
repositories {
...
maven { url 'https://jitpack.io' }
}
}
And add the dependency in your core project:
project(":core") {
...
dependencies {
...
api "com.github.jamestkhan.mundus:gdx-runtime:$mundusVersion"
}
}
If you are targeting HTML you will also need the following:
project(":html") {
...
dependencies {
...
api "com.github.jamestkhan.mundus:gdx-runtime:$mundusVersion:sources"
api "com.github.jamestkhan.mundus:commons:$mundusVersion:sources"
api "com.github.mgsx-dev.gdx-gltf:gltf:$gltfVersion:sources"
}
}
Copy your mundus project into your core/assets/mundus
directory.
public class LibGDXMundusExample extends ApplicationAdapter {
private Mundus mundus;
private Scene scene;
private FirstPersonCameraController controller;
@Override
public void create () {
mundus = new Mundus(Gdx.files.internal("mundus"));
scene = mundus.loadScene("Main Scene.mundus");
scene.cam.position.set(230, 150, 190);
scene.cam.direction.rotate(Vector3.Y, 70);
scene.cam.direction.rotate(Vector3.Z, -20);
controller = new FirstPersonCameraController(scene.cam);
controller.setVelocity(200f);
Gdx.input.setInputProcessor(controller);
}
@Override
public void render () {
ScreenUtils.clear(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
controller.update();
scene.sceneGraph.update();
scene.render();
}
@Override
public void dispose () {
mundus.dispose();
}
}
public class LibGDXMundusExample extends ApplicationAdapter {
private Mundus mundus;
@Override
public void create () {
mundus = new Mundus(Gdx.files.internal("mundus"));
mundus.getAssetManager().getGdxAssetManager().load("data/mymusic.ogg", Music.class);
mundus.getAssetManager().getGdxAssetManager().finishLoading();
Music music = mundus.getAssetManager().getGdxAssetManager().get("data/mymusic.ogg");
...
}
...
}
public class LibGDXMundusExample extends ApplicationAdapter {
private Mundus mundus;
private Scene scene;
private FirstPersonCameraController controller;
@Override
public void create () {
mundus = new Mundus(Gdx.files.internal("mundus"));
// Load external model via asset manager
mundus.getAssetManager().getGdxAssetManager().load("external_model.gltf", SceneAsset.class);
mundus.getAssetManager().getGdxAssetManager().finishLoading();
SceneAsset externalAsset = mundus.getAssetManager().getGdxAssetManager().get("external_model.gltf");
scene = mundus.loadScene("Main Scene.mundus");
scene.cam.position.set(230, 150, 190);
scene.cam.direction.rotate(Vector3.Y, 70);
scene.cam.direction.rotate(Vector3.Z, -20);
// Add external object into Mundus scene
scene.sceneGraph.addGameObject(new ModelInstance(externalAsset.scene.model), new Vector3(10, 2, 10));
controller = new FirstPersonCameraController(scene.cam);
controller.setVelocity(200f);
Gdx.input.setInputProcessor(controller);
}
...
}
scene.sceneGraph.update();
// We don't want to render these to the post-process FBO
scene.renderWaterFBOs();
scene.renderShadowMap();
// Capture Mundus scene in Framebuffer
fbo.begin();
ScreenUtils.clear(Color.CLEAR, true);
scene.renderScene(Gdx.graphics.getDeltaTime());
fbo.end();
spriteBatch.begin();
spriteBatch.draw(fbo.getColorBufferTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1, 1);
spriteBatch.end();