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,710 @@
|
|
|
1
|
+
import { Color3, Mesh, PBRMaterial, RawTexture, StandardMaterial, Texture, Vector3, VertexBuffer, VertexData, } from '@babylonjs/core';
|
|
2
|
+
/**
|
|
3
|
+
* High-Poly to Low-Poly Raycast Texture Baker & Automatic Projection Cage Generator.
|
|
4
|
+
* Bakes Tangent-Space Normal Maps and Ambient Occlusion (AO) Maps with UV seam dilation.
|
|
5
|
+
*/
|
|
6
|
+
export class TextureBaker {
|
|
7
|
+
service;
|
|
8
|
+
scene;
|
|
9
|
+
resolution = 512;
|
|
10
|
+
cageExtrusion = 0.04;
|
|
11
|
+
paddingPx = 4;
|
|
12
|
+
flipNormalY = false;
|
|
13
|
+
showCagePreview = false;
|
|
14
|
+
cagePreviewMesh = null;
|
|
15
|
+
lastBakeResult = null;
|
|
16
|
+
constructor(service) {
|
|
17
|
+
this.service = service;
|
|
18
|
+
this.scene = service.scene;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Computes welded smooth vertex normals for a mesh so the extruded projection cage
|
|
22
|
+
* has zero gaps or splits along hard UV/smoothing seams.
|
|
23
|
+
*/
|
|
24
|
+
computeSmoothCageNormals(positions, indices) {
|
|
25
|
+
const quant = 10000;
|
|
26
|
+
const posMap = new Map();
|
|
27
|
+
const numVerts = Math.floor(positions.length / 3);
|
|
28
|
+
const keys = new Array(numVerts);
|
|
29
|
+
for (let i = 0; i < numVerts; i++) {
|
|
30
|
+
const k = `${Math.round(positions[i * 3] * quant)},${Math.round(positions[i * 3 + 1] * quant)},${Math.round(positions[i * 3 + 2] * quant)}`;
|
|
31
|
+
keys[i] = k;
|
|
32
|
+
if (!posMap.has(k)) {
|
|
33
|
+
posMap.set(k, new Vector3(0, 0, 0));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const numTris = Math.floor(indices.length / 3);
|
|
37
|
+
for (let f = 0; f < numTris; f++) {
|
|
38
|
+
const i0 = indices[f * 3];
|
|
39
|
+
const i1 = indices[f * 3 + 1];
|
|
40
|
+
const i2 = indices[f * 3 + 2];
|
|
41
|
+
const p0 = new Vector3(positions[i0 * 3], positions[i0 * 3 + 1], positions[i0 * 3 + 2]);
|
|
42
|
+
const p1 = new Vector3(positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]);
|
|
43
|
+
const p2 = new Vector3(positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]);
|
|
44
|
+
const fn = Vector3.Cross(p1.subtract(p0), p2.subtract(p0));
|
|
45
|
+
posMap.get(keys[i0]).addInPlace(fn);
|
|
46
|
+
posMap.get(keys[i1]).addInPlace(fn);
|
|
47
|
+
posMap.get(keys[i2]).addInPlace(fn);
|
|
48
|
+
}
|
|
49
|
+
for (const vec of posMap.values()) {
|
|
50
|
+
if (vec.lengthSquared() > 1e-12)
|
|
51
|
+
vec.normalize();
|
|
52
|
+
else
|
|
53
|
+
vec.set(0, 1, 0);
|
|
54
|
+
}
|
|
55
|
+
const out = new Float32Array(positions.length);
|
|
56
|
+
for (let i = 0; i < numVerts; i++) {
|
|
57
|
+
const n = posMap.get(keys[i]);
|
|
58
|
+
out[i * 3] = n.x;
|
|
59
|
+
out[i * 3 + 1] = n.y;
|
|
60
|
+
out[i * 3 + 2] = n.z;
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generates or updates a 3D wireframe Projection Cage around `lowPolyMesh` inflated by `extrusion`.
|
|
66
|
+
*/
|
|
67
|
+
updateCagePreview(lowPolyMesh, extrusion = this.cageExtrusion, visible = this.showCagePreview) {
|
|
68
|
+
this.clearCagePreview();
|
|
69
|
+
this.cageExtrusion = Math.max(0.001, Math.min(extrusion, 2.0));
|
|
70
|
+
this.showCagePreview = visible;
|
|
71
|
+
if (!visible || !lowPolyMesh || lowPolyMesh.isDisposed()) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const positions = lowPolyMesh.getVerticesData(VertexBuffer.PositionKind);
|
|
75
|
+
const indices = lowPolyMesh.getIndices();
|
|
76
|
+
if (!positions || !indices || positions.length < 9)
|
|
77
|
+
return null;
|
|
78
|
+
const smoothNormals = this.computeSmoothCageNormals(positions, indices);
|
|
79
|
+
const cagePositions = new Float32Array(positions.length);
|
|
80
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
81
|
+
cagePositions[i] = positions[i] + smoothNormals[i] * this.cageExtrusion;
|
|
82
|
+
cagePositions[i + 1] = positions[i + 1] + smoothNormals[i + 1] * this.cageExtrusion;
|
|
83
|
+
cagePositions[i + 2] = positions[i + 2] + smoothNormals[i + 2] * this.cageExtrusion;
|
|
84
|
+
}
|
|
85
|
+
const cageMesh = new Mesh('editor_bake_cage_preview', this.scene);
|
|
86
|
+
const vd = new VertexData();
|
|
87
|
+
vd.positions = cagePositions;
|
|
88
|
+
vd.indices = Array.from(indices);
|
|
89
|
+
vd.normals = smoothNormals;
|
|
90
|
+
vd.applyToMesh(cageMesh, true);
|
|
91
|
+
lowPolyMesh.computeWorldMatrix(true);
|
|
92
|
+
cageMesh.position.copyFrom(lowPolyMesh.position);
|
|
93
|
+
cageMesh.rotation.copyFrom(lowPolyMesh.rotation);
|
|
94
|
+
if (lowPolyMesh.rotationQuaternion) {
|
|
95
|
+
cageMesh.rotationQuaternion = lowPolyMesh.rotationQuaternion.clone();
|
|
96
|
+
}
|
|
97
|
+
cageMesh.scaling.copyFrom(lowPolyMesh.scaling);
|
|
98
|
+
cageMesh.parent = lowPolyMesh.parent;
|
|
99
|
+
const cageMat = new StandardMaterial('editor_bake_cage_mat', this.scene);
|
|
100
|
+
cageMat.diffuseColor = new Color3(0.22, 0.74, 0.97);
|
|
101
|
+
cageMat.emissiveColor = new Color3(0.15, 0.65, 0.95);
|
|
102
|
+
cageMat.wireframe = true;
|
|
103
|
+
cageMat.disableLighting = true;
|
|
104
|
+
cageMat.alpha = 0.65;
|
|
105
|
+
cageMesh.material = cageMat;
|
|
106
|
+
cageMesh.isPickable = false;
|
|
107
|
+
this.cagePreviewMesh = cageMesh;
|
|
108
|
+
return cageMesh;
|
|
109
|
+
}
|
|
110
|
+
clearCagePreview() {
|
|
111
|
+
if (this.cagePreviewMesh) {
|
|
112
|
+
if (this.cagePreviewMesh.material) {
|
|
113
|
+
this.cagePreviewMesh.material.dispose();
|
|
114
|
+
}
|
|
115
|
+
this.cagePreviewMesh.dispose();
|
|
116
|
+
this.cagePreviewMesh = null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Automatically calculates an optimal cage extrusion distance based on the bounding distance
|
|
121
|
+
* between the High-Poly mesh and Low-Poly mesh.
|
|
122
|
+
*/
|
|
123
|
+
computeAutoCageDistance(lowPolyMesh, highPolyMesh) {
|
|
124
|
+
lowPolyMesh.computeWorldMatrix(true);
|
|
125
|
+
lowPolyMesh.refreshBoundingInfo();
|
|
126
|
+
const lowBounds = lowPolyMesh.getBoundingInfo().boundingBox;
|
|
127
|
+
const diag = Vector3.Distance(lowBounds.minimumWorld, lowBounds.maximumWorld);
|
|
128
|
+
if (!highPolyMesh || highPolyMesh === lowPolyMesh) {
|
|
129
|
+
this.cageExtrusion = Math.max(0.01, Math.min(0.25, Math.round(diag * 0.025 * 1000) / 1000));
|
|
130
|
+
return this.cageExtrusion;
|
|
131
|
+
}
|
|
132
|
+
highPolyMesh.computeWorldMatrix(true);
|
|
133
|
+
highPolyMesh.refreshBoundingInfo();
|
|
134
|
+
const highBounds = highPolyMesh.getBoundingInfo().boundingBox;
|
|
135
|
+
const maxDiff = Math.max(Math.abs(highBounds.maximumWorld.x - lowBounds.maximumWorld.x), Math.abs(highBounds.maximumWorld.y - lowBounds.maximumWorld.y), Math.abs(highBounds.maximumWorld.z - lowBounds.maximumWorld.z), Math.abs(highBounds.minimumWorld.x - lowBounds.minimumWorld.x), Math.abs(highBounds.minimumWorld.y - lowBounds.minimumWorld.y), Math.abs(highBounds.minimumWorld.z - lowBounds.minimumWorld.z));
|
|
136
|
+
this.cageExtrusion = Math.max(0.01, Math.min(0.5, Math.round(Math.max(maxDiff * 1.35, diag * 0.025) * 1000) / 1000));
|
|
137
|
+
return this.cageExtrusion;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Executes raycast Tangent-Space Normal Map and Ambient Occlusion baking from High-Poly to Low-Poly.
|
|
141
|
+
*/
|
|
142
|
+
async bakeTextures(options) {
|
|
143
|
+
const lowPoly = options.lowPolyMesh;
|
|
144
|
+
const highPoly = options.highPolyMesh || lowPoly;
|
|
145
|
+
const res = options.resolution || this.resolution;
|
|
146
|
+
const cageDist = options.cageExtrusion ?? this.cageExtrusion;
|
|
147
|
+
const flipY = options.flipNormalY ?? this.flipNormalY;
|
|
148
|
+
const paddingPx = options.paddingPx ?? this.paddingPx;
|
|
149
|
+
const applyToMaterial = options.applyToMaterial ?? true;
|
|
150
|
+
const autoUnwrapIfOverlapping = options.autoUnwrapIfOverlapping ?? false;
|
|
151
|
+
// Ensure low-poly mesh has valid UVs
|
|
152
|
+
let lowUVs = lowPoly.getVerticesData(VertexBuffer.UVKind);
|
|
153
|
+
const lowPos = lowPoly.getVerticesData(VertexBuffer.PositionKind);
|
|
154
|
+
const lowInd = lowPoly.getIndices();
|
|
155
|
+
if (!lowPos || !lowInd || lowInd.length < 3) {
|
|
156
|
+
throw new Error(`Low-poly mesh "${lowPoly.name}" has no valid geometry to bake.`);
|
|
157
|
+
}
|
|
158
|
+
if (!lowUVs || lowUVs.length < (lowPos.length / 3) * 2) {
|
|
159
|
+
this.service.uvUnwrapController?.unwrapMesh(lowPoly);
|
|
160
|
+
lowUVs = lowPoly.getVerticesData(VertexBuffer.UVKind);
|
|
161
|
+
}
|
|
162
|
+
else if (autoUnwrapIfOverlapping && this.service.uvUnwrapController) {
|
|
163
|
+
const stats = this.service.uvUnwrapController.analyzeUVs(lowPoly);
|
|
164
|
+
if (stats.overlapDetected) {
|
|
165
|
+
this.service.uvUnwrapController.unwrapMesh(lowPoly);
|
|
166
|
+
lowUVs = lowPoly.getVerticesData(VertexBuffer.UVKind);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const finalLowPos = lowPoly.getVerticesData(VertexBuffer.PositionKind);
|
|
170
|
+
const finalLowInd = lowPoly.getIndices();
|
|
171
|
+
const finalLowUVs = lowPoly.getVerticesData(VertexBuffer.UVKind);
|
|
172
|
+
let finalLowNorms = lowPoly.getVerticesData(VertexBuffer.NormalKind);
|
|
173
|
+
if (!finalLowNorms || finalLowNorms.length !== finalLowPos.length) {
|
|
174
|
+
const comp = [];
|
|
175
|
+
VertexData.ComputeNormals(finalLowPos, finalLowInd, comp);
|
|
176
|
+
finalLowNorms = comp;
|
|
177
|
+
}
|
|
178
|
+
const cageSmoothNormals = this.computeSmoothCageNormals(finalLowPos, finalLowInd);
|
|
179
|
+
lowPoly.computeWorldMatrix(true);
|
|
180
|
+
highPoly.computeWorldMatrix(true);
|
|
181
|
+
const lowWorldMat = lowPoly.getWorldMatrix();
|
|
182
|
+
const highWorldMat = highPoly.getWorldMatrix();
|
|
183
|
+
// Prepare High-Poly world triangles with smooth normals for raycast projection
|
|
184
|
+
const highTris = this.extractHighPolyTriangles(highPoly, highWorldMat);
|
|
185
|
+
const pixelCount = res * res;
|
|
186
|
+
const normalBuffer = new Uint8Array(pixelCount * 4);
|
|
187
|
+
const aoBuffer = new Uint8Array(pixelCount * 4);
|
|
188
|
+
const coverageMask = new Uint8Array(pixelCount);
|
|
189
|
+
// Initialize default flat tangent-space normal [128, 128, 255, 255] and white AO [245, 245, 245, 255]
|
|
190
|
+
for (let i = 0; i < pixelCount; i++) {
|
|
191
|
+
normalBuffer[i * 4] = 128;
|
|
192
|
+
normalBuffer[i * 4 + 1] = 128;
|
|
193
|
+
normalBuffer[i * 4 + 2] = 255;
|
|
194
|
+
normalBuffer[i * 4 + 3] = 255;
|
|
195
|
+
aoBuffer[i * 4] = 242;
|
|
196
|
+
aoBuffer[i * 4 + 1] = 242;
|
|
197
|
+
aoBuffer[i * 4 + 2] = 242;
|
|
198
|
+
aoBuffer[i * 4 + 3] = 255;
|
|
199
|
+
}
|
|
200
|
+
let rayHitCount = 0;
|
|
201
|
+
let coveredTexelCount = 0;
|
|
202
|
+
const numLowTris = Math.floor(finalLowInd.length / 3);
|
|
203
|
+
const maxRayDist = Math.max(cageDist * 3.5, 0.25);
|
|
204
|
+
// For Self-Bake mode: precompute face normals and crease flags so internal coplanar edges (e.g. quad diagonals) are not beveled
|
|
205
|
+
const triEdgeCrease = new Uint8Array(numLowTris * 3);
|
|
206
|
+
if (highPoly === lowPoly || highTris.length === 0) {
|
|
207
|
+
const quant = 10000;
|
|
208
|
+
const getCanonKey = (idx) => `${Math.round(finalLowPos[idx * 3] * quant)},${Math.round(finalLowPos[idx * 3 + 1] * quant)},${Math.round(finalLowPos[idx * 3 + 2] * quant)}`;
|
|
209
|
+
const faceNormals = new Array(numLowTris);
|
|
210
|
+
for (let f = 0; f < numLowTris; f++) {
|
|
211
|
+
const i0 = finalLowInd[f * 3];
|
|
212
|
+
const i1 = finalLowInd[f * 3 + 1];
|
|
213
|
+
const i2 = finalLowInd[f * 3 + 2];
|
|
214
|
+
const p0 = new Vector3(finalLowPos[i0 * 3], finalLowPos[i0 * 3 + 1], finalLowPos[i0 * 3 + 2]);
|
|
215
|
+
const p1 = new Vector3(finalLowPos[i1 * 3], finalLowPos[i1 * 3 + 1], finalLowPos[i1 * 3 + 2]);
|
|
216
|
+
const p2 = new Vector3(finalLowPos[i2 * 3], finalLowPos[i2 * 3 + 1], finalLowPos[i2 * 3 + 2]);
|
|
217
|
+
const fn = Vector3.Cross(p1.subtract(p0), p2.subtract(p0));
|
|
218
|
+
if (fn.lengthSquared() > 1e-12)
|
|
219
|
+
fn.normalize();
|
|
220
|
+
else
|
|
221
|
+
fn.set(0, 1, 0);
|
|
222
|
+
faceNormals[f] = fn;
|
|
223
|
+
}
|
|
224
|
+
const edgeMap = new Map();
|
|
225
|
+
for (let f = 0; f < numLowTris; f++) {
|
|
226
|
+
const k0 = getCanonKey(finalLowInd[f * 3]);
|
|
227
|
+
const k1 = getCanonKey(finalLowInd[f * 3 + 1]);
|
|
228
|
+
const k2 = getCanonKey(finalLowInd[f * 3 + 2]);
|
|
229
|
+
const edges = [
|
|
230
|
+
k0 < k1 ? `${k0}_${k1}` : `${k1}_${k0}`,
|
|
231
|
+
k1 < k2 ? `${k1}_${k2}` : `${k2}_${k1}`,
|
|
232
|
+
k2 < k0 ? `${k2}_${k0}` : `${k0}_${k2}`,
|
|
233
|
+
];
|
|
234
|
+
for (let e = 0; e < 3; e++) {
|
|
235
|
+
const ek = edges[e];
|
|
236
|
+
let list = edgeMap.get(ek);
|
|
237
|
+
if (!list) {
|
|
238
|
+
list = [];
|
|
239
|
+
edgeMap.set(ek, list);
|
|
240
|
+
}
|
|
241
|
+
list.push({ tri: f, edge: e });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
for (let f = 0; f < numLowTris; f++) {
|
|
245
|
+
const k0 = getCanonKey(finalLowInd[f * 3]);
|
|
246
|
+
const k1 = getCanonKey(finalLowInd[f * 3 + 1]);
|
|
247
|
+
const k2 = getCanonKey(finalLowInd[f * 3 + 2]);
|
|
248
|
+
const edges = [
|
|
249
|
+
k0 < k1 ? `${k0}_${k1}` : `${k1}_${k0}`,
|
|
250
|
+
k1 < k2 ? `${k1}_${k2}` : `${k2}_${k1}`,
|
|
251
|
+
k2 < k0 ? `${k2}_${k0}` : `${k0}_${k2}`,
|
|
252
|
+
];
|
|
253
|
+
for (let e = 0; e < 3; e++) {
|
|
254
|
+
const sharing = edgeMap.get(edges[e]);
|
|
255
|
+
let isCoplanar = false;
|
|
256
|
+
if (sharing && sharing.length > 1) {
|
|
257
|
+
for (const other of sharing) {
|
|
258
|
+
if (other.tri !== f) {
|
|
259
|
+
const dot = Vector3.Dot(faceNormals[f], faceNormals[other.tri]);
|
|
260
|
+
if (dot > 0.85) {
|
|
261
|
+
isCoplanar = true;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
triEdgeCrease[f * 3 + e] = isCoplanar ? 0 : 1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (let f = 0; f < numLowTris; f++) {
|
|
272
|
+
const i0 = finalLowInd[f * 3];
|
|
273
|
+
const i1 = finalLowInd[f * 3 + 1];
|
|
274
|
+
const i2 = finalLowInd[f * 3 + 2];
|
|
275
|
+
const u0 = finalLowUVs[i0 * 2];
|
|
276
|
+
const v0 = finalLowUVs[i0 * 2 + 1];
|
|
277
|
+
const u1 = finalLowUVs[i1 * 2];
|
|
278
|
+
const v1 = finalLowUVs[i1 * 2 + 1];
|
|
279
|
+
const u2 = finalLowUVs[i2 * 2];
|
|
280
|
+
const v2 = finalLowUVs[i2 * 2 + 1];
|
|
281
|
+
const wp0 = Vector3.TransformCoordinates(new Vector3(finalLowPos[i0 * 3], finalLowPos[i0 * 3 + 1], finalLowPos[i0 * 3 + 2]), lowWorldMat);
|
|
282
|
+
const wp1 = Vector3.TransformCoordinates(new Vector3(finalLowPos[i1 * 3], finalLowPos[i1 * 3 + 1], finalLowPos[i1 * 3 + 2]), lowWorldMat);
|
|
283
|
+
const wp2 = Vector3.TransformCoordinates(new Vector3(finalLowPos[i2 * 3], finalLowPos[i2 * 3 + 1], finalLowPos[i2 * 3 + 2]), lowWorldMat);
|
|
284
|
+
const wn0 = Vector3.TransformNormal(new Vector3(finalLowNorms[i0 * 3], finalLowNorms[i0 * 3 + 1], finalLowNorms[i0 * 3 + 2]), lowWorldMat).normalize();
|
|
285
|
+
const wn1 = Vector3.TransformNormal(new Vector3(finalLowNorms[i1 * 3], finalLowNorms[i1 * 3 + 1], finalLowNorms[i1 * 3 + 2]), lowWorldMat).normalize();
|
|
286
|
+
const wn2 = Vector3.TransformNormal(new Vector3(finalLowNorms[i2 * 3], finalLowNorms[i2 * 3 + 1], finalLowNorms[i2 * 3 + 2]), lowWorldMat).normalize();
|
|
287
|
+
const cn0 = Vector3.TransformNormal(new Vector3(cageSmoothNormals[i0 * 3], cageSmoothNormals[i0 * 3 + 1], cageSmoothNormals[i0 * 3 + 2]), lowWorldMat).normalize();
|
|
288
|
+
const cn1 = Vector3.TransformNormal(new Vector3(cageSmoothNormals[i1 * 3], cageSmoothNormals[i1 * 3 + 1], cageSmoothNormals[i1 * 3 + 2]), lowWorldMat).normalize();
|
|
289
|
+
const cn2 = Vector3.TransformNormal(new Vector3(cageSmoothNormals[i2 * 3], cageSmoothNormals[i2 * 3 + 1], cageSmoothNormals[i2 * 3 + 2]), lowWorldMat).normalize();
|
|
290
|
+
// Compute triangle tangent basis (T, B) from UV derivatives
|
|
291
|
+
const edge1 = wp1.subtract(wp0);
|
|
292
|
+
const edge2 = wp2.subtract(wp0);
|
|
293
|
+
const du1 = u1 - u0;
|
|
294
|
+
const dv1 = v1 - v0;
|
|
295
|
+
const du2 = u2 - u0;
|
|
296
|
+
const dv2 = v2 - v0;
|
|
297
|
+
const det = du1 * dv2 - du2 * dv1;
|
|
298
|
+
let tangent;
|
|
299
|
+
let bitangent;
|
|
300
|
+
if (Math.abs(det) > 1e-8) {
|
|
301
|
+
const invDet = 1.0 / det;
|
|
302
|
+
tangent = edge1.scale(dv2 * invDet).subtract(edge2.scale(dv1 * invDet)).normalize();
|
|
303
|
+
bitangent = edge2.scale(du1 * invDet).subtract(edge1.scale(du2 * invDet)).normalize();
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
const up = Math.abs(wn0.y) < 0.9 ? Vector3.Up() : Vector3.Right();
|
|
307
|
+
tangent = Vector3.Cross(up, wn0).normalize();
|
|
308
|
+
bitangent = Vector3.Cross(wn0, tangent).normalize();
|
|
309
|
+
}
|
|
310
|
+
// Bounding box in pixel coordinates [0, res - 1]
|
|
311
|
+
const x0 = u0 * res;
|
|
312
|
+
const y0 = (1 - v0) * res;
|
|
313
|
+
const x1 = u1 * res;
|
|
314
|
+
const y1 = (1 - v1) * res;
|
|
315
|
+
const x2 = u2 * res;
|
|
316
|
+
const y2 = (1 - v2) * res;
|
|
317
|
+
const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
|
|
318
|
+
const maxX = Math.min(res - 1, Math.ceil(Math.max(x0, x1, x2)));
|
|
319
|
+
const minY = Math.max(0, Math.floor(Math.min(y0, y1, y2)));
|
|
320
|
+
const maxY = Math.min(res - 1, Math.ceil(Math.max(y0, y1, y2)));
|
|
321
|
+
const denom = (y1 - y2) * (x0 - x2) + (x2 - x1) * (y0 - y2);
|
|
322
|
+
if (Math.abs(denom) < 1e-8)
|
|
323
|
+
continue;
|
|
324
|
+
const invDenom = 1.0 / denom;
|
|
325
|
+
for (let py = minY; py <= maxY; py++) {
|
|
326
|
+
for (let px = minX; px <= maxX; px++) {
|
|
327
|
+
const sx = px + 0.5;
|
|
328
|
+
const sy = py + 0.5;
|
|
329
|
+
const w0 = ((y1 - y2) * (sx - x2) + (x2 - x1) * (sy - y2)) * invDenom;
|
|
330
|
+
const w1 = ((y2 - y0) * (sx - x2) + (x0 - x2) * (sy - y2)) * invDenom;
|
|
331
|
+
const w2 = 1.0 - w0 - w1;
|
|
332
|
+
if (w0 < -0.02 || w1 < -0.02 || w2 < -0.02)
|
|
333
|
+
continue;
|
|
334
|
+
const cw0 = Math.max(0, w0);
|
|
335
|
+
const cw1 = Math.max(0, w1);
|
|
336
|
+
const cw2 = Math.max(0, w2);
|
|
337
|
+
const wSum = cw0 + cw1 + cw2 || 1;
|
|
338
|
+
const b0 = cw0 / wSum;
|
|
339
|
+
const b1 = cw1 / wSum;
|
|
340
|
+
const b2 = cw2 / wSum;
|
|
341
|
+
const pIdx = py * res + px;
|
|
342
|
+
if (coverageMask[pIdx] === 0) {
|
|
343
|
+
coverageMask[pIdx] = 1;
|
|
344
|
+
coveredTexelCount++;
|
|
345
|
+
}
|
|
346
|
+
// Interpolated Low-Poly position, surface normal, and cage ray origin
|
|
347
|
+
const lowPoint = new Vector3(wp0.x * b0 + wp1.x * b1 + wp2.x * b2, wp0.y * b0 + wp1.y * b1 + wp2.y * b2, wp0.z * b0 + wp1.z * b1 + wp2.z * b2);
|
|
348
|
+
const lowNormal = new Vector3(wn0.x * b0 + wn1.x * b1 + wn2.x * b2, wn0.y * b0 + wn1.y * b1 + wn2.y * b2, wn0.z * b0 + wn1.z * b1 + wn2.z * b2).normalize();
|
|
349
|
+
const cageNormal = new Vector3(cn0.x * b0 + cn1.x * b1 + cn2.x * b2, cn0.y * b0 + cn1.y * b1 + cn2.y * b2, cn0.z * b0 + cn1.z * b1 + cn2.z * b2).normalize();
|
|
350
|
+
const rayOrigin = lowPoint.add(cageNormal.scale(cageDist));
|
|
351
|
+
const rayDir = cageNormal.scale(-1);
|
|
352
|
+
// Sample High-Poly normal & cavity depth via raycast from Cage inward
|
|
353
|
+
let sampledNormal = cageNormal;
|
|
354
|
+
let hitDepthRatio = 0.0;
|
|
355
|
+
if (highPoly !== lowPoly && highTris.length > 0) {
|
|
356
|
+
const hit = this.raycastHighPoly(rayOrigin, rayDir, maxRayDist, highTris);
|
|
357
|
+
if (hit) {
|
|
358
|
+
sampledNormal = hit.normal;
|
|
359
|
+
hitDepthRatio = Math.abs(hit.distance - cageDist) / Math.max(0.001, cageDist);
|
|
360
|
+
rayHitCount++;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
// Self-baking: blend smooth cage normal with bevel edge relief near sharp/boundary edges only
|
|
365
|
+
// Edge 0 (i0->i1) is opposite vertex 2 (b2 -> 0)
|
|
366
|
+
// Edge 1 (i1->i2) is opposite vertex 0 (b0 -> 0)
|
|
367
|
+
// Edge 2 (i2->i0) is opposite vertex 1 (b1 -> 0)
|
|
368
|
+
const isCrease0 = triEdgeCrease[f * 3] === 1;
|
|
369
|
+
const isCrease1 = triEdgeCrease[f * 3 + 1] === 1;
|
|
370
|
+
const isCrease2 = triEdgeCrease[f * 3 + 2] === 1;
|
|
371
|
+
const dist0 = isCrease1 ? b0 : 1.0;
|
|
372
|
+
const dist1 = isCrease2 ? b1 : 1.0;
|
|
373
|
+
const dist2 = isCrease0 ? b2 : 1.0;
|
|
374
|
+
const edgeMinBary = Math.min(dist0, dist1, dist2) * 3.0;
|
|
375
|
+
const bevelBlend = Math.min(1.0, edgeMinBary * 2.2);
|
|
376
|
+
sampledNormal = Vector3.Lerp(cageNormal, lowNormal, bevelBlend).normalize();
|
|
377
|
+
hitDepthRatio = (1.0 - bevelBlend) * 0.35;
|
|
378
|
+
rayHitCount++;
|
|
379
|
+
}
|
|
380
|
+
// Orthonormalize TBN at this texel
|
|
381
|
+
const N = lowNormal;
|
|
382
|
+
const T = tangent.subtract(N.scale(Vector3.Dot(tangent, N))).normalize();
|
|
383
|
+
const B = bitangent.subtract(N.scale(Vector3.Dot(bitangent, N))).normalize();
|
|
384
|
+
const tsX = Vector3.Dot(sampledNormal, T);
|
|
385
|
+
const tsY = Vector3.Dot(sampledNormal, B) * (flipY ? -1 : 1);
|
|
386
|
+
const tsZ = Math.max(0.05, Vector3.Dot(sampledNormal, N));
|
|
387
|
+
const tsLen = Math.sqrt(tsX * tsX + tsY * tsY + tsZ * tsZ) || 1;
|
|
388
|
+
const rNorm = Math.round(((tsX / tsLen) * 0.5 + 0.5) * 255);
|
|
389
|
+
const gNorm = Math.round(((tsY / tsLen) * 0.5 + 0.5) * 255);
|
|
390
|
+
const bNorm = Math.round(((tsZ / tsLen) * 0.5 + 0.5) * 255);
|
|
391
|
+
normalBuffer[pIdx * 4] = Math.max(0, Math.min(255, rNorm));
|
|
392
|
+
normalBuffer[pIdx * 4 + 1] = Math.max(0, Math.min(255, gNorm));
|
|
393
|
+
normalBuffer[pIdx * 4 + 2] = Math.max(0, Math.min(255, bNorm));
|
|
394
|
+
normalBuffer[pIdx * 4 + 3] = 255;
|
|
395
|
+
// Compute Ambient Occlusion (cavity + normal alignment occlusion)
|
|
396
|
+
const normalAlignment = Math.max(0, Vector3.Dot(sampledNormal, cageNormal));
|
|
397
|
+
const aoFactor = Math.max(0.18, Math.min(1.0, (0.55 + 0.45 * normalAlignment) * (1.0 - Math.min(0.45, hitDepthRatio * 0.4))));
|
|
398
|
+
const aoByte = Math.round(aoFactor * 255);
|
|
399
|
+
aoBuffer[pIdx * 4] = aoByte;
|
|
400
|
+
aoBuffer[pIdx * 4 + 1] = aoByte;
|
|
401
|
+
aoBuffer[pIdx * 4 + 2] = aoByte;
|
|
402
|
+
aoBuffer[pIdx * 4 + 3] = 255;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
// Apply UV island border dilation (padding) so mipmaps never bleed along seams
|
|
407
|
+
if (paddingPx > 0) {
|
|
408
|
+
this.dilateBuffers(normalBuffer, aoBuffer, coverageMask, res, paddingPx);
|
|
409
|
+
}
|
|
410
|
+
const normalMapDataUrl = this.rgbaBufferToDataURL(normalBuffer, res, res);
|
|
411
|
+
const aoMapDataUrl = this.rgbaBufferToDataURL(aoBuffer, res, res);
|
|
412
|
+
if (applyToMaterial) {
|
|
413
|
+
this.applyBakedTexturesToMesh(lowPoly, normalBuffer, aoBuffer, res);
|
|
414
|
+
}
|
|
415
|
+
const coveragePercent = Math.round((coveredTexelCount / pixelCount) * 1000) / 10;
|
|
416
|
+
const result = {
|
|
417
|
+
lowPolyMeshName: lowPoly.name,
|
|
418
|
+
highPolyMeshName: highPoly.name,
|
|
419
|
+
resolution: res,
|
|
420
|
+
cageExtrusion: cageDist,
|
|
421
|
+
rayHitCount,
|
|
422
|
+
coveragePercent,
|
|
423
|
+
normalMapBuffer: normalBuffer,
|
|
424
|
+
aoMapBuffer: aoBuffer,
|
|
425
|
+
normalMapDataUrl,
|
|
426
|
+
aoMapDataUrl,
|
|
427
|
+
appliedToMaterial: applyToMaterial,
|
|
428
|
+
};
|
|
429
|
+
this.lastBakeResult = result;
|
|
430
|
+
return result;
|
|
431
|
+
}
|
|
432
|
+
extractHighPolyTriangles(highPoly, worldMat) {
|
|
433
|
+
const pos = highPoly.getVerticesData(VertexBuffer.PositionKind);
|
|
434
|
+
const ind = highPoly.getIndices();
|
|
435
|
+
if (!pos || !ind || ind.length < 3)
|
|
436
|
+
return [];
|
|
437
|
+
const smoothNorms = this.computeSmoothCageNormals(pos, ind);
|
|
438
|
+
const numTris = Math.floor(ind.length / 3);
|
|
439
|
+
// Cap triangle step if ultra dense so baking completes in <200ms in JS
|
|
440
|
+
const step = Math.max(1, Math.floor(numTris / 4000));
|
|
441
|
+
const tris = [];
|
|
442
|
+
for (let f = 0; f < numTris; f += step) {
|
|
443
|
+
const i0 = ind[f * 3];
|
|
444
|
+
const i1 = ind[f * 3 + 1];
|
|
445
|
+
const i2 = ind[f * 3 + 2];
|
|
446
|
+
const p0 = Vector3.TransformCoordinates(new Vector3(pos[i0 * 3], pos[i0 * 3 + 1], pos[i0 * 3 + 2]), worldMat);
|
|
447
|
+
const p1 = Vector3.TransformCoordinates(new Vector3(pos[i1 * 3], pos[i1 * 3 + 1], pos[i1 * 3 + 2]), worldMat);
|
|
448
|
+
const p2 = Vector3.TransformCoordinates(new Vector3(pos[i2 * 3], pos[i2 * 3 + 1], pos[i2 * 3 + 2]), worldMat);
|
|
449
|
+
const n0 = Vector3.TransformNormal(new Vector3(smoothNorms[i0 * 3], smoothNorms[i0 * 3 + 1], smoothNorms[i0 * 3 + 2]), worldMat).normalize();
|
|
450
|
+
const n1 = Vector3.TransformNormal(new Vector3(smoothNorms[i1 * 3], smoothNorms[i1 * 3 + 1], smoothNorms[i1 * 3 + 2]), worldMat).normalize();
|
|
451
|
+
const n2 = Vector3.TransformNormal(new Vector3(smoothNorms[i2 * 3], smoothNorms[i2 * 3 + 1], smoothNorms[i2 * 3 + 2]), worldMat).normalize();
|
|
452
|
+
const faceNormal = Vector3.Cross(p1.subtract(p0), p2.subtract(p0)).normalize();
|
|
453
|
+
tris.push({
|
|
454
|
+
p0,
|
|
455
|
+
p1,
|
|
456
|
+
p2,
|
|
457
|
+
n0,
|
|
458
|
+
n1,
|
|
459
|
+
n2,
|
|
460
|
+
faceNormal,
|
|
461
|
+
minX: Math.min(p0.x, p1.x, p2.x),
|
|
462
|
+
maxX: Math.max(p0.x, p1.x, p2.x),
|
|
463
|
+
minY: Math.min(p0.y, p1.y, p2.y),
|
|
464
|
+
maxY: Math.max(p0.y, p1.y, p2.y),
|
|
465
|
+
minZ: Math.min(p0.z, p1.z, p2.z),
|
|
466
|
+
maxZ: Math.max(p0.z, p1.z, p2.z),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return tris;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Möller–Trumbore ray-triangle intersection with barycentric smooth normal interpolation.
|
|
473
|
+
*/
|
|
474
|
+
raycastHighPoly(origin, dir, maxDist, tris) {
|
|
475
|
+
let bestT = maxDist;
|
|
476
|
+
let bestNormal = null;
|
|
477
|
+
const rMinX = Math.min(origin.x, origin.x + dir.x * maxDist) - 0.05;
|
|
478
|
+
const rMaxX = Math.max(origin.x, origin.x + dir.x * maxDist) + 0.05;
|
|
479
|
+
const rMinY = Math.min(origin.y, origin.y + dir.y * maxDist) - 0.05;
|
|
480
|
+
const rMaxY = Math.max(origin.y, origin.y + dir.y * maxDist) + 0.05;
|
|
481
|
+
const rMinZ = Math.min(origin.z, origin.z + dir.z * maxDist) - 0.05;
|
|
482
|
+
const rMaxZ = Math.max(origin.z, origin.z + dir.z * maxDist) + 0.05;
|
|
483
|
+
for (let i = 0; i < tris.length; i++) {
|
|
484
|
+
const t = tris[i];
|
|
485
|
+
if (t.maxX < rMinX ||
|
|
486
|
+
t.minX > rMaxX ||
|
|
487
|
+
t.maxY < rMinY ||
|
|
488
|
+
t.minY > rMaxY ||
|
|
489
|
+
t.maxZ < rMinZ ||
|
|
490
|
+
t.minZ > rMaxZ) {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const e1x = t.p1.x - t.p0.x;
|
|
494
|
+
const e1y = t.p1.y - t.p0.y;
|
|
495
|
+
const e1z = t.p1.z - t.p0.z;
|
|
496
|
+
const e2x = t.p2.x - t.p0.x;
|
|
497
|
+
const e2y = t.p2.y - t.p0.y;
|
|
498
|
+
const e2z = t.p2.z - t.p0.z;
|
|
499
|
+
const hx = dir.y * e2z - dir.z * e2y;
|
|
500
|
+
const hy = dir.z * e2x - dir.x * e2z;
|
|
501
|
+
const hz = dir.x * e2y - dir.y * e2x;
|
|
502
|
+
const a = e1x * hx + e1y * hy + e1z * hz;
|
|
503
|
+
if (a > -1e-7 && a < 1e-7)
|
|
504
|
+
continue;
|
|
505
|
+
const f = 1.0 / a;
|
|
506
|
+
const sx = origin.x - t.p0.x;
|
|
507
|
+
const sy = origin.y - t.p0.y;
|
|
508
|
+
const sz = origin.z - t.p0.z;
|
|
509
|
+
const u = f * (sx * hx + sy * hy + sz * hz);
|
|
510
|
+
if (u < 0.0 || u > 1.0)
|
|
511
|
+
continue;
|
|
512
|
+
const qx = sy * e1z - sz * e1y;
|
|
513
|
+
const qy = sz * e1x - sx * e1z;
|
|
514
|
+
const qz = sx * e1y - sy * e1x;
|
|
515
|
+
const v = f * (dir.x * qx + dir.y * qy + dir.z * qz);
|
|
516
|
+
if (v < 0.0 || u + v > 1.0)
|
|
517
|
+
continue;
|
|
518
|
+
const dist = f * (e2x * qx + e2y * qy + e2z * qz);
|
|
519
|
+
if (dist >= 0 && dist < bestT) {
|
|
520
|
+
bestT = dist;
|
|
521
|
+
const w = 1.0 - u - v;
|
|
522
|
+
bestNormal = new Vector3(t.n0.x * w + t.n1.x * u + t.n2.x * v, t.n0.y * w + t.n1.y * u + t.n2.y * v, t.n0.z * w + t.n1.z * u + t.n2.z * v).normalize();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (!bestNormal)
|
|
526
|
+
return null;
|
|
527
|
+
return { distance: bestT, normal: bestNormal };
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Dilates baked pixels outward by `passes` pixels to eliminate UV seam mipmap bleeding.
|
|
531
|
+
*/
|
|
532
|
+
dilateBuffers(normalBuf, aoBuf, mask, res, passes) {
|
|
533
|
+
const nextMask = new Uint8Array(mask.length);
|
|
534
|
+
const offsets = [
|
|
535
|
+
[-1, 0],
|
|
536
|
+
[1, 0],
|
|
537
|
+
[0, -1],
|
|
538
|
+
[0, 1],
|
|
539
|
+
];
|
|
540
|
+
for (let p = 0; p < passes; p++) {
|
|
541
|
+
nextMask.set(mask);
|
|
542
|
+
for (let y = 0; y < res; y++) {
|
|
543
|
+
for (let x = 0; x < res; x++) {
|
|
544
|
+
const idx = y * res + x;
|
|
545
|
+
if (mask[idx] !== 0)
|
|
546
|
+
continue;
|
|
547
|
+
let rN = 0, gN = 0, bN = 0, aoSum = 0, count = 0;
|
|
548
|
+
for (const [dx, dy] of offsets) {
|
|
549
|
+
const nx = x + dx;
|
|
550
|
+
const ny = y + dy;
|
|
551
|
+
if (nx >= 0 && nx < res && ny >= 0 && ny < res) {
|
|
552
|
+
const nIdx = ny * res + nx;
|
|
553
|
+
if (mask[nIdx] !== 0) {
|
|
554
|
+
rN += normalBuf[nIdx * 4];
|
|
555
|
+
gN += normalBuf[nIdx * 4 + 1];
|
|
556
|
+
bN += normalBuf[nIdx * 4 + 2];
|
|
557
|
+
aoSum += aoBuf[nIdx * 4];
|
|
558
|
+
count++;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (count > 0) {
|
|
563
|
+
normalBuf[idx * 4] = Math.round(rN / count);
|
|
564
|
+
normalBuf[idx * 4 + 1] = Math.round(gN / count);
|
|
565
|
+
normalBuf[idx * 4 + 2] = Math.round(bN / count);
|
|
566
|
+
const aoVal = Math.round(aoSum / count);
|
|
567
|
+
aoBuf[idx * 4] = aoVal;
|
|
568
|
+
aoBuf[idx * 4 + 1] = aoVal;
|
|
569
|
+
aoBuf[idx * 4 + 2] = aoVal;
|
|
570
|
+
nextMask[idx] = 1;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
mask.set(nextMask);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Applies the baked Normal Map and Ambient Occlusion Map directly onto the Low-Poly mesh's material.
|
|
579
|
+
*/
|
|
580
|
+
applyBakedTexturesToMesh(mesh, normalBuffer, aoBuffer, res) {
|
|
581
|
+
const normalTex = RawTexture.CreateRGBATexture(normalBuffer, res, res, this.scene, false, false, Texture.TRILINEAR_SAMPLINGMODE);
|
|
582
|
+
normalTex.name = `${mesh.name}_BakedNormalMap`;
|
|
583
|
+
const aoTex = RawTexture.CreateRGBATexture(aoBuffer, res, res, this.scene, false, false, Texture.TRILINEAR_SAMPLINGMODE);
|
|
584
|
+
aoTex.name = `${mesh.name}_BakedAOMap`;
|
|
585
|
+
let mat = mesh.material;
|
|
586
|
+
if (!mat || (!(mat instanceof PBRMaterial) && !(mat instanceof StandardMaterial))) {
|
|
587
|
+
const pbr = new PBRMaterial(`${mesh.name}_BakedPBR`, this.scene);
|
|
588
|
+
pbr.albedoColor = new Color3(0.78, 0.8, 0.84);
|
|
589
|
+
pbr.metallic = 0.1;
|
|
590
|
+
pbr.roughness = 0.55;
|
|
591
|
+
mesh.material = pbr;
|
|
592
|
+
mat = pbr;
|
|
593
|
+
}
|
|
594
|
+
if (mat instanceof PBRMaterial) {
|
|
595
|
+
mat.bumpTexture = normalTex;
|
|
596
|
+
mat.ambientTexture = aoTex;
|
|
597
|
+
mat.ambientTextureStrength = 0.85;
|
|
598
|
+
}
|
|
599
|
+
else if (mat instanceof StandardMaterial) {
|
|
600
|
+
mat.bumpTexture = normalTex;
|
|
601
|
+
mat.ambientTexture = aoTex;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Renders either the baked Normal Map or AO Map into a 2D preview <canvas>.
|
|
606
|
+
*/
|
|
607
|
+
renderBakePreviewToCanvas(canvas, channel = 'normal') {
|
|
608
|
+
const ctx = canvas.getContext('2d');
|
|
609
|
+
if (!ctx)
|
|
610
|
+
return;
|
|
611
|
+
const w = canvas.width;
|
|
612
|
+
const h = canvas.height;
|
|
613
|
+
ctx.clearRect(0, 0, w, h);
|
|
614
|
+
if (!this.lastBakeResult) {
|
|
615
|
+
ctx.fillStyle = '#0d1117';
|
|
616
|
+
ctx.fillRect(0, 0, w, h);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const res = this.lastBakeResult.resolution;
|
|
620
|
+
const src = channel === 'normal'
|
|
621
|
+
? this.lastBakeResult.normalMapBuffer
|
|
622
|
+
: this.lastBakeResult.aoMapBuffer;
|
|
623
|
+
if (typeof ImageData !== 'undefined') {
|
|
624
|
+
try {
|
|
625
|
+
const clamped = new Uint8ClampedArray(src);
|
|
626
|
+
const imgData = new ImageData(clamped, res, res);
|
|
627
|
+
const offscreen = document.createElement('canvas');
|
|
628
|
+
offscreen.width = res;
|
|
629
|
+
offscreen.height = res;
|
|
630
|
+
const offCtx = offscreen.getContext('2d');
|
|
631
|
+
if (offCtx) {
|
|
632
|
+
offCtx.putImageData(imgData, 0, 0);
|
|
633
|
+
ctx.drawImage(offscreen, 0, 0, w, h);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
// Fallback below for headless jsdom
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
ctx.fillStyle = channel === 'normal' ? '#8080ff' : '#e5e7eb';
|
|
642
|
+
ctx.fillRect(0, 0, w, h);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Converts an RGBA Uint8Array buffer into a valid image DataURL (with BMP fallback in headless jsdom).
|
|
646
|
+
*/
|
|
647
|
+
rgbaBufferToDataURL(buffer, width, height) {
|
|
648
|
+
if (typeof document !== 'undefined') {
|
|
649
|
+
try {
|
|
650
|
+
const canvas = document.createElement('canvas');
|
|
651
|
+
canvas.width = width;
|
|
652
|
+
canvas.height = height;
|
|
653
|
+
const ctx = canvas.getContext('2d');
|
|
654
|
+
if (ctx && typeof ImageData !== 'undefined') {
|
|
655
|
+
const clamped = new Uint8ClampedArray(buffer);
|
|
656
|
+
ctx.putImageData(new ImageData(clamped, width, height), 0, 0);
|
|
657
|
+
const url = canvas.toDataURL('image/png');
|
|
658
|
+
if (url && url.startsWith('data:image/')) {
|
|
659
|
+
return url;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
catch {
|
|
664
|
+
// Fallback to lightweight 24-bit BMP base64 encoding for headless test environments
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
// Minimal valid 24-bit BMP header + pixel data encoded as base64
|
|
668
|
+
const rowSize = Math.floor((24 * width + 31) / 32) * 4;
|
|
669
|
+
const pixelArraySize = rowSize * height;
|
|
670
|
+
const fileSize = 54 + pixelArraySize;
|
|
671
|
+
const bmp = new Uint8Array(fileSize);
|
|
672
|
+
const view = new DataView(bmp.buffer);
|
|
673
|
+
bmp[0] = 0x42; // 'B'
|
|
674
|
+
bmp[1] = 0x4d; // 'M'
|
|
675
|
+
view.setUint32(2, fileSize, true);
|
|
676
|
+
view.setUint32(10, 54, true);
|
|
677
|
+
view.setUint32(14, 40, true);
|
|
678
|
+
view.setInt32(18, width, true);
|
|
679
|
+
view.setInt32(22, -height, true); // top-down
|
|
680
|
+
view.setUint16(26, 1, true);
|
|
681
|
+
view.setUint16(28, 24, true);
|
|
682
|
+
view.setUint32(34, pixelArraySize, true);
|
|
683
|
+
for (let y = 0; y < height; y++) {
|
|
684
|
+
const rowOffset = 54 + y * rowSize;
|
|
685
|
+
for (let x = 0; x < width; x++) {
|
|
686
|
+
const srcIdx = (y * width + x) * 4;
|
|
687
|
+
const dstIdx = rowOffset + x * 3;
|
|
688
|
+
bmp[dstIdx] = buffer[srcIdx + 2]; // B
|
|
689
|
+
bmp[dstIdx + 1] = buffer[srcIdx + 1]; // G
|
|
690
|
+
bmp[dstIdx + 2] = buffer[srcIdx]; // R
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
let binary = '';
|
|
694
|
+
const chunk = 8192;
|
|
695
|
+
for (let i = 0; i < bmp.length; i += chunk) {
|
|
696
|
+
binary += String.fromCharCode(...bmp.subarray(i, i + chunk));
|
|
697
|
+
}
|
|
698
|
+
const nodeBuffer = globalThis.Buffer;
|
|
699
|
+
const b64 = typeof btoa === 'function'
|
|
700
|
+
? btoa(binary)
|
|
701
|
+
: nodeBuffer
|
|
702
|
+
? nodeBuffer.from(bmp).toString('base64')
|
|
703
|
+
: '';
|
|
704
|
+
return `data:image/bmp;base64,${b64}`;
|
|
705
|
+
}
|
|
706
|
+
dispose() {
|
|
707
|
+
this.clearCagePreview();
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
//# sourceMappingURL=TextureBaker.js.map
|