xushiting 3 years ago
parent
commit
9a80674342
5 changed files with 385 additions and 236 deletions
  1. 5 3
      src/EngineProxy.js
  2. 131 89
      src/Workers.js
  3. 169 68
      src/XMaterialComponent.js
  4. 3 2
      src/XVideoRawYUV.js
  5. 77 74
      src/Xverse_Room.js

+ 5 - 3
src/EngineProxy.js

@@ -217,7 +217,7 @@ export default class EngineProxy{
         await this.updateBillboard();
         await this.updateBillboard();
         logger.info("engine version:", VERSION$1);
         logger.info("engine version:", VERSION$1);
         logger.setLevel(LoggerLevels.Warn);
         logger.setLevel(LoggerLevels.Warn);
-        const r = {
+        const videoPanoInfo = {
             videoResOriArray: [{
             videoResOriArray: [{
                 width: 720,
                 width: 720,
                 height: 1280
                 height: 1280
@@ -260,8 +260,10 @@ export default class EngineProxy{
             disableWebGL2: this.room.options.disableWebGL2 || !1
             disableWebGL2: this.room.options.disableWebGL2 || !1
         };
         };
         const resolution = this.room.options.resolution;
         const resolution = this.room.options.resolution;
-        resolution && (r.videoResOriArray.some(l=>l.width === resolution.width && l.height === resolution.height) || r.videoResOriArray.push(resolution));
-        const sceneManager = this.room.sceneManager = getSceneManager(this.room.canvas, r);
+        if(resolution){
+            videoPanoInfo.videoResOriArray.some(l=>l.width === resolution.width && l.height === resolution.height) || videoPanoInfo.videoResOriArray.push(resolution)
+        }
+        const sceneManager = this.room.sceneManager = getSceneManager(this.room.canvas, videoPanoInfo);
         this.room.setPictureQualityLevel(this.room.options.pictureQualityLevel || "high");
         this.room.setPictureQualityLevel(this.room.options.pictureQualityLevel || "high");
         this.room.sceneManager.staticmeshComponent.setRegionLodRule([2, 2, -1, -1, -1]);
         this.room.sceneManager.staticmeshComponent.setRegionLodRule([2, 2, -1, -1, -1]);
         this.room.scene = sceneManager.Scene;
         this.room.scene = sceneManager.Scene;

+ 131 - 89
src/Workers.js

@@ -379,23 +379,34 @@ export default class Workers {
             this.firstYUVReceived = !0,
             this.firstYUVReceived = !0,
             this.lastRenderTs = Date.now()
             this.lastRenderTs = Date.now()
         }
         }
-        !this.cachedRender[this.setPtr] && this.cachedMetas[this.setPtr] != null && (this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0 && (e.data.data == null ? (this.executeFunction("stream", {
-            stream: this.cachedStreams[this.setPtr],
-            width: this.cachedResolution[this.setPtr].width,
-            height: this.cachedResolution[this.setPtr].height,
-            pts: this.cachedPtss[this.setPtr]
-        }),
-        this.executeFunction("signal", {
-            signal: this.cachedMetas[this.setPtr],
-            pts: this.cachedPtss[this.setPtr],
-            alreadyUpdateYUV: !0
-        })) : this.updateDropFrame += 1,
-        this.decoderWorker.postMessage({
-            t: 2,
-            frameCnt: this.cachedPtss[this.setPtr],
-            buffer: this.cachedStreams[this.setPtr]
-        }, [this.cachedStreams[this.setPtr].buffer])),
-        this.getPtr = (this.getPtr + 1) % this.cachedLength);
+        if(!this.cachedRender[this.setPtr] && this.cachedMetas[this.setPtr] != null){
+            if(this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0)
+            {
+                if(e.data.data == null){
+                    this.executeFunction("stream", {
+                        stream: this.cachedStreams[this.setPtr],
+                        width: this.cachedResolution[this.setPtr].width,
+                        height: this.cachedResolution[this.setPtr].height,
+                        pts: this.cachedPtss[this.setPtr]
+                    }),
+                    this.executeFunction("signal", {
+                        signal: this.cachedMetas[this.setPtr],
+                        pts: this.cachedPtss[this.setPtr],
+                        alreadyUpdateYUV: !0
+                    })
+                }
+                else{
+                    this.updateDropFrame += 1
+                }
+                this.decoderWorker.postMessage({
+                    t: 2,
+                    frameCnt: this.cachedPtss[this.setPtr],
+                    buffer: this.cachedStreams[this.setPtr]
+                }, [this.cachedStreams[this.setPtr].buffer])
+            }
+            this.getPtr = (this.getPtr + 1) % this.cachedLength
+        }
+
         const t = e.data.metadata;
         const t = e.data.metadata;
         if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
         if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
             for (const o of t.traceIds)
             for (const o of t.traceIds)
@@ -405,19 +416,21 @@ export default class Workers {
                     a.status = 2)
                     a.status = 2)
                 }
                 }
         }
         }
