|
@@ -1,120 +1,158 @@
|
|
|
|
+import Logger from "./Logger.js"
|
|
|
|
+
|
|
|
|
+const logger = new Logger('XAvatarLoader')
|
|
|
|
+
|
|
export default class XAvatarLoader {
|
|
export default class XAvatarLoader {
|
|
constructor() {
|
|
constructor() {
|
|
- E(this, "containers", new Map);
|
|
|
|
- E(this, "meshes", new Map);
|
|
|
|
- E(this, "animations", new Map);
|
|
|
|
- E(this, "aniPath", new Map);
|
|
|
|
- E(this, "binPath", new Map);
|
|
|
|
- E(this, "texPath", new Map);
|
|
|
|
- E(this, "matPath", new Map);
|
|
|
|
- E(this, "mshPath", new Map);
|
|
|
|
- E(this, "rootPath", new Map);
|
|
|
|
- E(this, "meshTexList", new Map);
|
|
|
|
- E(this, "_enableIdb", !0);
|
|
|
|
- E(this, "_mappings", new Map);
|
|
|
|
- E(this, "_sharedTex", new Map);
|
|
|
|
- E(this, "avaliableAnimation", new Map);
|
|
|
|
- E(this, "enableShareTexture", !0);
|
|
|
|
- E(this, "enableShareAnimation", !0);
|
|
|
|
- E(this, "fillEmptyLod", !0);
|
|
|
|
|
|
+ this.containers = new Map,
|
|
|
|
+ this.meshes = new Map,
|
|
|
|
+ this.animations = new Map,
|
|
|
|
+ this.aniPath = new Map,
|
|
|
|
+ this.binPath = new Map,
|
|
|
|
+ this.texPath = new Map,
|
|
|
|
+ this.matPath = new Map,
|
|
|
|
+ this.mshPath = new Map,
|
|
|
|
+ this.rootPath = new Map,
|
|
|
|
+ this.meshTexList = new Map,
|
|
|
|
+ this._enableIdb = !0,
|
|
|
|
+ this._mappings = new Map,
|
|
|
|
+ this._sharedTex = new Map,
|
|
|
|
+ this.avaliableAnimation = new Map,
|
|
|
|
+ this.enableShareTexture = !0,
|
|
|
|
+ this.enableShareAnimation = !0,
|
|
|
|
+ this.fillEmptyLod = !0,
|
|
|
|
+ this.pendantMap = new Map;
|
|
const e = new BABYLON.GLTFFileLoader;
|
|
const e = new BABYLON.GLTFFileLoader;
|
|
BABYLON.SceneLoader.RegisterPlugin(e),
|
|
BABYLON.SceneLoader.RegisterPlugin(e),
|
|
- e.preprocessUrlAsync = function(t) {
|
|
|
|
- const r = avatarLoader._mappings.get(t);
|
|
|
|
- return r ? Promise.resolve(r) : Promise.resolve(t)
|
|
|
|
|
|
+ e.preprocessUrlAsync = function(i) {
|
|
|
|
+ const o = avatarLoader._mappings.get(i);
|
|
|
|
+ return o ? Promise.resolve(o) : Promise.resolve(i)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ _parsePendant(e, i) {
|
|
|
|
+ if (!e || !i) {
|
|
|
|
+ logger.error("[Engine] invalid id or url when loading pendant");
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ const o = ".zip"
|
|
|
|
+ , s = i.replace(o, "/");
|
|
|
|
+ this.pendantMap.set(e, s)
|
|
|
|
+ }
|
|
|
|
+ pullAndLoadXObject(e, i) {
|
|
|
|
+ const o = avatarLoader.pendantMap.get(i);
|
|
|
|
+ return Tools.LoadFileAsync(o + `${i}.json`, !1).then(s=>{
|
|
|
|
+ if (!(s instanceof ArrayBuffer))
|
|
|
|
+ return LoadXObject(o, s).then(c=>c)
|
|
}
|
|
}
|
|
|
|
+ )
|
|
}
|
|
}
|
|
- getParsedUrl(e, t, r, n="") {
|
|
|
|
- return new Promise((o,a)=>{
|
|
|
|
- if (!r || r.indexOf(".zip") === -1)
|
|
|
|
- return o(r);
|
|
|
|
- const s = this.rootPath.get(r);
|
|
|
|
- if (s)
|
|
|
|
- return o(s);
|
|
|
|
|
|
+ getParsedUrl(e, i, o, s="") {
|
|
|
|
+ return new Promise((c,d)=>{
|
|
|
|
+ if (!o || o.indexOf(".zip") === -1)
|
|
|
|
+ return c(o);
|
|
|
|
+ const _ = this.rootPath.get(o);
|
|
|
|
+ if (_)
|
|
|
|
+ return c(_);
|
|
{
|
|
{
|
|
- const l = ".zip"
|
|
|
|
- , u = r.replace(l, "") + COMPONENT_LIST_PREFIX;
|
|
|
|
- e.urlTransformer(u, !0).then(c=>{
|
|
|
|
- if (!c)
|
|
|
|
- return a("Loading Failed");
|
|
|
|
- new Response(c).json().then(h=>{
|
|
|
|
- var _, g, m, v, y, b, T;
|
|
|
|
- const f = r.replace(l, "")
|
|
|
|
- , d = f + ((_ = h == null ? void 0 : h.components) == null ? void 0 : _.url.replace("./", ""));
|
|
|
|
- if (this.rootPath.set(r, d),
|
|
|
|
- h.components ? (h.components.url && this.mshPath.set(t, f + "/" + ((g = h == null ? void 0 : h.components) == null ? void 0 : g.url.replace("./", ""))),
|
|
|
|
- h.components.url_lod2 && this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((m = h == null ? void 0 : h.components) == null ? void 0 : m.url_lod2.replace("./", ""))),
|
|
|
|
- h.components.url_lod4 && this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((v = h == null ? void 0 : h.components) == null ? void 0 : v.url_lod4.replace("./", "")))) : (h.meshes.url && this.mshPath.set(t, f + "/" + ((y = h == null ? void 0 : h.meshes) == null ? void 0 : y.url.replace("./", ""))),
|
|
|
|
- h.meshes.url_lod2 && this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((b = h == null ? void 0 : h.meshes) == null ? void 0 : b.url_lod2.replace("./", ""))),
|
|
|
|
- h.meshes.url_lod4 && this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((T = h == null ? void 0 : h.meshes) == null ? void 0 : T.url_lod4.replace("./", "")))),
|
|
|
|
- h.materials && h.materials.forEach(C=>{
|
|
|
|
- const A = f + "/" + C.url;
|
|
|
|
- this.matPath.set(C.name, A)
|
|
|
|
|
|
+ const b = ".zip"
|
|
|
|
+ , k = o.replace(b, "") + COMPONENT_LIST_PREFIX;
|
|
|
|
+ e.urlTransformer(k, !0).then(j=>{
|
|
|
|
+ if (!j)
|
|
|
|
+ return d("Loading Failed");
|
|
|
|
+ new Response(j).json().then($=>{
|
|
|
|
+ var tt, rt, it, nt, ot, at, st;
|
|
|
|
+ const _e = o.replace(b, "")
|
|
|
|
+ , et = _e + ((tt = $ == null ? void 0 : $.components) == null ? void 0 : tt.url.replace("./", ""));
|
|
|
|
+ if (this.rootPath.set(o, et),
|
|
|
|
+ $.components ? ($.components.url && this.mshPath.set(i, _e + "/" + ((rt = $ == null ? void 0 : $.components) == null ? void 0 : rt.url.replace("./", ""))),
|
|
|
|
+ $.components.url_lod2 && this.mshPath.set(i + "_" + avatarSetting.lod[1].level, _e + "/" + ((it = $ == null ? void 0 : $.components) == null ? void 0 : it.url_lod2.replace("./", ""))),
|
|
|
|
+ $.components.url_lod4 && this.mshPath.set(i + "_" + avatarSetting.lod[2].level, _e + "/" + ((nt = $ == null ? void 0 : $.components) == null ? void 0 : nt.url_lod4.replace("./", "")))) : ($.meshes.url && this.mshPath.set(i, _e + "/" + ((ot = $ == null ? void 0 : $.meshes) == null ? void 0 : ot.url.replace("./", ""))),
|
|
|
|
+ $.meshes.url_lod2 && this.mshPath.set(i + "_" + avatarSetting.lod[1].level, _e + "/" + ((at = $ == null ? void 0 : $.meshes) == null ? void 0 : at.url_lod2.replace("./", ""))),
|
|
|
|
+ $.meshes.url_lod4 && this.mshPath.set(i + "_" + avatarSetting.lod[2].level, _e + "/" + ((st = $ == null ? void 0 : $.meshes) == null ? void 0 : st.url_lod4.replace("./", "")))),
|
|
|
|
+ $.materials && $.materials.forEach(ut=>{
|
|
|
|
+ const ct = _e + "/" + ut.url;
|
|
|
|
+ this.matPath.set(ut.name, ct)
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- h.bin) {
|
|
|
|
- const C = f + "/" + h.bin.url;
|
|
|
|
- this.binPath.set(t, C);
|
|
|
|
- const A = f + "/" + h.bin.url_lod2;
|
|
|
|
- this.binPath.set(t + "_" + avatarSetting.lod[1].level, A);
|
|
|
|
- const S = f + "/" + h.bin.url_lod4;
|
|
|
|
- this.binPath.set(t + "_" + avatarSetting.lod[2].level, S)
|
|
|
|
|
|
+ $.bin) {
|
|
|
|
+ const ut = _e + "/" + $.bin.url;
|
|
|
|
+ this.binPath.set(i, ut);
|
|
|
|
+ const ct = _e + "/" + $.bin.url_lod2;
|
|
|
|
+ this.binPath.set(i + "_" + avatarSetting.lod[1].level, ct);
|
|
|
|
+ const lt = _e + "/" + $.bin.url_lod4;
|
|
|
|
+ this.binPath.set(i + "_" + avatarSetting.lod[2].level, lt)
|
|
}
|
|
}
|
|
- return h.textures && h.textures.forEach(C=>{
|
|
|
|
- const A = f + "/" + C.url;
|
|
|
|
- this.texPath.set(C.url, A);
|
|
|
|
- const S = this.meshTexList.get(h.components.url);
|
|
|
|
- C.type === "png" && (S ? S.find(P=>P === C.name) || S.push(C.url) : this.meshTexList.set(t, [C.name]))
|
|
|
|
|
|
+ return $.textures && $.textures.forEach(ut=>{
|
|
|
|
+ const ct = _e + "/" + ut.url;
|
|
|
|
+ this.texPath.set(ut.url, ct);
|
|
|
|
+ const lt = this.meshTexList.get($.components.url);
|
|
|
|
+ ut.type === "png" && (lt ? lt.find(ft=>ft === ut.name) || lt.push(ut.url) : this.meshTexList.set(i, [ut.name]))
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- o(d)
|
|
|
|
|
|
+ c(et)
|
|
}
|
|
}
|
|
- ).catch(h=>{
|
|
|
|
- logger.error(`[Engine] parse json file error,${h}`)
|
|
|
|
|
|
+ ).catch($=>{
|
|
|
|
+ d(`[Engine] parse json file error,${$}`)
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
- ).catch(c=>{
|
|
|
|
- logger.error(`[Engine] ulrtransform error, cannot find resource in db,${c}`)
|
|
|
|
|
|
+ ).catch(j=>{
|
|
|
|
+ d(`[Engine] ulrtransform error, cannot find resource in db,${j}`)
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
- async parse(e, t) {
|
|
|
|
- const r = [];
|
|
|
|
- t.forEach(n=>{
|
|
|
|
- this._setAnimationList(n.id, n.animations),
|
|
|
|
- r.push(this.getParsedUrl(e, n.id, n.url)),
|
|
|
|
- n.components.forEach(o=>{
|
|
|
|
- o.units.forEach(a=>{
|
|
|
|
- r.push(this.getParsedUrl(e, a.name, a.url))
|
|
|
|
|
|
+ async parse(e, i) {
|
|
|
|
+ const o = [];
|
|
|
|
+ i.forEach(s=>{
|
|
|
|
+ this._setAnimationList(s.id, s.animations),
|
|
|
|
+ o.push(this.getParsedUrl(e, s.id, s.url)),
|
|
|
|
+ s.components.forEach(c=>{
|
|
|
|
+ c.name === "pendant" ? c.units.forEach(d=>{
|
|
|
|
+ this._parsePendant(d.id, d.url)
|
|
|
|
+ }
|
|
|
|
+ ) : c.units.forEach(d=>{
|
|
|
|
+ o.push(this.getParsedUrl(e, d.name, d.url))
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- await Promise.all(r)
|
|
|
|
|
|
+ await Promise.all(o)
|
|
}
|
|
}
|
|
- _setAnimationList(e, t) {
|
|
|
|
- t ? t.forEach(r=>{
|
|
|
|
- this.aniPath.set(e + "_" + r.name, r.url)
|
|
|
|
|
|
+ _setAnimationList(e, i) {
|
|
|
|
+ i ? i.forEach(o=>{
|
|
|
|
+ this.aniPath.set(e + "_" + o.name, o.url)
|
|
}
|
|
}
|
|
) : logger.error("[Engine] no animation list exist, please check config for details")
|
|
) : logger.error("[Engine] no animation list exist, please check config for details")
|
|
}
|
|
}
|
|
disposeContainer() {
|
|
disposeContainer() {
|
|
- this.containers.forEach((e,t)=>{
|
|
|
|
- e.xReferenceCount < 1 && (this.enableShareTexture && e.textures.length > 0 && e.textures[0].xReferenceCount != null && (e.textures[0].xReferenceCount--,
|
|
|
|
- e.textures = []),
|
|
|
|
- e.dispose(),
|
|
|
|
- this.containers.delete(t))
|
|
|
|
|
|
+ const e = [];
|
|
|
|
+ this.containers.forEach((i,o)=>{
|
|
|
|
+ if (i.xReferenceCount < 1) {
|
|
|
|
+ if (this.enableShareTexture && i.textures.length > 0) {
|
|
|
|
+ for (let s = 0; s < i.textures.length; ++s)
|
|
|
|
+ i.textures[s].xReferenceCount != null ? i.textures[s].xReferenceCount-- : i.textures[s].xReferenceCount = 0,
|
|
|
|
+ i.textures[s]._parentContainer = null;
|
|
|
|
+ i.textures = []
|
|
|
|
+ }
|
|
|
|
+ e.push(o)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- this._sharedTex.forEach((e,t)=>{
|
|
|
|
- e.xReferenceCount == 0 && (e.dispose(),
|
|
|
|
- this._sharedTex.delete(t))
|
|
|
|
|
|
+ e.forEach(i=>{
|
|
|
|
+ var o, s;
|
|
|
|
+ (o = this.containers.get(i)) == null || o.removeAllFromScene(),
|
|
|
|
+ (s = this.containers.get(i)) == null || s.dispose(),
|
|
|
|
+ this.containers.delete(i)
|
|
|
|
+ }
|
|
|
|
+ ),
|
|
|
|
+ this._sharedTex.forEach((i,o)=>{
|
|
|
|
+ i.xReferenceCount == 0 && (i.dispose(),
|
|
|
|
+ this._sharedTex.delete(o))
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -133,175 +171,172 @@ export default class XAvatarLoader {
|
|
getMeshUrl(e) {
|
|
getMeshUrl(e) {
|
|
return this.mshPath.get(e)
|
|
return this.mshPath.get(e)
|
|
}
|
|
}
|
|
- _getSourceKey(e, t) {
|
|
|
|
- return t && avatarSetting.lod[t] ? e + avatarSetting.lod[t].fileName.split(".")[0] : e
|
|
|
|
|
|
+ _getSourceKey(e, i) {
|
|
|
|
+ return i && avatarSetting.lod[i] ? e + avatarSetting.lod[i].fileName.split(".")[0] : e
|
|
}
|
|
}
|
|
- _getAnimPath(e, t) {
|
|
|
|
- let r = this.aniPath.get(t + "_animations_" + t.split("_")[1]);
|
|
|
|
- return r || (r = this.aniPath.get(t + "_" + e)),
|
|
|
|
- r
|
|
|
|
|
|
+ _getAnimPath(e, i) {
|
|
|
|
+ let o = this.aniPath.get(i + "_animations_" + i.split("_")[1]);
|
|
|
|
+ return o || (o = this.aniPath.get(i + "_" + e)),
|
|
|
|
+ o
|
|
}
|
|
}
|
|
- load(e, t, r, n) {
|
|
|
|
- return new Promise((o,a)=>{
|
|
|
|
- this.loadGlb(e, t, r).then(s=>s ? o(s) : a("[Engine] container load failed")).catch(()=>a("[Engine] container load failed"))
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
|
|
+ load(e, i, o, s) {
|
|
|
|
+ return this.loadGlb(e, i, o).then(c=>c || Promise.reject("[Engine] container load failed")).catch(()=>Promise.reject("[Engine] container load failed"))
|
|
}
|
|
}
|
|
- _searchAnimation(e, t) {
|
|
|
|
- let r;
|
|
|
|
- return this.containers.forEach((n,o)=>{
|
|
|
|
- const a = t.split("_")[0];
|
|
|
|
- o.indexOf(a) != -1 && o.indexOf(e) != -1 && (r = n)
|
|
|
|
|
|
+ _searchAnimation(e, i) {
|
|
|
|
+ let o;
|
|
|
|
+ return this.containers.forEach((s,c)=>{
|
|
|
|
+ const d = i.split("_")[0];
|
|
|
|
+ c.indexOf(d) != -1 && c.indexOf(e) != -1 && (o = s)
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- r
|
|
|
|
|
|
+ o
|
|
}
|
|
}
|
|
- loadAnimRes(e, t, r) {
|
|
|
|
- return new Promise((n,o)=>{
|
|
|
|
- const a = this._getAnimPath(t, r)
|
|
|
|
- , s = getAnimationKey(t, r);
|
|
|
|
- if (a && this.containers.get(a))
|
|
|
|
- return n(this.containers.get(a));
|
|
|
|
- if (a)
|
|
|
|
- this._loadGlbFromBlob(e, s, a).then(l=>l.animationGroups.length == 0 ? (this.containers.delete(s),
|
|
|
|
- l.dispose(),
|
|
|
|
- Promise.reject("container does not contains animation data")) : n(l));
|
|
|
|
- else
|
|
|
|
- return o("no such url")
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
|
|
+ loadAnimRes(e, i, o) {
|
|
|
|
+ const s = this._getAnimPath(i, o)
|
|
|
|
+ , c = getAnimationKey(i, o);
|
|
|
|
+ return s && this.containers.get(s) ? Promise.resolve(this.containers.get(s)) : s ? this._loadGlbFromBlob(e, c, s).then(d=>d.animationGroups.length == 0 ? (this.containers.delete(c),
|
|
|
|
+ d.dispose(),
|
|
|
|
+ Promise.reject("container does not contains animation data")) : d) : Promise.reject("no such url")
|
|
}
|
|
}
|
|
- loadGlb(e, t, r) {
|
|
|
|
- let n = this.getMeshUrl(this._getSourceKey(t, r));
|
|
|
|
- return !n && this.fillEmptyLod && (r = 0,
|
|
|
|
- n = this.getMeshUrl(this._getSourceKey(t, r))),
|
|
|
|
- n && this.containers.get(n) ? Promise.resolve(this.containers.get(n)) : n ? this._enableIdb ? Promise.resolve(this._loadGlbFromBlob(e, this._getSourceKey(t, r), n)) : Promise.resolve(this._loadGlbFromUrl(e, this._getSourceKey(t, r), n)) : Promise.reject("no such url")
|
|
|
|
|
|
+ loadGlb(e, i, o) {
|
|
|
|
+ let s = this.getMeshUrl(this._getSourceKey(i, o));
|
|
|
|
+ return !s && this.fillEmptyLod && (o = 0,
|
|
|
|
+ s = this.getMeshUrl(this._getSourceKey(i, o))),
|
|
|
|
+ s && this.containers.get(s) ? Promise.resolve(this.containers.get(s)) : s ? this._enableIdb ? this._loadGlbFromBlob(e, this._getSourceKey(i, o), s) : this._loadGlbFromUrl(e, this._getSourceKey(i, o), s) : Promise.reject("no such url")
|
|
}
|
|
}
|
|
- loadGltf(e, t, r, n) {
|
|
|
|
- const o = this._getSourceKey(t, r || 0);
|
|
|
|
- let a = this.getGltfPath(o);
|
|
|
|
- return !a && this.fillEmptyLod && (a = this.getGltfPath(t)),
|
|
|
|
- a && this.containers.get(a) ? Promise.resolve(this.containers.get(a)) : this._enableIdb ? this._loadGltfFromBlob(e, t, r, n) : a ? this._loadGltfFromUrl(e, t, a.replace(t + ".gltf", "")) : Promise.reject()
|
|
|
|
|
|
+ loadGltf(e, i, o, s) {
|
|
|
|
+ const c = this._getSourceKey(i, o || 0);
|
|
|
|
+ let d = this.getGltfPath(c);
|
|
|
|
+ return !d && this.fillEmptyLod && (d = this.getGltfPath(i)),
|
|
|
|
+ d && this.containers.get(d) ? Promise.resolve(this.containers.get(d)) : this._enableIdb ? this._loadGltfFromBlob(e, i, o, s) : d ? this._loadGltfFromUrl(e, i, d.replace(i + ".gltf", "")) : Promise.reject()
|
|
}
|
|
}
|
|
loadSubsequence() {}
|
|
loadSubsequence() {}
|
|
loadVAT() {}
|
|
loadVAT() {}
|
|
getResourceName(e) {
|
|
getResourceName(e) {
|
|
return this.meshTexList.get(e)
|
|
return this.meshTexList.get(e)
|
|
}
|
|
}
|
|
- _loadGltfFromUrl(e, t, r) {
|
|
|
|
- return BABYLON.SceneLoader.LoadAssetContainerAsync(r, t + ".gltf", e.Scene, null, ".gltf")
|
|
|
|
|
|
+ _loadGltfFromUrl(e, i, o) {
|
|
|
|
+ return BABYLON.SceneLoader.LoadAssetContainerAsync(o, i + ".gltf", e.Scene, null, ".gltf")
|
|
}
|
|
}
|
|
- _loadGlbFromBlob(e, t, r) {
|
|
|
|
- return new Promise((n,o)=>{
|
|
|
|
- e.urlTransformer(r).then(a=>{
|
|
|
|
- BABYLON.SceneLoader.LoadAssetContainerAsync("", a, e.Scene, null, ".glb").then(s=>{
|
|
|
|
- if (s) {
|
|
|
|
- if (this.enableShareTexture && s.textures.length > 0) {
|
|
|
|
- const l = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t
|
|
|
|
- , u = this._sharedTex.get(l);
|
|
|
|
- u ? (s.meshes[1].material._albedoTexture = u,
|
|
|
|
- s.textures.forEach(c=>{
|
|
|
|
- c.dispose()
|
|
|
|
|
|
+ _loadGlbFromBlob(e, i, o) {
|
|
|
|
+ return e.urlTransformer(o).then(s=>BABYLON.SceneLoader.LoadAssetContainerAsync("", s, e.Scene, null, ".glb").then(c=>{
|
|
|
|
+ if (c) {
|
|
|
|
+ if (this.containers.get(o))
|
|
|
|
+ return c.dispose(),
|
|
|
|
+ this.containers.get(o);
|
|
|
|
+ if (c.addAllToScene(),
|
|
|
|
+ this.enableShareTexture && c.textures.length > 0) {
|
|
|
|
+ const d = [];
|
|
|
|
+ let _ = !1;
|
|
|
|
+ c.meshes.forEach(b=>{
|
|
|
|
+ if (b.material) {
|
|
|
|
+ const k = b.material._albedoTexture;
|
|
|
|
+ if (k) {
|
|
|
|
+ let j = k.name;
|
|
|
|
+ j = j.replace(" (Base Color)", "").split(".")[0];
|
|
|
|
+ const $ = this._sharedTex.get(j);
|
|
|
|
+ $ ? (_ = !0,
|
|
|
|
+ b.material._albedoTexture = $,
|
|
|
|
+ d.push($),
|
|
|
|
+ $._parentContainer = c,
|
|
|
|
+ $.xReferenceCount++) : (this._sharedTex.set(j, k),
|
|
|
|
+ c.textures[0].xReferenceCount = 1)
|
|
}
|
|
}
|
|
- ),
|
|
|
|
- s.textures = [u],
|
|
|
|
- u.xReferenceCount++) : (this._sharedTex.set(l, s.textures[0]),
|
|
|
|
- s.textures[0].xReferenceCount = 1)
|
|
|
|
- }
|
|
|
|
- return s.addAllToScene(),
|
|
|
|
- s.xReferenceCount = 0,
|
|
|
|
- s.meshes.forEach(l=>{
|
|
|
|
- l.setEnabled(!1)
|
|
|
|
}
|
|
}
|
|
- ),
|
|
|
|
- this.containers.set(r, s),
|
|
|
|
- n(s)
|
|
|
|
- } else
|
|
|
|
- o("glb file load failed")
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- _loadGlbFromUrl(e, t, r) {
|
|
|
|
- return new Promise((n,o)=>{
|
|
|
|
- BABYLON.SceneLoader.LoadAssetContainerAsync("", r, e.Scene, null, ".glb").then(a=>{
|
|
|
|
- if (a) {
|
|
|
|
- if (a.addAllToScene(),
|
|
|
|
- a.meshes.forEach(s=>{
|
|
|
|
- s.setEnabled(!1)
|
|
|
|
}
|
|
}
|
|
),
|
|
),
|
|
- this.enableShareTexture && a.textures.length > 0) {
|
|
|
|
- const s = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t
|
|
|
|
- , l = this._sharedTex.get(s);
|
|
|
|
- l ? (a.meshes[1].material._albedoTexture = l,
|
|
|
|
- a.textures.forEach(u=>{
|
|
|
|
- u.dispose()
|
|
|
|
- }
|
|
|
|
- ),
|
|
|
|
- a.textures = [l],
|
|
|
|
- l.xReferenceCount++) : (this._sharedTex.set(s, a.textures[0]),
|
|
|
|
- a.textures[0].xReferenceCount = 1)
|
|
|
|
|
|
+ _ && (c.textures.forEach(b=>{
|
|
|
|
+ e.Scene.removeTexture(b),
|
|
|
|
+ b.dispose()
|
|
}
|
|
}
|
|
- return a.xReferenceCount = 0,
|
|
|
|
- this.containers.set(r, a),
|
|
|
|
- n(a)
|
|
|
|
- } else
|
|
|
|
- o("glb file load failed")
|
|
|
|
|
|
+ ),
|
|
|
|
+ c.textures = d)
|
|
|
|
+ }
|
|
|
|
+ return c.xReferenceCount = 0,
|
|
|
|
+ c.meshes.forEach(d=>{
|
|
|
|
+ d.setEnabled(!1)
|
|
|
|
+ }
|
|
|
|
+ ),
|
|
|
|
+ this.containers.set(o, c),
|
|
|
|
+ Promise.resolve(c)
|
|
|
|
+ } else
|
|
|
|
+ return Promise.reject("glb file load failed")
|
|
|
|
+ }
|
|
|
|
+ ))
|
|
|
|
+ }
|
|
|
|
+ _loadGlbFromUrl(e, i, o) {
|
|
|
|
+ return BABYLON.SceneLoader.LoadAssetContainerAsync("", o, e.Scene, null, ".glb").then(s=>s ? (s.addAllToScene(),
|
|
|
|
+ s.meshes.forEach(c=>{
|
|
|
|
+ c.setEnabled(!1)
|
|
|
|
+ }
|
|
|
|
+ ),
|
|
|
|
+ this.enableShareTexture && s.textures.length > 0 ? (s.meshes.forEach(c=>{
|
|
|
|
+ if (c.material) {
|
|
|
|
+ const d = c.material._albedoTexture;
|
|
|
|
+ if (d) {
|
|
|
|
+ let _ = d.name;
|
|
|
|
+ _ = _.replace(" (Base Color)", "").split(".")[0];
|
|
|
|
+ const b = this._sharedTex.get(_);
|
|
|
|
+ b ? (c.material._albedoTexture = b,
|
|
|
|
+ b.xReferenceCount++) : (this._sharedTex.set(_, d),
|
|
|
|
+ s.textures[0].xReferenceCount = 1)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- )
|
|
|
|
}
|
|
}
|
|
- )
|
|
|
|
|
|
+ ),
|
|
|
|
+ s.xReferenceCount = 0,
|
|
|
|
+ this.containers.set(o, s),
|
|
|
|
+ Promise.resolve(s)) : Promise.reject("glb file load failed"),
|
|
|
|
+ s.xReferenceCount = 0,
|
|
|
|
+ this.containers.set(o, s),
|
|
|
|
+ Promise.resolve(s)) : Promise.reject("glb file load failed"))
|
|
}
|
|
}
|
|
- _loadGltfFromBlob(e, t, r, n) {
|
|
|
|
- return new Promise((o,a)=>{
|
|
|
|
- const s = [];
|
|
|
|
- let l = this._getSourceKey(t, r)
|
|
|
|
- , u = this.getGltfPath(l);
|
|
|
|
- if (!u && this.fillEmptyLod && (r = 0,
|
|
|
|
- l = this._getSourceKey(t, r),
|
|
|
|
- u = this.getGltfPath(l)),
|
|
|
|
- !u)
|
|
|
|
- return a(`[Engine] gltf path incorrect ${l},cancel.`);
|
|
|
|
- const c = this.mshPath.get(l + ".gltf");
|
|
|
|
- if (!c)
|
|
|
|
- return a("cannot find asset mshPath");
|
|
|
|
- const h = this.binPath.get(l + ".bin");
|
|
|
|
- if (!h)
|
|
|
|
- return a("cannot find asset binPath");
|
|
|
|
- if (!n) {
|
|
|
|
- const _ = this.meshTexList.get(t);
|
|
|
|
- if (!_ || _.length == 0)
|
|
|
|
- return a("cannot find texture");
|
|
|
|
- n = _[0]
|
|
|
|
|
|
+ _loadGltfFromBlob(e, i, o, s) {
|
|
|
|
+ return new Promise((c,d)=>{
|
|
|
|
+ const _ = [];
|
|
|
|
+ let b = this._getSourceKey(i, o)
|
|
|
|
+ , k = this.getGltfPath(b);
|
|
|
|
+ if (!k && this.fillEmptyLod && (o = 0,
|
|
|
|
+ b = this._getSourceKey(i, o),
|
|
|
|
+ k = this.getGltfPath(b)),
|
|
|
|
+ !k)
|
|
|
|
+ return d(`[Engine] gltf path incorrect ${b},cancel.`);
|
|
|
|
+ const j = this.mshPath.get(b + ".gltf");
|
|
|
|
+ if (!j)
|
|
|
|
+ return d("cannot find asset mshPath");
|
|
|
|
+ const $ = this.binPath.get(b + ".bin");
|
|
|
|
+ if (!$)
|
|
|
|
+ return d("cannot find asset binPath");
|
|
|
|
+ if (!s) {
|
|
|
|
+ const tt = this.meshTexList.get(i);
|
|
|
|
+ if (!tt || tt.length == 0)
|
|
|
|
+ return d("cannot find texture");
|
|
|
|
+ s = tt[0]
|
|
}
|
|
}
|
|
- const f = this.texPath.get(n + ".png");
|
|
|
|
- if (!f)
|
|
|
|
- return a();
|
|
|
|
- const d = this.texPath.get(n + "-astc.ktx");
|
|
|
|
- if (!d)
|
|
|
|
- return a();
|
|
|
|
- s.push(this._blobMapping(e, c)),
|
|
|
|
- s.push(this._blobMapping(e, h)),
|
|
|
|
- s.push(this._blobMapping(e, f)),
|
|
|
|
- s.push(this._blobMapping(e, d)),
|
|
|
|
- Promise.all(s).then(()=>{
|
|
|
|
- const _ = u.replace(l + ".gltf", "");
|
|
|
|
- BABYLON.SceneLoader.LoadAssetContainerAsync(_, l + ".gltf", e.Scene, null, ".gltf").then(g=>{
|
|
|
|
- var v;
|
|
|
|
- this.containers.set(u, g),
|
|
|
|
- g.addAllToScene(),
|
|
|
|
- g.meshes.forEach(y=>{
|
|
|
|
- y.setEnabled(!1)
|
|
|
|
|
|
+ const _e = this.texPath.get(s + ".png");
|
|
|
|
+ if (!_e)
|
|
|
|
+ return d();
|
|
|
|
+ const et = this.texPath.get(s + "-astc.ktx");
|
|
|
|
+ if (!et)
|
|
|
|
+ return d();
|
|
|
|
+ _.push(this._blobMapping(e, j)),
|
|
|
|
+ _.push(this._blobMapping(e, $)),
|
|
|
|
+ _.push(this._blobMapping(e, _e)),
|
|
|
|
+ _.push(this._blobMapping(e, et)),
|
|
|
|
+ Promise.all(_).then(()=>{
|
|
|
|
+ const tt = k.replace(b + ".gltf", "");
|
|
|
|
+ BABYLON.SceneLoader.LoadAssetContainerAsync(tt, b + ".gltf", e.Scene, null, ".gltf").then(rt=>{
|
|
|
|
+ var nt;
|
|
|
|
+ this.containers.set(k, rt),
|
|
|
|
+ rt.addAllToScene(),
|
|
|
|
+ rt.meshes.forEach(ot=>{
|
|
|
|
+ ot.setEnabled(!1)
|
|
}
|
|
}
|
|
);
|
|
);
|
|
- const m = this._sharedTex.get(t);
|
|
|
|
- m ? ((v = g.meshes[1].material._albedoTexture) == null || v.dispose(),
|
|
|
|
- g.meshes[1].material._albedoTexture = m) : this._sharedTex.set(t, g.meshes[1].material._albedoTexture),
|
|
|
|
- o(g)
|
|
|
|
|
|
+ const it = this._sharedTex.get(i);
|
|
|
|
+ it ? ((nt = rt.meshes[1].material._albedoTexture) == null || nt.dispose(),
|
|
|
|
+ rt.meshes[1].material._albedoTexture = it) : this._sharedTex.set(i, rt.meshes[1].material._albedoTexture),
|
|
|
|
+ c(rt)
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -309,10 +344,10 @@ export default class XAvatarLoader {
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|
|
- _blobMapping(e, t) {
|
|
|
|
- return new Promise((r,n)=>{
|
|
|
|
- e.urlTransformer(t).then(o=>o ? (this._mappings.set(t, o),
|
|
|
|
- r(t)) : n(`[Engine] url urlTransformer parse error ${t}`))
|
|
|
|
|
|
+ _blobMapping(e, i) {
|
|
|
|
+ return new Promise((o,s)=>{
|
|
|
|
+ e.urlTransformer(i).then(c=>c ? (this._mappings.set(i, c),
|
|
|
|
+ o(i)) : s(`[Engine] url urlTransformer parse error ${i}`))
|
|
}
|
|
}
|
|
)
|
|
)
|
|
}
|
|
}
|