Three.js: Difference between revisions

Content deleted Content added
removed false details
Removed example code as per WP:CODE and added stub tag
Line 54:
 
Three.js is made available under the [[MIT License]].<ref name="license" />
 
== Usage ==
The following code creates a scene and adds a camera and cube to the scene. Next, it creates a WebGL renderer and appends its viewport to the body of the [[webpage]] document. Once Three.js has finished loading, the cube rotates about its x and y axes.
 
<syntaxhighlight lang="javascript">
import * as THREE from 'three';
 
// init
 
const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 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( window.innerWidth, window.innerHeight );
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 );
 
}
</syntaxhighlight>
 
== See also ==
Line 124 ⟶ 88:
[[Category:Software using the MIT license]]
[[Category:WebGL]]
{{compu-prog-stub}}