@kimap/indoor-positioning-sdk-vue2 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/KimapCore.js +34 -77
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimap/indoor-positioning-sdk-vue2",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
package/src/KimapCore.js CHANGED
@@ -19,18 +19,6 @@ function loadThree() {
19
19
  });
20
20
  }
21
21
 
22
- // FBXLoader 动态导入
23
- function loadFBXLoader() {
24
- return new Promise(function(resolve, reject) {
25
- try {
26
- var module = require('three/examples/jsm/loaders/FBXLoader.js');
27
- resolve(module.FBXLoader || module.default || module);
28
- } catch (error) {
29
- reject(new Error('Failed to load FBXLoader: ' + error.message));
30
- }
31
- });
32
- }
33
-
34
22
  // OrbitControls 动态导入
35
23
  function loadOrbitControls() {
36
24
  return new Promise(function(resolve, reject) {
@@ -345,7 +333,7 @@ SceneCore.prototype.initScene = function() {
345
333
  this.scene = new THREE.Scene();
346
334
  var bgColor = this.config.backgroundColor !== undefined
347
335
  ? this.config.backgroundColor
348
- : 0xf5f5f5;
336
+ : 0xf0f0f0;
349
337
  this.scene.background = new THREE.Color(bgColor);
350
338
  };
351
339
 
@@ -370,7 +358,7 @@ SceneCore.prototype.setCameraPosition = function() {
370
358
  };
371
359
 
372
360
  SceneCore.prototype.initRenderer = function() {
373
- this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
361
+ this.renderer = new THREE.WebGLRenderer({ antialias: true });
374
362
  this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
375
363
  this.renderer.setPixelRatio(window.devicePixelRatio);
376
364
 
@@ -381,8 +369,8 @@ SceneCore.prototype.initRenderer = function() {
381
369
  // 设置输出色彩空间为sRGB
382
370
  this.renderer.outputColorSpace = THREE.SRGBColorSpace;
383
371
 
384
- // 色调映射设置(与编辑器3D预览保持一致)
385
- this.renderer.toneMapping = THREE.NoToneMapping;
372
+ // 色调映射设置(优化颜色显示)
373
+ this.renderer.toneMapping = THREE.CineonToneMapping; // 3 = Cineon
386
374
  this.renderer.toneMappingExposure = 1.0;
387
375
 
388
376
  this.container.appendChild(this.renderer.domElement);
@@ -408,7 +396,7 @@ SceneCore.prototype.setupLights = function() {
408
396
  this.scene.add(ambientLight);
409
397
 
410
398
  // 主光源(从上方)
411
- var directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.8);
399
+ var directionalLight1 = new THREE.DirectionalLight(0xffffff, 0.75);
412
400
  directionalLight1.position.set(10, 20, 10);
413
401
  directionalLight1.castShadow = true;
414
402
  directionalLight1.shadow.camera.left = -50;
@@ -418,12 +406,12 @@ SceneCore.prototype.setupLights = function() {
418
406
  this.scene.add(directionalLight1);
419
407
 
420
408
  // 辅助光源
421
- var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.4);
409
+ var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.15);
422
410
  directionalLight2.position.set(-10, 15, -10);
423
411
  this.scene.add(directionalLight2);
424
412
 
425
413
  // 半球光
426
- var hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.4);
414
+ var hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x444444, 0.15);
427
415
  this.scene.add(hemisphereLight);
428
416
  };
429
417
 
@@ -598,31 +586,29 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
598
586
 
599
587
  // 提取颜色
600
588
  var mtlColor = child.material.color ? child.material.color.getHex() : 0xdddddd;
601
- var baseColor = new THREE.Color(mtlColor);
602
589
  var opacity = child.material.opacity !== undefined ? child.material.opacity : 1.0;
603
590
  var transparent = opacity < 1.0;
604
591
 
605
- // 根据材质名称判断元素类型,设置与编辑器预览接近的PBR参数
606
- var roughness = 0.95;
607
- var metalness = 0.0;
608
-
609
- // 墙体:颜色与白色混合 50%,使墙面更浅
610
- if (child.material.name.startsWith('Wall_')) {
611
- baseColor = baseColor.lerp(new THREE.Color(0xffffff), 0.5);
612
- }
613
-
614
- // 区域 / 形状 / 楼梯 与预览保持相似的高粗糙度、无金属反光
615
- // 区域通常需要透明度,由 MTL 的 opacity 控制,此处仅保留 transparent 标记
592
+ // 根据材质名称判断元素类型,设置对应的PBR参数
593
+ var roughness = 0.7;
594
+ var metalness = 0.1;
595
+
616
596
  if (child.material.name.startsWith('Area_')) {
617
- transparent = opacity < 1.0;
597
+ roughness = 0.05;
598
+ metalness = 0.3;
599
+ transparent = true;
600
+ } else if (child.material.name.startsWith('Wall_')) {
601
+ roughness = 0.55;
602
+ metalness = 0.1;
618
603
  } else if (child.material.name.startsWith('Shape_') ||
619
604
  child.material.name.startsWith('Stair_')) {
620
- // 使用同一套 roughness/metalness
605
+ roughness = 0.7;
606
+ metalness = 0.3;
621
607
  }
622
608
 
623
609
  // 创建新的PBR材质
624
610
  child.material = new THREE.MeshStandardMaterial({
625
- color: baseColor,
611
+ color: mtlColor,
626
612
  opacity: opacity,
627
613
  transparent: transparent,
628
614
  roughness: roughness,
@@ -643,11 +629,11 @@ SceneCore.prototype.loadMap = function(OBJLoader, MTLLoader) {
643
629
  }
644
630
 
645
631
  console.log('⚪ 创建默认材质 for', child.name || child.parent.name);
646
- // 设置材质(与预览接近:高粗糙度、无金属反光)
632
+ // 设置材质
647
633
  child.material = new THREE.MeshStandardMaterial({
648
634
  color: meshColor,
649
- roughness: 0.95,
650
- metalness: 0.0,
635
+ roughness: 0.7,
636
+ metalness: 0.1,
651
637
  side: THREE.DoubleSide
652
638
  });
653
639
  }
@@ -1483,41 +1469,15 @@ KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
1483
1469
  KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
1484
1470
  var self = this;
1485
1471
 
1486
- return new Promise(function(resolve, reject) {
1487
- // 构建模型URL
1488
- // serverUrl已经包含了完整的路径(例如:http://server.com/KiMap_3D_Model)
1489
- // 使用dataUrl(如果serverUrl不可用)或serverUrl
1490
- var baseUrl = serverUrl || self.dataUrl;
1491
-
1492
- // 解析文件扩展名:优先使用 kidata 中的 fileExt,其次从 id 中解析,最后默认为 .obj
1493
- var ext = furniture.fileExt || null;
1494
- var id = furniture.id;
1495
-
1496
- if (!ext && typeof id === 'string') {
1497
- var dotIndex = id.lastIndexOf('.');
1498
- if (dotIndex >= 0) {
1499
- ext = id.substring(dotIndex).toLowerCase();
1500
- id = id.substring(0, dotIndex);
1501
- }
1502
- }
1503
-
1504
- if (!ext) {
1505
- ext = '.obj';
1506
- }
1507
-
1508
- var modelUrl = baseUrl + '/' + furniture.type + '/' + id + ext;
1509
-
1510
- // 根据扩展名选择合适的加载器
1511
- var loaderPromise;
1512
- if (ext === '.fbx') {
1513
- loaderPromise = loadFBXLoader();
1514
- } else {
1515
- // 默认和其它格式暂时都走 OBJLoader,保证兼容旧数据
1516
- loaderPromise = loadOBJLoader();
1517
- }
1518
-
1519
- loaderPromise.then(function(LoaderClass) {
1520
- var loader = new LoaderClass();
1472
+ return loadOBJLoader().then(function(OBJLoader) {
1473
+ return new Promise(function(resolve, reject) {
1474
+ // 构建模型URL
1475
+ // serverUrl已经包含了完整的路径(例如:http://server.com/KiMap_3D_Model)
1476
+ // 使用dataUrl(如果serverUrl不可用)或serverUrl
1477
+ var baseUrl = serverUrl || self.dataUrl;
1478
+ var modelUrl = baseUrl + '/' + furniture.type + '/' + furniture.id + '.obj';
1479
+
1480
+ var loader = new OBJLoader();
1521
1481
  loader.load(
1522
1482
  modelUrl,
1523
1483
  function(obj) {
@@ -1592,18 +1552,15 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
1592
1552
  furnitureType: furniture.type
1593
1553
  };
1594
1554
 
1595
- console.log('✅ 家具模型加载成功:', furniture.type, 'URL:', modelUrl);
1555
+ console.log('✅ 家具模型加载成功:', furniture.type);
1596
1556
  resolve(obj);
1597
1557
  },
1598
1558
  undefined,
1599
1559
  function(error) {
1600
- console.error('❌ 家具模型加载失败:', furniture.type, 'URL:', modelUrl, error);
1560
+ console.error('❌ 家具模型加载失败:', furniture.type, error);
1601
1561
  reject(error);
1602
1562
  }
1603
1563
  );
1604
- }).catch(function(error) {
1605
- console.error('❌ 加载家具模型加载器失败:', error);
1606
- reject(error);
1607
1564
  });
1608
1565
  });
1609
1566
  };