Browse Source

兼容旧数据没有getImage

wangfumin 3 tháng trước cách đây
mục cha
commit
4f46703732
1 tập tin đã thay đổi với 10 bổ sung1 xóa
  1. 10 1
      src/hook/use-fly.ts

+ 10 - 1
src/hook/use-fly.ts

@@ -54,6 +54,13 @@ export const flyTagging = (tagging: Tagging, callback?: () => void) => {
   return stopFly;
 };
 
+const getImageCenter = (tag:any) =>{  //热点在模型的本地坐标 
+  if(!tag.parent) return { x: 0, y: 0, z: 0 }
+  tag.titleLabel.sprite.update()
+  let pos = tag.onMesh ? tag.position : tag.titleLabel.parent.position.clone().applyMatrix4(tag.matrixWorld).applyMatrix4(tag.root.matrixWorld.clone().invert()) 
+  //console.log(props.title, 'getImageCenter', pos.toArray(), tag.lineLength)
+  return  pos
+}
 export const flyTaggingPosition = (position: TaggingPosition) => {
   if (position.pose) {
     setPose({
@@ -67,8 +74,10 @@ export const flyTaggingPosition = (position: TaggingPosition) => {
     } as any, sdk, false);
   } else {
     console.log(position, getTaggingPosNode(position), 88888888)
+    const tagNode = getTaggingPosNode(position)!;
+    const focusPos = tagNode.getImageCenter ? tagNode.getImageCenter() : getImageCenter(tagNode);
     sdk.comeTo({
-      focusPos: getTaggingPosNode(position)!.getImageCenter(),
+      focusPos: focusPos,
       modelId: position.modelId,
       dur: 300,
       // distance: 3,