zhouenguang 3 years ago
parent
commit
b3efc8f18b
3 changed files with 41 additions and 38 deletions
  1. 24 24
      modules/Charactor.js
  2. 2 2
      modules/CharactorManager.js
  3. 15 12
      modules/index.js

+ 24 - 24
modules/Charactor.js

@@ -81,11 +81,12 @@ export default class Charactor {
 
         this.walkData = {
             pathArr: pathArr,
-            currentPoint: 0
+            currentPoint: -1
         }
         
         if(pathArr.length >= 2 && this.actionType.split("-")[1] != "Walking") 
         {
+            this.walkData.currentPoint = 0
             let video = pathArr[0].video
             if(video.isLoaded) {
                 this.AniTransfromTo("Walking")
@@ -108,37 +109,35 @@ export default class Charactor {
         // 更新房间的视频贴图
         let video = pathArr[currentPoint].video
         charactorManager.app.updateHouseVideo(video)
-
         let nextPos = pathArr[currentPoint+1].point
-        let nextVideo = pathArr[currentPoint+1].video
+        // console.error(pathArr, video)
 
-        if(!nextVideo)
-        {
-            // 即将走到终点之前,获取终点旋转视频
-            let endPointId = pathArr[currentPoint+1].id
-
-            console.log("[3D] send(getRotateVideoUrl): ", endPointId + "/" + endPointId)
-            window.connection.socket.emit("getRotateVideoUrl", {
-                videoPath: endPointId + "/" + endPointId,
-                sceneCode: settings.sceneCode,
-                roomId: settings.roomId,
-                userId: settings.userId,
-            });
-            window.connection.socket.emit("getRotateVideoUrl", {
-                videoPath: endPointId + "/" + endPointId + "_rotate",
-                sceneCode: settings.sceneCode,
-                roomId: settings.roomId,
-                userId: settings.userId,
-            });
 
-        }
+        // 立即获取下一个点的旋转视频,防止中途旋转导致行走停止
+        let endPointId = pathArr[currentPoint+1].id
+
+        console.log("[3D] send(getRotateVideoUrl): ", endPointId + "/" + endPointId)
+        window.connection.socket.emit("getRotateVideoUrl", {
+            videoPath: endPointId + "/" + endPointId,
+            sceneCode: settings.sceneCode,
+            roomId: settings.roomId,
+            userId: settings.userId,
+        });
+        window.connection.socket.emit("getRotateVideoUrl", {
+            videoPath: endPointId + "/" + endPointId + "_rotate",
+            sceneCode: settings.sceneCode,
+            roomId: settings.roomId,
+            userId: settings.userId,
+        });
+
 
         // 要跳转的位置与当前位置相同的话,就直接跳过,否则动画会出bug
         if(nextPos.x == this.mesh.position.x && nextPos.z == this.mesh.position.z) 
         {
             console.warn("跳转点位与当前点位相同, 已跳过!")
 
-            if(pathArr[currentPoint+1].video) {
+            let nextPointData = charactor.walkData.pathArr[++charactor.walkData.currentPoint]
+            if(nextPointData && nextPointData.video) {
                 charactor.walkByPath(charactorManager)
             } else {
                 charactor.AniTransfromTo("Idle")
@@ -188,7 +187,8 @@ export default class Charactor {
         charactorManager.app.scene.beginDirectAnimation(charactor.mesh, [walkAni, turnAroundAni], 0, Math.max(walkFrameNum, turnAroundFrameNum), false, 1, 
             () => {
                 // 如果还有下一个点位就继续走,否则变为站立
-                if(pathArr[++charactor.walkData.currentPoint].video) {
+                let nextPointData = charactor.walkData.pathArr[++charactor.walkData.currentPoint]
+                if(nextPointData && nextPointData.video) {
                     charactor.walkByPath(charactorManager)
                 } else {
                     charactor.AniTransfromTo("Idle")

+ 2 - 2
modules/CharactorManager.js

@@ -117,8 +117,8 @@ export default class CharactorManager {
 
     charactorWalkTo(endPoint) {
 
-        let currentPath = this.charactor.walkData.pathArr[this.charactor.walkData.currentPoint]
-        let startPoint = (currentPath && currentPath.point) || this.charactor.mesh.position
+        let currentPathEnd = this.charactor.walkData.pathArr[this.charactor.walkData.currentPoint+1]
+        let startPoint = (currentPathEnd && currentPathEnd.point) || this.charactor.mesh.position
         // let sendData = {
         //     startId: this.getClosestPointData(startPoint).id,   // todo
         //     endId: this.getClosestPointData(endPoint).id,   // todo

+ 15 - 12
modules/index.js

@@ -240,18 +240,21 @@ export default class App {
             console.log("[3D] getVideoUrl: ", data)
             const urlArr = data
 
-            let path = walkPointsTemp.map((point, i) => { 
-                return { 
-                    id: point.id,
-                    point: new BABYLON.Vector3(-point.location.x, 0, point.location.z), 
-                    video: urlArr[i] ? common.createVideoElement0(urlArr[i]) : null,
-                } 
-            })
-
-            // 行走时锁定camera
-            console.log("Walk Start: ", path)
-            this.cameraController.lockCamera(true)
-            this.charactorManager.charactor.startWalk(path, this.charactorManager)
+            if(this.charactorManager.charactor.actionType.split("-")[1] != "Walking") {
+                // TODO 目前禁止临时拐弯
+                let path = walkPointsTemp.map((point, i) => { 
+                    return { 
+                        id: point.id,
+                        point: new BABYLON.Vector3(-point.location.x, 0, point.location.z), 
+                        video: urlArr[i] ? common.createVideoElement0(urlArr[i]) : null,
+                    } 
+                })
+
+                // 行走时锁定camera
+                console.log("Walk Start: ", path)
+                this.cameraController.lockCamera(true)
+                this.charactorManager.charactor.startWalk(path, this.charactorManager)
+            }
         })
         
         // 获得行走路径