easy-three

create.pointLight

create.pointLight(props : Object) : Light

props - 設定オブジェクト。
  • color (Hex) : ライトの色 (デフォルト : 0xffffff)。
  • intensity (Number) : 光の強さ (デフォルト : 1)。
  • distance (Number) : ライトの距離 (デフォルト : 0)。
  • decay (Number) : 光の減衰率 (デフォルト : 2)。
  • position (Array) : 位置 (デフォルト : [6, 6, 6])。
  • castShadow (Boolean) : 影を投影するかどうか (デフォルト : true)。
  • shadow (Object) : シャドウの設定 (デフォルト : {width: 1024, height: 1024})。
  • helper (Number) : ヘルパーのサイズ (デフォルト : 0)。
  • helperColor (Hex) : ヘルパーの色 (デフォルト : 0xffffff)。
点光源を作成してシーンに追加します。

コードの例

点光源

const { camera, create, animate } = init()
camera.position.set(0, 0, 2)
create.pointLight({
  position: [0, 0, 2],
});

const cube = create.cube()

animate(({ delta }) => {
  cube.rotation.x += delta;
  cube.rotation.y += delta;
});

光量を変化させる

intensity で光量を変化させることができます。

const { camera, create, animate } = init()
camera.position.set(0, 0, 2)
const pointLight = create.pointLight({
  position: [0, 0, 2],
});

const cube = create.cube()

animate(({ delta, time }) => {
  cube.rotation.x += delta;
  cube.rotation.y += delta;
  pointLight.intensity = Math.sin(time) * 1 + 1;
});

ヘルパーの利用

ヘルパーを利用することで、ライトの位置を視覚的に確認することができます。
ヘルパーのサイズは helper で指定できます。
ヘルパーの色は helperColor で指定できます。

const { camera, create, animate } = init()
camera.position.set(0, 0, 2);

const pointLight = create.pointLight({
  position: [0, 0, 1],
  helper: 0.1,
  helperColor: 0xff0000,
});

const cube = create.cube();

animate(({ delta, time }) => {
  cube.rotation.x += delta;
  cube.rotation.y += delta;
  pointLight.position.set(
    Math.sin(time),
    0,
    Math.cos(time)
  )
});