three.js

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

Github星跟蹤圖

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

变更记录

发布

概覽

名稱與所有者mrdoob/three.js
主編程語言JavaScript
編程語言JavaScript (語言數: 5)
平台Linux, Mac, Web browsers, Windows
許可證MIT License
發布數157
最新版本名稱r165 (發布於 2024-05-31 20:02:20)
第一版名稱r1 (發布於 )
創建於2010-03-23 18:58:01
推送於2024-06-10 19:42:17
最后一次提交2024-05-31 20:01:18
星數99.8k
關注者數2.5k
派生數35.2k
提交數43.5k
已啟用問題?
問題數12338
打開的問題數369
拉請求數12444
打開的拉請求數129
關閉的拉請求數3495
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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

去到頂部