fl-web-component 2.0.0-beta.8 → 2.0.0
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.
- package/dist/fl-web-component.common.js +34645 -1611
- package/dist/fl-web-component.common.js.map +1 -1
- package/dist/fl-web-component.css +1 -1
- package/package.json +4 -15
- package/packages/components/com-card/index.vue +1 -1
- package/packages/components/com-flcanvas/components/bspline.js +31 -34
- package/packages/components/com-flcanvas/components/entityFormatting.js +810 -849
- package/packages/components/com-flcanvas/components/round10.js +17 -17
- package/packages/components/com-flcanvas/index.vue +314 -333
- package/packages/components/com-formDialog/index.vue +6 -4
- package/packages/components/com-graphics/component/ann-tool.vue +263 -208
- package/packages/components/com-graphics/index.vue +366 -773
- package/packages/components/com-graphics/pid.vue +304 -295
- package/packages/components/com-table/column-default.vue +2 -3
- package/packages/components/com-table/column-dynamic.vue +7 -4
- package/packages/components/com-table/column.vue +1 -2
- package/packages/components/com-table/index.vue +6 -5
- package/packages/components/com-tabs/index.vue +1 -2
- package/packages/components/com-tiles/index.vue +134 -136
- package/packages/components/com-treeDynamic/index.vue +1 -1
- package/packages/utils/StreamLoader.js +1548 -1489
- package/packages/utils/StreamLoaderParser.worker.js +9 -14
- package/src/main.js +2 -8
- package/src/utils/cloud.js +28 -28
- package/src/utils/cursor.js +11 -9
- package/src/utils/flgltf-parser.js +257 -245
- package/src/utils/instance-parser.js +20 -22
- package/src/utils/mini-devtool.js +94 -39
- package/src/utils/threejs/measure-angle.js +51 -13
- package/src/utils/threejs/measure-area.js +43 -12
- package/src/utils/threejs/measure-distance.js +43 -12
- package/src/utils/threejs/rain-shader.js +10 -10
- package/src/utils/threejs/snow-shader.js +9 -9
|
@@ -33,14 +33,7 @@ var [
|
|
|
33
33
|
while (true) yield v;
|
|
34
34
|
})(null);
|
|
35
35
|
|
|
36
|
-
var [
|
|
37
|
-
lastTime,
|
|
38
|
-
firstTime,
|
|
39
|
-
fpsClock,
|
|
40
|
-
timeStamp,
|
|
41
|
-
progress,
|
|
42
|
-
lastMiddleClickTime,
|
|
43
|
-
] = (function* (v) {
|
|
36
|
+
var [lastTime, firstTime, fpsClock, timeStamp, progress, lastMiddleClickTime] = (function* (v) {
|
|
44
37
|
while (true) yield v;
|
|
45
38
|
})(0);
|
|
46
39
|
var singleFrameTime = 1 / 30;
|
|
@@ -66,14 +59,7 @@ var [spaceUp] = (function* (v) {
|
|
|
66
59
|
const renderedThisFrame = new Set();
|
|
67
60
|
|
|
68
61
|
function markRendered(mesh) {
|
|
69
|
-
mesh.onBeforeRender = function (
|
|
70
|
-
renderer,
|
|
71
|
-
scene,
|
|
72
|
-
camera,
|
|
73
|
-
geometry,
|
|
74
|
-
material,
|
|
75
|
-
group,
|
|
76
|
-
) {
|
|
62
|
+
mesh.onBeforeRender = function (renderer, scene, camera, geometry, material, group) {
|
|
77
63
|
renderedThisFrame.add(mesh);
|
|
78
64
|
};
|
|
79
65
|
}
|
|
@@ -145,11 +131,7 @@ import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
|
|
|
145
131
|
import MeasureDistance from '@/utils/threejs/measure-distance.js';
|
|
146
132
|
import MeasureArea from '@/utils/threejs/measure-area.js';
|
|
147
133
|
import MeasureAngle from '@/utils/threejs/measure-angle.js';
|
|
148
|
-
import {
|
|
149
|
-
parseData,
|
|
150
|
-
processMeshData,
|
|
151
|
-
processNodeData,
|
|
152
|
-
} from '@/utils/flgltf-parser';
|
|
134
|
+
import { parseData, processMeshData, processNodeData } from '@/utils/flgltf-parser';
|
|
153
135
|
import {
|
|
154
136
|
handleInstancedMeshModel,
|
|
155
137
|
resetProcessingState,
|
|
@@ -171,9 +153,7 @@ import boxJson from './box.json';
|
|
|
171
153
|
import { StreamLoader } from '../../utils/StreamLoader.js';
|
|
172
154
|
import StreamLoaderParserWorker from '../../utils/StreamLoaderParser.worker.js';
|
|
173
155
|
|
|
174
|
-
const isDebug =
|
|
175
|
-
process.env.NODE_ENV !== 'production' ||
|
|
176
|
-
process.env.VUE_APP_IS_WATCH === true;
|
|
156
|
+
const isDebug = process.env.NODE_ENV !== 'production' || process.env.VUE_APP_IS_WATCH === true;
|
|
177
157
|
// const isDebug = false;
|
|
178
158
|
|
|
179
159
|
export default {
|
|
@@ -285,17 +265,13 @@ export default {
|
|
|
285
265
|
raycaster = new this.THREE.Raycaster();
|
|
286
266
|
sceneClock = new this.THREE.Clock();
|
|
287
267
|
mouse = new this.THREE.Vector2();
|
|
288
|
-
renderTarget = new this.THREE.WebGLRenderTarget(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
stencilBuffer: true,
|
|
296
|
-
samples: 0,
|
|
297
|
-
},
|
|
298
|
-
);
|
|
268
|
+
renderTarget = new this.THREE.WebGLRenderTarget(window.innerWidth, window.innerHeight, {
|
|
269
|
+
minFilter: this.THREE.LinearFilter,
|
|
270
|
+
magFilter: this.THREE.LinearFilter,
|
|
271
|
+
format: this.THREE.RGBAFormat,
|
|
272
|
+
stencilBuffer: true,
|
|
273
|
+
samples: 0,
|
|
274
|
+
});
|
|
299
275
|
},
|
|
300
276
|
mounted() {
|
|
301
277
|
instructions = document.getElementById('fl-model');
|
|
@@ -314,11 +290,7 @@ export default {
|
|
|
314
290
|
let isMobileDevice = this.isMobileDevice();
|
|
315
291
|
if (isMobileDevice) {
|
|
316
292
|
renderer.domElement.addEventListener('pointerup', this.mouseClick, false);
|
|
317
|
-
renderer.domElement.addEventListener(
|
|
318
|
-
'pointerdown',
|
|
319
|
-
this.mouseDown,
|
|
320
|
-
false,
|
|
321
|
-
);
|
|
293
|
+
renderer.domElement.addEventListener('pointerdown', this.mouseDown, false);
|
|
322
294
|
} else {
|
|
323
295
|
renderer.domElement.addEventListener('mouseup', this.mouseClick, false);
|
|
324
296
|
renderer.domElement.addEventListener('mousedown', this.mouseDown, false);
|
|
@@ -334,8 +306,7 @@ export default {
|
|
|
334
306
|
return `${instancedMesh.uuid}:${instanceIndex}`;
|
|
335
307
|
},
|
|
336
308
|
ensureOutlineInstanceProxy(instancedMesh, instanceIndex) {
|
|
337
|
-
if (!scene || !instancedMesh || !instancedMesh.isInstancedMesh)
|
|
338
|
-
return null;
|
|
309
|
+
if (!scene || !instancedMesh || !instancedMesh.isInstancedMesh) return null;
|
|
339
310
|
const state = this.noObserver;
|
|
340
311
|
if (!state || !state.outlineInstanceProxyMap) return null;
|
|
341
312
|
|
|
@@ -379,8 +350,7 @@ export default {
|
|
|
379
350
|
},
|
|
380
351
|
removeOutlineInstanceProxy(instancedMesh, instanceIndex) {
|
|
381
352
|
const state = this.noObserver;
|
|
382
|
-
if (!state || !state.outlineInstanceProxyMap || !instancedMesh)
|
|
383
|
-
return null;
|
|
353
|
+
if (!state || !state.outlineInstanceProxyMap || !instancedMesh) return null;
|
|
384
354
|
const key = this.getOutlineInstanceProxyKey(instancedMesh, instanceIndex);
|
|
385
355
|
const proxy = state.outlineInstanceProxyMap.get(key);
|
|
386
356
|
if (!proxy) return null;
|
|
@@ -435,8 +405,7 @@ export default {
|
|
|
435
405
|
let throttleTimer = null;
|
|
436
406
|
|
|
437
407
|
return function (...args) {
|
|
438
|
-
const currentDelay =
|
|
439
|
-
typeof delay === 'function' ? delay(...args) : delay;
|
|
408
|
+
const currentDelay = typeof delay === 'function' ? delay(...args) : delay;
|
|
440
409
|
|
|
441
410
|
// 如果返回 'throttle' 策略,则执行节流逻辑 (默认间隔 300ms,或可扩展)
|
|
442
411
|
if (
|
|
@@ -444,9 +413,7 @@ export default {
|
|
|
444
413
|
(typeof currentDelay === 'object' && currentDelay.type === 'throttle')
|
|
445
414
|
) {
|
|
446
415
|
const limit =
|
|
447
|
-
typeof currentDelay === 'object' && currentDelay.limit
|
|
448
|
-
? currentDelay.limit
|
|
449
|
-
: 300;
|
|
416
|
+
typeof currentDelay === 'object' && currentDelay.limit ? currentDelay.limit : 300;
|
|
450
417
|
const now = Date.now();
|
|
451
418
|
|
|
452
419
|
// 清除之前的防抖定时器,避免冲突
|
|
@@ -494,7 +461,7 @@ export default {
|
|
|
494
461
|
error: 'Worker is not initialized',
|
|
495
462
|
});
|
|
496
463
|
}
|
|
497
|
-
return new Promise(
|
|
464
|
+
return new Promise(resolve => {
|
|
498
465
|
const id = state.occlusionWorkerRequestId++;
|
|
499
466
|
state.occlusionWorkerRequestMap.set(id, { resolve });
|
|
500
467
|
state.occlusionWorker.postMessage({ id, type, data }, transferable);
|
|
@@ -503,8 +470,7 @@ export default {
|
|
|
503
470
|
scanOcclusionBufferSync(buffer, sw, sh, stride, maxIdx, minSampleCount) {
|
|
504
471
|
const indices = [];
|
|
505
472
|
if (!buffer || !sw || !sh || !maxIdx) return { indices };
|
|
506
|
-
const view =
|
|
507
|
-
buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
473
|
+
const view = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
508
474
|
const step = Math.max(1, stride || 1);
|
|
509
475
|
const minCount = Math.max(1, minSampleCount || 1);
|
|
510
476
|
const counts = new Uint32Array(maxIdx + 1);
|
|
@@ -526,8 +492,7 @@ export default {
|
|
|
526
492
|
},
|
|
527
493
|
async scanOcclusionIndices(buffer, sw, sh, stride, maxIdx, minSampleCount) {
|
|
528
494
|
const state = this.noObserver;
|
|
529
|
-
const canWorker =
|
|
530
|
-
state && state.occlusionWorker && buffer && buffer.buffer;
|
|
495
|
+
const canWorker = state && state.occlusionWorker && buffer && buffer.buffer;
|
|
531
496
|
if (canWorker) {
|
|
532
497
|
const response = await this.occlusionWorkerRequest(
|
|
533
498
|
'occlusionScan',
|
|
@@ -539,12 +504,9 @@ export default {
|
|
|
539
504
|
maxIdx,
|
|
540
505
|
minSampleCount,
|
|
541
506
|
},
|
|
542
|
-
[buffer.buffer]
|
|
507
|
+
[buffer.buffer]
|
|
543
508
|
);
|
|
544
|
-
const restored =
|
|
545
|
-
response && response.buffer
|
|
546
|
-
? new Uint8Array(response.buffer)
|
|
547
|
-
: buffer;
|
|
509
|
+
const restored = response && response.buffer ? new Uint8Array(response.buffer) : buffer;
|
|
548
510
|
if (response && response.type === 'success' && response.result) {
|
|
549
511
|
return {
|
|
550
512
|
indices: response.result.indices || [],
|
|
@@ -557,18 +519,11 @@ export default {
|
|
|
557
519
|
sh,
|
|
558
520
|
stride,
|
|
559
521
|
maxIdx,
|
|
560
|
-
minSampleCount
|
|
522
|
+
minSampleCount
|
|
561
523
|
);
|
|
562
524
|
return { indices: syncRes.indices, buffer: restored.buffer };
|
|
563
525
|
}
|
|
564
|
-
const syncRes = this.scanOcclusionBufferSync(
|
|
565
|
-
buffer,
|
|
566
|
-
sw,
|
|
567
|
-
sh,
|
|
568
|
-
stride,
|
|
569
|
-
maxIdx,
|
|
570
|
-
minSampleCount,
|
|
571
|
-
);
|
|
526
|
+
const syncRes = this.scanOcclusionBufferSync(buffer, sw, sh, stride, maxIdx, minSampleCount);
|
|
572
527
|
return {
|
|
573
528
|
indices: syncRes.indices,
|
|
574
529
|
buffer: buffer && buffer.buffer ? buffer.buffer : null,
|
|
@@ -595,7 +550,7 @@ export default {
|
|
|
595
550
|
|
|
596
551
|
const box = new this.THREE.Box3(
|
|
597
552
|
new this.THREE.Vector3(minX, minY, minZ),
|
|
598
|
-
new this.THREE.Vector3(maxX, maxY, maxZ)
|
|
553
|
+
new this.THREE.Vector3(maxX, maxY, maxZ)
|
|
599
554
|
).applyMatrix4(bizToThreeMatrix);
|
|
600
555
|
this.noObserver.sceneBoxes.set(documentId, box);
|
|
601
556
|
} else {
|
|
@@ -665,28 +620,16 @@ export default {
|
|
|
665
620
|
// 如果是 flag=3,解析并存储中心点、半轴长、旋转矩阵
|
|
666
621
|
else if (it.flag === 3 && it.obb && it.obb.length === 15) {
|
|
667
622
|
const obbData = it.obb;
|
|
668
|
-
const center = new this.THREE.Vector3(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
obbData[2],
|
|
672
|
-
);
|
|
673
|
-
const halfSize = new this.THREE.Vector3(
|
|
674
|
-
obbData[3],
|
|
675
|
-
obbData[4],
|
|
676
|
-
obbData[5],
|
|
677
|
-
);
|
|
678
|
-
const rotation = new this.THREE.Matrix3().fromArray(
|
|
679
|
-
obbData.slice(6, 15),
|
|
680
|
-
);
|
|
623
|
+
const center = new this.THREE.Vector3(obbData[0], obbData[1], obbData[2]);
|
|
624
|
+
const halfSize = new this.THREE.Vector3(obbData[3], obbData[4], obbData[5]);
|
|
625
|
+
const rotation = new this.THREE.Matrix3().fromArray(obbData.slice(6, 15));
|
|
681
626
|
|
|
682
627
|
// 预计算局部到世界的变换矩阵 (不含 bizToThreeMatrix,后续渲染时统一处理)
|
|
683
|
-
const rotationMatrix4 = new this.THREE.Matrix4().setFromMatrix3(
|
|
684
|
-
rotation,
|
|
685
|
-
);
|
|
628
|
+
const rotationMatrix4 = new this.THREE.Matrix4().setFromMatrix3(rotation);
|
|
686
629
|
const obbMatrix = new this.THREE.Matrix4().makeTranslation(
|
|
687
630
|
center.x,
|
|
688
631
|
center.y,
|
|
689
|
-
center.z
|
|
632
|
+
center.z
|
|
690
633
|
);
|
|
691
634
|
obbMatrix.multiply(rotationMatrix4);
|
|
692
635
|
|
|
@@ -701,16 +644,8 @@ export default {
|
|
|
701
644
|
const subBoxes = [];
|
|
702
645
|
for (let k = 0; k < it.obb.length; k += 6) {
|
|
703
646
|
if (k + 5 < it.obb.length) {
|
|
704
|
-
const min = new this.THREE.Vector3(
|
|
705
|
-
|
|
706
|
-
it.obb[k + 1],
|
|
707
|
-
it.obb[k + 2],
|
|
708
|
-
);
|
|
709
|
-
const max = new this.THREE.Vector3(
|
|
710
|
-
it.obb[k + 3],
|
|
711
|
-
it.obb[k + 4],
|
|
712
|
-
it.obb[k + 5],
|
|
713
|
-
);
|
|
647
|
+
const min = new this.THREE.Vector3(it.obb[k], it.obb[k + 1], it.obb[k + 2]);
|
|
648
|
+
const max = new this.THREE.Vector3(it.obb[k + 3], it.obb[k + 4], it.obb[k + 5]);
|
|
714
649
|
subBoxes.push({ min, max });
|
|
715
650
|
}
|
|
716
651
|
}
|
|
@@ -727,7 +662,7 @@ export default {
|
|
|
727
662
|
} else {
|
|
728
663
|
const modelIds = this.noObserver.documentModelIds.get(documentId);
|
|
729
664
|
if (modelIds) {
|
|
730
|
-
modelIds.forEach(
|
|
665
|
+
modelIds.forEach(id => {
|
|
731
666
|
this._boxIndex.delete(id);
|
|
732
667
|
});
|
|
733
668
|
this.noObserver.documentModelIds.delete(documentId);
|
|
@@ -752,7 +687,7 @@ export default {
|
|
|
752
687
|
let maxX = -Infinity,
|
|
753
688
|
maxY = -Infinity,
|
|
754
689
|
maxZ = -Infinity;
|
|
755
|
-
this._boxIndex.forEach(
|
|
690
|
+
this._boxIndex.forEach(box => {
|
|
756
691
|
if (!box || !box.isBox3) return;
|
|
757
692
|
const mn = box.min;
|
|
758
693
|
const mx = box.max;
|
|
@@ -765,7 +700,7 @@ export default {
|
|
|
765
700
|
});
|
|
766
701
|
const rootBox = new this.THREE.Box3(
|
|
767
702
|
new this.THREE.Vector3(minX, minY, minZ),
|
|
768
|
-
new this.THREE.Vector3(maxX, maxY, maxZ)
|
|
703
|
+
new this.THREE.Vector3(maxX, maxY, maxZ)
|
|
769
704
|
);
|
|
770
705
|
this._octreeMaxItems = 64;
|
|
771
706
|
this._octreeMaxDepth = 12;
|
|
@@ -780,7 +715,7 @@ export default {
|
|
|
780
715
|
const mid = new this.THREE.Vector3(
|
|
781
716
|
(min.x + max.x) * 0.5,
|
|
782
717
|
(min.y + max.y) * 0.5,
|
|
783
|
-
(min.z + max.z) * 0.5
|
|
718
|
+
(min.z + max.z) * 0.5
|
|
784
719
|
);
|
|
785
720
|
const children = [];
|
|
786
721
|
for (let i = 0; i < 8; i++) {
|
|
@@ -822,10 +757,7 @@ export default {
|
|
|
822
757
|
_octreeInsert(node, id, box) {
|
|
823
758
|
if (!node.children) {
|
|
824
759
|
node.items.push({ id, box });
|
|
825
|
-
if (
|
|
826
|
-
node.items.length > this._octreeMaxItems &&
|
|
827
|
-
node.depth < this._octreeMaxDepth
|
|
828
|
-
) {
|
|
760
|
+
if (node.items.length > this._octreeMaxItems && node.depth < this._octreeMaxDepth) {
|
|
829
761
|
this._octreeSubdivide(node);
|
|
830
762
|
}
|
|
831
763
|
return;
|
|
@@ -848,7 +780,7 @@ export default {
|
|
|
848
780
|
const frustum = new this.THREE.Frustum();
|
|
849
781
|
const vpMatrix = new this.THREE.Matrix4().multiplyMatrices(
|
|
850
782
|
camera.projectionMatrix,
|
|
851
|
-
camera.matrixWorldInverse
|
|
783
|
+
camera.matrixWorldInverse
|
|
852
784
|
);
|
|
853
785
|
frustum.setFromProjectionMatrix(vpMatrix);
|
|
854
786
|
return frustum;
|
|
@@ -876,8 +808,7 @@ export default {
|
|
|
876
808
|
if (node.items && node.items.length) {
|
|
877
809
|
for (let k = 0; k < node.items.length; k++) {
|
|
878
810
|
const it = node.items[k];
|
|
879
|
-
if (excludeSet && excludeSet.size > 0 && excludeSet.has(it.id))
|
|
880
|
-
continue;
|
|
811
|
+
if (excludeSet && excludeSet.size > 0 && excludeSet.has(it.id)) continue;
|
|
881
812
|
|
|
882
813
|
// 1. 粗测:World AABB
|
|
883
814
|
if (frustum.intersectsBox(it.box)) {
|
|
@@ -930,9 +861,7 @@ export default {
|
|
|
930
861
|
|
|
931
862
|
// 获取最新相机位置
|
|
932
863
|
camera.updateMatrixWorld(true);
|
|
933
|
-
const camPos = new this.THREE.Vector3().setFromMatrixPosition(
|
|
934
|
-
camera.matrixWorld,
|
|
935
|
-
);
|
|
864
|
+
const camPos = new this.THREE.Vector3().setFromMatrixPosition(camera.matrixWorld);
|
|
936
865
|
|
|
937
866
|
const min = sceneBoundingBox.min;
|
|
938
867
|
const max = sceneBoundingBox.max;
|
|
@@ -999,7 +928,7 @@ export default {
|
|
|
999
928
|
const ndcBase = new this.THREE.Vector3(
|
|
1000
929
|
(x / width) * 2 - 1,
|
|
1001
930
|
-(y / height) * 2 + 1,
|
|
1002
|
-
undefined
|
|
931
|
+
undefined
|
|
1003
932
|
);
|
|
1004
933
|
|
|
1005
934
|
const ndcNear = ndcBase.clone();
|
|
@@ -1029,14 +958,9 @@ export default {
|
|
|
1029
958
|
frustumPoints[4],
|
|
1030
959
|
frustumPoints[6],
|
|
1031
960
|
];
|
|
1032
|
-
const farCorners = [
|
|
1033
|
-
frustumPoints[1],
|
|
1034
|
-
frustumPoints[3],
|
|
1035
|
-
frustumPoints[5],
|
|
1036
|
-
frustumPoints[7],
|
|
1037
|
-
];
|
|
961
|
+
const farCorners = [frustumPoints[1], frustumPoints[3], frustumPoints[5], frustumPoints[7]];
|
|
1038
962
|
const volumeCorners = nearCorners.concat(farCorners);
|
|
1039
|
-
const projectedPoints = volumeCorners.map(
|
|
963
|
+
const projectedPoints = volumeCorners.map(p => {
|
|
1040
964
|
const yProj = -(a * p.x + c * p.z + d) / b;
|
|
1041
965
|
return new this.THREE.Vector3(p.x, yProj, p.z);
|
|
1042
966
|
});
|
|
@@ -1050,8 +974,8 @@ export default {
|
|
|
1050
974
|
function computePlaneMinYOverBox(plane, box) {
|
|
1051
975
|
const nearIndices = [0, 2, 4, 6];
|
|
1052
976
|
const farIndices = [1, 3, 5, 7];
|
|
1053
|
-
const nearYs = nearIndices.map(
|
|
1054
|
-
const farYs = farIndices.map(
|
|
977
|
+
const nearYs = nearIndices.map(i => frustumPoints[i].y);
|
|
978
|
+
const farYs = farIndices.map(i => frustumPoints[i].y);
|
|
1055
979
|
const minY = Math.min(...nearYs, ...farYs);
|
|
1056
980
|
const maxY = Math.max(...nearYs, ...farYs);
|
|
1057
981
|
return { min: minY, max: maxY };
|
|
@@ -1093,9 +1017,7 @@ export default {
|
|
|
1093
1017
|
if (camera.projectionMatrixNeedsUpdate) camera.updateProjectionMatrix();
|
|
1094
1018
|
|
|
1095
1019
|
// 相机世界位置
|
|
1096
|
-
const cameraPosition = new this.THREE.Vector3().setFromMatrixPosition(
|
|
1097
|
-
camera.matrixWorld,
|
|
1098
|
-
);
|
|
1020
|
+
const cameraPosition = new this.THREE.Vector3().setFromMatrixPosition(camera.matrixWorld);
|
|
1099
1021
|
|
|
1100
1022
|
// 从相机指向目标点的射线方向(优先使用 cameraControls._target)
|
|
1101
1023
|
const rayDirection = new this.THREE.Vector3();
|
|
@@ -1105,18 +1027,12 @@ export default {
|
|
|
1105
1027
|
cameraControls.enabled &&
|
|
1106
1028
|
cameraControls._target
|
|
1107
1029
|
) {
|
|
1108
|
-
rayDirection
|
|
1109
|
-
.copy(cameraControls._target)
|
|
1110
|
-
.sub(cameraPosition)
|
|
1111
|
-
.normalize();
|
|
1030
|
+
rayDirection.copy(cameraControls._target).sub(cameraPosition).normalize();
|
|
1112
1031
|
} else {
|
|
1113
1032
|
camera.getWorldDirection(rayDirection); // -Z 方向(世界坐标)
|
|
1114
1033
|
}
|
|
1115
1034
|
|
|
1116
|
-
const ray = new this.THREE.Ray(
|
|
1117
|
-
cameraPosition.clone(),
|
|
1118
|
-
rayDirection.clone(),
|
|
1119
|
-
);
|
|
1035
|
+
const ray = new this.THREE.Ray(cameraPosition.clone(), rayDirection.clone());
|
|
1120
1036
|
|
|
1121
1037
|
// 准备/计算场景包围盒
|
|
1122
1038
|
// if (!sceneBoundingBox) {
|
|
@@ -1135,9 +1051,7 @@ export default {
|
|
|
1135
1051
|
// 若包围盒不存在或为空,兜底从模型组/场景计算一次
|
|
1136
1052
|
if (
|
|
1137
1053
|
!sceneBoundingBox ||
|
|
1138
|
-
(sceneBoundingBox.isBox3 &&
|
|
1139
|
-
sceneBoundingBox.isEmpty &&
|
|
1140
|
-
sceneBoundingBox.isEmpty())
|
|
1054
|
+
(sceneBoundingBox.isBox3 && sceneBoundingBox.isEmpty && sceneBoundingBox.isEmpty())
|
|
1141
1055
|
) {
|
|
1142
1056
|
const obj =
|
|
1143
1057
|
typeof modelGroup !== 'undefined' &&
|
|
@@ -1151,10 +1065,7 @@ export default {
|
|
|
1151
1065
|
}
|
|
1152
1066
|
}
|
|
1153
1067
|
if (sceneBoundingBox && sceneBoundingBox.isBox3) {
|
|
1154
|
-
boxHitPoint = ray.intersectBox(
|
|
1155
|
-
sceneBoundingBox,
|
|
1156
|
-
new this.THREE.Vector3(),
|
|
1157
|
-
);
|
|
1068
|
+
boxHitPoint = ray.intersectBox(sceneBoundingBox, new this.THREE.Vector3());
|
|
1158
1069
|
}
|
|
1159
1070
|
|
|
1160
1071
|
// targetPoint 保留原平面回退逻辑(用于其他需要点位的场景)
|
|
@@ -1173,9 +1084,7 @@ export default {
|
|
|
1173
1084
|
}
|
|
1174
1085
|
|
|
1175
1086
|
// 以相机为原点,到包围盒交点的直线距离(若无交点则为 null)
|
|
1176
|
-
const distanceToBox = boxHitPoint
|
|
1177
|
-
? cameraPosition.distanceTo(boxHitPoint)
|
|
1178
|
-
: null;
|
|
1087
|
+
const distanceToBox = boxHitPoint ? cameraPosition.distanceTo(boxHitPoint) : null;
|
|
1179
1088
|
|
|
1180
1089
|
return {
|
|
1181
1090
|
targetPoint,
|
|
@@ -1203,7 +1112,7 @@ export default {
|
|
|
1203
1112
|
frustum = new this.THREE.Frustum();
|
|
1204
1113
|
const matrix = new this.THREE.Matrix4().multiplyMatrices(
|
|
1205
1114
|
camera.projectionMatrix,
|
|
1206
|
-
camera.matrixWorldInverse
|
|
1115
|
+
camera.matrixWorldInverse
|
|
1207
1116
|
);
|
|
1208
1117
|
frustum.setFromProjectionMatrix(matrix);
|
|
1209
1118
|
}
|
|
@@ -1280,7 +1189,7 @@ export default {
|
|
|
1280
1189
|
const frustum = new this.THREE.Frustum();
|
|
1281
1190
|
const vpMatrix = new this.THREE.Matrix4().multiplyMatrices(
|
|
1282
1191
|
camera.projectionMatrix,
|
|
1283
|
-
camera.matrixWorldInverse
|
|
1192
|
+
camera.matrixWorldInverse
|
|
1284
1193
|
);
|
|
1285
1194
|
frustum.setFromProjectionMatrix(vpMatrix);
|
|
1286
1195
|
|
|
@@ -1320,7 +1229,7 @@ export default {
|
|
|
1320
1229
|
const globalFrustum = this._frustum;
|
|
1321
1230
|
const globalVpMatrix = this._vpMatrix.multiplyMatrices(
|
|
1322
1231
|
camera.projectionMatrix,
|
|
1323
|
-
camera.matrixWorldInverse
|
|
1232
|
+
camera.matrixWorldInverse
|
|
1324
1233
|
);
|
|
1325
1234
|
globalFrustum.setFromProjectionMatrix(globalVpMatrix);
|
|
1326
1235
|
|
|
@@ -1330,7 +1239,7 @@ export default {
|
|
|
1330
1239
|
const visibleIds = [];
|
|
1331
1240
|
const candidates = [];
|
|
1332
1241
|
if (bypassList && bypassList.size > 0) {
|
|
1333
|
-
bypassList.forEach(
|
|
1242
|
+
bypassList.forEach(id => visibleIds.push(id));
|
|
1334
1243
|
}
|
|
1335
1244
|
const visibleIdSet = new Set(visibleIds);
|
|
1336
1245
|
if (this._octree) {
|
|
@@ -1338,30 +1247,22 @@ export default {
|
|
|
1338
1247
|
const exclude = bypassList || new Set();
|
|
1339
1248
|
const hits = this.queryOctreeByFrustum(frustum, exclude);
|
|
1340
1249
|
for (let i = 0; i < hits.length; i++) {
|
|
1341
|
-
if (
|
|
1342
|
-
hits[i].box &&
|
|
1343
|
-
hits[i].box.userData &&
|
|
1344
|
-
hits[i].box.userData.visible === false
|
|
1345
|
-
)
|
|
1250
|
+
if (hits[i].box && hits[i].box.userData && hits[i].box.userData.visible === false)
|
|
1346
1251
|
continue;
|
|
1347
1252
|
candidates.push(hits[i]);
|
|
1348
1253
|
}
|
|
1349
1254
|
} else if (this._boxIndex && this._boxIndex.size > 0) {
|
|
1350
1255
|
this._boxIndex.forEach((box, modelId) => {
|
|
1351
|
-
if (bypassList && bypassList.size > 0 && bypassList.has(modelId))
|
|
1352
|
-
return;
|
|
1256
|
+
if (bypassList && bypassList.size > 0 && bypassList.has(modelId)) return;
|
|
1353
1257
|
if (box.userData && box.userData.visible === false) return;
|
|
1354
1258
|
if (this.isBoxInFrustum(box)) {
|
|
1355
1259
|
candidates.push({ modelId, box });
|
|
1356
1260
|
}
|
|
1357
1261
|
});
|
|
1358
1262
|
}
|
|
1359
|
-
const occlusionState = this.noObserver
|
|
1360
|
-
? this.noObserver.occlusionState
|
|
1361
|
-
: this.occlusionState;
|
|
1263
|
+
const occlusionState = this.noObserver ? this.noObserver.occlusionState : this.occlusionState;
|
|
1362
1264
|
// 从响应式对象获取开关状态
|
|
1363
|
-
const occlusionEnabled =
|
|
1364
|
-
this.occlusionState && this.occlusionState.enabled;
|
|
1265
|
+
const occlusionEnabled = this.occlusionState && this.occlusionState.enabled;
|
|
1365
1266
|
|
|
1366
1267
|
if (occlusionEnabled) {
|
|
1367
1268
|
const state = occlusionState;
|
|
@@ -1371,9 +1272,7 @@ export default {
|
|
|
1371
1272
|
: 0;
|
|
1372
1273
|
const h =
|
|
1373
1274
|
renderer && renderer.domElement
|
|
1374
|
-
? renderer.domElement.clientHeight ||
|
|
1375
|
-
renderer.domElement.height ||
|
|
1376
|
-
0
|
|
1275
|
+
? renderer.domElement.clientHeight || renderer.domElement.height || 0
|
|
1377
1276
|
: 0;
|
|
1378
1277
|
// bufferWidth/Height 仍从响应式对象读取以支持动态修改
|
|
1379
1278
|
// 性能优化:使用降采样缓冲区进行遮挡剔除,大幅减少 readPixels 耗时 (从全屏降至约 256px 宽)
|
|
@@ -1402,10 +1301,7 @@ export default {
|
|
|
1402
1301
|
state._rtW = sw;
|
|
1403
1302
|
state._rtH = sh;
|
|
1404
1303
|
state._colorBuffer = new Uint8Array(sw * sh * 4);
|
|
1405
|
-
} else if (
|
|
1406
|
-
!state._colorBuffer ||
|
|
1407
|
-
state._colorBuffer.length !== sw * sh * 4
|
|
1408
|
-
) {
|
|
1304
|
+
} else if (!state._colorBuffer || state._colorBuffer.length !== sw * sh * 4) {
|
|
1409
1305
|
state._colorBuffer = new Uint8Array(sw * sh * 4);
|
|
1410
1306
|
}
|
|
1411
1307
|
|
|
@@ -1427,10 +1323,7 @@ export default {
|
|
|
1427
1323
|
const opaqueCandidates = [];
|
|
1428
1324
|
const transparentCandidates = [];
|
|
1429
1325
|
for (let i = 0; i < candidates.length; i++) {
|
|
1430
|
-
if (
|
|
1431
|
-
candidates[i].box.userData &&
|
|
1432
|
-
candidates[i].box.userData.transparent
|
|
1433
|
-
) {
|
|
1326
|
+
if (candidates[i].box.userData && candidates[i].box.userData.transparent) {
|
|
1434
1327
|
transparentCandidates.push(candidates[i]);
|
|
1435
1328
|
} else {
|
|
1436
1329
|
opaqueCandidates.push(candidates[i]);
|
|
@@ -1444,13 +1337,11 @@ export default {
|
|
|
1444
1337
|
? state._occIdIndexArr
|
|
1445
1338
|
: (state._occIdIndexArr = []);
|
|
1446
1339
|
const transparentIdIndexArr =
|
|
1447
|
-
state._occTransparentIdIndexArr &&
|
|
1448
|
-
Array.isArray(state._occTransparentIdIndexArr)
|
|
1340
|
+
state._occTransparentIdIndexArr && Array.isArray(state._occTransparentIdIndexArr)
|
|
1449
1341
|
? state._occTransparentIdIndexArr
|
|
1450
1342
|
: (state._occTransparentIdIndexArr = []);
|
|
1451
1343
|
|
|
1452
|
-
if (!state._occRenderObjects)
|
|
1453
|
-
state._occRenderObjects = Object.create(null);
|
|
1344
|
+
if (!state._occRenderObjects) state._occRenderObjects = Object.create(null);
|
|
1454
1345
|
const occObjs = state._occRenderObjects;
|
|
1455
1346
|
if (!occObjs._initialized) {
|
|
1456
1347
|
state._occScene.clear();
|
|
@@ -1477,7 +1368,7 @@ export default {
|
|
|
1477
1368
|
this.occlusionState.asyncBuildEnabled &&
|
|
1478
1369
|
!!window.requestAnimationFrame;
|
|
1479
1370
|
|
|
1480
|
-
const _occBuild =
|
|
1371
|
+
const _occBuild = opaqueList => {
|
|
1481
1372
|
const tBuild0 = performance.now();
|
|
1482
1373
|
|
|
1483
1374
|
const flag1Items = [];
|
|
@@ -1486,8 +1377,7 @@ export default {
|
|
|
1486
1377
|
let globalIdx = 1;
|
|
1487
1378
|
for (let i = 0; i < opaqueList.length; i++) {
|
|
1488
1379
|
const c = opaqueList[i];
|
|
1489
|
-
const obbData =
|
|
1490
|
-
c.box && c.box.userData ? c.box.userData.obbData : null;
|
|
1380
|
+
const obbData = c.box && c.box.userData ? c.box.userData.obbData : null;
|
|
1491
1381
|
if (!obbData || !obbData.length) continue;
|
|
1492
1382
|
const idx = globalIdx++;
|
|
1493
1383
|
activeIdIndexArr[idx] = this.formatModelId(c.modelId);
|
|
@@ -1503,39 +1393,25 @@ export default {
|
|
|
1503
1393
|
activeIdIndexArr.length = maxIdx + 1;
|
|
1504
1394
|
|
|
1505
1395
|
const _tempMatrix =
|
|
1506
|
-
occObjs._tempMatrix ||
|
|
1507
|
-
|
|
1508
|
-
const _tempColor =
|
|
1509
|
-
occObjs._tempColor ||
|
|
1510
|
-
(occObjs._tempColor = new this.THREE.Color());
|
|
1396
|
+
occObjs._tempMatrix || (occObjs._tempMatrix = new this.THREE.Matrix4());
|
|
1397
|
+
const _tempColor = occObjs._tempColor || (occObjs._tempColor = new this.THREE.Color());
|
|
1511
1398
|
const _tempScale =
|
|
1512
|
-
occObjs._tempScale ||
|
|
1513
|
-
|
|
1514
|
-
const
|
|
1515
|
-
occObjs._tempVec3 ||
|
|
1516
|
-
(occObjs._tempVec3 = new this.THREE.Vector3());
|
|
1517
|
-
const _tempMatA =
|
|
1518
|
-
occObjs._tempMatA ||
|
|
1519
|
-
(occObjs._tempMatA = new this.THREE.Matrix4());
|
|
1399
|
+
occObjs._tempScale || (occObjs._tempScale = new this.THREE.Vector3());
|
|
1400
|
+
const _tempVec3 = occObjs._tempVec3 || (occObjs._tempVec3 = new this.THREE.Vector3());
|
|
1401
|
+
const _tempMatA = occObjs._tempMatA || (occObjs._tempMatA = new this.THREE.Matrix4());
|
|
1520
1402
|
|
|
1521
1403
|
let boxes = occObjs.boxes;
|
|
1522
1404
|
const boxCount = flag3Items.length;
|
|
1523
1405
|
if (boxCount > 0) {
|
|
1524
1406
|
const needCapacity = boxCount;
|
|
1525
|
-
const capacity =
|
|
1526
|
-
boxes && typeof boxes.capacity === 'number'
|
|
1527
|
-
? boxes.capacity
|
|
1528
|
-
: 0;
|
|
1407
|
+
const capacity = boxes && typeof boxes.capacity === 'number' ? boxes.capacity : 0;
|
|
1529
1408
|
if (!boxes || capacity < needCapacity) {
|
|
1530
1409
|
if (boxes && boxes.mesh) {
|
|
1531
1410
|
state._occScene.remove(boxes.mesh);
|
|
1532
1411
|
if (boxes.mesh.geometry) boxes.mesh.geometry.dispose();
|
|
1533
1412
|
if (boxes.mesh.material) boxes.mesh.material.dispose();
|
|
1534
1413
|
}
|
|
1535
|
-
const nextCap = Math.max(
|
|
1536
|
-
needCapacity,
|
|
1537
|
-
capacity > 0 ? capacity * 2 : 256,
|
|
1538
|
-
);
|
|
1414
|
+
const nextCap = Math.max(needCapacity, capacity > 0 ? capacity * 2 : 256);
|
|
1539
1415
|
const geometry = new this.THREE.BoxGeometry(1, 1, 1);
|
|
1540
1416
|
const mat = new this.THREE.MeshBasicMaterial({
|
|
1541
1417
|
color: 0xffffff,
|
|
@@ -1545,11 +1421,7 @@ export default {
|
|
|
1545
1421
|
depthWrite: true,
|
|
1546
1422
|
toneMapped: false,
|
|
1547
1423
|
});
|
|
1548
|
-
const mesh = new this.THREE.InstancedMesh(
|
|
1549
|
-
geometry,
|
|
1550
|
-
mat,
|
|
1551
|
-
nextCap,
|
|
1552
|
-
);
|
|
1424
|
+
const mesh = new this.THREE.InstancedMesh(geometry, mat, nextCap);
|
|
1553
1425
|
mesh.frustumCulled = false;
|
|
1554
1426
|
mesh.matrixAutoUpdate = false;
|
|
1555
1427
|
state._occScene.add(mesh);
|
|
@@ -1570,10 +1442,7 @@ export default {
|
|
|
1570
1442
|
_tempScale.copy(halfSize).multiplyScalar(2);
|
|
1571
1443
|
_tempMatrix.copy(matrix);
|
|
1572
1444
|
_tempMatrix.scale(_tempScale);
|
|
1573
|
-
if (
|
|
1574
|
-
typeof bizToThreeMatrix !== 'undefined' &&
|
|
1575
|
-
bizToThreeMatrix
|
|
1576
|
-
) {
|
|
1445
|
+
if (typeof bizToThreeMatrix !== 'undefined' && bizToThreeMatrix) {
|
|
1577
1446
|
_tempMatrix.premultiply(bizToThreeMatrix);
|
|
1578
1447
|
}
|
|
1579
1448
|
|
|
@@ -1581,8 +1450,7 @@ export default {
|
|
|
1581
1450
|
boxes.mesh.setColorAt(i, _tempColor);
|
|
1582
1451
|
}
|
|
1583
1452
|
boxes.mesh.instanceMatrix.needsUpdate = true;
|
|
1584
|
-
if (boxes.mesh.instanceColor)
|
|
1585
|
-
boxes.mesh.instanceColor.needsUpdate = true;
|
|
1453
|
+
if (boxes.mesh.instanceColor) boxes.mesh.instanceColor.needsUpdate = true;
|
|
1586
1454
|
boxes.mesh.visible = true;
|
|
1587
1455
|
} else if (boxes && boxes.mesh) {
|
|
1588
1456
|
boxes.mesh.count = 0;
|
|
@@ -1607,8 +1475,7 @@ export default {
|
|
|
1607
1475
|
const needIdx = totalIdx;
|
|
1608
1476
|
|
|
1609
1477
|
const ensureBatch1 = () => {
|
|
1610
|
-
if (batch1 && batch1.mesh && batch1.geometry && batch1.material)
|
|
1611
|
-
return;
|
|
1478
|
+
if (batch1 && batch1.mesh && batch1.geometry && batch1.material) return;
|
|
1612
1479
|
const geometry = new this.THREE.BufferGeometry();
|
|
1613
1480
|
const material = new this.THREE.MeshBasicMaterial({
|
|
1614
1481
|
vertexColors: true,
|
|
@@ -1636,14 +1503,8 @@ export default {
|
|
|
1636
1503
|
}
|
|
1637
1504
|
|
|
1638
1505
|
if (batch1.posCap < needPos || batch1.idxCap < needIdx) {
|
|
1639
|
-
batch1.posCap = Math.max(
|
|
1640
|
-
|
|
1641
|
-
batch1.posCap > 0 ? batch1.posCap * 2 : needPos,
|
|
1642
|
-
);
|
|
1643
|
-
batch1.idxCap = Math.max(
|
|
1644
|
-
needIdx,
|
|
1645
|
-
batch1.idxCap > 0 ? batch1.idxCap * 2 : needIdx,
|
|
1646
|
-
);
|
|
1506
|
+
batch1.posCap = Math.max(needPos, batch1.posCap > 0 ? batch1.posCap * 2 : needPos);
|
|
1507
|
+
batch1.idxCap = Math.max(needIdx, batch1.idxCap > 0 ? batch1.idxCap * 2 : needIdx);
|
|
1647
1508
|
|
|
1648
1509
|
const positions = new Float32Array(batch1.posCap);
|
|
1649
1510
|
const colors = new Float32Array(batch1.posCap);
|
|
@@ -1694,10 +1555,7 @@ export default {
|
|
|
1694
1555
|
} else {
|
|
1695
1556
|
_tempMatA.identity();
|
|
1696
1557
|
}
|
|
1697
|
-
if (
|
|
1698
|
-
typeof bizToThreeMatrix !== 'undefined' &&
|
|
1699
|
-
bizToThreeMatrix
|
|
1700
|
-
) {
|
|
1558
|
+
if (typeof bizToThreeMatrix !== 'undefined' && bizToThreeMatrix) {
|
|
1701
1559
|
_tempMatA.premultiply(bizToThreeMatrix);
|
|
1702
1560
|
}
|
|
1703
1561
|
}
|
|
@@ -1771,8 +1629,7 @@ export default {
|
|
|
1771
1629
|
|
|
1772
1630
|
if (totalInstances > 0) {
|
|
1773
1631
|
if (asyncBuildEnabled && state._occHasBuiltOnce) {
|
|
1774
|
-
if (!state._occAsyncBuild)
|
|
1775
|
-
state._occAsyncBuild = { pending: false, token: 0 };
|
|
1632
|
+
if (!state._occAsyncBuild) state._occAsyncBuild = { pending: false, token: 0 };
|
|
1776
1633
|
const asyncState = state._occAsyncBuild;
|
|
1777
1634
|
if (!asyncState.pending) {
|
|
1778
1635
|
asyncState.pending = true;
|
|
@@ -1785,10 +1642,7 @@ export default {
|
|
|
1785
1642
|
try {
|
|
1786
1643
|
_occBuild(opaqueSnapshot);
|
|
1787
1644
|
} finally {
|
|
1788
|
-
if (
|
|
1789
|
-
state._occAsyncBuild &&
|
|
1790
|
-
state._occAsyncBuild.token === token
|
|
1791
|
-
) {
|
|
1645
|
+
if (state._occAsyncBuild && state._occAsyncBuild.token === token) {
|
|
1792
1646
|
state._occAsyncBuild.pending = false;
|
|
1793
1647
|
}
|
|
1794
1648
|
}
|
|
@@ -1798,16 +1652,13 @@ export default {
|
|
|
1798
1652
|
_occBuild(opaqueCandidates);
|
|
1799
1653
|
}
|
|
1800
1654
|
} else {
|
|
1801
|
-
if (occObjs.boxes && occObjs.boxes.mesh)
|
|
1802
|
-
|
|
1803
|
-
if (occObjs.batch1 && occObjs.batch1.mesh)
|
|
1804
|
-
occObjs.batch1.mesh.visible = false;
|
|
1655
|
+
if (occObjs.boxes && occObjs.boxes.mesh) occObjs.boxes.mesh.visible = false;
|
|
1656
|
+
if (occObjs.batch1 && occObjs.batch1.mesh) occObjs.batch1.mesh.visible = false;
|
|
1805
1657
|
state._occMaxIdx = 0;
|
|
1806
1658
|
activeIdIndexArr.length = 0;
|
|
1807
1659
|
}
|
|
1808
1660
|
|
|
1809
|
-
if (!state._occTransparentScene)
|
|
1810
|
-
state._occTransparentScene = new this.THREE.Scene();
|
|
1661
|
+
if (!state._occTransparentScene) state._occTransparentScene = new this.THREE.Scene();
|
|
1811
1662
|
let transparentMesh = state._occTransparentMesh;
|
|
1812
1663
|
const transparentCapacity =
|
|
1813
1664
|
transparentMesh &&
|
|
@@ -1823,7 +1674,7 @@ export default {
|
|
|
1823
1674
|
}
|
|
1824
1675
|
const nextCap = Math.max(
|
|
1825
1676
|
transparentTotal,
|
|
1826
|
-
transparentCapacity > 0 ? transparentCapacity * 2 : 256
|
|
1677
|
+
transparentCapacity > 0 ? transparentCapacity * 2 : 256
|
|
1827
1678
|
);
|
|
1828
1679
|
const geometry = new this.THREE.BoxGeometry(1, 1, 1);
|
|
1829
1680
|
const material = new this.THREE.MeshBasicMaterial({
|
|
@@ -1834,11 +1685,7 @@ export default {
|
|
|
1834
1685
|
depthWrite: false,
|
|
1835
1686
|
toneMapped: false,
|
|
1836
1687
|
});
|
|
1837
|
-
transparentMesh = new this.THREE.InstancedMesh(
|
|
1838
|
-
geometry,
|
|
1839
|
-
material,
|
|
1840
|
-
nextCap,
|
|
1841
|
-
);
|
|
1688
|
+
transparentMesh = new this.THREE.InstancedMesh(geometry, material, nextCap);
|
|
1842
1689
|
transparentMesh.frustumCulled = false;
|
|
1843
1690
|
transparentMesh.matrixAutoUpdate = false;
|
|
1844
1691
|
transparentMesh.userData.capacity = nextCap;
|
|
@@ -1866,10 +1713,7 @@ export default {
|
|
|
1866
1713
|
tempMatrix.copy(matrix);
|
|
1867
1714
|
tempScale.copy(halfSize).multiplyScalar(2);
|
|
1868
1715
|
tempMatrix.scale(tempScale);
|
|
1869
|
-
if (
|
|
1870
|
-
typeof bizToThreeMatrix !== 'undefined' &&
|
|
1871
|
-
bizToThreeMatrix
|
|
1872
|
-
) {
|
|
1716
|
+
if (typeof bizToThreeMatrix !== 'undefined' && bizToThreeMatrix) {
|
|
1873
1717
|
tempMatrix.premultiply(bizToThreeMatrix);
|
|
1874
1718
|
}
|
|
1875
1719
|
} else {
|
|
@@ -1886,8 +1730,7 @@ export default {
|
|
|
1886
1730
|
transparentMesh.count = transparentTotal;
|
|
1887
1731
|
transparentMesh.visible = true;
|
|
1888
1732
|
transparentMesh.instanceMatrix.needsUpdate = true;
|
|
1889
|
-
if (transparentMesh.instanceColor)
|
|
1890
|
-
transparentMesh.instanceColor.needsUpdate = true;
|
|
1733
|
+
if (transparentMesh.instanceColor) transparentMesh.instanceColor.needsUpdate = true;
|
|
1891
1734
|
const tMaxIdx = tIdx - 1;
|
|
1892
1735
|
transparentIdIndexArr.length = tMaxIdx + 1;
|
|
1893
1736
|
state._occTransparentMaxIdx = tMaxIdx;
|
|
@@ -1900,18 +1743,14 @@ export default {
|
|
|
1900
1743
|
|
|
1901
1744
|
// console.log('renderer', renderer)
|
|
1902
1745
|
const prevToneMapping = renderer.toneMapping;
|
|
1903
|
-
const prevTarget = renderer.getRenderTarget
|
|
1904
|
-
? renderer.getRenderTarget()
|
|
1905
|
-
: null;
|
|
1746
|
+
const prevTarget = renderer.getRenderTarget ? renderer.getRenderTarget() : null;
|
|
1906
1747
|
let prevClearColorHex = 0x000000;
|
|
1907
1748
|
let prevClearAlpha = 0;
|
|
1908
1749
|
try {
|
|
1909
1750
|
const c = renderer.getClearColor ? renderer.getClearColor() : null;
|
|
1910
1751
|
if (c && c.isColor) prevClearColorHex = c.getHex();
|
|
1911
1752
|
prevClearAlpha =
|
|
1912
|
-
typeof renderer.getClearAlpha === 'function'
|
|
1913
|
-
? renderer.getClearAlpha()
|
|
1914
|
-
: 0;
|
|
1753
|
+
typeof renderer.getClearAlpha === 'function' ? renderer.getClearAlpha() : 0;
|
|
1915
1754
|
} catch (_) {}
|
|
1916
1755
|
renderer.toneMapping = this.THREE.NoToneMapping;
|
|
1917
1756
|
renderer.setRenderTarget(rt);
|
|
@@ -1919,9 +1758,7 @@ export default {
|
|
|
1919
1758
|
renderer.clear(true, true, false);
|
|
1920
1759
|
camera.updateMatrixWorld(true);
|
|
1921
1760
|
renderer.render(state._occScene, camera);
|
|
1922
|
-
sceneBoundingBox = new this.THREE.Box3().setFromObject(
|
|
1923
|
-
state._occScene,
|
|
1924
|
-
);
|
|
1761
|
+
sceneBoundingBox = new this.THREE.Box3().setFromObject(state._occScene);
|
|
1925
1762
|
// const t1 = performance.now();
|
|
1926
1763
|
// 从响应式对象读取 previewEnabled
|
|
1927
1764
|
this.$emit('updateBoundingBox');
|
|
@@ -1940,10 +1777,7 @@ export default {
|
|
|
1940
1777
|
state._previewCanvas = cvs;
|
|
1941
1778
|
state._previewCtx = cvs.getContext('2d');
|
|
1942
1779
|
}
|
|
1943
|
-
if (
|
|
1944
|
-
!state._previewBuffer ||
|
|
1945
|
-
state._previewBuffer.length !== sw * sh * 4
|
|
1946
|
-
) {
|
|
1780
|
+
if (!state._previewBuffer || state._previewBuffer.length !== sw * sh * 4) {
|
|
1947
1781
|
state._previewBuffer = new Uint8Array(sw * sh * 4);
|
|
1948
1782
|
}
|
|
1949
1783
|
state._previewCanvas.width = sw;
|
|
@@ -1952,23 +1786,13 @@ export default {
|
|
|
1952
1786
|
const cssH = Math.min(renderer.domElement.height / 5);
|
|
1953
1787
|
state._previewCanvas.style.width = cssW + 'px';
|
|
1954
1788
|
state._previewCanvas.style.height = cssH + 'px';
|
|
1955
|
-
renderer.readRenderTargetPixels(
|
|
1956
|
-
rt,
|
|
1957
|
-
0,
|
|
1958
|
-
0,
|
|
1959
|
-
sw,
|
|
1960
|
-
sh,
|
|
1961
|
-
state._previewBuffer,
|
|
1962
|
-
);
|
|
1789
|
+
renderer.readRenderTargetPixels(rt, 0, 0, sw, sh, state._previewBuffer);
|
|
1963
1790
|
if (
|
|
1964
1791
|
!state._previewImageData ||
|
|
1965
1792
|
state._previewImageData.width !== sw ||
|
|
1966
1793
|
state._previewImageData.height !== sh
|
|
1967
1794
|
) {
|
|
1968
|
-
state._previewImageData = state._previewCtx.createImageData(
|
|
1969
|
-
sw,
|
|
1970
|
-
sh,
|
|
1971
|
-
);
|
|
1795
|
+
state._previewImageData = state._previewCtx.createImageData(sw, sh);
|
|
1972
1796
|
}
|
|
1973
1797
|
const dst = state._previewImageData.data;
|
|
1974
1798
|
const src = state._previewBuffer;
|
|
@@ -1981,9 +1805,7 @@ export default {
|
|
|
1981
1805
|
} else {
|
|
1982
1806
|
if (state._previewCanvas) {
|
|
1983
1807
|
if (state._previewCanvas.parentNode)
|
|
1984
|
-
state._previewCanvas.parentNode.removeChild(
|
|
1985
|
-
state._previewCanvas,
|
|
1986
|
-
);
|
|
1808
|
+
state._previewCanvas.parentNode.removeChild(state._previewCanvas);
|
|
1987
1809
|
state._previewCanvas = null;
|
|
1988
1810
|
state._previewCtx = null;
|
|
1989
1811
|
state._previewBuffer = null;
|
|
@@ -1995,13 +1817,12 @@ export default {
|
|
|
1995
1817
|
renderer.readRenderTargetPixels(rt, 0, 0, sw, sh, state._colorBuffer);
|
|
1996
1818
|
|
|
1997
1819
|
const idIndexArr = activeIdIndexArr;
|
|
1998
|
-
const maxIdx =
|
|
1999
|
-
typeof state._occMaxIdx === 'number' ? state._occMaxIdx : 0;
|
|
1820
|
+
const maxIdx = typeof state._occMaxIdx === 'number' ? state._occMaxIdx : 0;
|
|
2000
1821
|
const totalPixels = sw * sh;
|
|
2001
1822
|
const targetSamples = totalPixels;
|
|
2002
1823
|
const baseStride = Math.max(
|
|
2003
1824
|
1,
|
|
2004
|
-
Math.floor(Math.sqrt(totalPixels / Math.max(1, targetSamples)))
|
|
1825
|
+
Math.floor(Math.sqrt(totalPixels / Math.max(1, targetSamples)))
|
|
2005
1826
|
);
|
|
2006
1827
|
const extraStride =
|
|
2007
1828
|
this.occlusionState && this.occlusionState.sampleStride
|
|
@@ -2018,13 +1839,12 @@ export default {
|
|
|
2018
1839
|
sh,
|
|
2019
1840
|
stride,
|
|
2020
1841
|
maxIdx,
|
|
2021
|
-
minSampleCount
|
|
1842
|
+
minSampleCount
|
|
2022
1843
|
);
|
|
2023
1844
|
if (scanResult && scanResult.buffer) {
|
|
2024
1845
|
state._colorBuffer = new Uint8Array(scanResult.buffer);
|
|
2025
1846
|
}
|
|
2026
|
-
const indices =
|
|
2027
|
-
scanResult && scanResult.indices ? scanResult.indices : [];
|
|
1847
|
+
const indices = scanResult && scanResult.indices ? scanResult.indices : [];
|
|
2028
1848
|
for (let i = 0; i < indices.length; i++) {
|
|
2029
1849
|
const id = idIndexArr[indices[i]];
|
|
2030
1850
|
if (typeof id !== 'undefined') {
|
|
@@ -2033,25 +1853,12 @@ export default {
|
|
|
2033
1853
|
}
|
|
2034
1854
|
|
|
2035
1855
|
const transparentMaxIdx =
|
|
2036
|
-
typeof state._occTransparentMaxIdx === 'number'
|
|
2037
|
-
|
|
2038
|
-
: 0;
|
|
2039
|
-
if (
|
|
2040
|
-
transparentMaxIdx > 0 &&
|
|
2041
|
-
transparentMesh &&
|
|
2042
|
-
transparentMesh.visible
|
|
2043
|
-
) {
|
|
1856
|
+
typeof state._occTransparentMaxIdx === 'number' ? state._occTransparentMaxIdx : 0;
|
|
1857
|
+
if (transparentMaxIdx > 0 && transparentMesh && transparentMesh.visible) {
|
|
2044
1858
|
renderer.setClearColor(new this.THREE.Color(0, 0, 0), 0);
|
|
2045
1859
|
renderer.clear(true, false, false);
|
|
2046
1860
|
renderer.render(state._occTransparentScene, camera);
|
|
2047
|
-
renderer.readRenderTargetPixels(
|
|
2048
|
-
rt,
|
|
2049
|
-
0,
|
|
2050
|
-
0,
|
|
2051
|
-
sw,
|
|
2052
|
-
sh,
|
|
2053
|
-
state._colorBuffer,
|
|
2054
|
-
);
|
|
1861
|
+
renderer.readRenderTargetPixels(rt, 0, 0, sw, sh, state._colorBuffer);
|
|
2055
1862
|
|
|
2056
1863
|
const tIdIndexArr = transparentIdIndexArr;
|
|
2057
1864
|
const tScanResult = await this.scanOcclusionIndices(
|
|
@@ -2060,13 +1867,12 @@ export default {
|
|
|
2060
1867
|
sh,
|
|
2061
1868
|
stride,
|
|
2062
1869
|
transparentMaxIdx,
|
|
2063
|
-
minSampleCount
|
|
1870
|
+
minSampleCount
|
|
2064
1871
|
);
|
|
2065
1872
|
if (tScanResult && tScanResult.buffer) {
|
|
2066
1873
|
state._colorBuffer = new Uint8Array(tScanResult.buffer);
|
|
2067
1874
|
}
|
|
2068
|
-
const tIndices =
|
|
2069
|
-
tScanResult && tScanResult.indices ? tScanResult.indices : [];
|
|
1875
|
+
const tIndices = tScanResult && tScanResult.indices ? tScanResult.indices : [];
|
|
2070
1876
|
for (let i = 0; i < tIndices.length; i++) {
|
|
2071
1877
|
const id = tIdIndexArr[tIndices[i]];
|
|
2072
1878
|
if (typeof id !== 'undefined') {
|
|
@@ -2089,17 +1895,15 @@ export default {
|
|
|
2089
1895
|
}
|
|
2090
1896
|
}
|
|
2091
1897
|
visibleIds.length = 0;
|
|
2092
|
-
visibleIdSet.forEach(
|
|
1898
|
+
visibleIdSet.forEach(id => visibleIds.push(id));
|
|
2093
1899
|
const toLoadSet = new Set(visibleIdSet);
|
|
2094
1900
|
const parentsToCheck = new Set();
|
|
2095
|
-
scene.traverse(
|
|
1901
|
+
scene.traverse(child => {
|
|
2096
1902
|
if (!child.isInstancedMesh) return;
|
|
2097
1903
|
// 如果复用数量等于大于2个,则跳过裁剪和剔除处理(始终保留)
|
|
2098
1904
|
if (child.count >= 2) {
|
|
2099
1905
|
let instancesMap =
|
|
2100
|
-
child &&
|
|
2101
|
-
child.userData &&
|
|
2102
|
-
child.userData.instancesMap instanceof Map
|
|
1906
|
+
child && child.userData && child.userData.instancesMap instanceof Map
|
|
2103
1907
|
? child.userData.instancesMap
|
|
2104
1908
|
: child.parent &&
|
|
2105
1909
|
child.parent.userData &&
|
|
@@ -2120,8 +1924,7 @@ export default {
|
|
|
2120
1924
|
return;
|
|
2121
1925
|
}
|
|
2122
1926
|
|
|
2123
|
-
if (bypassList && bypassList.size > 0 && bypassList.has(modelId))
|
|
2124
|
-
return;
|
|
1927
|
+
if (bypassList && bypassList.size > 0 && bypassList.has(modelId)) return;
|
|
2125
1928
|
|
|
2126
1929
|
const instanceInfo = instancesMap.get(modelId);
|
|
2127
1930
|
const instanceIndex =
|
|
@@ -2129,11 +1932,7 @@ export default {
|
|
|
2129
1932
|
? instanceInfo.instanceIndex
|
|
2130
1933
|
: null;
|
|
2131
1934
|
|
|
2132
|
-
const inFrustum = this.isModelInFrustum(
|
|
2133
|
-
child,
|
|
2134
|
-
instanceIndex,
|
|
2135
|
-
globalFrustum,
|
|
2136
|
-
);
|
|
1935
|
+
const inFrustum = this.isModelInFrustum(child, instanceIndex, globalFrustum);
|
|
2137
1936
|
const modelInVisible = toLoadSet.has(modelId);
|
|
2138
1937
|
// console.log('modelId', modelId, 'inFrustum', inFrustum, 'modelInVisible', modelInVisible)
|
|
2139
1938
|
|
|
@@ -2162,13 +1961,10 @@ export default {
|
|
|
2162
1961
|
return;
|
|
2163
1962
|
}
|
|
2164
1963
|
const modelId =
|
|
2165
|
-
child.parent &&
|
|
2166
|
-
child.parent.userData &&
|
|
2167
|
-
child.parent.userData.instanceId
|
|
1964
|
+
child.parent && child.parent.userData && child.parent.userData.instanceId
|
|
2168
1965
|
? child.parent.userData.instanceId
|
|
2169
1966
|
: child.uuid;
|
|
2170
|
-
if (bypassList && bypassList.size > 0 && bypassList.has(modelId))
|
|
2171
|
-
return;
|
|
1967
|
+
if (bypassList && bypassList.size > 0 && bypassList.has(modelId)) return;
|
|
2172
1968
|
|
|
2173
1969
|
const inFrustum = this.isModelInFrustum(child, null, globalFrustum);
|
|
2174
1970
|
let modelInVisible = toLoadSet.has(modelId);
|
|
@@ -2184,22 +1980,20 @@ export default {
|
|
|
2184
1980
|
this.unloadInstancedModel(modelId, child);
|
|
2185
1981
|
}
|
|
2186
1982
|
if (scene) {
|
|
2187
|
-
parentsToCheck.forEach(
|
|
1983
|
+
parentsToCheck.forEach(group => {
|
|
2188
1984
|
if (group && group.children && group.children.length === 0) {
|
|
2189
1985
|
group.removeFromParent();
|
|
2190
1986
|
}
|
|
2191
1987
|
});
|
|
2192
1988
|
}
|
|
2193
|
-
this.modelStateManager.isloadedModelsIds = Object.freeze(
|
|
2194
|
-
Array.from(toLoadSet),
|
|
2195
|
-
);
|
|
1989
|
+
this.modelStateManager.isloadedModelsIds = Object.freeze(Array.from(toLoadSet));
|
|
2196
1990
|
},
|
|
2197
1991
|
isBoxInFrustum(box) {
|
|
2198
1992
|
if (!camera) return true;
|
|
2199
1993
|
const frustum = new this.THREE.Frustum();
|
|
2200
1994
|
const vpMatrix = new this.THREE.Matrix4().multiplyMatrices(
|
|
2201
1995
|
camera.projectionMatrix,
|
|
2202
|
-
camera.matrixWorldInverse
|
|
1996
|
+
camera.matrixWorldInverse
|
|
2203
1997
|
);
|
|
2204
1998
|
frustum.setFromProjectionMatrix(vpMatrix);
|
|
2205
1999
|
return frustum.intersectsBox(box);
|
|
@@ -2217,8 +2011,7 @@ export default {
|
|
|
2217
2011
|
|
|
2218
2012
|
// 卸载前内存快照
|
|
2219
2013
|
// this.logRendererMemory(`before unload modelId=${modelId}`);
|
|
2220
|
-
const { instanceIndex } =
|
|
2221
|
-
instancedMesh.userData.instancesMap.get(modelId) || 0;
|
|
2014
|
+
const { instanceIndex } = instancedMesh.userData.instancesMap.get(modelId) || 0;
|
|
2222
2015
|
// const instanceIndex = instancedMesh.userData.instanceIndex || 0;
|
|
2223
2016
|
|
|
2224
2017
|
this.removeOutlineInstanceProxy(instancedMesh, instanceIndex);
|
|
@@ -2246,8 +2039,7 @@ export default {
|
|
|
2246
2039
|
instancedMesh.parent && instancedMesh.parent.matrixWorld
|
|
2247
2040
|
? instancedMesh.parent.matrixWorld.clone()
|
|
2248
2041
|
: new this.THREE.Matrix4();
|
|
2249
|
-
instanceInfo.count =
|
|
2250
|
-
typeof instancedMesh.count === 'number' ? instancedMesh.count : 1;
|
|
2042
|
+
instanceInfo.count = typeof instancedMesh.count === 'number' ? instancedMesh.count : 1;
|
|
2251
2043
|
|
|
2252
2044
|
const parentGroup = instancedMesh.parent;
|
|
2253
2045
|
if (parentGroup) {
|
|
@@ -2269,7 +2061,7 @@ export default {
|
|
|
2269
2061
|
|
|
2270
2062
|
if (material) {
|
|
2271
2063
|
if (Array.isArray(material)) {
|
|
2272
|
-
material.forEach(
|
|
2064
|
+
material.forEach(m => {
|
|
2273
2065
|
// if (m && !this.isMaterialShared(m)) m.dispose();
|
|
2274
2066
|
if (m) m.dispose();
|
|
2275
2067
|
});
|
|
@@ -2315,16 +2107,13 @@ export default {
|
|
|
2315
2107
|
projectId,
|
|
2316
2108
|
debug: isDebug,
|
|
2317
2109
|
renderModelData: this.renderModelData.bind(this),
|
|
2318
|
-
ensureNotInteracting: async
|
|
2319
|
-
if (
|
|
2320
|
-
|
|
2321
|
-
this.noObserver.batchLoadingState.interactionState.isInteracting
|
|
2322
|
-
) {
|
|
2323
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
2110
|
+
ensureNotInteracting: async abortSignal => {
|
|
2111
|
+
if (userInteracting || this.noObserver.batchLoadingState.interactionState.isInteracting) {
|
|
2112
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
2324
2113
|
}
|
|
2325
2114
|
},
|
|
2326
2115
|
batchSize: this.noObserver.batchLoadingState.batchSize,
|
|
2327
|
-
onCancelRequestId: async
|
|
2116
|
+
onCancelRequestId: async requestId => {
|
|
2328
2117
|
if (modelApi && typeof modelApi.postCanceledRequest === 'function') {
|
|
2329
2118
|
return await modelApi.postCanceledRequest(requestId);
|
|
2330
2119
|
}
|
|
@@ -2338,11 +2127,9 @@ export default {
|
|
|
2338
2127
|
this.noObserver.occlusionWorker = streamLoader.worker;
|
|
2339
2128
|
this.noObserver.occlusionWorkerRequestId = 0;
|
|
2340
2129
|
this.noObserver.occlusionWorkerRequestMap = new Map();
|
|
2341
|
-
streamLoader.worker.addEventListener('message',
|
|
2130
|
+
streamLoader.worker.addEventListener('message', e => {
|
|
2342
2131
|
const payload = e.data || {};
|
|
2343
|
-
const pending = this.noObserver.occlusionWorkerRequestMap.get(
|
|
2344
|
-
payload.id,
|
|
2345
|
-
);
|
|
2132
|
+
const pending = this.noObserver.occlusionWorkerRequestMap.get(payload.id);
|
|
2346
2133
|
if (!pending) return;
|
|
2347
2134
|
this.noObserver.occlusionWorkerRequestMap.delete(payload.id);
|
|
2348
2135
|
pending.resolve(payload);
|
|
@@ -2372,11 +2159,7 @@ export default {
|
|
|
2372
2159
|
*/
|
|
2373
2160
|
async batchLoadRegions(item, divideData, materialData) {
|
|
2374
2161
|
if (this.noObserver.streamLoader) {
|
|
2375
|
-
await this.noObserver.streamLoader.batchLoadRegions(
|
|
2376
|
-
item,
|
|
2377
|
-
divideData,
|
|
2378
|
-
materialData,
|
|
2379
|
-
);
|
|
2162
|
+
await this.noObserver.streamLoader.batchLoadRegions(item, divideData, materialData);
|
|
2380
2163
|
}
|
|
2381
2164
|
},
|
|
2382
2165
|
|
|
@@ -2398,10 +2181,7 @@ export default {
|
|
|
2398
2181
|
* 处理单个模型项加载(供外部调用)
|
|
2399
2182
|
*/
|
|
2400
2183
|
async processModelItem(item, options = {}) {
|
|
2401
|
-
const res = await this.noObserver.streamLoader.processModelItem(
|
|
2402
|
-
item,
|
|
2403
|
-
options,
|
|
2404
|
-
);
|
|
2184
|
+
const res = await this.noObserver.streamLoader.processModelItem(item, options);
|
|
2405
2185
|
// item.id is the documentId
|
|
2406
2186
|
if (item && item.id) {
|
|
2407
2187
|
if (res && res.sceneBox) {
|
|
@@ -2432,23 +2212,32 @@ export default {
|
|
|
2432
2212
|
this.setSceneBox(null, documentId, false);
|
|
2433
2213
|
this.setBoxIndex(null, documentId, false);
|
|
2434
2214
|
},
|
|
2215
|
+
/**
|
|
2216
|
+
* 同步获取当前WebGL画面的截图数据,解决preserveDrawingBuffer为false时html2canvas截黑屏的问题
|
|
2217
|
+
*/
|
|
2218
|
+
getScreenshotDataURL() {
|
|
2219
|
+
if (!renderer || !scene || !camera) return null;
|
|
2220
|
+
|
|
2221
|
+
// 强制渲染一帧
|
|
2222
|
+
if (outlineComposer) {
|
|
2223
|
+
outlineComposer.render();
|
|
2224
|
+
} else {
|
|
2225
|
+
renderer.render(scene, camera);
|
|
2226
|
+
}
|
|
2435
2227
|
|
|
2228
|
+
// 立即同步提取像素数据
|
|
2229
|
+
return renderer.domElement.toDataURL('image/png', 1.0);
|
|
2230
|
+
},
|
|
2436
2231
|
/**
|
|
2437
2232
|
* 内部渲染流式数据方法
|
|
2438
2233
|
*/
|
|
2439
|
-
renderModelData(
|
|
2440
|
-
meshes,
|
|
2441
|
-
primitives,
|
|
2442
|
-
list,
|
|
2443
|
-
range,
|
|
2444
|
-
onComplete,
|
|
2445
|
-
immediateUpdate,
|
|
2446
|
-
) {
|
|
2234
|
+
renderModelData(meshes, primitives, list, range, onComplete, immediateUpdate) {
|
|
2447
2235
|
// 构造 drawModel 需要的数据格式
|
|
2448
2236
|
const modelRegistry = this.noObserver.streamLoader.modelRegistry;
|
|
2449
2237
|
const modelRecords = Array.from(modelRegistry.values());
|
|
2450
2238
|
const material = [];
|
|
2451
|
-
|
|
2239
|
+
const mergeMaterial = [];
|
|
2240
|
+
modelRecords.forEach(record => {
|
|
2452
2241
|
if (record.materialData) {
|
|
2453
2242
|
if (Array.isArray(record.materialData)) {
|
|
2454
2243
|
material.push(...record.materialData);
|
|
@@ -2456,10 +2245,19 @@ export default {
|
|
|
2456
2245
|
material.push(record.materialData);
|
|
2457
2246
|
}
|
|
2458
2247
|
}
|
|
2248
|
+
|
|
2249
|
+
if (record.mergeMaterialData) {
|
|
2250
|
+
if (Array.isArray(record.mergeMaterialData)) {
|
|
2251
|
+
mergeMaterial.push(...record.mergeMaterialData);
|
|
2252
|
+
} else {
|
|
2253
|
+
mergeMaterial.push(record.mergeMaterialData);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2459
2256
|
});
|
|
2460
2257
|
|
|
2461
2258
|
const regionModelData = {
|
|
2462
2259
|
material,
|
|
2260
|
+
mergeMaterial,
|
|
2463
2261
|
primitive: primitives,
|
|
2464
2262
|
mesh: meshes, // 注意这里 meshes 对应 drawModel 的 data.mesh (如果它是单个) 或处理逻辑
|
|
2465
2263
|
};
|
|
@@ -2598,7 +2396,7 @@ export default {
|
|
|
2598
2396
|
outlinePass = new OutlinePass(
|
|
2599
2397
|
new this.THREE.Vector2(window.innerWidth, window.innerHeight),
|
|
2600
2398
|
scene,
|
|
2601
|
-
camera
|
|
2399
|
+
camera
|
|
2602
2400
|
);
|
|
2603
2401
|
outlinePass.edgeStrength = 3;
|
|
2604
2402
|
outlinePass.edgeGlow = 0.5; // 边缘模糊度
|
|
@@ -2623,7 +2421,7 @@ export default {
|
|
|
2623
2421
|
45,
|
|
2624
2422
|
window.innerWidth / window.innerHeight,
|
|
2625
2423
|
0.1,
|
|
2626
|
-
1000000
|
|
2424
|
+
1000000
|
|
2627
2425
|
);
|
|
2628
2426
|
// camera.position.set(0, 100, 150);
|
|
2629
2427
|
},
|
|
@@ -2655,7 +2453,7 @@ export default {
|
|
|
2655
2453
|
|
|
2656
2454
|
// 1. 创建统一的响应触发器 (Debounced)
|
|
2657
2455
|
this._cameraChangeObserver = this.debounce(
|
|
2658
|
-
async
|
|
2456
|
+
async source => {
|
|
2659
2457
|
// 如果观察者被禁用,则不执行后续逻辑
|
|
2660
2458
|
if (!this.noObserver.isObserverEnabled) {
|
|
2661
2459
|
return;
|
|
@@ -2690,14 +2488,14 @@ export default {
|
|
|
2690
2488
|
this.getRangeStream(false);
|
|
2691
2489
|
}
|
|
2692
2490
|
},
|
|
2693
|
-
|
|
2491
|
+
source => {
|
|
2694
2492
|
// 漫游模式下,或者第一人称移动时,使用节流策略(每300ms触发一次)
|
|
2695
2493
|
// 避免在持续运动中因防抖重置定时器而无法触发
|
|
2696
2494
|
if (source === 'roam' || source === 'firstPersonMove') {
|
|
2697
2495
|
return { type: 'throttle', limit: 1000 };
|
|
2698
2496
|
}
|
|
2699
2497
|
return 300; // 默认防抖 300ms
|
|
2700
|
-
}
|
|
2498
|
+
}
|
|
2701
2499
|
);
|
|
2702
2500
|
|
|
2703
2501
|
// 2. 公开API:允许外部或业务逻辑手动触发更新
|
|
@@ -2706,7 +2504,7 @@ export default {
|
|
|
2706
2504
|
};
|
|
2707
2505
|
|
|
2708
2506
|
// 3. 监听器 - Wheel (用户滚轮)
|
|
2709
|
-
this._wheelHandler =
|
|
2507
|
+
this._wheelHandler = res => {
|
|
2710
2508
|
this.$emit('wheelStart', res);
|
|
2711
2509
|
|
|
2712
2510
|
// 统一交互开始处理
|
|
@@ -2717,8 +2515,7 @@ export default {
|
|
|
2717
2515
|
|
|
2718
2516
|
// 滚轮逻辑:infinityDolly 与 maxDollyDistance 控制
|
|
2719
2517
|
const event = res;
|
|
2720
|
-
const deltaY =
|
|
2721
|
-
event && typeof event.deltaY === 'number' ? event.deltaY : 0;
|
|
2518
|
+
const deltaY = event && typeof event.deltaY === 'number' ? event.deltaY : 0;
|
|
2722
2519
|
const isZoomOut = deltaY > 0; // 远离
|
|
2723
2520
|
const isZoomIn = deltaY < 0; // 靠近
|
|
2724
2521
|
|
|
@@ -2733,13 +2530,10 @@ export default {
|
|
|
2733
2530
|
if (sceneBoundingBox && isFinite(maxDollyDistance)) {
|
|
2734
2531
|
if (isZoomOut) {
|
|
2735
2532
|
camera.updateMatrixWorld(true);
|
|
2736
|
-
const currentDistance = camera.position.distanceTo(
|
|
2737
|
-
cameraControls._target,
|
|
2738
|
-
);
|
|
2533
|
+
const currentDistance = camera.position.distanceTo(cameraControls._target);
|
|
2739
2534
|
if (currentDistance >= maxDollyDistance) {
|
|
2740
2535
|
event.preventDefault && event.preventDefault();
|
|
2741
|
-
event.stopImmediatePropagation &&
|
|
2742
|
-
event.stopImmediatePropagation();
|
|
2536
|
+
event.stopImmediatePropagation && event.stopImmediatePropagation();
|
|
2743
2537
|
return;
|
|
2744
2538
|
}
|
|
2745
2539
|
}
|
|
@@ -2754,7 +2548,7 @@ export default {
|
|
|
2754
2548
|
renderer.domElement.addEventListener('wheel', this._wheelHandler);
|
|
2755
2549
|
|
|
2756
2550
|
// 4. 监听器 - Controls (用户拖拽/操作)
|
|
2757
|
-
this._onControlStart =
|
|
2551
|
+
this._onControlStart = res => {
|
|
2758
2552
|
this.noObserver.isControlActive = true;
|
|
2759
2553
|
|
|
2760
2554
|
// 统一交互开始处理(相机)
|
|
@@ -2770,7 +2564,7 @@ export default {
|
|
|
2770
2564
|
}
|
|
2771
2565
|
};
|
|
2772
2566
|
|
|
2773
|
-
this._onControlEnd =
|
|
2567
|
+
this._onControlEnd = res => {
|
|
2774
2568
|
this.noObserver.isControlActive = false;
|
|
2775
2569
|
|
|
2776
2570
|
this.$emit('controlEnd', res);
|
|
@@ -2821,10 +2615,7 @@ export default {
|
|
|
2821
2615
|
// 初始化光源
|
|
2822
2616
|
initLight() {
|
|
2823
2617
|
const pmremGenerator = new this.THREE.PMREMGenerator(renderer);
|
|
2824
|
-
scene.environment = pmremGenerator.fromScene(
|
|
2825
|
-
new RoomEnvironment(),
|
|
2826
|
-
0.04,
|
|
2827
|
-
).texture;
|
|
2618
|
+
scene.environment = pmremGenerator.fromScene(new RoomEnvironment(), 0.04).texture;
|
|
2828
2619
|
},
|
|
2829
2620
|
// 初始化文字画布
|
|
2830
2621
|
initLabelRender() {
|
|
@@ -2851,16 +2642,16 @@ export default {
|
|
|
2851
2642
|
color,
|
|
2852
2643
|
meshNameConfig,
|
|
2853
2644
|
options,
|
|
2854
|
-
|
|
2645
|
+
progress => {
|
|
2855
2646
|
// 触发原有的进度事件
|
|
2856
2647
|
this.$emit('loadProgress', progress);
|
|
2857
2648
|
},
|
|
2858
|
-
|
|
2649
|
+
complete => {
|
|
2859
2650
|
options?.onComplete?.(complete);
|
|
2860
2651
|
console.log('加载完成');
|
|
2861
2652
|
// 触发原有的完成事件
|
|
2862
2653
|
this.$emit('loadComplete');
|
|
2863
|
-
}
|
|
2654
|
+
}
|
|
2864
2655
|
);
|
|
2865
2656
|
},
|
|
2866
2657
|
// 动态设置视角滚轮的距离
|
|
@@ -2917,24 +2708,15 @@ export default {
|
|
|
2917
2708
|
mouse.x = (x / rect.width) * 2 - 1;
|
|
2918
2709
|
mouse.y = -(y / rect.height) * 2 + 1;
|
|
2919
2710
|
raycaster.setFromCamera(mouse, camera);
|
|
2920
|
-
return scene && scene.children
|
|
2921
|
-
? raycaster.intersectObjects(scene.children, true)
|
|
2922
|
-
: [];
|
|
2711
|
+
return scene && scene.children ? raycaster.intersectObjects(scene.children, true) : [];
|
|
2923
2712
|
},
|
|
2924
2713
|
getInstanceId(instancedMesh, instanceIndex, options) {
|
|
2925
|
-
if (
|
|
2926
|
-
!instancedMesh ||
|
|
2927
|
-
instanceIndex === undefined ||
|
|
2928
|
-
instanceIndex === null
|
|
2929
|
-
) {
|
|
2714
|
+
if (!instancedMesh || instanceIndex === undefined || instanceIndex === null) {
|
|
2930
2715
|
return null;
|
|
2931
2716
|
}
|
|
2932
2717
|
const meshName = instancedMesh.name;
|
|
2933
2718
|
for (const props of instancedMesh.userData.instancesMap.values()) {
|
|
2934
|
-
if (
|
|
2935
|
-
props.instancedMeshId === meshName &&
|
|
2936
|
-
props.instanceIndex === instanceIndex
|
|
2937
|
-
) {
|
|
2719
|
+
if (props.instancedMeshId === meshName && props.instanceIndex === instanceIndex) {
|
|
2938
2720
|
return props.instanceId;
|
|
2939
2721
|
}
|
|
2940
2722
|
}
|
|
@@ -2968,10 +2750,7 @@ export default {
|
|
|
2968
2750
|
};
|
|
2969
2751
|
if (intersects.length > 0) {
|
|
2970
2752
|
this.clearBypassCullingModelIds();
|
|
2971
|
-
const instanceId = this.getInstanceId(
|
|
2972
|
-
intersects[0].object,
|
|
2973
|
-
intersects[0].instanceId,
|
|
2974
|
-
);
|
|
2753
|
+
const instanceId = this.getInstanceId(intersects[0].object, intersects[0].instanceId);
|
|
2975
2754
|
params = {
|
|
2976
2755
|
objects: [intersects[0].object],
|
|
2977
2756
|
mousePosition: { x: event.clientX, y: event.clientY },
|
|
@@ -3136,31 +2915,18 @@ export default {
|
|
|
3136
2915
|
for (const key in ele.attr) {
|
|
3137
2916
|
switch (key) {
|
|
3138
2917
|
case 'color':
|
|
3139
|
-
targetObj.forEach(
|
|
2918
|
+
targetObj.forEach(children => {
|
|
3140
2919
|
if (children.isMesh) {
|
|
3141
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3142
|
-
|
|
3143
|
-
);
|
|
3144
|
-
children.setColorAt(
|
|
3145
|
-
instanceIndex,
|
|
3146
|
-
new this.THREE.Color(ele.attr[key]),
|
|
3147
|
-
);
|
|
2920
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
2921
|
+
children.setColorAt(instanceIndex, new this.THREE.Color(ele.attr[key]));
|
|
3148
2922
|
children.instanceColor.needsUpdate = true;
|
|
3149
2923
|
if (outlinePass) {
|
|
3150
2924
|
if (children.isInstancedMesh) {
|
|
3151
|
-
const proxy = this.ensureOutlineInstanceProxy(
|
|
3152
|
-
|
|
3153
|
-
instanceIndex,
|
|
3154
|
-
);
|
|
3155
|
-
if (
|
|
3156
|
-
proxy &&
|
|
3157
|
-
!outlinePass.selectedObjects.includes(proxy)
|
|
3158
|
-
) {
|
|
2925
|
+
const proxy = this.ensureOutlineInstanceProxy(children, instanceIndex);
|
|
2926
|
+
if (proxy && !outlinePass.selectedObjects.includes(proxy)) {
|
|
3159
2927
|
outlinePass.selectedObjects.push(proxy);
|
|
3160
2928
|
}
|
|
3161
|
-
} else if (
|
|
3162
|
-
!outlinePass.selectedObjects.includes(children)
|
|
3163
|
-
) {
|
|
2929
|
+
} else if (!outlinePass.selectedObjects.includes(children)) {
|
|
3164
2930
|
outlinePass.selectedObjects.push(children);
|
|
3165
2931
|
}
|
|
3166
2932
|
}
|
|
@@ -3177,14 +2943,10 @@ export default {
|
|
|
3177
2943
|
boxData.userData.visible = ele.attr[key];
|
|
3178
2944
|
}
|
|
3179
2945
|
}
|
|
3180
|
-
targetObj.forEach(
|
|
3181
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3182
|
-
instanceId,
|
|
3183
|
-
);
|
|
2946
|
+
targetObj.forEach(children => {
|
|
2947
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3184
2948
|
if (ele.attr[key]) {
|
|
3185
|
-
const restoreMatrix = new this.THREE.Matrix4().copy(
|
|
3186
|
-
children.userData.copyMatrix,
|
|
3187
|
-
);
|
|
2949
|
+
const restoreMatrix = new this.THREE.Matrix4().copy(children.userData.copyMatrix);
|
|
3188
2950
|
children.setMatrixAt(instanceIndex, restoreMatrix);
|
|
3189
2951
|
// if (outlinePass) {
|
|
3190
2952
|
// if (children.isInstancedMesh) {
|
|
@@ -3206,8 +2968,7 @@ export default {
|
|
|
3206
2968
|
this.removeOutlineInstanceProxy(children, instanceIndex);
|
|
3207
2969
|
} else {
|
|
3208
2970
|
const idx = outlinePass.selectedObjects.indexOf(children);
|
|
3209
|
-
if (idx !== -1)
|
|
3210
|
-
outlinePass.selectedObjects.splice(idx, 1);
|
|
2971
|
+
if (idx !== -1) outlinePass.selectedObjects.splice(idx, 1);
|
|
3211
2972
|
}
|
|
3212
2973
|
}
|
|
3213
2974
|
}
|
|
@@ -3216,24 +2977,18 @@ export default {
|
|
|
3216
2977
|
this.notifyCameraChange(); // 触发场景更新
|
|
3217
2978
|
break;
|
|
3218
2979
|
case 'opacity':
|
|
3219
|
-
targetObj.forEach(
|
|
2980
|
+
targetObj.forEach(children => {
|
|
3220
2981
|
if (children.isMesh) {
|
|
3221
2982
|
const opacity = children.geometry.attributes.opacity.array;
|
|
3222
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3223
|
-
instanceId,
|
|
3224
|
-
);
|
|
2983
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3225
2984
|
opacity[instanceIndex] = ele.attr[key];
|
|
3226
2985
|
children.geometry.attributes.opacity.needsUpdate = true;
|
|
3227
2986
|
}
|
|
3228
2987
|
});
|
|
3229
2988
|
break;
|
|
3230
2989
|
case 'position':
|
|
3231
|
-
targetObj.forEach(
|
|
3232
|
-
children.position.set(
|
|
3233
|
-
ele.attr[key].x,
|
|
3234
|
-
ele.attr[key].y,
|
|
3235
|
-
ele.attr[key].z,
|
|
3236
|
-
);
|
|
2990
|
+
targetObj.forEach(children => {
|
|
2991
|
+
children.position.set(ele.attr[key].x, ele.attr[key].y, ele.attr[key].z);
|
|
3237
2992
|
});
|
|
3238
2993
|
break;
|
|
3239
2994
|
}
|
|
@@ -3245,19 +3000,56 @@ export default {
|
|
|
3245
3000
|
this.buildOctreeFromBoxIndex();
|
|
3246
3001
|
}
|
|
3247
3002
|
},
|
|
3003
|
+
setAllModelVisible(visible) {
|
|
3004
|
+
const isVisible = Boolean(visible);
|
|
3005
|
+
const matrixCache = new this.THREE.Matrix4();
|
|
3006
|
+
|
|
3007
|
+
if (this._boxIndex && this._boxIndex.size > 0) {
|
|
3008
|
+
this._boxIndex.forEach(box => {
|
|
3009
|
+
if (!box || !box.userData) return;
|
|
3010
|
+
box.userData.visible = isVisible;
|
|
3011
|
+
});
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
if (scene) {
|
|
3015
|
+
scene.traverse(child => {
|
|
3016
|
+
if (!child || !child.isInstancedMesh) return;
|
|
3017
|
+
const userData = child.userData || {};
|
|
3018
|
+
if (!(userData.instancesMap instanceof Map) || userData.instancesMap.size === 0) return;
|
|
3019
|
+
if (!userData.copyMatrix) return;
|
|
3020
|
+
|
|
3021
|
+
userData.instancesMap.forEach(instanceInfo => {
|
|
3022
|
+
const instanceIndex =
|
|
3023
|
+
instanceInfo && typeof instanceInfo.instanceIndex === 'number'
|
|
3024
|
+
? instanceInfo.instanceIndex
|
|
3025
|
+
: null;
|
|
3026
|
+
if (instanceIndex === null) return;
|
|
3027
|
+
|
|
3028
|
+
if (isVisible) {
|
|
3029
|
+
matrixCache.copy(userData.copyMatrix);
|
|
3030
|
+
child.setMatrixAt(instanceIndex, matrixCache);
|
|
3031
|
+
} else {
|
|
3032
|
+
matrixCache.copy(userData.copyMatrix).makeTranslation(9999999, 9999999, 9999999);
|
|
3033
|
+
child.setMatrixAt(instanceIndex, matrixCache);
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
child.instanceMatrix.needsUpdate = true;
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
this.notifyCameraChange();
|
|
3041
|
+
if (this._boxIndex) {
|
|
3042
|
+
this.buildOctreeFromBoxIndex();
|
|
3043
|
+
}
|
|
3044
|
+
},
|
|
3248
3045
|
showOutlinePass(instanceId) {
|
|
3249
3046
|
let targetObj = this.getObjectByName(instanceId);
|
|
3250
|
-
targetObj.forEach(
|
|
3047
|
+
targetObj.forEach(children => {
|
|
3251
3048
|
if (children.isMesh) {
|
|
3252
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3253
|
-
instanceId,
|
|
3254
|
-
);
|
|
3049
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3255
3050
|
if (outlinePass) {
|
|
3256
3051
|
if (children.isInstancedMesh) {
|
|
3257
|
-
const proxy = this.ensureOutlineInstanceProxy(
|
|
3258
|
-
children,
|
|
3259
|
-
instanceIndex,
|
|
3260
|
-
);
|
|
3052
|
+
const proxy = this.ensureOutlineInstanceProxy(children, instanceIndex);
|
|
3261
3053
|
if (proxy && !outlinePass.selectedObjects.includes(proxy)) {
|
|
3262
3054
|
outlinePass.selectedObjects.push(proxy);
|
|
3263
3055
|
}
|
|
@@ -3270,11 +3062,9 @@ export default {
|
|
|
3270
3062
|
},
|
|
3271
3063
|
hideOutlinePass(instanceId) {
|
|
3272
3064
|
let targetObj = this.getObjectByName(instanceId);
|
|
3273
|
-
targetObj.forEach(
|
|
3065
|
+
targetObj.forEach(children => {
|
|
3274
3066
|
if (children.isMesh) {
|
|
3275
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3276
|
-
instanceId,
|
|
3277
|
-
);
|
|
3067
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3278
3068
|
if (outlinePass) {
|
|
3279
3069
|
if (children.isInstancedMesh) {
|
|
3280
3070
|
this.removeOutlineInstanceProxy(children, instanceIndex);
|
|
@@ -3312,11 +3102,9 @@ export default {
|
|
|
3312
3102
|
for (const key in ele.attr) {
|
|
3313
3103
|
switch (key) {
|
|
3314
3104
|
case 'nColor':
|
|
3315
|
-
targetObj.forEach(
|
|
3105
|
+
targetObj.forEach(children => {
|
|
3316
3106
|
if (children.isMesh) {
|
|
3317
|
-
children.material.userData[key] = new this.THREE.Color(
|
|
3318
|
-
ele.attr[key],
|
|
3319
|
-
);
|
|
3107
|
+
children.material.userData[key] = new this.THREE.Color(ele.attr[key]);
|
|
3320
3108
|
}
|
|
3321
3109
|
});
|
|
3322
3110
|
break;
|
|
@@ -3334,18 +3122,12 @@ export default {
|
|
|
3334
3122
|
for (const key in ele.attr) {
|
|
3335
3123
|
switch (key) {
|
|
3336
3124
|
case 'nColor':
|
|
3337
|
-
targetObj.forEach(
|
|
3125
|
+
targetObj.forEach(children => {
|
|
3338
3126
|
if (children.isMesh) {
|
|
3339
|
-
const { instanceIndex } = children.userData.instancesMap.get(
|
|
3340
|
-
|
|
3341
|
-
);
|
|
3342
|
-
children.setColorAt(
|
|
3343
|
-
instanceIndex,
|
|
3344
|
-
children.material.userData['oColor'],
|
|
3345
|
-
);
|
|
3127
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3128
|
+
children.setColorAt(instanceIndex, children.material.userData['oColor']);
|
|
3346
3129
|
children.instanceColor.needsUpdate = true;
|
|
3347
|
-
children.material.userData[key] =
|
|
3348
|
-
children.material.userData['oColor'];
|
|
3130
|
+
children.material.userData[key] = children.material.userData['oColor'];
|
|
3349
3131
|
}
|
|
3350
3132
|
});
|
|
3351
3133
|
break;
|
|
@@ -3363,55 +3145,37 @@ export default {
|
|
|
3363
3145
|
for (const key in ele.attr) {
|
|
3364
3146
|
switch (key) {
|
|
3365
3147
|
case 'color':
|
|
3366
|
-
obj.forEach(
|
|
3148
|
+
obj.forEach(children => {
|
|
3367
3149
|
if (children.isMesh) {
|
|
3368
|
-
const {
|
|
3369
|
-
|
|
3370
|
-
} = children.userData.instancesMap.get(instanceId);
|
|
3371
|
-
children.setColorAt(
|
|
3372
|
-
instanceIndex,
|
|
3373
|
-
children.material.userData.nColor,
|
|
3374
|
-
);
|
|
3150
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3151
|
+
children.setColorAt(instanceIndex, children.material.userData.nColor);
|
|
3375
3152
|
children.instanceColor.needsUpdate = true;
|
|
3376
3153
|
if (outlinePass) {
|
|
3377
3154
|
if (children.isInstancedMesh) {
|
|
3378
|
-
this.removeOutlineInstanceProxy(
|
|
3379
|
-
children,
|
|
3380
|
-
instanceIndex,
|
|
3381
|
-
);
|
|
3155
|
+
this.removeOutlineInstanceProxy(children, instanceIndex);
|
|
3382
3156
|
} else {
|
|
3383
|
-
const idx = outlinePass.selectedObjects.indexOf(
|
|
3384
|
-
|
|
3385
|
-
);
|
|
3386
|
-
if (idx !== -1)
|
|
3387
|
-
outlinePass.selectedObjects.splice(idx, 1);
|
|
3157
|
+
const idx = outlinePass.selectedObjects.indexOf(children);
|
|
3158
|
+
if (idx !== -1) outlinePass.selectedObjects.splice(idx, 1);
|
|
3388
3159
|
}
|
|
3389
3160
|
}
|
|
3390
3161
|
}
|
|
3391
3162
|
});
|
|
3392
3163
|
break;
|
|
3393
3164
|
case 'visible':
|
|
3394
|
-
obj.forEach(
|
|
3395
|
-
const {
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
} = children.userData.instancesMap.get(instanceId);
|
|
3399
|
-
const restoreMatrix = new this.THREE.Matrix4().copy(
|
|
3400
|
-
copyMatrix,
|
|
3401
|
-
);
|
|
3165
|
+
obj.forEach(children => {
|
|
3166
|
+
const { instanceIndex, copyMatrix } =
|
|
3167
|
+
children.userData.instancesMap.get(instanceId);
|
|
3168
|
+
const restoreMatrix = new this.THREE.Matrix4().copy(copyMatrix);
|
|
3402
3169
|
children.setMatrixAt(instanceIndex, restoreMatrix);
|
|
3403
3170
|
children.instanceMatrix.needsUpdate = true;
|
|
3404
3171
|
});
|
|
3405
3172
|
break;
|
|
3406
3173
|
case 'opacity':
|
|
3407
|
-
obj.forEach(
|
|
3174
|
+
obj.forEach(children => {
|
|
3408
3175
|
if (children.isMesh) {
|
|
3409
|
-
const {
|
|
3410
|
-
instanceIndex,
|
|
3411
|
-
} = children.userData.instancesMap.get(instanceId);
|
|
3176
|
+
const { instanceIndex } = children.userData.instancesMap.get(instanceId);
|
|
3412
3177
|
const opacity = children.geometry.attributes.opacity.array;
|
|
3413
|
-
opacity[instanceIndex] =
|
|
3414
|
-
children.material.userData.nOpacity;
|
|
3178
|
+
opacity[instanceIndex] = children.material.userData.nOpacity;
|
|
3415
3179
|
children.geometry.attributes.opacity.needsUpdate = true;
|
|
3416
3180
|
}
|
|
3417
3181
|
});
|
|
@@ -3426,9 +3190,9 @@ export default {
|
|
|
3426
3190
|
if (!scene) return;
|
|
3427
3191
|
if (Array.isArray(name)) {
|
|
3428
3192
|
const box3 = new this.THREE.Box3();
|
|
3429
|
-
name.forEach(
|
|
3193
|
+
name.forEach(n => {
|
|
3430
3194
|
const arr = this.getObjectByName(n);
|
|
3431
|
-
arr.forEach(
|
|
3195
|
+
arr.forEach(o => {
|
|
3432
3196
|
box3.expandByObject(o);
|
|
3433
3197
|
});
|
|
3434
3198
|
});
|
|
@@ -3466,17 +3230,14 @@ export default {
|
|
|
3466
3230
|
*/
|
|
3467
3231
|
updatePropertyByCustom(params) {
|
|
3468
3232
|
if (!scene) return;
|
|
3469
|
-
scene.traverse(
|
|
3470
|
-
if (
|
|
3471
|
-
child.isMesh &&
|
|
3472
|
-
child.userData[params.customName] === params.customValue
|
|
3473
|
-
) {
|
|
3233
|
+
scene.traverse(child => {
|
|
3234
|
+
if (child.isMesh && child.userData[params.customName] === params.customValue) {
|
|
3474
3235
|
for (const key in params.attr) {
|
|
3475
3236
|
switch (key) {
|
|
3476
3237
|
case 'color':
|
|
3477
3238
|
child.setColorAt(
|
|
3478
3239
|
obj.userData.instanceIndex,
|
|
3479
|
-
new this.THREE.Color(params.attr[key])
|
|
3240
|
+
new this.THREE.Color(params.attr[key])
|
|
3480
3241
|
);
|
|
3481
3242
|
child.instanceColor.needsUpdate = true;
|
|
3482
3243
|
break;
|
|
@@ -3508,7 +3269,7 @@ export default {
|
|
|
3508
3269
|
params.heading,
|
|
3509
3270
|
params.pitch,
|
|
3510
3271
|
params.roll,
|
|
3511
|
-
enableTransition
|
|
3272
|
+
enableTransition
|
|
3512
3273
|
);
|
|
3513
3274
|
cameraControls.update(0);
|
|
3514
3275
|
},
|
|
@@ -3533,14 +3294,10 @@ export default {
|
|
|
3533
3294
|
let distance = Math.min(maxDim * 100, baseDistance);
|
|
3534
3295
|
let direction = new this.THREE.Vector3(1, 1, 1).normalize();
|
|
3535
3296
|
|
|
3536
|
-
let p = new this.THREE.Vector3()
|
|
3537
|
-
.copy(center)
|
|
3538
|
-
.add(direction.multiplyScalar(distance));
|
|
3297
|
+
let p = new this.THREE.Vector3().copy(center).add(direction.multiplyScalar(distance));
|
|
3539
3298
|
let cameraCenter = viewAll
|
|
3540
3299
|
? new this.THREE.Vector3(p.x, p.y, p.z)
|
|
3541
|
-
: new this.THREE.Vector3(p.x, p.y, p.z).addScalar(
|
|
3542
|
-
Math.max(size.x, size.y, size.z),
|
|
3543
|
-
);
|
|
3300
|
+
: new this.THREE.Vector3(p.x, p.y, p.z).addScalar(Math.max(size.x, size.y, size.z));
|
|
3544
3301
|
cameraControls.setLookAt(
|
|
3545
3302
|
cameraCenter.x,
|
|
3546
3303
|
cameraCenter.y,
|
|
@@ -3548,7 +3305,7 @@ export default {
|
|
|
3548
3305
|
center.x,
|
|
3549
3306
|
center.y,
|
|
3550
3307
|
center.z,
|
|
3551
|
-
true
|
|
3308
|
+
true
|
|
3552
3309
|
);
|
|
3553
3310
|
},
|
|
3554
3311
|
// 添加广告牌
|
|
@@ -3577,14 +3334,9 @@ export default {
|
|
|
3577
3334
|
if (!scene) return [];
|
|
3578
3335
|
let object = [];
|
|
3579
3336
|
const instancedMeshProps = instanceToInstancedMeshMap.get(name);
|
|
3580
|
-
scene.traverse(
|
|
3581
|
-
const tempName = instancedMeshProps
|
|
3582
|
-
|
|
3583
|
-
: name;
|
|
3584
|
-
if (
|
|
3585
|
-
item.name == tempName &&
|
|
3586
|
-
item.type.toLowerCase() != passType.toLowerCase()
|
|
3587
|
-
) {
|
|
3337
|
+
scene.traverse(item => {
|
|
3338
|
+
const tempName = instancedMeshProps ? instancedMeshProps.drawObjectId : name;
|
|
3339
|
+
if (item.name == tempName && item.type.toLowerCase() != passType.toLowerCase()) {
|
|
3588
3340
|
object.push(item);
|
|
3589
3341
|
}
|
|
3590
3342
|
});
|
|
@@ -3607,7 +3359,7 @@ export default {
|
|
|
3607
3359
|
: this.modelStateManager;
|
|
3608
3360
|
if (!modelIds) return;
|
|
3609
3361
|
if (Array.isArray(modelIds)) {
|
|
3610
|
-
modelIds.forEach(
|
|
3362
|
+
modelIds.forEach(id => {
|
|
3611
3363
|
const modelId = this.formatModelId(id);
|
|
3612
3364
|
modelState.bypassCullingModelIds.add(modelId);
|
|
3613
3365
|
});
|
|
@@ -3628,7 +3380,7 @@ export default {
|
|
|
3628
3380
|
: this.modelStateManager;
|
|
3629
3381
|
if (!modelIds) return;
|
|
3630
3382
|
if (Array.isArray(modelIds)) {
|
|
3631
|
-
modelIds.forEach(
|
|
3383
|
+
modelIds.forEach(id => {
|
|
3632
3384
|
const modelId = this.formatModelId(id);
|
|
3633
3385
|
modelState.bypassCullingModelIds.delete(modelId);
|
|
3634
3386
|
});
|
|
@@ -3647,7 +3399,7 @@ export default {
|
|
|
3647
3399
|
removeObjectById(id) {
|
|
3648
3400
|
if (!scene) return;
|
|
3649
3401
|
let array = this.getObjectByName(id);
|
|
3650
|
-
array.forEach(
|
|
3402
|
+
array.forEach(item => {
|
|
3651
3403
|
if (item.name === id) {
|
|
3652
3404
|
item.material && item.material.dispose();
|
|
3653
3405
|
item.geometry && item.geometry.dispose();
|
|
@@ -3662,7 +3414,7 @@ export default {
|
|
|
3662
3414
|
removeObjectByName(name) {
|
|
3663
3415
|
if (!scene) return;
|
|
3664
3416
|
let array = this.getObjectByName(name);
|
|
3665
|
-
array.forEach(
|
|
3417
|
+
array.forEach(item => {
|
|
3666
3418
|
item.material && item.material.dispose();
|
|
3667
3419
|
item.geometry && item.geometry.dispose();
|
|
3668
3420
|
if (item.isMesh) {
|
|
@@ -3673,7 +3425,7 @@ export default {
|
|
|
3673
3425
|
},
|
|
3674
3426
|
// 删除场景中所有的实体
|
|
3675
3427
|
removeAll() {
|
|
3676
|
-
return new Promise(
|
|
3428
|
+
return new Promise(resolve => {
|
|
3677
3429
|
if (scene) {
|
|
3678
3430
|
this.removeTraverse();
|
|
3679
3431
|
this.removeModelByDocumentId();
|
|
@@ -3689,7 +3441,7 @@ export default {
|
|
|
3689
3441
|
if (length > 0) {
|
|
3690
3442
|
let list = modelGroup.children[0];
|
|
3691
3443
|
if (!list) return;
|
|
3692
|
-
list.traverse(
|
|
3444
|
+
list.traverse(item => {
|
|
3693
3445
|
if (item.isMesh) {
|
|
3694
3446
|
item.material && item.material.dispose();
|
|
3695
3447
|
item.geometry && item.geometry.dispose();
|
|
@@ -3716,14 +3468,13 @@ export default {
|
|
|
3716
3468
|
cancelAnimationFrame(animateId);
|
|
3717
3469
|
|
|
3718
3470
|
if (this.noObserver && this.noObserver.outlineInstanceProxyMap) {
|
|
3719
|
-
this.noObserver.outlineInstanceProxyMap.forEach(
|
|
3471
|
+
this.noObserver.outlineInstanceProxyMap.forEach(proxy => {
|
|
3720
3472
|
if (outlinePass) {
|
|
3721
3473
|
const idx = outlinePass.selectedObjects.indexOf(proxy);
|
|
3722
3474
|
if (idx !== -1) outlinePass.selectedObjects.splice(idx, 1);
|
|
3723
3475
|
}
|
|
3724
3476
|
if (scene) scene.remove(proxy);
|
|
3725
|
-
if (proxy && proxy.material && proxy.material.dispose)
|
|
3726
|
-
proxy.material.dispose();
|
|
3477
|
+
if (proxy && proxy.material && proxy.material.dispose) proxy.material.dispose();
|
|
3727
3478
|
});
|
|
3728
3479
|
this.noObserver.outlineInstanceProxyMap.clear();
|
|
3729
3480
|
}
|
|
@@ -3778,36 +3529,17 @@ export default {
|
|
|
3778
3529
|
|
|
3779
3530
|
// 移除鼠标点击/按下事件监听器
|
|
3780
3531
|
if (renderer && renderer.domElement) {
|
|
3781
|
-
renderer.domElement.removeEventListener(
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
);
|
|
3786
|
-
renderer.domElement.removeEventListener(
|
|
3787
|
-
'mousedown',
|
|
3788
|
-
this.mouseDown,
|
|
3789
|
-
false,
|
|
3790
|
-
);
|
|
3791
|
-
renderer.domElement.removeEventListener(
|
|
3792
|
-
'pointerup',
|
|
3793
|
-
this.mouseClick,
|
|
3794
|
-
false,
|
|
3795
|
-
);
|
|
3796
|
-
renderer.domElement.removeEventListener(
|
|
3797
|
-
'pointerdown',
|
|
3798
|
-
this.mouseDown,
|
|
3799
|
-
false,
|
|
3800
|
-
);
|
|
3532
|
+
renderer.domElement.removeEventListener('mouseup', this.mouseClick, false);
|
|
3533
|
+
renderer.domElement.removeEventListener('mousedown', this.mouseDown, false);
|
|
3534
|
+
renderer.domElement.removeEventListener('pointerup', this.mouseClick, false);
|
|
3535
|
+
renderer.domElement.removeEventListener('pointerdown', this.mouseDown, false);
|
|
3801
3536
|
}
|
|
3802
3537
|
|
|
3803
3538
|
// 取消 pointer lock 并移除相关键盘事件
|
|
3804
3539
|
if (pointControls) {
|
|
3805
3540
|
if (this._onFirstPersonChange) {
|
|
3806
3541
|
try {
|
|
3807
|
-
pointControls.removeEventListener(
|
|
3808
|
-
'change',
|
|
3809
|
-
this._onFirstPersonChange,
|
|
3810
|
-
);
|
|
3542
|
+
pointControls.removeEventListener('change', this._onFirstPersonChange);
|
|
3811
3543
|
} catch (e) {}
|
|
3812
3544
|
this._onFirstPersonChange = null;
|
|
3813
3545
|
}
|
|
@@ -3833,10 +3565,7 @@ export default {
|
|
|
3833
3565
|
// 移除 cameraControls 事件监听
|
|
3834
3566
|
if (cameraControls) {
|
|
3835
3567
|
if (this._onControlStart)
|
|
3836
|
-
cameraControls.removeEventListener(
|
|
3837
|
-
'controlstart',
|
|
3838
|
-
this._onControlStart,
|
|
3839
|
-
);
|
|
3568
|
+
cameraControls.removeEventListener('controlstart', this._onControlStart);
|
|
3840
3569
|
if (this._onControlEnd)
|
|
3841
3570
|
cameraControls.removeEventListener('controlend', this._onControlEnd);
|
|
3842
3571
|
this._onControlStart = null;
|
|
@@ -3871,14 +3600,12 @@ export default {
|
|
|
3871
3600
|
drawCurve(params) {
|
|
3872
3601
|
this.removeObjectByName(params.name);
|
|
3873
3602
|
const route = [];
|
|
3874
|
-
params.path.forEach(
|
|
3603
|
+
params.path.forEach(element => {
|
|
3875
3604
|
route.push(new this.THREE.Vector3(element.x, element.y, element.z));
|
|
3876
3605
|
});
|
|
3877
3606
|
if (route.length > 1) {
|
|
3878
3607
|
curve = new this.THREE.CatmullRomCurve3(route);
|
|
3879
|
-
const geometryLine = new this.THREE.BufferGeometry().setFromPoints(
|
|
3880
|
-
curve.getPoints(5000),
|
|
3881
|
-
);
|
|
3608
|
+
const geometryLine = new this.THREE.BufferGeometry().setFromPoints(curve.getPoints(5000));
|
|
3882
3609
|
const materialLine = new this.THREE.LineBasicMaterial({
|
|
3883
3610
|
color: params.color,
|
|
3884
3611
|
depthTest: false,
|
|
@@ -3900,7 +3627,7 @@ export default {
|
|
|
3900
3627
|
drawTextureCurve(params) {
|
|
3901
3628
|
this.removeObjectByName(params.name);
|
|
3902
3629
|
const route = [];
|
|
3903
|
-
params.path.forEach(
|
|
3630
|
+
params.path.forEach(element => {
|
|
3904
3631
|
route.push(new this.THREE.Vector3(element.x, element.y, element.z));
|
|
3905
3632
|
});
|
|
3906
3633
|
// 画曲线
|
|
@@ -3909,9 +3636,7 @@ export default {
|
|
|
3909
3636
|
curve = new this.THREE.CatmullRomCurve3(route, false, 'catmullrom', 0);
|
|
3910
3637
|
const geometry = new this.THREE.TubeGeometry(curve, 5000, 0.5, 4);
|
|
3911
3638
|
//加载纹理
|
|
3912
|
-
lineTexture = new this.THREE.TextureLoader().load(
|
|
3913
|
-
'/static/arrow/arrow-right.png',
|
|
3914
|
-
);
|
|
3639
|
+
lineTexture = new this.THREE.TextureLoader().load('/static/arrow/arrow-right.png');
|
|
3915
3640
|
lineTexture.wrapS = this.THREE.RepeatWrapping;
|
|
3916
3641
|
lineTexture.wrapT = this.THREE.RepeatWrapping;
|
|
3917
3642
|
lineTexture.repeat.set(20, 1); //水平重复20次
|
|
@@ -3986,12 +3711,7 @@ export default {
|
|
|
3986
3711
|
camera.position.set(point.x, point.y + 5, point.z);
|
|
3987
3712
|
camera.lookAt(pointBox.x, pointBox.y + 5, pointBox.z);
|
|
3988
3713
|
cameraControls.setPosition(point.x, point.y + 5, point.z, false);
|
|
3989
|
-
cameraControls.setTarget(
|
|
3990
|
-
pointBox.x,
|
|
3991
|
-
pointBox.y + 5,
|
|
3992
|
-
pointBox.z,
|
|
3993
|
-
false,
|
|
3994
|
-
);
|
|
3714
|
+
cameraControls.setTarget(pointBox.x, pointBox.y + 5, pointBox.z, false);
|
|
3995
3715
|
progress += roamConfig.speed / 300;
|
|
3996
3716
|
|
|
3997
3717
|
if (typeof this._cameraChangeObserver === 'function') {
|
|
@@ -4016,7 +3736,7 @@ export default {
|
|
|
4016
3736
|
if (scene.children.length === 0) return;
|
|
4017
3737
|
for (let i = 0; i < scene.children.length; i++) {
|
|
4018
3738
|
console.log('scene', scene);
|
|
4019
|
-
scene.children[i].traverse(
|
|
3739
|
+
scene.children[i].traverse(item => {
|
|
4020
3740
|
if (!item.isMesh || !item.worldDir) return;
|
|
4021
3741
|
// 爆炸公式
|
|
4022
3742
|
this.computedBomb(item, val);
|
|
@@ -4048,7 +3768,7 @@ export default {
|
|
|
4048
3768
|
},
|
|
4049
3769
|
getClippingPlanes() {
|
|
4050
3770
|
let clippingPlanesConstant = [];
|
|
4051
|
-
renderer.clippingPlanes.forEach(
|
|
3771
|
+
renderer.clippingPlanes.forEach(item => {
|
|
4052
3772
|
clippingPlanesConstant.push(item.constant);
|
|
4053
3773
|
});
|
|
4054
3774
|
return clippingPlanesConstant;
|
|
@@ -4065,39 +3785,27 @@ export default {
|
|
|
4065
3785
|
const clippingPlanes = [
|
|
4066
3786
|
new this.THREE.Plane(
|
|
4067
3787
|
new this.THREE.Vector3(-1, 0, 0),
|
|
4068
|
-
this.clippingPlanesConstants
|
|
4069
|
-
? this.clippingPlanesConstants[0]
|
|
4070
|
-
: Math.ceil(max.x),
|
|
3788
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[0] : Math.ceil(max.x)
|
|
4071
3789
|
),
|
|
4072
3790
|
new this.THREE.Plane(
|
|
4073
3791
|
new this.THREE.Vector3(0, -1, 0),
|
|
4074
|
-
this.clippingPlanesConstants
|
|
4075
|
-
? this.clippingPlanesConstants[1]
|
|
4076
|
-
: Math.ceil(max.y),
|
|
3792
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[1] : Math.ceil(max.y)
|
|
4077
3793
|
),
|
|
4078
3794
|
new this.THREE.Plane(
|
|
4079
3795
|
new this.THREE.Vector3(0, 0, -1),
|
|
4080
|
-
this.clippingPlanesConstants
|
|
4081
|
-
? this.clippingPlanesConstants[2]
|
|
4082
|
-
: Math.ceil(max.z),
|
|
3796
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[2] : Math.ceil(max.z)
|
|
4083
3797
|
),
|
|
4084
3798
|
new this.THREE.Plane(
|
|
4085
3799
|
new this.THREE.Vector3(1, 0, 0),
|
|
4086
|
-
this.clippingPlanesConstants
|
|
4087
|
-
? this.clippingPlanesConstants[3]
|
|
4088
|
-
: Math.ceil(-min.x),
|
|
3800
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[3] : Math.ceil(-min.x)
|
|
4089
3801
|
),
|
|
4090
3802
|
new this.THREE.Plane(
|
|
4091
3803
|
new this.THREE.Vector3(0, 1, 0),
|
|
4092
|
-
this.clippingPlanesConstants
|
|
4093
|
-
? this.clippingPlanesConstants[4]
|
|
4094
|
-
: Math.ceil(-min.y),
|
|
3804
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[4] : Math.ceil(-min.y)
|
|
4095
3805
|
),
|
|
4096
3806
|
new this.THREE.Plane(
|
|
4097
3807
|
new this.THREE.Vector3(0, 0, 1),
|
|
4098
|
-
this.clippingPlanesConstants
|
|
4099
|
-
? this.clippingPlanesConstants[5]
|
|
4100
|
-
: Math.ceil(-min.z),
|
|
3808
|
+
this.clippingPlanesConstants ? this.clippingPlanesConstants[5] : Math.ceil(-min.z)
|
|
4101
3809
|
),
|
|
4102
3810
|
];
|
|
4103
3811
|
|
|
@@ -4126,7 +3834,7 @@ export default {
|
|
|
4126
3834
|
z: min.y,
|
|
4127
3835
|
},
|
|
4128
3836
|
},
|
|
4129
|
-
clippingPlanes
|
|
3837
|
+
clippingPlanes
|
|
4130
3838
|
);
|
|
4131
3839
|
}
|
|
4132
3840
|
return {
|
|
@@ -4173,30 +3881,12 @@ export default {
|
|
|
4173
3881
|
const boundingBox = new this.THREE.Box3().copy(obj.boundingBox);
|
|
4174
3882
|
boundingBox.applyMatrix4(obj.matrixWorld);
|
|
4175
3883
|
let clippingPlanes = [
|
|
4176
|
-
new this.THREE.Plane(
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
),
|
|
4180
|
-
new this.THREE.Plane(
|
|
4181
|
-
|
|
4182
|
-
Math.ceil(boundingBox.max.y),
|
|
4183
|
-
),
|
|
4184
|
-
new this.THREE.Plane(
|
|
4185
|
-
new this.THREE.Vector3(0, 0, -1),
|
|
4186
|
-
Math.ceil(boundingBox.max.z),
|
|
4187
|
-
),
|
|
4188
|
-
new this.THREE.Plane(
|
|
4189
|
-
new this.THREE.Vector3(1, 0, 0),
|
|
4190
|
-
-Math.floor(boundingBox.min.x),
|
|
4191
|
-
),
|
|
4192
|
-
new this.THREE.Plane(
|
|
4193
|
-
new this.THREE.Vector3(0, 1, 0),
|
|
4194
|
-
-Math.floor(boundingBox.min.y),
|
|
4195
|
-
),
|
|
4196
|
-
new this.THREE.Plane(
|
|
4197
|
-
new this.THREE.Vector3(0, 0, 1),
|
|
4198
|
-
-Math.floor(boundingBox.min.z),
|
|
4199
|
-
),
|
|
3884
|
+
new this.THREE.Plane(new this.THREE.Vector3(-1, 0, 0), Math.ceil(boundingBox.max.x)),
|
|
3885
|
+
new this.THREE.Plane(new this.THREE.Vector3(0, -1, 0), Math.ceil(boundingBox.max.y)),
|
|
3886
|
+
new this.THREE.Plane(new this.THREE.Vector3(0, 0, -1), Math.ceil(boundingBox.max.z)),
|
|
3887
|
+
new this.THREE.Plane(new this.THREE.Vector3(1, 0, 0), -Math.floor(boundingBox.min.x)),
|
|
3888
|
+
new this.THREE.Plane(new this.THREE.Vector3(0, 1, 0), -Math.floor(boundingBox.min.y)),
|
|
3889
|
+
new this.THREE.Plane(new this.THREE.Vector3(0, 0, 1), -Math.floor(boundingBox.min.z)),
|
|
4200
3890
|
];
|
|
4201
3891
|
obj.material.clippingPlanes = clippingPlanes;
|
|
4202
3892
|
obj.material.needsUpdate = true;
|
|
@@ -4217,7 +3907,7 @@ export default {
|
|
|
4217
3907
|
y: Math.floor(boundingBox.min.z),
|
|
4218
3908
|
z: Math.floor(boundingBox.min.y),
|
|
4219
3909
|
},
|
|
4220
|
-
obj.material.clippingPlanes
|
|
3910
|
+
obj.material.clippingPlanes
|
|
4221
3911
|
);
|
|
4222
3912
|
// cube.material.clippingPlanes
|
|
4223
3913
|
}
|
|
@@ -4255,7 +3945,7 @@ export default {
|
|
|
4255
3945
|
'-z轴': 0,
|
|
4256
3946
|
};
|
|
4257
3947
|
gui && gui.destroy();
|
|
4258
|
-
clippingMesh.forEach(
|
|
3948
|
+
clippingMesh.forEach(item => {
|
|
4259
3949
|
item.material.clippingPlanes = Object.freeze([]);
|
|
4260
3950
|
item.material.needsUpdate = true;
|
|
4261
3951
|
});
|
|
@@ -4271,7 +3961,7 @@ export default {
|
|
|
4271
3961
|
.step(0.001)
|
|
4272
3962
|
.min(boudingValue.min.x)
|
|
4273
3963
|
.max(boudingValue.max.x)
|
|
4274
|
-
.onChange(
|
|
3964
|
+
.onChange(d => {
|
|
4275
3965
|
objClipp1[0].constant = d;
|
|
4276
3966
|
objClipp2 && (objClipp2[0].constant = d);
|
|
4277
3967
|
});
|
|
@@ -4280,7 +3970,7 @@ export default {
|
|
|
4280
3970
|
.step(0.001)
|
|
4281
3971
|
.min(boudingValue.min.x)
|
|
4282
3972
|
.max(boudingValue.max.x)
|
|
4283
|
-
.onChange(
|
|
3973
|
+
.onChange(d => {
|
|
4284
3974
|
objClipp1[3].constant = -d;
|
|
4285
3975
|
objClipp2 && (objClipp2[3].constant = -d);
|
|
4286
3976
|
});
|
|
@@ -4289,7 +3979,7 @@ export default {
|
|
|
4289
3979
|
.step(0.001)
|
|
4290
3980
|
.min(boudingValue.min.y)
|
|
4291
3981
|
.max(boudingValue.max.y)
|
|
4292
|
-
.onChange(
|
|
3982
|
+
.onChange(d => {
|
|
4293
3983
|
objClipp1[2].constant = d;
|
|
4294
3984
|
objClipp2 && (objClipp2[2].constant = d);
|
|
4295
3985
|
});
|
|
@@ -4298,7 +3988,7 @@ export default {
|
|
|
4298
3988
|
.step(0.001)
|
|
4299
3989
|
.min(boudingValue.min.y)
|
|
4300
3990
|
.max(boudingValue.max.y)
|
|
4301
|
-
.onChange(
|
|
3991
|
+
.onChange(d => {
|
|
4302
3992
|
objClipp1[5].constant = -d;
|
|
4303
3993
|
objClipp2 && (objClipp2[5].constant = -d);
|
|
4304
3994
|
});
|
|
@@ -4307,7 +3997,7 @@ export default {
|
|
|
4307
3997
|
.step(0.001)
|
|
4308
3998
|
.min(boudingValue.min.z)
|
|
4309
3999
|
.max(boudingValue.max.z)
|
|
4310
|
-
.onChange(
|
|
4000
|
+
.onChange(d => {
|
|
4311
4001
|
objClipp1[1].constant = d;
|
|
4312
4002
|
objClipp2 && (objClipp2[1].constant = d);
|
|
4313
4003
|
});
|
|
@@ -4316,7 +4006,7 @@ export default {
|
|
|
4316
4006
|
.step(0.001)
|
|
4317
4007
|
.min(boudingValue.min.z)
|
|
4318
4008
|
.max(boudingValue.max.z)
|
|
4319
|
-
.onChange(
|
|
4009
|
+
.onChange(d => {
|
|
4320
4010
|
objClipp1[4].constant = -d;
|
|
4321
4011
|
objClipp2 && (objClipp2[4].constant = -d);
|
|
4322
4012
|
});
|
|
@@ -4332,7 +4022,7 @@ export default {
|
|
|
4332
4022
|
new this.THREE.Vector3(),
|
|
4333
4023
|
new this.THREE.Vector3(0, -1, 0),
|
|
4334
4024
|
0,
|
|
4335
|
-
10
|
|
4025
|
+
10
|
|
4336
4026
|
);
|
|
4337
4027
|
velocity = new this.THREE.Vector3(); //移动速度变量
|
|
4338
4028
|
direction = new this.THREE.Vector3(); //移动的方向变量
|
|
@@ -4364,16 +4054,8 @@ export default {
|
|
|
4364
4054
|
cameraControls.enabled = false;
|
|
4365
4055
|
window.addEventListener('keydown', this.onKeyDown, false);
|
|
4366
4056
|
window.addEventListener('keyup', this.onKeyUp, false);
|
|
4367
|
-
renderer.domElement.removeEventListener(
|
|
4368
|
-
|
|
4369
|
-
this.mouseClick,
|
|
4370
|
-
false,
|
|
4371
|
-
);
|
|
4372
|
-
renderer.domElement.removeEventListener(
|
|
4373
|
-
'mousedown',
|
|
4374
|
-
this.mouseDown,
|
|
4375
|
-
false,
|
|
4376
|
-
);
|
|
4057
|
+
renderer.domElement.removeEventListener('mouseup', this.mouseClick, false);
|
|
4058
|
+
renderer.domElement.removeEventListener('mousedown', this.mouseDown, false);
|
|
4377
4059
|
if (typeof this._cameraChangeObserver === 'function') {
|
|
4378
4060
|
this._cameraChangeObserver('firstPersonLock');
|
|
4379
4061
|
}
|
|
@@ -4386,10 +4068,7 @@ export default {
|
|
|
4386
4068
|
this.home();
|
|
4387
4069
|
try {
|
|
4388
4070
|
if (this._onFirstPersonChange && pointControls) {
|
|
4389
|
-
pointControls.removeEventListener(
|
|
4390
|
-
'change',
|
|
4391
|
-
this._onFirstPersonChange,
|
|
4392
|
-
);
|
|
4071
|
+
pointControls.removeEventListener('change', this._onFirstPersonChange);
|
|
4393
4072
|
}
|
|
4394
4073
|
} catch (e) {}
|
|
4395
4074
|
if (this.noObserver) {
|
|
@@ -4398,16 +4077,8 @@ export default {
|
|
|
4398
4077
|
setTimeout(() => {
|
|
4399
4078
|
window.removeEventListener('keydown', this.onKeyDown);
|
|
4400
4079
|
window.removeEventListener('keyup', this.onKeyUp);
|
|
4401
|
-
renderer.domElement.addEventListener(
|
|
4402
|
-
|
|
4403
|
-
this.mouseClick,
|
|
4404
|
-
false,
|
|
4405
|
-
);
|
|
4406
|
-
renderer.domElement.addEventListener(
|
|
4407
|
-
'mousedown',
|
|
4408
|
-
this.mouseDown,
|
|
4409
|
-
false,
|
|
4410
|
-
);
|
|
4080
|
+
renderer.domElement.addEventListener('mouseup', this.mouseClick, false);
|
|
4081
|
+
renderer.domElement.addEventListener('mousedown', this.mouseDown, false);
|
|
4411
4082
|
// this.timeRender()
|
|
4412
4083
|
}, 0);
|
|
4413
4084
|
if (typeof this._cameraChangeObserver === 'function') {
|
|
@@ -4433,10 +4104,8 @@ export default {
|
|
|
4433
4104
|
direction.x = Number(moveRight) - Number(moveLeft);
|
|
4434
4105
|
// 将法向量的值归一化
|
|
4435
4106
|
direction.normalize();
|
|
4436
|
-
if (moveForward || moveBackward)
|
|
4437
|
-
|
|
4438
|
-
if (moveLeft || moveRight)
|
|
4439
|
-
velocity.x -= direction.x * removeSpeed * delta;
|
|
4107
|
+
if (moveForward || moveBackward) velocity.z -= direction.z * removeSpeed * delta;
|
|
4108
|
+
if (moveLeft || moveRight) velocity.x -= direction.x * removeSpeed * delta;
|
|
4440
4109
|
// }
|
|
4441
4110
|
// 复制相机的位置
|
|
4442
4111
|
downRaycaster.ray.origin.copy(control.position);
|
|
@@ -4444,9 +4113,7 @@ export default {
|
|
|
4444
4113
|
downRaycaster.ray.origin.y += 5;
|
|
4445
4114
|
// 判断是否停留在了立方体上面
|
|
4446
4115
|
let intersections =
|
|
4447
|
-
scene && scene.children
|
|
4448
|
-
? downRaycaster.intersectObjects(scene.children, true)
|
|
4449
|
-
: [];
|
|
4116
|
+
scene && scene.children ? downRaycaster.intersectObjects(scene.children, true) : [];
|
|
4450
4117
|
var onObject = intersections.length > 0;
|
|
4451
4118
|
if (onObject === true) {
|
|
4452
4119
|
velocity.y = Math.max(0, velocity.y);
|
|
@@ -4464,14 +4131,10 @@ export default {
|
|
|
4464
4131
|
}
|
|
4465
4132
|
if (this.noObserver) {
|
|
4466
4133
|
if (!this.noObserver._firstPersonLastPos) {
|
|
4467
|
-
this.noObserver._firstPersonLastPos = new this.THREE.Vector3().copy(
|
|
4468
|
-
control.position,
|
|
4469
|
-
);
|
|
4134
|
+
this.noObserver._firstPersonLastPos = new this.THREE.Vector3().copy(control.position);
|
|
4470
4135
|
}
|
|
4471
4136
|
const moved =
|
|
4472
|
-
this.noObserver._firstPersonLastPos.distanceToSquared(
|
|
4473
|
-
control.position,
|
|
4474
|
-
) > 1e-8;
|
|
4137
|
+
this.noObserver._firstPersonLastPos.distanceToSquared(control.position) > 1e-8;
|
|
4475
4138
|
if (moved) {
|
|
4476
4139
|
this.noObserver._firstPersonLastPos.copy(control.position);
|
|
4477
4140
|
if (typeof this._cameraChangeObserver === 'function') {
|
|
@@ -4588,7 +4251,7 @@ export default {
|
|
|
4588
4251
|
scene,
|
|
4589
4252
|
camera,
|
|
4590
4253
|
instructions.offsetWidth,
|
|
4591
|
-
instructions.offsetHeight
|
|
4254
|
+
instructions.offsetHeight
|
|
4592
4255
|
);
|
|
4593
4256
|
threeMeasure.start();
|
|
4594
4257
|
break;
|
|
@@ -4598,7 +4261,7 @@ export default {
|
|
|
4598
4261
|
scene,
|
|
4599
4262
|
camera,
|
|
4600
4263
|
instructions.offsetWidth,
|
|
4601
|
-
instructions.offsetHeight
|
|
4264
|
+
instructions.offsetHeight
|
|
4602
4265
|
);
|
|
4603
4266
|
threeMeasure.start();
|
|
4604
4267
|
break;
|
|
@@ -4608,7 +4271,7 @@ export default {
|
|
|
4608
4271
|
scene,
|
|
4609
4272
|
camera,
|
|
4610
4273
|
instructions.offsetWidth,
|
|
4611
|
-
instructions.offsetHeight
|
|
4274
|
+
instructions.offsetHeight
|
|
4612
4275
|
);
|
|
4613
4276
|
threeMeasure.start();
|
|
4614
4277
|
break;
|
|
@@ -4648,11 +4311,9 @@ export default {
|
|
|
4648
4311
|
let translateMatrix = new this.THREE.Matrix4().makeTranslation(
|
|
4649
4312
|
distance.x,
|
|
4650
4313
|
distance.y,
|
|
4651
|
-
distance.z
|
|
4314
|
+
distance.z
|
|
4652
4315
|
);
|
|
4653
|
-
let translateMatrixInvert = new this.THREE.Matrix4()
|
|
4654
|
-
.copy(translateMatrix)
|
|
4655
|
-
.invert();
|
|
4316
|
+
let translateMatrixInvert = new this.THREE.Matrix4().copy(translateMatrix).invert();
|
|
4656
4317
|
if (object.userData.translateMatrixInvert) {
|
|
4657
4318
|
object.applyMatrix4(object.userData.translateMatrixInvert);
|
|
4658
4319
|
}
|
|
@@ -4672,38 +4333,22 @@ export default {
|
|
|
4672
4333
|
// 原始向量 = 变化后的向量 * 逆矩阵
|
|
4673
4334
|
let center = object.userData.center;
|
|
4674
4335
|
let v = new this.THREE.Vector3(center.x, center.y, center.z).negate();
|
|
4675
|
-
let translateMatrix = new this.THREE.Matrix4().makeTranslation(
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
);
|
|
4680
|
-
let rotateX = new this.THREE.Matrix4().makeRotationX(
|
|
4681
|
-
degrees.x * (Math.PI / 180),
|
|
4682
|
-
);
|
|
4683
|
-
let rotateY = new this.THREE.Matrix4().makeRotationY(
|
|
4684
|
-
degrees.y * (Math.PI / 180),
|
|
4685
|
-
);
|
|
4686
|
-
let rotateZ = new this.THREE.Matrix4().makeRotationZ(
|
|
4687
|
-
degrees.z * (Math.PI / 180),
|
|
4688
|
-
);
|
|
4336
|
+
let translateMatrix = new this.THREE.Matrix4().makeTranslation(v.x, v.y, v.z);
|
|
4337
|
+
let rotateX = new this.THREE.Matrix4().makeRotationX(degrees.x * (Math.PI / 180));
|
|
4338
|
+
let rotateY = new this.THREE.Matrix4().makeRotationY(degrees.y * (Math.PI / 180));
|
|
4339
|
+
let rotateZ = new this.THREE.Matrix4().makeRotationZ(degrees.z * (Math.PI / 180));
|
|
4689
4340
|
let combineMatrix = new this.THREE.Matrix4()
|
|
4690
4341
|
.multiply(rotateX)
|
|
4691
4342
|
.multiply(rotateY)
|
|
4692
4343
|
.multiply(rotateZ);
|
|
4693
4344
|
object.applyMatrix4(translateMatrix);
|
|
4694
|
-
let combineMatrixInvert = new this.THREE.Matrix4()
|
|
4695
|
-
.copy(combineMatrix)
|
|
4696
|
-
.invert();
|
|
4345
|
+
let combineMatrixInvert = new this.THREE.Matrix4().copy(combineMatrix).invert();
|
|
4697
4346
|
if (object.userData.combineMatrixInvert) {
|
|
4698
4347
|
object.applyMatrix4(object.userData.combineMatrixInvert);
|
|
4699
4348
|
}
|
|
4700
4349
|
object.userData.combineMatrixInvert = combineMatrixInvert;
|
|
4701
4350
|
object.applyMatrix4(combineMatrix);
|
|
4702
|
-
let translateM = new this.THREE.Matrix4().makeTranslation(
|
|
4703
|
-
center.x,
|
|
4704
|
-
center.y,
|
|
4705
|
-
center.z,
|
|
4706
|
-
);
|
|
4351
|
+
let translateM = new this.THREE.Matrix4().makeTranslation(center.x, center.y, center.z);
|
|
4707
4352
|
object.applyMatrix4(translateM);
|
|
4708
4353
|
object.userData.position = new this.THREE.Vector3().copy(object.position);
|
|
4709
4354
|
object.userData.rotate = degrees;
|
|
@@ -4715,7 +4360,7 @@ export default {
|
|
|
4715
4360
|
isolate(object) {
|
|
4716
4361
|
if (!scene) return;
|
|
4717
4362
|
// 隔离 将目标实体以外的实体隐藏掉
|
|
4718
|
-
scene.traverse(
|
|
4363
|
+
scene.traverse(item => {
|
|
4719
4364
|
if (item.isMesh && item.name !== object.name) {
|
|
4720
4365
|
const offsetMatrix = new this.THREE.Matrix4()
|
|
4721
4366
|
.copy(item.userData.copyMatrix)
|
|
@@ -4728,12 +4373,9 @@ export default {
|
|
|
4728
4373
|
// 还原操作 将修改过的实体进行恢复
|
|
4729
4374
|
restore() {
|
|
4730
4375
|
if (!scene) return;
|
|
4731
|
-
scene.traverse(
|
|
4376
|
+
scene.traverse(item => {
|
|
4732
4377
|
if (item.isMesh) {
|
|
4733
|
-
item.setColorAt(
|
|
4734
|
-
item.userData.instanceIndex,
|
|
4735
|
-
item.material.userData.nColor,
|
|
4736
|
-
);
|
|
4378
|
+
item.setColorAt(item.userData.instanceIndex, item.material.userData.nColor);
|
|
4737
4379
|
item.instanceColor.needsUpdate = true;
|
|
4738
4380
|
item.userData.translate = {
|
|
4739
4381
|
x: 0,
|
|
@@ -4757,26 +4399,17 @@ export default {
|
|
|
4757
4399
|
});
|
|
4758
4400
|
item.userData.combineMatrixInvert = null;
|
|
4759
4401
|
}
|
|
4760
|
-
const offsetMatrix = new this.THREE.Matrix4().copy(
|
|
4761
|
-
item.userData.copyMatrix,
|
|
4762
|
-
);
|
|
4402
|
+
const offsetMatrix = new this.THREE.Matrix4().copy(item.userData.copyMatrix);
|
|
4763
4403
|
item.setMatrixAt(item.userData.instanceIndex, offsetMatrix);
|
|
4764
4404
|
item.instanceMatrix.needsUpdate = true;
|
|
4765
4405
|
}
|
|
4766
4406
|
});
|
|
4767
4407
|
},
|
|
4768
4408
|
// 添加自定义模型, 暂时只支持glb、gltf格式
|
|
4769
|
-
addCustomModel(
|
|
4770
|
-
name,
|
|
4771
|
-
position,
|
|
4772
|
-
url,
|
|
4773
|
-
scale = 1,
|
|
4774
|
-
immediately = false,
|
|
4775
|
-
callback,
|
|
4776
|
-
) {
|
|
4409
|
+
addCustomModel(name, position, url, scale = 1, immediately = false, callback) {
|
|
4777
4410
|
const loader = new GLTFLoader();
|
|
4778
4411
|
let locationModel = null;
|
|
4779
|
-
loader.load(url,
|
|
4412
|
+
loader.load(url, gltf => {
|
|
4780
4413
|
locationModel = gltf.scene;
|
|
4781
4414
|
locationModel.scale.set(scale, scale, scale);
|
|
4782
4415
|
locationModel.updateMatrixWorld();
|
|
@@ -4788,9 +4421,7 @@ export default {
|
|
|
4788
4421
|
locationModel.userData.cull = false;
|
|
4789
4422
|
locationModel.name = name;
|
|
4790
4423
|
if (scene) scene.add(locationModel);
|
|
4791
|
-
locationModel.position.copy(
|
|
4792
|
-
new this.THREE.Vector3(position.x, position.y, position.z),
|
|
4793
|
-
);
|
|
4424
|
+
locationModel.position.copy(new this.THREE.Vector3(position.x, position.y, position.z));
|
|
4794
4425
|
if (gltf.animations.length > 0) {
|
|
4795
4426
|
let actionMixer = new this.THREE.AnimationMixer(gltf.scene);
|
|
4796
4427
|
const walkActive = actionMixer.clipAction(gltf.animations[0]);
|
|
@@ -4810,7 +4441,7 @@ export default {
|
|
|
4810
4441
|
modelActions[index].uncacheRoot(item);
|
|
4811
4442
|
modelActions[index].uncacheRoot(modelActive[index]);
|
|
4812
4443
|
}
|
|
4813
|
-
item.traverse(
|
|
4444
|
+
item.traverse(child => {
|
|
4814
4445
|
if (child instanceof this.THREE.Mesh) {
|
|
4815
4446
|
child.geometry.dispose();
|
|
4816
4447
|
child.material.dispose();
|
|
@@ -4840,14 +4471,14 @@ export default {
|
|
|
4840
4471
|
scenePass = new ShaderPass(RainShader);
|
|
4841
4472
|
scenePass.uniforms['iResolution'].value = new this.THREE.Vector2(
|
|
4842
4473
|
window.innerWidth,
|
|
4843
|
-
window.innerHeight
|
|
4474
|
+
window.innerHeight
|
|
4844
4475
|
);
|
|
4845
4476
|
outlineComposer.addPass(scenePass);
|
|
4846
4477
|
} else if (type === 'snow') {
|
|
4847
4478
|
scenePass = new ShaderPass(SnowShader);
|
|
4848
4479
|
scenePass.uniforms['iResolution'].value = new this.THREE.Vector2(
|
|
4849
4480
|
window.innerWidth,
|
|
4850
|
-
window.innerHeight
|
|
4481
|
+
window.innerHeight
|
|
4851
4482
|
);
|
|
4852
4483
|
outlineComposer.addPass(scenePass);
|
|
4853
4484
|
}
|
|
@@ -4864,7 +4495,7 @@ export default {
|
|
|
4864
4495
|
if (isBox3Info) {
|
|
4865
4496
|
box3 = new this.THREE.Box3(
|
|
4866
4497
|
new this.THREE.Vector3(obj.min[0], obj.min[1], obj.min[2]),
|
|
4867
|
-
new this.THREE.Vector3(obj.max[0], obj.max[1], obj.max[2])
|
|
4498
|
+
new this.THREE.Vector3(obj.max[0], obj.max[1], obj.max[2])
|
|
4868
4499
|
);
|
|
4869
4500
|
}
|
|
4870
4501
|
let center = new this.THREE.Vector3();
|
|
@@ -4879,7 +4510,7 @@ export default {
|
|
|
4879
4510
|
if (isBox3Info) {
|
|
4880
4511
|
box3 = new this.THREE.Box3(
|
|
4881
4512
|
new this.THREE.Vector3(obj.min[0], obj.min[1], obj.min[2]),
|
|
4882
|
-
new this.THREE.Vector3(obj.max[0], obj.max[1], obj.max[2])
|
|
4513
|
+
new this.THREE.Vector3(obj.max[0], obj.max[1], obj.max[2])
|
|
4883
4514
|
);
|
|
4884
4515
|
}
|
|
4885
4516
|
let size = new this.THREE.Vector3();
|
|
@@ -4903,7 +4534,7 @@ export default {
|
|
|
4903
4534
|
|
|
4904
4535
|
if (timeStamp > singleFrameTime) {
|
|
4905
4536
|
if (modelActions.length > 0) {
|
|
4906
|
-
modelActions.forEach(
|
|
4537
|
+
modelActions.forEach(item => {
|
|
4907
4538
|
item.update(timeStamp);
|
|
4908
4539
|
});
|
|
4909
4540
|
}
|
|
@@ -4923,9 +4554,7 @@ export default {
|
|
|
4923
4554
|
? this.noObserver.batchLoadingState
|
|
4924
4555
|
: this.batchLoadingState;
|
|
4925
4556
|
const shouldSkipRendering =
|
|
4926
|
-
skipNextRenderFrame ||
|
|
4927
|
-
forceSkipRendering ||
|
|
4928
|
-
loadingState.interactionState.isInteracting;
|
|
4557
|
+
skipNextRenderFrame || forceSkipRendering || loadingState.interactionState.isInteracting;
|
|
4929
4558
|
|
|
4930
4559
|
if (shouldSkipRendering) {
|
|
4931
4560
|
// 重置单次跳过标记
|
|
@@ -5063,7 +4692,7 @@ export default {
|
|
|
5063
4692
|
meshNameConfig = {},
|
|
5064
4693
|
options = {},
|
|
5065
4694
|
onProgress = null,
|
|
5066
|
-
onComplete = null
|
|
4695
|
+
onComplete = null
|
|
5067
4696
|
) {
|
|
5068
4697
|
const loadingState = this.noObserver
|
|
5069
4698
|
? this.noObserver.batchLoadingState
|
|
@@ -5105,10 +4734,7 @@ export default {
|
|
|
5105
4734
|
loadingState.currentBatch = 0;
|
|
5106
4735
|
loadingState.totalCount = filteredInstances.length;
|
|
5107
4736
|
loadingState.loadedCount = 0;
|
|
5108
|
-
loadingState.pendingData = this.createBatches(
|
|
5109
|
-
filteredInstances,
|
|
5110
|
-
filteredDrawObjs,
|
|
5111
|
-
);
|
|
4737
|
+
loadingState.pendingData = this.createBatches(filteredInstances, filteredDrawObjs);
|
|
5112
4738
|
loadingState.onProgress = onProgress;
|
|
5113
4739
|
loadingState.onComplete = onComplete;
|
|
5114
4740
|
|
|
@@ -5145,13 +4771,13 @@ export default {
|
|
|
5145
4771
|
|
|
5146
4772
|
// 按drawObject分组
|
|
5147
4773
|
const drawObjMap = new Map();
|
|
5148
|
-
drawObjs.forEach(
|
|
4774
|
+
drawObjs.forEach(obj => {
|
|
5149
4775
|
drawObjMap.set(obj.drawObjId, obj);
|
|
5150
4776
|
});
|
|
5151
4777
|
|
|
5152
4778
|
// 按drawObject ID分组instances
|
|
5153
4779
|
const instancesByDrawObj = new Map();
|
|
5154
|
-
instances.forEach(
|
|
4780
|
+
instances.forEach(inst => {
|
|
5155
4781
|
if (!instancesByDrawObj.has(inst.drawObject)) {
|
|
5156
4782
|
instancesByDrawObj.set(inst.drawObject, []);
|
|
5157
4783
|
}
|
|
@@ -5169,7 +4795,7 @@ export default {
|
|
|
5169
4795
|
if (!drawObj) {
|
|
5170
4796
|
for (const value of drawObjMap.values()) {
|
|
5171
4797
|
if (value && Array.isArray(value.geoms)) {
|
|
5172
|
-
const found = value.geoms.some(
|
|
4798
|
+
const found = value.geoms.some(g => g.prmid === drawObjId);
|
|
5173
4799
|
if (found) {
|
|
5174
4800
|
drawObj = value;
|
|
5175
4801
|
break;
|
|
@@ -5181,13 +4807,10 @@ export default {
|
|
|
5181
4807
|
if (!drawObj) continue;
|
|
5182
4808
|
|
|
5183
4809
|
// 如果当前批次加上这个drawObject会超过限制,先保存当前批次
|
|
5184
|
-
if (
|
|
5185
|
-
currentBatchSize + objInstances.length > batchSize &&
|
|
5186
|
-
currentBatch.length > 0
|
|
5187
|
-
) {
|
|
4810
|
+
if (currentBatchSize + objInstances.length > batchSize && currentBatch.length > 0) {
|
|
5188
4811
|
batches.push({
|
|
5189
|
-
instances: currentBatch.flatMap(
|
|
5190
|
-
drawObjs: currentBatch.map(
|
|
4812
|
+
instances: currentBatch.flatMap(item => item.instances),
|
|
4813
|
+
drawObjs: currentBatch.map(item => item.drawObj),
|
|
5191
4814
|
});
|
|
5192
4815
|
currentBatch = [];
|
|
5193
4816
|
currentBatchSize = 0;
|
|
@@ -5202,8 +4825,8 @@ export default {
|
|
|
5202
4825
|
// 如果当前批次已满,保存并开始新批次
|
|
5203
4826
|
if (currentBatchSize >= batchSize) {
|
|
5204
4827
|
batches.push({
|
|
5205
|
-
instances: currentBatch.flatMap(
|
|
5206
|
-
drawObjs: currentBatch.map(
|
|
4828
|
+
instances: currentBatch.flatMap(item => item.instances),
|
|
4829
|
+
drawObjs: currentBatch.map(item => item.drawObj),
|
|
5207
4830
|
});
|
|
5208
4831
|
currentBatch = [];
|
|
5209
4832
|
currentBatchSize = 0;
|
|
@@ -5213,8 +4836,8 @@ export default {
|
|
|
5213
4836
|
// 保存最后一个批次
|
|
5214
4837
|
if (currentBatch.length > 0) {
|
|
5215
4838
|
batches.push({
|
|
5216
|
-
instances: currentBatch.flatMap(
|
|
5217
|
-
drawObjs: currentBatch.map(
|
|
4839
|
+
instances: currentBatch.flatMap(item => item.instances),
|
|
4840
|
+
drawObjs: currentBatch.map(item => item.drawObj),
|
|
5218
4841
|
});
|
|
5219
4842
|
}
|
|
5220
4843
|
|
|
@@ -5228,10 +4851,7 @@ export default {
|
|
|
5228
4851
|
const loadingState = this.noObserver
|
|
5229
4852
|
? this.noObserver.batchLoadingState
|
|
5230
4853
|
: this.batchLoadingState;
|
|
5231
|
-
if (
|
|
5232
|
-
!loadingState.isLoading ||
|
|
5233
|
-
loadingState.currentBatch >= loadingState.pendingData.length
|
|
5234
|
-
) {
|
|
4854
|
+
if (!loadingState.isLoading || loadingState.currentBatch >= loadingState.pendingData.length) {
|
|
5235
4855
|
this.completeBatchLoading();
|
|
5236
4856
|
return;
|
|
5237
4857
|
}
|
|
@@ -5313,14 +4933,14 @@ export default {
|
|
|
5313
4933
|
loadingState.color,
|
|
5314
4934
|
loadingState.meshNameConfig,
|
|
5315
4935
|
'',
|
|
5316
|
-
loadingState.options
|
|
4936
|
+
loadingState.options
|
|
5317
4937
|
);
|
|
5318
4938
|
isDebug && performance.mark('handleInstancedMeshModel-end');
|
|
5319
4939
|
isDebug &&
|
|
5320
4940
|
performance.measure(
|
|
5321
4941
|
'handleInstancedMeshModel',
|
|
5322
4942
|
'handleInstancedMeshModel-start',
|
|
5323
|
-
'handleInstancedMeshModel-end'
|
|
4943
|
+
'handleInstancedMeshModel-end'
|
|
5324
4944
|
);
|
|
5325
4945
|
},
|
|
5326
4946
|
|
|
@@ -5357,7 +4977,7 @@ export default {
|
|
|
5357
4977
|
.addVectors(modelBox3.max, modelBox3.min)
|
|
5358
4978
|
.multiplyScalar(0.5);
|
|
5359
4979
|
modelGroup.userData.modelWorldPs = modelWorldPs;
|
|
5360
|
-
modelGroup.traverse(
|
|
4980
|
+
modelGroup.traverse(child => {
|
|
5361
4981
|
if (child.isMesh && !child.userData.batchInitDone) {
|
|
5362
4982
|
markRendered(child);
|
|
5363
4983
|
const json = this.getMeshCenterAndVolume(child);
|
|
@@ -5367,18 +4987,12 @@ export default {
|
|
|
5367
4987
|
.addVectors(meshBox3.max, meshBox3.min)
|
|
5368
4988
|
.multiplyScalar(0.5);
|
|
5369
4989
|
if (isNaN(worldPs.x)) return;
|
|
5370
|
-
child.worldDir = new this.THREE.Vector3()
|
|
5371
|
-
.subVectors(worldPs, modelWorldPs)
|
|
5372
|
-
.normalize();
|
|
4990
|
+
child.worldDir = new this.THREE.Vector3().subVectors(worldPs, modelWorldPs).normalize();
|
|
5373
4991
|
child.userData.center = json.center;
|
|
5374
4992
|
child.userData.worldPs = worldPs;
|
|
5375
|
-
child.userData.oldPs = child.getWorldPosition(
|
|
5376
|
-
new this.THREE.Vector3(),
|
|
5377
|
-
);
|
|
4993
|
+
child.userData.oldPs = child.getWorldPosition(new this.THREE.Vector3());
|
|
5378
4994
|
child.userData.box = json.box;
|
|
5379
|
-
child.userData.position = new this.THREE.Vector3().copy(
|
|
5380
|
-
child.position,
|
|
5381
|
-
);
|
|
4995
|
+
child.userData.position = new this.THREE.Vector3().copy(child.position);
|
|
5382
4996
|
child.userData.translate = { x: 0, y: 0, z: 0 };
|
|
5383
4997
|
child.userData.rotate = { x: 0, y: 0, z: 0 };
|
|
5384
4998
|
child.userData.modelWorldPs = modelWorldPs;
|
|
@@ -5441,7 +5055,7 @@ export default {
|
|
|
5441
5055
|
meshNameConfig = {},
|
|
5442
5056
|
options = {},
|
|
5443
5057
|
onProgress = null,
|
|
5444
|
-
onComplete = null
|
|
5058
|
+
onComplete = null
|
|
5445
5059
|
) {
|
|
5446
5060
|
if (Object.keys(data).length === 0) {
|
|
5447
5061
|
onComplete && onComplete();
|
|
@@ -5454,14 +5068,7 @@ export default {
|
|
|
5454
5068
|
}
|
|
5455
5069
|
|
|
5456
5070
|
// 启动分帧加载
|
|
5457
|
-
this.startBatchLoading(
|
|
5458
|
-
data,
|
|
5459
|
-
color,
|
|
5460
|
-
meshNameConfig,
|
|
5461
|
-
options,
|
|
5462
|
-
onProgress,
|
|
5463
|
-
onComplete,
|
|
5464
|
-
);
|
|
5071
|
+
this.startBatchLoading(data, color, meshNameConfig, options, onProgress, onComplete);
|
|
5465
5072
|
},
|
|
5466
5073
|
|
|
5467
5074
|
/**
|
|
@@ -5516,10 +5123,7 @@ export default {
|
|
|
5516
5123
|
// 5. 联动 StreamLoader (如果存在实例)
|
|
5517
5124
|
// 确保网络流式加载也同步暂停
|
|
5518
5125
|
const streamLoader = this.noObserver.streamLoader;
|
|
5519
|
-
if (
|
|
5520
|
-
streamLoader &&
|
|
5521
|
-
typeof streamLoader.handleControlStart === 'function'
|
|
5522
|
-
) {
|
|
5126
|
+
if (streamLoader && typeof streamLoader.handleControlStart === 'function') {
|
|
5523
5127
|
streamLoader.handleControlStart();
|
|
5524
5128
|
}
|
|
5525
5129
|
} else {
|
|
@@ -5555,19 +5159,13 @@ export default {
|
|
|
5555
5159
|
forceSkipRendering = false;
|
|
5556
5160
|
|
|
5557
5161
|
// 恢复本地批量加载 (如果未完成)
|
|
5558
|
-
if (
|
|
5559
|
-
loadingState.isLoading &&
|
|
5560
|
-
loadingState.currentBatch < loadingState.totalBatches
|
|
5561
|
-
) {
|
|
5162
|
+
if (loadingState.isLoading && loadingState.currentBatch < loadingState.totalBatches) {
|
|
5562
5163
|
this.loadNextBatch();
|
|
5563
5164
|
}
|
|
5564
5165
|
|
|
5565
5166
|
// 恢复 StreamLoader
|
|
5566
5167
|
const streamLoader = this.noObserver.streamLoader;
|
|
5567
|
-
if (
|
|
5568
|
-
streamLoader &&
|
|
5569
|
-
typeof streamLoader.handleControlEnd === 'function'
|
|
5570
|
-
) {
|
|
5168
|
+
if (streamLoader && typeof streamLoader.handleControlEnd === 'function') {
|
|
5571
5169
|
// StreamLoader 内部通常有防抖或延迟,这里直接通知结束即可
|
|
5572
5170
|
streamLoader.handleControlEnd();
|
|
5573
5171
|
}
|
|
@@ -5603,12 +5201,7 @@ export default {
|
|
|
5603
5201
|
* 交互开始
|
|
5604
5202
|
*/
|
|
5605
5203
|
beginInteraction(type = 'user') {
|
|
5606
|
-
const reason =
|
|
5607
|
-
type === 'wheel'
|
|
5608
|
-
? 'wheel'
|
|
5609
|
-
: type === 'camera'
|
|
5610
|
-
? 'camera'
|
|
5611
|
-
: 'user_interaction';
|
|
5204
|
+
const reason = type === 'wheel' ? 'wheel' : type === 'camera' ? 'camera' : 'user_interaction';
|
|
5612
5205
|
this.setSystemInterruption(true, reason);
|
|
5613
5206
|
},
|
|
5614
5207
|
|