【问题标题】:Libgdx - play animation from objectLibgdx - 从对象播放动画
【发布时间】:2014-03-21 17:59:07
【问题描述】:

我正在 Libgdx 中开发桌面/Android 应用程序,我想导入我在 Blender 中完成的动画。我已经从 Blender 中导出了 .obj 文件并成功地将它导入到 libgdx 中,所以现在我启动了应用程序,我可以看到模型但它没有移动。我应该怎么做才能让它根据关键帧移动?先感谢您!这是我的代码:

public void create () {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.50f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

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

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

    assets = new AssetManager();
    assets.load("mod1.obj", Model.class);
    loading = true;
   }

private void doneLoading() {        
    Model mod1_model = assets.get("mod1.obj", Model.class);
    ModelInstance mod1_instance= new ModelInstance(mod1_model);
    mod1_instance.transform.setToTranslation(10f, 0, -10f);
    instances.add(mod1_instance);

    loading = false;
}

@Override
public void render () {
    if (loading && assets.update())
        doneLoading();
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}

【问题讨论】:

标签: object 3d libgdx blender


【解决方案1】:

使用3d包的AnimationController控制动画

private AnimationController animation;

在 create() 或 show() 方法中:

//Note you can get animation information by Animation Description
animationDescription = new AnimationController(modelInstance);
//when you export from blender to fbx the animation name is "new take" but here I used 'Walk'
animation.animate("Walk", 2, 1f, null, 0.2f);

在 render() 方法中:

//Note Gdx graphic delta
animation.update(delta);
//then render your instance

【讨论】:

  • "animation.animate("Walk", 2, 1f, null, 0.2f);"那会根据这些坐标移动模型吗?问题是我已经在 Blender 中创建了动画,所以我只想在 libgdx 中播放它。否则我已经将模型转换为 g3db,它现在显示在屏幕上,但它没有移动。 :?
  • animate() 是为您提供不移动整个角色的动作动画,例如移动可能被蒙皮的旋转或移动节点,对于移动角色您应该使用变换,例如 modelInstance.transform.translate()。
  • 另外不要忘记在 render() 中使用 delta 更新动画
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-09
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多