【问题标题】:Transform basic geometry in three.js [closed]在three.js中转换基本几何[关闭]
【发布时间】:2016-05-23 00:48:19
【问题描述】:

我正在尝试重新创建 this Three.js example。它从一组预定义的块面生成地形几何。但是,只是简单地复制代码开始,我遇到了一个问题。

这是示例中一个块面的代码:

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 中旋转、平移和缩放基本几何图形?

【问题讨论】:

  • 您引用的示例确实使用了 r74。
  • @gaitat 我更新了这个问题。我只是直接复制代码并添加了最新的 CDN,所以我认为这一定是问题所在。也就是说,我仍然找不到问题。
  • 那么问题不在于您发布的代码。这是使用 r74 无错误地修改您的代码:jsfiddle.net/8fhxw4je
  • 出现了codepen添加r70的“快速添加”菜单,很抱歉浪费您的时间。

标签: javascript graphics 3d three.js


【解决方案1】:

THREE.PlaneGeometry 的原型建立在THREE.Geometry 原型之上。你可以看到here。这意味着THREE.Geometry 的所有方法在THREE.PlaneGeometry 实例中也可用。

THREE.Geometry 有一个rotateY 方法。你可以看到here in the documentationhere in the file

所以回答您的问题:您可以使用THREE.Geometry 中的所有方法来旋转、平移和缩放您的基本几何图形。

【讨论】:

    猜你喜欢
    • 2021-12-21
    • 2020-07-11
    • 2012-02-27
    • 2018-12-03
    • 1970-01-01
    • 2019-01-01
    • 2013-02-25
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多