@babylonjs/mcp-servers 9.15.0 → 9.16.0

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.
@@ -100,7 +100,7 @@ ${i.join(`
100
100
  ### Children (${n.children.length})`);for(const c of n.children){const u=i._gridCellIndex.get(c.name),l=u?` [cell ${u}]`:"";o.push(` \u2022 ${c.name} (${c.className})${l}`)}}return n.className==="Grid"&&(n.rows&&n.rows.length>0&&(o.push(`
101
101
  ### Rows (${n.rows.length})`),n.rows.forEach((c,u)=>{const l=c;o.push(` [${u}] ${l.value}${l.unit===1?"px":""}`)})),n.columns&&n.columns.length>0&&(o.push(`
102
102
  ### Columns (${n.columns.length})`),n.columns.forEach((c,u)=>{const l=c;o.push(` [${u}] ${l.value}${l.unit===1?"px":""}`)}))),o.join(`
103
- `)}validateTexture(t){const r=this._textures.get(t);if(!r)return[`GUI texture "${t}" not found.`];const i=[];(!r.root.children||r.root.children.length===0)&&i.push("WARNING: GUI has no controls \u2014 root container is empty."),this._validateGrids(r,r.root,i);const n=new Set;this._collectNames(r.root,n,i);for(const[,a]of r._controlIndex){if(a.name==="root")continue;const s=Mt[a.className];s&&!s.isContainer&&a.width===void 0&&a.height===void 0&&r._parentIndex.get(a.name),(a.className==="Button"||a.className==="FocusableButton")&&(a.children?.some(u=>u.className==="TextBlock")||i.push(`WARNING: Button "${a.name}" has no text label. Set buttonText when creating it or add a TextBlock child.`))}const o=new Set;this._collectAllNames(r.root,o);for(const[a]of r._controlIndex)a!=="root"&&!o.has(a)&&i.push(`ERROR: Control "${a}" is in the index but not in the tree.`);return i.length===0&&i.push("No issues found \u2014 GUI looks valid."),i}exportJSON(t){const r=this._textures.get(t);if(!r)return null;const n={root:this._cloneControlForExport(r,r.root)};return r.width&&(n.width=r.width),r.height&&(n.height=r.height),JSON.stringify(n,null,2)}importJSON(t,r){try{const i=kT(r),n=typeof i.width=="number"?i.width:1920,o=typeof i.height=="number"?i.height:1080;this.createTexture(t,{width:n,height:o,isFullscreen:!0});const a=this._textures.get(t);return a.root=i.root,a._controlIndex.clear(),a._parentIndex.clear(),a._gridCellIndex.clear(),this._indexControlTree(a,a.root,void 0),"OK"}catch(i){return i.message}}_applyProperties(t,r,i){for(const[n,o]of Object.entries(i))n==="buttonText"||n==="buttonImage"||(r&&n in r.properties,t[n]=o)}_initButtonChildren(t,r,i){const n=t.name,o=`${n}_text`,a={name:o,className:"TextBlock",text:i?.buttonText??""};if(t.children.push(a),t.textBlockName=o,r._controlIndex.set(o,a),r._parentIndex.set(o,n),i?.buttonImage){const s=`${n}_image`,c={name:s,className:"Image",source:i.buttonImage};t.children.push(c),t.imageName=s,r._controlIndex.set(s,c),r._parentIndex.set(s,n)}}_removeFromIndexRecursive(t,r,i){if(i.children)for(const n of i.children)this._removeFromIndexRecursive(t,n.name,n);t._controlIndex.delete(r),t._parentIndex.delete(r),t._gridCellIndex.delete(r)}_isDescendantOf(t,r,i){let n=r;for(;n;){if(n===i)return!0;n=t._parentIndex.get(n)}return!1}_describeControlTree(t,r,i,n){const o=" ".repeat(n),a=t._gridCellIndex.get(r.name),s=a?` [cell ${a}]`:"",c=[];for(const[l,d]of Object.entries(r)){if(["name","className","children","rows","columns","tags","textBlockName","imageName"].includes(l)||d==null)continue;const m=typeof d=="string"?`"${d}"`:JSON.stringify(d);c.push(`${l}=${m}`)}const u=c.length>0?` {${c.join(", ")}}`:"";if(i.push(`${o}${r.name} (${r.className})${s}${u}`),r.className==="Grid"){if(r.rows&&r.rows.length>0){const l=r.rows.map(d=>{const m=d;return`${m.value}${m.unit===1?"px":""}`});i.push(`${o} rows: [${l.join(", ")}]`)}if(r.columns&&r.columns.length>0){const l=r.columns.map(d=>{const m=d;return`${m.value}${m.unit===1?"px":""}`});i.push(`${o} columns: [${l.join(", ")}]`)}}if(r.children)for(const l of r.children)this._describeControlTree(t,l,i,n+1)}_validateGrids(t,r,i){if(r.className==="Grid"&&((!r.rows||r.rows.length===0)&&i.push(`WARNING: Grid "${r.name}" has no row definitions. Add at least one row.`),(!r.columns||r.columns.length===0)&&i.push(`WARNING: Grid "${r.name}" has no column definitions. Add at least one column.`),r.children&&r.rows&&r.columns))for(const n of r.children){const o=t._gridCellIndex.get(n.name);if(!o)i.push(`WARNING: Grid child "${n.name}" has no cell assignment.`);else{const[a,s]=o.split(":"),c=parseInt(a),u=parseInt(s);c>=r.rows.length&&i.push(`WARNING: Grid child "${n.name}" assigned to row ${c}, but grid has only ${r.rows.length} rows.`),u>=r.columns.length&&i.push(`WARNING: Grid child "${n.name}" assigned to column ${u}, but grid has only ${r.columns.length} columns.`)}}if(r.children)for(const n of r.children)this._validateGrids(t,n,i)}_collectNames(t,r,i){if(r.has(t.name)&&i.push(`ERROR: Duplicate control name "${t.name}".`),r.add(t.name),t.children)for(const n of t.children)this._collectNames(n,r,i)}_collectAllNames(t,r){if(r.add(t.name),t.children)for(const i of t.children)this._collectAllNames(i,r)}_cloneControlForExport(t,r){const i={};for(const[n,o]of Object.entries(r))n!=="children"&&(i[n]=o);return r.className==="Grid"&&(r.rows&&(i.rowCount=r.rows.length),r.columns&&(i.columnCount=r.columns.length)),r.children&&r.children.length>0&&(i.children=r.children.map(n=>this._cloneControlForExport(t,n))),i}_indexControlTree(t,r,i){if(t._controlIndex.set(r.name,r),i&&t._parentIndex.set(r.name,i),r.tags&&r.children)for(let n=0;n<r.children.length;n++)n<r.tags.length&&t._gridCellIndex.set(r.children[n].name,r.tags[n]);if(r.children)for(const n of r.children)this._indexControlTree(t,n,r.name)}}const ZT="https://cdn.babylonjs.com",MT={havok:"havok/HavokPhysics_umd.js",ammo:"ammo/ammo.js",recast:"recast.js"},Qc="https://snippet.babylonjs.com";async function LT(e,t=Qc){let r=e.replace(/#/g,"/");r.includes("/")||(r+="/0");const i=`${t}/${r}`,n=await fetch(i);if(!n.ok)throw new Error(`Failed to fetch snippet "${e}": ${n.status} ${n.statusText}`);return await n.json()}const FT=[["nodeMaterial","nodeMaterial"],["nodeGeometry","nodeGeometry"],["nodeRenderGraph","nodeRenderGraph"],["nodeParticle","nodeParticle"],["gui","gui"],["encodedGui","gui"],["animations","animation"],["animation","animation"],["particleSystem","particleSystem"],["spriteManager","spriteManager"],["shaderMaterial","shaderMaterial"]];function VT(e){const t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r.buffer}function xv(e){const t=new Uint8Array(VT(e));return new TextDecoder("utf-8").decode(t)}function GT(e){if(e.files&&typeof e.files=="object"&&e.v!==void 0||typeof e.code=="string")return"playground";for(const[t,r]of FT)if(t in e)return r;return"unknown"}function qT(e,t,r,i){let n;switch(t){case"gui":{typeof e.encodedGui=="string"?n=JSON.parse(xv(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:i,data:n,load:o=>o?o(n):n}}let eu=null;async function BT(){return await import("monaco-editor/esm/vs/language/typescript/lib/typescriptServices")}async function JT(){return eu||(eu=BT().then(e=>e.typescript)),await eu}async function HT(e,t){const r=await JT();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 KT(e,t){const r={},i=[];for(const[n,o]of Object.entries(e))if(/\.tsx?$/i.test(n)){const a=n.replace(/\.tsx?$/i,".js");i.push((async()=>{r[a]=await Promise.resolve(t(o,n))})())}else r[n]=o;return await Promise.all(i),r}const Tv=["delayCreateScene","delayLoadScene","createScene","CreateScene","createscene"];function WT(e){if(e.includes("class Playground"))return"TS";if(Tv.some(i=>e.includes(i))||!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(i=>i.test(e))||r?"TS":"JS"}function XT(e,t){let r=e;if(t==="JS"){const n=r.search(/(?:var|let|const|function)\s+(?:createScene|delayCreateScene|delayLoadScene|createEngine|CreateScene)\b/),o=n>0?r.slice(0,n):"";o&&(r=o.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 i=t==="TS"?"Playground":Tv.find(n=>r.includes(n))??"createScene";return r+=`
103
+ `)}validateTexture(t){const r=this._textures.get(t);if(!r)return[`GUI texture "${t}" not found.`];const i=[];(!r.root.children||r.root.children.length===0)&&i.push("WARNING: GUI has no controls \u2014 root container is empty."),this._validateGrids(r,r.root,i);const n=new Set;this._collectNames(r.root,n,i);for(const[,a]of r._controlIndex){if(a.name==="root")continue;const s=Mt[a.className];s&&!s.isContainer&&a.width===void 0&&a.height===void 0&&r._parentIndex.get(a.name),(a.className==="Button"||a.className==="FocusableButton")&&(a.children?.some(u=>u.className==="TextBlock")||i.push(`WARNING: Button "${a.name}" has no text label. Set buttonText when creating it or add a TextBlock child.`))}const o=new Set;this._collectAllNames(r.root,o);for(const[a]of r._controlIndex)a!=="root"&&!o.has(a)&&i.push(`ERROR: Control "${a}" is in the index but not in the tree.`);return i.length===0&&i.push("No issues found \u2014 GUI looks valid."),i}exportJSON(t){const r=this._textures.get(t);if(!r)return null;const n={root:this._cloneControlForExport(r,r.root)};return r.width&&(n.width=r.width),r.height&&(n.height=r.height),JSON.stringify(n,null,2)}importJSON(t,r){try{const i=kT(r),n=typeof i.width=="number"?i.width:1920,o=typeof i.height=="number"?i.height:1080;this.createTexture(t,{width:n,height:o,isFullscreen:!0});const a=this._textures.get(t);return a.root=i.root,a._controlIndex.clear(),a._parentIndex.clear(),a._gridCellIndex.clear(),this._indexControlTree(a,a.root,void 0),"OK"}catch(i){return i.message}}_applyProperties(t,r,i){for(const[n,o]of Object.entries(i))n==="buttonText"||n==="buttonImage"||(r&&n in r.properties,t[n]=o)}_initButtonChildren(t,r,i){const n=t.name,o=`${n}_text`,a={name:o,className:"TextBlock",text:i?.buttonText??""};if(t.children.push(a),t.textBlockName=o,r._controlIndex.set(o,a),r._parentIndex.set(o,n),i?.buttonImage){const s=`${n}_image`,c={name:s,className:"Image",source:i.buttonImage};t.children.push(c),t.imageName=s,r._controlIndex.set(s,c),r._parentIndex.set(s,n)}}_removeFromIndexRecursive(t,r,i){if(i.children)for(const n of i.children)this._removeFromIndexRecursive(t,n.name,n);t._controlIndex.delete(r),t._parentIndex.delete(r),t._gridCellIndex.delete(r)}_isDescendantOf(t,r,i){let n=r;for(;n;){if(n===i)return!0;n=t._parentIndex.get(n)}return!1}_describeControlTree(t,r,i,n){const o=" ".repeat(n),a=t._gridCellIndex.get(r.name),s=a?` [cell ${a}]`:"",c=[];for(const[l,d]of Object.entries(r)){if(["name","className","children","rows","columns","tags","textBlockName","imageName"].includes(l)||d==null)continue;const m=typeof d=="string"?`"${d}"`:JSON.stringify(d);c.push(`${l}=${m}`)}const u=c.length>0?` {${c.join(", ")}}`:"";if(i.push(`${o}${r.name} (${r.className})${s}${u}`),r.className==="Grid"){if(r.rows&&r.rows.length>0){const l=r.rows.map(d=>{const m=d;return`${m.value}${m.unit===1?"px":""}`});i.push(`${o} rows: [${l.join(", ")}]`)}if(r.columns&&r.columns.length>0){const l=r.columns.map(d=>{const m=d;return`${m.value}${m.unit===1?"px":""}`});i.push(`${o} columns: [${l.join(", ")}]`)}}if(r.children)for(const l of r.children)this._describeControlTree(t,l,i,n+1)}_validateGrids(t,r,i){if(r.className==="Grid"&&((!r.rows||r.rows.length===0)&&i.push(`WARNING: Grid "${r.name}" has no row definitions. Add at least one row.`),(!r.columns||r.columns.length===0)&&i.push(`WARNING: Grid "${r.name}" has no column definitions. Add at least one column.`),r.children&&r.rows&&r.columns))for(const n of r.children){const o=t._gridCellIndex.get(n.name);if(!o)i.push(`WARNING: Grid child "${n.name}" has no cell assignment.`);else{const[a,s]=o.split(":"),c=parseInt(a),u=parseInt(s);c>=r.rows.length&&i.push(`WARNING: Grid child "${n.name}" assigned to row ${c}, but grid has only ${r.rows.length} rows.`),u>=r.columns.length&&i.push(`WARNING: Grid child "${n.name}" assigned to column ${u}, but grid has only ${r.columns.length} columns.`)}}if(r.children)for(const n of r.children)this._validateGrids(t,n,i)}_collectNames(t,r,i){if(r.has(t.name)&&i.push(`ERROR: Duplicate control name "${t.name}".`),r.add(t.name),t.children)for(const n of t.children)this._collectNames(n,r,i)}_collectAllNames(t,r){if(r.add(t.name),t.children)for(const i of t.children)this._collectAllNames(i,r)}_cloneControlForExport(t,r){const i={};for(const[n,o]of Object.entries(r))n!=="children"&&(i[n]=o);return r.className==="Grid"&&(r.rows&&(i.rowCount=r.rows.length),r.columns&&(i.columnCount=r.columns.length)),r.children&&r.children.length>0&&(i.children=r.children.map(n=>this._cloneControlForExport(t,n))),i}_indexControlTree(t,r,i){if(t._controlIndex.set(r.name,r),i&&t._parentIndex.set(r.name,i),r.tags&&r.children)for(let n=0;n<r.children.length;n++)n<r.tags.length&&t._gridCellIndex.set(r.children[n].name,r.tags[n]);if(r.children)for(const n of r.children)this._indexControlTree(t,n,r.name)}}const ZT="https://cdn.babylonjs.com",MT={havok:"havok/HavokPhysics_umd.js",ammo:"ammo/ammo.js",recast:"recast.js"},Qc="https://snippet.babylonjs.com";async function LT(e,t=Qc){let r=e.replace(/#/g,"/");r.includes("/")||(r+="/0");const i=`${t}/${r}`,n=await fetch(i);if(!n.ok)throw new Error(`Failed to fetch snippet "${e}": ${n.status} ${n.statusText}`);return await n.json()}const FT=[["nodeMaterial","nodeMaterial"],["nodeGeometry","nodeGeometry"],["nodeRenderGraph","nodeRenderGraph"],["nodeParticle","nodeParticle"],["gui","gui"],["encodedGui","gui"],["animations","animation"],["animation","animation"],["particleSystem","particleSystem"],["spriteManager","spriteManager"],["shaderMaterial","shaderMaterial"]];function VT(e){const t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r.buffer}function xv(e){const t=new Uint8Array(VT(e));return new TextDecoder("utf-8").decode(t)}function GT(e){if(e.files&&typeof e.files=="object"&&e.v!==void 0||typeof e.code=="string")return"playground";for(const[t,r]of FT)if(t in e)return r;return"unknown"}function qT(e,t,r,i){let n;switch(t){case"gui":{typeof e.encodedGui=="string"?n=JSON.parse(xv(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:i,data:n,load:o=>o?o(n):n}}let eu=null;async function BT(){return await import("monaco-editor/esm/vs/language/typescript/lib/typescriptServices")}async function JT(){return eu||(eu=BT().then(e=>e.typescript)),await eu}async function HT(e,t){const r=await JT();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 KT(e,t){const r={},i=[];for(const[n,o]of Object.entries(e))if(/\.tsx?$/i.test(n)){const a=n.replace(/\.tsx?$/i,".js");i.push((async()=>{r[a]=await Promise.resolve(t(o,n))})())}else r[n]=o;return await Promise.all(i),r}const Tv=["delayCreateScene","delayLoadScene","createScene","CreateScene","createscene"];function WT(e){if(e.includes("class Playground"))return"TS";if(Tv.some(i=>e.includes(i))||!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(i=>i.test(e))||r?"TS":"JS"}function XT(e,t){let r=e;if(t==="JS"){const n=r.search(/(?:var|let|const|function)\s+(?:createScene|delayCreateScene|delayLoadScene|createEngine|CreateScene)\b/),o=n>0?r.slice(0,n):"";o&&(r=o.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 i=t==="TS"?"Playground":Tv.find(n=>r.includes(n))??"createScene";return r+=`
104
104
  export default ${i}
105
105
  `,t==="JS"&&/\bfunction\s+createEngine\b|\bvar\s+createEngine\s*=|\bconst\s+createEngine\s*=|\blet\s+createEngine\s*=/.test(r)&&(r+=`
106
106
  export { createEngine }