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

相关内容

热门资讯

山东威海虐狗事件后续 山东威海虐狗事件后续山东威海虐狗事件后续... 山东威海虐狗事件后续 展开 这件事看出来我们中...
博越车上的音效均衡器怎么调整,... 博越车上的音效均衡器怎么调整,音乐才能好听首先需要一个专业修改过的高音质U盘,比普通歌的音质要高6倍...
天涯明月刀、太白用什么心法和石... 天涯明月刀、太白用什么心法和石头、非土豪!现在60级用的归翘、严师、白刃。 太白的主要属性是洞察和力...
华帝抽油烟机i字头和e字头产品... 华帝抽油烟机i字头和e字头产品那个好华帝抽油烟机i字头和e字头产品那个好e好,i是网上型号,e是实体...
竹笛伴我 四十载 转自:衢州日报  厉向军  搬家数次,许多旧物已离我而去,这支竹笛如影随形,伴我走过了四十年的风雨历...
从绰尔河到西辽河的千钧之诺 转自:内蒙古日报□本报记者  霍晓庆  高敏娜  2025年6月30日,内蒙古迄今为止投资规模最大的...
我区420家企业享受研发投入后... 转自:内蒙古日报本报7月6日讯  (记者  白莲)记者从自治区科技厅获悉,自治区科技厅日前会同财政厅...
兴证全球基金杨世进:秉持缓进之...   很会学、很谦虚、成绩好,是为“三好”。同事称赞道,在长达十五年的投研生涯中,兴证全球基金杨世进始...
个人账户余额可跨省转账   三湘都市报7月6日讯 在湖南工作的参保职工,可以给外省的家人转账医保个人账户资金了。记者刚刚从湖...
蜈蚣坝伏击战:大青山铭记的烽火... 转自:内蒙古日报□本报记者  宋爽  通讯员  陈艳平   夏风拂过蜈蚣坝顶,一块沉静的石碑吸引着过...