bill 1 year ago
parent
commit
5fcb70c452
2 changed files with 80 additions and 67 deletions
  1. 2 0
      src/sdk/sdk.ts
  2. 78 67
      src/views/merge/index.vue

+ 2 - 0
src/sdk/sdk.ts

@@ -17,6 +17,7 @@ export type SceneModel = ToChangeAPI<SceneModelAttrs>
         loadDone: void, 
         loadProgress: number,
         changeSelect: boolean,
+        
         transformChanged: {
           position?: SceneLocalPos,
           scale?: number,
@@ -29,6 +30,7 @@ export type SceneModel = ToChangeAPI<SceneModelAttrs>
     enterRotateMode: () => void
     enterMoveMode: () => void
     leaveTransform: () => void
+    getDefaultRotation: () => SceneLocalPos,
     enterAlignment: () => void
     leaveAlignment: () => void
     enterScaleSet:() => ScaleSet

+ 78 - 67
src/views/merge/index.vue

@@ -6,19 +6,21 @@
       </template>
       <ui-group-option label="等比缩放">
         <template #icon>
-          <a class="set-prop" 
-            :class="{disabled: isOld || currentItem}"
+          <a
+            class="set-prop"
+            :class="{ disabled: isOld || currentItem }"
             @click="router.push({ 
               name: RoutesName.proportion, 
               params: { id: custom.currentModel!.id, save: '1' },
             })"
-          >设置比例</a>
+            >设置比例</a
+          >
         </template>
-        <ui-input 
-          type="range" 
-          v-model="custom.currentModel.scale" 
-          v-bind="modelRange.scaleRange" 
-          :ctrl="false" 
+        <ui-input
+          type="range"
+          v-model="custom.currentModel.scale"
+          v-bind="modelRange.scaleRange"
+          :ctrl="false"
           width="100%"
         >
           <template #icon>%</template>
@@ -36,25 +38,26 @@
         </ui-input>
       </ui-group-option> -->
       <ui-group-option label="模型不透明度">
-        <ui-input 
-          type="range" 
-          v-model="custom.currentModel.opacity" 
-          v-bind="modelRange.opacityRange" 
-          :ctrl="false" 
+        <ui-input
+          type="range"
+          v-model="custom.currentModel.opacity"
+          v-bind="modelRange.opacityRange"
+          :ctrl="false"
           width="100%"
         >
           <template #icon>%</template>
         </ui-input>
       </ui-group-option>
       <ui-group-option>
-          <!-- :disabled="currentItem"  -->
-        <ui-button 
-          :class="{disabled: isOld}"
+        <!-- :disabled="currentItem"  -->
+        <ui-button
+          :class="{ disabled: isOld }"
           @click="router.push({ 
             name: RoutesName.registration, 
             params: {id: custom.currentModel!.id, save: '1' } 
           })"
-        >配准</ui-button>
+          >配准</ui-button
+        >
       </ui-group-option>
       <ui-group-option>
         <ui-button @click="reset">恢复默认</ui-button>
@@ -64,79 +67,88 @@
 </template>
 
 <script lang="ts" setup>
-import { RoutesName, router } from '@/router'
-import { RightPano } from '@/layout'
-import { autoSaveFuseModels, defaultFuseModelAttrs, isOld } from '@/store'
-import { togetherCallback } from '@/utils'
-import { sdk, getSceneModel, modelRange } from '@/sdk'
-import { useViewStack, useActive } from '@/hook'
-import { showLeftPanoStack, custom, modelsChangeStoreStack, showRightPanoStack } from '@/env'
-import { ref, nextTick, watchEffect, computed, watch } from 'vue'
-import { Dialog } from 'bill/expose-common'
+import { RoutesName, router } from "@/router";
+import { RightPano } from "@/layout";
+import { autoSaveFuseModels, defaultFuseModelAttrs, isOld } from "@/store";
+import { togetherCallback } from "@/utils";
+import { sdk, getSceneModel, modelRange } from "@/sdk";
+import { useViewStack, useActive } from "@/hook";
+import {
+  showLeftPanoStack,
+  custom,
+  modelsChangeStoreStack,
+  showRightPanoStack,
+} from "@/env";
+import { ref, nextTick, watchEffect, computed, watch } from "vue";
+import { Dialog } from "bill/expose-common";
 
