@volter/editor 0.5.58 → 0.5.59

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.
Files changed (70) hide show
  1. package/BUNDLED_NOTICES +6 -6
  2. package/dist/.vite/manifest.json +259 -259
  3. package/dist/assets/{AudioViewer-CEfg6soG.js → AudioViewer-C5C4xeUl.js} +1 -1
  4. package/dist/assets/{EntityModelDocument-rBweka7M.js → EntityModelDocument-DyhU8umO.js} +1 -1
  5. package/dist/assets/{EnvironmentAssetDocument-VgR_on1P.js → EnvironmentAssetDocument-D_VZ2iFj.js} +1 -1
  6. package/dist/assets/{GameplaySessionTimeline-B9v8LIxV.js → GameplaySessionTimeline-kIIuhFBI.js} +1 -1
  7. package/dist/assets/{ImageViewer-CvnifCXj.js → ImageViewer-Crv-yzT_.js} +1 -1
  8. package/dist/assets/{InspectorObjectPreview-gbDaFcDe.js → InspectorObjectPreview-CO-GVXfu.js} +1 -1
  9. package/dist/assets/{JsonAssetDocument-B-ze7id8.js → JsonAssetDocument-Dtg2QwPN.js} +1 -1
  10. package/dist/assets/{ModelAssetDocument-NDTeB7b_.js → ModelAssetDocument-BpZ8SZXe.js} +1 -1
  11. package/dist/assets/{NonThreeAuthoringBootstrap-D1oTrvVk.js → NonThreeAuthoringBootstrap-0nm5Hl3v.js} +2 -2
  12. package/dist/assets/{Object3DPreview-DvXwCq08.js → Object3DPreview-dHzSO5Ym.js} +2 -2
  13. package/dist/assets/{OnlineAssetDetail-GdHcOske.js → OnlineAssetDetail-DAdWXnmZ.js} +2 -2
  14. package/dist/assets/{SourceAssetViewer-C0qk5wJl.js → SourceAssetViewer-D3m0wF8T.js} +2 -2
  15. package/dist/assets/{StageHost-BU-t7Wwj.js → StageHost-DD_m8W0k.js} +4 -4
  16. package/dist/assets/{ToolObject3DPreview-CP6YmA70.js → ToolObject3DPreview-CWdklUZ1.js} +1 -1
  17. package/dist/assets/{TransientHint-Rw3wxMUO.js → TransientHint-aFFUtbSY.js} +1 -1
  18. package/dist/assets/{VideoViewer-D8aW7n4N.js → VideoViewer-BhH8aSzx.js} +1 -1
  19. package/dist/assets/{asset-editor-persistence-COlYs9e4.js → asset-editor-persistence-D5wYXQEL.js} +1 -1
  20. package/dist/assets/{blender-emscripten-engine-BkrPLmPf.js → blender-emscripten-engine-BhbEQhcb.js} +1 -1
  21. package/dist/assets/{blender-node-editor.document-DtaO2jAu.js → blender-node-editor.document-D-hrVHmR.js} +1 -1
  22. package/dist/assets/{blender-outliner-model-CfXIMSXz.js → blender-outliner-model-FscHWpfW.js} +1 -1
  23. package/dist/assets/{blender-properties-tab-DYiaVS6T.js → blender-properties-tab-Czi3_yYZ.js} +1 -1
  24. package/dist/assets/blender-runtime-host-C3rVDyG8.js +4 -0
  25. package/dist/assets/{blender-runtime-skin-CBll8ovN.js → blender-runtime-skin-AJdtKKnf.js} +1 -1
  26. package/dist/assets/{blender-runtime.document-CStrnPJb.js → blender-runtime.document-JlYY0bb7.js} +1 -1
  27. package/dist/assets/{blender-timeline.document-WjHuKO96.js → blender-timeline.document-5UN8V20F.js} +1 -1
  28. package/dist/assets/{blender-uv-editor.document-CsjAI-Lc.js → blender-uv-editor.document-maFJQzgA.js} +1 -1
  29. package/dist/assets/{blender-version.status-BcaIEqih.js → blender-version.status-CukRH8K3.js} +1 -1
  30. package/dist/assets/{blender-wali-engine-Dtwixi7B.js → blender-wali-engine-B0Q2w2Be.js} +1 -1
  31. package/dist/assets/blender.command-CY6QiXxp.js +1 -0
  32. package/dist/assets/{browserAll-DAbE1efB.js → browserAll-BQIn-DRw.js} +1 -1
  33. package/dist/assets/{edit-mode-authoring-BBWCwYeE.js → edit-mode-authoring-CWTeROGv.js} +1 -1
  34. package/dist/assets/{hosted-asset-materialization-CvAt4P7_.js → hosted-asset-materialization-DcthzsYS.js} +1 -1
  35. package/dist/assets/{index-CY4oDLhJ.js → index-DmtPt6RQ.js} +331 -331
  36. package/dist/assets/{models.finder-CZNTvr_w.js → models.finder-CrDJ41Cp.js} +1 -1
  37. package/dist/assets/{product-Dr7coa2h.js → product-CqAh01LU.js} +1 -1
  38. package/dist/assets/{properties-bone-constraints.inspector-DBAuXqr4.js → properties-bone-constraints.inspector-BPN6BRJV.js} +1 -1
  39. package/dist/assets/{properties-bone.inspector-C_F8SxhT.js → properties-bone.inspector-C4xD61mX.js} +1 -1
  40. package/dist/assets/{properties-collection.inspector-C1DLm9eT.js → properties-collection.inspector-BTps8t6G.js} +1 -1
  41. package/dist/assets/{properties-constraints.inspector-BySUEgAb.js → properties-constraints.inspector-BVvP6esW.js} +1 -1
  42. package/dist/assets/{properties-data.inspector-BOvrvedq.js → properties-data.inspector-CKKO8DVT.js} +1 -1
  43. package/dist/assets/{properties-material.inspector-CGJmh_QM.js → properties-material.inspector-BGfT8kHT.js} +1 -1
  44. package/dist/assets/{properties-modifiers.inspector-xnsQ1ddN.js → properties-modifiers.inspector-DJRANpOY.js} +1 -1
  45. package/dist/assets/{properties-object.inspector-BOEEbStu.js → properties-object.inspector-CgVfWmw2.js} +1 -1
  46. package/dist/assets/{properties-output.inspector-NXZnMx4l.js → properties-output.inspector-CBl5xEMZ.js} +1 -1
  47. package/dist/assets/{properties-particles.inspector-D6D1g8l3.js → properties-particles.inspector-CxVZ09ZY.js} +1 -1
  48. package/dist/assets/{properties-physics.inspector-DoPfj0an.js → properties-physics.inspector-DmG3i3vY.js} +1 -1
  49. package/dist/assets/{properties-render.inspector-Cvnkkapn.js → properties-render.inspector-TCoPfEn0.js} +1 -1
  50. package/dist/assets/{properties-scene.inspector-C2mQ8GLM.js → properties-scene.inspector-BjsTOBiY.js} +1 -1
  51. package/dist/assets/{properties-texture.inspector-DvASuzXS.js → properties-texture.inspector-D1X9iyVV.js} +1 -1
  52. package/dist/assets/{properties-view-layer.inspector-FIxWmUI0.js → properties-view-layer.inspector-dXTVxzzk.js} +1 -1
  53. package/dist/assets/{properties-world.inspector-BfopwUSa.js → properties-world.inspector-CRxJK930.js} +1 -1
  54. package/dist/assets/{react-story-board-DBO76grK.js → react-story-board-CnCZAhn6.js} +1 -1
  55. package/dist/assets/{react-three-rapier.esm-Cj4NtDam.js → react-three-rapier.esm-DsJqtzy_.js} +1 -1
  56. package/dist/assets/{spark.module-BOFvGTtp.js → spark.module-uQlq--TY.js} +1 -1
  57. package/dist/assets/{stage-keyboard-BsKOZggP.js → stage-keyboard-DzZMNYAr.js} +1 -1
  58. package/dist/assets/{stage-overlay-set-bQwh25SV.js → stage-overlay-set-D6OOz1L9.js} +1 -1
  59. package/dist/assets/{stage-presence-markers-CALnBqqb.js → stage-presence-markers-BUaSzKCv.js} +1 -1
  60. package/dist/assets/{story-capture-BLVE1Bck.js → story-capture-C2ExQiuI.js} +1 -1
  61. package/dist/assets/{story-pixi-preview-B1LxWTHx.js → story-pixi-preview-C6n-a2_M.js} +1 -1
  62. package/dist/assets/{story-three-preview-CsjJKTcf.js → story-three-preview-BazrPMDu.js} +2 -2
  63. package/dist/assets/{webworkerAll-dq7Pw9V8.js → webworkerAll-FJN9IDir.js} +1 -1
  64. package/dist/assets/worker-CBvBkaXr.js +2 -0
  65. package/dist/assets/{world-documents-PX5fRvVn.js → world-documents-B6usBw3s.js} +1 -1
  66. package/dist-node/cli.js +13 -7
  67. package/package.json +7 -7
  68. package/dist/assets/blender-runtime-host-DGe1KLVZ.js +0 -4
  69. package/dist/assets/blender.command-B9Qf17Yr.js +0 -1
  70. package/dist/assets/worker-29OHwCKe.js +0 -2
