使用 Three.js 渲染图形时未生成具有 Mesh lambert 材质的对象 [英] Objects with Mesh lambert material not being generated while rendering graphics with three.js
问题描述
好吧,我刚开始学习three.js,这对我来说是全新的.所以我正在写这一系列的 hello world kinda scrips.好吧,我写了下面的脚本来用 MeshBasicMaterial 生成一个立方体(好吧,这只是博客中给出的教程的精确副本)
Well I just started learning three.js which is totally totally totally new to me. So I am writing these series of hello world kinda scrips.Well I wrote the script below to generate a cube with MeshBasicMaterial (Well this is just an exact copy of a tutorial given in a blog)
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, 640/340, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(640, 340);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.CubeGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial({color: 0xD43001});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
var render = function (){
requestAnimationFrame(render);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
};
render();
当我从
var material = new THREE.MeshBasicMaterial({color: 0xD43001});
到
var material = new THREE.MeshLambertMaterial({color: 0xD43001});
什么都没有显示.我到底错过了什么?
nothing gets displayed. WHat exctly am I missing?
更新
所以我不得不添加一个光源来显示一个由网状兰伯特材料制成的对象.当我添加一个点光源时,对象被显示出来.
So i had to add a light source to display an object made out of mesh lambert material.When I added a point light the object got displayed.
推荐答案
这是因为 MeshBasicMaterial 不会对光照做出反应,而是具有恒定的颜色.
This is because MeshBasicMaterial does not react to lighting but has a constant colour.
然而,MeshLambertMaterial 确实会对光照做出反应,所以没有光,你就看不到它!MeshPhongMaterial 也是如此.
A MeshLambertMaterial however, does react to lighting, so without light, you cannot see it! The same goes for MeshPhongMaterial.
这篇关于使用 Three.js 渲染图形时未生成具有 Mesh lambert 材质的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!