我在使用LibGDX的ModelBatch中绘制ModelInstances,但模型的纹理变形,透明像素不透明。我使用纹理包装器like this来制作地图集。然后我将TextureAgion从atlas分配给Material,以便创建MeshPartBuilder:
GameModels() {
int attr = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
TextureRegion texture = textureAtlas.findRegion("cactus");
modelBuilder.begin();
MeshPartBuilder meshPartBuilder = modelBuilder.part("box", GL20.GL_TRIANGLES, attr,
new Material(TextureAttribute.createDiffuse(texture),
ColorAttribute.createDiffuse(ItemType.CACTUS.color)));
BoxShapeBuilder.build(meshPartBuilder, 1f,1f,1f);
cubeModel = modelBuilder.end();
}
但是从创建的模型中渲染会产生以下结果: A cropped and opaque texture
我希望生成一个尊重纹理的纹理渲染,并且是透明的,就像第二个链接中的第二个图像一样。我怎样才能做到这一点?
答案 0 :(得分:0)
通过向材质添加BlendingAttribute,纹理现在支持TextureRegion的透明度。
BlendingAttribute blendingAttribute = new BlendingAttribute();
blendingAttribute.opacity = 1f;
...
MeshPartBuilder meshPartBuilder = modelBuilder.part("box", GL20.GL_TRIANGLES, attr,
new Material(textureAttribute, blendingAttribute));