Browse Source

对接导览

bill 3 years ago
parent
commit
edc058faf6
5 changed files with 99 additions and 90 deletions
  1. 4 7
      src/sdk/association.ts
  2. 6 82
      src/sdk/index.ts
  3. 85 0
      src/sdk/sdk.ts
  4. 2 0
      src/views/guide/index.vue
  5. 2 1
      src/views/guide/sign.vue

+ 4 - 7
src/sdk/association.ts

@@ -1,3 +1,4 @@
+import { sdk } from './sdk'
 import { models, taggings, isEdit, sysBus, getModelShowVariable } from '@/store'
 import { toRaw, watchEffect, ref, watch } from 'vue'
 import { viewModeStack, custom } from '@/env'
@@ -99,7 +100,7 @@ const fullView = async (fn: () => void) => {
 }
 
 export const isScenePlayIng = ref(false)
-export const playSceneGuide = async (sdk: SDK, paths: SceneGuidePath[], changeIndexCallback: (index: number) => void) => {
+export const playSceneGuide = async (paths: SceneGuidePath[], changeIndexCallback: (index: number) => void) => {
   if (isScenePlayIng.value) {
     throw new Error('导览正在播放')
   }
@@ -145,11 +146,7 @@ export const playSceneGuide = async (sdk: SDK, paths: SceneGuidePath[], changeIn
 export const pauseSceneGuide = () => isScenePlayIng.value = false
 
 
-export const setup = (sdk: SDK, mountEl: HTMLDivElement) => {
-  try {
-    associationModels(sdk)
-  } catch {
-
-  }
+export const setupAssociation = (mountEl: HTMLDivElement) => {
+  associationModels(sdk)
   associationTaggings(mountEl)
 }

+ 6 - 82
src/sdk/index.ts

@@ -1,64 +1,5 @@
-import cover from './cover'
-import { setup } from './association'
-import { loadLib } from '@/utils'
-
-import type { ModelAttrs, Model, GuidePath, GuidePaths } from '@/store'
-import type { Emitter } from 'mitt'
-
-
-type SceneModelAttrs = ModelAttrs & { select: boolean }
-export type SceneModel = ToChangeAPI<Omit<SceneModelAttrs, 'position' | 'rotation'>>
-  & { 
-    bus: Emitter<
-      Pick<SceneModelAttrs, 'select'> & 
-      { 
-        loadDone: void, 
-        loadProgress: number,
-        changeSelect: boolean,
-        transformChanged: {
-          position?: SceneLocalPos,
-          scale?: number,
-          rotation?: SceneLocalPos,
-          bottom?: number
-        }
-      }
-    > 
-    destroy: () => void 
-    enterRotateMode: () => void
-    enterMoveMode: () => void
-    leaveTransform: () => void
-  }
-
-
-export type AddModelProps = Pick<Model, 'type' | 'url' | 'id'> & ModelAttrs
-
-export type SceneGuidePath = Pick<GuidePath, 'position' | 'target' | 'speed' | 'time'>
-export interface SceneGuide {
-  bus: Emitter<{ changePoint: number; playComplete: void }>
-  play: () => void
-  pause: () => void
-  clear: () => void
-}
-
-export type ScenePos = { localPos: SceneLocalPos, modelId: Model['id'] }
-export type ScreenPos = { 
-  trueSide: boolean,
-  pos: ScreenLocalPos, 
-  modelId: Model['id'] 
-}
-
-export interface SDK {
-  layout: HTMLDivElement,
-  sceneBus: Emitter<{ 'cameraChange': void }>
-  addModel: (props: AddModelProps) => SceneModel
-  getPositionByScreen: (screenPos: ScreenLocalPos, modelId?: Model['id']) => ScenePos | null
-  getScreenByPosition: (localPos: SceneLocalPos, modelId?: Model['id']) => ScreenPos | null
-  screenshot: (width: number, height: number) => Promise<string>
-  getPose: () => { position: SceneLocalPos, target: SceneLocalPos }
-  comeTo: (pos: { position: SceneLocalPos; target?: SceneLocalPos; dur?: number, modelId?: Model['id'] }) => void
-  enterSceneGuide: (data: SceneGuidePath[]) => SceneGuide
-}
-  
+import { initialSDK as initialSDKRaw, sdk } from './sdk'
+import { setupAssociation } from './association'
 
 const presetViewElement = (layout: HTMLDivElement) => {
   const style = getComputedStyle(layout)
@@ -82,28 +23,11 @@ const presetViewElement = (layout: HTMLDivElement) => {
 }
 
 
-export let sdk: SDK
-export type InialSDKProps = { layout: HTMLDivElement }
-let initialed = false
-export const initialSDK = async (props: InialSDKProps) => {
-  if (initialed) return;
-  initialed = true
-  const libs = [
-    `/lib/proj4/proj4.js`,
-    `/lib/jquery/jquery-3.1.1.min.js`,
-    `/lib/other/BinaryHeap.js`,
-    `/lib/tween/tween.min.js`,
-  ]
-  await Promise.all(libs.map(loadLib))
-  await loadLib(`/lib/potree/potree.js`)
-
-  const localSdk = cover(props.layout) as unknown as SDK
-
-  sdk = localSdk
-  sdk.layout = props.layout
-  setup(sdk, presetViewElement(props.layout))
+export const initialSDK: typeof initialSDKRaw = async (props) => {
+  await initialSDKRaw(props)
+  setupAssociation(presetViewElement(props.layout))
 }
 
-
 export * from './association'
+export * from './sdk'
 export default sdk

+ 85 - 0
src/sdk/sdk.ts

@@ -0,0 +1,85 @@
+import cover from './cover'
+import { loadLib } from '@/utils'
+
+import type { ModelAttrs, Model, GuidePath, GuidePaths } from '@/store'
+import type { Emitter } from 'mitt'
+
+
+type SceneModelAttrs = ModelAttrs & { select: boolean }
+export type SceneModel = ToChangeAPI<Omit<SceneModelAttrs, 'position' | 'rotation'>>
+  & { 
+    bus: Emitter<
+      Pick<SceneModelAttrs, 'select'> & 
+      { 
+        loadDone: void, 
+        loadProgress: number,
+        changeSelect: boolean,
+        transformChanged: {
+          position?: SceneLocalPos,
+          scale?: number,
+          rotation?: SceneLocalPos,
+          bottom?: number
+        }
+      }
+    > 
+    destroy: () => void 
+    enterRotateMode: () => void
+    enterMoveMode: () => void
+    leaveTransform: () => void
+  }
+
+
+export type AddModelProps = Pick<Model, 'type' | 'url' | 'id'> & ModelAttrs
+
+export type SceneGuidePath = Pick<GuidePath, 'position' | 'target' | 'speed' | 'time'>
+export interface SceneGuide {
+  bus: Emitter<{ changePoint: number; playComplete: void }>
+  play: () => void
+  pause: () => void
+  clear: () => void
+}
+
+export type ScenePos = { localPos: SceneLocalPos, modelId: Model['id'] }
+export type ScreenPos = { 
+  trueSide: boolean,
+  pos: ScreenLocalPos, 
+  modelId: Model['id'] 
+}
+
+export interface SDK {
+  layout: HTMLDivElement,
+  sceneBus: Emitter<{ 'cameraChange': void }>
+  addModel: (props: AddModelProps) => SceneModel
+  getPositionByScreen: (screenPos: ScreenLocalPos, modelId?: Model['id']) => ScenePos | null
+  getScreenByPosition: (localPos: SceneLocalPos, modelId?: Model['id']) => ScreenPos | null
+  screenshot: (width: number, height: number) => Promise<string>
+  getPose: () => { position: SceneLocalPos, target: SceneLocalPos }
+  comeTo: (pos: { position: SceneLocalPos; target?: SceneLocalPos; dur?: number, modelId?: Model['id'] }) => void
+  enterSceneGuide: (data: SceneGuidePath[]) => SceneGuide
+}
+  
+
+
+export let sdk: SDK
+export type InialSDKProps = { layout: HTMLDivElement }
+let initialed = false
+export const initialSDK = async (props: InialSDKProps) => {
+  if (initialed) return;
+  initialed = true
+  const libs = [
+    `/lib/proj4/proj4.js`,
+    `/lib/jquery/jquery-3.1.1.min.js`,
+    `/lib/other/BinaryHeap.js`,
+    `/lib/tween/tween.min.js`,
+  ]
+  await Promise.all(libs.map(loadLib))
+  await loadLib(`/lib/potree/potree.js`)
+
+  const localSdk = cover(props.layout) as unknown as SDK
+
+  sdk = localSdk
+  sdk.layout = props.layout
+  console.error('-0-0--0')
+}
+
+export default sdk

+ 2 - 0
src/views/guide/index.vue

@@ -13,6 +13,7 @@
         v-for="guide in guides" 
         :key="guide.id" 
         :guide="guide" 
+        @play="playSceneGuide(guide.paths)"
         @edit="edit(guide)"
         @delete="deleteGuide(guide)"
       />
@@ -31,6 +32,7 @@ import { ref } from 'vue';
 import GuideSign from './sign.vue'
 import EditPaths from './edit-paths.vue'
 import { useViewStack } from '@/hook'
+import { playSceneGuide } from '@/sdk'
 
 const currentGuide = ref<Guide | null>()
 const leaveEdit = () => currentGuide.value = null

+ 2 - 1
src/views/guide/sign.vue

@@ -3,7 +3,7 @@
     <div class="info">
       <div class="guide-cover">
         <img :src="getFileUrl(guide.cover)" />
-        <ui-icon type="preview" class="icon" ctrl />
+        <ui-icon type="preview" class="icon" ctrl @click="emit('play')" />
       </div>
       <div>
         <p>{{ guide.title }}</p>
@@ -27,6 +27,7 @@ import { getFileUrl } from '@/utils'
 defineProps<{ guide: Guide }>()
 const emit = defineEmits<{ 
   (e: 'delete'): void 
+  (e: 'play'): void 
   (e: 'edit'): void 
 }>()