@babylonjs/mcp-servers 9.15.0 → 9.16.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.
@@ -92,7 +92,7 @@ fn main() {}`,{bindingsMapping:{}}]},NodeRenderGraphIblShadowsRendererBlock:{cla
92
92
  `)}function Dx(e){const t=Tn[e];if(!t)return`Unknown block type "${e}". Use list_block_types to see available types.`;const r=[`## ${e}`,`**Category**: ${t.category}`,`**Description**: ${t.description}`,"","### Inputs"];if(t.inputs.length===0)r.push("_(none)_");else for(const o of t.inputs)r.push(`- \`${o.name}\` \u2014 **${o.type}**${o.isOptional?" _(optional)_":""}`);if(r.push("","### Outputs"),t.outputs.length===0)r.push("_(none)_");else for(const o of t.outputs)r.push(`- \`${o.name}\` \u2014 **${o.type}**`);if(t.properties&&Object.keys(t.properties).length>0){r.push("","### Configurable Properties");for(const[o,n]of Object.entries(t.properties))r.push(`- \`${o}\`: ${n}`)}return t.defaultAdditionalConstructionParameters!==void 0&&r.push("","### additionalConstructionParameters",`Default: \`${JSON.stringify(t.defaultAdditionalConstructionParameters)}\``,"These are embedded in the serialised block. Override them when calling add_block if needed."),r.join(`
93
93
  `)}class Ax{_graphs=new Map;_nextId=1;create(t,r){if(this._graphs.has(t))throw new Error(`A render graph named "${t}" already exists. Choose a different name or delete the existing one first.`);const o={customType:"BABYLON.NodeRenderGraph",name:t,comment:r,blocks:[],editorData:{locations:[]}};return this._graphs.set(t,o),o}delete(t){if(!this._graphs.has(t))throw new Error(`Render graph "${t}" not found.`);this._graphs.delete(t)}clearAll(){this._graphs.clear(),this._nextId=1}list(){return[...this._graphs.keys()]}get(t){const r=this._graphs.get(t);if(!r)throw new Error(`Render graph "${t}" not found. Use create_render_graph first.`);return r}addBlock(t,r,o,n){const i=this.get(t),a=Tn[r];if(!a)throw new Error(`Unknown block type "${r}". Call list_block_types to see all available block types.`);const s=this._nextId++,c=o??r,u=n!==void 0?n:a.defaultAdditionalConstructionParameters!==void 0?a.defaultAdditionalConstructionParameters:void 0,l=a.inputs.map(p=>({name:p.name})),d=a.outputs.map(p=>({name:p.name})),m={customType:`BABYLON.${r}`,id:s,name:c,inputs:l,outputs:d};return u!==void 0&&(m.additionalConstructionParameters=u),r==="NodeRenderGraphOutputBlock"&&(i.outputNodeId=s),i.blocks.push(m),i.editorData.locations.push({blockId:s,x:(i.blocks.length-1)*220,y:100}),m}addBlocksBatch(t,r){return r.map(o=>this.addBlock(t,o.blockType,o.blockName,o.additionalConstructionParameters))}removeBlock(t,r){const o=this.get(t),n=o.blocks.findIndex(i=>i.id===r);if(n===-1)throw new Error(`Block id ${r} not found in graph "${t}".`);o.blocks.splice(n,1);for(const i of o.blocks)for(const a of i.inputs)a.targetBlockId===r&&(delete a.inputName,delete a.targetBlockId,delete a.targetConnectionName);o.outputNodeId===r&&delete o.outputNodeId,o.editorData&&(o.editorData.locations=o.editorData.locations.filter(i=>i.blockId!==r))}connect(t,r,o,n,i){const a=this.get(t),s=a.blocks.find(d=>d.id===r),c=a.blocks.find(d=>d.id===n);if(!s)throw new Error(`Source block id ${r} not found in graph "${t}".`);if(!c)throw new Error(`Target block id ${n} not found in graph "${t}".`);if(!s.outputs.find(d=>d.name===o))throw new Error(`Output port "${o}" not found on block "${s.name}" (id ${r}). Available outputs: ${s.outputs.map(d=>d.name).join(", ")||"(none)"}`);const l=c.inputs.find(d=>d.name===i);if(!l)throw new Error(`Input port "${i}" not found on block "${c.name}" (id ${n}). Available inputs: ${c.inputs.map(d=>d.name).join(", ")||"(none)"}`);l.inputName=i,l.targetBlockId=r,l.targetConnectionName=o}connectBatch(t,r){for(const o of r)this.connect(t,o.sourceBlockId,o.sourcePortName,o.targetBlockId,o.targetPortName)}disconnectInput(t,r,o){const i=this.get(t).blocks.find(s=>s.id===r);if(!i)throw new Error(`Block id ${r} not found in graph "${t}".`);const a=i.inputs.find(s=>s.name===o);if(!a)throw new Error(`Input port "${o}" not found on block id ${r}.`);if(a.targetBlockId===void 0)throw new Error(`Input port "${o}" on block id ${r} is already disconnected.`);delete a.inputName,delete a.targetBlockId,delete a.targetConnectionName}setBlockProperties(t,r,o){const i=this.get(t).blocks.find(a=>a.id===r);if(!i)throw new Error(`Block id ${r} not found in graph "${t}".`);for(const[a,s]of Object.entries(o)){if(a==="id"||a==="customType"||a==="inputs"||a==="outputs")throw new Error(`Property "${a}" is reserved and cannot be set via set_block_properties.`);if(a==="additionalConstructionParameters"&&!Array.isArray(s))throw new Error('"additionalConstructionParameters" must be an array.');i[a]=s}}describeBlock(t,r){const o=this.get(t),n=o.blocks.find(i=>i.id===r);if(!n)throw new Error(`Block id ${r} not found in graph "${t}".`);return this._formatBlock(n,o)}describeGraph(t){const r=this.get(t),o=[`# Render Graph: "${r.name}"`,r.comment?`Comment: ${r.comment}`:"",`Output block id: ${r.outputNodeId??"(not set)"}`,`Blocks (${r.blocks.length}):`,""].filter(Boolean);for(const n of r.blocks)o.push(this._formatBlock(n,r)),o.push("");return o.join(`
94
94
  `)}_formatBlock(t,r){const o=[`**[${t.id}] ${t.name}** (${t.customType.replace("BABYLON.","")})`];if(t.inputs.length>0){o.push(" Inputs:");for(const a of t.inputs)if(a.targetBlockId!==void 0){const s=r.blocks.find(c=>c.id===a.targetBlockId);o.push(` \u2022 ${a.name} \u2190 [${a.targetBlockId}] ${s?.name??"?"}.${a.targetConnectionName}`)}else o.push(` \u2022 ${a.name} (not connected)`)}if(t.outputs.length>0){o.push(" Outputs:");for(const a of t.outputs){const s=[];for(const c of r.blocks)for(const u of c.inputs)u.targetBlockId===t.id&&u.targetConnectionName===a.name&&s.push(`[${c.id}] ${c.name}.${u.name}`);s.length>0?o.push(` \u2022 ${a.name} \u2192 ${s.join(", ")}`):o.push(` \u2022 ${a.name} (unconnected)`)}}const n=new Set(["customType","id","name","comments","visibleOnFrame","disabled","inputs","outputs"]),i=Object.keys(t).filter(a=>!n.has(a));if(i.length>0){o.push(" Properties:");for(const a of i)o.push(` ${a}: ${JSON.stringify(t[a])}`)}return o.join(`
95
- `)}validate(t){const r=this.get(t),o=[];if(r.outputNodeId===void 0)o.push("ERROR: No NodeRenderGraphOutputBlock found. Add one and connect a final texture to its 'texture' input.");else{const i=r.blocks.find(a=>a.id===r.outputNodeId);if(!i)o.push(`ERROR: outputNodeId=${r.outputNodeId} does not match any block. The OutputBlock may have been removed.`);else{const a=i.inputs.find(s=>s.name==="texture");(!a||a.targetBlockId===void 0)&&o.push("ERROR: NodeRenderGraphOutputBlock is missing a connection on its 'texture' input. Connect a rendered colour texture to it.")}}for(const i of r.blocks){const a=i.customType.replace("BABYLON.",""),s=Tn[a];if(!s){o.push(`WARNING: Block "${i.name}" (id ${i.id}) has unknown type "${i.customType}". It may have been added with import_graph_json from an external source.`);continue}for(const c of s.inputs){if(c.isOptional)continue;const u=i.inputs.find(l=>l.name===c.name);(!u||u.targetBlockId===void 0)&&o.push(`WARNING: Block "${i.name}" (id ${i.id}) has a required input "${c.name}" that is not connected.`)}}const n=new Set(r.blocks.map(i=>i.id));for(const i of r.blocks)for(const a of i.inputs)a.targetBlockId!==void 0&&!n.has(a.targetBlockId)&&o.push(`ERROR: Block "${i.name}" (id ${i.id}) input "${a.name}" references missing block id ${a.targetBlockId}. Connection must be removed.`);for(const i of r.blocks)if(i.customType==="BABYLON.NodeRenderGraphInputBlock"){const a=i.additionalConstructionParameters;(!a||!Array.isArray(a)||a.length===0)&&o.push(`WARNING: InputBlock "${i.name}" (id ${i.id}) is missing additionalConstructionParameters[0] (the connection-point type). Set it via set_block_properties with key "additionalConstructionParameters". Common values: Texture=1, TextureDepthStencilAttachment=8, Camera=16777216, ObjectList=33554432.`)}return{valid:o.filter(i=>i.startsWith("ERROR")).length===0,messages:o}}exportJson(t){const r=this.get(t);return JSON.stringify(r,null,2)}importJson(t,r,o=!1){const n=Sx(r);if(this._graphs.has(t)&&!o)throw new Error(`A render graph named "${t}" already exists. Pass overwrite=true to replace it.`);n.name=t,n.customType="BABYLON.NodeRenderGraph";for(const i of n.blocks)typeof i.id=="number"&&i.id>=this._nextId&&(this._nextId=i.id+1);return this._graphs.set(t,n),n}}const Cx="https://cdn.babylonjs.com",Ux={havok:"havok/HavokPhysics_umd.js",ammo:"ammo/ammo.js",recast:"recast.js"},Qc="https://snippet.babylonjs.com";async function Zx(e,t=Qc){let r=e.replace(/#/g,"/");r.includes("/")||(r+="/0");const o=`${t}/${r}`,n=await fetch(o);if(!n.ok)throw new Error(`Failed to fetch snippet "${e}": ${n.status} ${n.statusText}`);return await n.json()}const Mx=[["nodeMaterial","nodeMaterial"],["nodeGeometry","nodeGeometry"],["nodeRenderGraph","nodeRenderGraph"],["nodeParticle","nodeParticle"],["gui","gui"],["encodedGui","gui"],["animations","animation"],["animation","animation"],["particleSystem","particleSystem"],["spriteManager","spriteManager"],["shaderMaterial","shaderMaterial"]];function Bx(e){const t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return r.buffer}function Iv(e){const t=new Uint8Array(Bx(e));return new TextDecoder("utf-8").decode(t)}function Lx(e){if(e.files&&typeof e.files=="object"&&e.v!==void 0||typeof e.code=="string")return"playground";for(const[t,r]of Mx)if(t in e)return r;return"unknown"}function Fx(e,t,r,o){let n;switch(t){case"gui":{typeof e.encodedGui=="string"?n=JSON.parse(Iv(e.encodedGui)):n=typeof e.gui=="string"?JSON.parse(e.gui):e.gui;break}case"animation":{typeof e.animations=="string"?n=JSON.parse(e.animations):e.animations!==void 0?n=e.animations:typeof e.animation=="string"?n=JSON.parse(e.animation):n=e.animation;break}default:{const a=e[t];n=typeof a=="string"?JSON.parse(a):a;break}}return{snippetId:r,type:t,metadata:o,data:n,load:i=>i?i(n):n}}let eu=null;async function Gx(){return await import("monaco-editor/esm/vs/language/typescript/lib/typescriptServices")}async function qx(){return eu||(eu=Gx().then(e=>e.typescript)),await eu}async function Jx(e,t){const r=await qx();return r.transpileModule(e,{compilerOptions:{target:r.ScriptTarget.ESNext,module:r.ModuleKind.ESNext,jsx:t.endsWith(".tsx")?r.JsxEmit.ReactJSX:void 0,esModuleInterop:!1,allowJs:!0,sourceMap:!1,experimentalDecorators:!0,emitDecoratorMetadata:!1,isolatedModules:!0,strict:!1,allowUmdGlobalAccess:!0},fileName:t}).outputText}async function Vx(e,t){const r={},o=[];for(const[n,i]of Object.entries(e))if(/\.tsx?$/i.test(n)){const a=n.replace(/\.tsx?$/i,".js");o.push((async()=>{r[a]=await Promise.resolve(t(i,n))})())}else r[n]=i;return await Promise.all(o),r}const Pv=["delayCreateScene","delayLoadScene","createScene","CreateScene","createscene"];function Hx(e){if(e.includes("class Playground"))return"TS";if(Pv.some(o=>e.includes(o))||!e)return"JS";const t=[/\binterface\s+[A-Za-z_]\w*/m,/\benum\s+[A-Za-z_]\w*/m,/\btype\s+[A-Za-z_]\w*\s*=/m,/\bimplements\s+[A-Za-z_]/m,/\breadonly\b/m,/\bpublic\b|\bprivate\b|\bprotected\b/m,/\babstract\s+class\b/m,/\bas\s+const\b/m,/\bimport\s+type\s+/m],r=/[:]\s*[A-Za-z_$][\w$.<>,\s?\\[\]|&]*\b(?![:=])/m.test(e);return t.some(o=>o.test(e))||r?"TS":"JS"}function Kx(e,t){let r=e;if(t==="JS"){const n=r.search(/(?:var|let|const|function)\s+(?:createScene|delayCreateScene|delayLoadScene|createEngine|CreateScene)\b/),i=n>0?r.slice(0,n):"";i&&(r=i.replace(/^[^\S\n]*(?:var|let|const)\s+canvas\s*=\s*document\.getElementById\s*\([^)]*\)\s*;?[^\S\n]*$/gm,"// [snippet-loader] canvas provided by host").replace(/^[^\S\n]*(?:var|let|const)\s+engine\s*=\s*new\s+BABYLON\.\w*Engine\b[^;]*;?[^\S\n]*$/gm,"// [snippet-loader] engine provided by host")+r.slice(n))}const o=t==="TS"?"Playground":Pv.find(n=>r.includes(n))??"createScene";return r+=`
95
+ `)}validate(t){const r=this.get(t),o=[];if(r.outputNodeId===void 0)o.push("ERROR: No NodeRenderGraphOutputBlock found. Add one and connect a final texture to its 'texture' input.");else{const i=r.blocks.find(a=>a.id===r.outputNodeId);if(!i)o.push(`ERROR: outputNodeId=${r.outputNodeId} does not match any block. The OutputBlock may have been removed.`);else{const a=i.inputs.find(s=>s.name==="texture");(!a||a.targetBlockId===void 0)&&o.push("ERROR: NodeRenderGraphOutputBlock is missing a connection on its 'texture' input. Connect a rendered colour texture to it.")}}for(const i of r.blocks){const a=i.customType.replace("BABYLON.",""),s=Tn[a];if(!s){o.push(`WARNING: Block "${i.name}" (id ${i.id}) has unknown type "${i.customType}". It may have been added with import_graph_json from an external source.`);continue}for(const c of s.inputs){if(c.isOptional)continue;const u=i.inputs.find(l=>l.name===c.name);(!u||u.targetBlockId===void 0)&&o.push(`WARNING: Block "${i.name}" (id ${i.id}) has a required input "${c.name}" that is not connected.`)}}const n=new Set(r.blocks.map(i=>i.id));for(const i of r.blocks)for(const a of i.inputs)a.targetBlockId!==void 0&&!n.has(a.targetBlockId)&&o.push(`ERROR: Block "${i.name}" (id ${i.id}) input "${a.name}" references missing block id ${a.targetBlockId}. Connection must be removed.`);for(const i of r.blocks)if(i.customType==="BABYLON.NodeRenderGraphInputBlock"){const a=i.additionalConstructionParameters;(!a||!Array.isArray(a)||a.length===0)&&o.push(`WARNING: InputBlock "${i.name}" (id ${i.id}) is missing additionalConstructionParameters[0] (the connection-point type). Set it via set_block_properties with key "additionalConstructionParameters". Common values: Texture=1, TextureDepthStencilAttachment=8, Camera=16777216, ObjectList=33554432.`)}return{valid:o.filter(i=>i.startsWith("ERROR")).length===0,messages:o}}exportJson(t){const r=this.get(t);return JSON.stringify(r,null,2)}importJson(t,r,o=!1){const n=Sx(r);if(this._graphs.has(t)&&!o)throw new Error(`A render graph named "${t}" already exists. Pass overwrite=true to replace it.`);n.name=t,n.customType="BABYLON.NodeRenderGraph";for(const i of n.blocks)typeof i.id=="number"&&i.id>=this._nextId&&(this._nextId=i.id+1);return this._graphs.set(t,n),n}}const Cx="https://cdn.babylonjs.com",Ux={havok:"havok/HavokPhysics_umd.js",ammo:"ammo/ammo.js",recast:"recast.js"},Qc="https://snippet.babylonjs.com";async function Zx(e,t=Qc){let r=e.replace(/#/g,"/");r.includes("/")||(r+="/0");const o=`${t}/${r}`,n=await fetch(o);if(!n.ok)throw new Error(`Failed to fetch snippet "${e}": ${n.status} ${n.statusText}`);return await n.json()}const Mx=[["nodeMaterial","nodeMaterial"],["nodeGeometry","nodeGeometry"],["nodeRenderGraph","nodeRenderGraph"],["nodeParticle","nodeParticle"],["gui","gui"],["encodedGui","gui"],["animations","animation"],["animation","animation"],["particleSystem","particleSystem"],["spriteManager","spriteManager"],["shaderMaterial","shaderMaterial"]];function Bx(e){const t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return r.buffer}function Iv(e){const t=new Uint8Array(Bx(e));return new TextDecoder("utf-8").decode(t)}function Lx(e){if(e.files&&typeof e.files=="object"&&e.v!==void 0||typeof e.code=="string")return"playground";for(const[t,r]of Mx)if(t in e)return r;return"unknown"}function Fx(e,t,r,o){let n;switch(t){case"gui":{typeof e.encodedGui=="string"?n=JSON.parse(Iv(e.encodedGui)):n=typeof e.gui=="string"?JSON.parse(e.gui):e.gui;break}case"animation":{typeof e.animations=="string"?n=JSON.parse(e.animations):e.animations!==void 0?n=e.animations:typeof e.animation=="string"?n=JSON.parse(e.animation):n=e.animation;break}default:{const a=e[t];n=typeof a=="string"?JSON.parse(a):a;break}}return{snippetId:r,type:t,metadata:o,data:n,load:i=>i?i(n):n}}let eu=null;async function Gx(){return await import("monaco-editor/esm/vs/language/typescript/lib/typescriptServices")}async function qx(){return eu||(eu=Gx().then(e=>e.typescript)),await eu}async function Jx(e,t){const r=await qx();return r.transpileModule(e,{compilerOptions:{target:r.ScriptTarget.ESNext,module:r.ModuleKind.ESNext,jsx:t.endsWith(".tsx")?r.JsxEmit.ReactJSX:void 0,esModuleInterop:!1,allowJs:!0,sourceMap:!1,isolatedModules:!0,strict:!1,allowUmdGlobalAccess:!0},fileName:t}).outputText}async function Vx(e,t){const r={},o=[];for(const[n,i]of Object.entries(e))if(/\.tsx?$/i.test(n)){const a=n.replace(/\.tsx?$/i,".js");o.push((async()=>{r[a]=await Promise.resolve(t(i,n))})())}else r[n]=i;return await Promise.all(o),r}const Pv=["delayCreateScene","delayLoadScene","createScene","CreateScene","createscene"];function Hx(e){if(e.includes("class Playground"))return"TS";if(Pv.some(o=>e.includes(o))||!e)return"JS";const t=[/\binterface\s+[A-Za-z_]\w*/m,/\benum\s+[A-Za-z_]\w*/m,/\btype\s+[A-Za-z_]\w*\s*=/m,/\bimplements\s+[A-Za-z_]/m,/\breadonly\b/m,/\bpublic\b|\bprivate\b|\bprotected\b/m,/\babstract\s+class\b/m,/\bas\s+const\b/m,/\bimport\s+type\s+/m],r=/[:]\s*[A-Za-z_$][\w$.<>,\s?\\[\]|&]*\b(?![:=])/m.test(e);return t.some(o=>o.test(e))||r?"TS":"JS"}function Kx(e,t){let r=e;if(t==="JS"){const n=r.search(/(?:var|let|const|function)\s+(?:createScene|delayCreateScene|delayLoadScene|createEngine|CreateScene)\b/),i=n>0?r.slice(0,n):"";i&&(r=i.replace(/^[^\S\n]*(?:var|let|const)\s+canvas\s*=\s*document\.getElementById\s*\([^)]*\)\s*;?[^\S\n]*$/gm,"// [snippet-loader] canvas provided by host").replace(/^[^\S\n]*(?:var|let|const)\s+engine\s*=\s*new\s+BABYLON\.\w*Engine\b[^;]*;?[^\S\n]*$/gm,"// [snippet-loader] engine provided by host")+r.slice(n))}const o=t==="TS"?"Playground":Pv.find(n=>r.includes(n))??"createScene";return r+=`
96
96
  export default ${o}
97
97
  `,t==="JS"&&/\bfunction\s+createEngine\b|\bvar\s+createEngine\s*=|\bconst\s+createEngine\s*=|\blet\s+createEngine\s*=/.test(r)&&(r+=`
98
98
  export { createEngine }