-        if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs),
-        this.userId_test = this.rtcp.network.room.userId,
-        this.inMovingMode) {
+
+        e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs);
+        this.userId_test = this.rtcp.network.room.userId;
+
+        if (this.inMovingMode) {
             const o = Date.now()
             const o = Date.now()
-              , a = o - this.lastMoveProcessTime;
-            this.moveProcessCircular.add(a),
-            this.lastMoveProcessTime = o
+            const a = o - this.lastMoveProcessTime;
+            this.moveProcessCircular.add(a);
+            this.lastMoveProcessTime = o;
         }
         }
         const r = this.setPtr;
         const r = this.setPtr;
-        this.cachedStreams[r] = e.data.data,
-        this.cachedMetas[r] = e.data.metadata,
-        this.cachedPtss[r] = e.data.pts,
-        this.cachedRender[r] = !1,
+        this.cachedStreams[r] = e.data.data;
+        this.cachedMetas[r] = e.data.metadata;
+        this.cachedPtss[r] = e.data.pts;
+        this.cachedRender[r] = !1;
         this.cachedResolution[r] = {
         this.cachedResolution[r] = {
             width: e.data.width,
             width: e.data.width,
             height: e.data.height
             height: e.data.height
@@ -775,7 +788,9 @@ export default class Workers {
         var T, C, A, S, P, R, M, x, I, w;
         var T, C, A, S, P, R, M, x, I, w;
         const t = new DataView(e);
         const t = new DataView(e);
         if (t.getUint32(0) != 1437227610)
         if (t.getUint32(0) != 1437227610)
+        {
             return !1;
             return !1;
+        }
         t.getUint16(4);
         t.getUint16(4);
         const n = t.getUint16(6)
         const n = t.getUint16(6)
           , o = t.getUint16(8)
           , o = t.getUint16(8)
@@ -796,8 +811,10 @@ export default class Workers {
         this.calcSendTimeDiff(h);
         this.calcSendTimeDiff(h);
         let b;
         let b;
         if (this.inPanoMode && (c > 0 || f))
         if (this.inPanoMode && (c > 0 || f))
-            return defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode"),
-            !0;
+        {
+            defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode")
+            return !0;
+        }
         if (v === m) {
         if (v === m) {
             this.receivedMedia++;
             this.receivedMedia++;
             const O = new Uint8Array(e).subarray(n);
             const O = new Uint8Array(e).subarray(n);
@@ -806,33 +823,43 @@ export default class Workers {
             D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
             D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
             const F = c === 0
             const F = c === 0
               , V = h - this.lastServerTS;
               , V = h - this.lastServerTS;
-            this.lastServerTS != 0 && ((o + 65536 - this.lastSeq) % 65536 === 1 && this.lastIsPureMeta == F && (F ? this.srvMetaIntervalCircular.add(V) : this.srvMediaIntervalCircular.add(V)),
-            this.frameServerCircular.add(V),
-            this.frameClientCircular.add(D - this.lastClientTS)),
-            this.lastSeq = o,
-            this.lastIsPureMeta = F,
-            this.lastServerTS = h,
+            if(this.lastServerTS != 0)
+            {
+                if((o + 65536 - this.lastSeq) % 65536 === 1 && this.lastIsPureMeta == F){
+                    F ? this.srvMetaIntervalCircular.add(V) : this.srvMediaIntervalCircular.add(V)
+                }
+
+                this.frameServerCircular.add(V);
+                this.frameClientCircular.add(D - this.lastClientTS);
+            }
+            this.lastSeq = o;
+            this.lastIsPureMeta = F;
+            this.lastServerTS = h;
             this.lastClientTS = D;
             this.lastClientTS = D;
             const N = O.subarray(0, u)
             const N = O.subarray(0, u)
               , L = Date.now()
               , L = Date.now()
               , k = JSON.parse(this.Stringify(N))
               , k = JSON.parse(this.Stringify(N))
               , U = Date.now();
               , U = Date.now();
-            this.showAllReceivedMetadata && console.log(h, D, k),
-            this.metaParseAraay.push(U - L),
-            (T = k.traceIds) != null && T.length && this.processMetaWithTraceId(k),
-            c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o),
-            this.moveStartPts == o && (this.MoveResponseDelay = Date.now() - this.StartMovingTs,
-            console.log("move response delay: ", o, this.moveStartPts, this.MoveResponseDelay));
+            this.showAllReceivedMetadata && console.log(h, D, k);
+            this.metaParseAraay.push(U - L);
+            (T = k.traceIds) != null && T.length && this.processMetaWithTraceId(k);
+            c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o);
+            if(this.moveStartPts == o){
+                this.MoveResponseDelay = Date.now() - this.StartMovingTs;
+                console.log("move response delay: ", o, this.moveStartPts, this.MoveResponseDelay)
+            }
             const z = this.getIsMoving(k);
             const z = this.getIsMoving(k);
-            if (this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray(),
-            typeof z != "undefined" && (this.lastIsMoving = z),
-            this.inMovingMode) {
+            this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray();
+            typeof z != "undefined" && (this.lastIsMoving = z);
+            if (this.inMovingMode) {
                 const G = Date.now()
                 const G = Date.now()
                   , W = G - this.lastMoveResponseTime;
                   , W = G - this.lastMoveResponseTime;
-                this.moveResponseCircular.add(W),
-                this.lastMoveResponseTime = G
+                this.moveResponseCircular.add(W);
+                this.lastMoveResponseTime = G;
+            }
+            if(f || d){
+                b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(G=>G.userId === this._rtcp.network.room.userId)) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position
             }
             }
-            (f || d) && (b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(G=>G.userId === this._rtcp.network.room.userId)) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position);
             const H = {
             const H = {
                 t: 0,
                 t: 0,
                 data: O,
                 data: O,
@@ -848,59 +875,66 @@ export default class Workers {
                 position: b
                 position: b
             };
             };
             if (this.inPanoMode)
             if (this.inPanoMode)
-                return this.executeFunction("signal", {
+            {
+                this.executeFunction("signal", {
                     signal: k,
                     signal: k,
                     pts: -1,
                     pts: -1,
                     alreadyUpdateYUV: !0
                     alreadyUpdateYUV: !0
-                }),
-                !0;
-            if (this.decoderWorker.postMessage(H, [O.buffer]),
-            !this.firstMediaReceived) {
+                });
+                return !0;
+            }
+            this.decoderWorker.postMessage(H, [O.buffer]);
+            if (!this.firstMediaReceived) {
                 this.firstMediaArraval = Date.now();
                 this.firstMediaArraval = Date.now();
                 const G = this.firstMediaArraval - this.rtcp.network.room._startTime;
                 const G = this.firstMediaArraval - this.rtcp.network.room._startTime;
                 defaultLogger.infoAndReportMeasurement({
                 defaultLogger.infoAndReportMeasurement({
                     metric: "firstMediaArravalAt",
                     metric: "firstMediaArravalAt",
                     value: G,
                     value: G,
                     group: "joinRoom"
                     group: "joinRoom"
-                }),
-                this.firstMediaReceived = !0
+                });
+                this.firstMediaReceived = !0;
             }
             }
-        } else {
+        } 
+        else {
             const O = this.hasFrmCntInCache(a);
             const O = this.hasFrmCntInCache(a);
             if (O != -1)
             if (O != -1)
-                if (this.cacheFrameComposes[O].buffer.set(y, g),
-                this.cacheFrameComposes[O].size += v,
-                this.cacheFrameComposes[O].size === m) {
+            {
+                this.cacheFrameComposes[O].buffer.set(y, g);
+                this.cacheFrameComposes[O].size += v;
+                if (this.cacheFrameComposes[O].size === m) {
                     const D = new Uint8Array(this.cacheFrameComposes[O].buffer).slice(0, m);
                     const D = new Uint8Array(this.cacheFrameComposes[O].buffer).slice(0, m);
-                    this.cacheFrameComposes[O].frameCnt = -1,
-                    this.cacheFrameComposes[O].size = 0,
-                    this.cacheFrameComposes[O].startReceiveTime = 0,
-                    this.cacheFrameComposes[O].serverTime = 0,
-                    this.receivedMedia++,
+                    this.cacheFrameComposes[O].frameCnt = -1;
+                    this.cacheFrameComposes[O].size = 0;
+                    this.cacheFrameComposes[O].startReceiveTime = 0;
+                    this.cacheFrameComposes[O].serverTime = 0;
+                    this.receivedMedia++;
                     h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
                     h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
                     const F = Date.now();
                     const F = Date.now();
-                    F - this.lastClientTS > 60 ? this.clientFrameSlow++ : F - this.lastClientTS < 16 && this.clientFrameFast++,
-                    this.lastServerTS != 0 && (this.frameServerCircular.add(h - this.lastServerTS),
-                    this.frameClientCircular.add(F - this.lastClientTS)),
-                    this.lastServerTS = h,
+                    F - this.lastClientTS > 60 ? this.clientFrameSlow++ : F - this.lastClientTS < 16 && this.clientFrameFast++;
+                    if(this.lastServerTS != 0)
+                    {
+                        this.frameServerCircular.add(h - this.lastServerTS);
+                        this.frameClientCircular.add(F - this.lastClientTS);
+                    }
+                    this.lastServerTS = h;
                     this.lastClientTS = F;
                     this.lastClientTS = F;
                     const V = D.subarray(0, u)
                     const V = D.subarray(0, u)
                       , N = Date.now()
                       , N = Date.now()
                       , L = JSON.parse(this.Stringify(V))
                       , L = JSON.parse(this.Stringify(V))
                       , k = Date.now();
                       , k = Date.now();
-                    this.showAllReceivedMetadata && console.log(h, F, L),
-                    this.metaParseAraay.push(k - N),
-                    (R = L.traceIds) != null && R.length && this.processMetaWithTraceId(L),
-                    c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o),
+                    this.showAllReceivedMetadata && console.log(h, F, L);
+                    this.metaParseAraay.push(k - N);
+                    (R = L.traceIds) != null && R.length && this.processMetaWithTraceId(L);
+                    c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o);
                     this.moveStartPts == o && (this.MoveResponseDelay = Date.now() - this.StartMovingTs);
                     this.moveStartPts == o && (this.MoveResponseDelay = Date.now() - this.StartMovingTs);
                     const U = this.getIsMoving(L);
                     const U = this.getIsMoving(L);
-                    if (this.inMovingMode && U == 0 && this.lastIsMoving == 1 && this.clearMoveArray(),
-                    typeof U != "undefined" && (this.lastIsMoving = U),
-                    this.inMovingMode) {
+                    this.inMovingMode && U == 0 && this.lastIsMoving == 1 && this.clearMoveArray();
+                    typeof U != "undefined" && (this.lastIsMoving = U);
+                    if (this.inMovingMode) {
                         const H = Date.now()
                         const H = Date.now()
                           , G = H - this.lastMoveResponseTime;
                           , G = H - this.lastMoveResponseTime;
-                        this.moveResponseCircular.add(G),
-                        this.lastMoveResponseTime = H
+                        this.moveResponseCircular.add(G);
+                        this.lastMoveResponseTime = H;
                     }
                     }
                     (f || d) && (b = (w = (I = (x = (M = L.newUserStates) == null ? void 0 : M.find(H=>H.userId === this._rtcp.network.room.userId)) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
                     (f || d) && (b = (w = (I = (x = (M = L.newUserStates) == null ? void 0 : M.find(H=>H.userId === this._rtcp.network.room.userId)) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
                     const z = {
                     const z = {
@@ -918,14 +952,16 @@ export default class Workers {
                         position: b
                         position: b
                     };
                     };
                     if (this.inPanoMode)
                     if (this.inPanoMode)
-                        return this.executeFunction("signal", {
+                    {
+                        this.executeFunction("signal", {
                             signal: L,
                             signal: L,
                             pts: -1,
                             pts: -1,
                             alreadyUpdateYUV: !0
                             alreadyUpdateYUV: !0
-                        }),
-                        !0;
-                    if (this.decoderWorker.postMessage(z, [D.buffer]),
-                    !this.firstMediaReceived) {
+                        });
+                        return !0;
+                    }
+                    this.decoderWorker.postMessage(z, [D.buffer]);
+                    if (!this.firstMediaReceived) {
                         this.firstMediaArraval = Date.now();
                         this.firstMediaArraval = Date.now();
                         const H = this.firstMediaArraval - this.rtcp.network.room._startTime;
                         const H = this.firstMediaArraval - this.rtcp.network.room._startTime;
                         defaultLogger.infoAndReportMeasurement({
                         defaultLogger.infoAndReportMeasurement({
@@ -935,8 +971,12 @@ export default class Workers {
                         }),
                         }),
                         this.firstMediaReceived = !0
                         this.firstMediaReceived = !0
                     }
                     }
-                } else
+                } 
+                else
+                {
                     this.cacheFrameComposes[O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
                     this.cacheFrameComposes[O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
+                }
+            }
             else if (O == -1) {
             else if (O == -1) {
                 let D = this.hasFrmCntInCache(-1);
                 let D = this.hasFrmCntInCache(-1);
                 if (D == -1) {
                 if (D == -1) {
@@ -947,11 +987,11 @@ export default class Workers {
                         V = N);
                         V = N);
                     D = V
                     D = V
                 }
                 }
-                this.cacheFrameComposes[D].buffer.set(y, g),
-                this.cacheFrameComposes[D].size = v,
-                this.cacheFrameComposes[D].frameCnt = a,
-                this.cacheFrameComposes[D].startReceiveTime = Date.now(),
-                this.cacheFrameComposes[D].serverTime = h
+                this.cacheFrameComposes[D].buffer.set(y, g);
+                this.cacheFrameComposes[D].size = v;
+                this.cacheFrameComposes[D].frameCnt = a;
+                this.cacheFrameComposes[D].startReceiveTime = Date.now();
+                this.cacheFrameComposes[D].serverTime = h;
             }
             }
         }
         }
         return !0
         return !0
@@ -981,8 +1021,10 @@ export default class Workers {
         if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0)
         if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0)
             return;
             return;
         if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
         if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
-            this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}),
-            this.reconnectSignal = !1);
+            if(this.reconnectSignal){
+                this.executeFunction("reconnectedFrame", {});
+                this.reconnectSignal = !1
+            }
             return
             return
         }
         }
         if (t.length > 20 && this.unmarshalPano(t.buffer) == !0)
         if (t.length > 20 && this.unmarshalPano(t.buffer) == !0)

+ 169 - 68
src/XMaterialComponent.js

@@ -22,7 +22,7 @@ export default class XMaterialComponent {
         E(this, "_inputPanoYUV420", !0);
         E(this, "_inputPanoYUV420", !0);
         E(this, "_videoRawYUVTexArray");
         E(this, "_videoRawYUVTexArray");
         E(this, "_isUpdateYUV", !0);
         E(this, "_isUpdateYUV", !0);
-        E(this, "initMaterial", async()=>new Promise((e,t)=>{
+        E(this, "initMaterial", async()=>new Promise((resolve,t)=>{
             this._initDefaultShader(),
             this._initDefaultShader(),
             this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
             this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
                 this._initPureVideoShader(),
                 this._initPureVideoShader(),
@@ -30,59 +30,75 @@ export default class XMaterialComponent {
             }
             }
             ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
             ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
             this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
             this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
-            e(!0)
-        }
-        ));
-        E(this, "_initPureVideoContent", e=>{
-            this._inputYUV420 ? this._videoRawYUVTexArray.getVideoYUVTex(0) != null && (this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(0)),
-            this._lowModelShader.setFloat("isYUV", 1),
-            BABYLON.Texture.WhenAllReady([this._videoRawYUVTexArray.getVideoYUVTex(0)], ()=>{
-                this._changePureVideoLowModelShaderCanvasSize(e)
+            resolve(!0)
+        }));
+
+        E(this, "_initPureVideoContent", focal_width_height=>{
+            if(this._inputYUV420){
+                if(this._videoRawYUVTexArray.getVideoYUVTex(0) != null){
+                    this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(0));
+                    this._lowModelShader.setFloat("isYUV", 1);
+                    BABYLON.Texture.WhenAllReady([this._videoRawYUVTexArray.getVideoYUVTex(0)], ()=>{
+                        this._changePureVideoLowModelShaderCanvasSize(focal_width_height)
+                    })
+                }
             }
             }
-            )) : (this._videoElement = e.videoElement,
-            this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1)),
-            BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
-                this._changePureVideoLowModelShaderCanvasSize({
-                    width: this._videoElement.height,
-                    height: this._videoElement.width,
-                    fov: e.fov
-                })
+            else{
+                this._videoElement = e.videoElement;
+                this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
+                BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
+                    this._changePureVideoLowModelShaderCanvasSize({
+                        width: this._videoElement.height,
+                        height: this._videoElement.width,
+                        fov: e.fov
+                    })
+                });
+                this._lowModelShader.setTexture("texture_video", this._videoTexture);
+                this._lowModelShader.setFloat("isYUV", 0);
             }
             }
-            ),
-            this._lowModelShader.setTexture("texture_video", this._videoTexture),
-            this._lowModelShader.setFloat("isYUV", 0))
-        }
-        );
+        });
+
         E(this, "_changePureVideoLowModelShaderCanvasSize", e=>{
         E(this, "_changePureVideoLowModelShaderCanvasSize", e=>{
-            var a;
-            const t = e.fov || 50
-              , r = e.width || 720
-              , n = e.height || 1280
-              , o = r / (2 * Math.tan(Math.PI * t / 360));
-            (a = this._lowModelShader) == null || a.setVector3("focal_width_height", new BABYLON.Vector3(o,r,n))
+            var lowModelShader;
+            const fov = e.fov || 50
+            const width = e.width || 720
+            const height = e.height || 1280
+            const focus = width / (2 * Math.tan(Math.PI * fov / 360));
+            (lowModelShader = this._lowModelShader) == null || lowModelShader.setVector3("focal_width_height", new BABYLON.Vector3(focus,width,height))
         }
         }
         );
         );
