easy-three

create.sphere

create.sphere(props : Object) : Mesh

props - 設定オブジェクト。
  • size (Number) : 半径 (デフォルト : 1)。
  • segments (Array | Number) : セグメント (デフォルト : 64)。
  • 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)。

球体を作成してシーンに追加します。

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

コードの例

球の作成

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

create.sphere()

animate()

アニメーション

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

const sphere = create.sphere()

animate(({ time }) => {
  sphere.position.x = Math.sin(time)
})

オプションの変更

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

create.sphere({
  size: 0.5,
  position: [-1, 0, 0],
  material: "Normal",
});

create.sphere({
  size: 0.7,
  position: [1, 0, 0],
  option: {
    // material settings
    color: 0x00ff00,
    metalness: 0.6,
    roughness: 0,
    transparent: true,
    opacity: 0.5,
  },
});

const sphere3 = create.sphere({
  size: 1.5,
  position: [0, 0, -3],
});

animate(({ time }) => {
  sphere3.position.y = Math.sin(time) * 2;
});