3.j 但优化用于 伤亡情况
JavaScript 三维库
该项目的目的是创建一个方便使用,轻量级,跨浏览器,通用的3D库. 电流构造只包含一个WebGL渲染器,但WebGPU(实验),SVG和CSS3D渲染器也作为外加子提供.
实例 —— 说 文档 —— 说 手动 —— 说 维基 —— 说 移动 —— 说 问 题 —— 说 论坛 —— 说 解析器
使用量
这个代码创造了一个场景,相机,和一个几何立方体,它将立方体添加到场景中. 然后它就创造了一个 WebGL 场景和相机的渲染器,它把取景口加到 document.body 键。 最后,它为相机动画了场景内的立方体.
import * as THREE from 'three';
const width = window.innerWidth, height = window.innerHeight;
// init
const camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );
camera.position.z = 1;
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( width, height );
renderer.setAnimationLoop( animation );
document.body.appendChild( renderer.domElement );
// animation
function animation( time ) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render( scene, camera );
}
如果一切顺利,你应该看看 这个。 。 。 .
复制此寄存器
以所有历史来克隆回波导致~2GB下载. 如果你不需要整个历史,你可以使用 depth 参数可以显著地减少下载大小.
git clone --depth=1 https://github.com/mrdoob/three.js.git