@kimap/indoor-positioning-sdk-vue2 3.1.7 → 3.1.8
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/package.json +1 -1
- package/src/KimapCore.js +52 -6
package/package.json
CHANGED
package/src/KimapCore.js
CHANGED
|
@@ -303,6 +303,15 @@ SceneCore.prototype.setCameraPosition = function() {
|
|
|
303
303
|
var maxX = this.coordinateSystem.maxX;
|
|
304
304
|
var maxY = this.coordinateSystem.maxY;
|
|
305
305
|
|
|
306
|
+
// 如果 maxX 或 maxY 未定义,使用默认值(稍后会根据实际模型尺寸重新调整)
|
|
307
|
+
if (maxX === undefined || maxY === undefined) {
|
|
308
|
+
console.log('⚠️ 坐标系统尺寸未定义,使用默认相机位置(将在模型加载后自动调整)');
|
|
309
|
+
// 使用一个合理的默认位置:从斜上方俯视原点
|
|
310
|
+
this.camera.position.set(origin.x, 15, origin.z + 10);
|
|
311
|
+
this.camera.lookAt(origin.x, 0, origin.z);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
306
315
|
var centerX = origin.x + maxX / 2;
|
|
307
316
|
var centerZ = origin.z;
|
|
308
317
|
var distance = Math.max(maxX, maxY) * 1.5;
|
|
@@ -618,37 +627,74 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
|
|
|
618
627
|
|
|
619
628
|
// 基于模型包围盒自动调整相机位置和控制器目标,避免依赖配置中的 maxX/maxY
|
|
620
629
|
try {
|
|
630
|
+
console.log('=== 开始自动调整相机位置 ===');
|
|
631
|
+
|
|
621
632
|
// 使用模型当前位置重新计算包围盒和中心
|
|
622
633
|
var finalBox = new THREE.Box3().setFromObject(self.mapModel);
|
|
623
634
|
var finalCenter = new THREE.Vector3();
|
|
624
635
|
finalBox.getCenter(finalCenter);
|
|
636
|
+
|
|
637
|
+
console.log('📦 模型最终包围盒:', {
|
|
638
|
+
min: { x: finalBox.min.x.toFixed(2), y: finalBox.min.y.toFixed(2), z: finalBox.min.z.toFixed(2) },
|
|
639
|
+
max: { x: finalBox.max.x.toFixed(2), y: finalBox.max.y.toFixed(2), z: finalBox.max.z.toFixed(2) }
|
|
640
|
+
});
|
|
641
|
+
console.log('🎯 模型中心:', {
|
|
642
|
+
x: finalCenter.x.toFixed(2),
|
|
643
|
+
y: finalCenter.y.toFixed(2),
|
|
644
|
+
z: finalCenter.z.toFixed(2)
|
|
645
|
+
});
|
|
625
646
|
|
|
626
647
|
var finalSize = new THREE.Vector3();
|
|
627
648
|
finalBox.getSize(finalSize);
|
|
628
649
|
var maxSize = Math.max(finalSize.x, finalSize.z);
|
|
650
|
+
|
|
651
|
+
console.log('📏 模型尺寸:', {
|
|
652
|
+
x: finalSize.x.toFixed(2),
|
|
653
|
+
y: finalSize.y.toFixed(2),
|
|
654
|
+
z: finalSize.z.toFixed(2),
|
|
655
|
+
maxSize: maxSize.toFixed(2)
|
|
656
|
+
});
|
|
629
657
|
|
|
630
658
|
// 根据模型尺寸计算一个合理的视距
|
|
631
659
|
var distance = maxSize * 1.5;
|
|
660
|
+
|
|
661
|
+
console.log('📹 计算相机距离:', distance.toFixed(2));
|
|
632
662
|
|
|
633
663
|
// 相机从斜上方俯视模型中心
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
);
|
|
664
|
+
var cameraX = finalCenter.x;
|
|
665
|
+
var cameraY = finalCenter.y + distance;
|
|
666
|
+
var cameraZ = finalCenter.z + distance * 0.5;
|
|
667
|
+
|
|
668
|
+
self.camera.position.set(cameraX, cameraY, cameraZ);
|
|
639
669
|
self.camera.lookAt(finalCenter.x, finalCenter.y, finalCenter.z);
|
|
670
|
+
|
|
671
|
+
console.log('📹 相机位置:', {
|
|
672
|
+
x: cameraX.toFixed(2),
|
|
673
|
+
y: cameraY.toFixed(2),
|
|
674
|
+
z: cameraZ.toFixed(2)
|
|
675
|
+
});
|
|
676
|
+
console.log('👀 相机朝向:', {
|
|
677
|
+
x: finalCenter.x.toFixed(2),
|
|
678
|
+
y: finalCenter.y.toFixed(2),
|
|
679
|
+
z: finalCenter.z.toFixed(2)
|
|
680
|
+
});
|
|
640
681
|
|
|
641
682
|
// 更新控制器目标为模型中心
|
|
642
683
|
if (self.controls) {
|
|
643
684
|
self.controls.target.copy(finalCenter);
|
|
644
685
|
self.controls.update();
|
|
686
|
+
console.log('🎮 控制器目标已更新');
|
|
645
687
|
}
|
|
646
688
|
|
|
647
689
|
// 更新坐标系范围为模型的实际尺寸,供其它功能使用
|
|
648
690
|
self.coordinateSystem.maxX = finalSize.x;
|
|
649
691
|
self.coordinateSystem.maxY = finalSize.z;
|
|
692
|
+
|
|
693
|
+
console.log('✅ 相机自动调整完成');
|
|
694
|
+
console.log('=========================');
|
|
650
695
|
} catch (e) {
|
|
651
|
-
console.
|
|
696
|
+
console.error('❌ 根据模型自动调整相机位置失败:', e && e.message ? e.message : e);
|
|
697
|
+
console.error('错误堆栈:', e.stack);
|
|
652
698
|
}
|
|
653
699
|
|
|
654
700
|
resolve();
|