@realsee/dnalogel 2.0.0-alpha.24 → 2.0.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/ModelItemLabelPlugin/index.js +1 -1
  3. package/dist/ModelRoomLabelPlugin/index.js +82 -46
  4. package/dist/index.es.js +84 -48
  5. package/dist/index.js +83 -47
  6. package/dist/index.umd.js +83 -47
  7. package/docs/classes/ModelRoomLabelController.html +6 -6
  8. package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
  9. package/docs/enums/ModelFloorplanErrorType.html +1 -1
  10. package/docs/interfaces/LineJson.html +1 -1
  11. package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
  12. package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
  13. package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
  14. package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
  15. package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
  16. package/docs/interfaces/ModelFloorplanParameterType.html +1 -1
  17. package/docs/interfaces/ModelFloorplanViewEvent.html +2 -2
  18. package/docs/interfaces/ModelItemLabelPluginData.html +1 -1
  19. package/docs/interfaces/ModelItemLabelPluginExportReturnsType.html +1 -1
  20. package/docs/interfaces/ModelItemLabelPluginParametersType.html +1 -1
  21. package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
  22. package/docs/interfaces/ModelTVVideoPluginData.html +1 -1
  23. package/docs/interfaces/ModelTVVideoPluginExportType.html +1 -1
  24. package/docs/interfaces/ModelTVVideoPluginParameterType.html +1 -1
  25. package/docs/interfaces/PanoCompassPluginData.html +1 -1
  26. package/docs/interfaces/PanoCompassPluginParameterType.html +1 -1
  27. package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
  28. package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
  29. package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
  30. package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
  31. package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
  32. package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
  33. package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
  34. package/docs/interfaces/PointJson.html +1 -1
  35. package/docs/interfaces/RoomLabel.html +7 -7
  36. package/docs/interfaces/TopviewFloorplanPluginParameterType.html +8 -8
  37. package/docs/modules.html +12 -12
  38. package/libs/ModelItemLabelPlugin/ItemLabelComponent.js +1 -1
  39. package/libs/ModelRoomLabelPlugin/RoomLabelItems.js +83 -47
  40. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0-alpha.26
4
+ - 1.fix: ModelRoomLabelPlugin - 修复渲染区域大小改变时,标签位置没有更新
5
+ - 2.pref: ModelRoomLabelPlugin - 优化渲染逻辑
6
+
7
+ ## 2.0.0-alpha.25
8
+ - 1.refactor: 恢复发版
9
+
3
10
  ## 2.0.0-alpha.24
4
11
  - 1.feat: PanoRulerPlugin 支持数据 reload。
5
12
 
@@ -177,7 +177,7 @@ function get_each_context(ctx, list, i) {
177
177
  return child_ctx;
178
178
  }
179
179
 