-        E(this, "updateRawYUVData", (e,t,r,n=-1)=>{
+
+        E(this, "updateRawYUVData", (stream,width,height,fov=-1)=>{
             var o, a;
             var o, a;
-            if (n == -1 && (n = this.yuvInfo.fov),
-            this._isUpdateYUV == !0) {
+            fov == -1 && (fov = this.yuvInfo.fov);
+            if (this._isUpdateYUV == !0) {
                 const s = {
                 const s = {
-                    width: t,
-                    height: r,
-                    fov: n
+                    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)
+                if(VideoTexture != null){
+                    VideoTexture.update(stream)
+                    VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
                 }
                 }
-                  , l = this._videoRawYUVTexArray.findId(t, r)
-                  , u = this._videoRawYUVTexArray.getCurrentVideoTexId();
-                (u < 0 || l != u || n != this.yuvInfo.fov) && (this.yuvInfo.width = t,
-                this.yuvInfo.height = r,
-                this.yuvInfo.fov = n,
-                this._videoRawYUVTexArray.setCurrentVideoTexId(l),
-                this._changeVideoRes(l),
-                this._changePureVideoLowModelShaderCanvasSize(s),
-                this._scenemanager.cameraComponent.cameraFovChange(s),
-                this._scenemanager.yuvInfo = s),
-                (o = this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || o.update(e),
-                (a = this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+                //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
+                //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
             }
             }
         }
         }
         );
         );
@@ -90,25 +106,27 @@ export default class XMaterialComponent {
             this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(e))
             this._lowModelShader.setTexture("texture_video", this._videoRawYUVTexArray.getVideoYUVTex(e))
         }
         }
         );
         );
