import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'

// 加载器
export const modelLoader = (url) => {

  const dracoloader = new DRACOLoader()
  dracoloader.setDecoderPath('/draco/')

  const loader = new GLTFLoader()
  loader.setDRACOLoader(dracoloader)

  return new Promise(resolve => {
    loader.load(url, e => {
      resolve(e)
    }, undefined, err => {
      resolve(false)
    })
  })

}

export const carFormate = (xcar) => {

  const {
    carId, carMilestone, carPlate, collectionTime,
    isFocusMark, roadNo, speed, vehicleType, isDangerous, originDistance
  } = xcar

  return {
    id: carId,
    plate: carPlate,
    time: collectionTime,
    milestone: carMilestone,
    lanex: roadNo,
    speed,
    type: vehicleType,
    focused: isFocusMark,
    danger: isDangerous,
    distance: originDistance
  }

}

export const cameraFormate = (xcamera) => {

  const {
    id, cameraIndexCode, pileNumber, progress, section
  } = xcamera

  return {
    id, 
    progress,
    pileNumber,
    section,
    cameraIndexCode
  }

}
