shaogen1995 13 hours ago
parent
commit
9e49a1a029
2 changed files with 24 additions and 14 deletions
  1. 2 2
      project/public/three/data.js
  2. 22 12
      project/public/three/index.js

+ 2 - 2
project/public/three/data.js

@@ -1,6 +1,6 @@
 // 本地运行静态资源地址
-// const baseOssUrl1 = 'http://192.168.20.55:8080/'
-const baseOssUrl1 = 'http://192.168.0.78:8080/'
+const baseOssUrl1 = 'http://192.168.20.55:8080/'
+// const baseOssUrl1 = 'http://192.168.0.78:8080/'
 // 部署服务器静态资源地址
 const baseOssUrl2 = './'
 

+ 22 - 12
project/public/three/index.js

@@ -102,7 +102,7 @@ var Viewer = function (index, dom) {
  */
 
 Viewer.prototype.preLoadCards = function () {
-  let i = 10
+  let i = 5  // 减少初始卡片数量,让画面更稀疏
   while (i-- > 0) {
     this.addCard(true)
   }
@@ -110,7 +110,7 @@ Viewer.prototype.preLoadCards = function () {
   let add = () => {
     if (document.hidden) return
     this.addCard()
-    setTimeout(add, 40000 * Math.random() * this.getDensity()) //当前视野中密度越小 添加越频繁
+    setTimeout(add, 60000 * Math.random() * this.getDensity()) // 增加添加间隔时间(从40000改为60000)
   }
   add()
 
@@ -198,15 +198,25 @@ Viewer.prototype.addCard = function (around) {
       .copy(this.camera.position)
       .add(direction.add(new THREE.Vector3(0, h, 0)).multiplyScalar(far))
 
-    card.scale.set(map.image.width / 500, map.image.height / 500, 1)
-    this.cardGroup.add(card)
-
-    card.transition = transitions.start(
-      lerp.property(card.material, 'opacity', 1, e => {
-        //console.log(e, card.uuid)
-      }),
-      setting.cards.fadeInDur
-    )
+    card.scale.set(map.image.width / 300, map.image.height / 300, 1)  // 图片放大(分母从500改为300)
+    // 检查是否与现有卡片重叠,如果重叠则移除
+    let isOverlapping = false
+    this.cardGroup.children.forEach(existingCard => {
+      let distance = card.position.distanceTo(existingCard.position)
+      if (distance < 3) {  // 如果距离小于3,认为重叠
+        isOverlapping = true
+      }
+    })
+    if (!isOverlapping) {
+      this.cardGroup.add(card)
+
+      card.transition = transitions.start(
+        lerp.property(card.material, 'opacity', 1, e => {
+          //console.log(e, card.uuid)
+        }),
+        setting.cards.fadeInDur
+      )
+    }
   })
 }
 
@@ -233,7 +243,7 @@ Viewer.prototype.update = function (deltaTime) {
 
   if (this.autoMove) {
     let direction = new THREE.Vector3(0, 0, -1).applyQuaternion(this.camera.quaternion)
-    let moveSpeed = 0.8
+    let moveSpeed = 0.3  // 减慢速度(从0.8改为0.3)
     this.camera.position.add(direction.multiplyScalar(deltaTime * moveSpeed))
   }
   this.cardGroup.children.forEach(card => {