@@ -1,4 +0,0 @@
1
- import{bS as Ve,bT as We,e as _,ac as Ge,bU as ze}from"./index-CY4oDLhJ.js";import{d as He,W as ve,H as qe,br as Xe,i as Ze,bK as le,w as Ke,x as Ye,af as xe,V as te,bl as Je,$ as Qe,k as et,bL as tt,bf as ke}from"./three.module-BynznMJN.js";import{f as nt}from"./clip-planes-CnAI6DZn.js";class rt{#r;#s;#n=new Map;#y=0;#p=null;#i=new Map;#l=null;#u=0;#f=0;#w=0;#a=null;#g=null;#d=null;constructor(t){this.#s=t,this.#r=new Worker(new URL("/assets/worker-29OHwCKe.js",import.meta.url),{type:"module",name:"blender"}),this.#r.onmessage=n=>void this.#b(n.data),this.#r.onerror=n=>{const r=n.error,o=n.filename?` at ${n.filename}:${n.lineno}:${n.colno}`:"",a=r?.stack??r?.message??n.message,l=new Error(`Blender worker failed: ${a||"the worker script did not load"}${o}`);console.error(l.message);for(const s of[...this.#n.keys()])this.#h(s);for(const s of this.#n.values())s.reject(l);this.#n.clear()}}#o=null;#c=null;get project(){return this.#o}start(t,n){return this.#o!==null&&this.#o!==t?Promise.reject(new Error(`The Blender session is bound to ${this.#o}, not ${t}`)):n!==void 0&&this.#c!==null&&this.#c!==n?Promise.reject(new Error(`Blender resource conflict: the session holds ${this.#c}; cannot open ${n}`)):(this.#o=t,this.#c??=n??"models/model.blend",this.#p??=this.#e({op:"start",project:t,...n===void 0?{}:{document:n}}),this.#p)}#t(){return this.#o===null?Promise.reject(new Error("The Blender session has not been started with a project (blender-start)")):this.start(this.#o)}async execute(t,n=!0,r="Blender Python"){return await this.#t(),await this.#e({op:"execute",code:t,history:n,label:r})}async historyGesture(t){await this.#t(),await this.#e({op:t})}async historyStep(t,n){return await this.#t(),(await this.#e({op:"history-step",token:t,direction:n})).moved}async sceneInfo(){return await this.#t(),await this.#e({op:"scene-info"})}async objectInfo(t){return await this.#t(),await this.#e({op:"object-info",name:t})}async rna(t,n){return await this.#t(),await this.#e({op:"rna",path:t,...n===void 0?{}:{names:n}})}async rnaContext(t,n){return await this.#t(),await this.#e({op:"rna-context",...t===void 0?{}:{object:t},...n===void 0?{}:{collection:n}})}async rnaSet(t,n,r,o,a=!0){return await this.#t(),await this.#e({op:"rna-set",history:a,path:t,property:n,value:r,...o===void 0?{}:{index:o}})}async outliner(t){return await this.#t(),await this.#e({op:"outliner",...t===void 0?{}:{selected:t}})}async nodeTree(t){return await this.#t(),await this.#e({op:"node-tree",...t?.path===void 0?{}:{path:t.path},...t?.material===void 0?{}:{material:t.material}})}async uvLayout(t){return await this.#t(),await this.#e({op:"uv-layout",...t?.object===void 0?{}:{object:t.object},...t?.uvLayer===void 0?{}:{uvLayer:t.uvLayer}})}async rig(t){return await this.#t(),await this.#e({op:"rig",...t?.object===void 0?{}:{object:t.object}})}async actionClip(t){return await this.#t(),await this.#e({op:"action-clip",...t?.object===void 0?{}:{object:t.object},...t?.bake===void 0?{}:{bake:t.bake}})}async outlinerSet(t,n,r){return await this.#t(),await this.#e({op:"outliner-set",path:t,column:n,value:r})}async present(){await this.#t(),await this.#e({op:"present"})}async screenshotView(t){return await this.#t(),await this.#e({op:"screenshot-view",maxSize:t})}async readFile(t){return await this.#t(),await this.#e({op:"read-file",path:t})}async writeFile(t,n){await this.#t(),await this.#e({op:"write-file",path:t,bytes:n})}async listFiles(t){return await this.#t(),await this.#e({op:"list-files",path:t})}get presented(){return this.#g}terminate(){this.#r.terminate();const t=new Error("The Blender session was terminated");for(const n of[...this.#n.keys()])this.#h(n);for(const n of this.#n.values())n.reject(t);this.#n.clear()}metrics(t=performance.now()){let n=null,r=this.#u,o=this.#f,a=this.#w;for(const l of this.#i.values()){const s=t-l;(n===null||s>n)&&(n=s),s>r&&(r=s),s>=5e3&&(o+=1),s>=3e4&&(a+=1)}return{inFlightMs:n===null?null:Math.round(n),lastCallMs:this.#l===null?null:Math.round(this.#l),maxCallMs:this.#l===null&&n===null?null:Math.round(r),callsOver5s:o,callsOver30s:a,lastCallWindow:this.#a,wasmMemoryMB:this.#d===null?null:Math.round(this.#d/1048576)}}#h(t){const n=this.#i.get(t);if(n===void 0)return;this.#i.delete(t);const r=performance.now()-n;this.#l=r,r>this.#u&&(this.#u=r),r>=5e3&&(this.#f+=1),r>=3e4&&(this.#w+=1),this.#a!==null&&this.#a.start===n&&(this.#a={start:n,end:n+r})}#e(t){const n=++this.#y;return new Promise((r,o)=>{this.#n.set(n,{resolve:r,reject:o});const a=performance.now();this.#i.set(n,a),this.#a={start:a,end:null},this.#r.postMessage({...t,id:n})})}async#b(t){if("op"in t){if(t.op==="history"){this.#s.history?.(t.entries);return}if(t.op==="log"){this.#s.log?.(t.level,t.text);return}if(t.op==="memory"){this.#d=t.bytes;return}const r=t.frame;typeof r?.session=="string"&&typeof r.revision=="number"&&(this.#g={session:r.session,revision:r.revision});try{const o=await this.#s.present(t.frame,t.description,t.capture);this.#r.postMessage({op:"present-result",id:t.id,...o?.capture===void 0?{}:{capture:o.capture},...o!=null&&"held"in o?{held:o.held}:{}})}catch(o){this.#r.postMessage({op:"present-result",id:t.id,error:o instanceof Error?o.message:String(o)})}return}const n=this.#n.get(t.id);n&&(this.#n.delete(t.id),this.#h(t.id),"error"in t?n.reject(new Error(t.error)):n.resolve(t.result))}}const ot="/assets/agx-base-srgb-BjWZJgrZ.lut",at="/assets/agx-look-medium-high-contrast-D5F_ob1L.lut",st="/assets/agx-look-punchy-dxsnycNs.lut",it="/assets/filmic-srgb-Ct35FIH6.lut",A=new Float64Array(12),Ee=[0,0,0],F=new Float64Array(3),V=new Float64Array(3),B=new Int8Array([1,0,0,1,1,0,0,1,2,1,0,0,1,0,1,0,2,1,0,0,1,1,0,1,2,0,1,0,0,1,0,1,1,2,1,0,0,1,0,0,1,1,1,2,0,0,1,0,1,1,0,1,0,2]);function lt(e,t,n){return e>t?t>n?0:e>n?1:2:n>t?3:n>e?4:5}function je(e,t,n,r,o){const a=t*t,l=Math.min(1,Math.max(0,n))*(t-1),s=Math.min(1,Math.max(0,r))*(t-1),d=Math.min(1,Math.max(0,o))*(t-1),w=Math.min(Math.floor(l),t-2),i=Math.min(Math.floor(s),t-2),h=Math.min(Math.floor(d),t-2),k=l-w,g=s-i,c=d-h,b=(u,m,$,E)=>{const R=(w+m+(i+$)*t+(h+E)*a)*3;A[u]=e[R]/65535,A[u+1]=e[R+1]/65535,A[u+2]=e[R+2]/65535};b(0,0,0,0),b(9,1,1,1),F[0]=k,F[1]=g,F[2]=c;const p=lt(k,g,c)*9;b(3,B[p],B[p+1],B[p+2]),b(6,B[p+3],B[p+4],B[p+5]);const v=F[B[p+6]],y=F[B[p+7]],f=F[B[p+8]];for(let u=0;u<3;u++){const m=A[u];Ee[u]=m+v*(A[3+u]-m)+y*(A[6+u]-A[3+u])+f*(A[9+u]-A[6+u])}return Ee}function W(e){const t=e&32768?-1:1,n=e>>10&31,r=e&1023;return n===0?t*2**-24*r:n===31?r?Number.NaN:t*Number.POSITIVE_INFINITY:t*2**(n-15)*(1+r/1024)}function fe(e,t,n,r){const o=new Uint8ClampedArray(t*4);for(let a=0;a<t;a++){const l=a*4,s=W(e[l+3]),d=s===0?n:n/s;V[0]=W(e[l])*d,V[1]=W(e[l+1])*d,V[2]=W(e[l+2])*d;const w=r(V);o[l]=Math.round(w[0]*255),o[l+1]=Math.round(w[1]*255),o[l+2]=Math.round(w[2]*255),o[l+3]=Math.round(Math.min(1,Math.max(0,s))*255)}return o}function ct(e){return new URL(Object.assign({"./agx-base-srgb.lut":ot,"./agx-look-medium-high-contrast.lut":at,"./agx-look-punchy.lut":st,"./filmic-srgb.lut":it})[`./${e.replace(/\.lut$/,"")}.lut`],import.meta.url)}const ut=57,T=-12.47393,Te=12.5260688117,dt=[[.4123908,.3575843,.1804808],[.212639,.7151687,.0721923],[.0193308,.1191948,.9505322]],ht=[[1.5250528,-.3159135,-.1226583],[-.5091526,1.3333274,.1382844],[.0957153,.0508974,.7879558]];function Se(e,t,n){const r=t[0],o=t[1],a=t[2];n[0]=e[0][0]*r+e[0][1]*o+e[0][2]*a,n[1]=e[1][0]*r+e[1][1]*o+e[1][2]*a,n[2]=e[2][0]*r+e[2][1]*o+e[2][2]*a}const G=new Float64Array(3),Ce=new Float64Array(3),z=[0,0,0];function ne(e){const t=Math.min(1,Math.max(0,e));return t<=.0031308?12.92*t:1.055*t**(1/2.4)-.055}function Le(e,t,n,r){return je(e,ut,t,n,r)}function pt(e,t){Se(dt,t,Ce),Se(ht,Ce,G);const n=Te-T,r=Le(e,(Math.log2(Math.max(G[0],1e-10))-T)/n,(Math.log2(Math.max(G[1],1e-10))-T)/n,(Math.log2(Math.max(G[2],1e-10))-T)/n);return z[0]=ne(Math.max(0,r[0])**2.4),z[1]=ne(Math.max(0,r[1])**2.4),z[2]=ne(Math.max(0,r[2])**2.4),z}const ft={"AgX - Medium High Contrast":"agx-look-medium-high-contrast.lut","AgX - Punchy":"agx-look-punchy.lut"};function wt(e,t){const n=Te-T;return Le(e,(Math.log2(Math.max(t[0],1e-10))-T)/n,(Math.log2(Math.max(t[1],1e-10))-T)/n,(Math.log2(Math.max(t[2],1e-10))-T)/n)}function gt(e,t,n,r={}){const o=r.exposure??1,a=r.composedLook===!0?wt:pt;return fe(t,n,o,l=>a(e,l))}const Ie=33,ce=Ie**3*3,ue=4096,re=-12.473931188,oe=25;function ae(e,t){const n=Math.min(1,Math.max(0,t))*(ue-1),r=Math.min(Math.floor(n),ue-2),o=n-r;return((1-o)*e[ce+r]+o*e[ce+r+1])/65535}const H=[0,0,0];function yt(e,t){const n=je(e,Ie,(Math.log2(Math.max(t[0],1e-10))-re)/oe,(Math.log2(Math.max(t[1],1e-10))-re)/oe,(Math.log2(Math.max(t[2],1e-10))-re)/oe);return H[0]=ae(e,n[0]/.66),H[1]=ae(e,n[1]/.66),H[2]=ae(e,n[2]/.66),H}function bt(e,t,n,r){if(e.length!==ce+ue)throw new Error("Invalid Blender Filmic display table");return fe(t,n,r,o=>yt(e,o))}const U=2.4,I=.055,Re=I/(U-1),mt=1/(U/(1+I)*((Re+I)/(1+I))**(U-1)),Mt=((Re+I)/(1+I))**U;function se(e){return e>0?e<Mt?e*mt:(1+I)*e**(1/U)-I:0}const q=[0,0,0];function vt(e){return q[0]=se(e[0]),q[1]=se(e[1]),q[2]=se(e[2]),q}function xt(e,t,n){return fe(e,t,n,vt)}function Fe(e,t,n,r){if(!Number.isFinite(n.width)||!Number.isFinite(n.height)||n.width<1||n.height<1)throw new Error("Scene capture requires finite positive dimensions");const o=Math.min(2048,Math.round(n.width)),a=Math.min(2048,Math.round(n.height)),l=r?1:2,s=o*l,d=a*l,w=Ve(),i=w.renderer,h={target:i.getRenderTarget(),toneMapping:i.toneMapping,exposure:i.toneMappingExposure,colorSpace:i.outputColorSpace,shadows:i.shadowMap.enabled,shadowType:i.shadowMap.type,clearColor:i.getClearColor(new He),clearAlpha:i.getClearAlpha(),background:e.background};let k,g,c=!1;try{if(k=new ve(s,d,{type:qe}),i.shadowMap.enabled=!0,i.shadowMap.type=Xe,i.outputColorSpace=Ze,i.toneMapping=n.toneMapping??le,i.toneMappingExposure=n.exposure??1,i.setClearColor(0,n.transparent?0:1),n.transparent&&(e.background=null),i.setRenderTarget(k),i.clear(),i.render(e,t),r){const E=new Uint16Array(s*d*4);return i.readRenderTargetPixels(k,0,0,s,d,E),c=!0,{pixels:E,width:o,height:a}}g=new ve(s,d),We(n.transparent===!0).render(i,g,k,0,!1);const b=new Uint8Array(s*d*4);i.readRenderTargetPixels(g,0,0,s,d,b);const p=document.createElement("canvas");p.width=s,p.height=d;const v=p.getContext("2d");if(!v)throw new Error("Scene capture could not create an image canvas");const y=v.createImageData(s,d),f=s*4;for(let E=0;E<d;E++)y.data.set(b.subarray((d-1-E)*f,(d-E)*f),E*f);v.putImageData(y,0,0);const u=document.createElement("canvas");u.width=o,u.height=a;const m=u.getContext("2d");if(!m)throw new Error("Scene capture could not create an output canvas");m.drawImage(p,0,0,o,a);const $=u.toDataURL("image/png");return c=!0,$}finally{e.background=h.background,i.setRenderTarget(h.target),i.toneMapping=h.toneMapping,i.toneMappingExposure=h.exposure,i.outputColorSpace=h.colorSpace,i.shadowMap.enabled=h.shadows,i.shadowMap.type=h.shadowType,i.setClearColor(h.clearColor,h.clearAlpha),g?.dispose(),k?.dispose(),w.release({discard:!c})}}function kt(e,t,n){return Fe(e,t,n,!0)}function Et(e,t,n){return Fe(e,t,n,!1)}const St={transform:{cx:0,cy:0,zoom:1},looked:null,refusal:null,size:{w:0,h:0},framedAt:0,drawn:[]};let de=St,we=0;const Z=new Set;let Ne=0;function ie(){return de}function Wt(){return we}function Gt(e){return Z.add(e),()=>{Z.delete(e)}}function O(e){de={...de,...e},we+=1;for(const t of[...Z])t()}function Ct(){Ne+=1,we+=1;for(const e of[...Z])e()}function zt(){return Ne}function N(e){O({refusal:e})}const Ae=new Map;function At(e){let t=Ae.get(e);return t||(t=fetch(ct(e)).then(async n=>{if(!n.ok)throw new Error(`Blender display table ${e}: ${n.status} ${n.statusText}`);return new Uint16Array(await n.arrayBuffer())}),Ae.set(e,t)),t}function Bt(e){const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return new Uint16Array(n.buffer,n.byteOffset,n.byteLength>>1)}async function Be(e,t){const n=t.look??"None",r=t.toneMapping==="filmic",o=t.toneMapping==="none";if(!o&&t.toneMapping!=="agx"&&!r)throw new Error("Blender's Khronos PBR Neutral view transform has no scene-linear implementation in the browser, so it cannot resolve a composited or scene-referred frame (implemented: Standard, AgX, Filmic)");const a=o?null:r?"filmic-srgb.lut":n==="None"?"agx-base-srgb.lut":ft[n];if(a===void 0)throw new Error(`Blender display transform has no table for look ${n}`);const l=a?await At(a):null,s=t.linearInput,d=s?{pixels:Bt(s.base64),width:s.width,height:s.height}:e;if(!d)throw new Error("Blender display transform requires a linear capture");const{pixels:w,width:i,height:h}=d,k=o?xt(w,i*h,t.exposure):r?bt(l,w,i*h,t.exposure):gt(l,w,i*h,{exposure:t.exposure,composedLook:n!=="None"}),g=document.createElement("canvas");g.width=i,g.height=h;const c=g.getContext("2d");if(!c)throw new Error("Blender display transform could not create its image canvas");const b=c.createImageData(i,h),p=i*4;for(let f=0;f<h;f++){const u=(h-1-f)*p;b.data.set(k.subarray(u,u+p),f*p)}c.putImageData(b,0,0);const v=g.toDataURL("image/png"),y={base64:v.slice(v.indexOf(",")+1),mimeType:"image/png"};if(t.linear===!0){const f=new Uint8Array(w.buffer,w.byteOffset,w.byteLength);let u="";for(let m=0;m<f.length;m+=32768)u+=String.fromCharCode(...f.subarray(m,m+32768));y.linearBase64=btoa(u),y.linearWidth=i,y.linearHeight=h}return y}const _t="document:blender:runtime";let K=null;function jt(e){K=e}function L(){return K?.documentId??_t}function Ht(){return L()}async function qt(e,t,n){jt({documentId:e,entryId:n,blend:t});const r=_();if(!r.session.open())return;const o=r.projectLocalState.projectRootPath();o!==null&&(await M().start(o,t),await M().present())}function j(){return S?.project!=null}let $e=0;const he=new Set;function Xt(){return $e}function Zt(e){return he.add(e),()=>{he.delete(e)}}function Y(){$e+=1;for(const e of[...he])e()}async function Kt(e,t){return j()?M().rna(e,t):null}async function Yt(e,t){return j()?M().rnaContext(e,t):null}async function Tt(e,t,n,r,o=!0){if(!j())return null;const a=await M().rnaSet(e,t,n,r,o);return Y(),a}async function Lt(e,t=!0,n="Blender Python"){const r=await M().execute(e,t,n);Y();const o=/^Error executing code:/.exec(r);return{text:r,executed:o===null,result:o===null?r.replace(/^Code executed successfully: ?/,""):"",error:o===null?null:r.replace(/^Error executing code: ?/,"")}}function Jt(){M().historyGesture("history-begin").catch(e=>_().console.error(`Could not begin Blender undo gesture: ${String(e)}`,"blender-history"))}async function Qt(){await M().historyGesture("history-end")}async function en(e){return j()?M().outliner(e):null}async function tn(e){return j()?M().nodeTree(e):null}async function nn(e){return j()?M().uvLayout(e):null}async function rn(e){return j()?M().rig(e):null}async function on(e){return j()?M().actionClip(e):null}async function It(e,t,n){if(!j())return null;const r=await M().outlinerSet(e,t,n);return Y(),r}const Rt={view:"blender-node-view",title:"Node Editor",verbs:[["state",void 0],["look",void 0],["view-all","Node Editor: Frame All"],["zoom",void 0],["pan",void 0],["move",void 0],["link",void 0],["set-value",void 0],["use-nodes",void 0],["collapse-panel",void 0]].map(([e,t])=>({id:e,...t?{title:t}:{},run:n=>Oe({...n,action:e})}))};function Oe(e){const t=typeof e.action=="string"?e.action:"state";switch(t){case"state":break;case"look":O({looked:typeof e.node=="string"?e.node:null,refusal:null});break;case"view-all":Ct(),O({refusal:null});break;case"zoom":{const n=typeof e.zoom=="number"?e.zoom:1;O({transform:{...ie().transform,zoom:n},refusal:null});break}case"pan":{const n=ie().transform;O({transform:{...n,cx:typeof e.cx=="number"?e.cx:n.cx,cy:typeof e.cy=="number"?e.cy:n.cy},refusal:null});break}case"move":N(`Moving "${String(e.node??"a node")}" writes Node.location — editing parity is not the program.`);break;case"link":N("Dragging between sockets would make a link — editing parity is not the program.");break;case"set-value":N(`Changing "${String(e.socket??"a socket")}" writes the socket's default_value — editing parity is not the program.`);break;case"use-nodes":N("Use Nodes writes Material.use_nodes — editing parity is not the program.");break;case"collapse-panel":N(`Collapsing "${String(e.panel??"a panel")}" writes the panel's is_collapsed — editing parity is not the program.`);break;default:N(`blender-node-view: no action "${t}" — state, look, view-all, zoom, pan, and the refusals move, link, set-value, use-nodes, collapse-panel.`)}return ie()}let S=null;const X=new Set;function Ue(){X.size&&_().history.invalidate([...X]),X.clear()}let pe=null,_e=!1;function De(){Ue(),pe?.abort(),pe=null,S?.terminate(),S=null}function Ft(){_e||(_e=!0,_().session.onEnded(De))}const Nt=e=>typeof e=="object"&&e!==null&&typeof e.applyFrame=="function"&&typeof e.snapshot=="function"&&typeof e.captureSnapshot=="function"&&typeof e.recordPresentation=="function"&&typeof e.recordPhotograph=="function";async function $t(){const{documents:e}=_(),t=await e.waitForContext(L(),15e3);if(Nt(t))return t;throw new Error('The Blender Model document is not open, or the open one is not a Model this engine can present to (it must answer applyFrame, captureSnapshot, recordPresentation and recordPhotograph): present {kind: "document", id: "blender:runtime"} first (it ships with the editor; `vgai blender-mcp` presents it before its first call).')}function M(){if(S!==null)return S;Ft();const e=new AbortController;pe=e;let t=!1;S=new rt({history:r=>{const o=S;if(!o)throw new Error("Blender history arrived before its runtime");for(const a of r){if("reset"in a){Ue();continue}if(!a.resource)throw new Error("A Blender edit has no document resource");X.add(a.resource);const l=async s=>{if(S!==o)throw new Error("This Blender history belongs to a closed worker");const d=await o.historyStep(a.id,s);return Y(),d};_().history.record({id:a.id,label:a.label,resources:[a.resource],document:L(),undo:()=>l("undo"),redo:()=>l("redo")})}},present:async(r,o,a)=>{const l=L(),s=await $t();if(e.signal.throwIfAborted(),L()!==l)throw new Error("Blender document changed before its frame could be presented");const d=s.applyFrame(r),w=typeof d=="object"&&d!==null&&"held"in d,i=w?d.held:null,h=f=>({...f===void 0?{}:{capture:f},...w?{held:i}:{}});if(s.recordPresentation(o),!a||!a.render)return h(void 0);const k=s.snapshot(),g=()=>{if(e.signal.throwIfAborted(),L()!==l||s.snapshot()!==k)throw new Error("Blender capture document or source revision changed before completion")};if(a.render.linearInput){const f=await Be(null,a.render);return g(),h(f)}const{render:c,position:b,target:p,up:v}=a;if(!b||!p||!v)throw new Error("A Blender render capture must carry the scene camera position, target and up");if(t)throw new Error("A Blender render capture is already in progress");const y=s.captureSnapshot();t=!0,e.signal.addEventListener("abort",y.dispose,{once:!0});try{g();const f=new Ke;f.add(y.root),f.updateMatrixWorld(!0);const u=y.root.matrixWorld,m=new Ye().copy(u).invert(),$=new xe().setFromMatrix4(u),E=new xe().setFromMatrix4(m),R=new te(b[0],b[1],b[2]).applyMatrix4(u),ge=new te(p[0],p[1],p[2]).applyMatrix4(u),ye=new te(v[0],v[1],v[2]).applyMatrix3($),J=Math.min(2048,Math.round(c.width))/Math.min(2048,Math.round(c.height)),be=Ge(y.root).getBoundingSphere(new Je),D=nt(R.distanceTo(be.center),be.radius);let C;if(c.orthographic){const P=c.fov/2;C=new Qe(-P*J,P*J,P,-P,D.near,D.far)}else C=new et(c.fov,J,D.near,D.far);C.up.copy(ye),C.position.copy(R),C.lookAt(ge),C.updateMatrixWorld(!0);const Q={position:R.clone().applyMatrix4(m).toArray(),target:ge.clone().applyMatrix4(m).toArray(),up:ye.clone().applyMatrix3(E).toArray()};s.recordPhotograph({sent:{position:b,target:p,up:v},photographed:Q,render:{width:c.width,height:c.height,fov:c.fov,orthographic:c.orthographic}});const Pe={none:le,agx:ke,neutral:tt,filmic:le};await y.prepare(C),g();const me={width:c.width,height:c.height,transparent:c.transparent===!0,toneMapping:Pe[c.toneMapping]??ke,exposure:c.exposure},Me=c.toneMapping==="agx"||c.toneMapping==="filmic"||c.linear===!0?await Be(kt(f,C,me),c):null;if(g(),Me)return h({...Me,camera:Q});const ee=Et(f,C,me);if(!ee)throw new Error("Blender render could not capture its image");return h({base64:ee.slice(ee.indexOf(",")+1),mimeType:"image/png",camera:Q})}finally{t=!1,e.signal.removeEventListener("abort",y.dispose),y.dispose()}},log:(r,o)=>(r==="error"?console.error:console.log)(`[blender] ${o}`)});const n=S;return _().session.reportWorkerCallMeter(()=>n.metrics()),S}const Ot="models/model.blend",x=(e,t)=>{const n=e[t];if(typeof n!="string")throw new Error(`${String(e.type)} requires a string "${t}"`);return n};async function Ut(e){const t=_().projectLocalState.projectRootPath();if(t===null)return{};let n;try{n=await e.execute(`import bpy
2
- print(bpy.data.filepath)
3
- `,!1)}catch{return{}}if(/^Error executing code:/m.test(n))return{};const r=n.replace(/^Code executed successfully:/,"").split(`
4
- `).map(a=>a.trim()).filter(a=>a.startsWith("/")).pop()??"";if(r==="")return{};const o=t.endsWith("/")?t:`${t}/`;return r.startsWith(o)?{document:r.slice(o.length)}:{}}async function an(e){const t=_();if(e.type==="blender-status")return{ok:!0,data:{started:S?.project!=null,document:t.documents.context(L())!==void 0}};if(!t.session.open())return{ok:!1,error:`${e.type} needs an open project session; this editor page has none.`};try{const n=e.type==="blender-start"?x(e,"project"):null;if((e.type==="blender-stop"||e.type==="blender-start"&&e.fresh===!0)&&(De(),e.type==="blender-stop"))return{ok:!0,data:{stopped:!0}};if(e.type==="blender-start"&&!t.documents.context(L())&&!await t.workspace.open({kind:"document",id:"blender:runtime"}))return{ok:!1,error:"blender-start could not open the Blender Model document: nothing in this editor opens {kind: 'document', id: 'blender:runtime'} (it ships with @volter/editor-blender)."};const r=M();switch(e.type){case"blender-start":{const o=typeof e.document=="string"?e.document:K?.blend??Ot;return{ok:!0,data:{...await r.start(n,o)}}}case"blender-execute":return{ok:!0,data:{result:(await Lt(x(e,"code"))).text}};case"blender-scene-info":return{ok:!0,data:{result:await r.sceneInfo()}};case"blender-object-info":return{ok:!0,data:{result:await r.objectInfo(x(e,"name"))}};case"blender-rna":{const o=typeof e.names=="number"?e.names:void 0;return{ok:!0,data:{result:await r.rna(x(e,"path"),o)}}}case"blender-rna-context":{const o=typeof e.object=="string"?e.object:void 0,a=typeof e.collection=="string"?e.collection:void 0;return{ok:!0,data:{result:await r.rnaContext(o,a)}}}case"blender-rna-set":{const o=typeof e.index=="number"?e.index:void 0;return{ok:!0,data:{result:await Tt(x(e,"path"),x(e,"property"),e.value,o)}}}case"blender-outliner":{const o=Array.isArray(e.selected)?e.selected.filter(a=>typeof a=="string"):void 0;return{ok:!0,data:{result:await r.outliner(o)}}}case"blender-node-tree":return{ok:!0,data:{result:await r.nodeTree({...typeof e.path=="string"?{path:e.path}:{},...typeof e.material=="string"?{material:e.material}:{}})}};case"blender-uv-layout":return{ok:!0,data:{result:await r.uvLayout({...typeof e.object=="string"?{object:e.object}:{},...typeof e.uvLayer=="string"?{uvLayer:e.uvLayer}:{}})}};case"blender-rig":return{ok:!0,data:{result:await r.rig({...typeof e.object=="string"?{object:e.object}:{}})}};case"blender-action-clip":return{ok:!0,data:{result:await r.actionClip({...typeof e.object=="string"?{object:e.object}:{},...typeof e.bake=="boolean"?{bake:e.bake}:{}})}};case"blender-node-view":{const o=typeof e.action=="string"?e.action:"state";return{ok:!0,data:{result:Rt.verbs.some(l=>l.id===o)?ze("blender-node-view",o,e):Oe(e)}}}case"blender-outliner-set":return{ok:!0,data:{result:await It(x(e,"path"),x(e,"column"),e.value!==!1)}};case"blender-screenshot-view":{const o=typeof e.maxSize=="number"?e.maxSize:1e3,a={kind:"document",id:K?.entryId??"blender:runtime"};return{ok:!0,data:{...await r.screenshotView(o),document:a}}}case"blender-read-file":{const o=await r.readFile(x(e,"path")),a=x(e,"transferId"),l=await fetch(`/__editor/blender-file?id=${encodeURIComponent(a)}`,{method:"POST",headers:{"content-type":"application/octet-stream"},body:new Blob([o])});return l.ok?{ok:!0,data:{bytes:o.length}}:{ok:!1,error:`Transfer ${a} was refused: ${l.status}`}}case"blender-write-file":{const o=atob(x(e,"base64")),a=Uint8Array.from(o,l=>l.charCodeAt(0));return await r.writeFile(x(e,"path"),a),{ok:!0,data:{written:a.length}}}case"blender-list-files":{const o=await r.listFiles(x(e,"path")),a=r.presented;return{ok:!0,data:{entries:o,...a?{session:a.session,revision:a.revision}:{},...await Ut(r)}}}}return{ok:!1,error:`Unknown Blender command ${e.type}`}}catch(n){return{ok:!1,error:n instanceof Error?n.message:String(n)}}}export{Rt as N,Ht as a,j as b,It as c,en as d,Xt as e,Gt as f,O as g,an as h,ie as i,tn as j,zt as k,on as l,rn as m,Wt as n,nn as o,Tt as p,Qt as q,N as r,Zt as s,Jt as t,Lt as u,qt as v,jt as w,Y as x,Yt as y,Kt as z};
@@ -1 +0,0 @@
1
- import{h as l}from"./blender-runtime-host-DGe1KLVZ.js";import"./index-CY4oDLhJ.js";import"./index-DaQZGF7d.js";import"./_commonjsHelpers-D6-XlEtG.js";import"./index-D_NuPfjr.js";import"./jsx-runtime-DPjLkJKQ.js";import"./index-CtzuWnCS.js";import"./index-CinJrH5C.js";import"./index-D2LwEE0L.js";import"./client-DNXj_opT.js";import"./three.module-BynznMJN.js";import"./clip-planes-CnAI6DZn.js";const v="workspace.command",e=(o,n)=>({...n===void 0?{}:{timeoutMs:n},derivedRefresh:o,handle:r=>l(r)}),y={"blender-start":e("none",12e4),"blender-stop":e("none"),"blender-execute":e("always",30*6e4),"blender-scene-info":e("none",6e4),"blender-object-info":e("none",6e4),"blender-screenshot-view":e("always",6e4),"blender-read-file":e("none",6e4),"blender-write-file":e("none",6e4),"blender-list-files":e("none"),"blender-rna":e("none",6e4),"blender-rna-context":e("none",6e4),"blender-rna-set":e("always",6e4),"blender-outliner":e("none",6e4),"blender-node-tree":e("none",6e4),"blender-uv-layout":e("none",6e4),"blender-rig":e("none",6e4),"blender-action-clip":e("none",12e4),"blender-node-view":e("none"),"blender-outliner-set":e("always",6e4),"blender-status":e("none")};export{y as commands,v as point};
@@ -1,2 +0,0 @@
1
- const d="/work/.vgai-session",oe=`${d}/session.py`,ae=[`${d}/in`,`${d}/reply`],_="/__editor/blender-wasm";function L(e){return new URL(`${_}/${e}`,import.meta.url).href}async function M(){const e=await fetch(L("status"));return e.ok?await e.json():{available:!1,skew:null,dir:null,sizes:{},encoded:{},missing:[`${_}/status answered ${e.status}`]}}async function D(e){const r=await M();if(!r.available)throw new Error(`The headless Blender WebAssembly build is not served by this editor: ${r.missing.join("; ")}`);if(r.skew==="wali"){const{startWaliBlenderEngine:t}=await import("./blender-wali-engine-Dtwixi7B.js");return t(e,r)}const{startEmscriptenBlenderEngine:n}=await import("./blender-emscripten-engine-BkrPLmPf.js");return n(e,r)}function U(e){return e<200?1:e<5e3?5:25}const C=e=>new Promise(r=>setTimeout(r,e)),T=new TextDecoder;function se(e,r,n){let t=0,a=0;const o=new Set;async function s(u){for(const l of o)u.has(`${l}.done`)||(await e.unlink(`${d}/reply/${l}.json`),await e.unlink(`${d}/reply/${l}.done`),o.delete(l))}async function i(){let u;try{u=await e.readdir(`${d}/ask`)}catch{return}const l=new Set(u.filter(h=>h.endsWith(".done")));await s(l);for(const h of l){const y=h.slice(0,-5);if(Number(y)<=a)continue;a=Number(y);const m=JSON.parse(T.decode(await e.readFile(`${d}/ask/${y}.json`)));let j;try{j=await r.ask(m)}catch(v){j={error:v instanceof Error?v.message:String(v)}}await e.writeFile(`${d}/reply/${y}.json`,JSON.stringify(j??null)),await e.writeFile(`${d}/reply/${y}.done`,"1"),o.add(y)}}async function c(u){const l=String(++t);await e.writeFile(`${d}/in/${l}.json`,JSON.stringify(u)),await e.writeFile(`${d}/in/${l}.done`,"1");const h=performance.now();for(;;){if(await i(),await e.stat(`${d}/out/${l}.done`)){const m=JSON.parse(T.decode(await e.readFile(`${d}/out/${l}.json`)));if(await e.unlink(`${d}/in/${l}.json`),await e.unlink(`${d}/in/${l}.done`),m.error)throw new Error(m.error);return m.result}const y=n?.();if(y)throw new Error(`Blender is gone, so this call will never be answered: ${y}. The session keeps its directory and its cached banner, so every later call would wait on the same missing answer; start a new program with \`blender-start {fresh: true}\` (\`VGAI_BLENDER_FRESH_SESSION=1\` for the battery harness).`);await C(U(performance.now()-h))}}return{request:c}}const N=e=>typeof e=="object"&&e!==null&&typeof e.offset=="number"&&typeof e.length=="number"&&typeof e.dtype=="string"&&typeof e.count=="number"&&typeof e.stride=="number",J={f32:e=>new Float32Array(e.buffer,e.byteOffset,e.byteLength>>2),f64:e=>new Float64Array(e.buffer,e.byteOffset,e.byteLength>>3),u32:e=>new Uint32Array(e.buffer,e.byteOffset,e.byteLength>>2),i32:e=>new Int32Array(e.buffer,e.byteOffset,e.byteLength>>2),u16:e=>new Uint16Array(e.buffer,e.byteOffset,e.byteLength>>1),i16:e=>new Int16Array(e.buffer,e.byteOffset,e.byteLength>>1),u8:e=>e,i8:e=>new Int8Array(e.buffer,e.byteOffset,e.byteLength)};function V(e,r,n){const t=J[n.dtype];if(!t)throw new Error(`Blender frame column ${r}: unknown dtype ${n.dtype}`);const{offset:a,length:o}=n;if(a<0||o<0||a+o>e.byteLength)throw new Error(`Blender frame column ${r}: bytes ${a}..${a+o} lie outside the ${e.byteLength}-byte export arena`);const s=e.subarray(a,a+o).slice(),i=t(s),c=n.count*n.stride;if(i.length!==c)throw new Error(`Blender frame column ${r}: ${i.length} values, ${c} declared (${n.count} x ${n.stride})`);return i}function W(e,r){const n=(t,a)=>{if(N(t)){const o=V(e,a,t);return a==="co"?Float64Array.from(o):o}if(Array.isArray(t))return t.map(o=>n(o,a));if(typeof t=="object"&&t!==null){const o={};for(const[s,i]of Object.entries(t))o[s]=n(i,s);return o}return t};return n(r,"")}async function z(e,r){const n=async(t,a)=>{if(N(t)){const{offset:o,length:s,dtype:i}=t;if(o<0||s<0||o+s>e.byteLength)throw new Error(`Blender frame column ${a}: bytes ${o}..${o+s} lie outside the ${e.byteLength}-byte export arena`);const c=e.subarray(o,o+s).slice(),u=await crypto.subtle.digest("SHA-256",c),l=[...new Uint8Array(u)].map(h=>h.toString(16).padStart(2,"0")).join("");return{dtype:i,length:s,sha256:l}}if(Array.isArray(t))return Promise.all(t.map(o=>n(o,a)));if(typeof t=="object"&&t!==null){const o={};for(const[s,i]of Object.entries(t))o[s]=await n(i,s);return o}return t};return n(r,"")}const $=e=>self.postMessage(e),p=(e,r)=>$({op:"log",level:e,text:r});let b=null,O=null,G=0;const A=new Map;function H(e,r,n){const t=++G,a=[],o=e;for(const s of[o?.meshes??{},o?.images??{}])for(const i of Object.values(s))for(const c of Object.values(i))ArrayBuffer.isView(c)&&c.buffer instanceof ArrayBuffer&&!a.includes(c.buffer)&&a.push(c.buffer);return new Promise((s,i)=>{A.set(t,{resolve:s,reject:i}),self.postMessage({op:"present",id:t,frame:e,description:r,...n?{capture:n}:{}},a)})}let f=null,E=null,S=null,k=0;const K=1e3;function F(){E!==null&&(S!==null&&clearTimeout(S),S=setTimeout(()=>{S=null,Q()},K))}async function Q(){if(!f||E===null)return;if(k>0){F();return}const e=E;let r;try{r=await f.request({op:"save-document"})}catch(t){p("error",`@@VGAI-ERROR the Blender document ${e} could not be saved: ${g(t)}`);return}if(!r?.saved||typeof r.path!="string")return;let n;try{n=await f.files.readFile(r.path)}catch(t){p("error",`@@VGAI-ERROR the Blender document ${e} was saved but could not be read back out of the engine: ${g(t)}`);return}w.delete(r.path);try{const t=await fetch(`/__editor/blender-document?path=${encodeURIComponent(e)}`,{method:"POST",headers:{"content-type":"application/octet-stream"},body:new Blob([n])});if(!t.ok){const a=await t.text().catch(()=>"");p("error",`@@VGAI-ERROR the Blender document ${e} was not written to the project: HTTP ${t.status} ${a}`);return}}catch(t){p("error",`@@VGAI-ERROR the Blender document ${e} was not written to the project: ${g(t)}`);return}p("log",`@@VGAI-DOCUMENT ${JSON.stringify({path:e,bytes:n.length})}`)}async function X(e,r){const n={engine:null},t=await D({project:e,log:p,ask:async({frame:o,capture:s,saveDue:i})=>{if(!n.engine)throw new Error("The Blender session presented before it started");i&&F();const c=await n.engine.readArena(),u=await z(c,o),l=await H(W(c,o),u,s);return{...typeof l.capture=="object"&&l.capture!==null?l.capture:{},..."held"in l?{held:l.held}:{}}}});n.engine=t,f=t,r&&await P(t.files,e);const a=await t.request({op:"start",project:e,...r?{document:r}:{}});return r&&(E=r),b={start:async()=>a,execute:async o=>{const s=await t.request({op:"execute",code:o});return s.error?`Error executing code: ${s.error}`:`Code executed successfully: ${s.result}`},sceneInfo:async()=>JSON.stringify(await t.request({op:"scene-info"}),null,2),objectInfo:async o=>JSON.stringify(await t.request({op:"object-info",name:o}),null,2),screenshotView:async o=>(await t.request({op:"present",capture:{size:o}}),JSON.stringify({view:{size:o}}))},{...a,engine:"blender-wasm",skew:t.skew,bootMs:Math.round(t.bootMs),releasedPayloadMB:t.releasedPayloadBytes===null?null:Math.round(t.releasedPayloadBytes/1048576)}}async function Y(){try{const e=await fetch("/__editor/blender-wasm/status");return e.ok?await e.json():{available:!1,missing:[`status answered ${e.status}`]}}catch(e){return{available:!1,missing:[String(e)]}}}async function Z(e,r){if(b)throw new Error("The Blender session is already started");if(!e.startsWith("/"))throw new Error("The Blender session needs the project's absolute path");if(r!==void 0&&!q(r))throw new Error(`The Blender document must be a project-relative .blend path with no traversal (models/model.blend); got ${JSON.stringify(r)}`);const n=await Y();if(!n.available)throw new Error(`Headless Blender is not served by this editor, so there is no modeling engine: ${n.missing.join("; ")}. The engine is Blender compiled to WebAssembly (packages/blender-engine/wasm, or the directory VGAI_BLENDER_WASM_DIR names); nothing stands in for it.`);return O=e,X(e,r)}function q(e){return!e.endsWith(".blend")||e.startsWith("/")||e.includes("\\")?!1:e.split("/").every(n=>n!==""&&n!=="."&&n!=="..")}const I=new Set;function B(e){I.has(e)||(I.add(e),p("error",e))}async function ee(e){const r=s=>(B(`The project's files are not readable from Python: ${s}`),null);let n;try{n=await fetch("/__editor/blender-project-index")}catch(s){return r(String(s))}if(!n.ok)return r(`/__editor/blender-project-index answered ${n.status}`);let t;try{if(t=await n.json(),typeof t?.root!="string"||!Array.isArray(t.files))return r("invalid project index")}catch(s){return r(String(s))}const{root:a,files:o}=t;return a!==e&&B(`The editor serving this tab has ${a} open, not ${e}; its files are mounted at ${e}, which is where Python is looking.`),o}const w=new Map;async function te(e,r){const n=await e.stat(r);return n?`${n.size}:${n.mtimeMs}`:""}async function P(e,r){const n=await ee(r);if(!n)return;const t=new Set(n.map(a=>`${r}/${a.path}`));for(const a of[...w.keys()])if(!t.has(a)){try{await e.unlink(a)}catch{}w.delete(a)}for(const a of n){const o=`${r}/${a.path}`,s=`${a.size}:${a.mtime}`;if(w.get(o)?.host===s||!w.has(o)&&await e.stat(o)!==null)continue;const i=await fetch(`/__editor/blender-project-file?path=${encodeURIComponent(a.path)}`);if(!i.ok){B(`${a.path}: HTTP ${i.status}`);continue}const c=o.slice(0,o.lastIndexOf("/"));c&&await e.mkdirTree(c),await e.writeFile(o,new Uint8Array(await i.arrayBuffer())),w.set(o,{host:s,engine:await te(e,o)})}}async function ne(e,r){const n=[],t=async a=>{let o;try{o=await e.readdir(a)}catch{return}for(const s of o){if(s==="."||s==="..")continue;const i=`${a.replace(/\/$/,"")}/${s}`,c=await e.stat(i);if(c){if((c.mode&61440)===16384){await t(i);continue}w.get(i)?.engine!==`${c.size}:${c.mtimeMs}`&&n.push({path:i,size:c.size,mtime:c.mtimeMs})}}};return await t(r),n}async function R(e){switch(e.op){case"start":return Z(e.project,e.document);case"present-result":{const t=A.get(e.id);A.delete(e.id),t&&(e.error?t.reject(new Error(e.error)):t.resolve({...e.capture===void 0?{}:{capture:e.capture},..."held"in e?{held:e.held}:{}}));return}}if(!b||!O||!f)throw new Error("The Blender session has not started");const r=f.files,n=f.request.bind(f);switch(e.op){case"history-begin":case"history-end":return n({op:e.op});case"history-step":return n({op:"history-step",token:e.token,direction:e.direction});case"execute":await P(r,O);{const t=await n({op:"execute",code:e.code,history:e.history??!0,label:e.label??"Blender Python"});return t.error?`Error executing code: ${t.error}`:`Code executed successfully: ${t.result}`}case"present":return n({op:"present"});case"scene-info":return b.sceneInfo();case"object-info":return b.objectInfo(e.name);case"rna":return n({op:"rna",path:e.path,...e.names===void 0?{}:{names:e.names}});case"rna-context":return n({op:"rna-context",...e.object===void 0?{}:{object:e.object},...e.collection===void 0?{}:{collection:e.collection}});case"rna-set":return n({op:"rna-set",history:e.history!==!1,path:e.path,property:e.property,value:e.value,...e.index===void 0?{}:{index:e.index}});case"outliner":return n({op:"outliner",...e.selected===void 0?{}:{selected:[...e.selected]}});case"node-tree":return n({op:"node-tree",...e.path===void 0?{}:{path:e.path},...e.material===void 0?{}:{material:e.material}});case"uv-layout":return n({op:"uv-layout",...e.object===void 0?{}:{object:e.object},...e.uvLayer===void 0?{}:{uvLayer:e.uvLayer}});case"rig":return n({op:"rig",...e.object===void 0?{}:{object:e.object}});case"action-clip":return n({op:"action-clip",...e.object===void 0?{}:{object:e.object},...e.bake===void 0?{}:{bake:e.bake}});case"outliner-set":return n({op:"outliner-set",path:e.path,column:e.column,value:e.value});case"screenshot-view":return JSON.parse(await b.screenshotView(e.maxSize));case"read-file":return r.readFile(e.path);case"write-file":{const t=e.path.slice(0,e.path.lastIndexOf("/"));t&&await r.mkdirTree(t),await r.writeFile(e.path,e.bytes),w.delete(e.path);return}case"list-files":return ne(r,e.path)}throw new Error(`Unknown Blender worker request ${e.op}`)}function g(e){if(e instanceof Error)return e.stack??`${e.name}: ${e.message}`;if(typeof e=="object"&&e!==null){const r=e;if(typeof r.message=="string")return typeof r.name=="string"?`${r.name}: ${r.message}`:r.message;try{return JSON.stringify(e)??Object.prototype.toString.call(e)}catch{return Object.prototype.toString.call(e)}}return String(e)}function re(){if(!f)return;const e=f.memoryBytes();e!==null&&$({op:"memory",bytes:e})}self.onmessage=async e=>{const r=e.data;if(r.op==="present-result"){await R(r);return}k+=1;try{const n=await R(r);await x(),$({id:r.id,result:n})}catch(n){let t=g(n);try{await x()}catch(a){t+=`
2
- Unable to deliver Blender history: ${g(a)}`}$({id:r.id,error:t})}finally{k-=1}re()};async function x(){if(!f||!b)return;const e=await f.request({op:"history-events"});e.length&&$({op:"history",entries:e})}export{_ as A,ae as P,d as S,oe as a,L as b,se as o,C as s};