1. <legend id='nxHle'><style id='nxHle'><dir id='nxHle'><q id='nxHle'></q></dir></style></legend>
    2. <i id='nxHle'><tr id='nxHle'><dt id='nxHle'><q id='nxHle'><span id='nxHle'><b id='nxHle'><form id='nxHle'><ins id='nxHle'></ins><ul id='nxHle'></ul><sub id='nxHle'></sub></form><legend id='nxHle'></legend><bdo id='nxHle'><pre id='nxHle'><center id='nxHle'></center></pre></bdo></b><th id='nxHle'></th></span></q></dt></tr></i><div id='nxHle'><tfoot id='nxHle'></tfoot><dl id='nxHle'><fieldset id='nxHle'></fieldset></dl></div>
      • <bdo id='nxHle'></bdo><ul id='nxHle'></ul>
    3. <tfoot id='nxHle'></tfoot>

    4. <small id='nxHle'></small><noframes id='nxHle'>

      LibGDX - 使用 Modelbuilder.createBox 将单个纹理映射到

      时间:2023-05-19

        <tbody id='TP6Ge'></tbody>
      <tfoot id='TP6Ge'></tfoot>

      <small id='TP6Ge'></small><noframes id='TP6Ge'>

      <i id='TP6Ge'><tr id='TP6Ge'><dt id='TP6Ge'><q id='TP6Ge'><span id='TP6Ge'><b id='TP6Ge'><form id='TP6Ge'><ins id='TP6Ge'></ins><ul id='TP6Ge'></ul><sub id='TP6Ge'></sub></form><legend id='TP6Ge'></legend><bdo id='TP6Ge'><pre id='TP6Ge'><center id='TP6Ge'></center></pre></bdo></b><th id='TP6Ge'></th></span></q></dt></tr></i><div id='TP6Ge'><tfoot id='TP6Ge'></tfoot><dl id='TP6Ge'><fieldset id='TP6Ge'></fieldset></dl></div>
    5. <legend id='TP6Ge'><style id='TP6Ge'><dir id='TP6Ge'><q id='TP6Ge'></q></dir></style></legend>

          <bdo id='TP6Ge'></bdo><ul id='TP6Ge'></ul>

                本文介绍了LibGDX - 使用 Modelbuilder.createBox 将单个纹理映射到盒子的每个面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有以下生成 3D 立方体的代码片段:

                I have the following code snippet that generates a 3D cube:

                ModelBuilder modelBuilder = new ModelBuilder();
                
                box = modelBuilder.createBox(2f, 2f, 2f,
                                new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0])),
                                VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates
                        );
                

                到目前为止一切顺利.问题是立方体的所有面都使用相同的纹理,而我想要的是 Assetloader.tr[],它是一个数组,每个面上分别出现 6 个单独的纹理.

                So far so good. The problem is that all faces of the cube uses the same texture, whereas what I want is Assetloader.tr[], which is an array with 6 individual textures to appear on each face respectively.

                我试过了

                box.nodes.get(0).parts.get(0).material.set(new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0])));
                box.nodes.get(0).parts.get(1).material.set(new Material(TextureAttribute.createDiffuse(AssetLoader.tr[1])));
                ...
                

                但不知何故,文档并没有给我任何关于如何正确执行它的提示.我有点卡在这里atm.

                but somehow the documentation doesn't give me any hints for how to do it properly. I'm a bit stuck here atm.

                推荐答案

                有几个注意事项需要牢记.首先请务必仔细阅读:https://github.com/libgdx/libgdx/wiki/ModelBuilder%2C-MeshBuilder-and-MeshPartBuilder.

                There are several considerations to keep in mind. First of all make sure to carefully read: https://github.com/libgdx/libgdx/wiki/ModelBuilder%2C-MeshBuilder-and-MeshPartBuilder.

                其次,尽量避免使用 ModelBuilder#createXXX 方法.它们只是调试和测试目的的捷径.如果您查看 code 后面,你会发现它非常简单:

                Secondly, try to avoid the ModelBuilder#createXXX methods. They are just a shortcut for debugging and testing purposes. If you look at the code behind it, you'll see that's very straightforward:

                modelBuilder.begin();
                modelBuilder.part("box", GL20.GL_TRIANGLES, 
                        VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates,
                        new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0])))
                    .box(2f, 2f, 2f);
                box = modelBuilder.end();
                

                正如您所见,这会为整个盒子创建一个部分,因此尝试访问第二个部分(如您在示例中所做的那样)将不起作用.但是因为您想为每个面使用不同的材料,所以您需要为每个面创建一个零件.

                As you can see this creates a single part for the entire box, so trying to access a second part (as you do in your example) will not work. But because you want to use a different material for each face, you'll need to create a part for each face.

                int attr = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
                modelBuilder.begin();
                modelBuilder.part("front", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0])))
                    .rect(-2f,-2f,-2f, -2f,2f,-2f,  2f,2f,-2, 2f,-2f,-2f, 0,0,-1);
                modelBuilder.part("back", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[1])))
                    .rect(-2f,2f,2f, -2f,-2f,2f,  2f,-2f,2f, 2f,2f,2f, 0,0,1);
                modelBuilder.part("bottom", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[2])))
                    .rect(-2f,-2f,2f, -2f,-2f,-2f,  2f,-2f,-2f, 2f,-2f,2f, 0,-1,0);
                modelBuilder.part("top", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[3])))
                    .rect(-2f,2f,-2f, -2f,2f,2f,  2f,2f,2f, 2f,2f,-2f, 0,1,0);
                modelBuilder.part("left", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[4])))
                    .rect(-2f,-2f,2f, -2f,2f,2f,  -2f,2f,-2f, -2f,-2f,-2f, -1,0,0);
                modelBuilder.part("right", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[5])))
                    .rect(2f,-2f,-2f, 2f,2f,-2f,  2f,2f,2f, 2f,-2f,2f, 1,0,0);
                box = modelBuilder.end();
                

                但是,每个面都有一个零件确实意味着每个面都有一个渲染调用.确保所有 TextureRegion 共享相同的纹理并改为使用该纹理会更高效:

                However, having a part for each face does imply a render call for each face. It is more performant to make sure that all TextureRegions share the same texture and use that instead:

                int attr = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates;
                modelBuilder.begin();
                MeshPartBuilder mpb = modelBuilder.part("box", GL20.GL_TRIANGLES, attr, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0].getTexture())));
                mpb.setUVRange(AssetLoader.tr[0]);
                mpb.rect(-2f,-2f,-2f, -2f,2f,-2f,  2f,2f,-2, 2f,-2f,-2f, 0,0,-1);
                mpb.setUVRange(AssetLoader.tr[1]);
                mpb.rect(-2f,2f,2f, -2f,-2f,2f,  2f,-2f,2f, 2f,2f,2f, 0,0,1);
                mpb.setUVRange(AssetLoader.tr[2]);
                mpb.rect(-2f,-2f,2f, -2f,-2f,-2f,  2f,-2f,-2f, 2f,-2f,2f, 0,-1,0);
                mpb.setUVRange(AssetLoader.tr[3]);
                mpb.rect(-2f,2f,-2f, -2f,2f,2f,  2f,2f,2f, 2f,2f,-2f, 0,1,0);
                mpb.setUVRange(AssetLoader.tr[4]);
                mpb.rect(-2f,-2f,2f, -2f,2f,2f,  -2f,2f,-2f, -2f,-2f,-2f, -1,0,0);
                mpb.setUVRange(AssetLoader.tr[5]);
                mpb.rect(2f,-2f,-2f, 2f,2f,-2f,  2f,2f,2f, 2f,-2f,2f, 1,0,0);
                box = modelBuilder.end();
                

                虽然这可能对您有所帮助,但您确实应该重新考虑您的方法.如您所见,通过代码创建模型会很快变得一团糟.此外,在大多数情况下,为盒子创建单个模型远非最佳,除非您的目标是仅渲染单个盒子且仅渲染一个盒子.而是使用建模应用程序来创建模型.查看我的博客 http://blog.xoppa.com/ 了解更多信息.如果您真的想自己修改零件,请确保至少阅读并包括幕后"教程.

                While this might help you do you want, you should really reconsider your approach. As you can see, creating a model by code can get messy really fast. And, moreover, creating a single model for a box is in most cases far from optimal unless your goal is to only render a single box and nothing more than a box. Instead use a modeling application to create your models. Have a look at my blog at http://blog.xoppa.com/ for more info. If you really want to modify parts yourself, then make sure to read at least up to and including the "behind the scenes" tutorials.

                这篇关于LibGDX - 使用 Modelbuilder.createBox 将单个纹理映射到盒子的每个面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何获得带有包装文本的标签? 下一篇:按钮 ClickListener 在 LibGDX 游戏中不起作用

                相关文章

                最新文章

                • <bdo id='OOCLh'></bdo><ul id='OOCLh'></ul>

                <legend id='OOCLh'><style id='OOCLh'><dir id='OOCLh'><q id='OOCLh'></q></dir></style></legend>

                  <tfoot id='OOCLh'></tfoot>
                  <i id='OOCLh'><tr id='OOCLh'><dt id='OOCLh'><q id='OOCLh'><span id='OOCLh'><b id='OOCLh'><form id='OOCLh'><ins id='OOCLh'></ins><ul id='OOCLh'></ul><sub id='OOCLh'></sub></form><legend id='OOCLh'></legend><bdo id='OOCLh'><pre id='OOCLh'><center id='OOCLh'></center></pre></bdo></b><th id='OOCLh'></th></span></q></dt></tr></i><div id='OOCLh'><tfoot id='OOCLh'></tfoot><dl id='OOCLh'><fieldset id='OOCLh'></fieldset></dl></div>

                  1. <small id='OOCLh'></small><noframes id='OOCLh'>