zhouenguang 3 years ago
parent
commit
a0b792064a
4 changed files with 61 additions and 40 deletions
  1. 26 11
      src/ActionsHandler.js
  2. 13 6
      src/XMaterialComponent.js
  3. 6 6
      src/XSceneManager.js
  4. 16 17
      src/Xverse_Room.js

+ 26 - 11
src/ActionsHandler.js

@@ -12,7 +12,8 @@ import { SrsRTC } from "./srsRtc.js";
 import { Connection } from "./connection.js";
 
 
-const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/optest/"
+const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/new-video/new-nc/"
+const walkVideoFrame = 29
 
 window.currentFrame = null
 const logger = new Logger('actions-handler')
@@ -61,12 +62,14 @@ export default class ActionsHandler {
         
         window.connection.socket.on("getRoute", (pathArr) => {
             console.error("getRoute", pathArr);
+
+            if(!pathArr) return
             
             let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
             
             pathArr.forEach(point => {
                 // todo 矫正
-                let ue4Pos = util.xversePosition2Ue4({x: -point.location.x-0.8, y: point.location.y, z: point.location.z+0.8})
+                let ue4Pos = util.xversePosition2Ue4({x: -point.location.x, y: point.location.y, z: point.location.z})
                 point.location = new BABYLON.Vector3(ue4Pos.x, ue4Pos.y, ue4Pos.z)
             })
 
@@ -79,9 +82,9 @@ export default class ActionsHandler {
                 let point0 = new BABYLON.Vector3(pathArr[i].location.x, pathArr[i].location.y, pathArr[i].location.z)
                 let point1 = new BABYLON.Vector3(pathArr[i+1].location.x, pathArr[i+1].location.y, pathArr[i+1].location.z)
                 let distanceVec = point1.clone().subtract(point0)
-                let distancePerFrame = distanceVec.length() / 30
+                let distancePerFrame = distanceVec.length() / walkVideoFrame
                 let dir = distanceVec.normalize()
-                for(let currentFrame = 1; currentFrame <= 30; currentFrame++) {
+                for(let currentFrame = 1; currentFrame <= walkVideoFrame; currentFrame++) {
                     walkPoints.push(point0.add(dir.scale(distancePerFrame * currentFrame)))
                 }
             }
@@ -89,7 +92,7 @@ export default class ActionsHandler {
             console.error(walkPoints)
 
             window.walkSettings = {
-                "frameNum": 30 * (pathArr.length - 1),
+                "frameNum": walkVideoFrame * (pathArr.length - 1),
                 "walkPoints": walkPoints,
             }
 
@@ -185,15 +188,26 @@ export default class ActionsHandler {
 
         // 镜头矫正
         let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
+        let anglePlusFrame = Math.floor(anglePlus / (Math.PI/30))
+        anglePlus = anglePlusFrame * (Math.PI/30)
+
         if(Math.abs(anglePlus) > 0.0001) {
-            window.moveBackCall = {
+            window.moveCallBack = {
                 func: this.moveTo.bind(this),
                 args: [e]
             }
-            this.rotate({type: 'rotate', angle: anglePlus})
+            window.rotateCallBack = {
+                func: this.rotate.bind(this),
+                args: [{type: 'rotate', angle: Math.PI/30 * Math.sign(anglePlus)}],
+                frame: anglePlusFrame,
+                currentFrame: 0,
+            }
+            this.rotate({type: 'rotate', angle: Math.PI/30 * Math.sign(anglePlus)})
+
             return
         }
 
+
         const {point: t, extra: r="", motionType: n} = e
           , o = {
             action_type: Actions.Clicking,
@@ -520,7 +534,7 @@ export default class ActionsHandler {
 
         let endRotation = util.xverseRotation2Ue4(window.room.sceneManager.cameraComponent.mainCamera.rotation).yaw
         endRotation = (endRotation % 360 + 360) % 360
-        
+
         // todo 矫正
         let sfns = Math.round((endRotation + 180)/6)        // 仅视频贴图偏移矫正180度
         endRotation += angle/Math.PI*180
@@ -541,8 +555,8 @@ export default class ActionsHandler {
         // 起始帧不需要传入
         if(efns>sfns) sfns = (sfns + 1 + 60) % 60
         if(efns<sfns) sfns = (sfns - 1 + 60) % 60
-        efns = sfns // (efns + 60) % 60
-        // console.error(sfns, efns)
+        efns = sfns // (efns + 60) % 60         // 目前一帧一帧跳,防止漂移和跨0问题
+        // console.error(angle/Math.PI*180, endRotation, efns, sfns)
 
         window.rotating = true      // 标记旋转中
         window.rotateFrame = efns - sfns   // 旋转帧数
@@ -644,13 +658,14 @@ export default class ActionsHandler {
             //     "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1",
             // ]
             videoPathArr.forEach(path => {
-                for(let i = 0; i < 30; i++) {
+                for(let i = 0; i < walkVideoFrame; i++) {
                     sendData.push({
                         path: path,
                         frame: i,
                     })
                 }
             })
+            // sendData.reverse()
             this.vDecoder.mutiFetch(sendData);
         }
         else{

+ 13 - 6
src/XMaterialComponent.js

@@ -277,9 +277,21 @@ export default class XMaterialComponent {
         if(!window.rotating && !window.walking) return
 
         if(window.rotating) {
-            if(window.rotateFrame <= data.renderStateId) window.rotating = false
+            if(Math.abs(window.rotateFrame) <= data.renderStateId) window.rotating = false
             window.room.doRotate(window.star_angle)
             // window.room.doRotate(Math.PI/30 * Math.sign(window.star_angle))
+
+            if(window.rotateCallBack) {
+                if(++window.rotateCallBack.currentFrame < window.rotateCallBack.frame) {
+                    window.rotateCallBack.func(...window.rotateCallBack.args)
+                } else {
+                    window.moveCallBack.func(...window.moveCallBack.args)
+                    setTimeout(() => {
+                        window.rotateCallBack = null
+                        window.moveCallBack = null
+                    }, 500)
+                }
+            }
         } 
         else if(window.walking) {
 
@@ -303,11 +315,6 @@ export default class XMaterialComponent {
         }
 
         this.updateHouseTexture(data)
-
-        if(window.moveBackCall) {
-            window.moveBackCall.func(...window.moveBackCall.args)
-            window.moveBackCall = null
-        }
     }
 
     updateHouseTexture(data) {

+ 6 - 6
src/XSceneManager.js

@@ -482,12 +482,12 @@ export default class XSceneManager {
                 plane.material.useAlphaFromDiffuseTexture = !0
 
                 plane.rotation.x = Math.PI / 2
-                plane.position.x = -data.position.x - 0.8;  // 1
+                plane.position.x = -data.position.x;
                 plane.position.y = data.position.y+0.01;
-                plane.position.z = data.position.z + 0.8;   // 1
+                plane.position.z = data.position.z;
 
                 // todo 矫正
-                let ue4Pos = util.xversePosition2Ue4({x: -data.position.x - 0.8, y: data.position.y, z: data.position.z + 0.8}) // 1
+                let ue4Pos = util.xversePosition2Ue4({x: -data.position.x, y: data.position.y, z: data.position.z}) 
                 // console.error(data.position, ue4Pos)
                 data.position0 = data.position
                 data.position = new BABYLON.Vector3(ue4Pos.x, ue4Pos.y, ue4Pos.z)
@@ -513,12 +513,12 @@ export default class XSceneManager {
 
     correctCameraDirec() {
         // 视频逆时针旋转
-        let num = Math.round((this._cameraManager.mainCamera.rotation.y + Math.PI) / (Math.PI/4))       // 矫正
-        let angle = num * (Math.PI/4) - (this._cameraManager.mainCamera.rotation.y + Math.PI)
+        let num = Math.round((this._cameraManager.mainCamera.rotation.y + Math.PI/2*5) / (Math.PI/4))       // 矫正
+        let angle = num * (Math.PI/4) - (this._cameraManager.mainCamera.rotation.y + Math.PI/2*5)
 
         return {
             anglePlus: angle,
-            dircNum: num <= 0 ? -num : 8-num
+            dircNum: num <= 0 ? -num%8 : num%8
         }
     }
 

+ 16 - 17
src/Xverse_Room.js

@@ -248,23 +248,22 @@ export default class Xverse_Room extends EventEmitter {
         let cameraPosNew = cameraPos.add(walkDistanceVec)
 
         
-        // // 相机碰撞检测
-        // let cameraPosXverse = util.ue4Position2Xverse(cameraPosNew)
-        // let cameraCenterXverse = util.ue4Position2Xverse(playerPosNew)
-        // cameraCenterXverse.y = cameraPosXverse.y
-
-        // if(!this.ray) this.ray = new BABYLON.Ray(new BABYLON.Vector3(0,0,0), new BABYLON.Vector3(0,0,1), 50);
-        // this.ray.origin = cameraCenterXverse
-        // this.ray.direction = BABYLON.Vector3.Normalize( cameraPosXverse.clone().subtract(cameraCenterXverse) )
-        // let info = this.ray.intersectsMeshes(this.sceneManager.getGround())[0];
-
-        // // todo 矫正
-        // const offset = 0.09 // 0.05
-        // if(info) {
-        //     info.distance = Math.min(info.distance, 4.5 + offset)
-        //     cameraPosXverse = cameraCenterXverse.add(this.ray.direction.clone().scale(Math.max( info.distance - offset, 0.1 )))
-        //     cameraPosNew = util.xversePosition2Ue4(cameraPosXverse)
-        // }
+        // 相机碰撞检测
+        let cameraPosXverse = util.ue4Position2Xverse(cameraPosNew)
+        let cameraCenterXverse = util.ue4Position2Xverse(playerPosNew)
+        cameraCenterXverse.y = cameraPosXverse.y
+
+        if(!this.ray) this.ray = new BABYLON.Ray(new BABYLON.Vector3(0,0,0), new BABYLON.Vector3(0,0,1), 50);
+        this.ray.origin = cameraCenterXverse
+        this.ray.direction = BABYLON.Vector3.Normalize( cameraPosXverse.clone().subtract(cameraCenterXverse) )
+        let info = this.ray.intersectsMeshes(this.sceneManager.getGround())[0];
+
+        const offset = 0.05
+        if(info) {
+            info.distance = Math.min(info.distance, 4.5 + offset)
+            cameraPosXverse = cameraCenterXverse.add(this.ray.direction.clone().scale(Math.max( info.distance - offset, 0.1 )))
+            cameraPosNew = util.xversePosition2Ue4(cameraPosXverse)
+        }
 
 
         let cameraRota = util.xverseRotation2Ue4(this.sceneManager.cameraComponent.mainCamera.rotation)