zhouenguang 3 年之前
父節點
當前提交
c99f63afdb
共有 7 個文件被更改,包括 2593 次插入111 次删除
  1. 1 1
      dist/assets/config.json
  2. 2466 0
      dist/assets/config0.json
  3. 二進制
      dist/assets/level_L01.glb
  4. 34 31
      src/EngineProxy.js
  5. 5 4
      src/XSceneManager.js
  6. 69 54
      src/XStaticMeshComponent.js
  7. 18 21
      src/XStaticMeshFromOneGltf.js

+ 1 - 1
dist/assets/config.json

@@ -495,7 +495,7 @@
                             "className": "粗模",
                             "assetId": "",
                             "name": "ground_LQC_xverse.glb",
-                            "url": "https://app-mgt-resource-1258211750.file.myqcloud.com/model/65c92d17c07b4a92a3d4f1a9afc8f9af/ground_LQC_xverse.glb",
+                            "url": "../assets/level_L01.glb",
                             "thumbnailUrl": ""
                         },
                         {

File diff suppressed because it is too large
+ 2466 - 0
dist/assets/config0.json


二進制
dist/assets/level_L01.glb


+ 34 - 31
src/EngineProxy.js

@@ -110,12 +110,13 @@ export default class EngineProxy{
     _setFPS(sceneManager, fps=25) {
         logger.info("Set fps to", fps);
         const protectFps = fps > 60 ? 60 : fps < 24 ? 24 : fps;
-        sceneManager.Engine.stopRenderLoop();
         const mspf = 1e3 / protectFps; //毫秒每帧
         let o = Date.now()
             , a = Date.now()
             , lastGap = mspf
             , ratio = 1;
+        
+        sceneManager.Engine.stopRenderLoop();
 
         const updatePerGap = ()=>{
             const c = Date.now()
@@ -137,42 +138,43 @@ export default class EngineProxy{
                 {
                     this._checkSceneFrameCount++,
                     this.room.sceneManager.isReadyToRender({}) && this._checkSceneDurationFrameNum--,
-                    this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && (this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION,
-                    this._checkSceneFrameCount = 0,
-                    this._checkSceneNotReadyCount++,
-
+                    this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && 
                     (
-                        this._checkSceneNotReadyCount == 1 || 
-                        this._checkSceneNotReadyCount % 100 == 0
-                    ) && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`),
+                        this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION,
+                        this._checkSceneFrameCount = 0,
+                        
+                        this._checkSceneNotReadyCount++,
+                        (this._checkSceneNotReadyCount == 1 || this._checkSceneNotReadyCount % 100 == 0) 
+                            && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`),
+
+                        this._checkSceneNotReadyCount > 10 && (
+                            logger.error("[SDK] Scene not ready, reload later"),
+                            this.room.proxyEvents("renderError", {
+                                error: new Error("[SDK] Scene not ready, skip render and reload.")
+                            })
+                        ),
 
-                    this._checkSceneNotReadyCount > 10 && (
-                        logger.error("[SDK] Scene not ready, reload later"),
-                        this.room.proxyEvents("renderError", {
-                            error: new Error("[SDK] Scene not ready, skip render and reload.")
+                        this.room.stats.assign({
+                            renderErrorCount: this._checkSceneNotReadyCount
+                        }),
+
+                        logger.infoAndReportMeasurement({
+                            value: 0,
+                            startTime: Date.now(),
+                            metric: "renderError",
+                            error: new Error("[SDK] Scene not ready, skip render and reload."),
+                            reportOptions: {
+                                sampleRate: .1
+                            }
                         })
-                    ),
-                    this.room.stats.assign({
-                        renderErrorCount: this._checkSceneNotReadyCount
-                    }),
-                    logger.infoAndReportMeasurement({
-                        value: 0,
-                        startTime: Date.now(),
-                        metric: "renderError",
-                        error: new Error("[SDK] Scene not ready, skip render and reload."),
-                        reportOptions: {
-                            sampleRate: .1
-                        }
-                    }));
+                    );
                 } else {
                     try {
                         sceneManager.render()
                     } 
-                    catch (e) {
+                    catch (error) {
                         this.renderErrorCount++,
-                        this.renderErrorCount > 10 && this.room.proxyEvents("renderError", {
-                            error: e
-                        }),
+                        this.renderErrorCount > 10 && this.room.proxyEvents("renderError", { error }),
                         this.room.stats.assign({
                             renderErrorCount: this.renderErrorCount
                         }),
@@ -180,7 +182,7 @@ export default class EngineProxy{
                             value: 0,
                             startTime: Date.now(),
                             metric: "renderError",
-                            error: e,
+                            error,
                             reportOptions: {
                                 sampleRate: .1
                             }
@@ -272,7 +274,8 @@ export default class EngineProxy{
         };
         const resolution = this.room.options.resolution;
         if(resolution){
-            videoPanoInfo.videoResOriArray.some(l=>l.width === resolution.width && l.height === resolution.height) || videoPanoInfo.videoResOriArray.push(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");

+ 5 - 4
src/XSceneManager.js

@@ -436,12 +436,13 @@ export default class XSceneManager {
           , r = [];
         return t.forEach(n=>{
             n.mesh.name.indexOf("SM_Stage") >= 0 && r.push(n.mesh)
-        }
-        ),
+        }),
+        t.forEach(n=>{
+            n.mesh.name.indexOf("Level _L01") >= 0 && r.push(n.mesh)
+        }),
         this.Scene.meshes.forEach(n=>{
             n.name.split("_")[0] === "ground" && r.push(n)
-        }
-        ),
+        }),
         r
     }
 }

+ 69 - 54
src/XStaticMeshComponent.js

@@ -34,9 +34,11 @@ export default class XStaticMeshComponent{
         E(this, "_visCheckDurationFrameNumber");
         E(this, "_regionLodRule");
         E(this, "reg_staticmesh_partupdate", ()=>{
-            if (this._allowRegionUpdate && (this.scene.getFrameId(),
-            this._meshUpdateFrame()),
-            this._allowRegionForceLod) {
+            this._allowRegionUpdate && (
+                this.scene.getFrameId(),
+                this._meshUpdateFrame()
+            )
+            if (this._allowRegionForceLod) {
                 this.scene.getFrameId() % 2 == 0 && this.setOneRegionLod(this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length].toString(), this._forceLod);
                 let t = !0;
                 const r = Array.from(this._currentMeshUsedLod.keys());
@@ -46,19 +48,18 @@ export default class XStaticMeshComponent{
                     t && (this._allowRegionForceLod = !1)
                 }
             }
-        }
-        );
+        });
         E(this, "setMeshInfo", (e,t="")=>{
-            this._abosoluteUrl != e && (this._abosoluteUrl.length > 0 && this.deleteLastRegionMesh(),
-            this._partMeshSkinInfo = t,
-            this._abosoluteUrl = e,
-            this._rootDir = this._abosoluteUrl.slice(0, -4) + "/",
-            this.parseJson(this._rootDir + "meshInfo.json").then(()=>{
-                this.startMeshUpdate()
-            }
-            ))
-        }
-        );
+            this._abosoluteUrl != e && (
+                this._abosoluteUrl.length > 0 && this.deleteLastRegionMesh(),
+                this._partMeshSkinInfo = t,
+                this._abosoluteUrl = e,
+                this._rootDir = this._abosoluteUrl.slice(0, -4) + "/",
+                this.parseJson(this._rootDir + "meshInfo.json").then(()=>{
+                    this.startMeshUpdate()
+                })
+            )
+        });
         E(this, "_meshUpdateFrame", ()=>{
             {
                 let e = this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length];
@@ -167,61 +168,75 @@ export default class XStaticMeshComponent{
             return !0
         }
         );
-        E(this, "addNewLowPolyMesh", (e,t,r)=>{
-            if (!e.url.endsWith("glb") && !e.url.startsWith("blob:"))
-                return e.url.endsWith("zip") ? (this.setMeshInfo(e.url, e.skinInfo),
-                Promise.resolve(!0)) : (logger.error("[Engine] input model path is error! ", e.url),
-                Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + e.url)));
+        E(this, "addNewLowPolyMesh", (modelInfo, t, pureVideoShader)=>{
+            // 加载房间的glb模型
+
+            if (!modelInfo.url.endsWith("glb") && !modelInfo.url.startsWith("blob:")) {
+                return modelInfo.url.endsWith("zip") ? (
+                    this.setMeshInfo(modelInfo.url, modelInfo.skinInfo),
+                    Promise.resolve(!0)
+                ) : (
+                    logger.error("[Engine] input model path is error! ", modelInfo.url),
+                    Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + modelInfo.url))
+                );
+            }
+
             {
-                const n = e.url;
-                return new Promise((o,a)=>this._scenemanager.urlTransformer(e.url).then(s=>{
-                    e.url = s;
-                    const l = new XStaticMeshFromOneGltf(this.scene,e)
-                      , u = Date.now();
-                    return new Promise((c,h)=>{
-                        l.loadMesh(r, !0).then(f=>{
-                            const d = Date.now();
-                            if (this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(d - u),
-                            f == !0) {
-                                const _ = this.getLowModelType(e);
+                const fileUrl = modelInfo.url;
+                return new Promise((o, a)=>this._scenemanager.urlTransformer(modelInfo.url).then(blobUrl=>{
+                    modelInfo.url = blobUrl;
+                    const l = new XStaticMeshFromOneGltf(this.scene, modelInfo)
+                      , time0 = Date.now();
+
+                    return new Promise((c, h)=>{
+                        l.loadMesh(pureVideoShader, !0).then(f => {
+                            const time1 = Date.now();
+                            this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(time1 - time0)
+                            if (f == !0) {
+                                const modelType = this.getLowModelType(modelInfo);
                                 let g = 0;
-                                if (this._lowModel_group.has(_) && (g = this._lowModel_group.get(_).length),
-                                r != null && this._scenemanager.currentShader != null && this._scenemanager.currentShader.name != r.name && l.setMaterial(this._scenemanager.currentShader),
-                                this._allowRegionUpdate == !1 && _.startsWith("region_"))
+                                this._lowModel_group.has(modelType) && (g = this._lowModel_group.get(modelType).length)
+
+                                pureVideoShader && this._scenemanager.currentShader 
+                                && this._scenemanager.currentShader.name != pureVideoShader.name 
+                                && l.setMaterial(this._scenemanager.currentShader)
+
+                                if (this._allowRegionUpdate == !1 && modelType.startsWith("region_"))
                                     l.dispose();
-                                else if (this._staticmeshes.push(l),
-                                this.lowmodelGroupMapAddValue(_, l),
-                                t != null && t.length > 0) {
+                                else if (
+                                    this._staticmeshes.push(l),
+                                    this.lowmodelGroupMapAddValue(modelType, l),
+                                    t && t.length > 0
+                                ) {
                                     const m = [];
                                     for (let v = 0; v < t.length; ++v)
                                         m.push(t[v].group),
-                                        this.updateLowModelGroup(t[v], _, g)
+                                        this.updateLowModelGroup(t[v], modelType, g)
                                 }
-                                this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - d),
+                                this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - time1),
                                 c(!0)
                             } else
                                 h(new XLowpolyModelError("[Engine] after lowmodel error!"))
                         }
-                        ).catch(f=>{
-                            logger.error("[Engine] load Mesh [" + n + "] error! " + f),
-                            h(new XLowpolyModelError(`[Engine] load Mesh [${n}] error! ${f}`))
-                        }
-                        )
-                    }
-                    )
+                        ).catch(e=>{
+                            logger.error("[Engine] load Mesh [" + fileUrl + "] error! " + e),
+                            h(new XLowpolyModelError(`[Engine] load Mesh [${fileUrl}] error! ${e}`))
+                        })
+                    })
                 }
                 ).then(s=>{
-                    s == !0 ? (logger.info(`[Engine] load Mesh [${n}] successfully.`),
-                    o(!0)) : a(!1)
+                    s == !0 ? (
+                        logger.info(`[Engine] load Mesh [${fileUrl}] successfully.`),
+                        o(!0)
+                    ) : a(!1)
                 }
                 ).catch(s=>{
-                    logger.error("[Engine] addNewLowPolyMesh [" + n + "] error! " + s),
-                    a(new XLowpolyModelError(`[Engine] addNewLowPolyMesh [${n}] error! ${s}`))
-                }
-                ))
+                    logger.error("[Engine] addNewLowPolyMesh [" + fileUrl + "] error! " + s),
+                    a(new XLowpolyModelError(`[Engine] addNewLowPolyMesh [${fileUrl}] error! ${s}`))
+                }))
             }
-        }
-        );
+        });
+
         E(this, "toggleLowModelVisibility", e=>{
             const {vis: t, groupName: r="", skinInfo: n=""} = e;
             this._meshVis = t,

+ 18 - 21
src/XStaticMeshFromOneGltf.js

@@ -17,52 +17,49 @@ export default class XStaticMeshFromOneGltf {
         E(this, "_groupUuid");
         E(this, "_isInScene");
         E(this, "_skinInfo");
-        E(this, "loadMesh", (e,t)=>{
+        E(this, "loadMesh", (pureVideoShader, t)=>{
             const r = this._meshes.length
               , n = t ? 1 : 0
               , o = this._url;
             return BABYLON.SceneLoader.LoadAssetContainerAsync("", o, this._scene, ()=>{
                 this._scene.blockMaterialDirtyMechanism = !0
-            }
-            , ".glb").then(a=>{
+            }, ".glb").then(a=>{
                 for (let s = a.materials.length - 1; s >= 0; --s)
                     a.materials[s].dispose();
                 this._scene.blockMaterialDirtyMechanism = !0;
                 for (let s = 0; s < a.meshes.length; ++s) {
-                    const l = a.meshes[s];
-                    if ("instances"in l) {
-                        "visibility"in l && (l.visibility = 0),
-                        "isPickable"in l && (l.isPickable = this._pickable),
-                        e != null && (l.material = e),
-                        "hasVertexAlpha"in l && (l.hasVertexAlpha = !1);
-                        const u = new XStaticMesh({
+                    const mesh = a.meshes[s];
+                    if ("instances"in mesh) {
+                        "visibility"in mesh && (mesh.visibility = 0);
+                        "isPickable"in mesh && (mesh.isPickable = this._pickable);
+                        pureVideoShader && (mesh.material = pureVideoShader);
+                        "hasVertexAlpha"in mesh && (mesh.hasVertexAlpha = !1);
+                        const xMesh = new XStaticMesh({
                             id: this._groupUuid + "-" + Math.random().toString(36).substr(2, 5),
-                            mesh: l,
+                            mesh,
                             lod: this._lod,
                             group: this._group,
                             url: this._url,
                             xtype: EMeshType.XStaticMesh,
                             skinInfo: this._skinInfo
                         });
-                        this._meshes.push(u)
+                        // 房间模型初始180度矫正
+                        xMesh.setRotation({pitch: 0, roll:0, yaw:180})
+                        this._meshes.push(xMesh);
                     }
-                    this._scene.addMesh(l)
+                    this._scene.addMesh(mesh);
                 }
                 return !0
-            }
-            ).then(()=>{
+            }).then(()=>{
                 this._isInScene = !0;
                 for (let a = r; a < this._meshes.length; ++a)
                     this._meshes[a].mesh.visibility = n;
                 return Promise.resolve(!0)
-            }
-            ).catch(a=>{
+            }).catch(a=>{
                 logger.error("[Engine] input gltf mesh uri error! " + a),
                 Promise.reject(new XLowpolyModelError("[Engine] input gltf mesh uri error! " + a))
-            }
-            )
-        }
-        );
+            })
+        });
         this._meshes = [],
         this._scene = e,
         this._url = t.url,