Libgdx 导入blender 3D动画
创始人
2024-05-28 20:04:54
0

导入blender3D模型可以看上篇libgdx导入blender模型

本篇3D动画在上篇的基础上。

具体参考官网 3D 动画和蒙皮
blender动画参考 八个案例教程带你从0到1入门blender【已完结】

打开上次的blender的,选则物体属性
在这里插入图片描述
点击位置和旋转x,y,z后面的小点,确定初始x,y,z位置,和初始角度
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
更改数值,并点击锁后面的方块
在这里插入图片描述
点击播放,查看动画
在这里插入图片描述
导出fbx,与上篇导出模型一致。导出时需要选择自定义属性
在这里插入图片描述
在这里插入图片描述

转换为g3dj,这里看不明白的去看我上篇,不会blender的建模的去看视频教程
上篇libgdx导入blender模型
blender动画参考 八个案例教程带你从0到1入门blender【已完结】
在这里插入图片描述

项目中使用,将导出的cube.g3dj放入项目assets/data下

package top.wuliaodebaozi2.blockgame.blockgameinternal;import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
import com.badlogic.gdx.graphics.g3d.utils.AnimationController;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.utils.JsonReader;/*** Example program that imports "myModel.g3dj" from the assets folder and renders it onto the screen.*/
public class ImportG3DJ implements ApplicationListener {private Environment environment;private PerspectiveCamera camera;private CameraInputController cameraController;private ModelBatch modelBatch;private Model model;private ModelInstance instance;private AnimationController controller;@Overridepublic void create() {// Create an environment so we have some lightingenvironment = new Environment();environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));modelBatch = new ModelBatch();// Create a perspective camera with some sensible defaultscamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());camera.position.set(10f, 10f, 10f);camera.lookAt(0, 0, 0);camera.near = 1f;camera.far = 300f;camera.update();// Import and instantiate our model (called "myModel.g3dj")ModelBuilder modelBuilder = new ModelBuilder();model = new G3dModelLoader(new JsonReader()).loadModel(Gdx.files.internal("data/cube.g3dj"));instance = new ModelInstance(model);controller = new AnimationController(instance);controller.setAnimation("Cube|CubeAction",-1);cameraController = new CameraInputController(camera);Gdx.input.setInputProcessor(cameraController);}@Overridepublic void render() {cameraController.update();controller.update(Gdx.graphics.getDeltaTime());// Clear the stuff that is left over from the previous render cycleGdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);// Let our ModelBatch take care of efficient rendering of our ModelInstancemodelBatch.begin(camera);modelBatch.render(instance, environment);modelBatch.end();}@Overridepublic void dispose() {modelBatch.dispose();model.dispose();}@Overridepublic void resize(int width, int height) { }@Overridepublic void pause() { }@Overridepublic void resume() { }
}

这里主要与上篇导入模型的代码区别在于,增加了

ModelInstance instance;
AnimationController controller;
public void create() {...instance = new ModelInstance(model);controller = new AnimationController(instance);controller.setAnimation("Cube|CubeAction",-1);
}
public void render() {...controller.update(Gdx.graphics.getDeltaTime());...
}

代码中controller.setAnimation(“Cube|CubeAction”,-1); 动画的名字
用文本方式打开导出的cube.g3dj 可以看到"animations"数据块,看到id,就是动画的名字
在这里插入图片描述

效果:
https://live.csdn.net/v/280148
请添加图片描述

相关内容

热门资讯

怎么让自己唱歌更像原唱?(跪求... 怎么让自己唱歌更像原唱?(跪求)我想学(大海)这首歌怎么让我唱的更像张雨生的声音?更像原唱?去搜索一...
适合办公室养的小鸟是哪些? 适合办公室养的小鸟是哪些?蓝靛壳、黄鸟、鹦鹉
心智未开怎么办!? 心智未开怎么办!?我看你是几岁了,如果30岁心智还未打开还未成熟,那就没有办法了。那就让时间来打开自...
不怠人间客什么意思? 不怠人间客什么意思?不怠人间客的意思就是不懈怠从凡间来访的客人。
郑希怡都拍过哪些经典的电影和电... 郑希怡都拍过哪些经典的电影和电视剧?如果不曾爱过你,浪漫满厨,薛平贵与王宝钏、遇见王沥川,无懈可击之...
狐仙姐姐可以听地藏经吗? 狐仙姐姐可以听地藏经吗?可以啊,而且好多地仙也是修佛家法门的众生平等,我佛慈悲,共度终生,狐仙姐姐当...
崇文老地标重张后迎来首个暑假 ... 转自:千龙网原标题:崇文老地标重张后迎来首个暑假,老街坊带着孩子重访“文化地标” 好久不见 花市书店...
为什么男人打电话会情不自禁发出... 为什么男人打电话会情不自禁发出昂昂昂的声音?这是一种很自然的心理上的条件反应!雄性荷尔蒙分泌过盛是这...
特朗普批马斯克建立政党“荒谬至...   美国总统特朗普当地时间周日表示,马斯克创立一个美国新政党的举动是荒谬的,可能会加剧混乱。  特朗...
“笑商”也是城市软实力 转自:沈阳日报  □孙连宇  “很多工作中的压力都在笑声中烟消云散。”全国劳动模范、华晨宝马汽车有限...