3D 모델 렌더링에 libgdx를 사용합니다. 모든 먼저 나는 자산에서 내 모델을로드 :LibGDX : 기존 3D 모델에 새 애니메이션 추가
assetManager.load(name, Model.class);
assetManager.finishLoading();
Model model = assets.get(name, Model.class)
내 모델에 하나 유휴 애니메이션이 함께 제공됩니다. 다음 번엔 애니메이션 컨트롤러를 만들고 애니메이션으로 모델 렌더링을 시작합니다.
ModelInstance modelInstance = new ModelInstance(model);
AnimationController controller = new AnimationController(modelInstance);
controller.setAnimation(modelInstance.animations.first().id, -1);
방법
controller.update(Gdx.graphics.getDeltaTime());
modelBatch.begin(cam);
modelBatch.render(model, environment);
modelBatch.end();
그것은 좋은, 애니메이션이 재생 작동을 렌더링합니다.
다음 애니메이션을로드하고 실행할 때 문제가 발생합니다.
assetManager.load(animation, Model.class);
assetManager.finishLoading();
Model animModel = assets.get(animation, Model.class)
modelInstance.model.animations.add(animModel.animations.first());
System.out.println("animation size "+modelInstance.model.animations.size); // prints 2
controller.setAnimation(modelInstance.model.animations.get(1).id, -1);
나서 에러는 애니메이션 ModelInstance 첨가하지 않은 것 같습니다
com.badlogic.gdx.utils.GdxRuntimeException: Unknown animation: acrobat
W/System.err: atcom.badlogic.gdx.graphics.g3d.utils.AnimationController.obtain(AnimationController.java:158)atcom.badlogic.gdx.graphics.g3d.utils.AnimationController.animate(AnimationController.java:349)
at com.badlogic.gdx.graphics.g3d.utils.AnimationController.animate(AnimationController.java:331)
at com.badlogic.gdx.graphics.g3d.utils.AnimationController.animate(AnimationController.java:303)
at com.snaappy.ar.game.MyGameRenderer$5.run(MyGameRenderer.java:768)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:488)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1562)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1262)
발생한다.
다음
내가 직접modelInstance.animations.add(animModel.animations.first());
대신
modelInstance.model.animations.add(animModel.animations.first());
오류가 더 이상 표시하지만 애니메이션이 재생되지 ModelInstance에 애니메이션을 추가했습니다.
모델에는 2 개의 애니메이션이 있지만 원래 있던 첫 번째 유휴 애니메이션 만 재생할 수 있습니다.
이 문제는 다시 생성 ModelInstance 및 AnimationController 의해 해결된다. 애니메이션을로드 한 후 매번 그 객체를 재생성해야합니다.
modelInstance.model.animations.add(animModel.animations.first());
ModelInstance modelInstance = new ModelInstance(modelInstance.model);
AnimationControllercontroller = new AnimationController(modelInstance);
나는 이것이 좋지 않다고 생각합니다. LibGDX의 버그처럼 보입니다.
이 문제에 대한 전문적인 의견을 듣고 싶습니다.
문제를 설명하는 작지만 완전한 작동 예제를 게시 할 수 있습니까? –
이미 자세히 쓰여져 있다고 생각합니다. –
게시 한 코드를 실행할 수 없습니다.저는 3d 애니메이션을 위해 libgdx를 사용했고 여러분이 가지고있는 것과 같은 문제를 겪지는 않았습니다 만, 여러분의 코드를 볼 수 없다면, 여러분이 잘못하고있는 것을 말하기가 꽤 어렵습니다. 코드를 보여 주면 디버깅하는 것이 더 쉬울 것입니다. 어쨌든 행운을 빌어 요 –