Capsule은 Three.js 라이브러리의 클래스입니다. 캡슐 형태의 기하학적 구조를 정의하고, 물리적 시뮬레이션이나 충돌 검출 등의 다양한 용도로 사용할 수 있습니다.
import { Capsule } from 'three/addons/math/Capsule.js';
// 시작과 끝 점 정의
const start = new THREE.Vector3(0, 0, 0);
const end = new THREE.Vector3(0, 1, 0);
// 반지름 설정
const radius = 0.5;
// 캡슐 객체 생성
const capsule = new Capsule(start, end, radius);
// 캡슐을 씬에 추가 (물리엔진 사용 시 필요에 따라 처리)
scene.add(capsule.mesh);
import * as THREE from 'three';
import { Capsule } from 'three/addons/math/Capsule.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 캡슐 생성
const start = new THREE.Vector3(0, 0, 0);
const end = new THREE.Vector3(0, 1, 0);
const radius = 0.5;
const capsule = new Capsule(start, end, radius);
// 캡슐을 Mesh로 변환하여 씬에 추가
const capsuleGeometry = new THREE.CapsuleGeometry(radius, end.y - start.y - 2 * radius, 4, 8);
const capsuleMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const capsuleMesh = new THREE.Mesh(capsuleGeometry, capsuleMaterial);
scene.add(capsuleMesh);
const animate = function () {
requestAnimationFrame(animate);
capsuleMesh.rotation.x += 0.01;
capsuleMesh.rotation.y += 0.01;
renderer.render(scene, camera);
};
animate();
resize - Three.js (0) | 2024.11.22 |
---|---|
lookAt(), getWorldDirection() (1) | 2024.11.21 |
Octree (0) | 2024.11.21 |
WebGLRenderer(), CSS3DRenderer() (0) | 2024.11.21 |
camera.lookAt() (1) | 2024.11.21 |