Libgdx渲染地板3D游戏 [英] Libgdx rendering floor for 3D game
问题描述
在我的第一个3D游戏的我现在要渲染的地板上,这实际上是对 Y = 0的平面(不是libgdx
。平面
)
In my first 3D game i now want to render the floor, which is actually a plane (not a libgdx Plane
) on y = 0
.
我想添加一个纹理
来了,这样我就可以在每个级别的不同楼层。
I want to add a Texture
to it, so i can have different floors in each level.
现在我的问题是:什么是创建和渲染这种纹理的地板最好的方法是什么?
Now my question is: What is the best way to create and render this textured floor?
我想过使用基本块模型
制作与模型构建器
,然后添加一个纹理
,但我只能看到1的6个面二维纹理
就足够了,所以我想到了一个飞机
。
I thought about using basic Block Models
made with ModelBuilder
and then added a Texture
, but as i can only see 1 of 6 faces a 2d Texture
would be enough, so i thought about a Plane
.
我可以添加一个纹理
到平面
,因为它是在3D房间无限的脸?最后一件事的话,我想到是在贴花
秒。
Can i add a Texture
to a Plane
, as it is a infinite face in 3D room? The last thing i then thought about were the Decal
s.
为贴花
S I期待的?以及如何使用它们?或者你有其他的解决办法。
Are Decal
s what i am looking for? And how can i use them? Or do you have an other solution .
任何教程或其他帮助将是巨大的。
Any tutorial or other help would be great.
感谢
推荐答案
一是关于贴花,贴花像精灵,但在三维坐标,使用这样的:
First about Decals, decals are like Sprites but in 3d coordinate, use it like this:
私人贴纸贴花; 私人DecalBatch decalBatch;
private Decal decal; private DecalBatch decalBatch;
在显示()或创建()
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);
在渲染()
//Add all your decals then flush()
decalBatch.add(decal);
decalBatch.flush();
还配置有decalBatch.dispose();
also dispose with decalBatch.dispose();
请注意,在未来的贴纸将3D的一部分,我个人不建议您使用三维平面使用贴花作为我自己,我发现了一些问题有了它,使用这样的三维平面的使用,我贴我的一些$的C $ CS此处
notice that in future decal will be part of 3d, I personally do not encourage you to use Decals as myself using 3d plane and I saw some problems with it, to use 3d plane use like these, i paste some of my codes here
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());
}
纹理可以添加属性材料
texture can be added as attribute to material
material.set(new TextureAttribute(TextureAttribute.Diffuse, texture)
透明飞机已经阿尔法添加到其他属性的
for transparent plane that has alpha add to other attribute
attributes.add( new BlendingAttribute(color.getFloat(3)));
attributes.add( new FloatAttribute(FloatAttribute.AlphaTest, 0.5f));
material.set(attributes);
初始化的ModelInstance来获取返回的模型
Init the ModelInstance to get model that returned
modelInstance = new ModelInstance(createPlaneModel(...))
渲染渲染()与ModelBatch对象
render in render() with ModelBatch object
modelBatch.render(modelInstance );
请参见以下链接了。 http://www.badlogicgames.com/forum/viewtopic.php ?F = 11& T公司= 11884
see these links too. http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11884
这是我的基准平面上VS贴花 http://www.badlogicgames.com/forum/viewtopic.php ?F = 11& T公司= 12493
this is my benchmark on Plane vs Decals http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=12493
这篇关于Libgdx渲染地板3D游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!