大家好,我是从Three.js开始的,我不知道为什么我的第二个几何图形不显示。如果我错过了什么,请帮助我。我添加了所有材料的第一个几何图形并添加到场景中,但是我不想显示第二个几何图形。这里需要一点帮助,非常感谢!!!
// Scene and Camera
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000);
// Renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// Firt geometry with material and added to the scene.
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh(geometry, material);
scene.add( cube );
// Seconde geometry with material and added to the scene as well.
var mysphere = new THREE.SphereGeometry(5, 32, 32);
var color = new THREE.Color('#ee7800');
var hex = color.getHex;
var sphereMaterial = new THREE.MeshLambertMaterial( { color: hex } );
var sphere = new THREE.Mesh(mysphere, sphereMaterial);
sphere.position.y = 10;
scene.add( sphere );
// Better camera position
camera.position.z = 5;
// Render all and move the cube
function render() {
requestAnimationFrame( render );
cube.rotation.x += 0.03;
cube.rotation.y += 0.01;
renderer.render( scene, camera);
};
render();
最佳答案
只是为了澄清。您的控制台日志中是否有任何错误消息?
var hex = color.getHex();
因为getHex()是一种方法。
还有,为什么不
var sphereMaterial = new THREE.MeshLambertMaterial( { color: 0xee7800} );
色彩的构造者看起来很奇怪。应该是这样的:
var color = new THREE.Color( 0xee7800 );