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) 3.75 kB
import{n as e}from"./index-B8IgtevW.esm.min.js";import{S as t,m as r}from"./skeleton-fragment-PDCP12cv.esm.min.js";let n=null,o=null,i=null,s=null;const u={arrayStride:12,attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]};function a(e){return i??=e._device.createBindGroupLayout({label:"picking-deform-empty-bgl",entries:[]})}function f(e,t,n,o){const i=[];n&&i.push("var morphedPos = position;\nfor (var i = 0u; i < morph.count; i = i + 1u) {\nlet b = (i * morph.vertexCount + vertexIndex) * 6u;\nmorphedPos = morphedPos + morph.weights[i] * vec3<f32>(morphDeltas.d[b], morphDeltas.d[b + 1u], morphDeltas.d[b + 2u]);\n}"),e&&i.push(`var finalWorld = ${o};`,r(t,o));const s=e?"finalWorld":o;return i.push(`let projectedTransform = ${s};`,`let projectedWorld = (${s} * vec4f(${n?"morphedPos":"position"}, 1.0)).xyz;`),i.join("\n")}function l(e,t){if(!e)return[];const r=[{arrayStride:16,attributes:[{shaderLocation:1,offset:0,format:"uint32x4"}]},{arrayStride:16,attributes:[{shaderLocation:2,offset:0,format:"float32x4"}]}];return t&&r.push({arrayStride:16,attributes:[{shaderLocation:3,offset:0,format:"uint32x4"}]},{arrayStride:16,attributes:[{shaderLocation:4,offset:0,format:"float32x4"}]}),r}function d(r,n,o,i){const s=[];let d=0;n&&s.push({binding:d++,visibility:e.VERTEX,texture:{sampleType:"unfilterable-float"}}),i&&s.push({binding:d++,visibility:e.VERTEX,buffer:{type:"read-only-storage"}},{binding:d,visibility:e.VERTEX,buffer:{type:"read-only-storage"}});const p=`deform-${n?o?"skin8":"skin4":"noskin"}-${i?"morph":"nomorph"}`,c=r._device.createBindGroupLayout({label:`picking-${p}-bgl`,entries:s}),h=function(e,r){const n=[];let o=0;return e&&n.push(t,`@group(3) @binding(${o++}) var boneSampler: texture_2d<f32>;`),r&&n.push("struct morphUniforms {\ncount: u32,\nvertexCount: u32,\n_p0: u32,\n_p1: u32,\nweights: array<f32>,\n}\nstruct morphDeltasUniforms {\nd: array<f32>,\n}",`@group(3) @binding(${o++}) var<storage, read> morphDeltas: morphDeltasUniforms;`,`@group(3) @binding(${o}) var<storage, read> morph: morphUniforms;`),n.join("\n")}(n,i),m=function(e,t,r){let n="";return e&&(n+=", @location(1) joints: vec4<u32>, @location(2) weights: vec4<f32>",t&&(n+=", @location(3) joints1: vec4<u32>, @location(4) weights1: vec4<f32>")),r&&(n+=", @builtin(vertex_index) vertexIndex: u32"),n}(n,o,i);return{key:p,shader:{regularDeclarations:h,thinDeclarations:h,regularInputs:m,thinInputs:m,regularBody:f(n,o,i,"mesh.world"),thinBody:f(n,o,i,"world")},vertexBuffers:l(n,o),regularBGL:c,thinBGL:c,_layouts:(e,t)=>[...t.slice(0,2),t[2]??a(e),c],_buffers:[u,...l(n,o)]}}function p(e,t){if(t.vat)return null;const r=t.skeleton??null,u=t.morphTargets??null;return r||u?function(e,t,r,u){n!==e._device&&(n=e._device,o=null,i=null,s=null);const a=`${t?r?8:4:0}-${u?1:0}`,f=o??=new Map;let l=f.get(a);return l||(l=d(e,t,r,u),f.set(a,l)),l}(e,!!r,!(!r?.joints1Buffer||!r.weights1Buffer),!!u):null}function c(e,t,r,n,o,i){const u=n.skeleton,f=n.morphTargets,l=[];let d=0;if(u&&l.push({binding:d++,resource:u.boneTexture.createView()}),f&&l.push({binding:d++,resource:{buffer:f.deltasBuffer}},{binding:d,resource:{buffer:f.weightsBuffer}}),i||t.setBindGroup(2,function(e){return s??=e._device.createBindGroup({label:"picking-deform-empty-bg",layout:a(e),entries:[]})}(e)),t.setBindGroup(3,e._device.createBindGroup({label:"picking-deform-bg",layout:r.getBindGroupLayout(3),entries:l})),u){let e=o;t.setVertexBuffer(e++,u.jointsBuffer),t.setVertexBuffer(e++,u.weightsBuffer),u.joints1Buffer&&u.weights1Buffer&&(t.setVertexBuffer(e++,u.joints1Buffer),t.setVertexBuffer(e,u.weights1Buffer))}}export{c as bindDeformPickingProjection,p as getDeformPickingProjection}; //# sourceMappingURL=deform-picking-projection-BQbR83dT.esm.min.js.map