import * as THREE from 'three';
// 画布尺寸
const width = window.innerWidth;
const height = window.innerHeight;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000); // 视场角度fov; 画布宽高比; 近裁截面; 远裁截面
const renderer = new THREE.WebGLRenderer();
const material = new THREE.MeshBasicMaterial({
color: 0xff0000,
transparent: true,
opacity: 0.6
}); // 材质(分为是否受光照影响)
const geometry = new THREE.BoxGeometry( 50, 90, 100 );
const mesh = new THREE.Mesh(geometry,material);
const axesHelper = new THREE.AxesHelper(150); // 坐标系
// 网格模型位置xyz坐标:0,10,0
mesh.position.set(0,10,0);
scene.add(mesh);
scene.add(axesHelper);
camera.position.set(200, 200, 200); // x,y,z
camera.lookAt(mesh.position); // 相机视角: 指向mesh设置的位置(中心点)
renderer.setSize(width, height);
renderer.render(scene, camera); // 执行渲染操作
document.body.appendChild(renderer.domElement); // 通过.domElement获得.render渲染方法生成的canvas画布