【问题标题】:LibGDX - Unknown animation errorLibGDX - 未知动画错误
【发布时间】:2014-03-26 11:00:25
【问题描述】:

我正在 libgdx 上开发一个应用程序,我正在尝试播放我在 Blender 上创建的动画,但我继续收到未知动画错误。我的 create 方法中有这段代码:

model = modelLoader.loadModel(Gdx.files.getFileHandle("i1.g3db", FileType.Internal));
modelInstance = new ModelInstance(model);
modelInstance.transform.rotate(1, 0, 0, -90);
modelInstance.transform.translate(0, 0, -2);
controller = new AnimationController(modelInstance);  
controller.setAnimation("moveHand",1);

这在我的 render 方法中:

camera.update();
camController.update();
controller.update(Gdx.graphics.getDeltaTime());
modelBatch.begin(camera);
modelBatch.render(modelInstance, environment);
modelBatch.end();

我试图删掉与问题无关的部分。这是 Blender 中的摄影表图片,显示我已正确命名我的动画:

任何人都知道可能是什么问题,因为我已经卡在这个问题上很长一段时间了,谢谢!如果有人想打开它们,我会在此处上传动画文件(.g3db、.blender):

https://www.dropbox.com/s/xyx74tx5mbyj9i3/i1.zip

【问题讨论】:

    标签: java animation 3d libgdx blender


    【解决方案1】:

    一般注意事项:避免在动画名称中使用大写(和空格等)。另请查看https://github.com/libgdx/libgdx/wiki/3D-animations-and-skinning 了解有关动画的更多信息,以及查看https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX 了解有关在 LibGDX 中使用 Blender 模型的信息。

    使用-o G3DJ 命令行选项fbx-conv 将文件转换为.g3dj,例如fbx-conv -f -o G3DJ i1.fbx(其中-f 用于翻转纹理坐标)。确保更新您的代码以使用此 G3DJ 文件而不是以前的 G3DB 文件。接下来使用文本编辑器(例如记事本或 ide/eclipse 的文本编辑器)打开生成的 .g3dj 文件。该文件应该易于阅读(有关如何阅读的更多信息,请参阅 http://blog.xoppa.com/behind-the-3d-scenes-part1/)并包含一个名为 animations 的部分(json 键)。

    如果文件中没有动画,它应该在文件底部看起来像"animations": []。在这种情况下,请务必检查以在搅拌机中导出动画。另见:https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX

    如果文件中有动画,它们会包含在数组中(在"animations": [] 之间)。请注意,动画会占用大量空间,因此实际行 "animations": [ 可能位于文件中间的某个位置。在这种情况下,请确保动画的名称 (id) 与用于指定动画的字符串完全匹配。

    如果动画包含在文件中并且字符串匹配,则枚举模型/模型实例中的所有动画以确保它们被正确加载:

    for (Animation anim : modelInstance.animations)
        Gdx.app.log("Animation", anim.id);
    

    如果动画不包含在 ModelInstance 中,则在此 sn-p 中将 modelInstance 替换为 model 以确保它包含在模型中。如果它也不包含在模型中,请确保刷新/清理您的工作区。

    【讨论】:

    • 您好 Xoppa,非常感谢您的详细回复!我将模型转换为 g3dj,现在可以在文件底部看到动画。但是,当我尝试运行它时,出现“解析文件错误:com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:47) 处的 I_new.g3dj”错误;在此之前我应该​​使用与 g3db 相同的代码来导入文件吗?
    • 如果您不使用 AssetManager(我建议您使用),您必须为 G3DJ 文件指定 JsonReader(而不是为 G3DB 文件指定 UBJsonReader)。所以例如new G3dModelLoader(new JsonReader(), resolver)。请参阅blog.xoppa.com/loading-models-using-libgdx 了解如何使用 AssetManager 进行加载。
    • 我实现了 AssetManager,它现在显示模型,但是当我添加“controller.update(Gdx.graphics.getDeltaTime());”时行它返回一个空指针异常。我这里有代码:pastebin.com/E5tL5dJy 我错过了什么吗?
    • 检查控制器是否不为空,例如if (controller != null) controller.update(Gdx.graphics.getDeltaTime());
    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 2014-05-25
    • 2023-03-15
    • 2016-10-17
    • 2015-11-20
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多