用于 3D 游戏的 Libgdx 渲染地板 [英] Libgdx rendering floor for 3D game

查看:25
本文介绍了用于 3D 游戏的 Libgdx 渲染地板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的第一个 3D 游戏中,我现在想在 y = 0 上渲染地板,它实际上是一个平面(不是 libgdx Plane).

In my first 3D game i now want to render the floor, which is actually a plane (not a libgdx Plane) on y = 0.

我想给它添加一个Texture,这样我就可以在每一层都有不同的楼层了.

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?

我考虑过使用由 ModelBuilder 制作的基本 Block Models,然后添加了一个 Texture,但因为我只能看到 6 个面孔中的 1 个一个 2d Texture 就足够了,所以我想到了一个 Plane.

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.

我可以将 Texture 添加到 Plane,因为它是 3D 房间中的无限面吗?然后我想到的最后一件事是Decal.

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 Decals.

贴花是我要找的吗?我该如何使用它们?或者您有其他解决方案.

Are Decals 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.

谢谢

推荐答案

首先关于贴花,贴花就像精灵,但是在3d坐标中,这样使用它:

First about Decals, decals are like Sprites but in 3d coordinate, use it like this:

私人贴花贴花;私人贴花贴花贴花;

private Decal decal; private DecalBatch decalBatch;

在 show() 或 create() 中

in show() or 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);

在渲染()中

//Add all your decals then flush()
decalBatch.add(decal);
decalBatch.flush();

也可以使用 decalBatch.dispose();

also dispose with decalBatch.dispose();

请注意,未来贴花将成为 3d 的一部分,我个人不鼓励您像我自己一样使用贴花使用 3d 平面,我发现它存在一些问题,要像这样使用 3d 平面,我粘贴了一些代码这里

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)

对于具有 alpha 的透明平面添加到其他属性

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() 中渲染

render in render() with ModelBatch object

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

this is my benchmark on Plane vs Decals http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=12493

这篇关于用于 3D 游戏的 Libgdx 渲染地板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