use-fly.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { TaggingPosition } from "@/api";
  2. import { custom, showTaggingPositionsStack } from "@/env";
  3. import { currentModel, fuseModel, loadModel } from "@/model";
  4. import { sdk, getTaggingPosNode, setPose, getSceneMeasure, playSceneGuide, pauseSceneGuide, activeModel } from "@/sdk";
  5. import { getPathNode, pauseScenePath, playScenePath } from "@/sdk/association/path";
  6. import {
  7. getFuseModel,
  8. getFuseModelShowVariable,
  9. getTaggingPositions,
  10. Measure,
  11. Tagging,
  12. Path,
  13. View,
  14. viewToModelType,
  15. Guide,
  16. getGuidePaths,
  17. FuseModel,
  18. } from "@/store";
  19. import { nextTick, ref } from "vue";
  20. let stopFly: (() => void) | null = null;
  21. export const flyTagging = (tagging: Tagging, callback?: () => void) => {
  22. stopFly && stopFly();
  23. const positions = getTaggingPositions(tagging);
  24. console.error('fly tagging')
  25. let timeout: any
  26. let isStop = false;
  27. const flyIndex = (i: number) => {
  28. if (isStop || i >= positions.length) {
  29. callback && nextTick(callback);
  30. return;
  31. }
  32. const position = positions[i];
  33. const model = getFuseModel(position.modelId);
  34. if (!model || !getFuseModelShowVariable(model).value) {
  35. flyIndex(i + 1);
  36. return;
  37. }
  38. const pop = showTaggingPositionsStack.push(ref(new WeakSet([position])));
  39. flyTaggingPosition(position);
  40. timeout = setTimeout(() => {
  41. pop();
  42. flyIndex(i + 1);
  43. }, 2000);
  44. };
  45. flyIndex(0);
  46. stopFly = () => {
  47. clearTimeout(timeout)
  48. isStop = true;
  49. stopFly = null;
  50. };
  51. return stopFly;
  52. };
  53. export const flyTaggingPosition = (position: TaggingPosition) => {
  54. if (position.pose) {
  55. setPose({
  56. modelId: position.modelId,
  57. dur: 300,
  58. // distance: 3,
  59. maxDis: 15,
  60. isFlyToTag: true,
  61. focusPos: getTaggingPosNode(position)!.getImageCenter(),
  62. ...position.pose
  63. } as any, sdk, false);
  64. } else {
  65. sdk.comeTo({
  66. position: getTaggingPosNode(position)!.getImageCenter(),
  67. modelId: position.modelId,
  68. dur: 300,
  69. // distance: 3,
  70. maxDis: 15,
  71. isFlyToTag: true,
  72. });
  73. }
  74. };
  75. export const flyMeasure = (data: Measure) => {
  76. stopFly && stopFly();
  77. getSceneMeasure(data)?.fly();
  78. };
  79. export const flyPath = (path: Path) => {
  80. stopFly && stopFly();
  81. getPathNode(path.id)?.fly();
  82. getPathNode(path.id)?.focus(true);
  83. };
  84. export const flyView = (view: View) => {
  85. stopFly && stopFly();
  86. let isStop = false;
  87. stopFly = () => {
  88. isStop = true;
  89. stopFly = null
  90. };
  91. const modelType = viewToModelType(view);
  92. loadModel(modelType).then((sdk) => {
  93. if (!isStop) {
  94. custom.currentView = view;
  95. sdk.setView(view.flyData);
  96. }
  97. });
  98. return stopFly;
  99. };
  100. export const flyPlayGuide = (guide: Guide) => {
  101. stopFly && stopFly()
  102. stopFly = () => {
  103. stopFly = null
  104. pauseSceneGuide()
  105. }
  106. playSceneGuide(getGuidePaths(guide), undefined, true, guide)
  107. return stopFly
  108. }
  109. export const flyPlayPath = (path: Path) => {
  110. stopFly && stopFly()
  111. stopFly = () => {
  112. stopFly = null
  113. pauseScenePath()
  114. }
  115. playScenePath(path, true);
  116. return stopFly
  117. }
  118. export const flyLatLng = (latlng: number[]) => {
  119. stopFly && stopFly();
  120. sdk.comeToByLatLng(latlng)
  121. }
  122. export const flyModel = (model: FuseModel, mode: "pano" | "fuse", f = false) => {
  123. stopFly && stopFly();
  124. if (getFuseModelShowVariable(model).value) {
  125. if (custom.currentModel === model && mode === custom.showMode) {
  126. if (!f) return;
  127. activeModel({ showMode: "fuse", active: undefined, fore: f });
  128. } else {
  129. activeModel({ showMode: mode, active: model, fore: f });
  130. }
  131. }
  132. if (currentModel.value !== fuseModel) {
  133. loadModel(fuseModel);
  134. }
  135. };