xushiting 3 tahun lalu
induk
melakukan
aa6bb76569
5 mengubah file dengan 166 tambahan dan 35 penghapusan
  1. 63 11
      src/ActionsHandler.js
  2. 41 23
      src/RotationEvent.js
  3. 1 1
      src/Signal.js
  4. 60 0
      src/XMaterialComponent.js
  5. 1 0
      src/Xverse_Room.js

+ 63 - 11
src/ActionsHandler.js

@@ -5,12 +5,30 @@ import Person from "./enum/Person.js"
 import ClickType from "./enum/ClickType.js"
 import Logger from "./Logger.js"
 
+
+import { VDecoder } from "./h264Decoder/VDecoder.js";
+
 const logger = new Logger('actions-handler')
 const QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];
 export default class ActionsHandler {
     constructor(e) {
         this.currentActiveAction = null
         this.room = e
+
+        //xst
+        window.workerReady = false
+        this.vDecoder = new VDecoder({   
+            maxChip: 100,
+          });
+        window.vDecoder = this.vDecoder
+        this.init()
+    }
+
+    init(){
+        this.vDecoder.on('ready', () => {
+            console.log("ready");
+            window.workerReady = true
+        })
     }
 
     async avatarComponentsSync(e){
@@ -334,7 +352,7 @@ export default class ActionsHandler {
     }
 
 /***********************************************************************xst****************************************************************/
-    
+    /*
     rotate({pitch: e, yaw: t}) {
         var n;
         if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode))
@@ -353,19 +371,53 @@ export default class ActionsHandler {
             sampleRate: .02
         })
     }
+    */
     
 
-    // rotate({type: type, angle: angle}) {
-    //     //每6°一个角
-    //     for(let i=0;i<60;++i){
-    //         if(Math.abs(angle - i/60 * 2 * Math.PI)<0.01){
-    //             //找到了
-    //             this.sendData({
+    rotate({type: type, angle: angle}) {
+        let endRotation = window.room.sceneManager.cameraComponent.mainCamera.rotation.y
+        if(endRotation<0){
+            endRotation += 2*Math.PI
+        }
+        else if(endRotation>2*Math.PI){
+            endRotation -= 2*Math.PI
+        }
+        
+        let sfns = Math.round(endRotation/Math.PI * 180 /6)
+        //每6°一帧
+        for(let i=0;i<60;++i){
+            if(Math.abs(Math.abs(angle) - i/60 * 2 * Math.PI)<0.01){
+                //找到了
+                endRotation += angle
+                break;
+            }
+        }
+        let efns = Math.round(endRotation/Math.PI * 180 /6)
+        console.log('取帧:'+sfns+','+efns);
+        this.fetchData({
+            type:type,
+            sFrame:sfns,
+            eFrame:efns
+        })
+
+        this.room.sceneManager.materialComponent.initreceveFrames()
+ 
+        // this.room.sceneManager.cameraComponent.mainCamera.rotation.y = endRotation
+        // window.room.sceneManager.cameraComponent._cameraPose.rotation._y = endRotation
+        window.room.sceneManager.cameraComponent.mainCamera.rotation.y=endRotation
+    }
 
-    //             })
-    //         }
-    //     }
-    // }
+    fetchData({sFrame: sfns, eFrame: efns}){
+        if(window.workerReady){
+            this.vDecoder.fetch({
+                path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/earth",
+                range: [sfns, efns],
+              });
+        }
+        else{
+            console.error('还没准备好')
+        }
+    }
 
 /*******************************************************************************************************************************************/
 

+ 41 - 23
src/RotationEvent.js

@@ -21,23 +21,41 @@ export default class RotationEvent {
         );
         E(this, "handleMouseMove", e=>{
             if (!this.touchStartX || !this.touchStartY)
+            {
                 return;
-            const t = e.pageX
-              , r = e.pageY
-              , n = t - this.touchStartX
-              , o = r - this.touchStartY
-              , a = this._room.options.canvas.offsetHeight
-              , s = this._room.options.canvas.offsetWidth;
-            let l = 2 * o / a
-              , u = 2 * n / s;
-            l > 1 && (l = 1),
-            u > 1 && (u = 1),
+            }
+            // const t = e.pageX
+            //   , r = e.pageY
+            //   , n = t - this.touchStartX
+            //   , o = r - this.touchStartY
+            //   , a = this._room.options.canvas.offsetHeight
+            //   , s = this._room.options.canvas.offsetWidth;
+            // let l = 2 * o / a
+            //   , u = 2 * n / s;
+            // l > 1 && (l = 1),
+            // u > 1 && (u = 1),
+            // this._room.actionsHandler.rotate({
+            //     pitch: l,
+            //     yaw: u
+            // }),
+            // this.touchStartX = t,
+            // this.touchStartY = r
+
+            const pageX = e.pageX
+            const pageY = e.pageY
+            const offsetX = pageX - this.touchStartX
+            const offsetY = pageY - this.touchStartY
+            const offsetHeight = this._room.options.canvas.offsetHeight
+            const offsetWidth = this._room.options.canvas.offsetWidth
+
+            let angle = offsetX / offsetWidth * 2 * Math.PI
             this._room.actionsHandler.rotate({
-                pitch: l,
-                yaw: u
-            }),
-            this.touchStartX = t,
-            this.touchStartY = r
+                type: 'rotate',
+                angle: angle
+            });
+
+            this.touchStartX = pageX;
+            this.touchStartY = pageY;
         }
         );
         E(this, "handleMouseUp", ()=>{
@@ -67,17 +85,17 @@ export default class RotationEvent {
 
             pitch > 1 && (pitch = 1);
             yaw > 1 && (yaw = 1);
-
-            this._room.actionsHandler.rotate({
-                pitch: pitch,
-                yaw: yaw
-            });
 /***********************************************************************xst****************************************************************/
-            // let angle = offsetX / offsetWidth * 2 * Math.PI
             // this._room.actionsHandler.rotate({
-            //     type: 'rotate',
-            //     angle: angle
+            //     pitch: pitch,
+            //     yaw: yaw
             // });
+
+            let angle = offsetX / offsetWidth * 2 * Math.PI
+            this._room.actionsHandler.rotate({
+                type: 'rotate',
+                angle: angle
+            });
 /********************************************************************************************************************************************/           
             
             this.touchStartX = pageX;

+ 1 - 1
src/Signal.js

@@ -97,7 +97,7 @@ export default class Signal {
                 this._room.camera.setCameraPose(currentUserStates.playerState.camera)
 
                 //console.log('接收数据setCameraPose:'+JSON.stringify(currentUserStates.playerState.camera.angle))
-                console.log('我们计算:'+ util.ue4Rotation2Xverse(currentUserStates.playerState.camera.angle).y/Math.PI*180)
+                //console.log('我们计算:'+ util.ue4Rotation2Xverse(currentUserStates.playerState.camera.angle).y/Math.PI*180)
             }
         }
         currentUserStates != null && currentUserStates.renderInfo && this._room.camera.handleRenderInfo(currentUserStates)

+ 60 - 0
src/XMaterialComponent.js

@@ -258,8 +258,68 @@ export default class XMaterialComponent {
         t.yuvInfo != null && (this.yuvInfo = t.yuvInfo),
         t.panoInfo != null && this.setPanoInfo(t.panoInfo)
 
+        //xst
         window.testPlane = null
         this.addPlane()
+        this.initReceve =false
+    }
+
+    initreceveFrames(){
+        if(!this.initReceve){
+            this.initReceve = true
+            window.vDecoder.on("decodeData",this.receveFrames.bind(this))
+        }
+        
+    }
+    //xst
+    receveFrames(data){
+        const { width, height, data: buffer } = data;
+        let stream = new Uint8Array(buffer)
+        var o, a;
+        //fov == -1 && (fov = this.yuvInfo.fov);
+        let fov = this.yuvInfo.fov
+        if (this._isUpdateYUV == !0) {
+            const s = {
+                width: width,
+                height: height,
+                fov: fov
+            }
+            const videosResOriArrayIndex = this._videoRawYUVTexArray.findId(width, height)
+            const currentVideoId = this._videoRawYUVTexArray.getCurrentVideoTexId();
+
+            if(currentVideoId < 0 || videosResOriArrayIndex != currentVideoId || fov != this.yuvInfo.fov)
+            {
+                this.yuvInfo.width = width;
+                this.yuvInfo.height = height;
+                this.yuvInfo.fov = fov;
+                this._videoRawYUVTexArray.setCurrentVideoTexId(videosResOriArrayIndex);
+                this._changeVideoRes(videosResOriArrayIndex);
+                this._changePureVideoLowModelShaderCanvasSize(s);
+                this._scenemanager.cameraComponent.cameraFovChange(s);
+                this._scenemanager.yuvInfo = s;
+            }
+
+            let VideoTexture = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)
+            //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
+            //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+
+            if(window.testPlane != null){
+                    
+                // window.updateTexture( new Uint8Array(window.generateRandomArray()) );
+                ++sub
+                if(sub< renderCount)
+                {
+                    if(VideoTexture != null){
+                        window._videoRawYTexture.update(stream)
+                        window._videoRawYTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+                        
+                        VideoTexture.update(stream)
+                        VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+                    }
+                }
+            }
+        }
+
     }
 
     //调试

+ 1 - 0
src/Xverse_Room.js

@@ -64,6 +64,7 @@ export default class Xverse_Room extends EventEmitter {
         E(this, "_currentClickingState", null);
         E(this, "signal", new Signal(this));
         E(this, "firstFrameTimestamp");
+        
         E(this, "receiveRtcData", async()=>{
             logger.info("Invoke receiveRtcData");
             let e = !1