Spr*_*bua 4 java 3d decal libgdx
在我的第一个3D游戏中,我现在想要渲染地板,实际上是一个平面(不是libgdx Plane)y = 0.
我想添加一个Texture,所以我可以在每个级别有不同的楼层.
现在我的问题是:创建和渲染这个纹理地板的最佳方法是什么?
我考虑使用基本Block Models制作ModelBuilder然后添加了一个Texture,但因为我只能看到6个面中的一个,2d Texture就够了,所以我想到了Plane.
我可以添加一个Texture到Plane,因为它是在3D房间无限的脸?我接下来想到的最后一件事是Decals.
是否Decal就是我要寻找?我该如何使用它们?或者你有其他解决方案吗?
任何教程或其他帮助都会很棒.
谢谢
首先关于贴花,贴花就像精灵,但在三维坐标中,使用它像这样:
私人贴花贴花; 私人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);
Run Code Online (Sandbox Code Playgroud)
在渲染()
//Add all your decals then flush()
decalBatch.add(decal);
decalBatch.flush();
Run Code Online (Sandbox Code Playgroud)
也可以使用decalBatch.dispose();
请注意,在未来贴花将成为3d的一部分,我个人不鼓励你使用贴花作为我自己使用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);
//NOTE ON TEXTURE REGION, MAY FILL OTHER REGIONS, USE GET region.getU() and so on
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());
}
Run Code Online (Sandbox Code Playgroud)
纹理可以作为属性添加到材质中
material.set(new TextureAttribute(TextureAttribute.Diffuse, texture)
Run Code Online (Sandbox Code Playgroud)
对于具有alpha添加到其他属性的透明平面
attributes.add( new BlendingAttribute(color.getFloat(3)));
attributes.add( new FloatAttribute(FloatAttribute.AlphaTest, 0.5f));
material.set(attributes);
Run Code Online (Sandbox Code Playgroud)
初始化ModelInstance以获取返回的模型
modelInstance = new ModelInstance(createPlaneModel(...))
Run Code Online (Sandbox Code Playgroud)
使用ModelBatch对象在render()中渲染
modelBatch.render(modelInstance );
Run Code Online (Sandbox Code Playgroud)
也看到这些链接. http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11884
这是我对Plane vs Decals的基准测试 http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=12493
| 归档时间: |
|
| 查看次数: |
4743 次 |
| 最近记录: |