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