简体   繁体   English

在three.js的ExtrudeGeometry.UVGenerator.generateSideWallUV中条件语句的目的是什么?

[英]What is the purpose of the conditional statement in three.js's ExtrudeGeometry.UVGenerator.generateSideWallUV?

In three.js's ExtrudeGeometry.UVGenerator.generateSideWallUV there is the conditional: 在three.js的ExtrudeGeometry.UVGenerator.generateSideWallUV中有条件:

if ( Math.abs( a.y - b.y ) < 0.01 ) {

        return [
            new Vector2( a.x, 1 - a.z ),
            new Vector2( b.x, 1 - b.z ),
            new Vector2( c.x, 1 - c.z ),
            new Vector2( d.x, 1 - d.z )
        ];

    } else {

        return [
            new Vector2( a.y, 1 - a.z ),
            new Vector2( b.y, 1 - b.z ),
            new Vector2( c.y, 1 - c.z ),
            new Vector2( d.y, 1 - d.z )
        ];

    }

This makes weird discontinuities in the uvs, for example (just displaying the uv coordinates at the red and green channels on this shape): 例如,这会在uv中产生奇怪的不连续性(仅在此形状的红色和绿色通道上显示uv坐标):

字母“P”底部的紫外线不连续

Removing this block (and always using the else block) makes everything run as expected. 删除此块(并始终使用else块)可使所有内容按预期运行。 Can anyone tell me why this block exists in the first place? 谁能告诉我为什么这个区块首先存在?

The default UV generator for ExtrudeGeometry sets the UVs based on the position of the vertices. ExtrudeGeometry的默认UV生成器根据顶点的位置设置UV。

Note that the sidewall of ExtrudeGeometry consist of a series of rectangles chained together. 请注意, ExtrudeGeometry的侧壁由一系列链接在一​​起的矩形组成。

Where the sidewall is mostly vertical in XYZ-space, then the UVs are determined from the YZ-coordinates of the position; 在XYZ空间中侧壁大部分是垂直的,那么UV是由位置的YZ坐标确定的; otherwise, the XZ coordinates are used. 否则,使用XZ坐标。

This is not an easy problem. 这不是一个容易的问题。 The UV generation here is reasonable, but can result in stretching. 这里的紫外线产生是合理的,但可以导致拉伸。

You are free to specify your own UV-generator if you have a better algorithm. 如果您有更好的算法,可以自由指定自己的UV发生器。

three.js r.82 three.js r.82

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM