javascript Three.js:平面只有一半时间可见

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10889583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:22:57  来源:igfitidea点击:

Three.js: Plane visible only half the time

javascriptthree.js

提问by Randomblue

I've created a plane, which I rotate, using Three.js. For some reason, the plane doesn't show half the time. I've created a fiddle hereshowing the behaviour.

我使用 Three.js 创建了一个旋转的平面。出于某种原因,飞机有一半的时间没有出现。我在这里创建了一个小提琴显示行为。

回答by Chris

Note that this has changed slightly in Three.js revision r50. Rendering both sides of a plane can be achieved through the sideproperty on the Material, i.e.

请注意,这在 Three.js 修订版 r50 中略有变化。一个平面的两边都可以通过sideMaterial上的属性来实现渲染,即

plane.material.side = THREE.DoubleSide;

Look herefor more details.

查看此处了解更多详情。

回答by GNi33

It's not visible because the backface of the plane does not get rendered (or better said, a plane doesn't have backfaces per default. On a side note, have a look at backface-cullingregarding this. Although it's not the issue in this case, it may give you a little insight about rendering).

它是不可见的,因为飞机的背面没有被渲染(或者更好地说,默认情况下飞机没有背面。顺便说一下,看看背面剔除关于这个。虽然这不是问题情况下,它可能会让您对渲染有一些了解)。

Three.js does give you a very easy way to render backfaces though.

Three.js 确实为您提供了一种非常简单的方法来渲染背面。

In Three.js - r49 and below:

在 Three.js - r49 及以下

All you need to do is set the doubleSided- property of your plane-Object to true.

您需要做的就是将doubleSided飞机对象的- 属性设置为 true。

plane.doubleSided = true;

For newer versions - r50 and up

对于较新版本 - r50 及更高版本

In newer revisions, as donnyB already stated correctly in his answer, the property was moved from the Object3D- object to the Material- object, so you'd need to set it a little differently, like so:

在较新的修订版中,正如 donnyB 在他的回答中已经正确说明的那样,该属性已从Object3D- 对象移动到Material- 对象,因此您需要对其进行一些不同的设置,如下所示:

plane.material.side = THREE.DoubleSide;

Also edited your fiddle to show you: http://jsfiddle.net/VsWb9/1084/

还编辑了您的小提琴以向您展示:http: //jsfiddle.net/VsWb9/1084/

it is using a Three.js - version newer than r50, the property is set on line 35

它使用的是 Three.js - 比 r50 新的版本,属性设置在第 35 行