undefined

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

3์ฐจ์› ๊ณต๊ฐ„ ์ƒ์— ๋†“์ด๋Š” Object3D์˜ ํŒŒ์ƒ ํด๋ž˜์Šค๋Š” 3๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

  • Mesh: ์‚ผ๊ฐํ˜• ๋ฉด์œผ๋กœ ๊ตฌ์„ฑ๋œ ๊ฐ์ฒด
  • Line: ์„ ํ˜• ๊ฐ์ฒด
  • Points: ์ 

์ด 3D ์˜ค๋ธŒ์ ํŠธ๊ฐ€ 3์ฐจ์› ๊ณต๊ฐ„ ์ƒ์— ๋†“์ด๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ ๊ฐ’์„ ํ•„์š”๋กœ ํ•œ๋‹ค.

  • Position: ์œ„์น˜
  • Rotation: ํšŒ์ „
  • Scale: ํฌ๊ธฐ

์ด ๊ฐ’๋“ค์€ 4x4 ํฌ๊ธฐ์˜ ํ–‰๋ ฌ ์ •๋ณด๋กœ ๋ณ€ํ™˜๋œ๋‹ค.

๋ชฉํ‘œ

  • xyz ๊ณต๊ฐ„ ์ƒ์— ์—ฌ๋Ÿฌ 3D ๊ฐ์ฒด๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ๋ณธ๋‹ค.
  • ๊ณต๊ฐ„ ๊ตฌ์„ฑ์— Scene Graph๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • ํƒœ์–‘๊ณผ ์ง€๊ตฌ, ๋‹ฌ์˜ ์ž์ „๊ณผ ๊ณต์ „์„ ๊ตฌํ˜„ํ•œ๋‹ค.

Scene Graph๋กœ 3D ๊ณต๊ฐ„ ๊ตฌ์„ฑํ•˜๊ธฐ

scene graph๋ฅผ ์ฝ”๋“œ๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ = 3์ฐจ์› ๊ฐ์ฒด๋ฅผ ๊ณต๊ฐ„์ƒ์— ๊ตฌ์„ฑํ•œ๋‹ค๋Š” ๊ฒƒ

** ํ™”์‚ดํ‘œ๋Š” ๋ถ€๋ชจ → ์ž์‹์„ ๋œปํ•œ๋‹ค

  • ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋กœ ๊ฐ Object3D์˜ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ์„ค๊ณ„ํ•˜๊ณ  ๊ณต๊ฐ„์„ ๊ตฌ์„ฑํ•œ๋‹ค
  • Mesh๊ฐ€ Object3D ์•ˆ์— ๋ฐฐ์น˜๋œ๋‹ค.

 

PRACTICE: Scene graph๋ฅผ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ

ํƒœ์–‘ ๋งŒ๋“ค๊ธฐ

  1. solarSystem Object3D๋ฅผ ๋งŒ๋“ค๊ณ  scene์— ์ถ”๊ฐ€ํ•˜๊ธฐ
    • solarSystem์ด Scene graph์˜ ์ตœ์ƒ๋‹จ์— ์žˆ์œผ๋ฏ€๋กœ scene์— ์ถ”๊ฐ€ํ•ด ์ค€๋‹ค.
  2. const solarSystem = new THREE.Object3D(); this._scene.add(solarSystem);
  3. ๊ตฌ ํ˜•ํƒœ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์ƒ์„ฑ
  4. const sphereGeometry = new THREE.SphereGeometry(radius, widthSegments, heightSegments);
  5. ํƒœ์–‘์˜ material ์ •์˜
  6. const sunMaterial = new THREE.MeshPhongMaterial({ emissive: 0xffff00, flatShading: true, });
  7. ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ์™€ material๋กœ ํƒœ์–‘ ๋ฉ”์‰ฌ ์ƒ์„ฑ, scale ์กฐ์ •, solarSystem์— ์ถ”๊ฐ€
  8. const sunMesh = new THREE.Mesh(sphereGeometry, sunMaterial); sunMesh.scale.set(3, 3, 3); solarSystem.add(sunMesh);

 

