import storage from '@/utils/storage'
export default {
  data() {
    return {
      appInited: false,
    }
  },
  methods: {
    async initScene() {
      const scene = app.loadBundle('/scene-bundle')
      await scene.waitForComplete()
      // 模拟 editor 增加 app.defaultSceneInfo 用于关闭信息面板时归位
      const defaultSceneInfo = storage.getItem('defaultSceneInfo')
      if (defaultSceneInfo) {
        app.camera.position = defaultSceneInfo.position
        app.camera.target = defaultSceneInfo.target
      }

      const loginName = '@ThingJS (T3D) by UINO INC'

      // 登录名(暂时不用)
      THING['auth_login_name'] =
        typeof loginName !== 'undefined' ? loginName : ''
      // 授权地址
      // THING['auth_url_key'] = 'http://127.0.0.1:5501/tool/auth.json';
      // WASM 文件路径
      THING['auth_wasm_root_path'] = `/wasm/`

      if (this.loadLocalPrefabData) {
        //await THING.Utils.waitForAuth().then(() => {
        return this.loadLocalPrefabData()
        //})
      }
    },
    destroyPrefabObjects() {
      app.query('.PrefabObject').destroy()
    },
  },
  mounted() {
    window.app = new THING.App({
      isEditor: this.$route.meta?.isEditor,
    })
    window.rootObject = new THING.BaseObject3D()
    window.otherRootObject = new THING.BaseObject3D() // 用于修改属性面板，预制件所见即所得
    window.importer = new THING.SceneLoader()

    this.appInited = true
  },
}
