three.js README

The project's README from github.com/mrdoob/three.js. As one markdown file: README.md.

three.js

NPM Package Build Size NPM Downloads jsDelivr Downloads Discord

JavaScript 3D library

The aim of the project is to create an easy-to-use, lightweight, cross-browser, general-purpose 3D library. The current builds only include WebGL and WebGPU renderers but SVG and CSS3D renderers are also available as addons.

Examples — Docs — Manual — Wiki — Migrating — Questions — Forum — Discord

Usage

This code creates a scene, a camera, and a geometric cube, and it adds the cube to the scene. It then creates a WebGL renderer for the scene and camera, and it adds that viewport to the document.body element. Finally, it animates the cube within the scene for the camera.

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( animate );
document.body.appendChild( renderer.domElement );

// animation

function animate( time ) {

	mesh.rotation.x = time / 2000;
	mesh.rotation.y = time / 1000;

	renderer.render( scene, camera );

}

If everything goes well, you should see this.

Cloning this repository

Cloning the repo with all its history results in a ~2 GB download. If you don't need the whole history you can use the depth parameter to significantly reduce download size.

git clone --depth=1 https://github.com/mrdoob/three.js.git

Change log

Releases

three.js (mrdoob/three.js)

Searching Database…

116.6K ·GitHub
这是什么东西?它是一个面向浏览器的 JavaScript 3D 库:项目追求易用、轻量、跨浏览器、通用。2010 年就出现了,目前在 GitHub 上已有超过 116,000 颗星。
它是一个现成的应用,还是要在我自己的代码里使用的东西?是一个引入到你自己的 JavaScript 代码里的库,不是独立应用。主要的构建版本自带 WebGL 和 WebGPU 渲染器;SVG 和 CSS3D 渲染器则以插件(addon)形式提供。
最小可运行的示例是什么样的?README 的 Usage 部分就是配方:创建一个场景,加一个相机和一个立方体,把渲染器的视口挂到页面上,然后在循环里让立方体动起来。
安装它的时候会连带装其他依赖包吗?不会。这个包没有任何运行时依赖;你只需要一个支持 WebGL 的浏览器就能渲染内容。
如果我把仓库克隆下来随便看看,有什么坑吗?只有体积问题:带完整历史克隆要下载约 2 GB,所以建议加上 depth 参数来缩减体积。
它能做 VR 和 AR 吗,还是只能做普通 3D?可以——WebXR、虚拟现实和增强现实都在这个项目的 GitHub 话题标签里,所以沉浸式浏览器内容也在它的范围内,和普通 3D 渲染一样支持。
Creator
mrdoob
Size
1.6 GB
Stars
116.6K
Age
16y
Commits · 90 Days