Load a 3D Model
Real projects need real models. GLTFLoader handles the .glb format — the web standard for 3D assets. DRACO compression shrinks file sizes by up to 90%.
GLTFLoader
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
const draco = new DRACOLoader();
draco.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/');
const loader = new GLTFLoader();
loader.setDRACOLoader(draco);
loader.load('/models/duck.glb', (gltf) => {
scene.add(gltf.scene);
});
Loading Progress
loader.load(
url,
(gltf) => { scene.add(gltf.scene); hideLoader(); },
(xhr) => { updateProgress(xhr.loaded / xhr.total * 100); },
(error) => { console.error(error); }
);
OrbitControls
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// In animation loop:
controls.update();
What to Experiment With
- Find free glTF models at sketchfab.com (filter: downloadable, glTF)
- Traverse materials:
gltf.scene.traverse(child => { if (child.isMesh) child.material.wireframe = true }) - Set
controls.autoRotate = truefor passive viewers
실제 프로젝트에는 실제 모델이 필요합니다. GLTFLoader가 웹 표준 3D 포맷인 .glb를 처리합니다. DRACO 압축으로 파일 크기를 최대 90%까지 줄일 수 있습니다.
GLTFLoader
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
const draco = new DRACOLoader();
draco.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/');
const loader = new GLTFLoader();
loader.setDRACOLoader(draco);
loader.load('/models/duck.glb', (gltf) => {
scene.add(gltf.scene);
});
실제 프로젝트에서는 반드시 DRACOLoader를 설정하세요 — 로드 시간을 크게 단축합니다.