Three.js是基于原生WebGL(Javascript的3D图形接口,把JavaScript和OpenGL ES 2.0结合在一起。)封装运行的三维引擎
三要素是:场景(Scene)、相机(Camera)、渲染器(Renderer),下面通过三要素在浏览器中创建几何体并显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import * as THREE from "three"
const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) camera.position.set(0,0,10) scene.add(camera) const cubeGeometry = new THREE.BoxGeometry() const cubeMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 })
const cube = new THREE.Mesh(cubeGeometry,cubeMaterial)
scene.add(cube)
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
renderer.render(scene,camera)
|
threejs开源项目目录结构
…后续补坑
References
https://juejin.cn/post/7020396322062598181