정점(vertices)와 면으로 이루어진 요소들
particles은 vertices의 꼭지점을 의미한다.
translate()
, rotateX()
, normalize()
와 같은 메서드를 사용할 수 있다. 이 메서드는 mesh가 아닌 vertices에 적용되는 것이다.
순서대로 여섯가지 파라미터를 갖는다.
먼저 가로, 세로, 높이의 길이.
1. width — 길이(X axis) Optional; defaults to 1.
2. height — 높이(Y axis) Optional; defaults to 1.
3. depth — 깊이(Z axis) Optional; defaults to 1.
그리고 각 면이 몇 개의 세그먼트로 나뉘는지를 보여준다.
4. widthSegments — Optional; defaults to 1.
5. heightSegments — Optional; defaults to 1.
6. depthSegments — Optional; defaults to 1.
/*
* 6개의 파라미터를 가진다.
* 가로, 세로, 높이의 길이
* 그리고 각 면이 몇 개의 세그먼트로 이루어질지다.
*/
const geometry = new THREE.BoxGeometry(1, 1, 1, 1, 2, 3)
const material = new THREE.MeshBasicMaterial({ color: 0xff0000, wireframe: true })
const mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)
Float32Array를 만드는 두가지 방법이 있다.
const positionArray = new Float32Array(9)
positionArray[0] = 0
positionArray[1] = 0
positionArray[2] = 0
positionArray[3] = 0
positionArray[4] = 1
positionArray[5] = 0
positionArray[6] = 1
positionArray[7] = 0
positionArray[8] = 0
각각 x, y, z 가 위치하는 정점을 의미한다.
const positionArray = new Float32Array([
0, 0, 0, // 1
0, 1, 0, // 2
1, 0, 0, // 3
])
const geometry = new THREE.BufferGeometry()
/* parameter - array: THREE.TypedArray, itemSize: number, normalized?: boolean */
const positionAttribute = new THREE.BufferAttribute(positionArray, 3)
geometry.setAttribute('position', positionAttribute)
여러 개의 삼각형 도형을 랜덤하게 생성해보자.
// Scene
const scene = new THREE.Scene()
const geometry = new THREE.BufferGeometry()
const count = 5000
const positionsArray = new Float32Array(count * 3 * 3) // 삼각형은 3개의 정점과 각 정점은 3개의 좌표를 가지므로 3을 곱해준다.
for (let i = 0; i < count * 3 * 3; i++) {
positionsArray[i] = (Math.random() - 0.5) * 4
}
const positionAttribute = new THREE.BufferAttribute(positionsArray, 3) // 3개의 좌표를 가진 버퍼 어트리뷰트를 생성한다.
geometry.setAttribute('position', positionAttribute)