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.26 kB
import{S as n,aw as t,h as e}from"./index-DFZFpUG-.esm.min.js";let i=null,o=null,r=null;function a(n){i!==n._device&&(i=n._device,o=null,r=null)}const s={arrayStride:12,attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]};function c(i,r,c,u){const l=i._device,d=l.createShaderModule({label:`${u}-shader`,code:(f=r?{discardWgsl:r.wgsl,storage:r.storage}:void 0,`\n\nstruct SceneUniforms {\nviewProjection: mat4x4f,\nfragmentCoord: vec2f,\n};\n@group(0) @binding(0) var<uniform> scene: SceneUniforms;\n\nstruct MeshUniforms {\nworld: mat4x4f,\npickId: u32,\n};\n@group(1) @binding(0) var<uniform> mesh: MeshUniforms;\n\nstruct PickDiscardInput {\nworldPos: vec3f,\nfragmentCoord: vec2f,\npickId: u32,\nthinInstanceIndex: u32,\nhasThinInstance: u32,\ninstanceExtras: vec4f,\n};\n\n${function(n){const t=n?.storage;return t?.length?t.map((n,t)=>`@group(2) @binding(${t}) var<storage, read> ${n.name}: ${n.type};`).join("\n"):""}(f)}\n${f?.discardWgsl??"\nfn shouldDiscardPick(input: PickDiscardInput) -> bool {\nreturn false;\n}\n"}\n\nstruct VsOut {\n@builtin(position) p: vec4f,\n@location(0) @interpolate(flat) pickId: u32,\n@location(1) worldPos: vec3f,\n@location(2) @interpolate(flat) thinInstanceIndex: u32,\n@location(3) @interpolate(flat) hasThinInstance: u32,\n@location(4) @interpolate(flat) instanceExtras: vec4f,\n};\nstruct FsOut { @location(0) color: vec4f, @location(1) depth: f32 };\n@fragment fn fs(input: VsOut) -> FsOut {\nif (shouldDiscardPick(PickDiscardInput(input.worldPos, scene.fragmentCoord, input.pickId, input.thinInstanceIndex, input.hasThinInstance, input.instanceExtras))) { discard; }\nlet id = input.pickId;\nlet r = f32((id >> 16u) & 0xFFu) / 255.0;\nlet g = f32((id >> 8u) & 0xFFu) / 255.0;\nlet b = f32(id & 0xFFu) / 255.0;\nreturn FsOut(vec4f(r, g, b, 1.0), input.p.z);\n}\n\n@vertex fn vs(@location(0) position: vec3f) -> VsOut {\nvar out: VsOut;\nlet wp = (mesh.world * vec4f(position, 1.0)).xyz;\nout.p = scene.viewProjection * vec4f(wp, 1.0);\nout.pickId = mesh.pickId;\nout.worldPos = wp;\nout.thinInstanceIndex = 0xffffffffu;\nout.hasThinInstance = 0u;\nout.instanceExtras = vec4f(0.0);\nreturn out;\n}\n`)});var f;const p=function(t){return a(t),o??=e(t,"picking-mesh-bgl",n.VERTEX|n.FRAGMENT)}(i),g=l.createPipelineLayout({label:`${u}-pipeline-layout`,bindGroupLayouts:c?[t(i),p,c]:[t(i),p]});return l.createRenderPipeline({label:`${u}-pipeline`,layout:g,vertex:{module:d,entryPoint:"vs",buffers:[s]},fragment:{module:d,entryPoint:"fs",targets:[{format:"rgba8unorm"},{format:"r32float"}]},depthStencil:{format:"depth24plus",depthCompare:"greater",depthWriteEnabled:!0},primitive:{topology:"triangle-list",cullMode:"none"},multisample:{count:1}})}function u(t,e){a(t);const i=e?`discard:${e.key}`:"default",o=r??=new Map,s=o.get(i);if(s)return s;const u=e??null,l=u?.storage?.length?function(t,e){return t._device.createBindGroupLayout({label:`picking-discard-${e.key}-bgl`,entries:(e.storage??[]).map((t,e)=>({binding:e,visibility:n.FRAGMENT,buffer:{type:"read-only-storage"}}))})}(t,u):null,d=c(t,u,l,u?`picking-${u.key}`:"picking"),f={regularPipeline:d,thinInstancePipeline:d,discardBGL:l};return o.set(i,f),f}export{u as getPickingPipelineSet}; //# sourceMappingURL=picking-pipeline-BHt0mmB6.esm.min.js.map