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
请添加图片描述

相关内容

热门资讯

清朝有很多有名的历史人物,能给... 清朝有很多有名的历史人物,能给大家说几个清朝的历史人物吗?林则徐,张之洞,乾隆皇帝,曾国藩,朱耷,这...
曹丕的“太子四友”指的是谁 曹丕的“太子四友”指的是谁首先说,曹丕这四个,陈群司马懿是顶级的谋士和政治家,吴质有些小聪明,朱铄不...
在这次遇难者中存在了几名幸存者... 在这次遇难者中存在了几名幸存者。这句话是不是逻辑错误这句话的逻辑没有问题,有问题的是用词不当。遇难者...
在中国古代,有许多充满哲学智慧... 在中国古代,有许多充满哲学智慧的成语典故、寓言故事,如...在中国古代,有许多充满哲学智慧的成语典故...
清澈的意思是什么,… 清澈的意思是什么,…清净而明澈清而透明【造句】看着他清澈而又天真的眼眸,我的心久久不能平静……
蚂蚁森林合种爱情树一方退出怎么... 蚂蚁森林合种爱情树一方退出怎么找回来两个人合种的爱情树,我退出来,我怎么再次加入进去继续合作那个树?...
有好看的古代修炼小说推荐吗? 有好看的古代修炼小说推荐吗?古代重生穿越修炼......让我帮你找一下这些古代修炼的小说,找到这些类...
女主重生爱上前世辜负的人 女主重生爱上前世辜负的人重生我是你正妻渣女重生之竹马重生之弃渣重生之夫君可欺重生之换我疼你重生妇归来...
华胥引有广播剧吗 华胥引有广播剧吗现有的华胥引的广播剧是忆语广播剧社出品的,只有十三月和杯(这个是错字,请无视,居然输...
选文韩麦尔先生在说了,我的朋友... 选文韩麦尔先生在说了,我的朋友们我就要离开你们呢了,再见了银头鲑鱼tj75rt6yturdrruv ...
中通快递从北京保定市到广东揭阳... 中通快递从北京保定市到广东揭阳普宁要多久?中通快递从北京保定市到广东揭阳普宁要多久?从北京到广东需要...
关于离婚悲伤的歌曲 关于离婚悲伤的歌曲关于离婚悲伤的歌曲林俊杰《可惜没如果》 张靓颖《我走以后》 金志文《流着泪说分手》...
形容文笔差怎么说啊? 形容文笔差怎么说啊?哥哥姐姐,麻烦问下,我是做文员的,形容文案方面的工作很差应该怎么说啊?粗鄙怎么样...
我想做未婚妈妈,可行吗? 我想做未婚妈妈,可行吗?没关系吧?我同学好多他们妈妈都是30岁以后省得他们,都没事啊,但是如果你自己...
如何在两个excel表格里筛选... 如何在两个excel表格里筛选出重复的名字如何在两个excel表格里筛选出重复的名字1、电脑打开EX...
且试天下 哪些小说是用白绫做武... 且试天下 哪些小说是用白绫做武器的?神雕侠侣吖- -..小龙女一开始就是用白绫的聊斋 辛十四娘嘿嘿~...
自带高冷体质,笑起来温暖又治愈... 自带高冷体质,笑起来温暖又治愈的星座,你了解吗?虽然天生高冷体质,但是笑起来特别的温暖治愈的新作用天...
火星未解之谜 火星未解之谜多列举一些,每个事例最好长一点,谢啦~“火星人脸”, “地表被水冲击河道”,“原始大气和...
我是1991年10月4号生的,... 我是1991年10月4号生的,是什么星座啊有的说是处女座有的说是天平座,糊涂了,到底是什么啊很负责任...
梦见白狐狸,然后当时我骑着自行... 梦见白狐狸,然后当时我骑着自行车,我想躲开它,他很凶的的追赶我,最后它向我扑了过来,然后我就醒乐.你...