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

Add external model object #120

Merged
merged 2 commits into from
Oct 24, 2022

Conversation

Dgzt
Copy link
Collaborator

@Dgzt Dgzt commented Oct 23, 2022

A added two methods:

  • addGameObject(ModelInstance, Vector3)
  • addGameObject(Model, Vector3)

into SceneGraph.

There methods can add external model object into the scene graph.

Peek.2022-10-23.09-09.mp4

Test code:

        private Mundus mundus;
	private Scene scene;
	private FirstPersonCameraController controller;
	
	@Override
	public void create () {
		mundus = new Mundus(Gdx.files.internal("mundus"));
		mundus.getAssetManager().getGdxAssetManager().load("uploads_files_2305968.gltf", SceneAsset.class);
		mundus.getAssetManager().getGdxAssetManager().finishLoading();
		SceneAsset sceneAsset = mundus.getAssetManager().getGdxAssetManager().get("uploads_files_2305968.gltf");
		mundus.getAssetManager().maxNumBones = 30;

		scene = mundus.loadScene("Main Scene.mundus");

		scene.cam.position.set(10, 10, 10);
		scene.cam.direction.rotate(Vector3.Y, 70);
		scene.cam.direction.rotate(Vector3.Z, -20);

		scene.sceneGraph.addGameObject( new ModelInstance(sceneAsset.scene.model), new Vector3(10, 2, 10));

		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();

		if (Gdx.input.isKeyJustPressed(Input.Keys.F)) {
			SceneAsset sceneAsset = mundus.getAssetManager().getGdxAssetManager().get("uploads_files_2305968.gltf");
			scene.sceneGraph.addGameObject(sceneAsset.scene.model, new Vector3(MathUtils.random(100), 2, MathUtils.random(100)));
		}
	}

If the map has not any model, we should set manually the maxNumBones.

@Dgzt Dgzt requested a review from JamesTKhan October 23, 2022 07:17
@Dgzt
Copy link
Collaborator Author

Dgzt commented Oct 23, 2022

Currently these methods want Vector3, but later a Vector2 should be useful what add the model to the terrain.

Copy link
Owner

@JamesTKhan JamesTKhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it out, looks good,

@JamesTKhan JamesTKhan merged commit e9cd59b into JamesTKhan:master Oct 24, 2022
@Dgzt Dgzt deleted the add-external-model-object branch October 24, 2022 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants