import * as THREE from 'three'

/**
 * @param {Array<Array<number>>} outer - 外环 [[lng,lat], ...]
 * @param {Array<Array<Array<number>>>} holes - 内环数组，可选
 * @returns {THREE.Mesh}
 */
export default function createMesh (outer, holes = []) {
  const outerV2 = outer.map(p => new THREE.Vector2(p[0], p[1]))
  const shape   = new THREE.Shape(outerV2)

  holes.forEach(hole => {
    const holeV2 = hole.map(p => new THREE.Vector2(p[0], p[1]))
    shape.holes.push(new THREE.Path(holeV2))
  })

  const geometry = new THREE.ShapeGeometry(shape)   // r154+ 使用 ShapeGeometry
  const material = new THREE.MeshBasicMaterial({
    color: 0x004444,
    side: THREE.DoubleSide
  })
  return new THREE.Mesh(geometry, material)
}
