javascript THREE.meshphongmaterial 不工作 - 给出黑色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26937966/
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-28 06:42:53  来源:igfitidea点击:

THREE.meshphongmaterial Not Working - Giving Black Color

javascriptthree.js

提问by dc95

I am trying to use THREE.meshphongmaterialfrom this tutorial: http://solutiondesign.com/webgl-and-three-js-texture-mapping/

我正在尝试使用THREE.meshphongmaterial本教程:http: //solutiondesign.com/webgl-and-three-js-texture-mapping/

But it is not working and giving black color. Here is the jsfiddle for it: http://jsfiddle.net/8hrk7mu6/12/

但它不起作用并给出黑色。这是它的 jsfiddle:http: //jsfiddle.net/8hrk7mu6/12/

Problem is in line 32:

问题在第 32 行:

var material = new THREE.MeshPhongMaterial( { ambient: 0x050505, color: 0x0033ff, specular: 0x555555, shininess: 30 } );

Why is it not working? If I use THREE.MeshNormalMaterial, then it works.

为什么它不起作用?如果我使用THREE.MeshNormalMaterial,那么它的工作原理。

var material = new THREE.MeshNormalMaterial();

Later, I want to use texture from an image in my code. That is not working either. Only THREE.MeshNormalMaterialis working. Why?

后来,我想在我的代码中使用来自图像的纹理。那也不行。只有THREE.MeshNormalMaterial在工作。为什么?

回答by dc95

Turns out it is necessary to add light. Without light, meshphongmaterialgives black color.

事实证明,有必要添加光线。没有光,meshphongmaterial呈现黑色。

So I had to add something like this:

所以我不得不添加这样的东西:

var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 1, 1 ).normalize();
scene.add(light);

Got it from this link: https://github.com/mrdoob/three.js/issues/2766

从这个链接得到它:https: //github.com/mrdoob/three.js/issues/2766