嗨攪拌機& libGDX大師,加載攪拌機動畫到libGDX
我試圖加載攪拌機動畫到libGDX Android應用程式。所以我使用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();
}