Product Viewer
Product viewers let users inspect a 3D object interactively. The key patterns: constrained drag-to-rotate, variant color swaps, and smooth transitions.
Constrained Orbit
Limit OrbitControls to prevent disorientation:
controls.minPolarAngle = Math.PI / 4;
controls.maxPolarAngle = (3 * Math.PI) / 4;
controls.minDistance = 2;
controls.maxDistance = 8;
controls.enablePan = false;
Variant Color Swap
const variants = {
black: { color: 0x111111, metalness: 0.8, roughness: 0.2 },
silver: { color: 0xcccccc, metalness: 0.9, roughness: 0.1 },
gold: { color: 0xd4a853, metalness: 0.9, roughness: 0.15 },
};
function applyVariant(name) {
const v = variants[name];
mesh.material.color.set(v.color);
mesh.material.metalness = v.metalness;
mesh.material.roughness = v.roughness;
}
Smooth Camera Reset
function resetCamera() {
gsap.to(camera.position, {
x: 0, y: 0, z: 4,
duration: 1,
ease: 'power2.inOut',
onUpdate: () => controls.update()
});
}
What to Experiment With
- Add annotations: raycasting click → tooltip with product info
controls.autoRotate = truewhen idle, stop on pointerdowngsap.to(material, { metalness: 1 })for animated material transitions
제품 뷰어는 사용자가 3D 오브젝트를 인터랙티브하게 검사할 수 있게 합니다. 핵심 패턴: 제한된 드래그-회전, 변형 색상 스왑, 부드러운 전환입니다.
제한된 오빗
방향 감각 상실을 방지하기 위해 OrbitControls를 제한합니다:
controls.minPolarAngle = Math.PI / 4;
controls.maxPolarAngle = (3 * Math.PI) / 4;
controls.minDistance = 2;
controls.maxDistance = 8;
controls.enablePan = false;
변형 색상 스왑
const variants = {
black: { color: 0x111111, metalness: 0.8, roughness: 0.2 },
silver: { color: 0xcccccc, metalness: 0.9, roughness: 0.1 },
gold: { color: 0xd4a853, metalness: 0.9, roughness: 0.15 },
};
function applyVariant(name) {
const v = variants[name];
mesh.material.color.set(v.color);
mesh.material.metalness = v.metalness;
mesh.material.roughness = v.roughness;
}
부드러운 카메라 리셋
function resetCamera() {
gsap.to(camera.position, {
x: 0, y: 0, z: 4,
duration: 1,
ease: 'power2.inOut',
onUpdate: () => controls.update()
});
}
실험해보기
- 레이캐스팅 클릭 → 제품 정보 툴팁 어노테이션 추가
- 유휴 시
controls.autoRotate = true, pointerdown에서 정지 gsap.to(material, { metalness: 1 })로 재질 전환 애니메이션