three.js

JavaScript 3D库。(JavaScript 3D library.)

Github stars Tracking Chart

three.js

JavaScript 3D库

这个项目的目的是用默认的 WebGL 渲染器创建一个易用的、轻量级的 3D 库。在示例中,该库还提供了 Canvas 2D、SVG 和 CSS3D 渲染器。

范例文档Wiki迁移问题论坛SlackDiscord

用法

这段代码创建了一个场景、一个摄像机和一个几何立方体,并将立方体添加到场景中。然后它为场景和摄像机创建一个WebGL渲染器,并将该视口添加到文档中。body元素。最后,它为摄像机在场景中创建立方体动画。

import * as THREE from 'js/three.module.js';
var camera, scene, renderer;
var geometry, material, mesh;
init();
animate();
function init() {
    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
    camera.position.z = 1;
    scene = new THREE.Scene();
    geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
    material = new THREE.MeshNormalMaterial();
    mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize( window.innerWidth, window.innerHeight );
    document.body.appendChild( renderer.domElement );
}
function animate() {
    requestAnimationFrame( animate );
    mesh.rotation.x += 0.01;
    mesh.rotation.y += 0.02;
    renderer.render( scene, camera );
}

如果一切顺利,您应该会看到这个

克隆此存储库

克隆存储库及其所有历史记录将导致大约 2GB 的下载量。 如果您不需要整个历史记录,则可以使用 depth 参数来显着减小下载大小。

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

变更记录

发布

Main metrics

Overview
Name With Ownermrdoob/three.js
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 5)
PlatformLinux, Mac, Web browsers, Windows
License:MIT License
所有者活动
Created At2010-03-23 18:58:01
Pushed At2025-04-21 08:03:19
Last Commit At2025-03-28 14:44:13
Release Count167
Last Release Namer175 (Posted on 2025-03-28 15:05:58)
First Release Namer1 (Posted on )
用户参与
Stargazers Count105.8k
Watchers Count2.5k
Fork Count35.7k
Commits Count45.2k
Has Issues Enabled
Issues Count12959
Issue Open Count415
Pull Requests Count13943
Pull Requests Open Count137
Pull Requests Close Count3714
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

three.js

NPM package
Build Size
Build Status
Dependencies
Dev Dependencies
Language Grade

JavaScript 3D library

The aim of the project is to create an easy to use, lightweight, 3D library with a default WebGL renderer. The library also provides Canvas 2D, SVG and CSS3D renderers in the examples.

Examples
Documentation
Wiki
Migrating
Questions
Forum
Gitter
Slack

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 'js/three.module.js';

var camera, scene, renderer;
var geometry, material, mesh;

init();
animate();

function init() {

	camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
	camera.position.z = 1;

	scene = new THREE.Scene();

	geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
	material = new THREE.MeshNormalMaterial();

	mesh = new THREE.Mesh( geometry, material );
	scene.add( mesh );

	renderer = new THREE.WebGLRenderer( { antialias: true } );
	renderer.setSize( window.innerWidth, window.innerHeight );
	document.body.appendChild( renderer.domElement );

}

function animate() {

	requestAnimationFrame( animate );

	mesh.rotation.x += 0.01;
	mesh.rotation.y += 0.02;

	renderer.render( scene, camera );

}

If everything went well you should see this.

Change log

Releases