@fleox/agent3d 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -13
- package/changelog.json +26 -0
- package/dist/agent/agent3d.mjs +228 -53
- package/dist/agent/chunks/{assets-BUUM9TUB.mjs → assets-YBkgdfgy.mjs} +27 -8
- package/dist/agent/chunks/{browser-Br1tURgt.mjs → browser-Dil7VM5m.mjs} +1 -1
- package/dist/agent/chunks/{cdp-Bdtm4fBN.mjs → cdp-DLEis_Z3.mjs} +1 -1
- package/dist/agent/chunks/{check-CfZcfaPs.mjs → check-DP9fRYbK.mjs} +64 -4
- package/dist/agent/chunks/depth-BZT4gseQ.mjs +483 -0
- package/dist/agent/chunks/depth-CD_ql3QJ.mjs +190 -0
- package/dist/agent/chunks/{export-BHugc2H7.mjs → export-bJwh2SqG.mjs} +12 -6
- package/dist/agent/chunks/{imageCodec-QM0EXQDJ.mjs → imageCodec-DeGfmBp3.mjs} +3 -3
- package/dist/agent/chunks/{objects-DBAws7uf.mjs → objects-DuytRxiC.mjs} +3 -3
- package/dist/agent/chunks/{optimizeSizing-CkZ3fZRp.mjs → optimizeSizing-B-BBiUkD.mjs} +51 -3
- package/dist/agent/chunks/{package-fw4h5vsh.mjs → package-fMbw9UGh.mjs} +2 -1
- package/dist/agent/chunks/{render-EHb40avl.mjs → render-B05DU4Q5.mjs} +4 -4
- package/dist/agent/chunks/{scene-BgajNvBf.mjs → scene-DWgXH6As.mjs} +2 -2
- package/dist/agent/chunks/{server-CACCerkZ.mjs → server-Dt_YFvN7.mjs} +6 -2
- package/dist/agent/chunks/{tools-DKxgjQSJ.mjs → tools-Cm4BqDkO.mjs} +60 -6
- package/dist/agent/chunks/{tree-BrNYGui2.mjs → tree-CqSj-o8T.mjs} +1 -0
- package/dist/agent/ort/LICENSE.txt +9 -0
- package/dist/agent/ort/ort-wasm-simd-threaded.wasm +0 -0
- package/dist/agent/ort/ort.wasm.bundle.min.mjs +9 -0
- package/dist/runtime/agent3d-runtime.js +6 -6
- package/dist/runtime/agent3d-runtime.single.js +311 -62
- package/dist/runtime/chunks/assets-qnxDnVkj.js +1 -0
- package/dist/runtime/chunks/materials-dC4vDNHh.js +107 -0
- package/dist/runtime/chunks/{model-DbfZaLni.js → model-BCAl_NRl.js} +1 -1
- package/dist/runtime/chunks/photo-DNf14X7B.js +250 -0
- package/dist/runtime/chunks/svg-CLUxY6Zy.js +1 -0
- package/dist/runtime/chunks/{text-BaON-ISS.js → text-rSo_2Luk.js} +2 -2
- package/dist/studio/assets/assets-BW5lQkYR.js +1 -0
- package/dist/studio/assets/{camera-Be6lnp3k.js → camera-BgzPVnn-.js} +1 -1
- package/dist/studio/assets/{editor-Mpnz-b2E.js → editor-NkBUKsDB.js} +1 -1
- package/dist/studio/assets/{game-WMgRSJUD.js → game-DARpu0ah.js} +3 -3
- package/dist/studio/assets/{generators-DozXE7ta.js → generators-BjIs-kHx.js} +1 -1
- package/dist/studio/assets/index-L-N-e2KM.js +479 -0
- package/dist/studio/assets/{model-C2bZTK7-.js → model-CqI8j03Z.js} +1 -1
- package/dist/studio/assets/params-DhsDKSDs.js +1 -0
- package/dist/studio/assets/photo-DAHd1yNF.js +250 -0
- package/dist/studio/assets/{physicsHost-CTRsIvfu.js → physicsHost-tEUto2-_.js} +1 -1
- package/dist/studio/assets/{postfx-DQtp0JIy.js → postfx-BGu30OJK.js} +1 -1
- package/dist/studio/assets/runtime-C_qkIpAK.js +572 -0
- package/dist/studio/assets/{shaders-BOb6Uter.js → shaders-Dt6FGXH_.js} +12 -12
- package/dist/studio/assets/svg-ZZt5MdNf.js +2 -0
- package/dist/studio/assets/{text-CGIZs8HE.js → text-B-HM422i.js} +2 -2
- package/dist/studio/index.html +1 -1
- package/package.json +2 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/agent3d-assets/SKILL.md +40 -25
- package/plugin/skills/agent3d-create/SKILL.md +57 -21
- package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
- package/plugin/skills/agent3d-create/references/recipes.md +71 -6
- package/plugin/skills/agent3d-edit/SKILL.md +22 -22
- package/plugin/skills/agent3d-edit/references/patch-ops.md +11 -3
- package/plugin/skills/agent3d-game/SKILL.md +7 -7
- package/plugin/skills/agent3d-publish/SKILL.md +23 -21
- package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
- package/templates/hero-photo-3d/README.md +28 -0
- package/templates/hero-photo-3d/agent3d.json +8 -0
- package/templates/hero-photo-3d/assets/depth/street-depth.png +0 -0
- package/templates/hero-photo-3d/assets/manifest.json +25 -0
- package/templates/hero-photo-3d/assets/textures/street.webp +0 -0
- package/templates/hero-photo-3d/preview.png +0 -0
- package/templates/hero-photo-3d/scene.json +120 -0
- package/templates/hero-photo-3d/template.json +8 -0
- package/dist/runtime/chunks/materials-w3EW0g-7.js +0 -107
- package/dist/runtime/chunks/svg-CfPIQnDG.js +0 -1
- package/dist/studio/assets/index-tSGZFEt5.js +0 -479
- package/dist/studio/assets/runtime-NGp1VdnH.js +0 -572
- package/dist/studio/assets/svg-CnUMpv_N.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./GLTFLoader-1Zd9N406.js","./three.module-CnI50X0U.js","./BufferGeometryUtils-CAlXAboW.js","./SkeletonUtils-CG5akqME.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{Ln as e,U as t,c as n,d as r,ht as i,mt as a}from"./three.module-CnI50X0U.js";import{v as o}from"./camera-
|
|
2
|
+
import{Ln as e,U as t,c as n,d as r,ht as i,mt as a}from"./three.module-CnI50X0U.js";import{v as o}from"./camera-BgzPVnn-.js";import{o as s}from"./runtime-C_qkIpAK.js";import{h as c}from"./index-L-N-e2KM.js";var l=new Map;function u(e){let t=new Uint8Array(e),n;if(t.byteLength>=20&&new DataView(e).getUint32(0,!0)===1179937895){let r=new DataView(e).getUint32(12,!0);n=new TextDecoder().decode(t.subarray(20,20+r))}else n=new TextDecoder().decode(t);try{let e=JSON.parse(n);return Array.isArray(e.extensionsUsed)?e.extensionsUsed.filter(e=>typeof e==`string`):[]}catch{return[]}}async function d(e){let t=l.get(e);return t||(t=(async()=>{let[{GLTFLoader:t},n]=await Promise.all([c(()=>import(`./GLTFLoader-1Zd9N406.js`),__vite__mapDeps([0,1,2,3]),import.meta.url),fetch(e)]);if(!n.ok)throw Error(`HTTP ${n.status} for ${e}`);let r=await n.arrayBuffer(),i=u(r);if(i.includes(`KHR_draco_mesh_compression`))throw Error(`${e} uses Draco compression (KHR_draco_mesh_compression), which the Agent3D runtime does not decode. Re-export it without Draco (Blender: uncheck "Compression"), or convert it to meshopt with gltfpack (\`gltfpack -i in.glb -o out.glb -cc\`), then run \`agent3d assets optimize\`.`);let a=new t;if(i.includes(`EXT_meshopt_compression`)){let{MeshoptDecoder:e}=await c(async()=>{let{MeshoptDecoder:e}=await import(`./meshopt_decoder.module-DXTYc6wn.js`);return{MeshoptDecoder:e}},[],import.meta.url);await e.ready,a.setMeshoptDecoder(e)}let o=e.slice(0,e.lastIndexOf(`/`)+1);return a.parseAsync(r,/^data:/.test(e)?``:o)})(),t.catch(()=>l.delete(e)),l.set(e,t)),t}function f(e,t){e.traverse(e=>{let n=e;if(n.isMesh&&n.morphTargetDictionary&&n.morphTargetInfluences)for(let[e,r]of Object.entries(t)){let t=n.morphTargetDictionary[e];t!==void 0&&typeof r==`number`&&(n.morphTargetInfluences[t]=r)}})}async function p(l,u){let p=await d(u.resolveAsset(l.src)),{clone:m}=await c(async()=>{let{clone:e}=await import(`./SkeletonUtils-CG5akqME.js`);return{clone:e}},[],import.meta.url),h=m(p.scene),g=new t;g.add(h),h.updateMatrixWorld(!0);let _=new r().setFromObject(h);if(!_.isEmpty()){let t=_.getSize(new e),n=Math.max(t.x,t.y,t.z),r=l.fit&&n>0?l.fit/n:1;if(h.scale.multiplyScalar(r),l.center!==!1){let t=_.getCenter(new e);h.position.set(-t.x*r,-_.min.y*r,-t.z*r)}}h.traverse(e=>{let t=e;t.isMesh&&(t.castShadow=l.castShadow??!0,t.receiveShadow=l.receiveShadow??!1)}),l.material&&await s(h,l.material,u),l.morph&&f(h,l.morph);let v;if(p.animations.length){let e=new n(h),t=null,r=e=>typeof e==`number`||/^\d+$/.test(String(e))?p.animations[Number(e)]:p.animations.find(t=>t.name===e)??p.animations.find(t=>t.name.toLowerCase().includes(String(e).toLowerCase())),s=new Set,c=e=>{let t=r(e);return!t&&!s.has(String(e))&&(s.add(String(e)),u.issue(`asset-load`,`Model ${l.id} has no animation clip "${e}" (clips: ${p.animations.map(e=>e.name).join(`, `)})`,`objects#${l.id}.animation.clip`)),t},d=(n,r={})=>{let s=c(n);if(!s)return;let l=e.clipAction(s);l.setLoop(r.loop===!1?a:i,1/0),l.clampWhenFinished=r.loop===!1,l.timeScale=o(r.speed,1),l.enabled=!0,t&&t!==l?(l.reset().setEffectiveWeight(1).play(),t.crossFadeTo(l,o(r.crossfade,.3),!1)):l.setEffectiveWeight(1).play(),t=l},f=t=>{let n=c(t);if(!n)return null;let r=e.clipAction(n);return r.isRunning()||(r.enabled=!0,r.setLoop(i,1/0),r.play()),r},m={weight(e,t){f(e)?.setEffectiveWeight(Math.max(0,t))},speed(e,t){let n=f(e);n&&(n.timeScale=t)},time(e,t){let n=f(e);n&&(n.paused=!0,n.time=Math.max(0,t))}},g=l.animation??{},_=()=>{e.stopAllAction(),t=null,d(g.clip??0,g),g.offset&&t&&(t.time=Math.max(0,g.offset));for(let[e,t]of Object.entries(g.blend??{}))m.weight(e,t);e.update(0)};v={mixer:e,clips:p.animations,play:d,control:m,reset:_},_()}return{object:g,animator:v}}export{p as buildModel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{x as e}from"./three.module-CnI50X0U.js";import{C as t,D as n}from"./index-L-N-e2KM.js";var r=(t,n)=>{try{return t?t.color(n).clone():new e(n)}catch{return new e(n)}};function i(e,t,n){let i=t??{},a=t=>{let n=e.params.find(e=>e.name===t);if(!n)throw Error(`${e.id}: no catalog param "${t}"`);return n},o=e=>{let t=a(e),n=i[e];return n===void 0?t.default:n},s=(e,t)=>{let n=a(e);return n.min!==void 0&&t<n.min&&(t=n.min),n.max!==void 0&&t>n.max&&(t=n.max),t},c=e=>{let t=o(e);return typeof t==`string`&&(t=Number(t)),typeof t==`number`&&Number.isFinite(t)||(t=a(e).default),s(e,typeof t==`number`?t:0)};return{num:c,numOrNull:e=>i[e]===null?null:c(e),int:e=>Math.round(c(e)),bool:e=>{let t=o(e);return typeof t==`boolean`?t:!!a(e).default},str:e=>{let t=a(e),n=o(e);return typeof n==`string`&&(!t.options||t.options.includes(n))?n:t.default},color:e=>{let t=o(e);return r(n,typeof t==`string`?t:String(a(e).default??`#ffffff`))},colors:e=>{let t=o(e);return typeof t==`string`&&(t=[t]),Array.isArray(t)&&t.length!==0||(t=a(e).default),t.map(e=>r(n,typeof e==`string`?e:`#ffffff`))},vec3:e=>{let t=o(e),n=a(e).default??[0,0,0];return Array.isArray(t)?[0,1,2].map(e=>typeof t[e]==`number`?t[e]:n[e]):[...n]},raw:e=>o(e)}}var a=(e,t)=>{let n=e.find(e=>e.id===t);if(!n)throw Error(`unknown catalog id ${t}`);return n},o=(e,n,r)=>i(a(t,e),n,r),s=(e,t,r)=>i(a(n,e),t,r);export{i as n,s as r,o as t};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import{Bt as e,In as t,Ln as n,St as r,U as i,ct as a,d as o,h as s,kt as c,m as l,mn as u,on as d,rn as f,x as p,xt as m}from"./three.module-CnI50X0U.js";import{i as h}from"./assets-BW5lQkYR.js";import{d as g,p as _,v}from"./camera-BgzPVnn-.js";var y={width:4,strength:.5,focus:.5,segments:256,layers:6,edgeCut:.08,speed:1,smoothing:.9};function ee(e,t,n){let r=t>0&&n>0?t/n:1,i=typeof e.width==`number`&&e.width>0?e.width:void 0,a=typeof e.height==`number`&&e.height>0?e.height:void 0;if(i!==void 0&&a!==void 0)return{width:i,height:a};if(a!==void 0)return{width:a*r,height:a};let o=i??y.width;return{width:o,height:o/r}}function b(e,t,n){let r=2*Math.PI*Math.max(0,t)/10*n;switch(e??`sway`){case`sway`:return{x:.9*Math.sin(r),y:.35*Math.sin(2*r),zoom:0};case`orbit`:{let e=Math.min(1,r/Math.PI),t=.8*e*e*(3-2*e);return{x:t*Math.sin(r),y:t*Math.cos(r),zoom:0}}case`zoom`:return{x:0,y:0,zoom:.5-.5*Math.cos(r)};default:return{x:0,y:0,zoom:0}}}function te(e){let t=_(v(e?.pointer,1),0,1);return{pointer:t,scroll:_(v(e?.scroll,0),0,1),gyro:typeof e?.gyro==`boolean`?e.gyro:t>0,auto:e?.auto??`sway`,speed:Math.max(0,v(e?.speed,y.speed)),smoothing:_(v(e?.smoothing,y.smoothing),0,.99)}}function x(e,t){let n=t.reduced?{x:0,y:0,zoom:0}:b(e.auto,e.speed,t.t),r=e.pointer*(t.reduced?.5:1),i=0,a=0,o=0;t.gyro&&e.gyro&&t.pointer.weight<.5?(i=t.gyro.x,a=t.gyro.y,o=+(r>0)):r>0&&(i=t.pointer.x,a=t.pointer.y,o=_(t.pointer.weight,0,1));let s=n.x*(1-o)+i*r*o,c=n.y*(1-o)+a*r*o;return e.scroll>0&&(c+=(_(t.scroll,0,1)*2-1)*e.scroll),{x:_(s,-1,1),y:_(c,-1,1),zoom:n.zoom*(1-o)}}function S(e,t,n,r){if(r<=0||n<=0)return n<=0&&r>0?e:t;let i=1-_(r,0,.99)**(n*60),a=e+(t-e)*i;return Math.abs(t-a)<1e-4?t:a}function C(e,t,n){let r=_(e,0,1),i=Math.min(t,n),a=i/t,o=i/n;return{maxOffset:[r*.06*a,r*.06*o],inset:[1/(1+r*.1*a),1/(1+r*.1*o)]}}function ne(e,t,n){let r=Math.round(_(v(e,y.segments),2,1024));return t>=n?[r,Math.max(1,Math.round(r*n/t))]:[Math.max(1,Math.round(r*t/n)),r]}function w(e,t){return _(e,0,1)*t*.25}function re(e,t,n,r){let i=Math.round(_(v(e,y.layers),2,16)),a=[],o=_(n,0,1)*r*.1;for(let e=0;e<i;e++){let n=e/i,s=(e+1)/i,c=(n+s)/2;a.push({lo:n,hi:s,center:c,feather:.35/i,z:(c-t)*o+e*.001*r,background:e===0})}return a}function ie(e,t,n,r){let i=t-n.gamma,a=e-n.beta,o=(Math.round(r/90)%4+4)%4;return o===1?[i,a]=[a,-i]:o===2?[i,a]=[-i,-a]:o===3&&([i,a]=[-a,i]),{x:_(i/20,-1,1),y:_(-a/20,-1,1)}}var T=`
|
|
2
|
+
uniform sampler2D uMap;
|
|
3
|
+
uniform vec3 uTint;
|
|
4
|
+
uniform float uOpacity;
|
|
5
|
+
uniform float uIntensity;
|
|
6
|
+
vec4 shade(vec4 c, float a) {
|
|
7
|
+
return vec4(c.rgb * uTint * uIntensity, c.a * a * uOpacity);
|
|
8
|
+
}
|
|
9
|
+
`,E=`
|
|
10
|
+
varying vec2 vUv;
|
|
11
|
+
void main() {
|
|
12
|
+
vUv = uv;
|
|
13
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
14
|
+
}
|
|
15
|
+
`,D=`
|
|
16
|
+
${T}
|
|
17
|
+
uniform sampler2D uDepth;
|
|
18
|
+
uniform vec2 uView;
|
|
19
|
+
uniform float uZoom;
|
|
20
|
+
uniform vec2 uMaxOffset;
|
|
21
|
+
uniform vec2 uInset;
|
|
22
|
+
uniform float uFocus;
|
|
23
|
+
uniform float uWallSlope;
|
|
24
|
+
varying vec2 vUv;
|
|
25
|
+
const int STEPS = __STEPS__;
|
|
26
|
+
void main() {
|
|
27
|
+
// the zoom drift also pushes in slightly (stays inside the inset margin)
|
|
28
|
+
vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
|
|
29
|
+
vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
|
|
30
|
+
vec2 dir = v * uMaxOffset;
|
|
31
|
+
vec2 uv = base;
|
|
32
|
+
if (dot(dir, dir) > 1e-10) {
|
|
33
|
+
float stepH = 1.0 / float(STEPS);
|
|
34
|
+
float h = 1.0;
|
|
35
|
+
float prevH = 1.0 + stepH;
|
|
36
|
+
bool hit = false;
|
|
37
|
+
for (int i = 0; i <= STEPS; i++) {
|
|
38
|
+
h = 1.0 - float(i) * stepH;
|
|
39
|
+
float d = textureLod(uDepth, base + (h - uFocus) * dir, 0.0).r;
|
|
40
|
+
if (d >= h) { hit = true; break; }
|
|
41
|
+
prevH = h;
|
|
42
|
+
}
|
|
43
|
+
float lo = h, hi = min(prevH, 1.0);
|
|
44
|
+
if (hit) {
|
|
45
|
+
for (int j = 0; j < 6; j++) {
|
|
46
|
+
float mid = 0.5 * (lo + hi);
|
|
47
|
+
float d = textureLod(uDepth, base + (mid - uFocus) * dir, 0.0).r;
|
|
48
|
+
if (d >= mid) lo = mid; else hi = mid;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
uv = base + (lo - uFocus) * dir;
|
|
52
|
+
// Disocclusion: the ray hit the steep "wall" of a depth edge. Stretching
|
|
53
|
+
// the foreground edge colour reads as a smear: take the colour from just
|
|
54
|
+
// past the edge on the far side instead (the background continues).
|
|
55
|
+
vec2 texel = 1.0 / vec2(textureSize(uDepth, 0));
|
|
56
|
+
vec4 dh = textureLod(uDepth, uv, 0.0);
|
|
57
|
+
vec2 grad = vec2(
|
|
58
|
+
textureLod(uDepth, uv + vec2(texel.x * 1.5, 0.0), 0.0).r - textureLod(uDepth, uv - vec2(texel.x * 1.5, 0.0), 0.0).r,
|
|
59
|
+
textureLod(uDepth, uv + vec2(0.0, texel.y * 1.5), 0.0).r - textureLod(uDepth, uv - vec2(0.0, texel.y * 1.5), 0.0).r) / 3.0;
|
|
60
|
+
float g = length(grad);
|
|
61
|
+
vec2 toNear = grad / max(g, 1e-6);
|
|
62
|
+
float dNear = textureLod(uDepth, uv + toNear * texel * 3.0, 0.0).r;
|
|
63
|
+
if (hit && (g > uWallSlope || dh.a < 0.5) && dNear > lo + 0.04) {
|
|
64
|
+
vec2 away = -toNear;
|
|
65
|
+
vec2 probe = uv;
|
|
66
|
+
for (int k = 1; k <= 6; k++) {
|
|
67
|
+
vec2 q = uv + away * texel * float(k * 2);
|
|
68
|
+
probe = q;
|
|
69
|
+
if (textureLod(uDepth, q, 0.0).r < lo - 0.05) break;
|
|
70
|
+
}
|
|
71
|
+
uv = probe + away * texel * 2.0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
vec4 c = textureGrad(uMap, uv, dFdx(base), dFdy(base));
|
|
75
|
+
if (c.a * uOpacity < 0.004) discard;
|
|
76
|
+
gl_FragColor = shade(c, 1.0);
|
|
77
|
+
#include <tonemapping_fragment>
|
|
78
|
+
#include <colorspace_fragment>
|
|
79
|
+
}
|
|
80
|
+
`,ae=`
|
|
81
|
+
uniform sampler2D uDepth;
|
|
82
|
+
uniform float uRange;
|
|
83
|
+
uniform float uFocus;
|
|
84
|
+
uniform float uEdgeCut;
|
|
85
|
+
uniform vec3 uCam;
|
|
86
|
+
uniform float uPerspective;
|
|
87
|
+
attribute vec4 uvOther;
|
|
88
|
+
varying vec2 vUv;
|
|
89
|
+
varying float vDepth;
|
|
90
|
+
varying float vCut;
|
|
91
|
+
varying float vMotion;
|
|
92
|
+
vec3 displaced(vec3 p, float z) {
|
|
93
|
+
if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
|
|
94
|
+
p.z = z;
|
|
95
|
+
return p;
|
|
96
|
+
}
|
|
97
|
+
void main() {
|
|
98
|
+
vUv = uv;
|
|
99
|
+
vec4 d0 = textureLod(uDepth, uv, 0.0);
|
|
100
|
+
vec4 d1 = textureLod(uDepth, uvOther.xy, 0.0);
|
|
101
|
+
vec4 d2 = textureLod(uDepth, uvOther.zw, 0.0);
|
|
102
|
+
float jump = max(max(abs(d0.r - d1.r), abs(d1.r - d2.r)), abs(d0.r - d2.r));
|
|
103
|
+
bool cut = min(d0.a, min(d1.a, d2.a)) < 0.5 || (uEdgeCut > 0.0 && jump > uEdgeCut);
|
|
104
|
+
vCut = cut ? 1.0 : 0.0;
|
|
105
|
+
vDepth = d0.r;
|
|
106
|
+
vec4 c = projectionMatrix * modelViewMatrix * vec4(displaced(position, (d0.r - uFocus) * uRange), 1.0);
|
|
107
|
+
vMotion = 0.0;
|
|
108
|
+
if (cut) {
|
|
109
|
+
vec4 a = projectionMatrix * modelViewMatrix * vec4(displaced(position, -uFocus * uRange), 1.0);
|
|
110
|
+
vec4 b = projectionMatrix * modelViewMatrix * vec4(displaced(position, (1.0 - uFocus) * uRange), 1.0);
|
|
111
|
+
vMotion = length(b.xy / b.w - a.xy / a.w);
|
|
112
|
+
}
|
|
113
|
+
gl_Position = c;
|
|
114
|
+
}
|
|
115
|
+
`,oe=`
|
|
116
|
+
${T}
|
|
117
|
+
uniform sampler2D uDepth;
|
|
118
|
+
varying vec2 vUv;
|
|
119
|
+
varying float vDepth;
|
|
120
|
+
varying float vCut;
|
|
121
|
+
varying float vMotion;
|
|
122
|
+
void main() {
|
|
123
|
+
if (vCut > 0.5) {
|
|
124
|
+
float d = textureLod(uDepth, vUv, 0.0).r;
|
|
125
|
+
if (abs(d - vDepth) * vMotion > 0.004) discard;
|
|
126
|
+
}
|
|
127
|
+
vec4 c = texture2D(uMap, vUv);
|
|
128
|
+
if (c.a * uOpacity < 0.004) discard;
|
|
129
|
+
gl_FragColor = shade(c, 1.0);
|
|
130
|
+
#include <tonemapping_fragment>
|
|
131
|
+
#include <colorspace_fragment>
|
|
132
|
+
}
|
|
133
|
+
`,se=`
|
|
134
|
+
uniform sampler2D uDepth;
|
|
135
|
+
uniform float uRange;
|
|
136
|
+
uniform float uFocus;
|
|
137
|
+
uniform vec3 uCam;
|
|
138
|
+
uniform float uPerspective;
|
|
139
|
+
uniform vec2 uReach;
|
|
140
|
+
varying vec2 vUv;
|
|
141
|
+
varying float vDepth;
|
|
142
|
+
void main() {
|
|
143
|
+
vUv = uv;
|
|
144
|
+
float d = textureLod(uDepth, uv, 0.0).r;
|
|
145
|
+
for (int i = 1; i <= 2; i++) {
|
|
146
|
+
vec2 r = uReach * float(i) * 0.5;
|
|
147
|
+
d = min(d, textureLod(uDepth, uv + vec2(r.x, 0.0), 0.0).r);
|
|
148
|
+
d = min(d, textureLod(uDepth, uv - vec2(r.x, 0.0), 0.0).r);
|
|
149
|
+
d = min(d, textureLod(uDepth, uv + vec2(0.0, r.y), 0.0).r);
|
|
150
|
+
d = min(d, textureLod(uDepth, uv - vec2(0.0, r.y), 0.0).r);
|
|
151
|
+
d = min(d, textureLod(uDepth, uv + r, 0.0).r);
|
|
152
|
+
d = min(d, textureLod(uDepth, uv - r, 0.0).r);
|
|
153
|
+
d = min(d, textureLod(uDepth, uv + vec2(r.x, -r.y), 0.0).r);
|
|
154
|
+
d = min(d, textureLod(uDepth, uv + vec2(-r.x, r.y), 0.0).r);
|
|
155
|
+
}
|
|
156
|
+
vDepth = d;
|
|
157
|
+
float z = (d - uFocus) * uRange - uRange * 0.02;
|
|
158
|
+
vec3 p = position;
|
|
159
|
+
if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
|
|
160
|
+
p.z = z;
|
|
161
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
|
|
162
|
+
}
|
|
163
|
+
`,O=`
|
|
164
|
+
${T}
|
|
165
|
+
uniform sampler2D uDepth;
|
|
166
|
+
varying vec2 vUv;
|
|
167
|
+
varying float vDepth;
|
|
168
|
+
void main() {
|
|
169
|
+
vec2 uv = vUv;
|
|
170
|
+
float d = textureLod(uDepth, uv, 0.0).r;
|
|
171
|
+
if (d > vDepth + 0.04) {
|
|
172
|
+
vec2 texel = 1.0 / vec2(textureSize(uDepth, 0));
|
|
173
|
+
vec2 grad = vec2(
|
|
174
|
+
textureLod(uDepth, uv + vec2(texel.x * 2.0, 0.0), 0.0).r - textureLod(uDepth, uv - vec2(texel.x * 2.0, 0.0), 0.0).r,
|
|
175
|
+
textureLod(uDepth, uv + vec2(0.0, texel.y * 2.0), 0.0).r - textureLod(uDepth, uv - vec2(0.0, texel.y * 2.0), 0.0).r);
|
|
176
|
+
vec2 away = length(grad) > 1e-5 ? -normalize(grad) : vec2(0.0);
|
|
177
|
+
// walk towards the background until the depth reaches this surface's
|
|
178
|
+
for (int k = 1; k <= 24; k++) {
|
|
179
|
+
uv = vUv + away * texel * float(k * 3);
|
|
180
|
+
if (textureLod(uDepth, uv, 0.0).r <= vDepth + 0.04) break;
|
|
181
|
+
}
|
|
182
|
+
uv += away * texel * 2.0;
|
|
183
|
+
}
|
|
184
|
+
vec4 c = texture2D(uMap, uv);
|
|
185
|
+
if (c.a * uOpacity < 0.004) discard;
|
|
186
|
+
gl_FragColor = shade(c, 1.0);
|
|
187
|
+
#include <tonemapping_fragment>
|
|
188
|
+
#include <colorspace_fragment>
|
|
189
|
+
}
|
|
190
|
+
`,ce=`
|
|
191
|
+
${T}
|
|
192
|
+
uniform sampler2D uDepth;
|
|
193
|
+
uniform vec2 uView;
|
|
194
|
+
uniform float uZoom;
|
|
195
|
+
uniform vec2 uMaxOffset;
|
|
196
|
+
uniform vec2 uInset;
|
|
197
|
+
uniform float uFocus;
|
|
198
|
+
uniform float uCenter;
|
|
199
|
+
uniform float uLo;
|
|
200
|
+
uniform float uHi;
|
|
201
|
+
uniform float uFeather;
|
|
202
|
+
uniform float uBackground;
|
|
203
|
+
varying vec2 vUv;
|
|
204
|
+
void main() {
|
|
205
|
+
// the zoom drift also pushes in slightly (stays inside the inset margin)
|
|
206
|
+
vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
|
|
207
|
+
vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
|
|
208
|
+
// Each layer moves with the depth it shows, clamped to its band: a smooth
|
|
209
|
+
// surface crossing two bands stays continuous (no tear at the band edge);
|
|
210
|
+
// only real depth jumps separate the layers. Fixed-point solve, from the
|
|
211
|
+
// band centre.
|
|
212
|
+
vec2 dir = v * uMaxOffset;
|
|
213
|
+
vec2 uv = base + (uCenter - uFocus) * dir;
|
|
214
|
+
for (int i = 0; i < 3; i++) {
|
|
215
|
+
float di = clamp(textureLod(uDepth, uv, 0.0).r, uLo, uHi);
|
|
216
|
+
uv = base + (di - uFocus) * dir;
|
|
217
|
+
}
|
|
218
|
+
vec4 dd = textureLod(uDepth, uv, 0.0);
|
|
219
|
+
float d = dd.r;
|
|
220
|
+
// soft slice edges, but hard on marked depth edges (alpha 0): a blend of
|
|
221
|
+
// two layers there would draw a thin double outline
|
|
222
|
+
float a = uBackground > 0.5 ? 1.0 : dd.a < 0.5 ? step(uLo, d) : smoothstep(uLo - uFeather, uLo + uFeather, d);
|
|
223
|
+
if (a < 0.004) discard;
|
|
224
|
+
vec2 cuv = uv;
|
|
225
|
+
// covered by nearer content
|
|
226
|
+
if (d > uHi + uFeather) {
|
|
227
|
+
bool found = false;
|
|
228
|
+
vec2 reach = v * uMaxOffset * 1.25;
|
|
229
|
+
for (int k = 1; k <= 16; k++) {
|
|
230
|
+
vec2 q = uv + reach * (float(k) / 16.0);
|
|
231
|
+
vec4 dq = textureLod(uDepth, q, 0.0);
|
|
232
|
+
if (dq.r <= uHi && dq.a >= 0.5 && (uBackground > 0.5 || dq.r >= uLo - uFeather)) {
|
|
233
|
+
// step past the edge's blended texels
|
|
234
|
+
vec2 texel = 1.0 / vec2(textureSize(uMap, 0));
|
|
235
|
+
cuv = q + normalize(reach) * texel * 3.0;
|
|
236
|
+
found = true;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Nothing of this band to extend: let the layers below show (the
|
|
241
|
+
// background keeps the source texel).
|
|
242
|
+
if (!found && uBackground < 0.5) discard;
|
|
243
|
+
}
|
|
244
|
+
vec4 c = textureGrad(uMap, cuv, dFdx(base), dFdy(base));
|
|
245
|
+
gl_FragColor = shade(c, a);
|
|
246
|
+
if (gl_FragColor.a < 0.004) discard;
|
|
247
|
+
#include <tonemapping_fragment>
|
|
248
|
+
#include <colorspace_fragment>
|
|
249
|
+
}
|
|
250
|
+
`;function le(e){let t=e.image;return{w:t?.naturalWidth||t?.width||1,h:t?.naturalHeight||t?.height||1}}function k(e,t,n){let r=t.material??{};return{uMap:{value:e},uTint:{value:r.color?n.color(r.color):new p(1,1,1)},uOpacity:{value:_(v(r.opacity,1),0,1)},uIntensity:{value:Math.max(0,v(r.emissiveIntensity,1))}}}function A(e,t,n,r){let i=new d({vertexShader:e,fragmentShader:t,uniforms:n,transparent:r,toneMapped:!1,fog:!1,side:0});return i.depthWrite=!r,i}function ue(e,t,n,r){let i=n*r*2,a=new Float32Array(i*9),o=new Float32Array(i*6),c=new Float32Array(i*12),u=0,d=(n,r,i)=>{let s=[n,r,i];for(let n=0;n<3;n++){let[r,i]=s[n],l=s[(n+1)%3],d=s[(n+2)%3];a.set([(r-.5)*e,(i-.5)*t,0],u*3),o.set([r,i],u*2),c.set([l[0],l[1],d[0],d[1]],u*4),u++}};for(let e=0;e<r;e++)for(let t=0;t<n;t++){let i=t/n,a=(t+1)/n,o=e/r,s=(e+1)/r;d([i,o],[a,o],[a,s]),d([i,o],[a,s],[i,s])}let f=new s;return f.setAttribute(`position`,new l(a,3)),f.setAttribute(`uv`,new l(o,2)),f.setAttribute(`uvOther`,new l(c,4)),f}function de(e,t){return Math.max(8,Math.round((e===`low`?12:e===`medium`?20:e===`ultra`?48:32)*(.5+.5*Math.min(1,Math.max(0,t)/.6))))}async function j(s,l){let[d,p]=await Promise.all([h(l.resolveAsset(s.src)),s.depth?h(l.resolveAsset(s.depth)).catch(e=>(l.issue(`asset-load`,`${s.id}: depth map: ${e.message} — showing the photo flat`,`objects#${s.id}.depth`),null)):Promise.resolve(null)]);d.colorSpace=f,d.wrapS=d.wrapT=c,d.anisotropy=4,d.needsUpdate=!0,p&&(p.colorSpace=``,p.premultiplyAlpha=!1,p.wrapS=p.wrapT=c,p.generateMipmaps=!1,p.minFilter=a,p.magFilter=a,p.needsUpdate=!0);let b=le(d),{width:T,height:j}=ee(s,b.w,b.h),M=_(v(s.strength,y.strength),0,1),N=_(v(s.focus,y.focus),0,1),P=_(v(s.material?.opacity,1),0,1),F=P<1||/\.(png|webp)$/i.test(s.src),I=te(s.motion),L=p?s.mode??`parallax`:`flat`,R=new i,z=new i;R.add(z);let B=[],V=[],H=[],U=[],W=null,G=()=>{let t=new e(T,j);return V.push(t),t};if(L===`flat`){let e=s.material??{},t=new r({map:d,transparent:F,opacity:P,toneMapped:!1,fog:!1});e.color&&t.color.copy(l.color(e.color)),t.color.multiplyScalar(Math.max(0,v(e.emissiveIntensity,1))),F&&(t.alphaTest=P<1?0:.004),B.push(t),z.add(new m(G(),t))}else if(L===`parallax`){let e=C(M,T,j),n={...k(d,s,l),uDepth:{value:p},uView:{value:new t},uZoom:{value:0},uMaxOffset:{value:new t(...e.maxOffset)},uInset:{value:new t(...e.inset)},uFocus:{value:N},uWallSlope:{value:.02}},r=A(E,D.replace(`__STEPS__`,String(de(l.quality,M))),n,F);B.push(r),H.push(r),z.add(new m(G(),r))}else if(L===`mesh`){let[r,i]=ne(v(s.segments,y.segments),T,j),a=w(M,T),c=ue(T,j,r,i);c.boundingBox=new o(new n(-T/2,-j/2,-N*a),new n(T/2,j/2,(1-N)*a)),c.boundingSphere=c.boundingBox.getBoundingSphere(new u),V.push(c);let f={...k(d,s,l),uDepth:{value:p},uRange:{value:a},uFocus:{value:N},uEdgeCut:{value:_(v(s.edgeCut,y.edgeCut),0,1)},uCam:{value:new n(0,0,1e6)},uPerspective:{value:0}};W=f;let h=A(ae,oe,f,P<1);h.side=2,B.push(h);let g=new m(c,h);g.renderOrder=1,z.add(g);{let n=new e(T,j,Math.max(1,Math.round(r/2)),Math.max(1,Math.round(i/2)));n.boundingBox=c.boundingBox.clone(),n.boundingSphere=c.boundingSphere.clone(),V.push(n);let a=new t(6/r,6/i),o=A(se,O,{...f,uReach:{value:a}},P<1);o.side=2,B.push(o);let s=new m(n,o);s.renderOrder=0,s.raycast=()=>void 0,z.add(s)}}else{let e=C(M,T,j),n=G(),r=re(v(s.layers,y.layers),N,M,T),i=_(v(s.edgeCut,y.edgeCut),0,1);r.forEach((r,a)=>{let o=A(E,ce,{...k(d,s,l),uDepth:{value:p},uView:{value:new t},uZoom:{value:0},uMaxOffset:{value:new t(...e.maxOffset)},uInset:{value:new t(...e.inset)},uFocus:{value:N},uCenter:{value:r.center},uLo:{value:r.lo},uHi:{value:r.hi},uFeather:{value:i>0?Math.min(r.feather,i):.002},uBackground:{value:+!!r.background}},!r.background||F);B.push(o),H.push(o);let c=new m(n,o);c.position.z=r.z,c.renderOrder=a,c.userData.a3dPhotoLayer=a,z.add(c),U.push({mesh:c,band:r})})}let K=!l.deterministic,q={x:0,y:0,weight:0,init:!1},J=null,Y=null,X=null;if(K&&I.gyro&&I.pointer>0&&L!==`flat`&&typeof window<`u`&&typeof window.addEventListener==`function`){let e=e=>{if(e.beta===null||e.gamma===null)return;Y??={beta:e.beta,gamma:e.gamma};let t=typeof screen<`u`&&screen.orientation?.angle||0;J=ie(e.beta,e.gamma,Y,t)};window.addEventListener(`deviceorientation`,e),X=()=>window.removeEventListener(`deviceorientation`,e)}let Z=new n,Q=!1,$=M*8*g;return{object:R,update:(e,t,n)=>{if(L===`flat`)return;let r=n.pointer,i=r.inside?_(r.x,-1,1):0,a=r.inside?_(r.y,-1,1):0,o=+!!r.inside;!K||!q.init?(q.x=i,q.y=a,q.weight=o,q.init=K):(q.x=S(q.x,i,t,I.smoothing),q.y=S(q.y,a,t,I.smoothing),q.weight=S(q.weight,o,t,I.smoothing));let s=x(I,{t:e,pointer:q,gyro:K?J:null,scroll:n.scroll,reduced:n.reduced});for(let e of H)e.uniforms.uView.value.set(s.x,s.y),e.uniforms.uZoom.value=s.zoom;let c=!!n.camera&&!!n.camera.isPerspectiveCamera;if(n.camera&&!Q&&L!==`parallax`&&(n.camera.updateMatrixWorld(),R.updateWorldMatrix(!0,!1),Z.setFromMatrixPosition(n.camera.matrixWorld),R.worldToLocal(Z),Q=!0),L===`mesh`)z.rotation.set(s.y*$,-s.x*$,0),z.position.z=s.zoom*w(M,T)*.5,W&&(W.uCam.value.copy(Z),W.uPerspective.value=c&&Z.z>0?1:0);else if(L===`layers`&&Q){let e=Z.z;for(let{mesh:t,band:n}of U)if(c&&e>n.z+.001){let r=(e-n.z)/e;t.scale.set(r,r,1),t.position.set(Z.x*n.z/e,Z.y*n.z/e,n.z)}else t.scale.set(1,1,1),t.position.set(0,0,n.z)}},dispose(){X?.(),X=null;for(let e of B)e.dispose();for(let e of V)e.dispose();d.dispose(),p?.dispose()}}}export{j as buildPhoto};
|