|
@@ -8,6 +8,12 @@ import Logger from "./Logger.js"
|
|
|
import Response from "./Response.js"
|
|
|
import { VDecoder } from "./h264Decoder/VDecoder.js";
|
|
|
|
|
|
+import { SrsRTC } from "./srsRtc.js";
|
|
|
+import { Connection } from "./connection.js";
|
|
|
+
|
|
|
+
|
|
|
+const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/optest/"
|
|
|
+
|
|
|
window.currentFrame = null
|
|
|
const logger = new Logger('actions-handler')
|
|
|
const QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];
|
|
@@ -30,6 +36,71 @@ export default class ActionsHandler {
|
|
|
console.log("ready");
|
|
|
window.workerReady = true
|
|
|
})
|
|
|
+
|
|
|
+ this.initSocket()
|
|
|
+ }
|
|
|
+
|
|
|
+ initSocket() {
|
|
|
+
|
|
|
+ const sdk = new SrsRTC();
|
|
|
+ const testConfig = {
|
|
|
+ sceneCode: "testApp",
|
|
|
+ userId: "testUser",
|
|
|
+ roomId: "8888",
|
|
|
+ };
|
|
|
+ const connection = new Connection(testConfig);
|
|
|
+
|
|
|
+ console.log("sdk", sdk);
|
|
|
+ console.log("sdk", connection);
|
|
|
+ const url = "webrtc://demo-kms.4dage.com/live/test1";
|
|
|
+ sdk.start(url);
|
|
|
+
|
|
|
+ window.connection = connection
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ window.connection.socket.on("getRoute", (pathArr) => {
|
|
|
+ console.error("getRoute", pathArr);
|
|
|
+
|
|
|
+ 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})
|
|
|
+ point.location = new BABYLON.Vector3(ue4Pos.x, ue4Pos.y, ue4Pos.z)
|
|
|
+ })
|
|
|
+
|
|
|
+ let walkPoints = []
|
|
|
+ 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() / 30
|
|
|
+ let dir = distanceVec.normalize()
|
|
|
+ for(let currentFrame = 1; currentFrame <= 30; currentFrame++) {
|
|
|
+ walkPoints.push(point0.add(dir.scale(distancePerFrame * currentFrame)))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.error(walkPoints)
|
|
|
+
|
|
|
+ window.walkSettings = {
|
|
|
+ "frameNum": 30 * (pathArr.length - 1),
|
|
|
+ "walkPoints": walkPoints,
|
|
|
+ }
|
|
|
+
|
|
|
+ window.walking = true
|
|
|
+
|
|
|
+
|
|
|
+ this.mutiFetchData({
|
|
|
+ type: 'move',
|
|
|
+ videoPathArr: videoArr
|
|
|
+ })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
async avatarComponentsSync(e){
|
|
@@ -111,6 +182,18 @@ export default class ActionsHandler {
|
|
|
}
|
|
|
}
|
|
|
async moveTo(e) {
|
|
|
+
|
|
|
+ // 镜头矫正
|
|
|
+ let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
|
|
|
+ if(Math.abs(anglePlus) > 0.0001) {
|
|
|
+ window.moveBackCall = {
|
|
|
+ func: this.moveTo.bind(this),
|
|
|
+ args: [e]
|
|
|
+ }
|
|
|
+ this.rotate({type: 'rotate', angle: anglePlus})
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
const {point: t, extra: r="", motionType: n} = e
|
|
|
, o = {
|
|
|
action_type: Actions.Clicking,
|
|
@@ -122,9 +205,62 @@ export default class ActionsHandler {
|
|
|
},
|
|
|
clicking_state: this.room._currentClickingState
|
|
|
};
|
|
|
- return this.sendData({
|
|
|
- data: o
|
|
|
- })
|
|
|
+
|
|
|
+ let player = window.room.sceneManager.avatarComponent._mainUser
|
|
|
+
|
|
|
+ let closestPoint = window.room.sceneManager.getClosestPointData(t)
|
|
|
+ let closestPointSelf = window.room.sceneManager.getClosestPointData(player.position)
|
|
|
+
|
|
|
+ window.connection.socket.emit("getRoute", {
|
|
|
+ sceneCode: "testApp",
|
|
|
+ userId: "testUser",
|
|
|
+ roomId: "8888",
|
|
|
+ s_location: {
|
|
|
+ x: closestPointSelf.position0.x,
|
|
|
+ y: closestPointSelf.position0.y,
|
|
|
+ z: closestPointSelf.position0.z,
|
|
|
+ },
|
|
|
+ e_location: {
|
|
|
+ x: closestPoint.position0.x,
|
|
|
+ y: closestPoint.position0.y,
|
|
|
+ z: closestPoint.position0.z,
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // if(this.walkHandle) clearInterval(this.walkHandle)
|
|
|
+
|
|
|
+ // // window.room.moveTo(t)
|
|
|
+ // let currentFrame = 0
|
|
|
+ // this.walkHandle = setInterval(() => {
|
|
|
+ // currentFrame++
|
|
|
+ // let targetPos = {
|
|
|
+ // "x": player.position.x + distanceVec.x / frameNum,
|
|
|
+ // "y": player.position.y + distanceVec.y / frameNum,
|
|
|
+ // "z": player.position.z + distanceVec.z / frameNum
|
|
|
+ // }
|
|
|
+ // if(currentFrame < frameNum) {
|
|
|
+ // window.room.moveTo({
|
|
|
+ // position: targetPos,
|
|
|
+ // isEnd: false
|
|
|
+ // })
|
|
|
+ // } else {
|
|
|
+ // window.room.moveTo({
|
|
|
+ // position: targetPos,
|
|
|
+ // isEnd: true
|
|
|
+ // })
|
|
|
+ // clearInterval(this.walkHandle)
|
|
|
+ // }
|
|
|
+ // }, 1000 / fps)
|
|
|
+
|
|
|
+ // let date = new Date()
|
|
|
+ // console.error(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())
|
|
|
+
|
|
|
+ // console.error(closestPointSelf.id)
|
|
|
+
|
|
|
+ // return this.sendData({
|
|
|
+ // data: o
|
|
|
+ // })
|
|
|
}
|
|
|
transfer(e) {
|
|
|
const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s, person: l, noMedia: u, timeout: c, tag: h, special: f} = e
|
|
@@ -384,11 +520,12 @@ export default class ActionsHandler {
|
|
|
let endRotation = util.xverseRotation2Ue4(window.room.sceneManager.cameraComponent.mainCamera.rotation).yaw
|
|
|
endRotation = (endRotation % 360 + 360) % 360
|
|
|
|
|
|
- let sfns = Math.round(endRotation/6)
|
|
|
+ // todo 矫正
|
|
|
+ let sfns = Math.round((endRotation + 180)/6) // 仅视频贴图偏移矫正180度
|
|
|
endRotation += angle/Math.PI*180
|
|
|
endRotation = (endRotation % 360 + 360) % 360
|
|
|
|
|
|
- let efns = Math.round(endRotation/6)
|
|
|
+ let efns = Math.round((endRotation + 180)/6)
|
|
|
|
|
|
if(window.currentFrame == null){
|
|
|
window.currentFrame = efns
|
|
@@ -410,12 +547,17 @@ export default class ActionsHandler {
|
|
|
window.rotateFrame = efns - sfns // 旋转帧数
|
|
|
window.camera_endRotation = endRotation
|
|
|
window.star_angle = angle
|
|
|
+
|
|
|
+
|
|
|
+ let player = window.room.sceneManager.avatarComponent._mainUser
|
|
|
+ let closestPointSelf = window.room.sceneManager.getClosestPointData(player.position)
|
|
|
|
|
|
console.log('取帧:'+sfns+','+efns);
|
|
|
this.fetchData({
|
|
|
- type:type,
|
|
|
- sFrame:sfns,
|
|
|
- eFrame:efns
|
|
|
+ type: type,
|
|
|
+ path: ossVideoDir + closestPointSelf.id + "/" + closestPointSelf.id,
|
|
|
+ sFrame: sfns,
|
|
|
+ eFrame: efns
|
|
|
})
|
|
|
|
|
|
if(typeof(window.star_angle) == 'undefined'){
|
|
@@ -477,13 +619,38 @@ export default class ActionsHandler {
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
- fetchData({type:type, sFrame: sfns, eFrame: efns}){
|
|
|
+ fetchData({type, path, sFrame: sfns, eFrame: efns}){
|
|
|
if(window.workerReady){
|
|
|
this.vDecoder.fetch({
|
|
|
- path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/2",
|
|
|
+ // path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/res/720p",
|
|
|
+ path: path,
|
|
|
// range: [sfns, efns],
|
|
|
range: sfns == efns ? [efns] : [sfns, efns],
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ console.error('还没准备好')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mutiFetchData({type, videoPathArr}){
|
|
|
+ console.error(videoPathArr)
|
|
|
+ if(window.workerReady){
|
|
|
+ // https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/optest/0/0_1_0/
|
|
|
+ let sendData = []
|
|
|
+ // let videoPathArr = [
|
|
|
+ // "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 < 30; i++) {
|
|
|
+ sendData.push({
|
|
|
+ path: path,
|
|
|
+ frame: i,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.vDecoder.mutiFetch(sendData);
|
|
|
}
|
|
|
else{
|
|
|
console.error('还没准备好')
|