封装地址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);
}
};