スポットライトを作成してシーンに追加します。
const { camera, create, controls, animate } = init()
controls.connect();
camera.position.set(0, 1, 1.5);
create.spotLight({
position: [-1, 1, 1],
});
create.cube({
size: 0.5,
position: [0, 0.25, 0],
})
create.plane({
position: [0, 0, 0],
rotation: [-Math.PI / 2, 0, 0],
size: [10, 10],
option: {
color: "#ffffff",
},
});
animate();
ターゲットは動的に変更できます。
3D Objectをターゲットとして指定することもできます。
const { camera, create, animate } = init()
controls.connect();
camera.position.set(0, 1, 1.5);
const red = create.spotLight({
position: [-1, 1, 1],
angle: Math.PI / 6,
color: 0xff6666,
});
const green = create.spotLight({
position: [1, 1, 1],
angle: Math.PI / 6,
color: 0x66ff66,
});
const blue = create.spotLight({
position: [0, 1, 1],
angle: Math.PI / 6,
color: 0x6666ff,
});
create.cube({
size: 0.5,
position: [0, 0.25, 0],
});
create.plane({
position: [0, 0, 0],
rotation: [-Math.PI / 2, 0, 0],
size: [10, 10],
option: {
color: "#ffffff",
},
});
animate(({ time }) => {
red.target.position.set(Math.sin(time), 0, 0);
green.target.position.set(Math.sin(-time), 0, 0);
blue.target.position.set(0, 0, Math.sin(time));
});
ヘルパーを利用することで、ライトの位置を視覚的に確認することができます。
helper に 0 より大きい値を指定すると、ヘルパーが表示されます。
ヘルパーの色は helperColor で指定できます。
const { camera, create, controls, animate } = init()
controls.connect();
camera.position.set(0, 2, 3);
create.spotLight({
position: [-1, 1, 1],
helper: 1,
helperColor: 0xff0000,
});
create.cube({
size: 0.5,
position: [0, 0.25, 0],
})
create.plane({
position: [0, 0, 0],
rotation: [-Math.PI / 2, 0, 0],
size: [10, 10],
option: {
color: "#ffffff",
},
});
animate();