@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) • 4.98 kB
JavaScript
import{an as t,c as e,ao as n,ap as o,aq as _,p as s,U as i,F as c,ar as r,f as u,B as f}from"./index-B8IgtevW.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 r(t._slice.buffer,t._slice.byteOffset,t._slice.byteLength),n=m[t._componentType]??4,o=t._componentType,_=t._componentCount,s=new c(t._count*_);for(let i=0;i<t._count;i++){const c=t._offset+i*t._stride;for(let t=0;t<_;t++){const r=c+t*n;s[i*_+t]=o===l?e.getFloat32(r,!0):o===p?e.getUint16(r,!0):5125===o?e.getUint32(r,!0):e.getUint8(r)}}return s}async function v(e,n,r,u,f){const d=r.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 c=d[o];if(void 0===c)return{_tight:null,_count:0};if(g(e,c)){const o=function(e,n,o){const _=e.accessors[o],i=e.bufferViews[_.bufferView],c=n.buffer;return{_bufferView:_.bufferView,_stride:i.byteStride,_offset:_.byteOffset??0,_componentType:_.componentType,_componentCount:t[_.type]??1,_count:_.count,_slice:new s(c,n.byteOffset+(i.byteOffset??0),i.byteLength)}}(e,n,c),_=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 r=_(e,n,c);return{_tight:r._data,_count:r._count}},h=O("POSITION",!1);v._p=h._il,w=h._count;const T=O("NORMAL",!1);v._n=T._il;const V=d.TEXCOORD_0,x=void 0!==V&&e.accessors[V].componentType!==l?{_tight:(await import("./gltf-uv-denorm-BAE_IFxc.esm.min.js")).resolveUvVec2(e,n,V),_count:e.accessors[V].count}:O("TEXCOORD_0",!1);v._u=x._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,r=t[_.type]??4,u=e.bufferViews[_.bufferView],f=u.byteStride??r*i,a=5121===s?1/255:s===p?1/65535:1,d=(u.byteOffset??0)+(_.byteOffset??0),b=new c(4*_.count);for(let t=0;t<_.count;t++){const e=d+t*f;for(let o=0;o<4;o++){if(3===o&&r<4){b[4*t+3]=1;break}const _=e+o*i,c=s===l?n.getFloat32(_,!0):s===p?n.getUint16(_,!0):n.getUint8(_);b[4*t+o]=c*a}}return b}(e,n,U):null,B=h._tight;let F=T._tight,j=x._tight;const R=C._tight,$=N._tight,I=void 0!==r.indices?_(e,n,r.indices):null,L=I?I._data instanceof o?new o(I._data):I._data instanceof s?Uint16Array.from(I._data):new i(I._data.buffer,I._data.byteOffset,I._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(!F&&!v._n){const t=B??(v._p?y(v._p):new c(3*w));F=a(t,L,w)}j||v._u||(j=new c(2*w));return{_positions:B,_normals:F,_tangents:R,_uvs:j,_uv2s:$,_colors:E,_flatNormal:!T._tight&&!v._n,_indices:L,_vertexCount:w,_indexCount:L.length,_worldMatrix:u,_vb:v,_nodeIndex:f,_primitive:r}}function w(t,_,s,i,c,r){const a=r?._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):e(_._positions),d=n({name:c||`gltf_mesh_${s}`,material:i,receiveShadows:!1,boundMin:l,boundMax:p,_gpu:a,_flatNormal:_._flatNormal});return h(d,_),d._cpuIndices=r?._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 r(t._slice.buffer,t._slice.byteOffset,t._slice.byteLength);let o=1/0,_=1/0,s=1/0,i=-1/0,c=-1/0,u=-1/0;for(let r=0;r<t._count;r++){const f=t._offset+r*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>c&&(c=b),m<s&&(s=m),m>u&&(u=m)}return[[o,_,s],[i,c,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-Dk166jq6.esm.min.js.map