第一次嘗試三個js ...我的立方體是黑色的...我把顏色設置爲紅色,是有原因的嗎?三個js立方體是黑色的...不是紅色的
<!DOCTYPE html>
<html>
<head>
<title>Some shapes</title>
<script type="text/javascript" src="../lib/threejs/build/three.js"></script>
<script type="text/javascript" src="../lib/jquery-2.1.3.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="output">
</div>
<script type="text/javascript">
$(function() {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xEEEEEE);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMapEnabled = true;
var cubeGeometry = new THREE.CubeGeometry(8,8,8);
var cubeMaterial = new THREE.MeshLambertMaterial({color: 0x990000});
var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.x = -4;
cube.position.y = 3;
cube.position.z = 0;
scene.add(cube);
camera.position.x = -30;
camera.position.y = 40;
camera.position.z = 30;
camera.lookAt(scene.position);
$("#output").append(renderer.domElement);
renderer.render(scene, camera);
});
</script>
</body>
</html>
我在網格lambert材料中設置顏色......但我不認爲我需要做的比這更多嗎?在瀏覽器中它出來黑色......它可能與setClearColour有什麼關係?
我將MeshLambertMaterial更改爲MeshBasicMaterial並且它工作正常,我猜測這是因爲lambert材質顏色可能是由物體上的某種光源決定的,因爲沒有光線,顏色會出現黑色... – user2405469 2015-02-07 11:51:31