bill 8 月之前
父节点
当前提交
e94cc6df0c
共有 3 个文件被更改,包括 48 次插入79 次删除
  1. 14 46
      src/components/tagging/sign-new.vue
  2. 4 0
      src/sdk/sdk.ts
  3. 30 33
      src/views/tagging-position/index.vue

+ 14 - 46
src/components/tagging/sign-new.vue

@@ -77,13 +77,9 @@ const queryItems = computed(() =>
 const taggingStyle = computed(() => getTaggingStyle(props.tagging.styleId));
 
 const tag = sdk.createTagging({
+  ...props.scenePos,
   title: props.tagging.title,
-  type: props.scenePos.type,
-  mat: props.scenePos.mat,
-  altitudeAboveGround: props.scenePos.altitudeAboveGround,
   position: props.scenePos.localPos,
-  modelId: props.scenePos.modelId,
-  normal: props.scenePos.normal,
   canMove: false,
   image: getFileUrl(taggingStyle.value!.icon),
 });
@@ -92,51 +88,23 @@ watch(taggingStyle, (icon) => icon && tag.changeImage(getFileUrl(icon.icon)));
 watchEffect(() => {
   tag.changeCanMove(router.currentRoute.value.name === RoutesName.tagging);
 });
-watch(
-  () => props.scenePos.mat,
-  (val) => {
-    tag.changeMat(val);
-  },
-  { deep: true }
-);
-watch(
-  () => props.scenePos.altitudeAboveGround,
-  (val) => {
-    tag.changeAltitudeAboveGround(val);
-  },
-  { deep: true }
-);
-watch(
-  () => props.tagging.title,
-  (val) => {
-    tag.changeTitle(val);
-  },
-  { deep: true }
-);
-watch(
-  () => props.tagging.show3dTitle,
-  (val) => {
-    tag.visibilityTitle(val);
-  },
-  { deep: true }
-);
-watch(
-  () => props.scenePos.type,
-  (val) => {
-    tag.changeType(val);
-    changePos();
-  },
-  { deep: true }
-);
+watchEffect(() => tag.changeMat(props.scenePos.mat));
+watchEffect(() => tag.changeAltitudeAboveGround(props.scenePos.altitudeAboveGround));
+watchEffect(() => tag.changeTitle(props.tagging.title));
+watchEffect(() => tag.visibilityTitle(props.tagging.show3dTitle));
+watchEffect(() => tag.changeFontSize(props.scenePos.fontSize));
+watchEffect(() => tag.changeLineHeight(props.scenePos.lineHeight));
+watchEffect(() => {
+  tag.changeType(props.scenePos.type);
+  changePos();
+});
 
-const toCameraDistance = useCameraChange(
+const [toCameraDistance] = useCameraChange(
   () => tag.getCameraDisSquared && tag.getCameraDisSquared()
 );
+const maxDisSqua = Math.sqrt(30);
 const show = computed(
-  () =>
-    props.scenePos.globalVisibility ||
-    // || toCameraDistance.value <= 30
-    true
+  () => props.scenePos.globalVisibility || toCameraDistance.value <= maxDisSqua
 );
 watchEffect(() => tag.visibility(show.value));
 

+ 4 - 0
src/sdk/sdk.ts

@@ -243,6 +243,8 @@ export type Path = {
 }
 
 export type Tagging3DProps = {
+  lineHeight: number
+  fontSize: number,
   // 标题
   title: string
   // 标注类型 2d | 3d
@@ -276,6 +278,8 @@ export type Tagging3D = {
     // 位置变更
     changePosition: {pos: SceneLocalPos, modelId: string, normal: SceneLocalPos}
   }>;
+  changeFontSize: (fontSize: number) => void
+  changeLineHeight: (lineHeight: number) => void
   // 设置标题
   changeTitle: (title: string) => void
   // 标题是否可见

+ 30 - 33
src/views/tagging-position/index.vue

@@ -94,44 +94,41 @@ const applyGlobal = async (position: TaggingPosition, keys: string | string[]) =
 // const cameraPos = ref<SceneLocalPos>();
 // sdk.sceneBus.on("cameraChange", (pos) => (cameraPos.value = pos));
 
-watchEffect((onCleanup) => {
-  if (tagging.value) {
-    const clickHandler = async (ev: MouseEvent) => {
-      await nextTick();
-      await asyncTimeout();
-      const position = sdk.getPositionByScreen({
-        x: ev.clientX,
-        y: ev.clientY,
+let unKeepAdding: () => void;
+const keepAdding = () => {
+  const hide = Message.show({ msg: "请在模型上单击选择标签位置", type: "warning" });
+  const clickHandler = async (ev: MouseEvent) => {
+    await nextTick();
+    await asyncTimeout();
+    const position = sdk.getPositionByScreen({
+      x: ev.clientX,
+      y: ev.clientY,
+    });
+
+    if (!position) {
+      Message.error("当前位置无法添加");
+    } else {
+      const storePosition = createTaggingPosition({
+        ...position,
+        taggingId: tagging.value!.id,
       });
+      taggingPositions.value.push(storePosition);
 
-      if (!position) {
-        Message.error("当前位置无法添加");
-      } else {
-        const storePosition = createTaggingPosition({
-          ...position,
-          taggingId: tagging.value!.id,
-        });
-        taggingPositions.value.push(storePosition);
+      showId.value = storePosition.id;
+      // if (cameraPos.value && distance(cameraPos.value, position.worldPos) > 8) {
+      //   flyTaggingPosition(storePosition);
+      // }
+    }
+  };
+  sdk.layout.addEventListener("click", clickHandler, false);
 
-        showId.value = storePosition.id;
-        // if (cameraPos.value && distance(cameraPos.value, position.worldPos) > 8) {
-        //   flyTaggingPosition(storePosition);
-        // }
-      }
-    };
-    sdk.layout.addEventListener("click", clickHandler, false);
+  unKeepAdding = () => {
+    hide();
+    sdk.layout.removeEventListener("click", clickHandler, false);
+  };
+};
 
-    onCleanup(() => {
-      sdk.layout.removeEventListener("click", clickHandler, false);
-    });
-  }
-});
 useViewStack(autoSaveTaggings);
-useViewStack(() => {
-  const hide = Message.show({ msg: "请在模型上单击选择标签位置", type: "warning" });
-  enterEdit(() => router.back());
-  return hide;
-});
 </script>
 
 <style lang="scss" scoped>