如何使用顶点的 UV 属性将单个纹理映射到立方体的所有面?

How can I map a single texture to all sides of a cube using the UV attributes of vertices?

目前我正在创建这样的立方体网格:

        //bottom vertices of cube
                    positions.push([ 0.0, 0.0, 0.0 ]);
                    uvs.push([ 0.0, 0.0 ]);

                    positions.push([ 1.0, 0.0, 0.0 ]);
                    uvs.push([ 0.0, 1.0 ]);

                    positions.push([ 1.0, 0.0, 1.0 ]);
                    uvs.push([ 1.0, 1.0 ]);

                    positions.push([ 0.0, 0.0, 1.0 ]);
                    uvs.push([ 1.0, 0.0 ]);


                    //upper vertices of cube
                    positions.push([ 0.0, 1.0, 0.0 ]);
                    uvs.push([ 0.0, 1.0 ]);

                    positions.push([ 1.0, 1.0, 0.0 ]);
                    uvs.push([ 1.0, 1.0 ]);

                    positions.push([ 1.0, 1.0, 1.0 ]);
                    uvs.push([ 1.0, 0.0 ]);

                    positions.push([ 0.0, 1.0, 1.0 ]);
                    uvs.push([ 1.0, 1.0 ]);

(我使用了 16x16 像素大的纹理)

但是我很难映射这些 uv 位置,因为可以工作的最大面数是 4。 如果每边有 4 个顶点(总共 24 个),我会知道该怎么做,但由于性能原因我不想这样做。

有什么方法可以做到每个立方体只有 8 个顶点吗?

  • 最小立方体有六个面

  • 每边有两个三角形

  • 对于一个最小的立方体,您将拥有十二个三角形

  • 不要,重复不要费心尝试分享顶点。如果出于某种原因你想要,请稍后再做。

  • 只需确保每对三角形(一个正方形)具有正确的 UV