import storage from '../utils/storage'

export default {
  methods: {
    async initScene() {
      // const scene = app.loadBundle('/scene-bundle')
      // await scene.waitForComplete()
      const scene = app.loadBundle('/scene', {
        ignoreTheme: true,
      })
      await scene.waitForComplete().then(() => {
        app.levelManager.change(app.query('.Campus')[0])
      })
      // 模拟 editor 增加 app.defaultSceneInfo 用于关闭信息面板时归位
      const defaultSceneInfo = {
        position: THING.Utils.cloneObject(app.camera.position),
        target: THING.Utils.cloneObject(app.camera.target),
      }
      const localSceneInfo = storage.getItem('defaultSceneInfo')
      if (localSceneInfo) {
        app.defaultSceneInfo = JSON.parse(localSceneInfo)
      } else {
        app.defaultSceneInfo = defaultSceneInfo
      }

      app.camera.position = app.defaultSceneInfo.position
      app.camera.target = app.defaultSceneInfo.target

      if (this.loadLocalPrefabData) {
        await this.loadLocalPrefabData()
      }

      // 延迟 1.5s 等预制件创建完
      // setTimeout(() => {
      //   this.$UinoSpin.hide({ type: 'imageLoad' })
      // }, 1500)
    },

    destroyPrefabObjects() {
      app.query('.PrefabObject').destroy()
    },
  },
  mounted() {
    // this.$UinoSpin.show({ type: 'imageLoad' })
    window.app = new THING.App({
      isEditor: false,
    })
    window.rootObject = new THING.BaseObject3D()
  },
}
