Ver código fonte

Merge branch 'master' of http://face3d.4dage.com:7005/zhangyupeng/meta-server

gemercheung 3 anos atrás
pai
commit
4f026310f6
3 arquivos alterados com 87 adições e 21 exclusões
  1. 63 14
      src/move/move.service.ts
  2. 19 6
      src/rotate/rotate.service.ts
  3. 5 1
      src/scene/scene.service.ts

+ 63 - 14
src/move/move.service.ts

@@ -435,9 +435,9 @@ export class MoveService implements OnModuleInit {
     const user = this.users[userId];
     user.breakPointId = breakPointId;
 
-    if (lastReply.actionResponses[0].actionType != 15) {
-      user.player.position =
-        lastReply['newUserStates'][0].playerState.player.position;
+    if(lastReply.actionResponses[0].actionType != 15)
+    {
+      user.player.position = lastReply['newUserStates'][0].playerState.player.position;
     }
     user.player.angle = lastReply['newUserStates'][0].playerState.player.angle;
     user.camera.position =
@@ -682,6 +682,7 @@ export class MoveService implements OnModuleInit {
   //         neighPoints.push(neighPoint);
   //         ++count;
   //       }
+        
 
   //       if(Math.abs(angle - move_angle)<45||Math.abs(angle+360 - move_angle)<45){
   //         if(singleInfo == null){
@@ -699,7 +700,7 @@ export class MoveService implements OnModuleInit {
   //       this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
   //         JSON.stringify(playerPosition),
   //       );
-  //     }
+  //     } 
   //     else{
   //       if(singleInfo != null){
   //         return await this.moveDirect(
@@ -827,6 +828,8 @@ export class MoveService implements OnModuleInit {
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply.mediaSrc = null;
 
+      console.log('joystickjoystick:'+this.cameraInfos.length);
+
       if (surroundPointIds.length == 1) {
         console.log(
           'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
@@ -995,10 +998,31 @@ export class MoveService implements OnModuleInit {
         const cameraInfo = this.getCameraInfo();
         if (cameraInfo != null) {
           console.log('joystick自由--->合并');
-          this.reply['newUserStates'][0].playerState.camera.position =
-            cameraInfo.cameraPosition;
-          this.reply['newUserStates'][0].playerState.camera.angle =
-            cameraInfo.cameraAngle;
+          this.reply['newUserStates'][0].playerState.camera.position = cameraInfo.cameraPosition;
+          this.reply['newUserStates'][0].playerState.camera.angle = cameraInfo.cameraAngle;
+
+          if (cameraInfo.mediaSrc) {
+            this.reply.mediaSrc = cameraInfo.mediaSrc;
+          } 
+          else if (cameraInfo.file_name) {
+            this.reply.mediaSrc =
+              '/' +
+              appId +
+              '/' +
+              breakPointId +
+              '/' +
+              cameraInfo.file_name.substring(
+                0,
+                cameraInfo.file_name.indexOf('.'),
+              ) +
+              '/' +
+              cameraInfo.file_name +
+              '?m=' +
+              new Date().getTime();
+          }
+          if(this.cameraInfos.length == 0){
+            this.reply.moveOver = true;
+          }
         } else {
           console.log('joystick自由--->不合并');
         }
@@ -1024,7 +1048,7 @@ export class MoveService implements OnModuleInit {
   ) {
     const breakPoint = this.breakPointInfo[breakPointId];
     const user = this.users[userId];
-    const player_Position = this.getTarget(
+    let player_Position = this.getTarget(
       playerPosition,
       breakPoint.position,
       this.breakPointInfo[neighBreakPointId].position,
@@ -1052,10 +1076,32 @@ export class MoveService implements OnModuleInit {
       this.reply.actionResponses[0].actionType = actionType;
       const cameraInfo = this.getCameraInfo();
       if (cameraInfo != null) {
-        this.reply['newUserStates'][0].playerState.camera.position =
-          cameraInfo.camera_position;
-        this.reply['newUserStates'][0].playerState.camera.angle =
-          cameraInfo.camera_angle;
+        this.reply['newUserStates'][0].playerState.camera.position = cameraInfo.camera_position;
+        this.reply['newUserStates'][0].playerState.camera.angle = cameraInfo.camera_angle;
+   
+        if (cameraInfo.mediaSrc) {
+          this.reply.mediaSrc = cameraInfo.mediaSrc;
+        } 
+        else if (cameraInfo.file_name) {
+          this.reply.mediaSrc =
+            '/' +
+            appId +
+            '/' +
+            breakPointId +
+            '/' +
+            cameraInfo.file_name.substring(
+              0,
+              cameraInfo.file_name.indexOf('.'),
+            ) +
+            '/' +
+            cameraInfo.file_name +
+            '?m=' +
+            new Date().getTime();
+        }
+
+        if(this.cameraInfos.length == 0){
+          this.reply.moveOver = true;
+        }
       }
       return this.reply;
     }
@@ -1165,6 +1211,7 @@ export class MoveService implements OnModuleInit {
         } else {
           debugger;
         }
+        this.reply.moveStart = true;
       }
       return this.reply;
       // user.camera.position = JSON.parse(
@@ -1176,7 +1223,9 @@ export class MoveService implements OnModuleInit {
   }
 
   setCameraInfo(moveFrames) {
-    this.cameraInfos = moveFrames;
+    for(let i=0;i<moveFrames.length;i += 5){
+      this.cameraInfos.push(moveFrames[i]);
+    }
   }
 
   addCameraInfo(cameraPosition, cameraAngle, mediaSrc) {

+ 19 - 6
src/rotate/rotate.service.ts

@@ -247,7 +247,7 @@ export class RotateService {
   //   this.actionRequests.push(actionRequest)
   // }
 
-  rotateForAngle(userId, hAngle): Promise<any> {
+  async rotateForAngle(userId, hAngle): Promise<any> {
     return new Promise(async (resolve, reject) => {
       try {
         const user = this.users[userId];
@@ -267,7 +267,7 @@ export class RotateService {
         reply['newUserStates'][0]['userId'] = userId;
         //从redis里取
         //let key = user.appId + "-"+user.breakPointId+"-"+user.rotateInfo.frameIndex;
-        const key =
+        let key =
           'rotateframe:app_id:' +
           user.appId +
           ':frame_index:' +
@@ -276,11 +276,23 @@ export class RotateService {
           user.breakPointId;
         // const value = null;
         console.log('rotateForAngle-3:' + user.breakPointId);
-        console.log('rotateForAngle-3-key', key);
+        console.log('rotateForAngle-3-key:'+ key);
         this.logger.log('rotateForAngle-3-key', key);
-        const redisData = await this.cacheService.get(key);
+        let redisData = await this.cacheService.get(key);
         //if (redisData && redisData.length > 0) {
-        const value = JSON.parse(redisData); //redisData ? JSON.parse(redisData) : null;
+        let value = JSON.parse(redisData); //redisData ? JSON.parse(redisData) : null;
+        //console.log('rotateForAngle-4:'+user.breakPointId+','+value.directory+','+value.fileName);
+        if(value.directory != user.breakPointId){
+          key =
+          'rotateframe:app_id:' +
+          user.appId +
+          ':frame_index:' +
+          user.camera.angle.yaw +
+          ':break_point_id:' +
+          user.breakPointId;
+          redisData = await this.cacheService.get(key);
+          value = JSON.parse(redisData);
+        }
         // console.log('rotate-service', value);
         user.camera['position'] = JSON.parse(
           JSON.stringify(value.cameraPosition),
@@ -316,7 +328,7 @@ export class RotateService {
           '?m=' +
           new Date().getTime();
 
-        console.log('rotateForAngle-4:' + user.breakPointId);
+          console.log('rotateForAngle-5:'+user.breakPointId+','+value.directory+','+value.fileName);
         reply.breakPointId = user.breakPointId;
         this.replies[userId].traceIds = [];
         this.replies[userId].actionResponses = [];
@@ -328,6 +340,7 @@ export class RotateService {
         //   return null;
         // }
       } catch (error) {
+        debugger;
         this.logger.error('rotateForAngle::function', error);
         return reject(error);
       }

+ 5 - 1
src/scene/scene.service.ts

@@ -283,7 +283,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const metaData: StreamReplyType = JSON.parse(
           lastStreamFrame.metaData,
         ) as any as StreamReplyType;
-
+        if(!metaData.endBreakPointId){
+        }
         console.log('stop-4', metaData.traceIds[0]);
         console.log('stop-5', request.trace_id);
         //判断request是否是新的
@@ -315,6 +316,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             JSON.stringify(playerAngle),
         );
         //debugger;
+        console.log('moveService.stop-1:'+breakPointId)
         redisMeta = await this.moveService.stop(
           trace_id,
           userId,
@@ -417,6 +419,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               cameraAngle,
               cameraAngle,
             );
+            console.log('moveService.stop-2:'+breakPointId)
             const redisMeta = await this.moveService.stop(
               trace_id,
               userId,
@@ -609,6 +612,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       this.logger.log('joystickRes-1', joystickRes);
       this.onJoysticking.next(true);
+      console.log('handlejoystick:'+joystickRes.mediaSrc)
       if (Array.isArray(joystickRes)) {
         // 处理第一个镜头数据
         const rotateCamData = joystickRes[0];