-        E(this, "initDynamicData", (e,t,r)=>new Promise((n,o)=>{
-            this.setDynamicSize(e).then(a=>{
+
+        E(this, "initDynamicData", (dynamicRange,width,height)=>new Promise((resolve,reject)=>{
+            this.setDynamicSize(dynamicRange).then(a=>{
                 if (a) {
                 if (a) {
-                    for (let s = 0; s < e; ++s)
+                    for (let s = 0; s < dynamicRange; ++s)
                         (l=>{
                         (l=>{
-                            this.initDynamicTexture(l, t, r),
+                            this.initDynamicTexture(l, width, height),
                             this.initDynamicShaders(l).then(()=>{
                             this.initDynamicShaders(l).then(()=>{
                                 this._updatePanoShaderInput(l)
                                 this._updatePanoShaderInput(l)
                             }
                             }
                             )
                             )
                         }
                         }
                         )(s);
                         )(s);
-                    n(!0)
+                    resolve(!0)
                 } else
                 } else
-                    o(new XMaterialError(`[Engine] DynamicRoomSize (${e}) is too small`))
+                    reject(new XMaterialError(`[Engine] DynamicRoomSize (${dynamicRange}) is too small`))
             }
             }
             )
             )
         }
         }
         ).catch(n=>logger.error(`[Engine] ${n}`)));
         ).catch(n=>logger.error(`[Engine] ${n}`)));
