任意の形のシェイプを作成してシーンに追加します。
直線を用いる場合、shapes には position として 2要素 (x, y) の配列をもつオブジェクトの配列を指定します。
create.shape({
shapes: [
{ position: [0, 0] },
{ position: [1, 0] },
{ position: [1, 1] },
{ position: [0, 1] }
]
})ベジエ曲線を用いる場合、shapes には position として 6要素 (cp1X, cp1Y, cp2X, cp2Y, x, y) の配列をもつオブジェクトの配列を指定し、 type に "curve" を指定します。
この場合、cp1 は制御点1(始点側の制御点)、cp2 は制御点2(終点側の制御点)、x, y は終点を表します。
create.shape({
shapes: [
{ position: [0, 0] },
{ position: [0.2, 0.3, 0.8, 0.3, 1, 0], type: "curve" },
{ position: [0.7, 0.2, 0.7, 0.8, 1, 1], type: "curve" },
{ position: [0.8, 0.7, 0.2, 0.7, 0, 1], type: "curve" },
{ position: [0.3, 0.8, 0.3, 0.2, 0, 0], type: "curve" }
]
})const { camera, create, animate, THREE, Default } = init()
camera.position.set(0, 0, 2)
create.ambientLight()
create.directionalLight()
const shape = create.shape({
shapes: [
{ position: [0, 0] },
{ position: [1, 0] },
{ position: [1, 1] },
{ position: [0, 1] }
],
option: {
color: Default.color,
side: THREE.DoubleSide
}
});
animate(({ delta }) => {
shape.rotation.x += delta;
shape.rotation.y += delta;
});
const { camera, create, animate, THREE, Default } = init()
camera.position.set(0, 0, 2)
create.ambientLight()
create.directionalLight()
const shape = create.shape({
shapes: [
{ position: [0, 0] },
{ position: [0.2, 0.3, 0.8, 0.3, 1, 0], type: "curve" },
{ position: [0.7, 0.2, 0.7, 0.8, 1, 1], type: "curve" },
{ position: [0.8, 0.7, 0.2, 0.7, 0, 1], type: "curve" },
{ position: [0.3, 0.8, 0.3, 0.2, 0, 0], type: "curve" }
],
option: {
color: Default.color,
side: THREE.DoubleSide,
},
});
animate(({ delta }) => {
shape.rotation.x += delta;
shape.rotation.y += delta;
})