🌐 Web Development

Three.js

Three.js

A JavaScript library that renders 3D graphics on the web. A WebGL abstraction.

📖 Detailed Explanation

Three.js is a JavaScript library that makes it easy to implement 3D graphics in web browsers. By abstracting the WebGL API, it lets you work intuitively with 3D scenes, cameras, lights, materials, meshes, and more without complex low-level code.

Since Ricardo Cabello (Mr.doob) first released it in 2010, Three.js has become the de facto standard for web 3D graphics. It hides the complexity of WebGL while providing powerful features, and is used in a wide range of fields such as games, visualization, interactive art, and product demos.

The core components of Three.js are the Scene, the Camera, and the Renderer. You place 3D objects in the Scene, set the viewpoint with the Camera, and the Renderer draws the final image on the screen. Animation is implemented with a render loop that uses requestAnimationFrame.

In practice, Three.js is essential for product 3D viewers, data visualization, virtual exhibition halls, WebXR content, and more. When used together with a React integration library such as React Three Fiber, you can build 3D scenes in a component-based way, which greatly improves maintainability.

💻 Code Example

// Three.js 기본 장면 설정
import * as THREE from 'three';

// 1. Scene 생성
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1a1a2e);

// 2. Camera 설정 (시야각, 종횡비, near, far)
const camera = new THREE.PerspectiveCamera(
    75, window.innerWidth / window.innerHeight, 0.1, 1000
);
camera.position.z = 5;

// 3. Renderer 생성
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// 4. 3D 객체 생성 (지오메트리 + 재질 = 메시)
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
    color: 0x6366f1,
    metalness: 0.3,
    roughness: 0.4
});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

// 5. 조명 추가
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(5, 5, 5);
scene.add(light);
scene.add(new THREE.AmbientLight(0x404040));

// 6. 애니메이션 루프
function animate() {
    requestAnimationFrame(animate);
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.01;
    renderer.render(scene, camera);
}
animate();

🗣️ Say It Like This in Practice

💬 In a Planning Meeting
"If we add a 3D viewer to the product page, customers can rotate the product 360 degrees. If we build it with Three.js, they can experience it right in the browser without installing an app. I think you can just get the 3D model in glTF format."
💬 In an Interview
"Three.js is a library that abstracts WebGL and uses the Scene-Camera-Renderer pattern. For performance optimization, I used geometry instancing, LOD, and frustum culling, and I also have experience with declarative 3D development using React Three Fiber."
💬 In a code review
"In this part, a new geometry is being created every frame. If you don't call dispose(), a GPU memory leak will occur. Please either reuse the geometry and material, or be sure to dispose of them after use."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Leaving Memory Leaks Unaddressed

If you don't call dispose() on Geometry, Material, and Texture after using them, GPU memory keeps accumulating. This is especially essential when objects are dynamically created and deleted.

❌
Creating Objects in the Render Loop

If you call new Vector3() or new Color() inside the animate() function, garbage is generated every frame. Declare them in advance outside the loop and reuse them.

✅
The right way

Use BufferGeometry, texture compression (basis/ktx2), LOD, and OrbitControls' enableDamping to implement smooth interaction.

🔗 Related Terms

📚 Learn More