zhouenguang 3 yıl önce
ebeveyn
işleme
b927d3ceaf
4 değiştirilmiş dosya ile 58 ekleme ve 14 silme
  1. 1 0
      libs/socket.io.js.map
  2. 17 7
      modules/CharactorManager.js
  3. 10 7
      modules/index.js
  4. 30 0
      modules/utils/common.js

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 0
libs/socket.io.js.map


+ 17 - 7
modules/CharactorManager.js

@@ -69,7 +69,7 @@ export default class CharactorManager {
 
                 // todo
                 this.app.rotateCamera(this.app.camera.alpha - cameraAlphaAmend, () => {
-                    // this.charactorWalkTo(pickinfo.pickedPoint)
+                    this.charactorWalkTo(pickinfo.pickedPoint)
                 })
             }
         }
@@ -83,13 +83,12 @@ export default class CharactorManager {
 
     charactorWalkTo(endPoint) {
 
-        let endPointData = this.getClosestPointData(endPoint)
-
         let currentPath = this.charactor.walkData.pathArr[this.charactor.walkData.currentPoint]
         let startPoint = (currentPath && currentPath.point) || this.charactor.mesh.position
         let sendData = {
-            video: [endPointData.id],   // todo
-            reverse: true   // todo
+            startId: this.getClosestPointData(startPoint).id,   // todo
+            endId: this.getClosestPointData(endPoint).id,   // todo
+            dir: this.getVideoDirecNum()
         }
 
         // window.connection.socket.emit("getPush", sendData)
@@ -98,10 +97,10 @@ export default class CharactorManager {
         let path = data.walkPath    // response
         path.forEach(data => data.point = this.pointsData[data.id].position)
 
-        path = path.map(data => { 
+        path = path.map((data) => { 
             return { 
                 point: new BABYLON.Vector3(data.point.x, 0, data.point.y), 
-                video: data.video && common.createVideoElement(data.video) 
+                video: data.video && common.createVideoElement0(data.video)
             } 
         })
 
@@ -124,4 +123,15 @@ export default class CharactorManager {
         return closestPoint.data
     }
 
+    getVideoDirecNum() {
+        // 视频逆时针旋转
+        let num = Math.floor(this.app.camera.alpha % (Math.PI * 2) / (Math.PI / 4))
+
+        if(num <= 0) {
+            return -num
+        } else {
+            return 8 - num
+        }
+    }
+
 }

+ 10 - 7
modules/index.js

@@ -194,7 +194,8 @@ export default class App {
         if(!this.lastDirc) this.lastDirc = 0
 
         // 一般来说瞬时距离不会超过100,定100时转180度
-        let alphaOffset = pointerOffset / 100 * Math.PI
+        // let alphaOffset = Math.max(Math.floor((pointerOffset / 100 * Math.PI / (Math.PI / 30)) * (Math.PI / 30) + Math.PI / 60), Math.PI / 30)
+        let alphaOffset = Math.max(pointerOffset / 100 * Math.PI, Math.PI / 30)
         alphaOffset *= dirc
 
         if(charactor.actionType.split("-")[1] == "Walking") {
@@ -220,6 +221,7 @@ export default class App {
         this.lastDirc = dirc
     }
 
+    // async 
     rotateCamera(alphaOffset, func) {
         // todo
         let video0 = document.getElementById("houseTexture0")
@@ -228,9 +230,6 @@ export default class App {
         let durtime = Math.abs(alphaOffset / (Math.PI * 2) * video0.duration)
 
         if(video0.paused) {
-            video0.currentTime = startTime
-            video0.play()
-
             // if(dirc * this.lastDirc < 0) {
                 // 清除已有动画再播新动画
                 this.scene.stopAnimation(this.camera, "rotateCamera")
@@ -250,6 +249,10 @@ export default class App {
 
             rotateAni.setKeys(rotateFrames);
 
+            video0.currentTime = startTime
+            // await 
+            video0.play()
+
             this.scene.beginDirectAnimation(this.camera, [rotateAni], 0, rotateCameraFrameNum, false, 1, 
                 () => {
                     this.lastDirc = 0
@@ -259,14 +262,14 @@ export default class App {
             
         } else {
             // console.error("-------------")
-            video0.pause()
+            // video0.pause()
         }
     }
 
     lockCamera(isTrue) {
         this.cameraControlEnable = isTrue
-        // this.camera.lowerAlphaLimit = isTrue ? this.camera.alpha : null
-        // this.camera.upperAlphaLimit = isTrue ? this.camera.alpha : null
+        this.camera.lowerAlphaLimit = isTrue ? this.camera.alpha : null
+        this.camera.upperAlphaLimit = isTrue ? this.camera.alpha : null
     }
 
     updateHouseVideo(video) {

+ 30 - 0
modules/utils/common.js

@@ -19,6 +19,36 @@ export default {
 
     createVideoElement: (path) => {
 
+        return new Promise((resolve, reject) => {
+            
+            let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
+            let oldVideo = document.getElementById(videoName)
+            if(oldVideo) {
+                oldVideo.currentTime = 0
+                oldVideo.isLoaded = true
+                resolve(oldVideo)
+            } 
+            else {
+                let video = document.createElement("video")
+                video.src = path
+                video.id = videoName
+                video.crossOrigin = "anonymous" 
+                video.playsinline = "playsinline" 
+                video.autoplay = "autoplay" 
+                video.muted = "muted"
+
+                document.getElementById("videoTextureBox").appendChild(video)
+
+                video.onloadeddata = () => {
+                    resolve(video);
+                }
+            }
+            
+        });
+    },
+    
+    createVideoElement0: (path) => {
+
         let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
         let oldVideo = document.getElementById(videoName)
         if(oldVideo) {