zhouenguang 3 years ago
parent
commit
b7d02631cc
2 changed files with 26 additions and 17 deletions
  1. 26 16
      src/ActionsHandler.js
  2. 0 1
      src/XMaterialComponent.js

+ 26 - 16
src/ActionsHandler.js

@@ -12,7 +12,7 @@ import { SrsRTC } from "./srsRtc.js";
 import { Connection } from "./connection.js";
 
 
-const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/new-video/new-nc/"
+const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/new-video/720p/"
 const walkVideoFrame = 29
 
 window.currentFrame = null
@@ -68,40 +68,51 @@ export default class ActionsHandler {
             let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
             
             pathArr.forEach(point => {
-                // todo 矫正
                 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)
             })
 
+            const walkSpeed = 1     // m/s
+            const frameRate = 29    // fps
+
             let walkPoints = []
+            let walkFrames = []
             let videoArr = []
             for(let i = 0; i < pathArr.length - 1; i++) {
 
-                videoArr.push( ossVideoDir + pathArr[i].id + "/" + pathArr[i].id + "_" + pathArr[i+1].id + "_" + dircNum)
-
                 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() / walkVideoFrame
+                let distance = distanceVec.length() / 100   // m    
+                let distancePerFrame = walkSpeed / frameRate    // m/帧     // walkVideoFrame
+                let walkFrame = Math.round(distance / distancePerFrame)     // 帧
                 let dir = distanceVec.normalize()
-                for(let currentFrame = 1; currentFrame <= walkVideoFrame; currentFrame++) {
-                    walkPoints.push(point0.add(dir.scale(distancePerFrame * currentFrame)))
+
+                videoArr.push( {
+                    path: ossVideoDir + pathArr[i].id + "/" + pathArr[i].id + "_" + pathArr[i+1].id + "_" + dircNum,
+                    frame: walkFrame
+                })
+                walkFrames.push(walkFrame)
+                for(let currentFrame = 1; currentFrame <= walkFrame; currentFrame++) {
+                    walkPoints.push(point0.add(dir.scale(distancePerFrame * 100 * currentFrame)))   // 单位转换成cm
                 }
             }
 
             console.error(walkPoints)
 
             window.walkSettings = {
-                "frameNum": walkVideoFrame * (pathArr.length - 1),
+                "frameNum": walkFrames.reduce(function(prev, curr){
+                    // 计算总帧数
+                    return prev + curr;
+                }),
                 "walkPoints": walkPoints,
             }
 
             window.walking = true
 
-
             this.mutiFetchData({
                 type: 'move',
-                videoPathArr: videoArr
+                videoDataArr: videoArr
             })
         });
     }
@@ -648,8 +659,8 @@ export default class ActionsHandler {
         }
     }
 
-    mutiFetchData({type, videoPathArr}){
-        console.error(videoPathArr)
+    mutiFetchData({type, videoDataArr}){
+        console.error(videoDataArr)
         if(window.workerReady){
             // https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/optest/0/0_1_0/
             let sendData = []
@@ -657,15 +668,14 @@ export default class ActionsHandler {
             //     "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
             //     "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1",
             // ]
-            videoPathArr.forEach(path => {
-                for(let i = 0; i < walkVideoFrame; i++) {
+            videoDataArr.forEach(data => {
+                for(let i = 0; i < data.frame; i++) {
                     sendData.push({
-                        path: path,
+                        path: data.path,
                         frame: i,
                     })
                 }
             })
-            // sendData.reverse()
             this.vDecoder.mutiFetch(sendData);
         }
         else{

+ 0 - 1
src/XMaterialComponent.js

@@ -297,7 +297,6 @@ export default class XMaterialComponent {
 
             let targetPos = window.walkSettings.walkPoints[data.renderStateId]
 
-            // if(window.walkSettings.currentFrame < frameNum) {
             if(data.renderStateId < window.walkSettings.frameNum - 1) {
                 window.room.moveTo({
                     position: targetPos,