1、scene= new THREE.Scene();
2、camera的幾個函數設置
camera = new THREE.PerspectiveCamera(VIEW_ANGLE, ASPECT, NEAR, FAR);
//照相機參數設定
camera.position.set(x,y,z);
//照相機的位置
camera.lookAt(scene.position);//這裏的參數是個集合,所以要寫成camera.lookAt(x: ,y: ,z:);這種形式
//照相機要看的點
2、renderer渲染窗口的設置
renderer = new THREE.WebGLRenderer({antialias:true} );
//建立renderer對象
renderer.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
//設置renderer的大小
container = document.getElementById( 'ThreeJS' );
//建立容器對象
container.appendChild( renderer.domElement);
//將renderer附在剛纔創建的容器對象上。
3、light對象設置
var light = new THREE.PointLight(0xffffff);點光源設置
light.position.set(0,250,0);光源位置
scene.add(light);將光源對象附加在scene
4、mesh對象
首先:var sphereGeometry =new THREE.SphereGeometry( 半徑, width的段數, height的段數 );
其次:var sphereMaterial =new THREE.MeshLambertMaterial( {color: 0x8888ff} );建立一種材質
再次:將前面兩個建立的對象組成mesh對象var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
然後:position.set(100, 50, -50);設置mesh的位置
最後:scene.add(sphere);將mesh加入sence中
5對每一幀刷新
function animate()
{
requestAnimationFrame( animate );//反覆調用這個函數
render();//更新場景
update();//你要更新的其他內容
}
function render()
{
renderer.render( scene, camera );
}