ソースを参照

修复小数位长度问题

bill 3 年 前
コミット
3cf317d439
3 ファイル変更37 行追加6 行削除
  1. 31 5
      src/sdk/association.ts
  2. 0 1
      src/utils/diff.ts
  3. 6 0
      src/utils/index.ts

+ 31 - 5
src/sdk/association.ts

@@ -1,6 +1,6 @@
 import { sdk } from './sdk'
 import { fuseModels, taggings, isEdit, sysBus, getFuseModelShowVariable, SceneType } from '@/store'
-import { toRaw, watchEffect, ref, watch, nextTick } from 'vue'
+import { toRaw, ref, watch, nextTick } from 'vue'
 import { viewModeStack, custom, getResource } from '@/env'
 import { 
   mount, 
@@ -8,7 +8,9 @@ import {
   shallowWatchArray, 
   arrayChildEffectScope,
   showLoad,
-  hideLoad
+  hideLoad,
+  deepIsRevise,
+  round
 } from '@/utils'
 
 import TaggingComponent from '@/components/tagging/list.vue'
@@ -53,8 +55,32 @@ const associationModels = (sdk: SDK) => {
       sceneModelMap.set(itemRaw, sceneModel)
 
       sceneModel.bus.on('transformChanged', transform => {
-        unSet(() => Object.assign(item, transform))
+        transform = { ...transform }
+        if (transform.rotation) {
+          transform.rotation = {
+            x: round(transform.rotation.x, 5),
+            y: round(transform.rotation.y, 5),
+            z: round(transform.rotation.z, 5),
+          }
+        }
+        if (transform.position) {
+          transform.position = {
+            x: round(transform.position.x, 5),
+            y: round(transform.position.y, 5),
+            z: round(transform.position.z, 5),
+          }
+        }
+
+        const updateKeys = Object.keys(transform)
+        const update: any = {}
+        for (const key of updateKeys) {
+          update[key] = (item as any)[key]
+        }
+        if (deepIsRevise(update, transform)) {
+          unSet(() => Object.assign(item, transform))
+        }
       })
+
       sceneModel.bus.on('changeSelect', select => {
         if (custom.currentModel === item && !select) {
           custom.currentModel = null
@@ -89,8 +115,8 @@ const associationModels = (sdk: SDK) => {
           watch(() => item.bottom, () => isUnSet || getSceneModel(item)?.changeBottom(item.bottom), {immediate: true})
           watch(() => item.opacity, () => isUnSet || getSceneModel(item)?.changeOpacity(item.opacity), {immediate: true})
           watch(() => item.scale, () => isUnSet || getSceneModel(item)?.changeScale(item.scale), {immediate: true})
-          watch(() => item.position, () => isUnSet || getSceneModel(item)?.changePosition(item.position), {immediate: true})
-          watch(() => item.rotation, () => isUnSet || getSceneModel(item)?.changeRotation(item.rotation), {immediate: true})
+          // watch(() => item.position, () => isUnSet || getSceneModel(item)?.changePosition(item.position), {immediate: true})
+          // watch(() => item.rotation, () => isUnSet || getSceneModel(item)?.changeRotation(item.rotation), {immediate: true})
           watch(() => modelShow.value, () => isUnSet || getSceneModel(item)?.changeShow(modelShow.value), {immediate: true})
           stopLoadedWatch()
         }

+ 0 - 1
src/utils/diff.ts

@@ -12,7 +12,6 @@ const _deepIsRevise = (
   const rawType2 = toRawType(raw2);
 
   if (rawType1 !== rawType2) {
-    console.log('===', rawType1, rawType2)
     return true;
   } else if (
     rawType1 === "String" ||

+ 6 - 0
src/utils/index.ts

@@ -61,6 +61,12 @@ export const jsonToForm = (data: { [key in string]: any }) => {
 }
 
 
+// 四舍五入保留指定位数
+export const round = (num: number, index: number = 2) => {
+  const s = Math.pow(10, index)
+  return Math.round(num * s) / s
+}
+
 export * from './store-help'
 export * from "./stack";
 export * from "./loading";