@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.02 kB
JavaScript
import{ag as t,c as e,ah as n,ai as o,aj as _,j as s,U as i,F as r,ak as c,d as u,B as f}from"./index-DFZFpUG-.esm.min.js";import{computeSmoothNormals as a}from"./gltf-normals-BSzLZia6.esm.min.js";const l=5126,p=5123,d=5125,b=5121,m={[b]:1,[p]:2,[d]:4,[l]:4};function g(e,n){const o=e.accessors[n],_=e.bufferViews[o.bufferView].byteStride;if(void 0===_)return!1;return _!==(t[o.type]??1)*(m[o.componentType]??4)}function y(t){const e=new c(t._slice.buffer,t._slice.byteOffset,t._slice.byteLength),n=m[t._componentType]??4,o=t._componentType,_=t._componentCount,s=new r(t._count*_);for(let i=0;i<t._count;i++){const r=t._offset+i*t._stride;for(let t=0;t<_;t++){const c=r+t*n;s[i*_+t]=o===l?e.getFloat32(c,!0):o===p?e.getUint16(c,!0):5125===o?e.getUint32(c,!0):e.getUint8(c)}}return s}async function v(e,n,c,u,f){const d=c.attributes;let b=!1;for(const t in d)if(g(e,d[t])){b=!0;break}if(!b)return;const v={};let w=0;const O=(o,i)=>{const r=d[o];if(void 0===r)return{_tight:null,_count:0};if(g(e,r)){const o=function(e,n,o){const _=e.accessors[o],i=e.bufferViews[_.bufferView],r=n.buffer;return{_bufferView:_.bufferView,_stride:i.byteStride,_offset:_.byteOffset??0,_componentType:_.componentType,_componentCount:t[_.type]??1,_count:_.count,_slice:new s(r,n.byteOffset+(i.byteOffset??0),i.byteLength)}}(e,n,r),_=o._componentCount*(m[o._componentType]??4);return o._offset+_>o._stride?{_tight:y(o),_count:o._count}:{_tight:i?y(o):null,_il:o,_count:o._count}}const c=_(e,n,r);return{_tight:c._data,_count:c._count}},h=O("POSITION",!1);v._p=h._il,w=h._count;const T=O("NORMAL",!1);v._n=T._il;const x=d.TEXCOORD_0,V=void 0!==x&&e.accessors[x].componentType!==l?{_tight:(await import("./gltf-uv-denorm-Wox5EPL3.esm.min.js")).resolveUvVec2(e,n,x),_count:e.accessors[x].count}:O("TEXCOORD_0",!1);v._u=V._il;const C=O("TANGENT",!0);v._t=C._il;const N=O("TEXCOORD_1",!0);v._u2=N._il;const U=d.COLOR_0,E=void 0!==U?function(e,n,o){const _=e.accessors[o],s=_.componentType,i=m[s]??4,c=t[_.type]??4,u=e.bufferViews[_.bufferView],f=u.byteStride??c*i,a=5121===s?1/255:s===p?1/65535:1,d=(u.byteOffset??0)+(_.byteOffset??0),b=new r(4*_.count);for(let t=0;t<_.count;t++){const e=d+t*f;for(let o=0;o<4;o++){if(3===o&&c<4){b[4*t+3]=1;break}const _=e+o*i,r=s===l?n.getFloat32(_,!0):s===p?n.getUint16(_,!0):n.getUint8(_);b[4*t+o]=r*a}}return b}(e,n,U):null,j=h._tight;let B=T._tight,F=V._tight;const M=C._tight,R=N._tight,$=void 0!==c.indices?_(e,n,c.indices):null,I=$?$._data instanceof o?new o($._data):$._data instanceof s?Uint16Array.from($._data):new i($._data.buffer,$._data.byteOffset,$._count):function(t){const e=t>65535?new o(t):new i(t);for(let n=0;n<t;n++)e[n]=n;return e}(w);if(!B&&!v._n){const t=j??(v._p?y(v._p):new r(3*w));B=a(t,I,w)}F||v._u||(F=new r(2*w));return{_positions:j,_normals:B,_tangents:M,_uvs:F,_uv2s:R,_colors:E,_flatNormal:!T._tight&&!v._n,_indices:I,_vertexCount:w,_indexCount:I.length,_worldMatrix:u,_vb:v,_nodeIndex:f,_primitive:c}}function w(t,_,s,i,r,c){const a=c?._gpu??function(t,e){const n=e._vb,_=new Map,s=(e,n)=>{if(!e)return n?u(t,n,f.VERTEX):null;let o=_.get(e._bufferView);return o||_.set(e._bufferView,o=u(t,e._slice,f.VERTEX)),o},i=t=>`${t?._stride??0},${t?._offset??0}`;return{positionBuffer:s(n._p,e._positions),normalBuffer:s(n._n,e._normals),tangentBuffer:e._tangents?s(n._t,e._tangents):null,uvBuffer:s(n._u,e._uvs),uv2Buffer:e._uv2s?s(n._u2,e._uv2s):null,colorBuffer:e._colors?s(n._c,e._colors):null,indexBuffer:u(t,e._indices,f.INDEX),indexCount:e._indexCount,indexFormat:e._indices instanceof o?"uint32":"uint16",_vbLayout:n,_vbKey:`vb${i(n._p)}.${i(n._n)}.${i(n._t)}.${i(n._u)}`}}(t,_),[l,p]=_._vb._p?O(_._vb._p,_._worldMatrix):e(_._positions,_._worldMatrix),d={name:r||`gltf_mesh_${s}`,material:i,receiveShadows:!1,boundMin:l,boundMax:p,_gpu:a,_flatNormal:_._flatNormal};return n(d),h(d,_),d._cpuIndices=c?._cpuIndices??(_._indices instanceof o?_._indices:new o(_._indices)),t._dlr?.m(d,_._uv2s,_._tangents,_._colors,_._indices,a.indexFormat),d}function O(t,e){const n=new c(t._slice.buffer,t._slice.byteOffset,t._slice.byteLength);let o=1/0,_=1/0,s=1/0,i=-1/0,r=-1/0,u=-1/0;for(let c=0;c<t._count;c++){const f=t._offset+c*t._stride,a=n.getFloat32(f,!0),l=n.getFloat32(f+4,!0),p=n.getFloat32(f+8,!0);let d=a,b=l,m=p;e&&(d=e[0]*a+e[4]*l+e[8]*p+e[12],b=e[1]*a+e[5]*l+e[9]*p+e[13],m=e[2]*a+e[6]*l+e[10]*p+e[14]),d<o&&(o=d),d>i&&(i=d),b<_&&(_=b),b>r&&(r=b),m<s&&(s=m),m>u&&(u=m)}return[[o,_,s],[i,r,u]]}function h(t,e){const n=e._vb;n._p?Object.defineProperty(t,"_cpuPositions",T(n._p)):e._positions&&(t._cpuPositions=e._positions),n._n?Object.defineProperty(t,"_cpuNormals",T(n._n)):e._normals&&(t._cpuNormals=e._normals),n._u?Object.defineProperty(t,"_cpuUvs",T(n._u)):e._uvs&&(t._cpuUvs=e._uvs)}function T(t){let e;return{configurable:!0,enumerable:!0,get:()=>e??(t._cpu??=y(t)),set(t){e=t}}}export{g as accessorIsStrided,w as buildInterleavedMesh,v as buildInterleavedPartial,O as computeAabbStrided,h as installLazyCpu};
//# sourceMappingURL=gltf-interleave-CHQwKY56.esm.min.js.map