UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

3 lines (2 loc) 5.64 kB
import{r as e}from"./index-DFZFpUG-.esm.min.js";const s=(e,s)=>e.order-s.order;let t=null,n=null;function r(e,s,t,n){if(!s||t.material!==s)return n??Promise.resolve();const r=i(e,s._buildGroup,t);return n?Promise.all([n,r]).then(()=>{}):r}function i(e,s,t){if(e._z||!e.meshes.includes(t))return e._runtimeBuilds?.all().catch(()=>{})??Promise.resolve();if(function(e,s,t){for(const[n,r]of e._groups)if(n!==s){const e=r.indexOf(t);e>=0&&r.splice(e,1)}let n=e._groups.get(s);n||(n=[],e._groups.set(s,n));n.includes(t)||n.push(t)}(e,s,t),"pbr"===s._materialFamily&&(e._built||e._groups.get(s)?.r)){const s=e._runtimeBuilds??l(e),t=import("./index-DFZFpUG-.esm.min.js").then(function(e){return e.bn}).then(({rebuildScenePbrPipelines:s})=>e._z?void 0:s(e,!0)).catch(s=>{e._runtimeBuilds?._x(s)});return s.track(t)}return(e._runtimeBuilds??l(e)).queue(s,t).catch(()=>{})}function o(e,s,t){return e._z?Promise.resolve(void 0):(e._runtimeBuilds??l(e)).exclusive(s,t)}function l(r){const i={disposed:!1,error:null,active:new Set,chains:new WeakMap,generations:new WeakMap,installed:new WeakMap,installedMeshes:new Set,tail:null},o=r,l={queue:(o,a)=>{const c=(i.generations.get(a)??0)+1,f=a.material;i.generations.set(a,c);const _=i.chains.get(a),h=[i.tail,t?.get(o)].filter(e=>!!e);let m=()=>{};const g=new Promise(e=>{m=e});i.tail=g,(t??=new WeakMap).set(o,g);const b=(_?_.catch(()=>{}):Promise.resolve()).then(()=>Promise.all(h)).then(()=>async function(t,r,i,o,l,a){if(!u(t,r,i,o,l,a))return;const c=t._meshDisposables.get(o);c&&t._meshDisposables.delete(o);const f=i._rebuildSingle,_=n?.get(i),h=_?.bases.get(t)??t._groups.get(i)?.r,m=!!t._groups.get(i)?.r,g=t._disposables.length,b=t,w=b._pbrGeomContext;let v,M;try{M=await i(t,[o]),v=b._pbrGeomContext}catch(e){if(d(t,r,o,c),p(t,r),!u(t,r,i,o,l,a))return;throw e}finally{i._rebuildSingle=f,"pbr"===i._materialFamily&&m&&(b._pbrGeomContext=w)}if(!u(t,r,i,o,l,a))return d(t,r,o,c),void p(t,r);for(let e=t._renderables.length-1;e>=0;e--)t._renderables[e].mesh===o&&t._renderables.splice(e,1);if(c){for(const e of c){const s=e.p;if(s){s._disposed=!0;const e=s._owner;if(e){const t=e.indexOf(s);t>=0&&e.splice(t,1),s._owner=void 0}}}e(t.surface.engine,()=>{for(const e of c)e()})}t._renderables.push(...M.renderables),M.updater&&t._uniformUpdaters.push(M.updater);m&&function(e,s){const t=new Set(e._disposables.slice(0,s));for(let n=e._disposables.length-1;n>=s;n--)t.has(e._disposables[n])&&e._disposables.splice(n,1)}(t,g);"pbr"===i._materialFamily&&m&&v&&(b._pbrMeshGeomContexts??=new WeakMap).set(o,v);(function(e,s,t,r,i,o){let l=n?.get(t);if(!l){const e=new WeakMap,s=new WeakMap,r=(n,r,i)=>{const o=e.get(n)?.get(r);if(o)return o(n,r,i);const l=s.get(n)??n._groups.get(t)?.r;if(l)return l(n,r,i);throw new Error("Material group has not completed its initial build")};l={bases:s,dispatch:r,scenes:e},(n??=new WeakMap).set(t,l)}let a=l.scenes.get(e);a||(a=new WeakMap,l.scenes.set(e,a));a.set(r,i),l.bases.has(e)||l.bases.set(e,o??i);const c=e._groups.get(t);c&&(c.r=l.dispatch);let u=s.installed.get(r);u||(u=new Set,s.installed.set(r,u));u.add(t),s.installedMeshes.add(r)})(t,r,i,o,M.rebuildSingle,m?h??f:M.rebuildSingle),o.material._csmGen=(o.material._csmGen??0)+1;const x=t._groups.get(i);x&&!m&&(x.r=M.rebuildSingle);t._renderables.sort(s),t._renderableVersion++,t._materialEpoch++}(r,i,o,a,f,c)).catch(e=>{throw u(r,i,o,a,f,c)&&(i.error=e instanceof Error?e:new Error("Runtime mesh build failed",{cause:e})),e}).finally(()=>{m(),i.tail===g&&(i.tail=null),t?.get(o)===g&&t.delete(o)}),w=b.finally(()=>{i.chains.get(a)===w&&i.chains.delete(a)});return i.chains.set(a,w),l.track(w)},all:()=>Promise.all(i.active).then(()=>{}),track:e=>{const s=e.finally(()=>i.active.delete(s));return i.active.add(s),Promise.all(i.active).then(()=>{})},base:(e,s)=>{const t=n?.get(e);return t&&t.bases.set(r,s),t?.dispatch??s},get w(){return!!i.tail},reset:e=>{c(r,i,e),o._pbrMeshGeomContexts?.delete(e)},remove:e=>{i.generations.set(e,(i.generations.get(e)??0)+1),i.chains.delete(e),a(r,i,e),o._pbrMeshGeomContexts?.delete(e)},wait:async e=>{const s=new Set;for(const t of e){const e=i.chains.get(t);e&&s.add(e)}await Promise.all(s)},_e:(e=!0)=>{if(i.error){const s=i.error;throw e&&(i.error=null),s}},_x:e=>{i.error=e instanceof Error?e:new Error("Runtime mesh build failed",{cause:e})},_d:()=>i.disposed,exclusive:(e,s)=>{const n=[];i.tail&&n.push(i.tail);const r=t?.get(e);r&&n.push(r);const o=Promise.all(n).then(s),l=o.then(()=>{},()=>{});return i.tail=l,(t??=new WeakMap).set(e,l),l.then(()=>{i.tail===l&&(i.tail=null),t?.get(e)===l&&t.delete(e)}),o}};return r._runtimeBuilds=l,(r._beforeRender??=[]).push(()=>{l._e()}),r._disposables.push(()=>{i.disposed=!0,i.active.clear();for(const e of i.installedMeshes)c(r,i,e);for(const e of r._groups.keys())n?.get(e)?.bases.delete(r);r._runtimeBuilds=void 0,o._pbrMeshGeomContexts=void 0}),l}function a(e,s,t){const r=s.installed.get(t);if(r){for(const s of r)n?.get(s)?.scenes.get(e)?.delete(t);s.installed.delete(t),s.installedMeshes.delete(t)}}function c(e,s,t){a(e,s,t)}function u(e,s,t,n,r,i){return!s.disposed&&s.generations.get(n)===i&&e.meshes.includes(n)&&n.material===r&&r._buildGroup===t}function d(s,t,n,r){const i=s._meshDisposables.get(n);if(i&&i!==r){s._meshDisposables.delete(n);for(const e of i)e()}if(r)if(s.meshes.includes(n))s._meshDisposables.set(n,r);else if(t.disposed)for(const e of r)e();else e(s.surface.engine,()=>{for(const e of r)e()})}function p(e,s){if(!s.disposed)return;const t=e._disposables.splice(0);for(const e of t)e()}export{r as A,i as B,o as X}; //# sourceMappingURL=scene-runtime-mesh-build-DnekFvq1.esm.min.js.map