我正在尝试重新创建 this Three.js example 。它从一组预定义的 block 面生成地形几何形状。然而,只是简单地复制代码开始,我遇到了一个问题。
以下是示例中一个 block 面的代码:
var pxGeometry = new THREE.PlaneGeometry( 100, 100 );
pxGeometry.faces[ 0 ].vertexColors = [ light, shadow, light ];
pxGeometry.faces[ 1 ].vertexColors = [ shadow, shadow, light ];
pxGeometry.faceVertexUvs[ 0 ][ 0 ][ 0 ].y = 0.5;
pxGeometry.faceVertexUvs[ 0 ][ 0 ][ 2 ].y = 0.5;
pxGeometry.faceVertexUvs[ 0 ][ 1 ][ 2 ].y = 0.5;
pxGeometry.rotateY( Math.PI / 2 );
pxGeometry.translate( 50, 0, 0 );
这会抛出 pxGeometry.rotateY is not a function
.
据我所知,旋转和平移功能在 PlaneGeometry
上不可用。默认情况下。但是,如果是这种情况,我看不到这些在示例中添加的位置。
如何在 Three.js 中旋转、平移和缩放基本几何图形?
最佳答案
THREE.PlaneGeometry
的原型(prototype)构建在 THREE.Geometry
原型(prototype)之上。可以看到here 。这意味着 THREE.Geometry
的所有方法也可以在 THREE.PlaneGeometry
实例中使用。
THREE.Geometry
有一个 rotateY
方法。可以看到here in the documentation和 here in the file .
回答您的问题:您可以使用 THREE.Geometry
中的所有方法来旋转、平移和缩放基本几何图形。
关于javascript - 在 Three.js 中转换基本几何图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35352959/