path.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { diffArrayChange, mount, shallowWatchArray } from "@/utils";
  2. import TaggingComponent from "@/components/path/list.vue";
  3. import { Path as PathData, paths, selectPaths } from "@/store/path";
  4. import { sdk, Path, SDK } from "../sdk";
  5. import { nextTick, reactive, ref, watch, watchEffect } from "vue";
  6. import { groupProxy } from "@/store/group";
  7. import { isScenePlayRun, pauseScene, playScene } from "@/utils/full";
  8. import { analysisPose, setPose } from ".";
  9. import { custom, showPathsStack, showPathStack, showSearchStack, showViewSettingStack } from "@/env";
  10. import { Message } from "bill/expose-common";
  11. import { mergeFuns } from "@/components/drawing/hook";
  12. // -----------------导览线关联--------------------
  13. export type PathNode = Path;
  14. export type PathsNode = { node: PathNode; id: PathData["id"] }[];
  15. const pathNodes = reactive(new Map<PathData, PathNode>());
  16. export const getPathNode = (
  17. path: PathData | PathData["id"]
  18. ): undefined | PathNode => {
  19. if (typeof path !== "object") {
  20. path = paths.value.find((item) => item.id === path)!;
  21. if (!path) return void 0;
  22. }
  23. return pathNodes.get(path);
  24. };
  25. export const pathsGroup = groupProxy(() => {
  26. const nodes = [] as PathNode[];
  27. for (const path of paths.value) {
  28. const node = getPathNode(path);
  29. if (node) {
  30. nodes.push(node);
  31. }
  32. }
  33. return nodes;
  34. });
  35. watchEffect(() => {
  36. pathsGroup.visibility(custom.showPaths);
  37. if (custom.showPath) {
  38. const node = getPathNode(custom.showPath);
  39. node?.visibility(true);
  40. // node?.fly()
  41. }
  42. })
  43. export const playScenePath = async (
  44. path: PathData,
  45. forceFull = false,
  46. ) => {
  47. const node = getPathNode(path)
  48. if (!node) {
  49. console.error('un', path.id)
  50. return Message.error('路径所在模型被隐藏活删除,无法播放');
  51. }
  52. showPathsStack.push(ref(false))
  53. showPathStack.push(ref(path.id))
  54. let initPose: any;
  55. let pop: null | (() => void) = null
  56. await playScene({
  57. create: () => {
  58. const cleanups = [showSearchStack.push(ref(false))]
  59. if (forceFull) {
  60. cleanups.push(showViewSettingStack.push(ref(false)))
  61. }
  62. pop = mergeFuns(cleanups)
  63. },
  64. play: () => {
  65. return new Promise(resolve => {
  66. initPose = analysisPose(sdk.getPose());
  67. node.play(resolve)
  68. })
  69. },
  70. pause: () => {
  71. setPose(initPose)
  72. node.pause();
  73. },
  74. clear: () => {
  75. pop && pop()
  76. }
  77. }, forceFull)
  78. showPathsStack.pop()
  79. showPathStack.pop()
  80. }
  81. export const pauseScenePath = pauseScene
  82. export const isScenePathPlayIng = isScenePlayRun
  83. export const associationPaths = (sdk: SDK, el: HTMLDivElement) => {
  84. mount<PathsNode>(el, TaggingComponent, { paths }, (pathsNode) => {
  85. watch(
  86. () => {
  87. if (!pathsNode) return []
  88. pathsNode.forEach(i => !!i?.id)
  89. return pathsNode
  90. },
  91. (nodes, oldNodes = []) => {
  92. watchEffect(() => {
  93. pathNodes.clear()
  94. nodes.forEach(node => {
  95. const path = paths.value.find((item) => item.id === node.id)!;
  96. pathNodes.set(path, node.node);
  97. })
  98. })
  99. },
  100. {immediate: true}
  101. );
  102. });
  103. watchEffect(() => {
  104. selectPaths.selects.value.forEach(item => {
  105. pathNodes.get(item)?.visibility(true)
  106. })
  107. selectPaths.unSelects.value.forEach(item => {
  108. pathNodes.get(item)?.visibility(false)
  109. })
  110. })
  111. };