import { cameraFormate, create2DModel } from '../utils'


export default class Camera {

  camera
  direct = null // 隧道编码
  curves = null // 隧道引导线
  infos = null // 摄像机基础信息
  lanex // 挂载车道

  player2d = null
  vm_instance = null // vue 实例

  constructor (context, configs) {
    
    this.camera = configs.model.scene.clone()

    this.direct = configs.infos.direct
    this.curve = configs.curve
    this.infos = cameraFormate(configs.infos)
    this.setPoint()

    this.camera.userData = {
      type: 'glb-camera',
      infos: this.infos
    }

    context.scene.add(this.camera)

  }

  setPoint () {

    const position = this.curve.getPointAt(this.infos.progress)
    this.camera.scale.set(0.12, 0.12, 0.12)
    position.y += 2
    
    this.camera.position.copy(position)
    if (this.direct === 1) {
      position.x += 1
      this.camera.rotation.y = Math.PI
    } else {
      position.x -= 1
    }

  }





}