์ง€๊ตฌ ๋งŒ๋“ค๊ธฐ

  1. earthOrbit Object3D๋ฅผ ๋งŒ๋“ค๊ณ  solarSystem์— ์ถ”๊ฐ€
    • Scene graph์—์„œ earthOrbit์€ solarSystem์˜ ์ž์‹์ด๋ฏ€๋กœ scene์ด ์•„๋‹ˆ๋ผ solarSystem์— ์ถ”๊ฐ€
    • ํƒœ์–‘์œผ๋กœ๋ถ€ํ„ฐ 10๋งŒํผ ๋–จ์–ด์ ธ ์žˆ๋„๋ก earthOrbit์˜ ์œ„์น˜๋ฅผ ์กฐ์ •ํ•œ๋‹ค.
  2. const earthOrbit = new THREE.Object3D() earthOrbit.position.x = 10 // solarSystem์œผ๋กœ๋ถ€ํ„ฐ 10๋งŒํผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ solarSystem.add(earthOrbit)
  3. ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ์ง€๊ตฌ์˜ ๋ฉ”์‰ฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  earthOrbit์— ์ถ”๊ฐ€
  4. const earthMesh = new THREE.Mesh(sphereGeometry, earthMaterial); earthOrbit.add(earthMesh);

 

๋‹ฌ ๋งŒ๋“ค๊ธฐ

  1. moonOrbit Object3D๋ฅผ ๋งŒ๋“ค๊ณ  earthOrbit์— ์ถ”๊ฐ€
    • Scene graph์—์„œ moonOrbit์€ earthOrbit์˜ ์ž์‹์ด๋ฏ€๋กœ earthOrbit์— ์ถ”๊ฐ€
    • ์ง€๊ตฌ๋กœ๋ถ€ํ„ฐ 2๋งŒํผ ๋–จ์–ด์ ธ ์žˆ๋„๋ก moonOrbit์˜ ์œ„์น˜๋ฅผ ์กฐ์ •ํ•œ๋‹ค.
  2. const moonOrbit = new THREE.Object3D(); moonOrbit.position.x = 2; // earthOrbit์—์„œ 2๋งŒํผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ earthOrbit.add(moonOrbit);
  3. ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ๋‹ฌ์˜ ๋ฉ”์‰ฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  moonOrbit์— ์ถ”๊ฐ€
  4. const moonMesh = new THREE.Mesh(sphereGeometry, moonMaterial); moonMesh.scale.set(0.5, 0.5, 0.5); moonOrbit.add(moonMesh);

 

solarSystem์„ y์ถ•์— ๋Œ€ํ•˜์—ฌ ํšŒ์ „์‹œํ‚ค๊ธฐ

render ๋ฉ”์„œ๋“œ์—์„œ ํ˜ธ์ถœํ•˜๋Š” update ๋ฉ”์†Œ๋“œ์—์„œ solarSystem์˜ rotation๊ฐ’์„ ๋ณ€๊ฒฝํ•œ๋‹ค

render(time) {
  this._renderer.render(this._scene, this._camera); // renderer๊ฐ€ scene์„ camera์˜ ์‹œ์ ์œผ๋กœ ๋ Œ๋”๋งํ•จ
  this.update(time); // ์†์„ฑ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ ๊ตฌํ˜„
  requestAnimationFrame(this.render.bind(this)); // render ๋ฉ”์†Œ๋“œ๋ฅผ ์ ๋‹นํ•œ ์‹œ์ ์—, ์ตœ๋Œ€ํ•œ ๋น ๋ฅด๊ฒŒ ๋ฐ˜๋ณต ํ˜ธ์ถœ
}

update(time) {
  time *= 0.001; // ms -> s
  this._solarSystem.rotation.y = time / 2
}
  • time์€ ๊ณ„์† ์ฆ๊ฐ€ํ•˜๋Š” ๊ฐ’์ด๋ฏ€๋กœ solarSystem์ด ๊ณ„์† ํšŒ์ „ํ•˜๊ฒŒ ๋œ๋‹ค

