1. Home
  2. /
  3. Threejs-animation
  4. /
  5. Simple Rotating Cube

Simple Rotating Cube - Threejs-animation Typing CST Test

Loading…

Simple Rotating Cube — Threejs-animation Code

A basic Three.js example animating a rotating cube.

# threejs/demo/RotatingCube.html
<html>
  <head>
	<script src="https://cdn.jsdelivr.net/npm/three@0.150.1/build/three.min.js"></script>
  </head>
  <body>
	<script>
		const scene = new THREE.Scene()
		const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000)
		const renderer = new THREE.WebGLRenderer()
		renderer.setSize(window.innerWidth, window.innerHeight)
		document.body.appendChild(renderer.domElement)

		const geometry = new THREE.BoxGeometry()
		const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
		const cube = new THREE.Mesh(geometry, material)
		scene.add(cube)

		camera.position.z = 5

		function animate() {
		requestAnimationFrame(animate)
		cube.rotation.x += 0.01
		cube.rotation.y += 0.01
		renderer.render(scene, camera)
		}
		animate()
	</script>
  </body>
</html>

Threejs-animation Language Guide

Three.js Animation System is a powerful, flexible framework for keyframe-based animations of 3D objects, cameras, materials, and morph targets. It uses AnimationMixer, AnimationClips, and KeyframeTracks to animate properties over time with smooth interpolation and precise timeline control.

Primary Use Cases

  • ▸Object and camera animations
  • ▸GLTF character and skeletal animations
  • ▸Morph target and facial animations
  • ▸Scene transitions and cinematic sequences
  • ▸3D product demos and interactive experiences

Notable Features

  • ▸AnimationMixer for global control
  • ▸AnimationClip for reusable timelines
  • ▸KeyframeTrack system
  • ▸Interpolation modes (linear, cubic, quaternion)
  • ▸Blendable and cross-fade animations

Origin & Creator

Three.js Animation System was introduced and evolved by the Three.js open-source community led by Ricardo Cabello (mrdoob). It matured significantly between 2014-2020 with GLTF-centric animation workflows.

Industrial Note

Three.js Animation is heavily used in web-based product configurators, architectural walkthroughs, scientific simulations, cinematic scenes, NFT 3D viewers, interactive landing pages, and real-time motion graphics.

More Threejs-animation Typing Exercises

Bouncing SphereRotating TorusColor Changing CubeMultiple Spinning CubesRotating ConePulsing SphereOrbiting Cube

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher