如何在3D环境中的表面上渲染图像?我知道如何渲染3D形状和2D精灵,但例如,我如何将某个图片放在立方体/长方体的一侧?例如,我想创建一个2D正方形,并在它的两侧放置一张图片,然后在我的3D环境中渲染整个东西。或者是每一面都有不同图像的盒子。我不知道我是不是说得通。
顺便说一下,我在eclipse上使用的是libGdx。
发布于 2014-08-15 13:33:28
在我的游戏中,我有一些类似如下的代码。这面墙是我用代码生成的一个简单的盒子模型。纹理是通过Material应用的。
private static final ModelBuilder MODEL_BUILDER = new ModelBuilder();
public static Model createWall(float width, float height, float depth) {
Texture texture = new Texture("wall.png");
Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
Model wall = MODEL_BUILDER.createBox(width, height, depth, material, attributes);
return wall;
}之后,您可以从该文件(new ModelInstance(wallModel))创建一个ModelInstance,然后通过ModelBatch呈现它。
https://stackoverflow.com/questions/25321568
复制相似问题