Libgdx 3D封装

封装地址github:wangGame/LibgdxTool3D仓库。

已经封装目录

  • 简化绘制
  • 方便使用Actor3D来展示模型
  • 简单的动画封装
  • 鼠标点击

基本的封装思路

创建一个stage3D,基本和2D的类似,这个里面进行绘制和点击检测。也引入基本的Group操作,方便管理子类,动画也基本是沿用2D的动画操作,引入Action3Ds对动画进行添加。

使用

继承BaseScreen3D

public class GameScreen extends BaseScreen3D {
    public GameScreen(BaseGame game) {
        super(game);
    }

    @Override
    public void initView() {
        //加入初始化页面内容  
    }     
}

绘制正方体

        Actor3D actor3D1 = new Actor3D();
        stage3D.addActor(actor3D1);
        actor3D1.buildModel(3,3,3,true);

展示模型

模型加载,使用Asset3D进行加载

 Model model = Asset3D.getAsset3D().getModel("tile/table.g3db");
//创建模型actor
Actor3D actor3D = new Actor3D(model);
stage3D.addActor(actor3D);
//创建皮肤
Texture woodTexture = Asset.getAsset().getTexture("tile/Bd.png");
woodTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
woodTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
actor3D.setMaterialTexture(woodTexture);
//缩放
actor3D.setScale(7,7,7);
//位置
actor3D.setPosition(0,-0.5f,0);

设置材质

attributes1.set(
       ColorAttribute.createDiffuse(0.39f, 0.09f, 0.07f, 1.0f),
       ColorAttribute.createSpecular(1.0f, 1.0f, 1.0f, 1.0f), 
      FloatAttribute.createShininess(1000.0f)
);
actor3D.setMetal(attributes1);

动画操作

//int值的操作
actor3D.addAction(Action3Ds.addAction3D(
        Action3Ds.intAction3D(0,100, Interpolation.bounceIn,1)
));
//移动
actor3D.addAction(Action3Ds.moveToAction3D(2,2,2,2,Interpolation.linear));
//旋转
actor3D.addAction(Action3Ds.rotation3D(0,180,180,2,Interpolation.linear));

点击事件

目前点击事件没有复杂封装,仅仅是点击到那个模型,就执行该模型的touchDown方法

Actor3D actor3D = new Actor3D(model){
     @Override
     public void touchUp(Vector3 vector3, int pointer, int button) {
         super.touchUp(vector3, pointer, button);
         setColor(Color.BLUE);
     }
};
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、WebGL与threeJS WebGL是一种3D绘图协议,其允许JavaScript和OpenGL ES2.0...
    患者_阅读 20,595评论 1 22
  • 这是500Lines项目中的A 3D modeller文章的翻译版,讲述如何使用Python,OpenGL,GLU...
    今天又忘记密码阅读 1,189评论 0 2
  • 1. 介绍 人类天生具有创造力。我们不断设计和构建新颖,实用和有趣的东西。在现代,我们编写软件来协助设计和创作过程...
    博士伦2014阅读 1,216评论 0 1
  • 3D开发中涉及到的技术 OpenGLOpenGL 是用于渲染 2D 、3D 矢量图形的跨语言、跨平台的应用程序编程...
    香辣牛肉面阅读 897评论 0 1
  • 一:什么是协同程序? 在主线程运行的同时开启另一段逻辑处理,来协助当前程序的执行,协程很像多线程,但是不是多线程,...
    胤醚貔貅阅读 2,096评论 0 13