<script type="text/javascript"> functioninit(){ //渲染器 var renderer = new THREE.WebGLRenderer({ canvas:document.getElementById('mainCanvas') }); renderer.setClearColor(0x000000); //场景 var scene = new THREE.Scene(); //照相机 var camera = new THREE.OrthographicCamera(-2, 2, 1.5, -1.5, 1, 10); camera.position.set(4, -3, 5); camera.lookAt(new THREE.Vector3(0, 0, 0)); scene.add(camera); //创建边长为1的红色正方体,wireframe(线框)材质,以便看到正方体后方的边 var cube = new THREE.Mesh(new THREE.CubeGeometry(1,1,1), new THREE.MeshBasicMaterial({ color:0xff0000, wireframe:true }) ); scene.add(cube); //渲染 renderer.render(scene,camera); } </script>
6.透视投影照相机(Perspective Camera)
THREE.PerspectiveCamera(fov, aspect, near, far)
fov — 相机视锥体竖直方向上的张角(是角度制而非弧度制) aspect — 相机视锥体宽高比width / height,通常设为Canvas 的横纵比例 near — 相机视锥体近裁剪面 far — 相机视锥体远裁剪面
<script type="text/javascript"> functioninit(){ //渲染器 var renderer = new THREE.WebGLRenderer({ canvas:document.getElementById('mainCanvas') }); renderer.setClearColor(0x000000); //场景 var scene = new THREE.Scene(); //照相机 var camera = new THREE.PerspectiveCamera(60, 400 / 300, 1, 10); camera.position.set(0, 0, 5); scene.add(camera); //创建边长为1的红色正方体,wireframe(线框)材质,以便看到正方体后方的边 var cube = new THREE.Mesh(new THREE.CubeGeometry(1,1,1), new THREE.MeshBasicMaterial({ color:0xff0000, wireframe:true }) ); scene.add(cube); //渲染 renderer.render(scene,camera); } </script>