-import Actions from '@/components/actions/index.vue'
+import Actions from "@/components/actions/index.vue";
 
-import type { ActionsProps, ActionsItem } from '@/components/actions/index.vue'
+import type { ActionsProps, ActionsItem } from "@/components/actions/index.vue";
 
-const active = useActive()
-const actionItems: ActionsProps['items'] = [
+const active = useActive();
+const actionItems: ActionsProps["items"] = [
   {
-    icon: 'move',
-    text: '移动',
+    icon: "move",
+    text: "移动",
     action: () => {
-      getSceneModel(custom.currentModel)?.enterMoveMode()
-      return () => getSceneModel(custom.currentModel)?.leaveTransform()
-    }
+      getSceneModel(custom.currentModel)?.enterMoveMode();
+      return () => getSceneModel(custom.currentModel)?.leaveTransform();
+    },
   },
   {
-    icon: 'flip',
-    text: '旋转',
+    icon: "flip",
+    text: "旋转",
     action: () => {
-      getSceneModel(custom.currentModel)?.enterRotateMode()
+      getSceneModel(custom.currentModel)?.enterRotateMode();
       return () => {
-        getSceneModel(custom.currentModel)?.leaveTransform()
-      }
-    }
+        getSceneModel(custom.currentModel)?.leaveTransform();
+      };
+    },
   },
-]
+];
 
-
-const currentItem = ref<ActionsItem | null>(null)
+const currentItem = ref<ActionsItem | null>(null);
 watchEffect(() => {
   if (!custom.currentModel) {
-    currentItem.value = null
+    currentItem.value = null;
   }
-})
+});
 
 watch(
-  () => custom.currentModel, 
+  () => custom.currentModel,
   () => {
-    console.log('???')
     currentItem.value = null;
   }
-)
+);
 
 const reset = async () => {
-  if (custom.currentModel && await Dialog.confirm('确定恢复默认?此操作无法撤销')) {
-    Object.assign(custom.currentModel, defaultFuseModelAttrs)
-    await nextTick()
-    custom.currentModel && (custom.currentModel.bottom = 0)
+  if (custom.currentModel && (await Dialog.confirm("确定恢复默认?此操作无法撤销"))) {
+    Object.assign(custom.currentModel, {
+      ...defaultFuseModelAttrs,
+      rotation: getSceneModel(custom.currentModel)!.getDefaultRotation(),
+    });
+    await nextTick();
+
+    custom.currentModel && (custom.currentModel.bottom = 0);
   }
-}
-useViewStack(() => togetherCallback([
-  showLeftPanoStack.push(ref(true)),
-  showRightPanoStack.push(computed(() => !!custom.currentModel)),
-  modelsChangeStoreStack.push(ref(true)),
-  () => currentItem.value = null
-]))
-useViewStack(autoSaveFuseModels)
+};
+useViewStack(() =>
+  togetherCallback([
+    showLeftPanoStack.push(ref(true)),
+    showRightPanoStack.push(computed(() => !!custom.currentModel)),
+    modelsChangeStoreStack.push(ref(true)),
+    () => (currentItem.value = null),
+  ])
+);
+useViewStack(autoSaveFuseModels);
 
 useViewStack(() => {
-  sdk.showGrid()
+  sdk.showGrid();
   return () => {
-    sdk.hideGrid()
-  }
-})
+    sdk.hideGrid();
+  };
+});
 </script>
 
 <style lang="scss">
@@ -150,8 +162,7 @@ useViewStack(() => {
   }
 }
 
-
 .set-prop {
   cursor: pointer;
 }
-</style>
+</style>