|
@@ -5,13 +5,247 @@ import XLowpolyModelError from "./error/XLowpolyModelError.js"
|
|
|
import Logger from "./Logger.js"
|
|
import Logger from "./Logger.js"
|
|
|
import XLowpolyJsonError from "./Error/XLowpolyJsonError.js"
|
|
import XLowpolyJsonError from "./Error/XLowpolyJsonError.js"
|
|
|
|
|
|
|
|
-const logger = new Logger('StaticMeshComponent')
|
|
|
|
|
|
|
+const logger = new Logger('XStaticMeshComponent')
|
|
|
export default class XStaticMeshComponent{
|
|
export default class XStaticMeshComponent{
|
|
|
- constructor(scenemanager) {
|
|
|
|
|
- this._CgPlane
|
|
|
|
|
- this._orijson
|
|
|
|
|
- this._notUsedRegionLists
|
|
|
|
|
-
|
|
|
|
|
|
|
+ constructor(d) {
|
|
|
|
|
+ this.reg_staticmesh_partupdate = ()=>{
|
|
|
|
|
+ if (!GEngine.engineOption.bDisableCloudRender && (this._allowRegionUpdate && (this.scene.getFrameId(),
|
|
|
|
|
+ this._meshUpdateFrame()),
|
|
|
|
|
+ this._allowRegionForceLod)) {
|
|
|
|
|
+ this.scene.getFrameId() % 2 == 0 && this.setOneRegionLod(this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length].toString(), this._forceLod);
|
|
|
|
|
+ let s = !0;
|
|
|
|
|
+ const c = Array.from(this._currentMeshUsedLod.keys());
|
|
|
|
|
+ if (c.length > 0) {
|
|
|
|
|
+ for (let _ = 0; _ < c.length; ++_)
|
|
|
|
|
+ this._currentMeshUsedLod.get(c[_]) != this._forceLod && (s = !1);
|
|
|
|
|
+ s && (this._allowRegionForceLod = !1)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.setMeshInfo = (o,s="")=>{
|
|
|
|
|
+ this._abosoluteUrl != o && (this._abosoluteUrl.length > 0 && this.deleteLastRegionMesh(),
|
|
|
|
|
+ this._partMeshSkinInfo = s,
|
|
|
|
|
+ this._abosoluteUrl = o,
|
|
|
|
|
+ this._rootDir = this._abosoluteUrl.slice(0, -4) + "/",
|
|
|
|
|
+ this.parseJson(this._rootDir + "meshInfo.json").then(()=>{
|
|
|
|
|
+ this.startMeshUpdate()
|
|
|
|
|
+ }
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this._meshUpdateFrame = ()=>{
|
|
|
|
|
+ {
|
|
|
|
|
+ let o = this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length];
|
|
|
|
|
+ const s = !0;
|
|
|
|
|
+ let c = 3;
|
|
|
|
|
+ if (this._scenemanager != null && this._scenemanager.cameraComponent != null) {
|
|
|
|
|
+ const _ = this._getMainPlayerPosition();
|
|
|
|
|
+ if (_ != null) {
|
|
|
|
|
+ if (this._cameraInRegionId >= 0) {
|
|
|
|
|
+ const k = this.getRegionIdWhichIncludeCamera(_);
|
|
|
|
|
+ (this._cameraInRegionId != k || this.regionIdInCamera.length == 0) && (this._cameraInRegionId = k,
|
|
|
|
|
+ this.regionIdInCamera = this._getNeighborId(this._cameraInRegionId.toString()),
|
|
|
|
|
+ this.regionIdInCameraConst = this.regionIdInCamera.slice());
|
|
|
|
|
+ let j = this.regionIdInCamera.pop();
|
|
|
|
|
+ for (; j != null; )
|
|
|
|
|
+ if (this._notUsedRegionLists.indexOf(j) >= 0)
|
|
|
|
|
+ j = this.regionIdInCamera.pop();
|
|
|
|
|
+ else
|
|
|
|
|
+ break;
|
|
|
|
|
+ j != null && (o = j.toString())
|
|
|
|
|
+ } else
|
|
|
|
|
+ this._cameraInRegionId = this.getRegionIdWhichIncludeCamera(_);
|
|
|
|
|
+ if (this._currentMeshUsedLod.size == 0 || this._notUsedRegionLists.indexOf(parseInt(o)) >= 0) {
|
|
|
|
|
+ o = this._cameraInRegionId.toString();
|
|
|
|
|
+ const k = this._getNeighborId(o);
|
|
|
|
|
+ for (; k.length == 0 && (o = this.getNearestRegionIdWithCamera(_).toString()),
|
|
|
|
|
+ this._notUsedRegionLists.indexOf(parseInt(o)) >= 0; )
|
|
|
|
|
+ o = k.pop().toString()
|
|
|
|
|
+ }
|
|
|
|
|
+ const b = this._meshInfoJson[this._cameraInRegionId.toString()].lod;
|
|
|
|
|
+ c = 3,
|
|
|
|
|
+ this._cameraInRegionId.toString() == o ? c = this._regionLodRule[0] : b[0].indexOf(parseInt(o)) >= 0 ? c = this._regionLodRule[1] : b[1].indexOf(parseInt(o)) >= 0 ? c = this._regionLodRule[2] : b[2].indexOf(parseInt(o)) >= 0 ? c = this._regionLodRule[3] : c = this._regionLodRule[4]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setOneRegionLod(o, c, s),
|
|
|
|
|
+ this.updateRegionNotInLocalNeighbor(),
|
|
|
|
|
+ this.cleanRootNodes()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.updateRegionNotInLocalNeighbor = ()=>{
|
|
|
|
|
+ Array.from(this._currentMeshUsedLod.keys()).forEach(s=>{
|
|
|
|
|
+ this.regionIdInCameraConst.indexOf(parseInt(s)) < 0 && this.setOneRegionLod(s, -1)
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.cleanRootNodes = ()=>{
|
|
|
|
|
+ if (this.scene.getFrameId() % 3 == 0) {
|
|
|
|
|
+ const o = [];
|
|
|
|
|
+ this.scene.rootNodes.forEach(s=>{
|
|
|
|
|
+ (s.getClassName() == "TransformNode" && s.getChildren().length == 0 || s.getClassName() == "Mesh" && s.name == "__root__" && s.getChildren().length == 0) && o.push(s)
|
|
|
|
|
+ }
|
|
|
|
|
+ ),
|
|
|
|
|
+ o.forEach(s=>{
|
|
|
|
|
+ s.dispose()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.setOneRegionLod = (o,s,c=!0)=>{
|
|
|
|
|
+ this._currentUpdateRegionCount++;
|
|
|
|
|
+ const _ = this._calHashCode(this._rootDir)
|
|
|
|
|
+ , b = "region_" + _ + "_" + o;
|
|
|
|
|
+ if (s < 0) {
|
|
|
|
|
+ this._currentMeshUsedLod.has(o) && (this._currentMeshUsedLod.delete(o),
|
|
|
|
|
+ this._currentPartGroup.delete(b),
|
|
|
|
|
+ this.deleteMeshesByCustomProperty("group", "region_" + _ + "_" + o));
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const k = this._rootDir + o + "_lod" + s + "_xverse.glb"
|
|
|
|
|
+ , j = this._currentMeshUsedLod.get(o);
|
|
|
|
|
+ this._currentPartGroup.add(b),
|
|
|
|
|
+ j != null ? j != s && (this._currentMeshUsedLod.set(o, s),
|
|
|
|
|
+ this._scenemanager.addNewLowPolyMesh({
|
|
|
|
|
+ url: k,
|
|
|
|
|
+ group: "region_" + _ + "_" + o,
|
|
|
|
|
+ pick: !0,
|
|
|
|
|
+ lod: s,
|
|
|
|
|
+ skinInfo: this._partMeshSkinInfo
|
|
|
|
|
+ }, [{
|
|
|
|
|
+ group: "region_" + _ + "_" + o,
|
|
|
|
|
+ mode: 0
|
|
|
|
|
+ }])) : (this._currentMeshUsedLod.set(o, s),
|
|
|
|
|
+ this._scenemanager.addNewLowPolyMesh({
|
|
|
|
|
+ url: k,
|
|
|
|
|
+ group: "region_" + _ + "_" + o,
|
|
|
|
|
+ pick: !0,
|
|
|
|
|
+ lod: s,
|
|
|
|
|
+ skinInfo: this._partMeshSkinInfo
|
|
|
|
|
+ }))
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.checkPointInView = ({x: o, y: s, z: c})=>{
|
|
|
|
|
+ const _ = ue4Position2Xverse({
|
|
|
|
|
+ x: o,
|
|
|
|
|
+ y: s,
|
|
|
|
|
+ z: c
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!_)
|
|
|
|
|
+ return !1;
|
|
|
|
|
+ for (let b = 0; b < 6; b++)
|
|
|
|
|
+ if (this.scene.frustumPlanes[b].dotCoordinate(_) < 0)
|
|
|
|
|
+ return !1;
|
|
|
|
|
+ return !0
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.addNewLowPolyMesh = (o,s,c)=>{
|
|
|
|
|
+ if (!o.url.endsWith("glb") && !o.url.startsWith("blob:"))
|
|
|
|
|
+ return o.url.endsWith("zip") ? (this.setMeshInfo(o.url, o.skinInfo),
|
|
|
|
|
+ Promise.resolve(!0)) : (logger.error("[Engine] input model path is error! ", o.url),
|
|
|
|
|
+ Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + o.url)));
|
|
|
|
|
+ {
|
|
|
|
|
+ const _ = o.url;
|
|
|
|
|
+ return new Promise((b,k)=>this._scenemanager.urlTransformer(o.url).then(j=>{
|
|
|
|
|
+ o.url = j;
|
|
|
|
|
+ const $ = new XStaticMeshFromOneGltf(this.scene,o)
|
|
|
|
|
+ , _e = Date.now();
|
|
|
|
|
+ return new Promise((et,tt)=>{
|
|
|
|
|
+ $.loadMesh(c, !0).then(rt=>{
|
|
|
|
|
+ const it = Date.now();
|
|
|
|
|
+ if (this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(it - _e),
|
|
|
|
|
+ rt == !0) {
|
|
|
|
|
+ const nt = this.getLowModelType(o);
|
|
|
|
|
+ let at = 0;
|
|
|
|
|
+ if (this._lowModel_group.has(nt) && (at = this._lowModel_group.get(nt).length),
|
|
|
|
|
+ c != null && this._scenemanager.currentShader != null && this._scenemanager.currentShader.name != c.name && $.setMaterial(this._scenemanager.currentShader),
|
|
|
|
|
+ this._allowRegionUpdate == !1 && nt.startsWith("region_"))
|
|
|
|
|
+ $.dispose();
|
|
|
|
|
+ else if (this._staticmeshes.push($),
|
|
|
|
|
+ this.lowmodelGroupMapAddValue(nt, $),
|
|
|
|
|
+ s != null && s.length > 0) {
|
|
|
|
|
+ const ot = [];
|
|
|
|
|
+ for (let st = 0; st < s.length; ++st)
|
|
|
|
|
+ ot.push(s[st].group),
|
|
|
|
|
+ this.updateLowModelGroup(s[st], nt, at)
|
|
|
|
|
+ }
|
|
|
|
|
+ this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - it),
|
|
|
|
|
+ et(!0)
|
|
|
|
|
+ } else
|
|
|
|
|
+ tt(new XLowpolyModelError("[Engine] after lowmodel error!"))
|
|
|
|
|
+ }
|
|
|
|
|
+ ).catch(rt=>{
|
|
|
|
|
+ logger.error("[Engine] load Mesh [" + _ + "] error! " + rt),
|
|
|
|
|
+ tt(new XLowpolyModelError(`[Engine] load Mesh [${_}] error! ${rt}`))
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ ).then(j=>{
|
|
|
|
|
+ j == !0 ? (logger.info(`[Engine] load Mesh [${_}] successfully.`),
|
|
|
|
|
+ b(!0)) : k(!1)
|
|
|
|
|
+ }
|
|
|
|
|
+ ).catch(j=>{
|
|
|
|
|
+ logger.error("[Engine] addNewLowPolyMesh [" + _ + "] error! " + j),
|
|
|
|
|
+ k(new XLowpolyModelError(`[Engine] addNewLowPolyMesh [${_}] error! ${j}`))
|
|
|
|
|
+ }
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.toggleLowModelVisibility = o=>{
|
|
|
|
|
+ const {vis: s, groupName: c="", skinInfo: _=""} = o;
|
|
|
|
|
+ this._meshVis = s,
|
|
|
|
|
+ this._meshVisTypeName = {
|
|
|
|
|
+ groupName: c,
|
|
|
|
|
+ skinInfo: _
|
|
|
|
|
+ },
|
|
|
|
|
+ this._doMeshVisChangeNumber = 0,
|
|
|
|
|
+ c == _XStaticMeshComponent.ALL_MESHES || this._currentPartGroup.has(c) == !0 || this._partMeshSkinInfo == _ ? s == !1 ? (this._visCheckDurationFrameNumber = 100,
|
|
|
|
|
+ this.stopMeshUpdate()) : (this._visCheckDurationFrameNumber = 1,
|
|
|
|
|
+ this.startMeshUpdate()) : this._visCheckDurationFrameNumber = 1
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this.reg_staticmesh_visibility = ()=>{
|
|
|
|
|
+ if (!GEngine.engineOption.bDisableCloudRender && this._doMeshVisChangeNumber >= 0)
|
|
|
|
|
+ if (this._doMeshVisChangeNumber < this._visCheckDurationFrameNumber)
|
|
|
|
|
+ if (this._doMeshVisChangeNumber = this._doMeshVisChangeNumber + 1,
|
|
|
|
|
+ this._meshVisTypeName.groupName == _XStaticMeshComponent.ALL_MESHES)
|
|
|
|
|
+ this._lowModel_group.forEach((o,s)=>{
|
|
|
|
|
+ for (let c = 0, _ = o.length; c < _; ++c)
|
|
|
|
|
+ o[c].toggleVisibility(this._meshVis)
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (this._lowModel_group.has(this._meshVisTypeName.groupName))
|
|
|
|
|
+ for (let o = 0; o < this._lowModel_group.get(this._meshVisTypeName.groupName).length; ++o)
|
|
|
|
|
+ this._lowModel_group.get(this._meshVisTypeName.groupName)[o].toggleVisibility(this._meshVis);
|
|
|
|
|
+ if (this._meshVisTypeName.skinInfo != "")
|
|
|
|
|
+ for (let o = 0; o < this._staticmeshes.length; ++o)
|
|
|
|
|
+ this._staticmeshes[o].skinInfo == this._meshVisTypeName.skinInfo && this._staticmeshes[o].toggleVisibility(this._meshVis)
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ this._meshVis = !0,
|
|
|
|
|
+ this._meshVisTypeName = {
|
|
|
|
|
+ groupName: "",
|
|
|
|
|
+ skinInfo: ""
|
|
|
|
|
+ },
|
|
|
|
|
+ this._doMeshVisChangeNumber = -1
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
|
|
+ this._getMeshesByCustomProperty = (o,s)=>{
|
|
|
|
|
+ let c = [];
|
|
|
|
|
+ return this._staticmeshes.forEach(_=>{
|
|
|
|
|
+ _[o] != null && _[o] == s && (c = c.concat(_.meshes))
|
|
|
|
|
+ }
|
|
|
|
|
+ ),
|
|
|
|
|
+ c
|
|
|
|
|
+ }
|
|
|
|
|
+ ,
|
|
|
this._lowModel_group = new Map,
|
|
this._lowModel_group = new Map,
|
|
|
this._staticmeshes = [],
|
|
this._staticmeshes = [],
|
|
|
this._meshInfoJson = null,
|
|
this._meshInfoJson = null,
|
|
@@ -24,8 +258,8 @@ export default class XStaticMeshComponent{
|
|
|
this._allowRegionForceLod = !1,
|
|
this._allowRegionForceLod = !1,
|
|
|
this._currentMeshUsedLod = new Map,
|
|
this._currentMeshUsedLod = new Map,
|
|
|
this._currentPartGroup = new Set,
|
|
this._currentPartGroup = new Set,
|
|
|
- this._scenemanager = scenemanager,
|
|
|
|
|
- this.scene = scenemanager.Scene,
|
|
|
|
|
|
|
+ this._scenemanager = d,
|
|
|
|
|
+ this.scene = d.Scene,
|
|
|
this.regionIdInCamera = [],
|
|
this.regionIdInCamera = [],
|
|
|
this.regionIdInCameraConst = [],
|
|
this.regionIdInCameraConst = [],
|
|
|
this._cameraInRegionId = -1,
|
|
this._cameraInRegionId = -1,
|
|
@@ -41,268 +275,13 @@ export default class XStaticMeshComponent{
|
|
|
this.initCgLowModel(),
|
|
this.initCgLowModel(),
|
|
|
this._regionPartLoop()
|
|
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() {
|
|
get cameraInRegionId() {
|
|
|
return this._cameraInRegionId
|
|
return this._cameraInRegionId
|
|
|
}
|
|
}
|
|
|
- setRegionLodRule(e) {
|
|
|
|
|
- return e.length != 5 ? !1 : (e.forEach(t=>{}
|
|
|
|
|
|
|
+ setRegionLodRule(d) {
|
|
|
|
|
+ return d.length != 5 ? !1 : (d.forEach(o=>{}
|
|
|
),
|
|
),
|
|
|
- this._regionLodRule = e,
|
|
|
|
|
|
|
+ this._regionLodRule = d,
|
|
|
!0)
|
|
!0)
|
|
|
}
|
|
}
|
|
|
get lowModel_group() {
|
|
get lowModel_group() {
|
|
@@ -312,84 +291,84 @@ export default class XStaticMeshComponent{
|
|
|
this.scene.registerBeforeRender(this.reg_staticmesh_partupdate),
|
|
this.scene.registerBeforeRender(this.reg_staticmesh_partupdate),
|
|
|
this.scene.registerAfterRender(this.reg_staticmesh_visibility)
|
|
this.scene.registerAfterRender(this.reg_staticmesh_visibility)
|
|
|
}
|
|
}
|
|
|
- _globalSearchCameraInWhichRegion(e, t) {
|
|
|
|
|
- let r = -1;
|
|
|
|
|
- for (let n = 0; n < t.length; ++n) {
|
|
|
|
|
- const o = this._meshInfoJson[t[n].toString()].boundingbox
|
|
|
|
|
- , a = o[0]
|
|
|
|
|
- , s = o[1];
|
|
|
|
|
- if (e.x >= a[0] && e.x <= s[0] && e.y >= a[1] && e.y <= s[1] && e.z >= a[2] && e.z <= s[2] || e.x >= s[0] && e.x <= a[0] && e.y >= s[1] && e.y <= a[1] && e.z >= s[2] && e.z <= a[2]) {
|
|
|
|
|
- r = parseInt(t[n].toString());
|
|
|
|
|
|
|
+ _globalSearchCameraInWhichRegion(d, o) {
|
|
|
|
|
+ let s = -1;
|
|
|
|
|
+ for (let c = 0; c < o.length; ++c) {
|
|
|
|
|
+ const _ = this._meshInfoJson[o[c].toString()].boundingbox
|
|
|
|
|
+ , b = _[0]
|
|
|
|
|
+ , k = _[1];
|
|
|
|
|
+ if (d.x >= b[0] && d.x <= k[0] && d.y >= b[1] && d.y <= k[1] && d.z >= b[2] && d.z <= k[2] || d.x >= k[0] && d.x <= b[0] && d.y >= k[1] && d.y <= b[1] && d.z >= k[2] && d.z <= b[2]) {
|
|
|
|
|
+ s = parseInt(o[c].toString());
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return r
|
|
|
|
|
|
|
+ return s
|
|
|
}
|
|
}
|
|
|
- getRegionIdByPosition(e) {
|
|
|
|
|
- return this.getRegionIdWhichIncludeCamera(e)
|
|
|
|
|
|
|
+ getRegionIdByPosition(d) {
|
|
|
|
|
+ return this.getRegionIdWhichIncludeCamera(d)
|
|
|
}
|
|
}
|
|
|
- getRegionIdWhichIncludeCamera(e) {
|
|
|
|
|
- let t = -1;
|
|
|
|
|
|
|
+ getRegionIdWhichIncludeCamera(d) {
|
|
|
|
|
+ let o = -1;
|
|
|
if (this._allowRegionUpdate == !1)
|
|
if (this._allowRegionUpdate == !1)
|
|
|
- return t;
|
|
|
|
|
- if (this._cameraInRegionId == -1 ? t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys) : (t = this._globalSearchCameraInWhichRegion(e, this.regionIdInCameraConst),
|
|
|
|
|
- t == -1 && (t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys))),
|
|
|
|
|
- t == -1) {
|
|
|
|
|
- let r = 1e7;
|
|
|
|
|
- for (let n = 0; n < this._meshInfoKeys.length; ++n) {
|
|
|
|
|
- const o = this._meshInfoJson[this._meshInfoKeys[n]].center
|
|
|
|
|
- , a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
|
|
|
|
|
- r > a && (r = a,
|
|
|
|
|
- t = parseInt(this._meshInfoKeys[n]))
|
|
|
|
|
|
|
+ return o;
|
|
|
|
|
+ if (this._cameraInRegionId == -1 ? o = this._globalSearchCameraInWhichRegion(d, this._meshInfoKeys) : (o = this._globalSearchCameraInWhichRegion(d, this.regionIdInCameraConst),
|
|
|
|
|
+ o == -1 && (o = this._globalSearchCameraInWhichRegion(d, this._meshInfoKeys))),
|
|
|
|
|
+ o == -1) {
|
|
|
|
|
+ let s = 1e7;
|
|
|
|
|
+ for (let c = 0; c < this._meshInfoKeys.length; ++c) {
|
|
|
|
|
+ const _ = this._meshInfoJson[this._meshInfoKeys[c]].center
|
|
|
|
|
+ , b = Math.abs(d.x - _[0]) + Math.abs(d.y - _[1]);
|
|
|
|
|
+ s > b && (s = b,
|
|
|
|
|
+ o = parseInt(this._meshInfoKeys[c]))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return t
|
|
|
|
|
|
|
+ return o
|
|
|
}
|
|
}
|
|
|
- getNearestRegionIdWithCamera(e) {
|
|
|
|
|
- let t = 1
|
|
|
|
|
- , r = 1e7;
|
|
|
|
|
- for (let n = 0; n < this._meshInfoKeys.length; ++n) {
|
|
|
|
|
- if (this._notUsedRegionLists.indexOf(parseInt(this._meshInfoKeys[n])) >= 0)
|
|
|
|
|
|
|
+ getNearestRegionIdWithCamera(d) {
|
|
|
|
|
+ let o = 1
|
|
|
|
|
+ , s = 1e7;
|
|
|
|
|
+ for (let c = 0; c < this._meshInfoKeys.length; ++c) {
|
|
|
|
|
+ if (this._notUsedRegionLists.indexOf(parseInt(this._meshInfoKeys[c])) >= 0)
|
|
|
continue;
|
|
continue;
|
|
|
- const o = this._meshInfoJson[this._meshInfoKeys[n]].center
|
|
|
|
|
- , a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
|
|
|
|
|
- r > a && (r = a,
|
|
|
|
|
- t = parseInt(this._meshInfoKeys[n]))
|
|
|
|
|
|
|
+ const _ = this._meshInfoJson[this._meshInfoKeys[c]].center
|
|
|
|
|
+ , b = Math.abs(d.x - _[0]) + Math.abs(d.y - _[1]);
|
|
|
|
|
+ s > b && (s = b,
|
|
|
|
|
+ o = parseInt(this._meshInfoKeys[c]))
|
|
|
}
|
|
}
|
|
|
- return t
|
|
|
|
|
|
|
+ return o
|
|
|
}
|
|
}
|
|
|
- _getNeighborId(e) {
|
|
|
|
|
- const t = this._meshInfoJson[e].lod;
|
|
|
|
|
- let r = [];
|
|
|
|
|
- const n = Object.keys(t);
|
|
|
|
|
- for (let o = n.length - 1; o >= 0; --o)
|
|
|
|
|
- r = r.concat(t[n[o]]);
|
|
|
|
|
- return r.push(parseInt(e)),
|
|
|
|
|
- r
|
|
|
|
|
|
|
+ _getNeighborId(d) {
|
|
|
|
|
+ const o = this._meshInfoJson[d].lod;
|
|
|
|
|
+ let s = [];
|
|
|
|
|
+ const c = Object.keys(o);
|
|
|
|
|
+ for (let _ = c.length - 1; _ >= 0; --_)
|
|
|
|
|
+ s = s.concat(o[c[_]]);
|
|
|
|
|
+ return s.push(parseInt(d)),
|
|
|
|
|
+ s
|
|
|
}
|
|
}
|
|
|
_getMainPlayerPosition() {
|
|
_getMainPlayerPosition() {
|
|
|
- const e = this._scenemanager.cameraComponent.getCameraPose().position
|
|
|
|
|
- , t = this._scenemanager.avatarComponent.getMainAvatar();
|
|
|
|
|
- if (t != null && t != null) {
|
|
|
|
|
- const r = t.position;
|
|
|
|
|
- if (r != null)
|
|
|
|
|
- return r
|
|
|
|
|
|
|
+ const d = this._scenemanager.cameraComponent.getCameraPose().position
|
|
|
|
|
+ , o = this._scenemanager.avatarComponent.getMainAvatar();
|
|
|
|
|
+ if (o != null && o != null) {
|
|
|
|
|
+ const s = o.position;
|
|
|
|
|
+ if (s != null)
|
|
|
|
|
+ return s
|
|
|
}
|
|
}
|
|
|
- return e
|
|
|
|
|
|
|
+ return d
|
|
|
}
|
|
}
|
|
|
- _calHashCode(e) {
|
|
|
|
|
- return hashCode(e) + "_" + this._partMeshSkinInfo
|
|
|
|
|
|
|
+ _calHashCode(d) {
|
|
|
|
|
+ return hashCode(d) + "_" + this._partMeshSkinInfo
|
|
|
}
|
|
}
|
|
|
- forceAllRegionLod(e=3) {
|
|
|
|
|
- e < 0 && (e = 0),
|
|
|
|
|
- e > 3 && (e = 3),
|
|
|
|
|
|
|
+ forceAllRegionLod(d=3) {
|
|
|
|
|
+ d < 0 && (d = 0),
|
|
|
|
|
+ d > 3 && (d = 3),
|
|
|
this.stopMeshUpdate(),
|
|
this.stopMeshUpdate(),
|
|
|
this._allowRegionForceLod = !0,
|
|
this._allowRegionForceLod = !0,
|
|
|
- this._forceLod = e
|
|
|
|
|
|
|
+ this._forceLod = d
|
|
|
}
|
|
}
|
|
|
deleteLastRegionMesh() {
|
|
deleteLastRegionMesh() {
|
|
|
if (this._rootDir != "") {
|
|
if (this._rootDir != "") {
|
|
|
- const e = this._calHashCode(this._rootDir);
|
|
|
|
|
|
|
+ const d = this._calHashCode(this._rootDir);
|
|
|
this._currentMeshUsedLod.clear(),
|
|
this._currentMeshUsedLod.clear(),
|
|
|
this._currentPartGroup.clear(),
|
|
this._currentPartGroup.clear(),
|
|
|
this._meshInfoJson = null,
|
|
this._meshInfoJson = null,
|
|
@@ -400,7 +379,7 @@ export default class XStaticMeshComponent{
|
|
|
this._partMeshSkinInfo = "",
|
|
this._partMeshSkinInfo = "",
|
|
|
this._abosoluteUrl = "",
|
|
this._abosoluteUrl = "",
|
|
|
this.stopMeshUpdate(),
|
|
this.stopMeshUpdate(),
|
|
|
- this.deleteMeshesByCustomProperty("group", "region_" + e, !0)
|
|
|
|
|
|
|
+ this.deleteMeshesByCustomProperty("group", "region_" + d, !0)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
startMeshUpdate() {
|
|
startMeshUpdate() {
|
|
@@ -409,170 +388,172 @@ export default class XStaticMeshComponent{
|
|
|
stopMeshUpdate() {
|
|
stopMeshUpdate() {
|
|
|
this._allowRegionUpdate = !1
|
|
this._allowRegionUpdate = !1
|
|
|
}
|
|
}
|
|
|
- parseJson(e) {
|
|
|
|
|
- return new Promise((t,r)=>this._scenemanager.urlTransformer(e).then(n=>{
|
|
|
|
|
- const o = new XMLHttpRequest;
|
|
|
|
|
- o.open("get", n),
|
|
|
|
|
- o.send(null),
|
|
|
|
|
- o.onload = ()=>{
|
|
|
|
|
- if (o.status == 200) {
|
|
|
|
|
- const a = JSON.parse(o.responseText);
|
|
|
|
|
- this._orijson = a,
|
|
|
|
|
|
|
+ parseJson(d) {
|
|
|
|
|
+ return new Promise((o,s)=>this._scenemanager.urlTransformer(d).then(c=>{
|
|
|
|
|
+ const _ = new XMLHttpRequest;
|
|
|
|
|
+ _.open("get", c),
|
|
|
|
|
+ _.send(null),
|
|
|
|
|
+ _.onload = ()=>{
|
|
|
|
|
+ if (_.status == 200) {
|
|
|
|
|
+ const b = JSON.parse(_.responseText);
|
|
|
|
|
+ this._orijson = b,
|
|
|
this._meshInfoJson = this._orijson.usedRegion,
|
|
this._meshInfoJson = this._orijson.usedRegion,
|
|
|
this._notUsedRegionLists = this._orijson.notUsedRegion,
|
|
this._notUsedRegionLists = this._orijson.notUsedRegion,
|
|
|
this._meshInfoKeys = Object.keys(this._meshInfoJson),
|
|
this._meshInfoKeys = Object.keys(this._meshInfoJson),
|
|
|
logger.info("[Engine] parse zip mesh info successful"),
|
|
logger.info("[Engine] parse zip mesh info successful"),
|
|
|
- t()
|
|
|
|
|
|
|
+ o()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
,
|
|
,
|
|
|
- o.onerror = ()=>{
|
|
|
|
|
- logger.error(`[Engine] load zip mesh info json error, (provided by blob): ${n}`),
|
|
|
|
|
- r(new XLowpolyJsonError(`[Engine] load zip mesh info json error, (provided by blob): ${n}`))
|
|
|
|
|
|
|
+ _.onerror = ()=>{
|
|
|
|
|
+ logger.error(`[Engine] load zip mesh info json error, (provided by blob): ${c}`),
|
|
|
|
|
+ s(new XLowpolyJsonError(`[Engine] load zip mesh info json error, (provided by blob): ${c}`))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- ).catch(n=>{
|
|
|
|
|
- logger.error(`[Engine] load zip mesh info json error: ${n}, link:${e}`),
|
|
|
|
|
- r(new XLowpolyJsonError(`[Engine] load zip mesh info json error: ${n}, link: ${e}`))
|
|
|
|
|
|
|
+ ).catch(c=>{
|
|
|
|
|
+ logger.error(`[Engine] load zip mesh info json error: ${c}, link:${d}`),
|
|
|
|
|
+ s(new XLowpolyJsonError(`[Engine] load zip mesh info json error: ${c}, link: ${d}`))
|
|
|
}
|
|
}
|
|
|
))
|
|
))
|
|
|
}
|
|
}
|
|
|
initCgLowModel() {
|
|
initCgLowModel() {
|
|
|
- const e = BABYLON.MeshBuilder.CreatePlane("CgPlane", {
|
|
|
|
|
|
|
+ const d = BABYLON.MeshBuilder.CreatePlane("CgPlane", {
|
|
|
size: 400
|
|
size: 400
|
|
|
});
|
|
});
|
|
|
- e.position = new BABYLON.Vector3(0,1010,0),
|
|
|
|
|
- e.rotation = new BABYLON.Vector3(3 * Math.PI / 2,0,0),
|
|
|
|
|
|
|
+ d.position = new BABYLON.Vector3(0,1010,0),
|
|
|
|
|
+ d.rotation = new BABYLON.Vector3(3 * Math.PI / 2,0,0),
|
|
|
this._CgPlane = new XStaticMesh({
|
|
this._CgPlane = new XStaticMesh({
|
|
|
id: "CgPlane",
|
|
id: "CgPlane",
|
|
|
- mesh: e,
|
|
|
|
|
|
|
+ mesh: d,
|
|
|
xtype: EMeshType.Cgplane
|
|
xtype: EMeshType.Cgplane
|
|
|
}),
|
|
}),
|
|
|
this._CgPlane.hide()
|
|
this._CgPlane.hide()
|
|
|
}
|
|
}
|
|
|
- getLowModelType(e) {
|
|
|
|
|
- let t = "";
|
|
|
|
|
- return e.group != null ? t = e.group : t = "default",
|
|
|
|
|
- t
|
|
|
|
|
- }
|
|
|
|
|
- lowmodelGroupMapAddValue(e, t) {
|
|
|
|
|
- const r = this._lowModel_group.get(e);
|
|
|
|
|
- r != null ? (r.push(t),
|
|
|
|
|
- this._lowModel_group.set(e, r)) : this._lowModel_group.set(e, [t])
|
|
|
|
|
- }
|
|
|
|
|
- updateLowModelGroup(e, t, r) {
|
|
|
|
|
- let n = r;
|
|
|
|
|
- e.group == t || (n = -1),
|
|
|
|
|
- e.mode == 0 ? this.deleteLowModelGroup(e.group, n) : e.mode == 1 ? this.toggleVisibleLowModelGroup(!1, e.group, n) : e.mode == 2 && this.toggleVisibleLowModelGroup(!0, e.group, n)
|
|
|
|
|
- }
|
|
|
|
|
- toggleVisibleLowModelGroup(e, t, r=-1) {
|
|
|
|
|
- if (this._lowModel_group.has(t)) {
|
|
|
|
|
- const n = this._lowModel_group.get(t);
|
|
|
|
|
- let o = n.length;
|
|
|
|
|
- r >= 0 && o >= r && (o = r);
|
|
|
|
|
- for (let a = 0; a < o; ++a)
|
|
|
|
|
- n[a].toggleVisibility(e)
|
|
|
|
|
|
|
+ getLowModelType(d) {
|
|
|
|
|
+ let o = "";
|
|
|
|
|
+ return d.group != null ? o = d.group : o = "default",
|
|
|
|
|
+ o
|
|
|
|
|
+ }
|
|
|
|
|
+ lowmodelGroupMapAddValue(d, o) {
|
|
|
|
|
+ const s = this._lowModel_group.get(d);
|
|
|
|
|
+ s != null ? (s.push(o),
|
|
|
|
|
+ this._lowModel_group.set(d, s)) : this._lowModel_group.set(d, [o])
|
|
|
|
|
+ }
|
|
|
|
|
+ updateLowModelGroup(d, o, s) {
|
|
|
|
|
+ let c = s;
|
|
|
|
|
+ d.group == o || (c = -1),
|
|
|
|
|
+ d.mode == 0 ? this.deleteLowModelGroup(d.group, c) : d.mode == 1 ? this.toggleVisibleLowModelGroup(!1, d.group, c) : d.mode == 2 && this.toggleVisibleLowModelGroup(!0, d.group, c)
|
|
|
|
|
+ }
|
|
|
|
|
+ toggleVisibleLowModelGroup(d, o, s=-1) {
|
|
|
|
|
+ if (this._lowModel_group.has(o)) {
|
|
|
|
|
+ const c = this._lowModel_group.get(o);
|
|
|
|
|
+ let _ = c.length;
|
|
|
|
|
+ s >= 0 && _ >= s && (_ = s);
|
|
|
|
|
+ for (let b = 0; b < _; ++b)
|
|
|
|
|
+ c[b].toggleVisibility(d)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- deleteLowModelGroup(e, t=-1) {
|
|
|
|
|
- if (this._lowModel_group.has(e)) {
|
|
|
|
|
- const o = this._lowModel_group.get(e);
|
|
|
|
|
- let a = o.length;
|
|
|
|
|
- t >= 0 && a >= t && (a = t);
|
|
|
|
|
- for (let s = 0; s < a; ++s)
|
|
|
|
|
- o[s].dispose();
|
|
|
|
|
- t >= 0 ? this._lowModel_group.set(e, this._lowModel_group.get(e).slice(a)) : this._lowModel_group.delete(e)
|
|
|
|
|
|
|
+ deleteLowModelGroup(d, o=-1) {
|
|
|
|
|
+ if (this._lowModel_group.has(d)) {
|
|
|
|
|
+ const _ = this._lowModel_group.get(d);
|
|
|
|
|
+ let b = _.length;
|
|
|
|
|
+ o >= 0 && b >= o && (b = o);
|
|
|
|
|
+ for (let k = 0; k < b; ++k)
|
|
|
|
|
+ _[k].dispose();
|
|
|
|
|
+ o >= 0 ? this._lowModel_group.set(d, this._lowModel_group.get(d).slice(b)) : this._lowModel_group.delete(d)
|
|
|
}
|
|
}
|
|
|
- const r = this._lowModel_group.get(e)
|
|
|
|
|
- , n = [];
|
|
|
|
|
- r != null && r.length > 0 ? this._staticmeshes.forEach(o=>{
|
|
|
|
|
- if (o.group != e)
|
|
|
|
|
- n.push(o);
|
|
|
|
|
|
|
+ const s = this._lowModel_group.get(d)
|
|
|
|
|
+ , c = [];
|
|
|
|
|
+ s != null && s.length > 0 ? this._staticmeshes.forEach(_=>{
|
|
|
|
|
+ if (_.group != d)
|
|
|
|
|
+ c.push(_);
|
|
|
else
|
|
else
|
|
|
- for (let a = 0; a < r.length; ++a)
|
|
|
|
|
- o.groupUuid == r[a].groupUuid && n.push(o)
|
|
|
|
|
|
|
+ for (let b = 0; b < s.length; ++b)
|
|
|
|
|
+ _.groupUuid == s[b].groupUuid && c.push(_)
|
|
|
}
|
|
}
|
|
|
- ) : this._staticmeshes.forEach(o=>{
|
|
|
|
|
- o.group != e && n.push(o)
|
|
|
|
|
|
|
+ ) : this._staticmeshes.forEach(_=>{
|
|
|
|
|
+ _.group != d && c.push(_)
|
|
|
}
|
|
}
|
|
|
),
|
|
),
|
|
|
- this._staticmeshes = n
|
|
|
|
|
|
|
+ this._staticmeshes = c
|
|
|
}
|
|
}
|
|
|
- deleteMeshesByGroup(e) {
|
|
|
|
|
- this.deleteLowModelGroup(e)
|
|
|
|
|
|
|
+ deleteMeshesByGroup(d) {
|
|
|
|
|
+ this.deleteLowModelGroup(d)
|
|
|
}
|
|
}
|
|
|
- deleteMeshesById(e) {
|
|
|
|
|
- this.deleteMeshesByCustomProperty("id", e)
|
|
|
|
|
|
|
+ deleteMeshesById(d) {
|
|
|
|
|
+ this.deleteMeshesByCustomProperty("id", d)
|
|
|
}
|
|
}
|
|
|
- deleteMeshesByLoD(e) {
|
|
|
|
|
- this.deleteMeshesByCustomProperty("lod", e)
|
|
|
|
|
|
|
+ deleteMeshesByLoD(d) {
|
|
|
|
|
+ this.deleteMeshesByCustomProperty("lod", d)
|
|
|
}
|
|
}
|
|
|
- deleteMeshesBySkinInfo(e) {
|
|
|
|
|
- this.deleteMeshesByCustomProperty("skinInfo", e)
|
|
|
|
|
|
|
+ deleteMeshesBySkinInfo(d) {
|
|
|
|
|
+ this.deleteMeshesByCustomProperty("skinInfo", d)
|
|
|
}
|
|
}
|
|
|
- removeMeshesFromSceneByGroup(e) {
|
|
|
|
|
- this.removeMeshesFromSceneByCustomProperty("group", e)
|
|
|
|
|
|
|
+ removeMeshesFromSceneByGroup(d) {
|
|
|
|
|
+ this.removeMeshesFromSceneByCustomProperty("group", d)
|
|
|
}
|
|
}
|
|
|
- removeMeshesFromSceneById(e) {
|
|
|
|
|
- this.removeMeshesFromSceneByCustomProperty("id", e)
|
|
|
|
|
|
|
+ removeMeshesFromSceneById(d) {
|
|
|
|
|
+ this.removeMeshesFromSceneByCustomProperty("id", d)
|
|
|
}
|
|
}
|
|
|
- addMeshesToSceneByGroup(e) {
|
|
|
|
|
- this.addMeshesToSceneByCustomProperty("group", e)
|
|
|
|
|
|
|
+ addMeshesToSceneByGroup(d) {
|
|
|
|
|
+ this.addMeshesToSceneByCustomProperty("group", d)
|
|
|
}
|
|
}
|
|
|
- addMeshesToSceneById(e) {
|
|
|
|
|
- this.addMeshesToSceneByCustomProperty("id", e)
|
|
|
|
|
|
|
+ addMeshesToSceneById(d) {
|
|
|
|
|
+ this.addMeshesToSceneByCustomProperty("id", d)
|
|
|
}
|
|
}
|
|
|
- removeMeshesFromSceneByCustomProperty(e, t, r=!1) {
|
|
|
|
|
- this._staticmeshes.forEach(n=>{
|
|
|
|
|
- n.isinscene && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.removeFromScene() : n[e] != t || n.removeFromScene())
|
|
|
|
|
|
|
+ removeMeshesFromSceneByCustomProperty(d, o, s=!1) {
|
|
|
|
|
+ this._staticmeshes.forEach(c=>{
|
|
|
|
|
+ c.isinscene && c[d] != null && (s ? c[d].indexOf(o) < 0 || c.removeFromScene() : c[d] != o || c.removeFromScene())
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
- addMeshesToSceneByCustomProperty(e, t, r=!1) {
|
|
|
|
|
- this._staticmeshes.forEach(n=>{
|
|
|
|
|
- n.isinscene == !1 && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.addToScene() : n[e] != t || n.addToScene())
|
|
|
|
|
|
|
+ addMeshesToSceneByCustomProperty(d, o, s=!1) {
|
|
|
|
|
+ this._staticmeshes.forEach(c=>{
|
|
|
|
|
+ c.isinscene == !1 && c[d] != null && (s ? c[d].indexOf(o) < 0 || c.addToScene() : c[d] != o || c.addToScene())
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
- deleteMeshesByCustomProperty(e, t, r=!1) {
|
|
|
|
|
- const n = [];
|
|
|
|
|
- this._staticmeshes.forEach(a=>{
|
|
|
|
|
- a[e] != null && (r ? a[e].indexOf(t) < 0 ? n.push(a) : a.dispose() : a[e] != t ? n.push(a) : a.dispose())
|
|
|
|
|
|
|
+ deleteMeshesByCustomProperty(d, o, s=!1) {
|
|
|
|
|
+ const c = [];
|
|
|
|
|
+ this._staticmeshes.forEach(b=>{
|
|
|
|
|
+ b[d] != null && (s ? b[d].indexOf(o) < 0 ? c.push(b) : b.dispose() : b[d] != o ? c.push(b) : b.dispose())
|
|
|
}
|
|
}
|
|
|
),
|
|
),
|
|
|
- this._staticmeshes = n;
|
|
|
|
|
- const o = Array.from(this._lowModel_group.keys());
|
|
|
|
|
- for (let a = 0; a < o.length; ++a) {
|
|
|
|
|
- const s = o[a]
|
|
|
|
|
- , l = this._lowModel_group.get(s);
|
|
|
|
|
- if (l != null) {
|
|
|
|
|
- const u = [];
|
|
|
|
|
- for (let c = 0; c < l.length; ++c)
|
|
|
|
|
- l[c][e] != null && (r ? l[c][e].indexOf(t) < 0 && u.push(l[c]) : l[c][e] != t && u.push(l[c]));
|
|
|
|
|
- u.length > 0 ? this._lowModel_group.set(s, u) : this._lowModel_group.delete(s)
|
|
|
|
|
|
|
+ this._staticmeshes = c;
|
|
|
|
|
+ const _ = Array.from(this._lowModel_group.keys());
|
|
|
|
|
+ for (let b = 0; b < _.length; ++b) {
|
|
|
|
|
+ const k = _[b]
|
|
|
|
|
+ , j = this._lowModel_group.get(k);
|
|
|
|
|
+ if (j != null) {
|
|
|
|
|
+ const $ = [];
|
|
|
|
|
+ for (let _e = 0; _e < j.length; ++_e)
|
|
|
|
|
+ j[_e][d] != null && (s ? j[_e][d].indexOf(o) < 0 && $.push(j[_e]) : j[_e][d] != o && $.push(j[_e]));
|
|
|
|
|
+ $.length > 0 ? this._lowModel_group.set(k, $) : this._lowModel_group.delete(k)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
getMeshes() {
|
|
getMeshes() {
|
|
|
- let e = [];
|
|
|
|
|
- for (let t = 0; t < this._staticmeshes.length; ++t)
|
|
|
|
|
- e = e.concat(this._staticmeshes[t].meshes);
|
|
|
|
|
- return e
|
|
|
|
|
|
|
+ let d = [];
|
|
|
|
|
+ for (let o = 0; o < this._staticmeshes.length; ++o)
|
|
|
|
|
+ d = d.concat(this._staticmeshes[o].meshes);
|
|
|
|
|
+ return d
|
|
|
}
|
|
}
|
|
|
getCgMesh() {
|
|
getCgMesh() {
|
|
|
return this._CgPlane
|
|
return this._CgPlane
|
|
|
}
|
|
}
|
|
|
- getMeshesByGroup(e="default") {
|
|
|
|
|
- const t = this._lowModel_group.get(e);
|
|
|
|
|
- if (t != null) {
|
|
|
|
|
- let r = [];
|
|
|
|
|
- for (let n = 0; n < t.length; ++n)
|
|
|
|
|
- r = r.concat(t[n].meshes);
|
|
|
|
|
- return r
|
|
|
|
|
|
|
+ getMeshesByGroup(d="default") {
|
|
|
|
|
+ const o = this._lowModel_group.get(d);
|
|
|
|
|
+ if (o != null) {
|
|
|
|
|
+ let s = [];
|
|
|
|
|
+ for (let c = 0; c < o.length; ++c)
|
|
|
|
|
+ s = s.concat(o[c].meshes);
|
|
|
|
|
+ return s
|
|
|
} else
|
|
} else
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
- getMeshesByGroup2(e="default") {
|
|
|
|
|
- return this._getMeshesByCustomProperty("group", e)
|
|
|
|
|
|
|
+ getMeshesByGroup2(d="default") {
|
|
|
|
|
+ return this._getMeshesByCustomProperty("group", d)
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+XStaticMeshComponent.ALL_MESHES = "ALL_MESHES";
|