-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarLoad.js
More file actions
34 lines (26 loc) · 1.13 KB
/
starLoad.js
File metadata and controls
34 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as THREE from 'three';
export function starLoad(coords, geometry, material, radius) {
const constellationGroup = new THREE.Group();
const interactiveStars = []; // 이 별자리에 속한 별들만 담을 임시 배열
// 5. 좌표 배열을 순회하며 별 생성 및 배치
coords.forEach( coord => {
const ra = coord.ra;
const dec = coord.dec;
const x = -radius * Math.cos(dec) * Math.cos(ra);
const y = radius * Math.sin(dec);
const z = radius * Math.cos(dec) * Math.sin(ra);
// 인자로 받은 재질과 지오메트리로 별(메쉬)을 생성
const star = new THREE.Mesh( geometry, material );
// 좌표 배열에 정의된 위치에 별을 배치
star.position.set( x, y, z );
// (A) 그룹에 별을 추가
constellationGroup.add( star );
// (B) 반환할 배열에 별을 추가
interactiveStars.push( star );
} );
// 6. 완성된 '그룹'과 '별 배열'을 객체로 묶어 반환
return {
group: constellationGroup,
stars: interactiveStars
};
}