180
- // (162:1) {#each renderItemLabels as itemLabelItem (itemLabelItem.id)}
180
+ // (163:1) {#each renderItemLabels as itemLabelItem (itemLabelItem.id)}
181
181
  function create_each_block(key_1, ctx) {
182
182
  let first;
183
183
  let itemlabelitem;
@@ -110,17 +110,19 @@ class RoomLabelItem extends internal.SvelteComponent {
110
110
 
111
111
  /* src/ModelRoomLabelPlugin/RoomLabelItems.svelte generated by Svelte v3.47.0 */
112
112
 
113
+ const { Map: Map_1 } = internal.globals;
114
+
113
115
  function add_css(target) {
114
116
  internal.append_styles(target, "svelte-9eg4zi", ".room-labels-container.svelte-9eg4zi{width:100%;height:100%;position:relative;color:#fff}");
115
117
  }
116
118
 
117
119
  function get_each_context(ctx, list, i) {
118
120
  const child_ctx = ctx.slice();
119
- child_ctx[9] = list[i];
121
+ child_ctx[12] = list[i];
120
122
  return child_ctx;
121
123
  }
122
124
 
123
- // (70:2) {#each roomLabels as roomLableItem (roomLableItem.id)}
125
+ // (82:2) {#each roomLabels as roomLableItem (roomLableItem.id)}
124
126
  function create_each_block(key_1, ctx) {
125
127
  let first;
126
128
  let roomlabelitem;
@@ -128,7 +130,7 @@ function create_each_block(key_1, ctx) {
128
130
 
129
131
  roomlabelitem = new RoomLabelItem({
130
132
  props: {
131
- roomLabel: /*roomLableItem*/ ctx[9],
133
+ roomLabel: /*roomLableItem*/ ctx[12],
132
134
  five: /*five*/ ctx[1]
133
135
  }
134
136
  });
@@ -149,7 +151,7 @@ function create_each_block(key_1, ctx) {
149
151
  p(new_ctx, dirty) {
150
152
  ctx = new_ctx;
151
153
  const roomlabelitem_changes = {};
152
- if (dirty & /*roomLabels*/ 1) roomlabelitem_changes.roomLabel = /*roomLableItem*/ ctx[9];
154
+ if (dirty & /*roomLabels*/ 1) roomlabelitem_changes.roomLabel = /*roomLableItem*/ ctx[12];
153
155
  if (dirty & /*five*/ 2) roomlabelitem_changes.five = /*five*/ ctx[1];
154
156
  roomlabelitem.$set(roomlabelitem_changes);
155
157
  },
@@ -172,11 +174,11 @@ function create_each_block(key_1, ctx) {
172
174
  function create_fragment(ctx) {
173
175
  let div;
174
176
  let each_blocks = [];
175
- let each_1_lookup = new Map();
177
+ let each_1_lookup = new Map_1();
176
178
  let div_resize_listener;
177
179
  let current;
178
180
  let each_value = /*roomLabels*/ ctx[0];
179
- const get_key = ctx => /*roomLableItem*/ ctx[9].id;
181
+ const get_key = ctx => /*roomLableItem*/ ctx[12].id;
180
182
 
181
183
  for (let i = 0; i < each_value.length; i += 1) {
182
184
  let child_ctx = get_each_context(ctx, each_value, i);
@@ -193,7 +195,7 @@ function create_fragment(ctx) {
193
195
  }
194
196
 
195
197
  internal.attr(div, "class", "room-labels-container svelte-9eg4zi");
196
- internal.add_render_callback(() => /*div_elementresize_handler*/ ctx[4].call(div));
198
+ internal.add_render_callback(() => /*div_elementresize_handler*/ ctx[6].call(div));
197
199
  },
198
200
  m(target, anchor) {
199
201
  internal.insert(target, div, anchor);
@@ -202,7 +204,7 @@ function create_fragment(ctx) {
202
204
  each_blocks[i].m(div, null);
203
205
  }
204
206
 
205
- div_resize_listener = internal.add_resize_listener(div, /*div_elementresize_handler*/ ctx[4].bind(div));
207
+ div_resize_listener = internal.add_resize_listener(div, /*div_elementresize_handler*/ ctx[6].bind(div));
206
208
  current = true;
207
209
  },
208
210
  p(ctx, [dirty]) {
@@ -242,22 +244,17 @@ function create_fragment(ctx) {
242
244
  }
243
245
 
244
246
  function instance($$self, $$props, $$invalidate) {
247
+ let rendererSize;
245
248
  let { five } = $$props;
246
249
  let { roomLabels } = $$props;
247
250
  let containerWidth;
248
251
  let containerHeight;
252
+ let shownFloor = null;
249
253
 
250
- function getLabelVisible(five, roomLabelItem) {
251
- // 先看是不是在当前展示的楼层上
252
- const isLabelInFloor = five.model.shownFloor === null || roomLabelItem.floorIndex === five.model.shownFloor;
253
-
254
- if (!isLabelInFloor) return false;
255
-
256
- // 再看是不是被模型遮挡
254
+ function getLabelVisible(item) {
257
255
  const raycaster = new three.Raycaster();
258
-
259
256
  const cameraPosition = five.camera.position.clone();
260
- const position = new three.Vector3(roomLabelItem.position.x, roomLabelItem.position.y, roomLabelItem.position.z);
257
+ const position = new three.Vector3(item.position.x, item.position.y, item.position.z);
261
258
  const vectorDistance = position.distanceTo(cameraPosition);
262
259
  raycaster.set(cameraPosition.clone(), position.clone().sub(cameraPosition).normalize());
263
260
  const [intersection] = five.model.intersectRaycaster(raycaster);
@@ -265,53 +262,60 @@ function instance($$self, $$props, $$invalidate) {
265
262
  return true;
266
263
  }
267
264
 
268
- function getLabelTransform(five, roomLabelItem) {
269
- const position = new three.Vector3(roomLabelItem.position.x, roomLabelItem.position.y, roomLabelItem.position.z);
265
+ function getLabelTransform(item, rendererSize) {
266
+ const position = new three.Vector3(item.position.x, item.position.y, item.position.z);
270
267
  const mouse = position.clone().project(five.camera);
271
- const xOffset = Math.ceil((mouse.x + 1) / 2 * containerWidth);
272
- const yOffset = Math.ceil((-mouse.y + 1) / 2 * containerHeight);
268
+ const xOffset = Math.ceil((mouse.x + 1) / 2 * rendererSize.x);
269
+ const yOffset = Math.ceil((-mouse.y + 1) / 2 * rendererSize.y);
273
270
  return `translate(${xOffset}px, ${yOffset}px)`;
274
271
  }
275
272
 
276
- function getFormatedRoomLabels(five, labels) {
277
- const newLabels = labels.map(roomLabelItem => {
278
- // 计算是否可见,如果不可见,不会更新位置
279
- const visible = getLabelVisible(five, roomLabelItem);
273
+ function getFormatedRoomLabels(rendererSize) {
274
+ // 因为 item distance 需要重复计算,所以缓存一下
275
+ const distanceMap = new Map();
276
+
277
+ function getItemDistance(item) {
278
+ const cacheDistance = distanceMap.get(item.id);
279
+ if (cacheDistance) return cacheDistance;
280
+ const { x, y, z } = item.position;
281
+ const distance = new three.Vector3(x, y, z).clone().distanceTo(five.camera.position);
282
+ distanceMap.set(item.id, distance);
283
+ return distance;
284
+ }
280
285
 
281
- if (!visible) return Object.assign(Object.assign({}, roomLabelItem), { visible });
286
+ const formatedItems = roomLabels.map(item => {
287
+ const visible = getLabelVisible(item);
282
288
 
283
- // 更新位置
284
- const transform = getLabelTransform(five, roomLabelItem);
289
+ const transform = visible
290
+ ? getLabelTransform(item, rendererSize)
291
+ : item.transform;
285
292
 
286
- return Object.assign(Object.assign({}, roomLabelItem), { visible, transform });
287
- });
293
+ const itemDistance = getItemDistance(item);
288
294
 
289
- const sortedRoomLabelItems = newLabels.filter(({ visible }) => visible).map(roomLabelItem => ({
290
- roomLabelItem,
291
- distance: new three.Vector3(...Object.values(roomLabelItem.position)).clone().distanceTo(five.camera.position)
292
- })).sort((a, b) => a.distance - b.distance);
295
+ // visible === true item 中,distance 比自己小的 item 个数
296
+ const minItemLen = roomLabels.filter(item => item.visible && getItemDistance(item) < itemDistance).length;
293
297
 
294
- return newLabels.map(roomLabelItem => {
295
- const sortIndex = sortedRoomLabelItems.findIndex(item => item.roomLabelItem.id === roomLabelItem.id);
296
- if (sortIndex !== undefined) return Object.assign(Object.assign({}, roomLabelItem), { zIndex: sortIndex * 10 });
297
- return roomLabelItem;
298
+ const zIndex = minItemLen * 10;
299
+ return Object.assign(Object.assign({}, item), { visible, transform, zIndex });
298
300
  });
301
+
302
+ return formatedItems;
299
303
  }
300
304
 
301
305
  function onFiveCameraUpdate() {
302
- $$invalidate(0, roomLabels = getFormatedRoomLabels(five, roomLabels));
306
+ $$invalidate(0, roomLabels = getFormatedRoomLabels(rendererSize));
307
+ }
308
+
309
+ function onFiveModelShownFloorChange(floorIndex) {
310
+ $$invalidate(4, shownFloor = floorIndex);
303
311
  }
304
312
 
305
313
  five.on('cameraUpdate', onFiveCameraUpdate);
306
- five.on('modelShownFloorChange', onFiveCameraUpdate);
314
+ five.on('modelShownFloorChange', onFiveModelShownFloorChange);
307
315
 
308
316
  svelte.onDestroy(() => {
309
317
  five.off('cameraUpdate', onFiveCameraUpdate);
310
- five.off('modelShownFloorChange', onFiveCameraUpdate);
311
- });
312
-
313
- svelte.onMount(() => {
314
- onFiveCameraUpdate();
318
+ five.off('modelShownFloorChange', onFiveModelShownFloorChange);
315
319
  });
316
320
 
317
321
  function div_elementresize_handler() {
@@ -326,7 +330,39 @@ function instance($$self, $$props, $$invalidate) {
326
330
  if ('roomLabels' in $$props) $$invalidate(0, roomLabels = $$props.roomLabels);
327
331
  };
328
332
 
329
- return [roomLabels, five, containerWidth, containerHeight, div_elementresize_handler];
333
+ $$self.$$.update = () => {
334
+ if ($$self.$$.dirty & /*containerWidth, containerHeight*/ 12) {
335
+ $$invalidate(5, rendererSize = { x: containerWidth, y: containerHeight });
336
+ }
337
+
338
+ if ($$self.$$.dirty & /*rendererSize*/ 32) {
339
+ {
340
+ // rendererSize 变化时,触发 reRender
341
+ $$invalidate(0, roomLabels = getFormatedRoomLabels(rendererSize));
342
+ }
343
+ }
344
+
345
+ if ($$self.$$.dirty & /*roomLabels, shownFloor*/ 17) {
346
+ {
347
+ // shownFloor 变化时,更新 item visible
348
+ $$invalidate(0, roomLabels = roomLabels.map(item => {
349
+ const isLabelInFloor = shownFloor === null || item.floorIndex === shownFloor;
350
+ const visible = isLabelInFloor ? item.visible : false;
351
+ return Object.assign(Object.assign({}, item), { visible });
352
+ }));
353
+ }
354
+ }
355
+ };
356
+
357
+ return [
358
+ roomLabels,
359
+ five,
360
+ containerWidth,
361
+ containerHeight,
362
+ shownFloor,
363
+ rendererSize,
364
+ div_elementresize_handler
365
+ ];
330
366
  }
331
367
 
332
368
  class RoomLabelItems extends internal.SvelteComponent {
package/dist/index.es.js CHANGED
@@ -2,7 +2,7 @@ import * as THREE from 'three';
2
2
  import { Vector3, Scene, Group, Raycaster, MeshBasicMaterial, CanvasTexture, AnimationMixer, Vector2, Color, TextureLoader, PlaneGeometry, sRGBEncoding, Mesh, CurvePath, LineCurve3, TubeGeometry, DoubleSide, SphereGeometry } from 'three';
3
3
  import { CSS3DRenderer, CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer';
4
4
  import { Line as Line$1 } from '@realsee/five/line';
5
- import { SvelteComponent, init, safe_not_equal, append_styles, element, text, space, attr, set_style, toggle_class, insert, append, listen, set_data, noop, detach, empty, create_component, mount_component, transition_in, transition_out, destroy_component, add_render_callback, add_resize_listener, group_outros, update_keyed_each, outro_and_destroy_block, check_outros, src_url_equal, HtmlTag, get_spread_update, assign, destroy_block, destroy_each, svg_element, null_to_empty, create_in_transition, binding_callbacks } from 'svelte/internal';
5
+ import { SvelteComponent, init, safe_not_equal, append_styles, element, text, space, attr, set_style, toggle_class, insert, append, listen, set_data, noop, detach, empty, create_component, mount_component, transition_in, transition_out, destroy_component, add_render_callback, add_resize_listener, group_outros, update_keyed_each, outro_and_destroy_block, check_outros, globals, src_url_equal, HtmlTag, get_spread_update, assign, destroy_block, destroy_each, svg_element, null_to_empty, create_in_transition, binding_callbacks } from 'svelte/internal';
6
6
  import { onDestroy, onMount, afterUpdate, beforeUpdate } from 'svelte';
7
7
  import { linear } from 'svelte/easing';
8
8
  import { fade } from 'svelte/transition';
@@ -562,17 +562,19 @@ class RoomLabelItem extends SvelteComponent {
562
562
 
563
563
  /* src/ModelRoomLabelPlugin/RoomLabelItems.svelte generated by Svelte v3.47.0 */
564
564
 
565
+ const { Map: Map_1 } = globals;
566
+
565
567
  function add_css$l(target) {
566
568
  append_styles(target, "svelte-9eg4zi", ".room-labels-container.svelte-9eg4zi{width:100%;height:100%;position:relative;color:#fff}");
567
569
  }
568
570
 
569
571
  function get_each_context$9(ctx, list, i) {
570
572
  const child_ctx = ctx.slice();
571
- child_ctx[9] = list[i];
573
+ child_ctx[12] = list[i];
572
574
  return child_ctx;
573
575
  }
574
576
 
575
- // (70:2) {#each roomLabels as roomLableItem (roomLableItem.id)}
577
+ // (82:2) {#each roomLabels as roomLableItem (roomLableItem.id)}
576
578
  function create_each_block$9(key_1, ctx) {
577
579
  let first;
578
580
  let roomlabelitem;
@@ -580,7 +582,7 @@ function create_each_block$9(key_1, ctx) {
580
582
 
581
583
  roomlabelitem = new RoomLabelItem({
582
584
  props: {
583
- roomLabel: /*roomLableItem*/ ctx[9],
585
+ roomLabel: /*roomLableItem*/ ctx[12],
584
586
  five: /*five*/ ctx[1]
585
587
  }
586
588
  });
@@ -601,7 +603,7 @@ function create_each_block$9(key_1, ctx) {
601
603
  p(new_ctx, dirty) {
602
604
  ctx = new_ctx;
603
605
  const roomlabelitem_changes = {};
604
- if (dirty & /*roomLabels*/ 1) roomlabelitem_changes.roomLabel = /*roomLableItem*/ ctx[9];
606
+ if (dirty & /*roomLabels*/ 1) roomlabelitem_changes.roomLabel = /*roomLableItem*/ ctx[12];
605
607
  if (dirty & /*five*/ 2) roomlabelitem_changes.five = /*five*/ ctx[1];
606
608
  roomlabelitem.$set(roomlabelitem_changes);
607
609
  },
@@ -624,11 +626,11 @@ function create_each_block$9(key_1, ctx) {
624
626
  function create_fragment$p(ctx) {
625
627
  let div;
626
628
  let each_blocks = [];
627
- let each_1_lookup = new Map();
629
+ let each_1_lookup = new Map_1();
628
630
  let div_resize_listener;
629
631
  let current;
630
632
  let each_value = /*roomLabels*/ ctx[0];
631
- const get_key = ctx => /*roomLableItem*/ ctx[9].id;
633
+ const get_key = ctx => /*roomLableItem*/ ctx[12].id;
632
634
 
633
635
  for (let i = 0; i < each_value.length; i += 1) {
634
636
  let child_ctx = get_each_context$9(ctx, each_value, i);
@@ -645,7 +647,7 @@ function create_fragment$p(ctx) {
645
647
  }
646
648
 
647
649
  attr(div, "class", "room-labels-container svelte-9eg4zi");
648
- add_render_callback(() => /*div_elementresize_handler*/ ctx[4].call(div));
650
+ add_render_callback(() => /*div_elementresize_handler*/ ctx[6].call(div));
649
651
  },
650
652
  m(target, anchor) {
651
653
  insert(target, div, anchor);
@@ -654,7 +656,7 @@ function create_fragment$p(ctx) {
654
656
  each_blocks[i].m(div, null);
655
657
  }
656
658
 
657
- div_resize_listener = add_resize_listener(div, /*div_elementresize_handler*/ ctx[4].bind(div));
659
+ div_resize_listener = add_resize_listener(div, /*div_elementresize_handler*/ ctx[6].bind(div));
658
660
  current = true;
659
661
  },
660
662
  p(ctx, [dirty]) {
@@ -694,22 +696,17 @@ function create_fragment$p(ctx) {
694
696
  }
695
697
 
696
698
  function instance$p($$self, $$props, $$invalidate) {
699
+ let rendererSize;
697
700
  let { five } = $$props;
698
701
  let { roomLabels } = $$props;
699
702
  let containerWidth;
700
703
  let containerHeight;
704
+ let shownFloor = null;
701
705
 
702
- function getLabelVisible(five, roomLabelItem) {
703
- // 先看是不是在当前展示的楼层上
704
- const isLabelInFloor = five.model.shownFloor === null || roomLabelItem.floorIndex === five.model.shownFloor;
705
-
706
- if (!isLabelInFloor) return false;
707
-
708
- // 再看是不是被模型遮挡
706
+ function getLabelVisible(item) {
709
707
  const raycaster = new Raycaster();
710
-
711
708
  const cameraPosition = five.camera.position.clone();
712
- const position = new Vector3(roomLabelItem.position.x, roomLabelItem.position.y, roomLabelItem.position.z);
709
+ const position = new Vector3(item.position.x, item.position.y, item.position.z);
713
710
  const vectorDistance = position.distanceTo(cameraPosition);
714
711
  raycaster.set(cameraPosition.clone(), position.clone().sub(cameraPosition).normalize());
715
712
  const [intersection] = five.model.intersectRaycaster(raycaster);
@@ -717,53 +714,60 @@ function instance$p($$self, $$props, $$invalidate) {
717
714
  return true;
718
715
  }
719
716
 
720
- function getLabelTransform(five, roomLabelItem) {
721
- const position = new Vector3(roomLabelItem.position.x, roomLabelItem.position.y, roomLabelItem.position.z);
717
+ function getLabelTransform(item, rendererSize) {
718
+ const position = new Vector3(item.position.x, item.position.y, item.position.z);
722
719
  const mouse = position.clone().project(five.camera);
723
- const xOffset = Math.ceil((mouse.x + 1) / 2 * containerWidth);
724
- const yOffset = Math.ceil((-mouse.y + 1) / 2 * containerHeight);
720
+ const xOffset = Math.ceil((mouse.x + 1) / 2 * rendererSize.x);
721
+ const yOffset = Math.ceil((-mouse.y + 1) / 2 * rendererSize.y);
725
722
  return `translate(${xOffset}px, ${yOffset}px)`;
726
723
  }
727
724
 
728
- function getFormatedRoomLabels(five, labels) {
729
- const newLabels = labels.map(roomLabelItem => {
730
- // 计算是否可见,如果不可见,不会更新位置
731
- const visible = getLabelVisible(five, roomLabelItem);
725
+ function getFormatedRoomLabels(rendererSize) {
726
+ // 因为 item distance 需要重复计算,所以缓存一下
727
+ const distanceMap = new Map();
728
+
729
+ function getItemDistance(item) {
730
+ const cacheDistance = distanceMap.get(item.id);
731
+ if (cacheDistance) return cacheDistance;
732
+ const { x, y, z } = item.position;
733
+ const distance = new Vector3(x, y, z).clone().distanceTo(five.camera.position);
734
+ distanceMap.set(item.id, distance);
735
+ return distance;
736
+ }
732
737
 
733
- if (!visible) return Object.assign(Object.assign({}, roomLabelItem), { visible });
738
+ const formatedItems = roomLabels.map(item => {
739
+ const visible = getLabelVisible(item);
734
740
 
735
- // 更新位置
736
- const transform = getLabelTransform(five, roomLabelItem);
741
+ const transform = visible
742
+ ? getLabelTransform(item, rendererSize)
743
+ : item.transform;
737
744
 
738
- return Object.assign(Object.assign({}, roomLabelItem), { visible, transform });
739
- });
745
+ const itemDistance = getItemDistance(item);
740
746
 
741
- const sortedRoomLabelItems = newLabels.filter(({ visible }) => visible).map(roomLabelItem => ({
742
- roomLabelItem,
743
- distance: new Vector3(...Object.values(roomLabelItem.position)).clone().distanceTo(five.camera.position)
744
- })).sort((a, b) => a.distance - b.distance);
747
+ // visible === true item 中,distance 比自己小的 item 个数
748
+ const minItemLen = roomLabels.filter(item => item.visible && getItemDistance(item) < itemDistance).length;
745
749
 
746
- return newLabels.map(roomLabelItem => {
747
- const sortIndex = sortedRoomLabelItems.findIndex(item => item.roomLabelItem.id === roomLabelItem.id);
748
- if (sortIndex !== undefined) return Object.assign(Object.assign({}, roomLabelItem), { zIndex: sortIndex * 10 });
749
- return roomLabelItem;
750
+ const zIndex = minItemLen * 10;
751
+ return Object.assign(Object.assign({}, item), { visible, transform, zIndex });
750
752
  });
753
+
754
+ return formatedItems;
751
755
  }
752
756
 
753
757
  function onFiveCameraUpdate() {
754
- $$invalidate(0, roomLabels = getFormatedRoomLabels(five, roomLabels));
758
+ $$invalidate(0, roomLabels = getFormatedRoomLabels(rendererSize));
759
+ }
760
+
761
+ function onFiveModelShownFloorChange(floorIndex) {
762
+ $$invalidate(4, shownFloor = floorIndex);
755
763
  }
756
764
 
757
765
  five.on('cameraUpdate', onFiveCameraUpdate);
758
- five.on('modelShownFloorChange', onFiveCameraUpdate);
766
+ five.on('modelShownFloorChange', onFiveModelShownFloorChange);
759
767
 
760
768
  onDestroy(() => {
761
769
  five.off('cameraUpdate', onFiveCameraUpdate);
762
- five.off('modelShownFloorChange', onFiveCameraUpdate);
763
- });
764
-
765
- onMount(() => {
766
- onFiveCameraUpdate();
770
+ five.off('modelShownFloorChange', onFiveModelShownFloorChange);
767
771
  });
768
772
 
769
773
  function div_elementresize_handler() {
@@ -778,7 +782,39 @@ function instance$p($$self, $$props, $$invalidate) {
778
782
  if ('roomLabels' in $$props) $$invalidate(0, roomLabels = $$props.roomLabels);
779
783
  };
780
784
 
781
- return [roomLabels, five, containerWidth, containerHeight, div_elementresize_handler];
785
+ $$self.$$.update = () => {
786
+ if ($$self.$$.dirty & /*containerWidth, containerHeight*/ 12) {
787
+ $$invalidate(5, rendererSize = { x: containerWidth, y: containerHeight });
788
+ }
789
+
790
+ if ($$self.$$.dirty & /*rendererSize*/ 32) {
791
+ {
792
+ // rendererSize 变化时,触发 reRender
793
+ $$invalidate(0, roomLabels = getFormatedRoomLabels(rendererSize));
794
+ }
795
+ }
796
+
797
+ if ($$self.$$.dirty & /*roomLabels, shownFloor*/ 17) {
798
+ {
799
+ // shownFloor 变化时,更新 item visible
800
+ $$invalidate(0, roomLabels = roomLabels.map(item => {
801
+ const isLabelInFloor = shownFloor === null || item.floorIndex === shownFloor;
802
+ const visible = isLabelInFloor ? item.visible : false;
803
+ return Object.assign(Object.assign({}, item), { visible });
804
+ }));
805
+ }
806
+ }
807
+ };
808
+
809
+ return [
810
+ roomLabels,
811
+ five,
812
+ containerWidth,
813
+ containerHeight,
814
+ shownFloor,
815
+ rendererSize,
816
+ div_elementresize_handler
817
+ ];
782
818
  }
783
819
 
784
820
  class RoomLabelItems extends SvelteComponent {
@@ -14383,7 +14419,7 @@ function get_each_context(ctx, list, i) {
14383
14419
  return child_ctx;
14384
14420
  }
14385
14421
 
14386
- // (162:1) {#each renderItemLabels as itemLabelItem (itemLabelItem.id)}
14422
+ // (163:1) {#each renderItemLabels as itemLabelItem (itemLabelItem.id)}
14387
14423
  function create_each_block(key_1, ctx) {
14388
14424
  let first;
14389
14425
  let itemlabelitem;