gemercheung 3 years ago
parent
commit
a7edfcd44b
3 changed files with 28 additions and 19 deletions
  1. 18 12
      src/move/move.service.ts
  2. 6 3
      src/scene/scene.service.ts
  3. 4 4
      src/scene/stream/stream.service.ts

+ 18 - 12
src/move/move.service.ts

@@ -1,4 +1,9 @@
-import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
+import {
+  ConsoleLogger,
+  Injectable,
+  Logger,
+  OnModuleInit,
+} from '@nestjs/common';
 import { readFileSync } from 'fs';
 import { join } from 'path';
 import { CacheService } from 'src/cache/cache.service';
@@ -168,8 +173,7 @@ export class MoveService implements OnModuleInit {
 
       const appId = user.appId;
       const path = pathArray || [100, 101, 102]; //需要计算路径
-      const angle = user.camera.angle.yaw % 44; //纠正需要
-      console.log('矫正前-相机:' + user.camera.angle.yaw);
+      const angle = (user.camera.angle.yaw + 1) % 45; //纠正需要
       const replys = [];
       const traceIds = [];
       traceIds.push(traceId);
@@ -219,8 +223,7 @@ export class MoveService implements OnModuleInit {
       this.reply.traceIds = traceIds;
       this.reply['newUserStates'][0].userId = userId;
       this.reply['actionResponses'][0].traceId = traceId;
-      console.log('矫正后-相机:' + user.camera.angle.yaw);
-      const index = Math.floor(user.camera.angle.yaw / 44); //过渡需要
+      const index = Math.floor((user.camera.angle.yaw + 1) / 45); //过渡需要
       for (let i = 0; i < path.length - 1; ++i) {
         let pathReplys = [];
         const start_break_point_id = path[i];
@@ -240,6 +243,7 @@ export class MoveService implements OnModuleInit {
           return replys;
         }
         const moveFrames = JSON.parse(moveFramesRes);
+        // debugger;
         //读redis里的数据
         const startBreakPointRes = await this.cacheService.get(
           'breakpoints:app_id:' +
@@ -301,7 +305,7 @@ export class MoveService implements OnModuleInit {
       endPosition,
     );
 
-    for (let i = 1; i < moveFrames.length; i += 5) {
+    for (let i = 1; i < moveFrames.length; i += 2) {
       const moveFrame = moveFrames[i];
 
       const reply = JSON.parse(JSON.stringify(this.reply));
@@ -324,6 +328,12 @@ export class MoveService implements OnModuleInit {
 
       reply['newUserStates'][0].playerState.camera.position =
         moveFrame.camera_position;
+      if (moveFrame.camera_angle.yaw < 0) {
+        moveFrame.camera_angle.yaw += 360;
+      } else if (moveFrame.camera_angle.yaw > 359) {
+        moveFrame.camera_angle.yaw -= 360;
+      }
+
       reply['newUserStates'][0].playerState.camera.angle =
         moveFrame.camera_angle;
       reply['newUserStates'][0].playerState.cameraCenter =
@@ -580,7 +590,7 @@ export class MoveService implements OnModuleInit {
           traceIds.push(traceId);
           // debugger;
           const checkReplys = [];
-          angle = user.camera.angle.yaw % 44; //纠正需要
+          angle = (user.camera.angle.yaw + 1) % 45; //纠正需要
           for (let i = 0; i < angle; ++i) {
             const reply = await this.rotateService.rotateForAngle(userId, 1);
             reply.traceIds = [];
@@ -604,7 +614,7 @@ export class MoveService implements OnModuleInit {
             ':end_break_point_id:' +
             chooseBreakPointId +
             ':angle:' +
-            (user.camera.angle.yaw % 44);
+            ((user.camera.angle.yaw + 1) % 45);
           const moveFramesRes = await this.cacheService.get(key);
           if (moveFramesRes == null) {
             return replys;
@@ -634,10 +644,6 @@ export class MoveService implements OnModuleInit {
             endBreakPoint.position,
           );
           replys.push(pathReplys);
-          if (replys.length > 0) {
-            console.log('最后一帧' + JSON.stringify(replys[replys.length - 1]));
-          }
-
           return replys;
         }
       }

+ 6 - 3
src/scene/scene.service.ts

@@ -25,7 +25,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     private rotateService: RotateService,
     private moveService: MoveService,
     private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
-  ) { }
+  ) {}
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
 
   public _frameInteval: NodeJS.Timeout;
@@ -369,7 +369,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             console.log('walkingRes', walkingRes[i]);
             Array.from(walkingRes[i]).forEach(
               (item: StreamReplyType, index: number) => {
-                const dir = this.isHeaderOrLast(index, walkingRes[i].length - 1);
+                const dir = this.isHeaderOrLast(
+                  index,
+                  walkingRes[i].length - 1,
+                );
                 item.DIR = dir ? 1 : 3;
               },
             );
@@ -707,7 +710,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 delete redisData.mediaSrc;
                 this.logger.log(
                   `user:${this.user_id}:first render stream` +
-                  JSON.stringify({ path: clipPath, meta: redisData }),
+                    JSON.stringify({ path: clipPath, meta: redisData }),
                 );
                 const status = await this.pushFirstRender(
                   clipPath,

+ 4 - 4
src/scene/stream/stream.service.ts

@@ -96,11 +96,11 @@ export class StreamService {
       try {
         // console.log('process.env', process.env.node_env);
         //TODO 开发替换path
-        const src = stream.clipPath.replace('/mnt/metaverse/scene', '');
-        const srcTmp = join(__dirname, `../ws/${src}`);
-        const clipPath = srcTmp;
+        // const src = stream.clipPath.replace('/mnt/metaverse/scene', '');
+        // const srcTmp = join(__dirname, `../ws/${src}`);
+        // const clipPath = srcTmp;
 
-        // const clipPath = stream.clipPath;
+        const clipPath = stream.clipPath;
         const metaData = stream.metaData || '{}';
         const frame = stream.frame;
         const serverTime = stream.serverTime || 754871824;