+        
         E(this, "_initDefaultShader", ()=>{
         E(this, "_initDefaultShader", ()=>{
             this._defaultShader == null && (this._defaultShader = new BABYLON.GridMaterial("GridShader",this.scene),
             this._defaultShader == null && (this._defaultShader = new BABYLON.GridMaterial("GridShader",this.scene),
             this._defaultShader.gridRatio = 50,
             this._defaultShader.gridRatio = 50,
@@ -200,9 +218,11 @@ export default class XMaterialComponent {
     setPanoInfo(e) {
     setPanoInfo(e) {
         this._panoInfo = e
         this._panoInfo = e
     }
     }
-    _prepareRender(e) {
-        e && (this._initPureVideoContent(e),
-        this._updatePureVideoShaderInput())
+    _prepareRender(focal_width_height) {
+        if(focal_width_height){
+            this._initPureVideoContent(focal_width_height)
+            this._updatePureVideoShaderInput()
+        }
     }
     }
     getPureVideoShader() {
     getPureVideoShader() {
         return this._lowModelShader
         return this._lowModelShader
@@ -274,22 +294,103 @@ export default class XMaterialComponent {
         return this._dynamic_shaders[e]
         return this._dynamic_shaders[e]
     }
     }
     _updatePureVideoShaderInput() {
     _updatePureVideoShaderInput() {
+        /*
         var e, t, r, n, o, a, s, l, u, c;
         var e, t, r, n, o, a, s, l, u, c;
-        if (this.scene.getLightByName("AvatarLight") ? ((e = this._lowModelShader) == null || e.setFloat("haveShadowLight", 1),
-        (n = this._lowModelShader) == null || n.setTexture("shadowSampler", (r = (t = this.scene.getLightByName("AvatarLight")) == null ? void 0 : t.getShadowGenerator()) == null ? void 0 : r.getShadowMapForRendering()),
-        (s = this._lowModelShader) == null || s.setMatrix("lightSpaceMatrix", (a = (o = this.scene.getLightByName("AvatarLight")) == null ? void 0 : o.getShadowGenerator()) == null ? void 0 : a.getTransformMatrix())) : ((l = this._lowModelShader) == null || l.setTexture("shadowSampler", this._videoTexture),
-        (u = this._lowModelShader) == null || u.setMatrix("lightSpaceMatrix", new Matrix),
-        (c = this._lowModelShader) == null || c.setFloat("haveShadowLight", 0)),
-        this.scene.getLightByName("fireworkLight"))
-            this.scene.registerBeforeRender(()=>{
-                var h;
-                this._lowModelShader.setFloat("fireworkLight", this.scene.getLightByName("fireworkLight").getScaledIntensity()),
-                this._lowModelShader.setVector3("fireworkLightPosition", (h = this.scene.getLightByName("fireworkLight")) == null ? void 0 : h.position)
+
+        if(this.scene.getLightByName("AvatarLight")){
+            (e = this._lowModelShader) == null || e.setFloat("haveShadowLight", 1);
+
+            n = this._lowModelShader
+            if(n != null){
+                t = this.scene.getLightByName("AvatarLight")
+                if(t == null){
+                    r = void 0
+                }
+                else{
+                    r = t.getShadowGenerator()
+                }
+
+                if(r == null){
+                    n.setTexture("shadowSampler",void 0)
+                }
+                else{
+                    n.setTexture("shadowSampler",r.getShadowMapForRendering())
+                }
             }
             }
-            );
+
+            //(n = this._lowModelShader) == null || n.setTexture("shadowSampler", (r = (t = this.scene.getLightByName("AvatarLight")) == null ? void 0 : t.getShadowGenerator()) == null ? void 0 : r.getShadowMapForRendering());
+
+            s = this._lowModelShader
+            if(s != null){
+                o = this.scene.getLightByName("AvatarLight")
+                if(o == null){
+                    a = void 0
+                }
+                else{
+                    a = o.getShadowGenerator()
+                }
+
+                if(a == null){
+                    s.setMatrix("lightSpaceMatrix",void 0)
+                }
+                else{
+                    s.setMatrix("lightSpaceMatrix",a.getTransformMatrix())
+                }
+            }
+            //(s = this._lowModelShader) == null || s.setMatrix("lightSpaceMatrix", (a = (o = this.scene.getLightByName("AvatarLight")) == null ? void 0 : o.getShadowGenerator()) == null ? void 0 : a.getTransformMatrix())
+        }
+        else{
+            (l = this._lowModelShader) == null || l.setTexture("shadowSampler", this._videoTexture);
+            (u = this._lowModelShader) == null || u.setMatrix("lightSpaceMatrix", new Matrix);
+            (c = this._lowModelShader) == null || c.setFloat("haveShadowLight", 0);
+        }
+        */
+        
+        let lowModelShader = this._lowModelShader
+        if(lowModelShader!= null){
+            if(this.scene.getLightByName("AvatarLight")){
+                lowModelShader.setFloat("haveShadowLight", 1);
+
+                let avatarLight = this.scene.getLightByName("AvatarLight")
+                let shadow = void 0
+                if(avatarLight != null){
+                    shadow = avatarLight.getShadowGenerator()
+                }
+
+                if(shadow == null){
+                    lowModelShader.setTexture("shadowSampler",void 0)
+                    lowModelShader.setMatrix("lightSpaceMatrix",void 0)
+                }
+                else{
+                    lowModelShader.setTexture("shadowSampler",shadow.getShadowMapForRendering())
+                    lowModelShader.setMatrix("lightSpaceMatrix",shadow.getTransformMatrix())
+                }
+            }
+            else{
+                lowModelShader.setTexture("shadowSampler", this._videoTexture);
+                lowModelShader.setMatrix("lightSpaceMatrix", new Matrix);
+                lowModelShader.setFloat("haveShadowLight", 0);
+            }
+        }
+
+        if (this.scene.getLightByName("fireworkLight"))
+        {
+            this.scene.registerBeforeRender(()=>{
+                
+                this._lowModelShader.setFloat("fireworkLight", this.scene.getLightByName("fireworkLight").getScaledIntensity());
+                var fireworkLight = this.scene.getLightByName("fireworkLight")
+                if(fireworkLight == null){
+                    this._lowModelShader.setVector3("fireworkLightPosition",  void 0);
+                }
+                else{
+                    this._lowModelShader.setVector3("fireworkLightPosition",  fireworkLight.position);
+                }
+                //this._lowModelShader.setVector3("fireworkLightPosition", (h = this.scene.getLightByName("fireworkLight")) == null ? void 0 : h.position);
+            });
+        }
         else {
         else {
-            const h = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
-            h.intensity = 0
+            const pointLight = new BABYLON.PointLight("fireworkLight",new BABYLON.Vector3(0,0,0),this.scene);
+            pointLight.intensity = 0
         }
         }
     }
     }
     _updatePanoShaderInput(e) {
     _updatePanoShaderInput(e) {

+ 3 - 2
src/XVideoRawYUV.js

@@ -22,10 +22,11 @@ export default class XVideoRawYUV {
     getVideoYUVTex(e) {
     getVideoYUVTex(e) {
         return this.inRange(e) ? this._videoRawYUVTexture[e] : null
         return this.inRange(e) ? this._videoRawYUVTexture[e] : null
     }
     }
-    findId(e, t) {
+
+    findId(width, height) {
         let r = 0;
         let r = 0;
         for (let n = 0; n < this.videosResOriArray.length; ++n)
         for (let n = 0; n < this.videosResOriArray.length; ++n)
-            if (this.videosResOriArray[n].width == e && this.videosResOriArray[n].height == t) {
+            if (this.videosResOriArray[n].width == width && this.videosResOriArray[n].height == height) {
                 r = n;
                 r = n;
                 break
                 break
             }
             }

File diff suppressed because it is too large
+ 77 - 74
src/Xverse_Room.js