admin管理员组文章数量:1356224
I have the following code that draws a diamond in Three.js:
var material = new THREE.MeshPhongMaterial({color: 0x55B663, side:THREE.DoubleSide});
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0, 1, 0));
geometry.vertices.push(new THREE.Vector3(0, -1, 0));
geometry.vertices.push(new THREE.Vector3(-1, 0, -1));
geometry.vertices.push(new THREE.Vector3(1, 0, -1));
geometry.vertices.push(new THREE.Vector3(1, 0, 1));
geometry.vertices.push(new THREE.Vector3(-1, 0, 1));
geometry.faces.push(new THREE.Face3(0, 4, 5));
geometry.faces.push(new THREE.Face3(0, 3, 4));
geometry.faces.push(new THREE.Face3(0, 2, 5));
geometry.faces.push(new THREE.Face3(0, 2, 3));
geometry.faces.push(new THREE.Face3(1, 4, 5));
geometry.faces.push(new THREE.Face3(1, 3, 4));
geometry.faces.push(new THREE.Face3(1, 2, 5));
geometry.faces.push(new THREE.Face3(1, 2, 3));
And this is how I set up the lighting:
var light = new THREE.PointLight(0xffffff);
light.position.set(100,200,100);
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 1.0);
light.position.set(0, 0, 0);
scene.add(light);
light = new THREE.AmbientLight(0x404040);
scene.add(light);
But when the scene is rendered - only the ambient lighting is applied:
However, as soon as I change my custom geometry to a standard cube - it all works:
var geometry = new THREE.BoxGeometry(1, 1, 1);
I am lost. Why doesn't the lighting work with my custom geometry?
I have the following code that draws a diamond in Three.js:
var material = new THREE.MeshPhongMaterial({color: 0x55B663, side:THREE.DoubleSide});
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0, 1, 0));
geometry.vertices.push(new THREE.Vector3(0, -1, 0));
geometry.vertices.push(new THREE.Vector3(-1, 0, -1));
geometry.vertices.push(new THREE.Vector3(1, 0, -1));
geometry.vertices.push(new THREE.Vector3(1, 0, 1));
geometry.vertices.push(new THREE.Vector3(-1, 0, 1));
geometry.faces.push(new THREE.Face3(0, 4, 5));
geometry.faces.push(new THREE.Face3(0, 3, 4));
geometry.faces.push(new THREE.Face3(0, 2, 5));
geometry.faces.push(new THREE.Face3(0, 2, 3));
geometry.faces.push(new THREE.Face3(1, 4, 5));
geometry.faces.push(new THREE.Face3(1, 3, 4));
geometry.faces.push(new THREE.Face3(1, 2, 5));
geometry.faces.push(new THREE.Face3(1, 2, 3));
And this is how I set up the lighting:
var light = new THREE.PointLight(0xffffff);
light.position.set(100,200,100);
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 1.0);
light.position.set(0, 0, 0);
scene.add(light);
light = new THREE.AmbientLight(0x404040);
scene.add(light);
But when the scene is rendered - only the ambient lighting is applied:
However, as soon as I change my custom geometry to a standard cube - it all works:
var geometry = new THREE.BoxGeometry(1, 1, 1);
I am lost. Why doesn't the lighting work with my custom geometry?
Share Improve this question edited May 8, 2015 at 2:39 WestLangley 105k11 gold badges287 silver badges283 bronze badges asked May 7, 2015 at 15:13 YemSalatYemSalat 21.5k13 gold badges48 silver badges51 bronze badges1 Answer
Reset to default 11It's because you haven't specified normals for your custom figure. You also need to do:
geometry.puteFaceNormals();
geometry.puteVertexNormals();
本文标签: javascriptThree js custom geometrylighting does not workStack Overflow
版权声明:本文标题:javascript - Three js custom geometry - lighting does not work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744061815a2584263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论