|
@@ -6,286 +6,11 @@ import Logger from "./Logger.js"
|
|
|
|
|
|
const logger = new Logger('XStaticMeshComponent')
|
|
|
export default class XStaticMeshComponent{
|
|
|
- constructor(e) {
|
|
|
- E(this, "scene");
|
|
|
- E(this, "_staticmeshes");
|
|
|
- E(this, "_lowModel_group");
|
|
|
- E(this, "_CgPlane");
|
|
|
- E(this, "_rootDir");
|
|
|
- E(this, "_abosoluteUrl");
|
|
|
- E(this, "_partMeshSkinInfo");
|
|
|
- E(this, "_meshInfoJson");
|
|
|
- E(this, "_orijson");
|
|
|
- E(this, "_notUsedRegionLists");
|
|
|
- E(this, "_meshInfoKeys");
|
|
|
- E(this, "_currentUpdateRegionCount");
|
|
|
- E(this, "_currentMeshUsedLod");
|
|
|
- E(this, "_currentPartGroup");
|
|
|
- E(this, "_allowRegionUpdate");
|
|
|
- E(this, "_allowRegionForceLod");
|
|
|
- E(this, "_forceLod");
|
|
|
- E(this, "_scenemanager");
|
|
|
- E(this, "regionIdInCamera");
|
|
|
- E(this, "regionIdInCameraConst");
|
|
|
- E(this, "_cameraInRegionId");
|
|
|
- E(this, "_meshVis");
|
|
|
- E(this, "_doMeshVisChangeNumber");
|
|
|
- E(this, "_meshVisTypeName");
|
|
|
- E(this, "_visCheckDurationFrameNumber");
|
|
|
- E(this, "_regionLodRule");
|
|
|
- E(this, "reg_staticmesh_partupdate", ()=>{
|
|
|
- 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());
|
|
|
- if (r.length > 0) {
|
|
|
- for (let n = 0; n < r.length; ++n)
|
|
|
- this._currentMeshUsedLod.get(r[n]) != this._forceLod && (t = !1);
|
|
|
- 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()
|
|
|
- })
|
|
|
- )
|
|
|
- });
|
|
|
- E(this, "_meshUpdateFrame", ()=>{
|
|
|
- {
|
|
|
- let e = this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length];
|
|
|
- const t = !0;
|
|
|
- let r = 3;
|
|
|
- if (this._scenemanager != null && this._scenemanager.cameraComponent != null) {
|
|
|
- const n = this._getMainPlayerPosition();
|
|
|
- if (n != null) {
|
|
|
- if (this._cameraInRegionId >= 0) {
|
|
|
- const a = this.getRegionIdWhichIncludeCamera(n);
|
|
|
- (this._cameraInRegionId != a || this.regionIdInCamera.length == 0) && (this._cameraInRegionId = a,
|
|
|
- this.regionIdInCamera = this._getNeighborId(this._cameraInRegionId.toString()),
|
|
|
- this.regionIdInCameraConst = this.regionIdInCamera.slice());
|
|
|
- let s = this.regionIdInCamera.pop();
|
|
|
- for (; s != null; )
|
|
|
- if (this._notUsedRegionLists.indexOf(s) >= 0)
|
|
|
- s = this.regionIdInCamera.pop();
|
|
|
- else
|
|
|
- break;
|
|
|
- s != null && (e = s.toString())
|
|
|
- } else
|
|
|
- this._cameraInRegionId = this.getRegionIdWhichIncludeCamera(n);
|
|
|
- if (this._currentMeshUsedLod.size == 0 || this._notUsedRegionLists.indexOf(parseInt(e)) >= 0) {
|
|
|
- e = this._cameraInRegionId.toString();
|
|
|
- const a = this._getNeighborId(e);
|
|
|
- for (; a.length == 0 && (e = this.getNearestRegionIdWithCamera(n).toString()),
|
|
|
- this._notUsedRegionLists.indexOf(parseInt(e)) >= 0; )
|
|
|
- e = a.pop().toString()
|
|
|
- }
|
|
|
- const o = this._meshInfoJson[this._cameraInRegionId.toString()].lod;
|
|
|
- r = 3,
|
|
|
- this._cameraInRegionId.toString() == e ? r = this._regionLodRule[0] : o[0].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[1] : o[1].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[2] : o[2].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[3] : r = this._regionLodRule[4]
|
|
|
- }
|
|
|
- }
|
|
|
- this.setOneRegionLod(e, r, t),
|
|
|
- this.updateRegionNotInLocalNeighbor(),
|
|
|
- this.cleanRootNodes()
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "updateRegionNotInLocalNeighbor", ()=>{
|
|
|
- Array.from(this._currentMeshUsedLod.keys()).forEach(t=>{
|
|
|
- this.regionIdInCameraConst.indexOf(parseInt(t)) < 0 && this.setOneRegionLod(t, -1)
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "cleanRootNodes", ()=>{
|
|
|
- if (this.scene.getFrameId() % 3 == 0) {
|
|
|
- const e = [];
|
|
|
- this.scene.rootNodes.forEach(t=>{
|
|
|
- (t.getClassName() == "TransformNode" && t.getChildren().length == 0 || t.getClassName() == "Mesh" && t.name == "__root__" && t.getChildren().length == 0) && e.push(t)
|
|
|
- }
|
|
|
- ),
|
|
|
- e.forEach(t=>{
|
|
|
- t.dispose()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "setOneRegionLod", (e,t,r=!0)=>{
|
|
|
- this._currentUpdateRegionCount++;
|
|
|
- const n = this._calHashCode(this._rootDir)
|
|
|
- , o = "region_" + n + "_" + e;
|
|
|
- if (t < 0) {
|
|
|
- this._currentMeshUsedLod.has(e) && (this._currentMeshUsedLod.delete(e),
|
|
|
- this._currentPartGroup.delete(o),
|
|
|
- this.deleteMeshesByCustomProperty("group", "region_" + n + "_" + e));
|
|
|
- return
|
|
|
- }
|
|
|
- const a = this._rootDir + e + "_lod" + t + "_xverse.glb"
|
|
|
- , s = this._currentMeshUsedLod.get(e);
|
|
|
- this._currentPartGroup.add(o),
|
|
|
- s != null ? s != t && (this._currentMeshUsedLod.set(e, t),
|
|
|
- this._scenemanager.addNewLowPolyMesh({
|
|
|
- url: a,
|
|
|
- group: "region_" + n + "_" + e,
|
|
|
- pick: !0,
|
|
|
- lod: t,
|
|
|
- skinInfo: this._partMeshSkinInfo
|
|
|
- }, [{
|
|
|
- group: "region_" + n + "_" + e,
|
|
|
- mode: 0
|
|
|
- }])) : (this._currentMeshUsedLod.set(e, t),
|
|
|
- this._scenemanager.addNewLowPolyMesh({
|
|
|
- url: a,
|
|
|
- group: "region_" + n + "_" + e,
|
|
|
- pick: !0,
|
|
|
- lod: t,
|
|
|
- skinInfo: this._partMeshSkinInfo
|
|
|
- }))
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "checkPointInView", ({x: e, y: t, z: r})=>{
|
|
|
- const n = ue4Position2Xverse({
|
|
|
- x: e,
|
|
|
- y: t,
|
|
|
- z: r
|
|
|
- });
|
|
|
- if (!n)
|
|
|
- return !1;
|
|
|
- for (let o = 0; o < 6; o++)
|
|
|
- if (this.scene.frustumPlanes[o].dotCoordinate(n) < 0)
|
|
|
- return !1;
|
|
|
- return !0
|
|
|
- }
|
|
|
- );
|
|
|
- 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))
|
|
|
- );
|
|
|
- }
|
|
|
+ constructor(scenemanager) {
|
|
|
+ this._CgPlane
|
|
|
+ this._orijson
|
|
|
+ this._notUsedRegionLists
|
|
|
|
|
|
- {
|
|
|
- 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;
|
|
|
- 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(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], modelType, g)
|
|
|
- }
|
|
|
- this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - time1),
|
|
|
- c(!0)
|
|
|
- } else
|
|
|
- h(new XLowpolyModelError("[Engine] after lowmodel error!"))
|
|
|
- }
|
|
|
- ).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 [${fileUrl}] successfully.`),
|
|
|
- o(!0)
|
|
|
- ) : a(!1)
|
|
|
- }
|
|
|
- ).catch(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,
|
|
|
- this._meshVisTypeName = {
|
|
|
- groupName: r,
|
|
|
- skinInfo: n
|
|
|
- },
|
|
|
- this._doMeshVisChangeNumber = 0,
|
|
|
- r == Te.ALL_MESHES || this._currentPartGroup.has(r) == !0 || this._partMeshSkinInfo == n ? t == !1 ? (this._visCheckDurationFrameNumber = 100,
|
|
|
- this.stopMeshUpdate()) : (this._visCheckDurationFrameNumber = 1,
|
|
|
- this.startMeshUpdate()) : this._visCheckDurationFrameNumber = 1
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "reg_staticmesh_visibility", ()=>{
|
|
|
- if (this._doMeshVisChangeNumber >= 0)
|
|
|
- if (this._doMeshVisChangeNumber < this._visCheckDurationFrameNumber)
|
|
|
- if (this._doMeshVisChangeNumber = this._doMeshVisChangeNumber + 1,
|
|
|
- this._meshVisTypeName.groupName == Te.ALL_MESHES)
|
|
|
- this._lowModel_group.forEach((e,t)=>{
|
|
|
- for (let r = 0, n = e.length; r < n; ++r)
|
|
|
- e[r].toggleVisibility(this._meshVis)
|
|
|
- }
|
|
|
- );
|
|
|
- else {
|
|
|
- if (this._lowModel_group.has(this._meshVisTypeName.groupName))
|
|
|
- for (let e = 0; e < this._lowModel_group.get(this._meshVisTypeName.groupName).length; ++e)
|
|
|
- this._lowModel_group.get(this._meshVisTypeName.groupName)[e].toggleVisibility(this._meshVis);
|
|
|
- if (this._meshVisTypeName.skinInfo != "")
|
|
|
- for (let e = 0; e < this._staticmeshes.length; ++e)
|
|
|
- this._staticmeshes[e].skinInfo == this._meshVisTypeName.skinInfo && this._staticmeshes[e].toggleVisibility(this._meshVis)
|
|
|
- }
|
|
|
- else
|
|
|
- this._meshVis = !0,
|
|
|
- this._meshVisTypeName = {
|
|
|
- groupName: "",
|
|
|
- skinInfo: ""
|
|
|
- },
|
|
|
- this._doMeshVisChangeNumber = -1
|
|
|
- }
|
|
|
- );
|
|
|
- E(this, "_getMeshesByCustomProperty", (e,t)=>{
|
|
|
- let r = [];
|
|
|
- return this._staticmeshes.forEach(n=>{
|
|
|
- n[e] != null && n[e] == t && (r = r.concat(n.meshes))
|
|
|
- }
|
|
|
- ),
|
|
|
- r
|
|
|
- }
|
|
|
- );
|
|
|
this._lowModel_group = new Map,
|
|
|
this._staticmeshes = [],
|
|
|
this._meshInfoJson = null,
|
|
@@ -298,8 +23,8 @@ export default class XStaticMeshComponent{
|
|
|
this._allowRegionForceLod = !1,
|
|
|
this._currentMeshUsedLod = new Map,
|
|
|
this._currentPartGroup = new Set,
|
|
|
- this._scenemanager = e,
|
|
|
- this.scene = e.Scene,
|
|
|
+ this._scenemanager = scenemanager,
|
|
|
+ this.scene = scenemanager.Scene,
|
|
|
this.regionIdInCamera = [],
|
|
|
this.regionIdInCameraConst = [],
|
|
|
this._cameraInRegionId = -1,
|
|
@@ -315,6 +40,261 @@ export default class XStaticMeshComponent{
|
|
|
this.initCgLowModel(),
|
|
|
this._regionPartLoop()
|
|
|
}
|
|
|
+
|
|
|
+ reg_staticmesh_partupdate() {
|
|
|
+ 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());
|
|
|
+ if (r.length > 0) {
|
|
|
+ for (let n = 0; n < r.length; ++n)
|
|
|
+ this._currentMeshUsedLod.get(r[n]) != this._forceLod && (t = !1);
|
|
|
+ t && (this._allowRegionForceLod = !1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()
|
|
|
+ })
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ _meshUpdateFrame() {
|
|
|
+ {
|
|
|
+ let e = this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length];
|
|
|
+ const t = !0;
|
|
|
+ let r = 3;
|
|
|
+ if (this._scenemanager != null && this._scenemanager.cameraComponent != null) {
|
|
|
+ const n = this._getMainPlayerPosition();
|
|
|
+ if (n != null) {
|
|
|
+ if (this._cameraInRegionId >= 0) {
|
|
|
+ const a = this.getRegionIdWhichIncludeCamera(n);
|
|
|
+ (this._cameraInRegionId != a || this.regionIdInCamera.length == 0) && (this._cameraInRegionId = a,
|
|
|
+ this.regionIdInCamera = this._getNeighborId(this._cameraInRegionId.toString()),
|
|
|
+ this.regionIdInCameraConst = this.regionIdInCamera.slice());
|
|
|
+ let s = this.regionIdInCamera.pop();
|
|
|
+ for (; s != null; )
|
|
|
+ if (this._notUsedRegionLists.indexOf(s) >= 0)
|
|
|
+ s = this.regionIdInCamera.pop();
|
|
|
+ else
|
|
|
+ break;
|
|
|
+ s != null && (e = s.toString())
|
|
|
+ } else
|
|
|
+ this._cameraInRegionId = this.getRegionIdWhichIncludeCamera(n);
|
|
|
+ if (this._currentMeshUsedLod.size == 0 || this._notUsedRegionLists.indexOf(parseInt(e)) >= 0) {
|
|
|
+ e = this._cameraInRegionId.toString();
|
|
|
+ const a = this._getNeighborId(e);
|
|
|
+ for (; a.length == 0 && (e = this.getNearestRegionIdWithCamera(n).toString()),
|
|
|
+ this._notUsedRegionLists.indexOf(parseInt(e)) >= 0; )
|
|
|
+ e = a.pop().toString()
|
|
|
+ }
|
|
|
+ const o = this._meshInfoJson[this._cameraInRegionId.toString()].lod;
|
|
|
+ r = 3,
|
|
|
+ this._cameraInRegionId.toString() == e ? r = this._regionLodRule[0] : o[0].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[1] : o[1].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[2] : o[2].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[3] : r = this._regionLodRule[4]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setOneRegionLod(e, r, t),
|
|
|
+ this.updateRegionNotInLocalNeighbor(),
|
|
|
+ this.cleanRootNodes()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateRegionNotInLocalNeighbor() {
|
|
|
+ Array.from(this._currentMeshUsedLod.keys()).forEach(t=>{
|
|
|
+ this.regionIdInCameraConst.indexOf(parseInt(t)) < 0 && this.setOneRegionLod(t, -1)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ cleanRootNodes() {
|
|
|
+ if (this.scene.getFrameId() % 3 == 0) {
|
|
|
+ const e = [];
|
|
|
+ this.scene.rootNodes.forEach(t=>{
|
|
|
+ (t.getClassName() == "TransformNode" && t.getChildren().length == 0 || t.getClassName() == "Mesh" && t.name == "__root__" && t.getChildren().length == 0) && e.push(t)
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ e.forEach(t=>{
|
|
|
+ t.dispose()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setOneRegionLod(e,t,r=!0) {
|
|
|
+ this._currentUpdateRegionCount++;
|
|
|
+ const n = this._calHashCode(this._rootDir)
|
|
|
+ , o = "region_" + n + "_" + e;
|
|
|
+ if (t < 0) {
|
|
|
+ this._currentMeshUsedLod.has(e) && (this._currentMeshUsedLod.delete(e),
|
|
|
+ this._currentPartGroup.delete(o),
|
|
|
+ this.deleteMeshesByCustomProperty("group", "region_" + n + "_" + e));
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const a = this._rootDir + e + "_lod" + t + "_xverse.glb"
|
|
|
+ , s = this._currentMeshUsedLod.get(e);
|
|
|
+ this._currentPartGroup.add(o),
|
|
|
+ s != null ? s != t && (this._currentMeshUsedLod.set(e, t),
|
|
|
+ this._scenemanager.addNewLowPolyMesh({
|
|
|
+ url: a,
|
|
|
+ group: "region_" + n + "_" + e,
|
|
|
+ pick: !0,
|
|
|
+ lod: t,
|
|
|
+ skinInfo: this._partMeshSkinInfo
|
|
|
+ }, [{
|
|
|
+ group: "region_" + n + "_" + e,
|
|
|
+ mode: 0
|
|
|
+ }])) : (this._currentMeshUsedLod.set(e, t),
|
|
|
+ this._scenemanager.addNewLowPolyMesh({
|
|
|
+ url: a,
|
|
|
+ group: "region_" + n + "_" + e,
|
|
|
+ pick: !0,
|
|
|
+ lod: t,
|
|
|
+ skinInfo: this._partMeshSkinInfo
|
|
|
+ }))
|
|
|
+ }
|
|
|
+
|
|
|
+ checkPointInView({x: e, y: t, z: r}) {
|
|
|
+ const n = ue4Position2Xverse({
|
|
|
+ x: e,
|
|
|
+ y: t,
|
|
|
+ z: r
|
|
|
+ });
|
|
|
+ if (!n)
|
|
|
+ return !1;
|
|
|
+ for (let o = 0; o < 6; o++)
|
|
|
+ if (this.scene.frustumPlanes[o].dotCoordinate(n) < 0)
|
|
|
+ return !1;
|
|
|
+ return !0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载房间的glb模型
|
|
|
+ addNewLowPolyMesh(modelInfo, t, pureVideoShader) {
|
|
|
+
|
|
|
+ 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 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;
|
|
|
+ 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(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], modelType, g)
|
|
|
+ }
|
|
|
+ this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - time1),
|
|
|
+ c(!0)
|
|
|
+ } else
|
|
|
+ h(new XLowpolyModelError("[Engine] after lowmodel error!"))
|
|
|
+ }
|
|
|
+ ).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 [${fileUrl}] successfully.`),
|
|
|
+ o(!0)
|
|
|
+ ) : a(!1)
|
|
|
+ }
|
|
|
+ ).catch(s=>{
|
|
|
+ logger.error("[Engine] addNewLowPolyMesh [" + fileUrl + "] error! " + s),
|
|
|
+ a(new XLowpolyModelError(`[Engine] addNewLowPolyMesh [${fileUrl}] error! ${s}`))
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ toggleLowModelVisibility(e) {
|
|
|
+ const {vis: t, groupName: r="", skinInfo: n=""} = e;
|
|
|
+ this._meshVis = t,
|
|
|
+ this._meshVisTypeName = {
|
|
|
+ groupName: r,
|
|
|
+ skinInfo: n
|
|
|
+ },
|
|
|
+ this._doMeshVisChangeNumber = 0,
|
|
|
+ r == Te.ALL_MESHES || this._currentPartGroup.has(r) == !0 || this._partMeshSkinInfo == n ? t == !1 ? (this._visCheckDurationFrameNumber = 100,
|
|
|
+ this.stopMeshUpdate()) : (this._visCheckDurationFrameNumber = 1,
|
|
|
+ this.startMeshUpdate()) : this._visCheckDurationFrameNumber = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ reg_staticmesh_visibility() {
|
|
|
+ if (this._doMeshVisChangeNumber >= 0)
|
|
|
+ if (this._doMeshVisChangeNumber < this._visCheckDurationFrameNumber)
|
|
|
+ if (this._doMeshVisChangeNumber = this._doMeshVisChangeNumber + 1,
|
|
|
+ this._meshVisTypeName.groupName == Te.ALL_MESHES)
|
|
|
+ this._lowModel_group.forEach((e,t)=>{
|
|
|
+ for (let r = 0, n = e.length; r < n; ++r)
|
|
|
+ e[r].toggleVisibility(this._meshVis)
|
|
|
+ }
|
|
|
+ );
|
|
|
+ else {
|
|
|
+ if (this._lowModel_group.has(this._meshVisTypeName.groupName))
|
|
|
+ for (let e = 0; e < this._lowModel_group.get(this._meshVisTypeName.groupName).length; ++e)
|
|
|
+ this._lowModel_group.get(this._meshVisTypeName.groupName)[e].toggleVisibility(this._meshVis);
|
|
|
+ if (this._meshVisTypeName.skinInfo != "")
|
|
|
+ for (let e = 0; e < this._staticmeshes.length; ++e)
|
|
|
+ this._staticmeshes[e].skinInfo == this._meshVisTypeName.skinInfo && this._staticmeshes[e].toggleVisibility(this._meshVis)
|
|
|
+ }
|
|
|
+ else
|
|
|
+ this._meshVis = !0,
|
|
|
+ this._meshVisTypeName = {
|
|
|
+ groupName: "",
|
|
|
+ skinInfo: ""
|
|
|
+ },
|
|
|
+ this._doMeshVisChangeNumber = -1
|
|
|
+ }
|
|
|
+
|
|
|
+ _getMeshesByCustomProperty(e,t) {
|
|
|
+ let r = [];
|
|
|
+ return this._staticmeshes.forEach(n=>{
|
|
|
+ n[e] != null && n[e] == t && (r = r.concat(n.meshes))
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ r
|
|
|
+ }
|
|
|
+
|
|
|
get cameraInRegionId() {
|
|
|
return this._cameraInRegionId
|
|
|
}
|