首先是关于贴花(Decals)的内容,贴花类似于精灵(Sprites),但在三维坐标中,可以这样使用:
private Decal decal;
private DecalBatch decalBatch;
在 show() 或 create() 方法中使用。
decalBatch = new DecalBatch()
CameraGroupStrategy cameraGroupStrategy = new CameraGroupStrategy(camera)
decal = Decal.newDecal(textureRegion, true)
decal.setPosition(5, 8, 1)
decal.setScale(0.02f)
decalBatch.setGroupStrategy(cameraGroupStrategy)
in render()
//Add all your decals then flush()
decalBatch.add(decal);
decalBatch.flush();
还要使用decalBatch.dispose();来清除。
请注意,在未来,decal将成为3d的一部分,个人建议不要像我一样使用Decals,因为我在使用3d平面时遇到了一些问题。如果要使用3D平面,请按照以下方式使用。以下是我贴出的一些代码:
private Model createPlaneModel(final float width, final float height, final Material material,
final float u1, final float v1, final float u2, final float v2) {
modelBuilder.begin();
MeshPartBuilder bPartBuilder = modelBuilder.part("rect",
GL10.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates,
material);
bPartBuilder.setUVRange(u1, v1, u2, v2);
bPartBuilder.rect(
-(width*0.5f), -(height*0.5f), 0,
(width*0.5f), -(height*0.5f), 0,
(width*0.5f), (height*0.5f), 0,
-(width*0.5f), (height*0.5f), 0,
0, 0, -1);
return (modelBuilder.end());
}
材质可以添加纹理属性
material.set(new TextureAttribute(TextureAttribute.Diffuse, texture)
为具有透明度的平面添加 Alpha 到其他属性。
attributes.add( new BlendingAttribute(color.getFloat(3)));
attributes.add( new FloatAttribute(FloatAttribute.AlphaTest, 0.5f));
material.set(attributes);
初始化ModelInstance以获取返回的模型
modelInstance = new ModelInstance(createPlaneModel(...))
使用ModelBatch对象在render()中进行渲染
modelBatch.render(modelInstance );
请看下面这些链接。
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11884
以下是我对平面与贴花的基准测试结果。
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=12493