easy-three

create.plane

create.plane(props : Object) : Mesh

props - 設定オブジェクト。
  • size (Array | Number) : サイズ (デフォルト : 1)。
  • position (Array) : 位置 (デフォルト : [0, 0, 0])。
  • rotation (Array) : 回転 (デフォルト : [0, 0, 0])。
  • option (Object) : オプション (デフォルト : {color: Default.color })。
  • material (String | Material | Material[]) : マテリアルタイプ、またはマテリアルオブジェクト、またはマテリアルオブジェクトの配列 (デフォルト :Default.material)。
  • castShadow (Boolean) : 別のオブジェクトに影を落とすかどうか (デフォルト : true)。
  • receiveShadow (Boolean) : 別のオブジェクトからの影を受けるかどうか (デフォルト : true)。
  • doubleSide (Boolean) : 両面表示にするか? (デフォルト : false)。
  • upsideDown (Boolean) : 裏面表示にするか? (デフォルト : false)。
  • autoAdd (Boolean) : 自動でシーンに追加 (デフォルト : true)。

平面を作成してシーンに追加します。

size については、通常2つの値を持つ配列で指定します。
配列でなく1つの数値を指定した場合、その値を2つ持つ配列として扱います。
(例 : size: 2 は [2, 2] と同じ)

option.material には、マテリアルの種類を文字列で指定します。
マテリアルの種類については、Three.js で定義されているものから 「THREE.」と「Mesh」を除いたものになります。
(例 : "Physical" は THREE.MeshPhysicalMaterial を意味します。)
例外として、THREE.NormalMaterial は "Normal" として指定します。

平面には表裏があり、裏面はデフォルトで描画されません。
裏面も描画する場合は、option に side: THREE.DoubleSide を指定します (init メソッドから THREE を取得できます)。
具体例は下記の「アニメーション」のコードを参照してください。

コードの例

平面の作成

const { camera, create, animate } = init()
camera.position.set(0, 1, 1)
create.ambientLight()
create.directionalLight()

create.plane()

animate()

アニメーション

const { camera, create, animate, THREE, Default } = init()
camera.position.set(0, 0, 2)
create.ambientLight()
create.directionalLight()

const plane = create.plane({
  option: {
    side: THREE.DoubleSide,
    color: Default.color,
  }
})

animate(({ delta }) => {
  plane.rotation.x += delta
})

オプションの変更

const { camera, create, animate, THREE, Default } = init()
camera.position.set(0, 0, 4);
create.ambientLight();
create.directionalLight();

const plane1 = create.plane({
  size: 1,
  position: [-1, 0, 0],
  material: "Normal",
  option: {
    side: THREE.DoubleSide,
  },
});

const plane2 = create.plane({
  size: 1.5,
  position: [1, 0, 0],
  option: {
    // material settings
    color: 0x00ff00,
    metalness: 0.6,
    roughness: 0,
    transparent: true,
    opacity: 0.5,
    side: THREE.DoubleSide,
  },
});

const plane3 = create.plane({
  size: 3,
  position: [0, 0, -3],
  option: {
    side: THREE.DoubleSide,
    color: Default.color,
  },
});

animate(({ time, delta }) => {
  plane1.rotation.x += delta;
  plane2.rotation.y += delta;
  plane3.rotation.x += delta;
  plane3.rotation.z += delta;
  plane3.position.y = Math.sin(time) * 2;
});