๊ฒฐ๊ณผ

solarSystem์„ y์ถ•์— ๋Œ€ํ•˜์—ฌ ํšŒ์ „์‹œํ‚จ ๊ฒฐ๊ณผ

์ง€๊ตฌ๋Š” ํƒœ์–‘์˜ ์ž์‹์ด๊ณ  ๋‹ฌ์€ ์ง€๊ตฌ์˜ ์ž์‹์ด๋ฏ€๋กœ ํƒœ์–‘์˜ ํšŒ์ „์— ์˜ํ–ฅ์„ ๋ฐ›๋Š”๋‹ค.

  • ํƒœ์–‘๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ง€๊ตฌ์™€ ๋‹ฌ๋„ ํƒœ์–‘์„ ์ค‘์‹ฌ์œผ๋กœ ํšŒ์ „ํ•˜๊ณ  ์žˆ๋‹ค
  • ์ง€๊ตฌ์™€ ๋‹ฌ์€ ๊ณต์ „๋งŒ ํ•  ๋ฟ ์•„์ง ์ž์ „ํ•˜๊ณ  ์žˆ์ง€๋Š” ์•Š๋‹ค

 

์ง€๊ตฌ์™€ ๋‹ฌ ์ž์ „ ์‹œํ‚ค๊ธฐ

update ๋ฉ”์„œ๋“œ์— ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค

this._earthOrbit.rotation.y = time * 2
this._moonOrbit.rotation.y = time * 5

์ตœ์ข… ๊ฒฐ๊ณผ

์ง€๊ตฌ์™€ ๋‹ฌ๋„ y์ถ•์— ๋Œ€ํ•˜์—ฌ ํšŒ์ „์‹œํ‚จ ๊ฒฐ๊ณผ

  • ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ง€๊ตฌ๋ฅผ ํšŒ์ „์‹œํ‚ค๋ฉด ์ง€๊ตฌ์˜ ์ž์‹์ธ ๋‹ฌ๋„ ์ง€๊ตฌ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ํšŒ์ „ํ•œ๋‹ค

์ •๋ฆฌ

  • Scene graph๋กœ 3์ฐจ์› ๊ฐ์ฒด ๊ณต๊ฐ„์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Scene graph๋ฅผ ์ด์šฉํ•˜๋ฉด 3์ฐจ์› ๊ฐ์ฒด๋ฅผ ์›ํ•˜๋Š” ๊ณต๊ฐ„์— ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋ณต์žกํ•œ ์ˆ˜ํ•™์  ๋ณ€ํ™˜์‹์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
  • Object3D๋Š” ๊ณต๊ฐ„ ์ƒ์— ๋†“์ด๋Š” ํ•˜๋‚˜์˜ ๊ทธ๋ฃน์ด๋ผ๊ณ  ์ดํ•ดํ–ˆ๋‹ค.

๊ฐœ๋ฐœ์ž์—๊ฒŒ ์ต์ˆ™ํ•œ ํŠธ๋ฆฌ ํ˜•ํƒœ๋กœ ๊ณต๊ฐ„์„ ๊ตฌ์„ฑํ•œ๋‹ค๋Š” ์ ์ด ํฅ๋ฏธ๋กœ์› ๋‹ค.

์”ฌ๊ทธ๋ž˜ํ”„๋Š” 3D ๊ณต๊ฐ„์— ๋Œ€ํ•œ ์„ค๊ณ„๋„์ด๋‹ค. ์”ฌ๊ทธ๋ž˜ํ”„๋ฅผ ๋”ฐ๋ผ๊ฐ€๋ฉฐ ๋ถ€๋ชจ ์ž์‹ ๊ด€๊ณ„๋ฅผ ์ฝ”๋“œ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๊ณผ์ •์ด ์žฌ๋ฏธ์žˆ์—ˆ๋‹ค.