@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.12 kB
JavaScript
import{S as n,aw as e,h as i}from"./index-DFZFpUG-.esm.min.js";let t=null,o=null,r=null;function a(n){t!==n._device&&(t=n._device,o=null,r=null)}function l(n){return`${`enable primitive_index;\nstruct SceneUniforms { viewProjection: mat4x4f, fragmentCoord: vec2f }\n var<uniform> scene: SceneUniforms;\nstruct PickDiscardInput {\nworldPos: vec3f,\nfragmentCoord: vec2f,\npickId: u32,\nthinInstanceIndex: u32,\nhasThinInstance: u32,\ninstanceExtras: vec4f,\n}\n${n?.storage?.map((n,e)=>` var<storage, read> ${n.name}: ${n.type};`).join("\n")??""}\n${n?.wgsl??"fn shouldDiscardPick(input: PickDiscardInput) -> bool {\nreturn false;\n}"}\nstruct O {\n p: vec4f,\n id: u32,\n w: vec3f,\n ti: u32,\n hasTi: u32,\n extras: vec4f,\n local: vec3f,\n}\nstruct F { color: vec4f, depth: f32, detail: vec4u }\n fn fs(i: O, primitiveIndex: u32) -> F {\nif (shouldDiscardPick(PickDiscardInput(i.w, scene.fragmentCoord, i.id, i.ti, i.hasTi, i.extras))) { discard; }\nlet r = f32((i.id >> 16u) & 255u) / 255.0;\nlet g = f32((i.id >> 8u) & 255u) / 255.0;\nlet b = f32(i.id & 255u) / 255.0;\nreturn F(vec4f(r, g, b, 1), i.p.z, vec4u(primitiveIndex, bitcast<u32>(i.local.x), bitcast<u32>(i.local.y), bitcast<u32>(i.local.z)));\n}`}\nstruct M { world: mat4x4f, pickId: u32 }\n var<uniform> m: M;\n fn vs( position: vec3f) -> O {\nvar o: O;\nlet w = (m.world * vec4f(position, 1)).xyz;\no.p = scene.viewProjection * vec4f(w, 1);\no.id = m.pickId;\no.w = w;\no.ti = 0xffffffffu;\no.hasTi = 0u;\no.extras = vec4f(0);\no.local = position;\nreturn o;\n}`}const c={arrayStride:12,attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]};function u(t,r,u,s){const d=t._device,f=d.createShaderModule({label:`${s}-shader`,code:l(r)}),p=function(e){return a(e),o??=i(e,"picking-mesh-bgl",n.VERTEX|n.FRAGMENT)}(t);return d.createRenderPipeline({label:`${s}-pipeline`,layout:d.createPipelineLayout({bindGroupLayouts:u?[e(t),p,u]:[e(t),p]}),vertex:{module:f,entryPoint:"vs",buffers:[c]},fragment:{module:f,entryPoint:"fs",targets:[{format:"rgba8unorm"},{format:"r32float"},{format:"rgba32uint"}]},depthStencil:{format:"depth24plus",depthCompare:"greater",depthWriteEnabled:!0},primitive:{topology:"triangle-list",cullMode:"none"}})}function s(e,i){a(e);const t=i?i.key:"default",o=r??=new Map,l=o.get(t);if(l)return l;const c=i??null,s=c?function(e,i){return i.storage?.length?e._device.createBindGroupLayout({label:`picking-discard-${i.key}-bgl`,entries:i.storage.map((e,i)=>({binding:i,visibility:n.FRAGMENT,buffer:{type:"read-only-storage"}}))}):null}(e,c):null,d=u(e,c,s,c?`picking-${c.key}-detailed`:"picking-detailed"),f={regularPipeline:d,thinInstancePipeline:d,discardBGL:s,detailed:!0};return o.set(t,f),f}export{s as getPickingPipelineSet};
//# sourceMappingURL=picking-detailed-pipeline-D12DWvJM.esm.min.js.map