Giter Site home page Giter Site logo

Comments (5)

mgsx-dev avatar mgsx-dev commented on May 10, 2024 2

it looks like you didn't configure enough bones with your scene manager (default is 12 like libgdx classic). For instance, if you have up to 36 bones in your models, configure it like this :

new SceneManager(36);

Note that it has to be configured up front because scene manager don't know how many bones a scene would require.

from gdx-gltf.

mgsx-dev avatar mgsx-dev commented on May 10, 2024 1

note that you can get number of bones required by your scene : SceneAsset#maxBones

from gdx-gltf.

mgsx-dev avatar mgsx-dev commented on May 10, 2024 1

@waverider404 i think you make confusion between SceneAsset#maxBones and shader Config#numBones :

  • SceneAsset#maxBones give you how many bones you have in your model file
  • Config#numBones must be set to render these bones (default is 12)

Also, you may want to use PBRShaderProvider in order to enable other GLTF features (not mandatory but recommended), see example code. If you really want to use your own ModelBatch, you can create it like this : new ModelBatch(PBRShaderProvider.createDefault(maxBones))

If you have further questions, we can talk about it on discord ;-)

from gdx-gltf.

ademola-lou avatar ademola-lou commented on May 10, 2024

I guess i still have the same issue:
Model url: https://cdn.glitch.com/ca440387-5ef4-4401-a707-6a988d4e8bc5%2Fcynthia.glb?v=1585537867699
Here's my code:
`package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelCache;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.utils.AnimationController;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.physics.bullet.Bullet;
import com.badlogic.gdx.physics.bullet.collision.btCollisionObject;
import com.badlogic.gdx.utils.Array;

import net.mgsx.gltf.loaders.gltf.GLTFLoader;
import net.mgsx.gltf.loaders.glb.GLBLoader;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.scene.Scene;
import net.mgsx.gltf.scene3d.scene.SceneAsset;
import net.mgsx.gltf.scene3d.scene.SceneManager;
import net.mgsx.gltf.scene3d.scene.SceneSkybox;
import net.mgsx.gltf.scene3d.utils.EnvironmentUtil;

public class MyGdxGame extends ApplicationAdapter {
public Environment environment;
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;
public Array trees = new Array();
public ModelCache treeCache; //needed to reduce draw calls!
AnimationController controller;
ModelInstance player;
private SceneManager sceneManager;
private Scene scene;
private float time;
@OverRide
public void create() {

    Bullet.init();
    btCollisionObject groundObject = new btCollisionObject();

    CharSequence str = groundObject.toString();
    System.out.println(str);

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    modelBatch = new ModelBatch();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    SceneAsset model_asset = new GLBLoader().load(Gdx.files.internal("room.glb"));

    this.instance = new ModelInstance(model_asset.scene.model);
    this.instance.transform.scale(8.5f, 8.5f, 8.5f);


    SceneAsset player_asset = new GLBLoader().load(Gdx.files.internal("cynthia.glb"));
    player_asset.maxBones = 36;
    player = new ModelInstance(player_asset.scene.model);
    player.transform.scale(2.05f, 2.05f, 2.05f);

    controller = new AnimationController(player);
    controller.setAnimation("Armature|mixamo.com|Layer0", -1);

    this.trees.add(this.instance);
   // this.trees.add(player);

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
}

@Override
public void render() {


    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    controller.update(Gdx.graphics.getDeltaTime());


    modelBatch.begin(cam);
    modelBatch.render(player);
    modelBatch.render(trees, environment);
    modelBatch.end();

}

@Override
public void dispose() {
    modelBatch.dispose();
    trees.clear();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

}`

from gdx-gltf.

InnoLuke avatar InnoLuke commented on May 10, 2024

This helped me a lot. I wasn't using SceneManager at all (I only extract the model from SceneAsset), and am new to GDX, so was confused by the earlier advice. Instead, I needed to configure the numBones value on my ShaderProvider before passing it to my ModelBatch:

(Kotlin but hope it's readable for Java folks)

fun createShaderProvider(): ShaderProvider {
        val config = DefaultShader.Config()
        config.numBones = 50
        return DefaultShaderProvider(config)
}
// ...
val modelBatch = ModelBatch(createShaderProvider())

from gdx-gltf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.