mesheditor 0.0.0-stage → 1.0.2
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/LICENSE +201 -0
- package/README.md +853 -2
- package/dist-lib/esm/AIAgentService.d.ts +107 -0
- package/dist-lib/esm/AIAgentService.d.ts.map +1 -0
- package/dist-lib/esm/AIAgentService.js +1471 -0
- package/dist-lib/esm/AIAgentService.js.map +1 -0
- package/dist-lib/esm/MeshEditorApp.d.ts +413 -0
- package/dist-lib/esm/MeshEditorApp.d.ts.map +1 -0
- package/dist-lib/esm/MeshEditorApp.js +9093 -0
- package/dist-lib/esm/MeshEditorApp.js.map +1 -0
- package/dist-lib/esm/MeshEditorService.d.ts +460 -0
- package/dist-lib/esm/MeshEditorService.d.ts.map +1 -0
- package/dist-lib/esm/MeshEditorService.js +7084 -0
- package/dist-lib/esm/MeshEditorService.js.map +1 -0
- package/dist-lib/esm/Neural3DGeneratorService.d.ts +89 -0
- package/dist-lib/esm/Neural3DGeneratorService.d.ts.map +1 -0
- package/dist-lib/esm/Neural3DGeneratorService.js +1398 -0
- package/dist-lib/esm/Neural3DGeneratorService.js.map +1 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.d.ts +17 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.d.ts.map +1 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.js +26 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.js.map +1 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.d.ts +33 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.d.ts.map +1 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.js +337 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.js.map +1 -0
- package/dist-lib/esm/adapters/HostAppAdapter.d.ts +55 -0
- package/dist-lib/esm/adapters/HostAppAdapter.d.ts.map +1 -0
- package/dist-lib/esm/adapters/HostAppAdapter.js +76 -0
- package/dist-lib/esm/adapters/HostAppAdapter.js.map +1 -0
- package/dist-lib/esm/adapters/PlatformAdapter.d.ts +99 -0
- package/dist-lib/esm/adapters/PlatformAdapter.d.ts.map +1 -0
- package/dist-lib/esm/adapters/PlatformAdapter.js +2 -0
- package/dist-lib/esm/adapters/PlatformAdapter.js.map +1 -0
- package/dist-lib/esm/adapters/index.d.ts +14 -0
- package/dist-lib/esm/adapters/index.d.ts.map +1 -0
- package/dist-lib/esm/adapters/index.js +16 -0
- package/dist-lib/esm/adapters/index.js.map +1 -0
- package/dist-lib/esm/assets/fonts/Droid_Sans_Bold.json +1 -0
- package/dist-lib/esm/assets/fonts/Droid_Sans_Regular.json +1 -0
- package/dist-lib/esm/assets/fonts/Kenney_Future_Regular.json +1 -0
- package/dist-lib/esm/baking/TextureBaker.d.ts +85 -0
- package/dist-lib/esm/baking/TextureBaker.d.ts.map +1 -0
- package/dist-lib/esm/baking/TextureBaker.js +710 -0
- package/dist-lib/esm/baking/TextureBaker.js.map +1 -0
- package/dist-lib/esm/builtInSkills.d.ts +20 -0
- package/dist-lib/esm/builtInSkills.d.ts.map +1 -0
- package/dist-lib/esm/builtInSkills.js +187 -0
- package/dist-lib/esm/builtInSkills.js.map +1 -0
- package/dist-lib/esm/compression/ModelCompressor.d.ts +88 -0
- package/dist-lib/esm/compression/ModelCompressor.d.ts.map +1 -0
- package/dist-lib/esm/compression/ModelCompressor.js +554 -0
- package/dist-lib/esm/compression/ModelCompressor.js.map +1 -0
- package/dist-lib/esm/decals/DecalController.d.ts +148 -0
- package/dist-lib/esm/decals/DecalController.d.ts.map +1 -0
- package/dist-lib/esm/decals/DecalController.js +1032 -0
- package/dist-lib/esm/decals/DecalController.js.map +1 -0
- package/dist-lib/esm/decals/decalAssetUrls.d.ts +2 -0
- package/dist-lib/esm/decals/decalAssetUrls.d.ts.map +1 -0
- package/dist-lib/esm/decals/decalAssetUrls.js +17 -0
- package/dist-lib/esm/decals/decalAssetUrls.js.map +1 -0
- package/dist-lib/esm/geometry/architecture.d.ts +115 -0
- package/dist-lib/esm/geometry/architecture.d.ts.map +1 -0
- package/dist-lib/esm/geometry/architecture.js +832 -0
- package/dist-lib/esm/geometry/architecture.js.map +1 -0
- package/dist-lib/esm/geometry/bevelModifier.d.ts +60 -0
- package/dist-lib/esm/geometry/bevelModifier.d.ts.map +1 -0
- package/dist-lib/esm/geometry/bevelModifier.js +346 -0
- package/dist-lib/esm/geometry/bevelModifier.js.map +1 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.d.ts +128 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.d.ts.map +1 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.js +677 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.js.map +1 -0
- package/dist-lib/esm/geometry/roundedBox.d.ts +16 -0
- package/dist-lib/esm/geometry/roundedBox.d.ts.map +1 -0
- package/dist-lib/esm/geometry/roundedBox.js +134 -0
- package/dist-lib/esm/geometry/roundedBox.js.map +1 -0
- package/dist-lib/esm/index.d.ts +22 -0
- package/dist-lib/esm/index.d.ts.map +1 -0
- package/dist-lib/esm/index.js +51 -0
- package/dist-lib/esm/index.js.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.d.ts +60 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.d.ts.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.js +484 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.js.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.d.ts +77 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.d.ts.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.js +1793 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.js.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.d.ts +96 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.d.ts.map +1 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.js +628 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.js.map +1 -0
- package/dist-lib/esm/pathExtrusion/index.d.ts +5 -0
- package/dist-lib/esm/pathExtrusion/index.d.ts.map +1 -0
- package/dist-lib/esm/pathExtrusion/index.js +5 -0
- package/dist-lib/esm/pathExtrusion/index.js.map +1 -0
- package/dist-lib/esm/pathExtrusion/types.d.ts +51 -0
- package/dist-lib/esm/pathExtrusion/types.d.ts.map +1 -0
- package/dist-lib/esm/pathExtrusion/types.js +2 -0
- package/dist-lib/esm/pathExtrusion/types.js.map +1 -0
- package/dist-lib/esm/plugin.d.ts +251 -0
- package/dist-lib/esm/plugin.d.ts.map +1 -0
- package/dist-lib/esm/plugin.js +145 -0
- package/dist-lib/esm/plugin.js.map +1 -0
- package/dist-lib/esm/rigging/WeightPaintController.d.ts +163 -0
- package/dist-lib/esm/rigging/WeightPaintController.d.ts.map +1 -0
- package/dist-lib/esm/rigging/WeightPaintController.js +1422 -0
- package/dist-lib/esm/rigging/WeightPaintController.js.map +1 -0
- package/dist-lib/esm/sculpting/SculptController.d.ts +147 -0
- package/dist-lib/esm/sculpting/SculptController.d.ts.map +1 -0
- package/dist-lib/esm/sculpting/SculptController.js +2039 -0
- package/dist-lib/esm/sculpting/SculptController.js.map +1 -0
- package/dist-lib/esm/sdf/index.d.ts +3 -0
- package/dist-lib/esm/sdf/index.d.ts.map +1 -0
- package/dist-lib/esm/sdf/index.js +3 -0
- package/dist-lib/esm/sdf/index.js.map +1 -0
- package/dist-lib/esm/sdf/sdfPrimitives.d.ts +98 -0
- package/dist-lib/esm/sdf/sdfPrimitives.d.ts.map +1 -0
- package/dist-lib/esm/sdf/sdfPrimitives.js +403 -0
- package/dist-lib/esm/sdf/sdfPrimitives.js.map +1 -0
- package/dist-lib/esm/sdf/surfaceNets.d.ts +30 -0
- package/dist-lib/esm/sdf/surfaceNets.d.ts.map +1 -0
- package/dist-lib/esm/sdf/surfaceNets.js +400 -0
- package/dist-lib/esm/sdf/surfaceNets.js.map +1 -0
- package/dist-lib/esm/styles.d.ts +12 -0
- package/dist-lib/esm/styles.d.ts.map +1 -0
- package/dist-lib/esm/styles.js +33 -0
- package/dist-lib/esm/styles.js.map +1 -0
- package/dist-lib/esm/template.d.ts +13 -0
- package/dist-lib/esm/template.d.ts.map +1 -0
- package/dist-lib/esm/template.js +20 -0
- package/dist-lib/esm/template.js.map +1 -0
- package/dist-lib/esm/textMesh/TextMeshController.d.ts +62 -0
- package/dist-lib/esm/textMesh/TextMeshController.d.ts.map +1 -0
- package/dist-lib/esm/textMesh/TextMeshController.js +405 -0
- package/dist-lib/esm/textMesh/TextMeshController.js.map +1 -0
- package/dist-lib/esm/textures/AITextureGenerator.d.ts +120 -0
- package/dist-lib/esm/textures/AITextureGenerator.d.ts.map +1 -0
- package/dist-lib/esm/textures/AITextureGenerator.js +946 -0
- package/dist-lib/esm/textures/AITextureGenerator.js.map +1 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.d.ts +63 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.d.ts.map +1 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.js +880 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.js.map +1 -0
- package/dist-lib/esm/tools/AbstractTool.d.ts +69 -0
- package/dist-lib/esm/tools/AbstractTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/AbstractTool.js +129 -0
- package/dist-lib/esm/tools/AbstractTool.js.map +1 -0
- package/dist-lib/esm/tools/ToolExecutionContext.d.ts +41 -0
- package/dist-lib/esm/tools/ToolExecutionContext.d.ts.map +1 -0
- package/dist-lib/esm/tools/ToolExecutionContext.js +2 -0
- package/dist-lib/esm/tools/ToolExecutionContext.js.map +1 -0
- package/dist-lib/esm/tools/ToolInterface.d.ts +105 -0
- package/dist-lib/esm/tools/ToolInterface.d.ts.map +1 -0
- package/dist-lib/esm/tools/ToolInterface.js +2 -0
- package/dist-lib/esm/tools/ToolInterface.js.map +1 -0
- package/dist-lib/esm/tools/ToolRegistry.d.ts +44 -0
- package/dist-lib/esm/tools/ToolRegistry.d.ts.map +1 -0
- package/dist-lib/esm/tools/ToolRegistry.js +116 -0
- package/dist-lib/esm/tools/ToolRegistry.js.map +1 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.d.ts +35 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.js +49 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.d.ts +35 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.js +55 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.d.ts +43 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.js +82 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.d.ts +52 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.js +87 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.d.ts +79 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.js +171 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.d.ts +76 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.js +116 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.d.ts +119 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.js +90 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.d.ts +115 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.js +106 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.d.ts +88 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.js +61 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.d.ts +115 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.js +213 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.d.ts +121 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.js +96 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.d.ts +163 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.js +303 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.d.ts +121 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.js +109 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.d.ts +102 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.js +80 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.d.ts +225 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.js +239 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.d.ts +136 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.js +120 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.d.ts +95 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.js +132 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.d.ts +88 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.js +60 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.d.ts +146 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.js +125 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/DecalTool.d.ts +77 -0
- package/dist-lib/esm/tools/builtin/DecalTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/DecalTool.js +144 -0
- package/dist-lib/esm/tools/builtin/DecalTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.d.ts +21 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.js +43 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.d.ts +22 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.js +96 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.d.ts +115 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.js +77 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.d.ts +105 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.js +69 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.d.ts +37 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.js +58 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.d.ts +31 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.js +50 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.d.ts +31 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.js +50 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.d.ts +35 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.js +56 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.d.ts +132 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.js +456 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.d.ts +88 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.js +217 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.d.ts +12 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.js +13 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.d.ts +29 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.js +57 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.d.ts +88 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.js +156 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.d.ts +51 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.js +117 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.d.ts +56 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.js +140 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.d.ts +139 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.js +256 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.d.ts +22 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.js +32 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.d.ts +31 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.js +58 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.d.ts +67 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.js +106 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.d.ts +24 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.js +38 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.d.ts +24 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.js +40 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.d.ts +79 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.js +70 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.d.ts +49 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.js +108 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.d.ts +61 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.js +154 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.js.map +1 -0
- package/dist-lib/esm/tools/builtin/index.d.ts +45 -0
- package/dist-lib/esm/tools/builtin/index.d.ts.map +1 -0
- package/dist-lib/esm/tools/builtin/index.js +45 -0
- package/dist-lib/esm/tools/builtin/index.js.map +1 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.d.ts +19 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.js +44 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.d.ts +16 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.js +29 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.d.ts +30 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.js +57 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.js +30 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.d.ts +22 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.js +45 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.d.ts +21 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.js +43 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.d.ts +21 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.js +49 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.js +37 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.js +37 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.d.ts +24 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.js +81 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.d.ts +19 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.js +44 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.js +38 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.js +35 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.js +73 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.d.ts +28 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.js +67 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.js +36 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.d.ts +29 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.js +71 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.js +31 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.js +29 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.d.ts +28 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.js +71 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.js +69 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.js.map +1 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.d.ts +31 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.js +229 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.js.map +1 -0
- package/dist-lib/esm/tools/editor/index.d.ts +33 -0
- package/dist-lib/esm/tools/editor/index.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/index.js +55 -0
- package/dist-lib/esm/tools/editor/index.js.map +1 -0
- package/dist-lib/esm/tools/editor/toolViews.d.ts +11 -0
- package/dist-lib/esm/tools/editor/toolViews.d.ts.map +1 -0
- package/dist-lib/esm/tools/editor/toolViews.js +54 -0
- package/dist-lib/esm/tools/editor/toolViews.js.map +1 -0
- package/dist-lib/esm/tools/editorTools.d.ts +6 -0
- package/dist-lib/esm/tools/editorTools.d.ts.map +1 -0
- package/dist-lib/esm/tools/editorTools.js +6 -0
- package/dist-lib/esm/tools/editorTools.js.map +1 -0
- package/dist-lib/esm/tools/index.d.ts +9 -0
- package/dist-lib/esm/tools/index.d.ts.map +1 -0
- package/dist-lib/esm/tools/index.js +9 -0
- package/dist-lib/esm/tools/index.js.map +1 -0
- package/dist-lib/esm/tools/textureUtils.d.ts +19 -0
- package/dist-lib/esm/tools/textureUtils.d.ts.map +1 -0
- package/dist-lib/esm/tools/textureUtils.js +289 -0
- package/dist-lib/esm/tools/textureUtils.js.map +1 -0
- package/dist-lib/esm/types.d.ts +165 -0
- package/dist-lib/esm/types.d.ts.map +1 -0
- package/dist-lib/esm/types.js +2 -0
- package/dist-lib/esm/types.js.map +1 -0
- package/dist-lib/esm/uv/UVUnwrapController.d.ts +109 -0
- package/dist-lib/esm/uv/UVUnwrapController.d.ts.map +1 -0
- package/dist-lib/esm/uv/UVUnwrapController.js +1023 -0
- package/dist-lib/esm/uv/UVUnwrapController.js.map +1 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.d.ts +16 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.d.ts.map +1 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.js +170 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.js.map +1 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.d.ts +55 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.d.ts.map +1 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.js +631 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.js.map +1 -0
- package/dist-lib/esm/voxel/VoxelPainterController.d.ts +101 -0
- package/dist-lib/esm/voxel/VoxelPainterController.d.ts.map +1 -0
- package/dist-lib/esm/voxel/VoxelPainterController.js +672 -0
- package/dist-lib/esm/voxel/VoxelPainterController.js.map +1 -0
- package/dist-lib/esm/voxel/index.d.ts +5 -0
- package/dist-lib/esm/voxel/index.d.ts.map +1 -0
- package/dist-lib/esm/voxel/index.js +5 -0
- package/dist-lib/esm/voxel/index.js.map +1 -0
- package/dist-lib/esm/voxel/types.d.ts +79 -0
- package/dist-lib/esm/voxel/types.d.ts.map +1 -0
- package/dist-lib/esm/voxel/types.js +2 -0
- package/dist-lib/esm/voxel/types.js.map +1 -0
- package/dist-lib/esm/web-component/MeshEditorElement.d.ts +104 -0
- package/dist-lib/esm/web-component/MeshEditorElement.d.ts.map +1 -0
- package/dist-lib/esm/web-component/MeshEditorElement.js +247 -0
- package/dist-lib/esm/web-component/MeshEditorElement.js.map +1 -0
- package/dist-lib/esm/web-component/index.d.ts +2 -0
- package/dist-lib/esm/web-component/index.d.ts.map +1 -0
- package/dist-lib/esm/web-component/index.js +2 -0
- package/dist-lib/esm/web-component/index.js.map +1 -0
- package/dist-lib/index.umd.js +3 -0
- package/dist-lib/mesheditor.css +2 -0
- package/dist-lib/standalone/mesheditor-element.bundle.js +3 -0
- package/package.json +113 -4
- package/skills/README.md +48 -0
- package/skills/figure-sculptor.md +297 -0
- package/skills/image-to-mesh.md +18 -0
- package/skills/mesh-updater.md +27 -0
- package/skills/neural-3d-generator.md +53 -0
- package/skills/procedural-modeler.md +267 -0
- package/skills/voxel-painter.md +21 -0
- package/src/mesheditor.css +6477 -0
|
@@ -0,0 +1,1471 @@
|
|
|
1
|
+
import { Color3, MultiMaterial, PBRMaterial, StandardMaterial, Vector3, } from '@babylonjs/core';
|
|
2
|
+
import earcut from 'earcut';
|
|
3
|
+
import { createDefaultNeural3DProviders, Neural3DGeneratorService, normalizeNeural3DProviders, } from './Neural3DGeneratorService';
|
|
4
|
+
export { createDefaultNeural3DProviders, NEURAL_3D_PROTOCOL_DEFAULTS, Neural3DGeneratorService, normalizeNeural3DProviders, } from './Neural3DGeneratorService';
|
|
5
|
+
import { createDefaultImageGeneratorProviders, normalizeImageGeneratorProviders, } from './textures/ExternalImageGeneratorService';
|
|
6
|
+
export { createDefaultImageGeneratorProviders, ExternalImageGeneratorService, IMAGE_GENERATOR_PROTOCOL_DEFAULTS, normalizeImageGeneratorProviders, } from './textures/ExternalImageGeneratorService';
|
|
7
|
+
import { createDefaultToolRegistry, } from './tools';
|
|
8
|
+
export { generateProceduralTextureDataUrl, } from './tools/textureUtils';
|
|
9
|
+
// Ensure earcut is available globally for Babylon.js PolygonMeshBuilder / ExtrudePolygon
|
|
10
|
+
if (typeof globalThis !== 'undefined') {
|
|
11
|
+
globalThis.earcut = earcut;
|
|
12
|
+
}
|
|
13
|
+
export const AI_AGENT_STORAGE_KEY = 'mesheditor_ai_agent_config';
|
|
14
|
+
export const DEFAULT_AI_AGENT_CONFIG = {
|
|
15
|
+
baseUrl: '/api/antigravity/v1',
|
|
16
|
+
apiKey: '',
|
|
17
|
+
model: 'gemini-3.8-flash-medium',
|
|
18
|
+
temperature: 0.2,
|
|
19
|
+
maxIterations: 12,
|
|
20
|
+
minPolygons: 200,
|
|
21
|
+
maxPolygons: 5000,
|
|
22
|
+
createTextures: true,
|
|
23
|
+
createNormalMaps: true,
|
|
24
|
+
visualCritique: false,
|
|
25
|
+
neural3DProviders: createDefaultNeural3DProviders(),
|
|
26
|
+
imageGeneratorEnabled: true,
|
|
27
|
+
imageGeneratorActiveBackend: 'pollinations',
|
|
28
|
+
imageGeneratorProviders: createDefaultImageGeneratorProviders(),
|
|
29
|
+
};
|
|
30
|
+
export const AI_ENDPOINT_PRESETS = [
|
|
31
|
+
{
|
|
32
|
+
id: 'antigravity',
|
|
33
|
+
label: 'Antigravity (Local Account)',
|
|
34
|
+
baseUrl: '/api/antigravity/v1',
|
|
35
|
+
defaultModel: 'gemini-3.8-flash-medium',
|
|
36
|
+
requiresKey: false,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'openai',
|
|
40
|
+
label: 'OpenAI',
|
|
41
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
42
|
+
defaultModel: 'gpt-4o',
|
|
43
|
+
requiresKey: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'openrouter',
|
|
47
|
+
label: 'OpenRouter',
|
|
48
|
+
baseUrl: 'https://openrouter.ai/api/v1',
|
|
49
|
+
defaultModel: 'openai/gpt-4o',
|
|
50
|
+
requiresKey: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'gemini',
|
|
54
|
+
label: 'Gemini 3 Flash (OpenAI API)',
|
|
55
|
+
baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai',
|
|
56
|
+
defaultModel: 'gemini-3-flash-preview',
|
|
57
|
+
requiresKey: true,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'gemini-pro',
|
|
61
|
+
label: 'Gemini 3.1 Pro (OpenAI API)',
|
|
62
|
+
baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai',
|
|
63
|
+
defaultModel: 'gemini-3.1-pro-preview',
|
|
64
|
+
requiresKey: true,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'omlx',
|
|
68
|
+
label: 'oMLX (Local Apple Silicon)',
|
|
69
|
+
baseUrl: 'http://localhost:8000/v1',
|
|
70
|
+
defaultModel: 'mlx-community/Qwen2.5-Coder-32B-Instruct-4bit',
|
|
71
|
+
requiresKey: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'ollama',
|
|
75
|
+
label: 'Ollama (Local)',
|
|
76
|
+
baseUrl: 'http://localhost:11434/v1',
|
|
77
|
+
defaultModel: 'qwen2.5-coder:14b',
|
|
78
|
+
requiresKey: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'lmstudio',
|
|
82
|
+
label: 'LM Studio (Local)',
|
|
83
|
+
baseUrl: 'http://localhost:1234/v1',
|
|
84
|
+
defaultModel: 'local-model',
|
|
85
|
+
requiresKey: false,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
/* =========================================================================
|
|
89
|
+
BUILT-IN BABYLON.JS MODELING SKILLS (Loaded from /skills directory)
|
|
90
|
+
========================================================================= */
|
|
91
|
+
export { BUILT_IN_AGENT_SKILLS, discoverSkills, parseSkillMarkdown } from './builtInSkills';
|
|
92
|
+
import { discoverSkills, parseSkillMarkdown } from './builtInSkills';
|
|
93
|
+
/* =========================================================================
|
|
94
|
+
AI AGENT SERVICE
|
|
95
|
+
========================================================================= */
|
|
96
|
+
export class AIAgentService {
|
|
97
|
+
service;
|
|
98
|
+
config;
|
|
99
|
+
skills;
|
|
100
|
+
chatHistory = [];
|
|
101
|
+
toolRegistry;
|
|
102
|
+
materialRegistry = new Map();
|
|
103
|
+
customFetch = null;
|
|
104
|
+
currentRequestImages = [];
|
|
105
|
+
currentRequestSignal;
|
|
106
|
+
currentRequestOnStatus;
|
|
107
|
+
constructor(service, initialConfig, customFetch) {
|
|
108
|
+
this.service = service;
|
|
109
|
+
this.customFetch = customFetch || null;
|
|
110
|
+
this.skills = discoverSkills();
|
|
111
|
+
this.toolRegistry = createDefaultToolRegistry();
|
|
112
|
+
const saved = this.loadSavedConfig();
|
|
113
|
+
this.config = {
|
|
114
|
+
...DEFAULT_AI_AGENT_CONFIG,
|
|
115
|
+
...saved,
|
|
116
|
+
...initialConfig,
|
|
117
|
+
neural3DProviders: normalizeNeural3DProviders(initialConfig?.neural3DProviders || saved.neural3DProviders || DEFAULT_AI_AGENT_CONFIG.neural3DProviders),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Registers a custom modeling tool into the agent registry.
|
|
122
|
+
*/
|
|
123
|
+
registerTool(tool) {
|
|
124
|
+
this.toolRegistry.register(tool);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Builds the execution context provided to tools during dispatch.
|
|
128
|
+
*/
|
|
129
|
+
createToolContext() {
|
|
130
|
+
return {
|
|
131
|
+
service: this.service,
|
|
132
|
+
scene: this.service.scene,
|
|
133
|
+
aiAgent: this,
|
|
134
|
+
attachedImages: this.currentRequestImages,
|
|
135
|
+
signal: this.currentRequestSignal,
|
|
136
|
+
onStatus: this.currentRequestOnStatus,
|
|
137
|
+
materialRegistry: this.materialRegistry,
|
|
138
|
+
findMeshByNameOrId: (id) => this.findMeshByNameOrId(id),
|
|
139
|
+
getOrCreateMaterial: (materialName, colorHex, roughness, metallic, fallbackName) => this.getOrCreateMaterial(materialName, colorHex, roughness, metallic, fallbackName),
|
|
140
|
+
applyTransformArgs: (mesh, args) => this.applyTransformArgs(mesh, args),
|
|
141
|
+
registerCreatedMesh: (mesh) => this.registerCreatedMesh(mesh),
|
|
142
|
+
normalizeHex: (hex) => this.normalizeHex(hex),
|
|
143
|
+
parseVec3: (v, defaultVal) => this.parseVec3(v, defaultVal),
|
|
144
|
+
parsePolygonPoint: (p) => this.parsePolygonPoint(p),
|
|
145
|
+
buildSceneSummary: () => this.buildSceneSummary(),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
normalizeModelName(model, baseUrl) {
|
|
149
|
+
let m = (model || DEFAULT_AI_AGENT_CONFIG.model).trim();
|
|
150
|
+
const url = (baseUrl ?? this.config?.baseUrl ?? '').toLowerCase();
|
|
151
|
+
if (url.includes('/api/antigravity') || url.includes('localhost:8787') || url.includes('127.0.0.1:8787')) {
|
|
152
|
+
const lower = m.toLowerCase();
|
|
153
|
+
if (lower === 'gemini-3.8-flash' || lower === 'gemini-3-flash-preview' || lower === 'gemini-3-flash' || lower === 'gemini-2.5-pro') {
|
|
154
|
+
return 'gemini-3.8-flash-medium';
|
|
155
|
+
}
|
|
156
|
+
if (lower === 'gemini-3.1-pro-preview' || lower === 'gemini-4-argon') {
|
|
157
|
+
return 'gemini-4-argon-medium';
|
|
158
|
+
}
|
|
159
|
+
return m;
|
|
160
|
+
}
|
|
161
|
+
if (url.includes('generativelanguage.googleapis.com')) {
|
|
162
|
+
m = m.replace(/^models\//i, '');
|
|
163
|
+
const lower = m.toLowerCase();
|
|
164
|
+
if (lower === 'gemini-2.5-pro') {
|
|
165
|
+
return 'gemini-3-flash-preview';
|
|
166
|
+
}
|
|
167
|
+
if (lower === 'gemini-3.1-pro' || lower === 'gemini-3-pro') {
|
|
168
|
+
return 'gemini-3.1-pro-preview';
|
|
169
|
+
}
|
|
170
|
+
if (lower === 'gemini-3-flash' ||
|
|
171
|
+
lower === 'gemini-3.0-flash' ||
|
|
172
|
+
lower === 'gemini-3.8-flash' ||
|
|
173
|
+
lower === 'gemini-flash') {
|
|
174
|
+
return 'gemini-3-flash-preview';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return m;
|
|
178
|
+
}
|
|
179
|
+
loadSavedConfig() {
|
|
180
|
+
if (typeof localStorage === 'undefined')
|
|
181
|
+
return {};
|
|
182
|
+
try {
|
|
183
|
+
const raw = localStorage.getItem(AI_AGENT_STORAGE_KEY);
|
|
184
|
+
if (!raw)
|
|
185
|
+
return {};
|
|
186
|
+
const parsed = JSON.parse(raw);
|
|
187
|
+
const baseUrl = typeof parsed.baseUrl === 'string' ? parsed.baseUrl : DEFAULT_AI_AGENT_CONFIG.baseUrl;
|
|
188
|
+
const rawModel = typeof parsed.model === 'string' ? parsed.model : DEFAULT_AI_AGENT_CONFIG.model;
|
|
189
|
+
return {
|
|
190
|
+
baseUrl,
|
|
191
|
+
apiKey: typeof parsed.apiKey === 'string' ? parsed.apiKey : DEFAULT_AI_AGENT_CONFIG.apiKey,
|
|
192
|
+
model: this.normalizeModelName(rawModel, baseUrl),
|
|
193
|
+
temperature: typeof parsed.temperature === 'number' ? parsed.temperature : DEFAULT_AI_AGENT_CONFIG.temperature,
|
|
194
|
+
maxIterations: typeof parsed.maxIterations === 'number' ? parsed.maxIterations : DEFAULT_AI_AGENT_CONFIG.maxIterations,
|
|
195
|
+
minPolygons: typeof parsed.minPolygons === 'number' ? parsed.minPolygons : DEFAULT_AI_AGENT_CONFIG.minPolygons,
|
|
196
|
+
maxPolygons: typeof parsed.maxPolygons === 'number' ? parsed.maxPolygons : DEFAULT_AI_AGENT_CONFIG.maxPolygons,
|
|
197
|
+
createTextures: typeof parsed.createTextures === 'boolean' ? parsed.createTextures : DEFAULT_AI_AGENT_CONFIG.createTextures,
|
|
198
|
+
createNormalMaps: typeof parsed.createNormalMaps === 'boolean' ? parsed.createNormalMaps : DEFAULT_AI_AGENT_CONFIG.createNormalMaps,
|
|
199
|
+
visualCritique: typeof parsed.visualCritique === 'boolean' ? parsed.visualCritique : DEFAULT_AI_AGENT_CONFIG.visualCritique,
|
|
200
|
+
neural3DProviders: normalizeNeural3DProviders(parsed.neural3DProviders),
|
|
201
|
+
imageGeneratorEnabled: typeof parsed.imageGeneratorEnabled === 'boolean'
|
|
202
|
+
? parsed.imageGeneratorEnabled
|
|
203
|
+
: DEFAULT_AI_AGENT_CONFIG.imageGeneratorEnabled,
|
|
204
|
+
imageGeneratorActiveBackend: parsed.imageGeneratorActiveBackend || DEFAULT_AI_AGENT_CONFIG.imageGeneratorActiveBackend,
|
|
205
|
+
imageGeneratorProviders: normalizeImageGeneratorProviders(parsed.imageGeneratorProviders),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
saveConfig(newConfig) {
|
|
213
|
+
const mergedBaseUrl = newConfig.baseUrl !== undefined ? newConfig.baseUrl : this.config.baseUrl;
|
|
214
|
+
const mergedModel = newConfig.model !== undefined
|
|
215
|
+
? this.normalizeModelName(newConfig.model, mergedBaseUrl)
|
|
216
|
+
: this.normalizeModelName(this.config.model, mergedBaseUrl);
|
|
217
|
+
const mergedProviders = newConfig.neural3DProviders
|
|
218
|
+
? normalizeNeural3DProviders({
|
|
219
|
+
...(this.config.neural3DProviders || createDefaultNeural3DProviders()),
|
|
220
|
+
...newConfig.neural3DProviders,
|
|
221
|
+
})
|
|
222
|
+
: normalizeNeural3DProviders(this.config.neural3DProviders);
|
|
223
|
+
const mergedImageProviders = newConfig.imageGeneratorProviders
|
|
224
|
+
? normalizeImageGeneratorProviders({
|
|
225
|
+
...(this.config.imageGeneratorProviders || createDefaultImageGeneratorProviders()),
|
|
226
|
+
...newConfig.imageGeneratorProviders,
|
|
227
|
+
})
|
|
228
|
+
: normalizeImageGeneratorProviders(this.config.imageGeneratorProviders);
|
|
229
|
+
this.config = {
|
|
230
|
+
...this.config,
|
|
231
|
+
...newConfig,
|
|
232
|
+
baseUrl: mergedBaseUrl,
|
|
233
|
+
model: mergedModel,
|
|
234
|
+
neural3DProviders: mergedProviders,
|
|
235
|
+
imageGeneratorProviders: mergedImageProviders,
|
|
236
|
+
};
|
|
237
|
+
// Keep externalImageGenerator service synchronized with active backend if specified
|
|
238
|
+
if (this.service?.externalImageGenerator) {
|
|
239
|
+
if (newConfig.imageGeneratorActiveBackend) {
|
|
240
|
+
this.service.externalImageGenerator.setActiveBackend(this.config.imageGeneratorEnabled
|
|
241
|
+
? newConfig.imageGeneratorActiveBackend
|
|
242
|
+
: 'procedural');
|
|
243
|
+
}
|
|
244
|
+
else if (newConfig.imageGeneratorEnabled !== undefined) {
|
|
245
|
+
this.service.externalImageGenerator.setActiveBackend(newConfig.imageGeneratorEnabled
|
|
246
|
+
? this.config.imageGeneratorActiveBackend || 'pollinations'
|
|
247
|
+
: 'procedural');
|
|
248
|
+
}
|
|
249
|
+
if (newConfig.imageGeneratorProviders) {
|
|
250
|
+
for (const [id, prov] of Object.entries(mergedImageProviders)) {
|
|
251
|
+
this.service.externalImageGenerator.updateProvider(id, prov);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (typeof localStorage !== 'undefined') {
|
|
256
|
+
try {
|
|
257
|
+
localStorage.setItem(AI_AGENT_STORAGE_KEY, JSON.stringify(this.config));
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
console.warn('[AIAgentService] Failed to persist config to localStorage:', e);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return this.config;
|
|
264
|
+
}
|
|
265
|
+
getConfig() {
|
|
266
|
+
return {
|
|
267
|
+
...this.config,
|
|
268
|
+
neural3DProviders: normalizeNeural3DProviders(this.config.neural3DProviders),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
getNeural3DProviders() {
|
|
272
|
+
return normalizeNeural3DProviders(this.config.neural3DProviders);
|
|
273
|
+
}
|
|
274
|
+
getEnabledNeural3DProviders() {
|
|
275
|
+
const map = this.getNeural3DProviders();
|
|
276
|
+
return ['trellis', 'hunyuan3d', 'hi3d']
|
|
277
|
+
.map((id) => map[id])
|
|
278
|
+
.filter((p) => p && p.enabled);
|
|
279
|
+
}
|
|
280
|
+
setNeural3DProviderConfig(id, partial) {
|
|
281
|
+
const current = this.getNeural3DProviders();
|
|
282
|
+
const updated = {
|
|
283
|
+
...current[id],
|
|
284
|
+
...partial,
|
|
285
|
+
id,
|
|
286
|
+
};
|
|
287
|
+
this.saveConfig({
|
|
288
|
+
neural3DProviders: {
|
|
289
|
+
...current,
|
|
290
|
+
[id]: updated,
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
return this.getNeural3DProviders()[id];
|
|
294
|
+
}
|
|
295
|
+
async testNeural3DProvider(id) {
|
|
296
|
+
const provider = this.getNeural3DProviders()[id];
|
|
297
|
+
return await Neural3DGeneratorService.testProviderConnection(provider, this.customFetch);
|
|
298
|
+
}
|
|
299
|
+
getSkills() {
|
|
300
|
+
return this.skills;
|
|
301
|
+
}
|
|
302
|
+
setSkillEnabled(skillId, enabled) {
|
|
303
|
+
const skill = this.skills.find((s) => s.id === skillId);
|
|
304
|
+
if (skill) {
|
|
305
|
+
skill.enabled = enabled;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Registers or updates an AI agent skill definition.
|
|
310
|
+
*/
|
|
311
|
+
registerSkill(skill) {
|
|
312
|
+
const existingIndex = this.skills.findIndex((s) => s.id === skill.id);
|
|
313
|
+
if (existingIndex >= 0) {
|
|
314
|
+
this.skills[existingIndex] = { ...skill };
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
this.skills.push({ ...skill });
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Parses and registers a skill directly from raw Markdown content (with optional YAML frontmatter).
|
|
322
|
+
*/
|
|
323
|
+
registerSkillFromMarkdown(content, fallbackId = 'custom-skill') {
|
|
324
|
+
const skill = parseSkillMarkdown(content, fallbackId);
|
|
325
|
+
this.registerSkill(skill);
|
|
326
|
+
return skill;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Reloads skills discovered from the /skills directory, preserving user checkbox states.
|
|
330
|
+
*/
|
|
331
|
+
reloadSkills() {
|
|
332
|
+
const existingStates = new Map();
|
|
333
|
+
for (const s of this.skills) {
|
|
334
|
+
existingStates.set(s.id, s.enabled);
|
|
335
|
+
}
|
|
336
|
+
const freshSkills = discoverSkills();
|
|
337
|
+
for (const fresh of freshSkills) {
|
|
338
|
+
if (existingStates.has(fresh.id)) {
|
|
339
|
+
fresh.enabled = existingStates.get(fresh.id);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
this.skills = freshSkills;
|
|
343
|
+
return this.skills;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Optionally fetches dynamically discovered skills from the local dev server or bridge API (/api/skills).
|
|
347
|
+
*/
|
|
348
|
+
async fetchSkillsFromApi(apiUrl = '/api/skills') {
|
|
349
|
+
try {
|
|
350
|
+
const fetchFn = this.customFetch || (typeof fetch !== 'undefined' ? fetch : null);
|
|
351
|
+
if (!fetchFn)
|
|
352
|
+
return this.skills;
|
|
353
|
+
const res = await fetchFn(apiUrl);
|
|
354
|
+
if (!res.ok)
|
|
355
|
+
return this.skills;
|
|
356
|
+
const data = await res.json();
|
|
357
|
+
if (Array.isArray(data)) {
|
|
358
|
+
for (const item of data) {
|
|
359
|
+
if (item && item.id && item.instructions) {
|
|
360
|
+
this.registerSkill(item);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// Ignore network errors and keep currently loaded skills
|
|
367
|
+
}
|
|
368
|
+
return this.skills;
|
|
369
|
+
}
|
|
370
|
+
clearChatHistory() {
|
|
371
|
+
this.chatHistory = [];
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Resolves the OpenAI-compatible chat completions URL from a user-provided baseUrl.
|
|
375
|
+
*/
|
|
376
|
+
getChatCompletionsUrl(baseUrl) {
|
|
377
|
+
const raw = (baseUrl ?? this.config.baseUrl ?? DEFAULT_AI_AGENT_CONFIG.baseUrl).trim().replace(/\/+$/, '');
|
|
378
|
+
if (raw.endsWith('/chat/completions')) {
|
|
379
|
+
return raw;
|
|
380
|
+
}
|
|
381
|
+
return `${raw}/chat/completions`;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Resolves the OpenAI-compatible models list URL from a user-provided baseUrl.
|
|
385
|
+
*/
|
|
386
|
+
getModelsUrl(baseUrl) {
|
|
387
|
+
const raw = (baseUrl ?? this.config.baseUrl ?? DEFAULT_AI_AGENT_CONFIG.baseUrl).trim().replace(/\/+$/, '');
|
|
388
|
+
if (raw.endsWith('/chat/completions')) {
|
|
389
|
+
return raw.replace(/\/chat\/completions$/, '/models');
|
|
390
|
+
}
|
|
391
|
+
if (raw.endsWith('/models')) {
|
|
392
|
+
return raw;
|
|
393
|
+
}
|
|
394
|
+
return `${raw}/models`;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Queries GET {baseUrl}/models to discover available models on the OpenAI-compatible endpoint.
|
|
398
|
+
*/
|
|
399
|
+
async fetchAvailableModels(overrideConfig) {
|
|
400
|
+
const cfg = { ...this.config, ...overrideConfig };
|
|
401
|
+
const url = this.getModelsUrl(cfg.baseUrl);
|
|
402
|
+
const headers = {
|
|
403
|
+
Accept: 'application/json',
|
|
404
|
+
};
|
|
405
|
+
if (cfg.apiKey && cfg.apiKey.trim()) {
|
|
406
|
+
headers['Authorization'] = `Bearer ${cfg.apiKey.trim()}`;
|
|
407
|
+
}
|
|
408
|
+
const fetchFn = this.customFetch || globalThis.fetch.bind(globalThis);
|
|
409
|
+
let res;
|
|
410
|
+
try {
|
|
411
|
+
res = await fetchFn(url, {
|
|
412
|
+
method: 'GET',
|
|
413
|
+
headers,
|
|
414
|
+
});
|
|
415
|
+
if (!res.ok && url.startsWith('/api/antigravity/v1')) {
|
|
416
|
+
res = await fetchFn(url.replace(/^\/api\/antigravity\/v1/, 'http://localhost:8787/v1'), {
|
|
417
|
+
method: 'GET',
|
|
418
|
+
headers,
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
catch (err) {
|
|
423
|
+
if (url.startsWith('/api/antigravity/v1')) {
|
|
424
|
+
res = await fetchFn(url.replace(/^\/api\/antigravity\/v1/, 'http://localhost:8787/v1'), {
|
|
425
|
+
method: 'GET',
|
|
426
|
+
headers,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
throw err;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (!res.ok) {
|
|
434
|
+
const errText = await res.text().catch(() => '');
|
|
435
|
+
throw new Error(`HTTP ${res.status}: ${errText || res.statusText}`);
|
|
436
|
+
}
|
|
437
|
+
const json = await res.json();
|
|
438
|
+
const list = Array.isArray(json?.data) ? json.data : Array.isArray(json?.models) ? json.models : [];
|
|
439
|
+
const isGeminiEndpoint = url.toLowerCase().includes('generativelanguage.googleapis.com');
|
|
440
|
+
const ids = list
|
|
441
|
+
.map((item) => {
|
|
442
|
+
const rawId = typeof item === 'string' ? item : item?.id || item?.name || '';
|
|
443
|
+
return isGeminiEndpoint ? String(rawId).replace(/^models\//i, '') : String(rawId);
|
|
444
|
+
})
|
|
445
|
+
.filter((id) => typeof id === 'string' && id.length > 0);
|
|
446
|
+
return Array.from(new Set(ids));
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Captures a PNG data URL snapshot of the current 3D Babylon canvas for vision-assisted mesh updates.
|
|
450
|
+
*/
|
|
451
|
+
captureViewportDataUrl() {
|
|
452
|
+
try {
|
|
453
|
+
this.service.scene.render();
|
|
454
|
+
if (this.service.canvas && typeof this.service.canvas.toDataURL === 'function') {
|
|
455
|
+
const dataUrl = this.service.canvas.toDataURL('image/png');
|
|
456
|
+
if (dataUrl && dataUrl.startsWith('data:image/')) {
|
|
457
|
+
return dataUrl;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (err) {
|
|
462
|
+
console.warn('[AIAgentService] Could not capture canvas screenshot:', err);
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Renders a 4-panel multi-view inspection sheet (1. Front, 2. Right Side, 3. 3/4 Perspective, 4. 3/4 Wireframe/Topology)
|
|
468
|
+
* into a composite PNG data URL so the AI model can visually critique proportions, alignment, and polygon density.
|
|
469
|
+
*/
|
|
470
|
+
captureMultiViewDataUrl() {
|
|
471
|
+
const cam = this.service.camera;
|
|
472
|
+
const validMeshes = this.service.importedMeshes.filter((m) => !this.service.isEditorHelper(m) && !m.isDisposed() && m.isVisible);
|
|
473
|
+
// Compute scene bounding box
|
|
474
|
+
let min = new Vector3(Infinity, Infinity, Infinity);
|
|
475
|
+
let max = new Vector3(-Infinity, -Infinity, -Infinity);
|
|
476
|
+
for (const m of validMeshes) {
|
|
477
|
+
m.computeWorldMatrix(true);
|
|
478
|
+
const bb = m.getBoundingInfo()?.boundingBox;
|
|
479
|
+
if (bb && Number.isFinite(bb.minimumWorld.x) && Number.isFinite(bb.maximumWorld.x)) {
|
|
480
|
+
min = Vector3.Minimize(min, bb.minimumWorld);
|
|
481
|
+
max = Vector3.Maximize(max, bb.maximumWorld);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (!Number.isFinite(min.x)) {
|
|
485
|
+
min = new Vector3(-1, 0, -1);
|
|
486
|
+
max = new Vector3(1, 2, 1);
|
|
487
|
+
}
|
|
488
|
+
const center = min.add(max).scale(0.5);
|
|
489
|
+
const size = max.subtract(min);
|
|
490
|
+
const radius = Math.max(Vector3.Distance(min, max) * 0.5, 0.5);
|
|
491
|
+
const vFov = cam?.fov || 0.8;
|
|
492
|
+
const dist = Math.max((radius / Math.sin(vFov * 0.5)) * 1.1, Math.max(size.x, size.y, size.z) * 1.45, 1.5);
|
|
493
|
+
const savedPos = cam ? cam.position.clone() : Vector3.Zero();
|
|
494
|
+
const savedRot = cam ? cam.rotation.clone() : Vector3.Zero();
|
|
495
|
+
const savedWireframe = new Map();
|
|
496
|
+
for (const m of validMeshes) {
|
|
497
|
+
if (m.material && !savedWireframe.has(m.material)) {
|
|
498
|
+
savedWireframe.set(m.material, !!m.material.wireframe);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const views = [
|
|
502
|
+
{
|
|
503
|
+
label: '1. FRONT (+Z)',
|
|
504
|
+
pos: new Vector3(center.x, center.y + dist * 0.12, center.z - dist),
|
|
505
|
+
wireframe: false,
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
label: '2. RIGHT SIDE (+X)',
|
|
509
|
+
pos: new Vector3(center.x + dist, center.y + dist * 0.12, center.z),
|
|
510
|
+
wireframe: false,
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
label: '3. 3/4 PERSPECTIVE',
|
|
514
|
+
pos: new Vector3(center.x + dist * 0.68, center.y + dist * 0.52, center.z - dist * 0.68),
|
|
515
|
+
wireframe: false,
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
label: '4. 3/4 WIREFRAME (DENSITY)',
|
|
519
|
+
pos: new Vector3(center.x - dist * 0.68, center.y + dist * 0.52, center.z - dist * 0.68),
|
|
520
|
+
wireframe: true,
|
|
521
|
+
},
|
|
522
|
+
];
|
|
523
|
+
try {
|
|
524
|
+
if (typeof document !== 'undefined' && this.service.canvas) {
|
|
525
|
+
const sheet = document.createElement('canvas');
|
|
526
|
+
const quadW = 400;
|
|
527
|
+
const quadH = 300;
|
|
528
|
+
sheet.width = quadW * 2;
|
|
529
|
+
sheet.height = quadH * 2;
|
|
530
|
+
let ctx = null;
|
|
531
|
+
try {
|
|
532
|
+
ctx = sheet.getContext('2d');
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
ctx = null;
|
|
536
|
+
}
|
|
537
|
+
if (ctx) {
|
|
538
|
+
ctx.fillStyle = '#0d1117';
|
|
539
|
+
ctx.fillRect(0, 0, sheet.width, sheet.height);
|
|
540
|
+
for (let i = 0; i < views.length; i++) {
|
|
541
|
+
const v = views[i];
|
|
542
|
+
if (cam) {
|
|
543
|
+
cam.rotationQuaternion = null;
|
|
544
|
+
cam.position.copyFrom(v.pos);
|
|
545
|
+
cam.setTarget(center);
|
|
546
|
+
}
|
|
547
|
+
for (const [mat, origWf] of savedWireframe.entries()) {
|
|
548
|
+
mat.wireframe = v.wireframe ? true : origWf;
|
|
549
|
+
}
|
|
550
|
+
this.service.scene.render();
|
|
551
|
+
const qx = (i % 2) * quadW;
|
|
552
|
+
const qy = Math.floor(i / 2) * quadH;
|
|
553
|
+
try {
|
|
554
|
+
ctx.drawImage(this.service.canvas, qx, qy, quadW, quadH);
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
// ignore drawImage error on headless mock canvas
|
|
558
|
+
}
|
|
559
|
+
// Draw quadrant border & label badge
|
|
560
|
+
ctx.strokeStyle = 'rgba(88, 166, 255, 0.4)';
|
|
561
|
+
ctx.lineWidth = 2;
|
|
562
|
+
ctx.strokeRect(qx + 1, qy + 1, quadW - 2, quadH - 2);
|
|
563
|
+
ctx.fillStyle = 'rgba(13, 17, 23, 0.82)';
|
|
564
|
+
ctx.fillRect(qx + 8, qy + 8, 190, 22);
|
|
565
|
+
ctx.fillStyle = '#58a6ff';
|
|
566
|
+
ctx.font = 'bold 11px sans-serif';
|
|
567
|
+
ctx.fillText(v.label, qx + 14, qy + 23);
|
|
568
|
+
}
|
|
569
|
+
const compositeUrl = sheet.toDataURL('image/png');
|
|
570
|
+
if (compositeUrl && compositeUrl.startsWith('data:image/')) {
|
|
571
|
+
return compositeUrl;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
catch (err) {
|
|
577
|
+
console.warn('[AIAgentService] Multi-view composite capture fallback:', err);
|
|
578
|
+
}
|
|
579
|
+
finally {
|
|
580
|
+
for (const [mat, origWf] of savedWireframe.entries()) {
|
|
581
|
+
mat.wireframe = origWf;
|
|
582
|
+
}
|
|
583
|
+
if (cam) {
|
|
584
|
+
cam.rotationQuaternion = null;
|
|
585
|
+
cam.position.copyFrom(savedPos);
|
|
586
|
+
cam.rotation.copyFrom(savedRot);
|
|
587
|
+
}
|
|
588
|
+
try {
|
|
589
|
+
this.service.scene.render();
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
// ignore
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
// Fallback to single viewport capture or minimal 1x1 PNG in headless test mode
|
|
596
|
+
return (this.captureViewportDataUrl() ||
|
|
597
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
|
598
|
+
}
|
|
599
|
+
/* =========================================================================
|
|
600
|
+
SYSTEM PROMPT & SCENE CONTEXT BUILDER
|
|
601
|
+
========================================================================= */
|
|
602
|
+
buildSceneSummary() {
|
|
603
|
+
const validMeshes = this.service.importedMeshes.filter((m) => !this.service.isEditorHelper(m) && !m.isDisposed());
|
|
604
|
+
const rawMeshes = validMeshes.map((m) => {
|
|
605
|
+
m.computeWorldMatrix(true);
|
|
606
|
+
const bb = m.getBoundingInfo()?.boundingBox;
|
|
607
|
+
const min = bb?.minimumWorld || Vector3.Zero();
|
|
608
|
+
const max = bb?.maximumWorld || Vector3.Zero();
|
|
609
|
+
const size = max.subtract(min);
|
|
610
|
+
const center = bb?.centerWorld || m.position;
|
|
611
|
+
const rotDeg = this.service.getMeshRotationDegrees(m);
|
|
612
|
+
const mat = m.material;
|
|
613
|
+
let matSummary = null;
|
|
614
|
+
if (mat instanceof PBRMaterial) {
|
|
615
|
+
matSummary = {
|
|
616
|
+
name: mat.name,
|
|
617
|
+
type: 'PBRMaterial',
|
|
618
|
+
albedoColor: mat.albedoColor?.toHexString?.() || '#ffffff',
|
|
619
|
+
roughness: mat.roughness,
|
|
620
|
+
metallic: mat.metallic,
|
|
621
|
+
alpha: mat.alpha,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
else if (mat instanceof StandardMaterial) {
|
|
625
|
+
matSummary = {
|
|
626
|
+
name: mat.name,
|
|
627
|
+
type: 'StandardMaterial',
|
|
628
|
+
diffuseColor: mat.diffuseColor?.toHexString?.() || '#ffffff',
|
|
629
|
+
alpha: mat.alpha,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
else if (mat instanceof MultiMaterial) {
|
|
633
|
+
matSummary = {
|
|
634
|
+
name: mat.name,
|
|
635
|
+
type: 'MultiMaterial',
|
|
636
|
+
subMaterialsCount: mat.subMaterials?.length || 0,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
const triangles = Math.floor(m.getTotalIndices() / 3);
|
|
640
|
+
const volumeApprox = Math.max(1e-6, Math.abs(size.x * size.y * size.z));
|
|
641
|
+
return {
|
|
642
|
+
name: m.name,
|
|
643
|
+
visible: m.isVisible,
|
|
644
|
+
isSelected: this.service.selectedNodes.includes(m) || this.service.selectedMesh === m,
|
|
645
|
+
parentGroup: m.parent && this.service.isGroupNode(m.parent) ? m.parent.name : null,
|
|
646
|
+
vertices: m.getTotalVertices(),
|
|
647
|
+
triangles,
|
|
648
|
+
subMeshesCount: m.subMeshes?.length || 1,
|
|
649
|
+
position: {
|
|
650
|
+
x: Number(m.position.x.toFixed(3)),
|
|
651
|
+
y: Number(m.position.y.toFixed(3)),
|
|
652
|
+
z: Number(m.position.z.toFixed(3)),
|
|
653
|
+
},
|
|
654
|
+
rotationDegrees: {
|
|
655
|
+
x: Number(rotDeg.x.toFixed(1)),
|
|
656
|
+
y: Number(rotDeg.y.toFixed(1)),
|
|
657
|
+
z: Number(rotDeg.z.toFixed(1)),
|
|
658
|
+
},
|
|
659
|
+
scaling: {
|
|
660
|
+
x: Number(m.scaling.x.toFixed(3)),
|
|
661
|
+
y: Number(m.scaling.y.toFixed(3)),
|
|
662
|
+
z: Number(m.scaling.z.toFixed(3)),
|
|
663
|
+
},
|
|
664
|
+
worldBounds: {
|
|
665
|
+
min: { x: Number(min.x.toFixed(3)), y: Number(min.y.toFixed(3)), z: Number(min.z.toFixed(3)) },
|
|
666
|
+
max: { x: Number(max.x.toFixed(3)), y: Number(max.y.toFixed(3)), z: Number(max.z.toFixed(3)) },
|
|
667
|
+
size: { x: Number(size.x.toFixed(3)), y: Number(size.y.toFixed(3)), z: Number(size.z.toFixed(3)) },
|
|
668
|
+
center: { x: Number(center.x.toFixed(3)), y: Number(center.y.toFixed(3)), z: Number(center.z.toFixed(3)) },
|
|
669
|
+
},
|
|
670
|
+
volumeApprox: Number(volumeApprox.toFixed(4)),
|
|
671
|
+
material: matSummary,
|
|
672
|
+
};
|
|
673
|
+
});
|
|
674
|
+
const totalSceneTriangles = rawMeshes.reduce((acc, m) => acc + m.triangles, 0);
|
|
675
|
+
const meshes = rawMeshes.map((m) => ({
|
|
676
|
+
...m,
|
|
677
|
+
triangleSharePercent: totalSceneTriangles > 0 ? Number(((m.triangles / totalSceneTriangles) * 100).toFixed(1)) : 0,
|
|
678
|
+
}));
|
|
679
|
+
// Compute automatic topology & proportion diagnostics
|
|
680
|
+
const proportionWarnings = [];
|
|
681
|
+
if (meshes.length >= 2) {
|
|
682
|
+
const sortedByVol = [...meshes].sort((a, b) => b.volumeApprox - a.volumeApprox);
|
|
683
|
+
const primary = sortedByVol[0];
|
|
684
|
+
for (const m of meshes) {
|
|
685
|
+
if (m.name !== primary.name &&
|
|
686
|
+
m.volumeApprox < primary.volumeApprox * 0.08 &&
|
|
687
|
+
m.triangles > primary.triangles) {
|
|
688
|
+
proportionWarnings.push(`Disproportionate polygon density: small detail "${m.name}" (${m.triangles} tris) has more polygons than primary volume "${primary.name}" (${primary.triangles} tris).`);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const minPoly = typeof this.config.minPolygons === 'number' ? this.config.minPolygons : 200;
|
|
693
|
+
const maxPoly = typeof this.config.maxPolygons === 'number' ? this.config.maxPolygons : 5000;
|
|
694
|
+
const budgetStatus = totalSceneTriangles === 0
|
|
695
|
+
? 'empty'
|
|
696
|
+
: totalSceneTriangles < minPoly
|
|
697
|
+
? 'below_minimum'
|
|
698
|
+
: totalSceneTriangles > maxPoly
|
|
699
|
+
? 'exceeds_maximum'
|
|
700
|
+
: 'within_budget';
|
|
701
|
+
const groups = this.service.groups
|
|
702
|
+
.filter((g) => !g.isDisposed())
|
|
703
|
+
.map((g) => ({
|
|
704
|
+
name: g.name,
|
|
705
|
+
childMeshes: g
|
|
706
|
+
.getChildMeshes()
|
|
707
|
+
.filter((cm) => !this.service.isEditorHelper(cm))
|
|
708
|
+
.map((cm) => cm.name),
|
|
709
|
+
}));
|
|
710
|
+
return {
|
|
711
|
+
totalMeshes: meshes.length,
|
|
712
|
+
totalSceneTriangles,
|
|
713
|
+
selectedMeshNames: this.service.selectedNodes.map((n) => n.name),
|
|
714
|
+
activeMeshName: this.service.selectedMesh?.name || null,
|
|
715
|
+
diagnostics: {
|
|
716
|
+
budgetStatus,
|
|
717
|
+
proportionWarnings,
|
|
718
|
+
},
|
|
719
|
+
groups,
|
|
720
|
+
meshes,
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
buildSystemPrompt() {
|
|
724
|
+
const activeSkillsText = this.skills
|
|
725
|
+
.filter((s) => s.enabled)
|
|
726
|
+
.map((s) => `--- SKILL: ${s.name} (${s.id}) ---\n${s.instructions}`)
|
|
727
|
+
.join('\n\n');
|
|
728
|
+
const sceneStateJson = JSON.stringify(this.buildSceneSummary(), null, 2);
|
|
729
|
+
const minPoly = typeof this.config.minPolygons === 'number' ? this.config.minPolygons : 200;
|
|
730
|
+
const maxPoly = typeof this.config.maxPolygons === 'number' ? this.config.maxPolygons : 5000;
|
|
731
|
+
const createTextures = this.config.createTextures !== false;
|
|
732
|
+
const createNormalMaps = this.config.createNormalMaps !== false && createTextures;
|
|
733
|
+
const normalMapRule = createNormalMaps
|
|
734
|
+
? ` Normal maps are ENABLED: use \`normalMapUrl\` / \`bumpTextureUrl\` or automatic procedural normal mapping in \`modeler_create_material\` (with \`bumpLevel\`, \`invertNormalMapY\` for DirectX/OpenGL, or \`useParallax\`) to add realistic tactile depth and surface micro-relief.`
|
|
735
|
+
: ` Normal maps are DISABLED by the user: do not apply bump or normal maps.`;
|
|
736
|
+
const textureRule = createTextures
|
|
737
|
+
? `3. **Colors, Textures & Materials (Textures ENABLED)**:
|
|
738
|
+
- For primary visible surfaces (e.g. walls, floors, columns, stairs, roofs, armor, props), call \`modeler_generate_texture\` (with a descriptive \`prompt\` like \`"Weathered fluted white marble"\`, \`"Aged terracotta roof tiles"\`, \`"Ancient ashlar stone wall"\`, \`"Polished dark oak wood"\`, \`useAI: true\`, and \`applyToMesh\`) so high-resolution AI textures and normal maps are synthesized and bound to the meshes!
|
|
739
|
+
- You can also pass \`texturePrompt\` directly to architectural tools (\`modeler_create_column\`, \`modeler_create_wall\`, \`modeler_create_roof\`, \`modeler_create_stairs\`) or use \`proceduralTexture\` in \`modeler_create_material\`.
|
|
740
|
+
- Never leave the entire model in flat solid untextured colors when Textures is enabled!${normalMapRule}`
|
|
741
|
+
: `3. **Colors & Materials (Textures DISABLED)**: Texturing is turned OFF by the user. Do NOT generate or apply procedural or image textures (\`proceduralTexture\` / \`textureUrl\`). Use ONLY solid PBR colors (\`color\` / \`albedoColor\`, \`roughness\`, \`metallic\`).`;
|
|
742
|
+
const enabledNeural = this.getEnabledNeural3DProviders();
|
|
743
|
+
const neuralDelegationSection = enabledNeural.length > 0
|
|
744
|
+
? `\n## Active Neural 3D Generators (Available via \`modeler_generate_neural_mesh\`)
|
|
745
|
+
The user has configured and enabled the following external Neural 3D Generators:
|
|
746
|
+
${enabledNeural
|
|
747
|
+
.map((p) => `- **\`${p.id}\` (${p.name})** — Protocol: \`${p.protocol}\`, Model: \`${p.modelId || p.id}\`, Endpoint: \`${p.endpointUrl}\``)
|
|
748
|
+
.join('\n')}
|
|
749
|
+
|
|
750
|
+
When requested to create complex organic figures, creatures, statues, busts, monsters, detailed props, or Image-to-3D reconstructions, delegate full tasks or organic hero subtasks to \`modeler_generate_neural_mesh\` (\`backend: "trellis" | "hunyuan3d" | "hi3d" | "auto"\`). For architectural or composite scenes, build walls/columns/stairs/pedestals procedurally and delegate only the organic hero elements to \`modeler_generate_neural_mesh\`.\n`
|
|
751
|
+
: '';
|
|
752
|
+
return `You are the built-in 3D AI Mesh Agent in **Mesh Editor**.
|
|
753
|
+
Your mission is to procedurally build high-quality 3D meshes or accurately update existing meshes directly in the active Babylon.js 3D scene from text prompts and/or reference images ("Text-to-Mesh", "Image-to-Mesh", "Text/Image-to-Mesh Update").
|
|
754
|
+
|
|
755
|
+
You have built-in Babylon.js modeling tools (\`modeler_*\`) and the following built-in skills available:
|
|
756
|
+
|
|
757
|
+
${activeSkillsText}
|
|
758
|
+
${neuralDelegationSection}
|
|
759
|
+
## Current 3D Scene State
|
|
760
|
+
\`\`\`json
|
|
761
|
+
${sceneStateJson}
|
|
762
|
+
\`\`\`
|
|
763
|
+
|
|
764
|
+
## Key Execution Rules
|
|
765
|
+
1. **Actively call the provided tools** to create or modify geometry in the scene! Never reply with text alone when the user requests a 3D model or modification.
|
|
766
|
+
2. **Descriptive Naming**: Give every created mesh and material a meaningful name (e.g., \`"stone_pillar_base"\`, \`"gear_wheel"\`, \`"oak_wood_mat"\`).
|
|
767
|
+
${textureRule}
|
|
768
|
+
4. **Right Tool for the Job (Avoid Wooden / Blocky Results)**:
|
|
769
|
+
- **Organic, Characters, Creatures & Smooth Clay**: Use \`modeler_create_sdf_mesh\` (smooth polynomial union/subtraction of spheres, ellipsoids, tapered round_cones, and capsules with \`symmetryX: true\`) for seamless, watertight organic bodies, busts, and limbs, OR \`modeler_spawn_base_mesh\` + \`modeler_sculpt_mesh\`.
|
|
770
|
+
- **Explicit Clay Sphere Requests**: If the user explicitly asks to sculpt or model from a clay sphere, ALWAYS honor the request! Call \`modeler_spawn_base_mesh\` with \`type: "sculpt_sphere"\` and shape it using \`modeler_sculpt_mesh\` (using \`"grab"\`, \`"clay"\`, \`"inflate"\`, \`"pinch"\`, \`"flatten"\`, \`"smooth"\` with \`from\`/\`to\` paths) and/or \`modeler_create_sdf_mesh\`.
|
|
771
|
+
- **Architecture & Hard-Surface**: Prefer high-level architectural tools (\`modeler_create_wall\` with window/door \`openings\`, \`modeler_create_arch\`, \`modeler_create_column\`, \`modeler_create_molding\`, \`modeler_create_stairs\`, \`modeler_create_roof\`, and \`modeler_create_rounded_box\` for beveled masonry/furniture) instead of raw un-beveled boxes.
|
|
772
|
+
- **Game Asset Pipeline (Bevel CSG, Retopology, UV Unwrap, Baking & Rigging)**: Use \`modeler_boolean_operation\` (with \`nonDestructive: true\` and \`bevelWidth\` / \`bevelProfile\`), \`modeler_retopologize_mesh\` (\`mode: "decimate" | "shrinkwrap" | "quad_cage" | "quad_strip"\`), \`modeler_uv_unwrap\` (Smart Seams, uniform Texel Density \`px/m\`, and 2D Island Bin-Packing), \`modeler_bake_textures\` (High-to-Low-Poly Tangent-Space Normal & AO baking with smooth Projection Cage), and \`modeler_rig_and_weight\` (\`humanoid\`/\`quadruped\`/\`spine\` Auto-Rigging, normalized 4-bone skin weights, Weight Painting, and Joint Pose testing).
|
|
773
|
+
- **AI Texture Generation, 3D Text & Surface Decals**:
|
|
774
|
+
- Use \`modeler_generate_texture\` to synthesize custom seamless 2D PBR textures and normal maps from a natural language \`prompt\` (e.g., cobblestone, brick, wood planks, sci-fi panels, rust, volcanic lava, marble, glowing runes, dragon scales, moss, or alpha decals) and apply them to meshes.
|
|
775
|
+
- Use \`modeler_create_text_mesh\` whenever the user asks for 3D text, signs, labels, logos, or typography (\`font: "kenney_future" | "droid_sans_bold" | "droid_sans_regular"\`, \`size\`, \`depth\`, \`resolution\`, \`color\`).
|
|
776
|
+
- Use \`modeler_decal\` (\`action: "place" | "merge" | "clear"\`) to project 2D decals (bullet holes, cracks, rust stains, splatters, glowing runes, hazard stripes, riveted plates, star emblems, ivy leaves, vines, flowers, stones, or custom \`prompt\` decals) onto mesh surfaces. Decals are automatically fused into the mesh on export or when \`action: "merge"\` / \`mergeIntoMesh: true\` is used.
|
|
777
|
+
- **Complex Multi-Part Planning**: For multi-part characters, creatures, or buildings, call \`modeler_plan_model\` first to verify proportional hierarchy, vertical grounding, and per-part polygon budgets.
|
|
778
|
+
5. **Concise Summary at the End**: When all tool calls are completed, explain concisely to the user what you built or updated.
|
|
779
|
+
6. **Polygon Budget & Proportional Density (Game Asset)**:
|
|
780
|
+
- Target Polygon Budget: **${minPoly.toLocaleString()} to ${maxPoly.toLocaleString()} triangles**.
|
|
781
|
+
- **Proportional Density Rule**: Primary volumes (torso, head, main walls, roof) must receive **50–65%** of the polygon budget; Secondary parts (limbs, columns, arches) **25–35%**; Tertiary details (eyes, pupils, buttons, bolts, rivets, fingers) **< 10–15%**. NEVER give a small detail (such as an eye) more triangles than the torso or main body! Use \`detailTier: "tertiary"\` or low \`segments\` (6–8) on small spheres/cylinders.
|
|
782
|
+
- **Minimum Polygons (${minPoly.toLocaleString()})**: Ensure the asset has sufficient geometric definition, bevels, segments, or facets to meet or exceed this baseline.
|
|
783
|
+
- **Maximum Polygons (${maxPoly.toLocaleString()})**: Do NOT exceed this limit! Use \`modeler_retopologize_mesh\` if a high-poly sculpt or SDF mesh exceeds the budget.`;
|
|
784
|
+
}
|
|
785
|
+
/* =========================================================================
|
|
786
|
+
OPENAI-COMPATIBLE TOOL DEFINITIONS
|
|
787
|
+
========================================================================= */
|
|
788
|
+
getOpenAITools() {
|
|
789
|
+
return this.toolRegistry.getOpenAITools();
|
|
790
|
+
}
|
|
791
|
+
/* =========================================================================
|
|
792
|
+
TOOL EXECUTION ENGINE
|
|
793
|
+
========================================================================= */
|
|
794
|
+
findMeshByNameOrId(identifier) {
|
|
795
|
+
if (!identifier)
|
|
796
|
+
return undefined;
|
|
797
|
+
const clean = identifier.trim();
|
|
798
|
+
const valid = this.service.importedMeshes.filter((m) => !this.service.isEditorHelper(m) && !m.isDisposed());
|
|
799
|
+
let found = valid.find((m) => m.name === clean);
|
|
800
|
+
if (!found) {
|
|
801
|
+
found = valid.find((m) => m.name.toLowerCase() === clean.toLowerCase());
|
|
802
|
+
}
|
|
803
|
+
if (!found) {
|
|
804
|
+
found = valid.find((m) => m.name.toLowerCase().includes(clean.toLowerCase()));
|
|
805
|
+
}
|
|
806
|
+
return found;
|
|
807
|
+
}
|
|
808
|
+
getOrCreateMaterial(materialName, colorHex, roughness, metallic, fallbackName = 'Mat') {
|
|
809
|
+
if (materialName) {
|
|
810
|
+
const existing = this.materialRegistry.get(materialName) ||
|
|
811
|
+
this.service.scene.materials.find((m) => m instanceof PBRMaterial && m.name.toLowerCase() === materialName.toLowerCase());
|
|
812
|
+
if (existing) {
|
|
813
|
+
if (colorHex)
|
|
814
|
+
existing.albedoColor = Color3.FromHexString(this.normalizeHex(colorHex));
|
|
815
|
+
if (roughness !== undefined)
|
|
816
|
+
existing.roughness = roughness;
|
|
817
|
+
if (metallic !== undefined)
|
|
818
|
+
existing.metallic = metallic;
|
|
819
|
+
return existing;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
const name = materialName || `${fallbackName}_mat_${Date.now().toString().slice(-4)}`;
|
|
823
|
+
const mat = new PBRMaterial(name, this.service.scene);
|
|
824
|
+
mat.albedoColor = Color3.FromHexString(this.normalizeHex(colorHex || '#58a6ff'));
|
|
825
|
+
mat.roughness = roughness !== undefined ? roughness : 0.45;
|
|
826
|
+
mat.metallic = metallic !== undefined ? metallic : 0.1;
|
|
827
|
+
mat.backFaceCulling = false;
|
|
828
|
+
this.materialRegistry.set(name, mat);
|
|
829
|
+
return mat;
|
|
830
|
+
}
|
|
831
|
+
normalizeHex(hex) {
|
|
832
|
+
if (!hex || typeof hex !== 'string')
|
|
833
|
+
return '#58a6ff';
|
|
834
|
+
const trimmed = hex.trim();
|
|
835
|
+
if (/^#[0-9a-fA-F]{6}$/.test(trimmed))
|
|
836
|
+
return trimmed;
|
|
837
|
+
if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {
|
|
838
|
+
return ('#' +
|
|
839
|
+
trimmed
|
|
840
|
+
.slice(1)
|
|
841
|
+
.split('')
|
|
842
|
+
.map((c) => c + c)
|
|
843
|
+
.join(''));
|
|
844
|
+
}
|
|
845
|
+
if (/^[0-9a-fA-F]{6}$/.test(trimmed))
|
|
846
|
+
return '#' + trimmed;
|
|
847
|
+
return '#58a6ff';
|
|
848
|
+
}
|
|
849
|
+
parseVec3(v, defaultVal = 0) {
|
|
850
|
+
if (Array.isArray(v)) {
|
|
851
|
+
return new Vector3(Number(v[0] ?? defaultVal) || 0, Number(v[1] ?? defaultVal) || 0, Number(v[2] ?? defaultVal) || 0);
|
|
852
|
+
}
|
|
853
|
+
return new Vector3(Number(v?.x ?? defaultVal) || 0, Number(v?.y ?? defaultVal) || 0, Number(v?.z ?? defaultVal) || 0);
|
|
854
|
+
}
|
|
855
|
+
parsePolygonPoint(p) {
|
|
856
|
+
if (Array.isArray(p)) {
|
|
857
|
+
if (p.length === 2) {
|
|
858
|
+
return new Vector3(Number(p[0]) || 0, 0, Number(p[1]) || 0);
|
|
859
|
+
}
|
|
860
|
+
return new Vector3(Number(p[0]) || 0, Number(p[1]) || 0, Number(p[2]) || 0);
|
|
861
|
+
}
|
|
862
|
+
return new Vector3(Number(p?.x) || 0, Number(p?.y) || 0, Number(p?.z) || 0);
|
|
863
|
+
}
|
|
864
|
+
applyTransformArgs(mesh, args) {
|
|
865
|
+
if (args.position) {
|
|
866
|
+
mesh.position.copyFrom(this.parseVec3(args.position, 0));
|
|
867
|
+
}
|
|
868
|
+
if (args.rotationDegrees) {
|
|
869
|
+
mesh.rotationQuaternion = null;
|
|
870
|
+
const deg = this.parseVec3(args.rotationDegrees, 0);
|
|
871
|
+
mesh.rotation.set((deg.x * Math.PI) / 180, (deg.y * Math.PI) / 180, (deg.z * Math.PI) / 180);
|
|
872
|
+
}
|
|
873
|
+
else if (args.rotation && typeof args.rotation === 'object') {
|
|
874
|
+
mesh.rotationQuaternion = null;
|
|
875
|
+
mesh.rotation.copyFrom(this.parseVec3(args.rotation, 0));
|
|
876
|
+
}
|
|
877
|
+
else if (args.meshRotation && typeof args.meshRotation === 'object') {
|
|
878
|
+
mesh.rotationQuaternion = null;
|
|
879
|
+
mesh.rotation.copyFrom(this.parseVec3(args.meshRotation, 0));
|
|
880
|
+
}
|
|
881
|
+
if (args.scaling) {
|
|
882
|
+
const sc = Array.isArray(args.scaling)
|
|
883
|
+
? new Vector3(Number(args.scaling[0] ?? 1) || 1, Number(args.scaling[1] ?? 1) || 1, Number(args.scaling[2] ?? 1) || 1)
|
|
884
|
+
: new Vector3(Number(args.scaling.x ?? 1) || 1, Number(args.scaling.y ?? 1) || 1, Number(args.scaling.z ?? 1) || 1);
|
|
885
|
+
mesh.scaling.copyFrom(sc);
|
|
886
|
+
}
|
|
887
|
+
mesh.computeWorldMatrix(true);
|
|
888
|
+
}
|
|
889
|
+
registerCreatedMesh(mesh) {
|
|
890
|
+
mesh.isPickable = true;
|
|
891
|
+
if (mesh.material) {
|
|
892
|
+
mesh.material.backFaceCulling = false;
|
|
893
|
+
}
|
|
894
|
+
if (!this.service.importedMeshes.includes(mesh)) {
|
|
895
|
+
this.service.importedMeshes.push(mesh);
|
|
896
|
+
}
|
|
897
|
+
mesh.computeWorldMatrix(true);
|
|
898
|
+
mesh.refreshBoundingInfo();
|
|
899
|
+
}
|
|
900
|
+
async executeToolCall(toolName, rawArgs) {
|
|
901
|
+
const context = this.createToolContext();
|
|
902
|
+
return await this.toolRegistry.execute(toolName, rawArgs, context);
|
|
903
|
+
}
|
|
904
|
+
/* =========================================================================
|
|
905
|
+
FALLBACK PARSER FOR ENDPOINTS WITHOUT NATIVE TOOL CALLING
|
|
906
|
+
========================================================================= */
|
|
907
|
+
extractFallbackToolCallsFromText(content) {
|
|
908
|
+
const calls = [];
|
|
909
|
+
if (!content)
|
|
910
|
+
return calls;
|
|
911
|
+
// 1. Check for ```json ... ``` blocks containing tool calls
|
|
912
|
+
const jsonFenceRegex = /```(?:json)?\s*([\s\S]*?)```/gi;
|
|
913
|
+
let match;
|
|
914
|
+
while ((match = jsonFenceRegex.exec(content)) !== null) {
|
|
915
|
+
const block = match[1].trim();
|
|
916
|
+
try {
|
|
917
|
+
const parsed = JSON.parse(block);
|
|
918
|
+
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
919
|
+
for (const item of items) {
|
|
920
|
+
if (item && typeof item.name === 'string' && item.name.startsWith('modeler_')) {
|
|
921
|
+
calls.push({ name: item.name, arguments: item.arguments || item.args || item.parameters || {} });
|
|
922
|
+
}
|
|
923
|
+
else if (item && typeof item.tool === 'string' && item.tool.startsWith('modeler_')) {
|
|
924
|
+
calls.push({ name: item.tool, arguments: item.arguments || item.args || item.parameters || {} });
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
catch {
|
|
929
|
+
// Not a JSON tool block
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (calls.length > 0)
|
|
933
|
+
return calls;
|
|
934
|
+
// 2. Check for ```javascript / ```ts / ```babylon code blocks that use MeshBuilder
|
|
935
|
+
const codeFenceRegex = /```(?:javascript|js|typescript|ts|babylon)\s*([\s\S]*?)```/gi;
|
|
936
|
+
while ((match = codeFenceRegex.exec(content)) !== null) {
|
|
937
|
+
const code = match[1].trim();
|
|
938
|
+
if (code.includes('MeshBuilder.') || code.includes('CSG') || code.includes('new Mesh')) {
|
|
939
|
+
calls.push({
|
|
940
|
+
name: 'modeler_execute_babylon_code',
|
|
941
|
+
arguments: {
|
|
942
|
+
description: 'Execute generated Babylon.js code block',
|
|
943
|
+
code,
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return calls;
|
|
949
|
+
}
|
|
950
|
+
/* =========================================================================
|
|
951
|
+
AGENT EXECUTION LOOP (Text-to-Mesh, Image-to-Mesh, Mesh-Update)
|
|
952
|
+
========================================================================= */
|
|
953
|
+
async runPrompt(options) {
|
|
954
|
+
const prompt = (options.prompt || '').trim();
|
|
955
|
+
const images = [...(options.images || [])];
|
|
956
|
+
if (options.includeViewportSnapshot) {
|
|
957
|
+
const snap = this.captureViewportDataUrl();
|
|
958
|
+
if (snap)
|
|
959
|
+
images.push(snap);
|
|
960
|
+
}
|
|
961
|
+
if (!prompt && images.length === 0) {
|
|
962
|
+
throw new Error('Please provide a prompt or attach an image.');
|
|
963
|
+
}
|
|
964
|
+
if (options.mode === 'replace_scene') {
|
|
965
|
+
this.service.clearModel();
|
|
966
|
+
}
|
|
967
|
+
// Record user message in history
|
|
968
|
+
const userMsg = {
|
|
969
|
+
id: `msg_${Date.now()}_user`,
|
|
970
|
+
role: 'user',
|
|
971
|
+
content: prompt || '(Image-to-Mesh generation)',
|
|
972
|
+
images: images.length > 0 ? images : undefined,
|
|
973
|
+
timestamp: Date.now(),
|
|
974
|
+
};
|
|
975
|
+
this.chatHistory.push(userMsg);
|
|
976
|
+
// Build OpenAI messages payload
|
|
977
|
+
const apiMessages = [
|
|
978
|
+
{
|
|
979
|
+
role: 'system',
|
|
980
|
+
content: this.buildSystemPrompt(),
|
|
981
|
+
},
|
|
982
|
+
];
|
|
983
|
+
// Include up to last 6 conversational turns for context
|
|
984
|
+
const recentHistory = this.chatHistory.slice(-7, -1);
|
|
985
|
+
for (const h of recentHistory) {
|
|
986
|
+
if (h.role === 'user') {
|
|
987
|
+
apiMessages.push({ role: 'user', content: h.content });
|
|
988
|
+
}
|
|
989
|
+
else if (h.role === 'assistant') {
|
|
990
|
+
apiMessages.push({ role: 'assistant', content: h.content });
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
// Current user message (multimodal if images are attached)
|
|
994
|
+
if (images.length > 0) {
|
|
995
|
+
const contentParts = [
|
|
996
|
+
{
|
|
997
|
+
type: 'text',
|
|
998
|
+
text: prompt ||
|
|
999
|
+
'Analyze this reference image and recreate the corresponding 3D model in detail using the Babylon.js Modeler tools in the scene.',
|
|
1000
|
+
},
|
|
1001
|
+
];
|
|
1002
|
+
for (const imgUrl of images) {
|
|
1003
|
+
contentParts.push({
|
|
1004
|
+
type: 'image_url',
|
|
1005
|
+
image_url: { url: imgUrl },
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
apiMessages.push({
|
|
1009
|
+
role: 'user',
|
|
1010
|
+
content: contentParts,
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
else {
|
|
1014
|
+
apiMessages.push({
|
|
1015
|
+
role: 'user',
|
|
1016
|
+
content: prompt,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
// Snapshot scene meshes before agent execution for 1-click Undo/Redo support
|
|
1020
|
+
const meshesBeforeRun = new Set(this.service.importedMeshes.filter((m) => !this.service.isEditorHelper(m) && !m.isDisposed()));
|
|
1021
|
+
const preRunTransforms = new Map();
|
|
1022
|
+
for (const m of meshesBeforeRun) {
|
|
1023
|
+
preRunTransforms.set(m, {
|
|
1024
|
+
pos: m.position.clone(),
|
|
1025
|
+
rot: m.rotation.clone(),
|
|
1026
|
+
scale: m.scaling.clone(),
|
|
1027
|
+
mat: m.material,
|
|
1028
|
+
visible: m.isVisible,
|
|
1029
|
+
enabled: m.isEnabled(),
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
const executedSteps = [];
|
|
1033
|
+
const maxIterations = Math.max(1, Math.min(25, this.config.maxIterations || 12));
|
|
1034
|
+
const enableVisualCritique = options.visualCritique !== undefined ? options.visualCritique : !!this.config.visualCritique;
|
|
1035
|
+
let critiqueCompleted = false;
|
|
1036
|
+
let finalAssistantText = '';
|
|
1037
|
+
let toolsSupported = true;
|
|
1038
|
+
this.currentRequestImages = images;
|
|
1039
|
+
this.currentRequestSignal = options.signal;
|
|
1040
|
+
this.currentRequestOnStatus = options.onStatus;
|
|
1041
|
+
this.service.events.onStatusChanged?.('AI Agent working...', true);
|
|
1042
|
+
try {
|
|
1043
|
+
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
1044
|
+
if (options.signal?.aborted) {
|
|
1045
|
+
throw new Error('Generation cancelled by user.');
|
|
1046
|
+
}
|
|
1047
|
+
options.onStatus?.(iteration === 0
|
|
1048
|
+
? 'Sending request to AI endpoint...'
|
|
1049
|
+
: `AI Agent modeling (step ${iteration + 1})...`);
|
|
1050
|
+
const responseData = await this.callChatCompletions(apiMessages, toolsSupported, options.signal);
|
|
1051
|
+
// If endpoint rejected `tools` parameter, retry without native tools
|
|
1052
|
+
if (responseData.__retryWithoutTools) {
|
|
1053
|
+
toolsSupported = false;
|
|
1054
|
+
iteration--;
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
const choice = responseData?.choices?.[0];
|
|
1058
|
+
const message = choice?.message;
|
|
1059
|
+
if (!message) {
|
|
1060
|
+
throw new Error('Invalid response from OpenAI-compatible endpoint (no message in choices[0]).');
|
|
1061
|
+
}
|
|
1062
|
+
const assistantContent = typeof message.content === 'string'
|
|
1063
|
+
? message.content
|
|
1064
|
+
: Array.isArray(message.content)
|
|
1065
|
+
? message.content.map((p) => p?.text || '').join('\n')
|
|
1066
|
+
: '';
|
|
1067
|
+
if (assistantContent) {
|
|
1068
|
+
finalAssistantText = assistantContent;
|
|
1069
|
+
}
|
|
1070
|
+
const nativeToolCalls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
|
|
1071
|
+
// Support legacy function_call if returned by some endpoints
|
|
1072
|
+
if (nativeToolCalls.length === 0 && message.function_call && message.function_call.name) {
|
|
1073
|
+
nativeToolCalls.push({
|
|
1074
|
+
id: `call_legacy_${iteration}`,
|
|
1075
|
+
type: 'function',
|
|
1076
|
+
function: {
|
|
1077
|
+
name: message.function_call.name,
|
|
1078
|
+
arguments: message.function_call.arguments || '{}',
|
|
1079
|
+
},
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
if (nativeToolCalls.length > 0) {
|
|
1083
|
+
apiMessages.push({
|
|
1084
|
+
role: 'assistant',
|
|
1085
|
+
content: message.content || null,
|
|
1086
|
+
tool_calls: nativeToolCalls,
|
|
1087
|
+
});
|
|
1088
|
+
for (const tc of nativeToolCalls) {
|
|
1089
|
+
if (options.signal?.aborted) {
|
|
1090
|
+
throw new Error('Generation cancelled by user.');
|
|
1091
|
+
}
|
|
1092
|
+
const fnName = tc.function?.name || '';
|
|
1093
|
+
const rawArgs = tc.function?.arguments || '{}';
|
|
1094
|
+
let parsedArgs = {};
|
|
1095
|
+
try {
|
|
1096
|
+
parsedArgs = typeof rawArgs === 'string' ? JSON.parse(rawArgs) : rawArgs;
|
|
1097
|
+
}
|
|
1098
|
+
catch {
|
|
1099
|
+
parsedArgs = { raw: rawArgs };
|
|
1100
|
+
}
|
|
1101
|
+
options.onStatus?.(`Executing tool: ${fnName}...`);
|
|
1102
|
+
const startTime = Date.now();
|
|
1103
|
+
let toolResultStr = '';
|
|
1104
|
+
let isError = false;
|
|
1105
|
+
try {
|
|
1106
|
+
toolResultStr = await this.executeToolCall(fnName, parsedArgs);
|
|
1107
|
+
}
|
|
1108
|
+
catch (err) {
|
|
1109
|
+
isError = true;
|
|
1110
|
+
toolResultStr = JSON.stringify({ error: err?.message || String(err) });
|
|
1111
|
+
}
|
|
1112
|
+
const step = {
|
|
1113
|
+
id: tc.id || `step_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
1114
|
+
toolName: fnName,
|
|
1115
|
+
args: parsedArgs,
|
|
1116
|
+
result: toolResultStr,
|
|
1117
|
+
isError,
|
|
1118
|
+
durationMs: Date.now() - startTime,
|
|
1119
|
+
};
|
|
1120
|
+
executedSteps.push(step);
|
|
1121
|
+
options.onStep?.(step);
|
|
1122
|
+
apiMessages.push({
|
|
1123
|
+
role: 'tool',
|
|
1124
|
+
tool_call_id: tc.id,
|
|
1125
|
+
name: fnName,
|
|
1126
|
+
content: toolResultStr,
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
// Update viewport after each batch of tool calls
|
|
1130
|
+
this.service.updateStats();
|
|
1131
|
+
this.service.events.onSceneModified?.();
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
// Check fallback code/JSON blocks if no native tool_calls were emitted
|
|
1135
|
+
const fallbackCalls = this.extractFallbackToolCallsFromText(assistantContent);
|
|
1136
|
+
if (fallbackCalls.length > 0 && executedSteps.length === 0) {
|
|
1137
|
+
for (const fc of fallbackCalls) {
|
|
1138
|
+
const startTime = Date.now();
|
|
1139
|
+
let toolResultStr = '';
|
|
1140
|
+
let isError = false;
|
|
1141
|
+
try {
|
|
1142
|
+
toolResultStr = await this.executeToolCall(fc.name, fc.arguments);
|
|
1143
|
+
}
|
|
1144
|
+
catch (err) {
|
|
1145
|
+
isError = true;
|
|
1146
|
+
toolResultStr = JSON.stringify({ error: err?.message || String(err) });
|
|
1147
|
+
}
|
|
1148
|
+
const step = {
|
|
1149
|
+
id: `step_fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
1150
|
+
toolName: fc.name,
|
|
1151
|
+
args: fc.arguments,
|
|
1152
|
+
result: toolResultStr,
|
|
1153
|
+
isError,
|
|
1154
|
+
durationMs: Date.now() - startTime,
|
|
1155
|
+
};
|
|
1156
|
+
executedSteps.push(step);
|
|
1157
|
+
options.onStep?.(step);
|
|
1158
|
+
}
|
|
1159
|
+
this.service.updateStats();
|
|
1160
|
+
this.service.events.onSceneModified?.();
|
|
1161
|
+
}
|
|
1162
|
+
// Optional Multi-View Visual Critique & Self-Correction Phase (uses the same active 3D model)
|
|
1163
|
+
if (enableVisualCritique &&
|
|
1164
|
+
!critiqueCompleted &&
|
|
1165
|
+
executedSteps.length > 0 &&
|
|
1166
|
+
iteration + 1 < maxIterations) {
|
|
1167
|
+
critiqueCompleted = true;
|
|
1168
|
+
options.onStatus?.('Visual critique: rendering 4-view + wireframe sheet for inspection...');
|
|
1169
|
+
const multiViewUrl = this.captureMultiViewDataUrl();
|
|
1170
|
+
const summary = this.buildSceneSummary();
|
|
1171
|
+
const minPoly = typeof this.config.minPolygons === 'number' ? this.config.minPolygons : 200;
|
|
1172
|
+
const maxPoly = typeof this.config.maxPolygons === 'number' ? this.config.maxPolygons : 5000;
|
|
1173
|
+
if (assistantContent) {
|
|
1174
|
+
apiMessages.push({
|
|
1175
|
+
role: 'assistant',
|
|
1176
|
+
content: assistantContent,
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
const critiqueText = `[VISUAL CRITIQUE & SELF-CORRECTION PHASE]
|
|
1180
|
+
Inspect the attached 4-view render sheet (1. Front, 2. Right Side, 3. 3/4 Perspective, 4. 3/4 Wireframe/Topology) and the 3D Scene Diagnostics below against the user's request: "${prompt || 'Reference image reconstruction'}".
|
|
1181
|
+
|
|
1182
|
+
Scene Diagnostics:
|
|
1183
|
+
${JSON.stringify({
|
|
1184
|
+
totalSceneTriangles: summary.totalSceneTriangles,
|
|
1185
|
+
targetBudget: { minPolygons: minPoly, maxPolygons: maxPoly },
|
|
1186
|
+
diagnostics: summary.diagnostics,
|
|
1187
|
+
meshes: (summary.meshes || []).map((m) => ({
|
|
1188
|
+
name: m.name,
|
|
1189
|
+
triangles: m.triangles,
|
|
1190
|
+
triangleSharePercent: m.triangleSharePercent,
|
|
1191
|
+
worldBounds: m.worldBounds,
|
|
1192
|
+
})),
|
|
1193
|
+
}, null, 2)}
|
|
1194
|
+
|
|
1195
|
+
Evaluate all 4 criteria:
|
|
1196
|
+
1. Silhouette & Organic/Architectural Quality: Does the model look natural and detailed rather than blocky or wooden?
|
|
1197
|
+
2. Alignment & Grounding: Are any parts floating, detached, or mispositioned in the Front/Side views?
|
|
1198
|
+
3. Proportional Polygon Density (Wireframe View): Does any small detail (such as an eye, button, or trim) have more triangles than the torso/main body, or is total triangle count outside the budget?
|
|
1199
|
+
4. Completeness: Are all requested features and materials present?
|
|
1200
|
+
|
|
1201
|
+
If you detect ANY issues or warnings above, call the appropriate \`modeler_*\` tools NOW to fix them (e.g. transform mispositioned parts, replace disproportionate primitives, smooth/sculpt wooden forms, or retopologize). If the model is already well-proportioned and complete, reply with a concise final summary and no tool calls.`;
|
|
1202
|
+
if (multiViewUrl) {
|
|
1203
|
+
apiMessages.push({
|
|
1204
|
+
role: 'user',
|
|
1205
|
+
content: [
|
|
1206
|
+
{ type: 'text', text: critiqueText },
|
|
1207
|
+
{ type: 'image_url', image_url: { url: multiViewUrl } },
|
|
1208
|
+
],
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
else {
|
|
1212
|
+
apiMessages.push({
|
|
1213
|
+
role: 'user',
|
|
1214
|
+
content: critiqueText,
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
// No more tool calls -> finished!
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
// Finalize scene state, selection, camera focus, and Undo/Redo action
|
|
1223
|
+
this.service.importedMeshes = this.service.importedMeshes.filter((m) => !this.service.isEditorHelper(m) && !m.isDisposed());
|
|
1224
|
+
const meshesAfterRun = new Set(this.service.importedMeshes);
|
|
1225
|
+
const newlyCreatedMeshes = Array.from(meshesAfterRun).filter((m) => !meshesBeforeRun.has(m));
|
|
1226
|
+
if (newlyCreatedMeshes.length > 0) {
|
|
1227
|
+
this.service.selectNodes(newlyCreatedMeshes);
|
|
1228
|
+
this.service.focusOnAll();
|
|
1229
|
+
}
|
|
1230
|
+
if (executedSteps.length > 0) {
|
|
1231
|
+
this.registerUndoRedoRecord(prompt, meshesBeforeRun, preRunTransforms, newlyCreatedMeshes);
|
|
1232
|
+
}
|
|
1233
|
+
this.service.updateStats();
|
|
1234
|
+
this.service.events.onSceneModified?.();
|
|
1235
|
+
this.service.events.onStatusChanged?.('Ready', false);
|
|
1236
|
+
this.service.events.onToast?.(`AI Agent finished (${executedSteps.length} modeling steps executed)!`, 'success');
|
|
1237
|
+
const assistantMsg = {
|
|
1238
|
+
id: `msg_${Date.now()}_assistant`,
|
|
1239
|
+
role: 'assistant',
|
|
1240
|
+
content: finalAssistantText ||
|
|
1241
|
+
(executedSteps.length > 0
|
|
1242
|
+
? `${executedSteps.length} 3D modeling operation(s) successfully executed in the scene.`
|
|
1243
|
+
: 'Request completed.'),
|
|
1244
|
+
toolSteps: executedSteps,
|
|
1245
|
+
timestamp: Date.now(),
|
|
1246
|
+
};
|
|
1247
|
+
this.chatHistory.push(assistantMsg);
|
|
1248
|
+
return assistantMsg;
|
|
1249
|
+
}
|
|
1250
|
+
catch (err) {
|
|
1251
|
+
this.service.events.onStatusChanged?.('Ready', false);
|
|
1252
|
+
this.service.events.onToast?.(`AI Agent error: ${err?.message || err}`, 'error');
|
|
1253
|
+
throw err;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
registerUndoRedoRecord(prompt, meshesBeforeRun, preRunTransforms, newlyCreatedMeshes) {
|
|
1257
|
+
const postRunTransforms = new Map();
|
|
1258
|
+
for (const m of meshesBeforeRun) {
|
|
1259
|
+
if (!m.isDisposed()) {
|
|
1260
|
+
postRunTransforms.set(m, {
|
|
1261
|
+
pos: m.position.clone(),
|
|
1262
|
+
rot: m.rotation.clone(),
|
|
1263
|
+
scale: m.scaling.clone(),
|
|
1264
|
+
mat: m.material,
|
|
1265
|
+
visible: m.isVisible,
|
|
1266
|
+
enabled: m.isEnabled(),
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
const shortPrompt = prompt.length > 28 ? prompt.slice(0, 28) + '...' : prompt || 'AI Mesh Generation';
|
|
1271
|
+
this.service.recordAction({
|
|
1272
|
+
name: `AI Agent: ${shortPrompt}`,
|
|
1273
|
+
undo: () => {
|
|
1274
|
+
this.service.clearSelectionProxy();
|
|
1275
|
+
for (const m of newlyCreatedMeshes) {
|
|
1276
|
+
if (!m.isDisposed()) {
|
|
1277
|
+
m.setEnabled(false);
|
|
1278
|
+
const idx = this.service.importedMeshes.indexOf(m);
|
|
1279
|
+
if (idx !== -1)
|
|
1280
|
+
this.service.importedMeshes.splice(idx, 1);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
for (const [m, state] of preRunTransforms.entries()) {
|
|
1284
|
+
if (!m.isDisposed()) {
|
|
1285
|
+
m.position.copyFrom(state.pos);
|
|
1286
|
+
m.rotation.copyFrom(state.rot);
|
|
1287
|
+
m.scaling.copyFrom(state.scale);
|
|
1288
|
+
m.material = state.mat;
|
|
1289
|
+
m.isVisible = state.visible;
|
|
1290
|
+
m.setEnabled(state.enabled);
|
|
1291
|
+
if (state.enabled && !this.service.importedMeshes.includes(m)) {
|
|
1292
|
+
this.service.importedMeshes.push(m);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
this.service.selectNodes([]);
|
|
1297
|
+
this.service.events.onSceneModified?.();
|
|
1298
|
+
},
|
|
1299
|
+
redo: () => {
|
|
1300
|
+
this.service.clearSelectionProxy();
|
|
1301
|
+
for (const m of newlyCreatedMeshes) {
|
|
1302
|
+
if (!m.isDisposed()) {
|
|
1303
|
+
m.setEnabled(true);
|
|
1304
|
+
if (!this.service.importedMeshes.includes(m)) {
|
|
1305
|
+
this.service.importedMeshes.push(m);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
for (const [m, state] of postRunTransforms.entries()) {
|
|
1310
|
+
if (!m.isDisposed()) {
|
|
1311
|
+
m.position.copyFrom(state.pos);
|
|
1312
|
+
m.rotation.copyFrom(state.rot);
|
|
1313
|
+
m.scaling.copyFrom(state.scale);
|
|
1314
|
+
m.material = state.mat;
|
|
1315
|
+
m.isVisible = state.visible;
|
|
1316
|
+
m.setEnabled(state.enabled);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
this.service.selectNodes(newlyCreatedMeshes);
|
|
1320
|
+
this.service.events.onSceneModified?.();
|
|
1321
|
+
},
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
async callChatCompletions(messages, includeTools, signal) {
|
|
1325
|
+
const url = this.getChatCompletionsUrl();
|
|
1326
|
+
const headers = {
|
|
1327
|
+
'Content-Type': 'application/json',
|
|
1328
|
+
Accept: 'application/json',
|
|
1329
|
+
};
|
|
1330
|
+
if (this.config.apiKey && this.config.apiKey.trim()) {
|
|
1331
|
+
headers['Authorization'] = `Bearer ${this.config.apiKey.trim()}`;
|
|
1332
|
+
}
|
|
1333
|
+
const activeModel = this.normalizeModelName(this.config.model || DEFAULT_AI_AGENT_CONFIG.model, url);
|
|
1334
|
+
const body = {
|
|
1335
|
+
model: activeModel,
|
|
1336
|
+
messages,
|
|
1337
|
+
temperature: this.config.temperature ?? 0.2,
|
|
1338
|
+
};
|
|
1339
|
+
if (includeTools) {
|
|
1340
|
+
body.tools = this.getOpenAITools();
|
|
1341
|
+
body.tool_choice = 'auto';
|
|
1342
|
+
}
|
|
1343
|
+
const fetchFn = this.customFetch || globalThis.fetch.bind(globalThis);
|
|
1344
|
+
let res;
|
|
1345
|
+
const timeoutMs = 600000; // 10-minute safety limit to prevent indefinite hanging
|
|
1346
|
+
const timeoutController = new AbortController();
|
|
1347
|
+
const timer = setTimeout(() => {
|
|
1348
|
+
timeoutController.abort(new Error('Endpoint request timed out after 10 minutes.'));
|
|
1349
|
+
}, timeoutMs);
|
|
1350
|
+
// Combine caller signal with timeout controller
|
|
1351
|
+
let effectiveSignal = timeoutController.signal;
|
|
1352
|
+
if (signal) {
|
|
1353
|
+
if (signal.aborted) {
|
|
1354
|
+
clearTimeout(timer);
|
|
1355
|
+
throw new Error('Generation cancelled by user.');
|
|
1356
|
+
}
|
|
1357
|
+
signal.addEventListener('abort', () => timeoutController.abort(), { once: true });
|
|
1358
|
+
}
|
|
1359
|
+
try {
|
|
1360
|
+
res = await fetchFn(url, {
|
|
1361
|
+
method: 'POST',
|
|
1362
|
+
headers,
|
|
1363
|
+
body: JSON.stringify(body),
|
|
1364
|
+
signal: effectiveSignal,
|
|
1365
|
+
});
|
|
1366
|
+
if (res.status === 404 && url.startsWith('/api/antigravity/v1')) {
|
|
1367
|
+
res = await fetchFn(url.replace(/^\/api\/antigravity\/v1/, 'http://localhost:8787/v1'), {
|
|
1368
|
+
method: 'POST',
|
|
1369
|
+
headers,
|
|
1370
|
+
body: JSON.stringify(body),
|
|
1371
|
+
signal: effectiveSignal,
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
catch (err) {
|
|
1376
|
+
if (url.startsWith('/api/antigravity/v1') && !effectiveSignal.aborted) {
|
|
1377
|
+
try {
|
|
1378
|
+
res = await fetchFn(url.replace(/^\/api\/antigravity\/v1/, 'http://localhost:8787/v1'), {
|
|
1379
|
+
method: 'POST',
|
|
1380
|
+
headers,
|
|
1381
|
+
body: JSON.stringify(body),
|
|
1382
|
+
signal: effectiveSignal,
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
catch {
|
|
1386
|
+
clearTimeout(timer);
|
|
1387
|
+
throw err;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
else {
|
|
1391
|
+
clearTimeout(timer);
|
|
1392
|
+
if (err?.name === 'AbortError' && !signal?.aborted) {
|
|
1393
|
+
throw new Error('Endpoint request timed out after 10 minutes. The model or bridge did not respond in time.');
|
|
1394
|
+
}
|
|
1395
|
+
throw err;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
finally {
|
|
1399
|
+
clearTimeout(timer);
|
|
1400
|
+
}
|
|
1401
|
+
if (!res.ok) {
|
|
1402
|
+
const errText = await res.text().catch(() => '');
|
|
1403
|
+
// Auto-switch to local Antigravity Bridge if Google AI Studio returns 402 (depleted prepayment credits)
|
|
1404
|
+
if (res.status === 402 && url.toLowerCase().includes('generativelanguage.googleapis.com')) {
|
|
1405
|
+
const agyModel = 'gemini-3.8-flash-medium';
|
|
1406
|
+
this.saveConfig({ baseUrl: '/api/antigravity/v1', model: agyModel });
|
|
1407
|
+
body.model = agyModel;
|
|
1408
|
+
try {
|
|
1409
|
+
res = await fetchFn('/api/antigravity/v1/chat/completions', {
|
|
1410
|
+
method: 'POST',
|
|
1411
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
1412
|
+
body: JSON.stringify(body),
|
|
1413
|
+
signal,
|
|
1414
|
+
});
|
|
1415
|
+
if (!res.ok) {
|
|
1416
|
+
res = await fetchFn('http://localhost:8787/v1/chat/completions', {
|
|
1417
|
+
method: 'POST',
|
|
1418
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
1419
|
+
body: JSON.stringify(body),
|
|
1420
|
+
signal,
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
if (res.ok) {
|
|
1424
|
+
return await res.json();
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
catch {
|
|
1428
|
+
// Fall through to error reporting if local bridge is unreachable
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
// Auto-recover if Gemini endpoint reports a deprecated model and suggests a replacement model
|
|
1432
|
+
if (res.status === 404 && url.toLowerCase().includes('generativelanguage.googleapis.com')) {
|
|
1433
|
+
const suggestedMatch = errText.match(/use\s+models\/([a-zA-Z0-9._-]+)/i);
|
|
1434
|
+
const fallbackModel = suggestedMatch ? suggestedMatch[1] : 'gemini-3-flash-preview';
|
|
1435
|
+
if (fallbackModel && fallbackModel !== body.model) {
|
|
1436
|
+
this.saveConfig({ model: fallbackModel });
|
|
1437
|
+
body.model = fallbackModel;
|
|
1438
|
+
res = await fetchFn(url, {
|
|
1439
|
+
method: 'POST',
|
|
1440
|
+
headers,
|
|
1441
|
+
body: JSON.stringify(body),
|
|
1442
|
+
signal,
|
|
1443
|
+
});
|
|
1444
|
+
if (res.ok) {
|
|
1445
|
+
return await res.json();
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
// If the model/endpoint does not support tool calling (HTTP 400 mentioning tools/functions), retry once without tools
|
|
1450
|
+
if (includeTools &&
|
|
1451
|
+
res.status === 400 &&
|
|
1452
|
+
/tool|function/i.test(errText)) {
|
|
1453
|
+
return { __retryWithoutTools: true };
|
|
1454
|
+
}
|
|
1455
|
+
let friendlyError = errText || res.statusText;
|
|
1456
|
+
try {
|
|
1457
|
+
const parsedErr = JSON.parse(errText);
|
|
1458
|
+
const errObj = Array.isArray(parsedErr) ? parsedErr[0]?.error : parsedErr?.error;
|
|
1459
|
+
if (errObj?.message) {
|
|
1460
|
+
friendlyError = errObj.message;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
catch {
|
|
1464
|
+
// Keep raw text
|
|
1465
|
+
}
|
|
1466
|
+
throw new Error(`Endpoint error (${res.status}): ${friendlyError}`);
|
|
1467
|
+
}
|
|
1468
|
+
return await res.json();
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
//# sourceMappingURL=AIAgentService.js.map
|