index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import '@sdk/modules/core/Scene'
  2. import '@sdk/internal/Store'
  3. import '@sdk/internal/Resource'
  4. import * as PetiteVue from '@sdk/template'
  5. import { setup as setupSDK } from '@sdk/modules/sdk'
  6. import { setup as setupFetch } from '@sdk/utils/request'
  7. import KanKan from '@sdk/internal/core'
  8. import { usePlugin } from '@sdk/utils/scripts'
  9. import { Emiter } from '@sdk/utils/Emiter'
  10. import Deferred from '@sdk/utils/Deferred'
  11. import transitions from '@sdk/utils/transitions'
  12. import easing from '@sdk/utils/easing'
  13. import lerp from '@sdk/utils/lerp'
  14. import MathLight from '@sdk/utils/MathLight'
  15. import convert from '@sdk/utils/convert'
  16. import math from '@sdk/utils/math'
  17. import * as editApis from '@sdk/apis/scene-edit.js'
  18. import * as viewApis from '@sdk/apis/scene-view.js'
  19. import Viewmode from '@sdk/modules/core/enum/Viewmode'
  20. export default class extends KanKan {
  21. static MITT = { Emiter }
  22. static Utils = { math, convert, MathLight }
  23. static Animate = { transitions, easing, lerp }
  24. static Viewmode = Viewmode
  25. static THREE = THREE
  26. static Deferred = Deferred
  27. constructor(options) {
  28. super(options)
  29. this.withComponent('store')
  30. this.withComponent('resource')
  31. this.withComponent('Scene')
  32. if (this.config.dom) {
  33. this.withDom()
  34. }
  35. this.remote_editor = editApis
  36. this.remote_viewer = viewApis
  37. setupSDK(this)
  38. setupFetch(this)
  39. if (this.config.useStatistics) {
  40. window._hmt = window._hmt || []
  41. ;(function () {
  42. var hm = document.createElement('script')
  43. hm.src = 'https://hm.baidu.com/hm.js?aa59943d9a481ab824cf054f2d463ca2'
  44. var s = document.getElementsByTagName('script')[0]
  45. s.parentNode.insertBefore(hm, s)
  46. })()
  47. }
  48. // const medici = Medici.init({
  49. // platform: 'web',
  50. // appId: '7b5958d5-1ae6-4ad5-8a87-5fc8a4b92999',
  51. // // endPoint: 'https://v4-test.4dkankan.com', //服务器
  52. // endPoint: '/track_api', //服务器
  53. // config: {
  54. // version: '1', //配置要track当前版本
  55. // },
  56. // })
  57. // KanKan.medici = medici
  58. }
  59. use(plugin, config) {
  60. if (typeof plugin === 'string') {
  61. if (this.Plugins[plugin]) {
  62. return Promise.resolve(this.Plugins[plugin])
  63. }
  64. return usePlugin(plugin, this.config.version + '-' + Date.now()).then(name => {
  65. return this.Plugins.add(window[name], config)
  66. })
  67. } else if (typeof plugin === 'function') {
  68. return this.Plugins.add(plugin, config)
  69. }
  70. }
  71. mount(el) {
  72. if (!el) {
  73. throw new Error('el must be require')
  74. }
  75. this.config.dom = el
  76. this.withDom()
  77. return this
  78. }
  79. render() {
  80. this.core.get('Scene').start()
  81. return this
  82. }
  83. metadata(data) {
  84. if (data === void 0) {
  85. this.store.set('metadata')
  86. return this
  87. }
  88. return this.store.get('metadata')
  89. }
  90. }
  91. window.PetiteVue = PetiteVue