加载搅拌机动画到libGDX

问题描述:

嗨搅拌机& libGDX大师,加载搅拌机动画到libGDX

我试图加载搅拌机动画到libGDX And​​roid应用程式。所以我使用Blenders动作编辑器创建了一个动画,我将它导出为.fbx格式。然后我运行fbx-conv工具创建一个.G3DB文件。然后我使用modelLoader将这个文件上传到libGDX中。

一切似乎工作正常(我没有收到任何错误信息),但屏幕为空我看不到任何动画或模型

我已经在运行kitkat的三星银河平板电脑上运行此代码,nexus手机运行棉花糖和模拟器,但结果相同。

我通过教程,并使用一些代码上传我的一个搅拌机模型。我仍然不知道这一点,我需要帮助搞清楚这一点。

任何帮助将不胜感激。

这里是链接到搅拌机中的文件: Animated Low-Poly Horse No Lights and no Camera

这里是我的代码中,我上传的libGDX模型。我基本上是使用教程中的代码。

@Override 
public void create() { 

    // Create camera sized to screens width/height with Field of View of 75 degrees 
    camera = new PerspectiveCamera(
      75, 
      Gdx.graphics.getWidth(), 
      Gdx.graphics.getHeight()); 

    // Move the camera 5 units back along the z-axis and look at the origin 
    camera.position.set(0f,0f,7f); 
    camera.lookAt(0f,0f,0f); 

    // Near and Far (plane) represent the minimum and maximum ranges of the camera in, um, units 
    camera.near = 0.1f; 
    camera.far = 300.0f; 
    camera.update(); 

    // A ModelBatch to batch up geometry for OpenGL 
    modelBatch = new ModelBatch(); 

    // Model loader needs a binary json reader to decode 
    UBJsonReader jsonReader = new UBJsonReader(); 
    // Create a model loader passing in our json reader 
    G3dModelLoader modelLoader = new G3dModelLoader(jsonReader); 
    // Now load the model by name 
    // Note, the model (g3db file) and textures need to be added to the assets folder of the Android proj 
    model = modelLoader.loadModel(Gdx.files.getFileHandle("AnimatedLowPolyHorseStageFenced_Ver5.g3db", Files.FileType.Internal)); 
    // Now create an instance. Instance holds the positioning data, etc of an instance of your model 
    modelInstance = new ModelInstance(model); 

    //fbx-conv is supposed to perform this rotation for you... it doesnt seem to 
    modelInstance.transform.rotate(1, 0, 0, -90); 
    //move the model down a bit on the screen (in a z-up world, down is -z). 
    modelInstance.transform.translate(0, 0, -2); 

    // Finally we want some light, or we wont see our color. The environment gets passed in during 
    // the rendering process. Create one, then create an Ambient (non-positioned, non-directional) light. 
    environment = new Environment(); 
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f)); 
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); 

    // You use an AnimationController to um, control animations. Each control is tied to the model instance 
    controller = new AnimationController(modelInstance); 
    // Pick the current animation by name 

    controller.setAnimation("Armature|ArmatureAction",1, new AnimationListener(){ 

     @Override 
     public void onEnd(AnimationDesc animation) { 
      // this will be called when the current animation is done. 
      // queue up another animation called "balloon". 
      // Passing a negative to loop count loops forever. 1f for speed is normal speed. 
      //controller.queue("Armature|ArmatureAction",-1,1f,null,0f); 
     } 

     @Override 
     public void onLoop(AnimationDesc animation) { 
      // TODO Auto-generated method stub 

     } 

    }); 

} 

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

@Override 
public void render() { 
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
    //Gdx.gl.glClearColor(1, 1, 1, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 

    // For some flavor, lets spin our camera around the Y axis by 1 degree each time render is called 

    // You need to call update on the animation controller so it will advance the animation. Pass in frame delta 
    controller.update(Gdx.graphics.getDeltaTime()); 
    // Like spriteBatch, just with models! pass in the box Instance and the environment 
    modelBatch.begin(camera); 
    modelBatch.render(modelInstance, environment); 
    modelBatch.end(); 
} 

当转换与fbxconv你有一个警告, “网格包含零骨骼权重顶点”来G3DB。

尝试以下步骤: - 迈上了一个新的骨添加到您的混合 - 它连接到非动画(或全部)顶点 - 再出口&转换

如果仍然收到警告,重复但将新骨骼连接到所有顶点。

我知道这是一个老问题,但我最近有类似的问题,这工作。