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,1023 @@
|
|
|
1
|
+
import { Color3, DynamicTexture, Mesh, MeshBuilder, PointerEventTypes, StandardMaterial, Vector3, VertexBuffer, VertexData, } from '@babylonjs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Controller for Smart Seam Marking, LSCM/Angle-Based UV Unwrapping,
|
|
4
|
+
* Texel Density Normalization (px/m), and 2D UV Island Bin-Packing.
|
|
5
|
+
*/
|
|
6
|
+
export class UVUnwrapController {
|
|
7
|
+
service;
|
|
8
|
+
scene;
|
|
9
|
+
isActive = false;
|
|
10
|
+
seamPickMode = false;
|
|
11
|
+
angleThresholdDeg = 60;
|
|
12
|
+
textureResolution = 1024;
|
|
13
|
+
targetTexelDensity = 512; // px / meter
|
|
14
|
+
marginPx = 6;
|
|
15
|
+
rotateOptimal = true;
|
|
16
|
+
checkerPreviewActive = false;
|
|
17
|
+
seamOverlayMesh = null;
|
|
18
|
+
savedMaterials = new WeakMap();
|
|
19
|
+
checkerMaterial = null;
|
|
20
|
+
onStateChanged;
|
|
21
|
+
onUVModified;
|
|
22
|
+
constructor(service) {
|
|
23
|
+
this.service = service;
|
|
24
|
+
this.scene = service.scene;
|
|
25
|
+
this.initPointerHandling();
|
|
26
|
+
}
|
|
27
|
+
setActive(active) {
|
|
28
|
+
this.isActive = active;
|
|
29
|
+
if (!active) {
|
|
30
|
+
this.seamPickMode = false;
|
|
31
|
+
this.clearSeamOverlay();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Deactivate other exclusive 3D tools
|
|
35
|
+
if (this.service.sculptController?.isActive) {
|
|
36
|
+
this.service.sculptController.setActive(false);
|
|
37
|
+
}
|
|
38
|
+
if (this.service.voxelPainter?.isActive) {
|
|
39
|
+
this.service.voxelPainter.setActive(false);
|
|
40
|
+
}
|
|
41
|
+
if (this.service.pathExtrusion?.isActive) {
|
|
42
|
+
this.service.pathExtrusion.setActive(false);
|
|
43
|
+
}
|
|
44
|
+
if (this.service.weightPaintController?.isActive) {
|
|
45
|
+
this.service.weightPaintController.setActive(false);
|
|
46
|
+
}
|
|
47
|
+
const mesh = this.getActiveTargetMesh();
|
|
48
|
+
if (mesh) {
|
|
49
|
+
this.refreshSeamOverlay(mesh);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.onStateChanged?.(active);
|
|
53
|
+
}
|
|
54
|
+
getActiveTargetMesh() {
|
|
55
|
+
if (this.service.selectedMesh &&
|
|
56
|
+
!this.service.isEditorHelper(this.service.selectedMesh) &&
|
|
57
|
+
!this.service.selectedMesh.isDisposed() &&
|
|
58
|
+
this.service.selectedMesh.getTotalVertices() > 0) {
|
|
59
|
+
return this.service.selectedMesh;
|
|
60
|
+
}
|
|
61
|
+
const first = this.service.importedMeshes.find((m) => !this.service.isEditorHelper(m) && !m.isDisposed() && m.getTotalVertices() > 0);
|
|
62
|
+
return first || null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interactive 3D viewport click handler for manual seam edge marking.
|
|
66
|
+
*/
|
|
67
|
+
initPointerHandling() {
|
|
68
|
+
this.scene.onPointerObservable.add((pointerInfo) => {
|
|
69
|
+
if (!this.isActive || !this.seamPickMode)
|
|
70
|
+
return;
|
|
71
|
+
if (pointerInfo.type !== PointerEventTypes.POINTERDOWN)
|
|
72
|
+
return;
|
|
73
|
+
const evt = pointerInfo.event;
|
|
74
|
+
if (evt && evt.button !== 0)
|
|
75
|
+
return;
|
|
76
|
+
const pick = pointerInfo.pickInfo;
|
|
77
|
+
if (pick &&
|
|
78
|
+
pick.hit &&
|
|
79
|
+
pick.pickedPoint &&
|
|
80
|
+
pick.pickedMesh instanceof Mesh &&
|
|
81
|
+
!this.service.isGizmoMesh(pick.pickedMesh) &&
|
|
82
|
+
!this.service.isEditorHelper(pick.pickedMesh) &&
|
|
83
|
+
pick.pickedMesh !== this.service.gridMesh) {
|
|
84
|
+
this.toggleNearestEdgeSeam(pick.pickedMesh, pick.pickedPoint, pick.faceId);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Builds canonical vertex mapping so split vertices at identical 3D positions share topological edges.
|
|
90
|
+
*/
|
|
91
|
+
buildCanonicalVertices(positions) {
|
|
92
|
+
const quant = 10000;
|
|
93
|
+
const map = new Map();
|
|
94
|
+
const canonPositions = [];
|
|
95
|
+
const count = Math.floor(positions.length / 3);
|
|
96
|
+
const vertToCanon = new Int32Array(count);
|
|
97
|
+
for (let i = 0; i < count; i++) {
|
|
98
|
+
const x = positions[i * 3];
|
|
99
|
+
const y = positions[i * 3 + 1];
|
|
100
|
+
const z = positions[i * 3 + 2];
|
|
101
|
+
const key = `${Math.round(x * quant)},${Math.round(y * quant)},${Math.round(z * quant)}`;
|
|
102
|
+
let c = map.get(key);
|
|
103
|
+
if (c === undefined) {
|
|
104
|
+
c = canonPositions.length;
|
|
105
|
+
map.set(key, c);
|
|
106
|
+
canonPositions.push(new Vector3(x, y, z));
|
|
107
|
+
}
|
|
108
|
+
vertToCanon[i] = c;
|
|
109
|
+
}
|
|
110
|
+
return { canonPositions, vertToCanon };
|
|
111
|
+
}
|
|
112
|
+
makeEdgeKey(a, b) {
|
|
113
|
+
return a < b ? `${a}_${b}` : `${b}_${a}`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Toggles the seam state of the triangle edge closest to `worldHitPoint`.
|
|
117
|
+
*/
|
|
118
|
+
toggleNearestEdgeSeam(mesh, worldHitPoint, faceId) {
|
|
119
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
120
|
+
const indices = mesh.getIndices();
|
|
121
|
+
if (!positions || !indices)
|
|
122
|
+
return false;
|
|
123
|
+
const { canonPositions, vertToCanon } = this.buildCanonicalVertices(positions);
|
|
124
|
+
mesh.computeWorldMatrix(true);
|
|
125
|
+
const invWorld = mesh.getWorldMatrix().clone().invert();
|
|
126
|
+
const localHit = Vector3.TransformCoordinates(worldHitPoint, invWorld);
|
|
127
|
+
let bestEdgeKey = null;
|
|
128
|
+
let bestDist = Infinity;
|
|
129
|
+
const checkTriangle = (triIdx) => {
|
|
130
|
+
const i0 = indices[triIdx * 3];
|
|
131
|
+
const i1 = indices[triIdx * 3 + 1];
|
|
132
|
+
const i2 = indices[triIdx * 3 + 2];
|
|
133
|
+
const c0 = vertToCanon[i0];
|
|
134
|
+
const c1 = vertToCanon[i1];
|
|
135
|
+
const c2 = vertToCanon[i2];
|
|
136
|
+
const pairs = [
|
|
137
|
+
[c0, c1],
|
|
138
|
+
[c1, c2],
|
|
139
|
+
[c2, c0],
|
|
140
|
+
];
|
|
141
|
+
for (const [ca, cb] of pairs) {
|
|
142
|
+
if (ca === cb)
|
|
143
|
+
continue;
|
|
144
|
+
const pa = canonPositions[ca];
|
|
145
|
+
const pb = canonPositions[cb];
|
|
146
|
+
const ab = pb.subtract(pa);
|
|
147
|
+
const lenSq = ab.lengthSquared();
|
|
148
|
+
const t = lenSq > 1e-10 ? Math.max(0, Math.min(1, Vector3.Dot(localHit.subtract(pa), ab) / lenSq)) : 0;
|
|
149
|
+
const proj = pa.add(ab.scale(t));
|
|
150
|
+
const d = Vector3.Distance(localHit, proj);
|
|
151
|
+
if (d < bestDist) {
|
|
152
|
+
bestDist = d;
|
|
153
|
+
bestEdgeKey = this.makeEdgeKey(ca, cb);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
if (faceId !== undefined && faceId >= 0 && faceId * 3 + 2 < indices.length) {
|
|
158
|
+
checkTriangle(faceId);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
const numTris = Math.floor(indices.length / 3);
|
|
162
|
+
for (let t = 0; t < numTris; t++) {
|
|
163
|
+
checkTriangle(t);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!bestEdgeKey)
|
|
167
|
+
return false;
|
|
168
|
+
if (!mesh.metadata)
|
|
169
|
+
mesh.metadata = {};
|
|
170
|
+
if (!Array.isArray(mesh.metadata.uvSeams)) {
|
|
171
|
+
mesh.metadata.uvSeams = [];
|
|
172
|
+
}
|
|
173
|
+
const seamSet = new Set(mesh.metadata.uvSeams);
|
|
174
|
+
let added = false;
|
|
175
|
+
if (seamSet.has(bestEdgeKey)) {
|
|
176
|
+
seamSet.delete(bestEdgeKey);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
seamSet.add(bestEdgeKey);
|
|
180
|
+
added = true;
|
|
181
|
+
}
|
|
182
|
+
mesh.metadata.uvSeams = Array.from(seamSet);
|
|
183
|
+
this.refreshSeamOverlay(mesh);
|
|
184
|
+
this.onUVModified?.(mesh, this.analyzeUVs(mesh, this.textureResolution));
|
|
185
|
+
return added;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Automatically detects and marks Smart UV Seams along sharp crease angles, open boundaries,
|
|
189
|
+
* and cylindrical longitudinal seams.
|
|
190
|
+
*/
|
|
191
|
+
markSmartSeams(mesh, angleThresholdDeg = this.angleThresholdDeg) {
|
|
192
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
193
|
+
const indices = mesh.getIndices();
|
|
194
|
+
if (!positions || !indices || indices.length < 3) {
|
|
195
|
+
return { seamEdgeCount: 0, seamKeys: [] };
|
|
196
|
+
}
|
|
197
|
+
const { canonPositions, vertToCanon } = this.buildCanonicalVertices(positions);
|
|
198
|
+
const numTris = Math.floor(indices.length / 3);
|
|
199
|
+
const faceNormals = new Array(numTris);
|
|
200
|
+
const edgeToFaces = new Map();
|
|
201
|
+
for (let f = 0; f < numTris; f++) {
|
|
202
|
+
const c0 = vertToCanon[indices[f * 3]];
|
|
203
|
+
const c1 = vertToCanon[indices[f * 3 + 1]];
|
|
204
|
+
const c2 = vertToCanon[indices[f * 3 + 2]];
|
|
205
|
+
const p0 = canonPositions[c0];
|
|
206
|
+
const p1 = canonPositions[c1];
|
|
207
|
+
const p2 = canonPositions[c2];
|
|
208
|
+
const n = Vector3.Cross(p1.subtract(p0), p2.subtract(p0));
|
|
209
|
+
if (n.lengthSquared() > 1e-12)
|
|
210
|
+
n.normalize();
|
|
211
|
+
else
|
|
212
|
+
n.set(0, 1, 0);
|
|
213
|
+
faceNormals[f] = n;
|
|
214
|
+
if (c0 !== c1 && c1 !== c2 && c2 !== c0) {
|
|
215
|
+
const edges = [
|
|
216
|
+
this.makeEdgeKey(c0, c1),
|
|
217
|
+
this.makeEdgeKey(c1, c2),
|
|
218
|
+
this.makeEdgeKey(c2, c0),
|
|
219
|
+
];
|
|
220
|
+
for (const ek of edges) {
|
|
221
|
+
let list = edgeToFaces.get(ek);
|
|
222
|
+
if (!list) {
|
|
223
|
+
list = [];
|
|
224
|
+
edgeToFaces.set(ek, list);
|
|
225
|
+
}
|
|
226
|
+
list.push(f);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const cosThresh = Math.cos((angleThresholdDeg * Math.PI) / 180);
|
|
231
|
+
const seamKeys = new Set();
|
|
232
|
+
for (const [edgeKey, faces] of edgeToFaces.entries()) {
|
|
233
|
+
if (faces.length === 1) {
|
|
234
|
+
// Open boundary edge is always a seam
|
|
235
|
+
seamKeys.add(edgeKey);
|
|
236
|
+
}
|
|
237
|
+
else if (faces.length >= 2) {
|
|
238
|
+
const nA = faceNormals[faces[0]];
|
|
239
|
+
const nB = faceNormals[faces[1]];
|
|
240
|
+
if (Vector3.Dot(nA, nB) <= cosThresh) {
|
|
241
|
+
seamKeys.add(edgeKey);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// Also add a longitudinal back-seam for smooth closed surfaces (like spheres/cylinders/organic limbs)
|
|
246
|
+
// that otherwise have 0 sharp edges
|
|
247
|
+
if (seamKeys.size < 3 && canonPositions.length >= 6) {
|
|
248
|
+
for (const [edgeKey] of edgeToFaces.entries()) {
|
|
249
|
+
const [aStr, bStr] = edgeKey.split('_');
|
|
250
|
+
const pa = canonPositions[Number(aStr)];
|
|
251
|
+
const pb = canonPositions[Number(bStr)];
|
|
252
|
+
// Back-center meridian (X near 0, Z <= 0)
|
|
253
|
+
if (Math.abs(pa.x) < 0.08 && Math.abs(pb.x) < 0.08 && pa.z <= 0 && pb.z <= 0) {
|
|
254
|
+
seamKeys.add(edgeKey);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const resultKeys = Array.from(seamKeys);
|
|
259
|
+
if (!mesh.metadata)
|
|
260
|
+
mesh.metadata = {};
|
|
261
|
+
mesh.metadata.uvSeams = resultKeys;
|
|
262
|
+
this.refreshSeamOverlay(mesh);
|
|
263
|
+
return { seamEdgeCount: resultKeys.length, seamKeys: resultKeys };
|
|
264
|
+
}
|
|
265
|
+
clearSeams(mesh) {
|
|
266
|
+
if (mesh.metadata) {
|
|
267
|
+
mesh.metadata.uvSeams = [];
|
|
268
|
+
}
|
|
269
|
+
this.clearSeamOverlay();
|
|
270
|
+
}
|
|
271
|
+
clearSeamOverlay() {
|
|
272
|
+
if (this.seamOverlayMesh) {
|
|
273
|
+
this.seamOverlayMesh.dispose();
|
|
274
|
+
this.seamOverlayMesh = null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Renders marked UV seams as a bright orange-red 3D wireframe overlay in the viewport.
|
|
279
|
+
*/
|
|
280
|
+
refreshSeamOverlay(mesh) {
|
|
281
|
+
this.clearSeamOverlay();
|
|
282
|
+
if (!mesh || mesh.isDisposed())
|
|
283
|
+
return;
|
|
284
|
+
const seamKeys = mesh.metadata?.uvSeams || [];
|
|
285
|
+
if (seamKeys.length === 0)
|
|
286
|
+
return;
|
|
287
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
288
|
+
if (!positions)
|
|
289
|
+
return;
|
|
290
|
+
const { canonPositions } = this.buildCanonicalVertices(positions);
|
|
291
|
+
mesh.computeWorldMatrix(true);
|
|
292
|
+
const worldMat = mesh.getWorldMatrix();
|
|
293
|
+
const lines = [];
|
|
294
|
+
for (const key of seamKeys) {
|
|
295
|
+
const [aStr, bStr] = key.split('_');
|
|
296
|
+
const ca = Number(aStr);
|
|
297
|
+
const cb = Number(bStr);
|
|
298
|
+
if (ca < canonPositions.length && cb < canonPositions.length) {
|
|
299
|
+
const wa = Vector3.TransformCoordinates(canonPositions[ca], worldMat);
|
|
300
|
+
const wb = Vector3.TransformCoordinates(canonPositions[cb], worldMat);
|
|
301
|
+
lines.push([wa, wb]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (lines.length === 0)
|
|
305
|
+
return;
|
|
306
|
+
this.seamOverlayMesh = MeshBuilder.CreateLineSystem('editor_uv_seam_lines', { lines }, this.scene);
|
|
307
|
+
this.seamOverlayMesh.color = new Color3(1.0, 0.28, 0.15);
|
|
308
|
+
this.seamOverlayMesh.isPickable = false;
|
|
309
|
+
this.seamOverlayMesh.renderingGroupId = 1;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Performs Seam-Aware Chart Unwrapping, Texel Density Normalization, and 2D UV Island Bin-Packing.
|
|
313
|
+
*/
|
|
314
|
+
unwrapMesh(mesh, options = {}) {
|
|
315
|
+
const method = options.method || 'smart_seams';
|
|
316
|
+
const angleThresholdDeg = options.angleThresholdDeg ?? this.angleThresholdDeg;
|
|
317
|
+
const textureResolution = options.textureResolution ?? this.textureResolution;
|
|
318
|
+
const marginPx = options.marginPx ?? this.marginPx;
|
|
319
|
+
const rotateOptimal = options.rotateOptimal ?? this.rotateOptimal;
|
|
320
|
+
const prePositions = Array.from(mesh.getVerticesData(VertexBuffer.PositionKind) || []);
|
|
321
|
+
const preIndices = Array.from(mesh.getIndices() || []);
|
|
322
|
+
const preNormals = Array.from(mesh.getVerticesData(VertexBuffer.NormalKind) || []);
|
|
323
|
+
const preUVs = mesh.getVerticesData(VertexBuffer.UVKind)
|
|
324
|
+
? Array.from(mesh.getVerticesData(VertexBuffer.UVKind))
|
|
325
|
+
: null;
|
|
326
|
+
if (prePositions.length < 9 || preIndices.length < 3) {
|
|
327
|
+
return this.analyzeUVs(mesh, textureResolution);
|
|
328
|
+
}
|
|
329
|
+
// Ensure smart seams are marked if using smart_seams and none are present yet
|
|
330
|
+
if (method === 'smart_seams' &&
|
|
331
|
+
(!mesh.metadata?.uvSeams || mesh.metadata.uvSeams.length === 0)) {
|
|
332
|
+
this.markSmartSeams(mesh, angleThresholdDeg);
|
|
333
|
+
}
|
|
334
|
+
const seamSet = new Set(mesh.metadata?.uvSeams || []);
|
|
335
|
+
const { canonPositions, vertToCanon } = this.buildCanonicalVertices(prePositions);
|
|
336
|
+
const numTris = Math.floor(preIndices.length / 3);
|
|
337
|
+
// Compute triangle normals and adjacency across non-seam edges
|
|
338
|
+
const faceNormals = new Array(numTris);
|
|
339
|
+
const edgeToTris = new Map();
|
|
340
|
+
for (let f = 0; f < numTris; f++) {
|
|
341
|
+
const c0 = vertToCanon[preIndices[f * 3]];
|
|
342
|
+
const c1 = vertToCanon[preIndices[f * 3 + 1]];
|
|
343
|
+
const c2 = vertToCanon[preIndices[f * 3 + 2]];
|
|
344
|
+
const p0 = canonPositions[c0];
|
|
345
|
+
const p1 = canonPositions[c1];
|
|
346
|
+
const p2 = canonPositions[c2];
|
|
347
|
+
const n = Vector3.Cross(p1.subtract(p0), p2.subtract(p0));
|
|
348
|
+
if (n.lengthSquared() > 1e-12)
|
|
349
|
+
n.normalize();
|
|
350
|
+
else
|
|
351
|
+
n.set(0, 1, 0);
|
|
352
|
+
faceNormals[f] = n;
|
|
353
|
+
const edges = [
|
|
354
|
+
this.makeEdgeKey(c0, c1),
|
|
355
|
+
this.makeEdgeKey(c1, c2),
|
|
356
|
+
this.makeEdgeKey(c2, c0),
|
|
357
|
+
];
|
|
358
|
+
for (const ek of edges) {
|
|
359
|
+
if (!edgeToTris.has(ek))
|
|
360
|
+
edgeToTris.set(ek, []);
|
|
361
|
+
edgeToTris.get(ek).push(f);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// Flood-fill triangles into connected UV Charts (Islands) stopping at marked seams and sharp angle breaks
|
|
365
|
+
const cosAngleLimit = Math.cos((angleThresholdDeg * Math.PI) / 180);
|
|
366
|
+
const triVisited = new Uint8Array(numTris);
|
|
367
|
+
const charts = [];
|
|
368
|
+
for (let f = 0; f < numTris; f++) {
|
|
369
|
+
if (triVisited[f])
|
|
370
|
+
continue;
|
|
371
|
+
const chart = [];
|
|
372
|
+
const seedNormal = faceNormals[f].clone();
|
|
373
|
+
const queue = [f];
|
|
374
|
+
triVisited[f] = 1;
|
|
375
|
+
while (queue.length > 0) {
|
|
376
|
+
const curr = queue.shift();
|
|
377
|
+
chart.push(curr);
|
|
378
|
+
const c0 = vertToCanon[preIndices[curr * 3]];
|
|
379
|
+
const c1 = vertToCanon[preIndices[curr * 3 + 1]];
|
|
380
|
+
const c2 = vertToCanon[preIndices[curr * 3 + 2]];
|
|
381
|
+
const edges = [
|
|
382
|
+
this.makeEdgeKey(c0, c1),
|
|
383
|
+
this.makeEdgeKey(c1, c2),
|
|
384
|
+
this.makeEdgeKey(c2, c0),
|
|
385
|
+
];
|
|
386
|
+
for (const ek of edges) {
|
|
387
|
+
if (seamSet.has(ek))
|
|
388
|
+
continue; // Stop at marked seam!
|
|
389
|
+
const nbrs = edgeToTris.get(ek) || [];
|
|
390
|
+
for (const nb of nbrs) {
|
|
391
|
+
if (triVisited[nb])
|
|
392
|
+
continue;
|
|
393
|
+
// Check dihedral angle and chart normal fold prevention
|
|
394
|
+
const dotAdj = Vector3.Dot(faceNormals[curr], faceNormals[nb]);
|
|
395
|
+
const dotSeed = Vector3.Dot(seedNormal, faceNormals[nb]);
|
|
396
|
+
if (dotAdj >= cosAngleLimit && dotSeed >= -0.15) {
|
|
397
|
+
triVisited[nb] = 1;
|
|
398
|
+
queue.push(nb);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
charts.push(chart);
|
|
404
|
+
}
|
|
405
|
+
// Build unindexed/chart-isolated vertices so UV seams have independent UV coordinates cleanly
|
|
406
|
+
const hasColors = !!mesh.getVerticesData(VertexBuffer.ColorKind);
|
|
407
|
+
const rawColors = mesh.getVerticesData(VertexBuffer.ColorKind);
|
|
408
|
+
const newPositions = [];
|
|
409
|
+
const newNormals = [];
|
|
410
|
+
const newColors = [];
|
|
411
|
+
const newUVs = [];
|
|
412
|
+
const newIndices = [];
|
|
413
|
+
for (let cIdx = 0; cIdx < charts.length; cIdx++) {
|
|
414
|
+
const tris = charts[cIdx];
|
|
415
|
+
// Compute area-weighted average normal of the chart
|
|
416
|
+
const avgNormal = new Vector3(0, 0, 0);
|
|
417
|
+
for (const f of tris) {
|
|
418
|
+
avgNormal.addInPlace(faceNormals[f]);
|
|
419
|
+
}
|
|
420
|
+
if (avgNormal.lengthSquared() > 1e-8)
|
|
421
|
+
avgNormal.normalize();
|
|
422
|
+
else
|
|
423
|
+
avgNormal.set(0, 1, 0);
|
|
424
|
+
// Construct orthonormal tangent plane basis (tangentU, bitangentV) for chart flattening
|
|
425
|
+
const upRef = Math.abs(avgNormal.y) < 0.9 ? Vector3.Up() : Vector3.Right();
|
|
426
|
+
const tangentU = Vector3.Cross(upRef, avgNormal).normalize();
|
|
427
|
+
const bitangentV = Vector3.Cross(avgNormal, tangentU).normalize();
|
|
428
|
+
// Map canonical vertex -> local chart vertex index so vertices WITHIN the same island are shared
|
|
429
|
+
const chartVertMap = new Map();
|
|
430
|
+
const chartLocalVerts = [];
|
|
431
|
+
for (const f of tris) {
|
|
432
|
+
for (let k = 0; k < 3; k++) {
|
|
433
|
+
const origV = preIndices[f * 3 + k];
|
|
434
|
+
const canonV = vertToCanon[origV];
|
|
435
|
+
// Share within chart if normals are close
|
|
436
|
+
const key = canonV;
|
|
437
|
+
let localV = chartVertMap.get(key);
|
|
438
|
+
if (localV === undefined) {
|
|
439
|
+
localV = newPositions.length / 3;
|
|
440
|
+
chartVertMap.set(key, localV);
|
|
441
|
+
chartLocalVerts.push(localV);
|
|
442
|
+
const px = prePositions[origV * 3];
|
|
443
|
+
const py = prePositions[origV * 3 + 1];
|
|
444
|
+
const pz = prePositions[origV * 3 + 2];
|
|
445
|
+
newPositions.push(px, py, pz);
|
|
446
|
+
if (preNormals.length >= (origV + 1) * 3) {
|
|
447
|
+
newNormals.push(preNormals[origV * 3], preNormals[origV * 3 + 1], preNormals[origV * 3 + 2]);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
newNormals.push(avgNormal.x, avgNormal.y, avgNormal.z);
|
|
451
|
+
}
|
|
452
|
+
if (hasColors && rawColors) {
|
|
453
|
+
newColors.push(rawColors[origV * 4], rawColors[origV * 4 + 1], rawColors[origV * 4 + 2], rawColors[origV * 4 + 3]);
|
|
454
|
+
}
|
|
455
|
+
const pVec = new Vector3(px, py, pz);
|
|
456
|
+
let u = 0;
|
|
457
|
+
let v = 0;
|
|
458
|
+
if (method === 'cylindrical') {
|
|
459
|
+
const angle = Math.atan2(pVec.x, pVec.z);
|
|
460
|
+
u = (angle + Math.PI) / (2 * Math.PI);
|
|
461
|
+
v = pVec.y;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
u = Vector3.Dot(pVec, tangentU);
|
|
465
|
+
v = Vector3.Dot(pVec, bitangentV);
|
|
466
|
+
}
|
|
467
|
+
newUVs.push(u, v);
|
|
468
|
+
}
|
|
469
|
+
newIndices.push(localV);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
// Perform 2 passes of interior UV harmonic relaxation on charts with > 4 vertices to reduce distortion
|
|
473
|
+
if (chartLocalVerts.length > 4 && tris.length > 2) {
|
|
474
|
+
const boundarySet = new Set();
|
|
475
|
+
const chartEdgeCounts = new Map();
|
|
476
|
+
const localNeighbors = new Map();
|
|
477
|
+
for (let t = 0; t < tris.length; t++) {
|
|
478
|
+
const baseIdx = newIndices.length - (tris.length - t) * 3;
|
|
479
|
+
const v0 = newIndices[baseIdx];
|
|
480
|
+
const v1 = newIndices[baseIdx + 1];
|
|
481
|
+
const v2 = newIndices[baseIdx + 2];
|
|
482
|
+
const pairs = [
|
|
483
|
+
[v0, v1],
|
|
484
|
+
[v1, v2],
|
|
485
|
+
[v2, v0],
|
|
486
|
+
];
|
|
487
|
+
for (const [va, vb] of pairs) {
|
|
488
|
+
const ek = this.makeEdgeKey(va, vb);
|
|
489
|
+
chartEdgeCounts.set(ek, (chartEdgeCounts.get(ek) || 0) + 1);
|
|
490
|
+
if (!localNeighbors.has(va))
|
|
491
|
+
localNeighbors.set(va, new Set());
|
|
492
|
+
if (!localNeighbors.has(vb))
|
|
493
|
+
localNeighbors.set(vb, new Set());
|
|
494
|
+
localNeighbors.get(va).add(vb);
|
|
495
|
+
localNeighbors.get(vb).add(va);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
for (const [ek, count] of chartEdgeCounts.entries()) {
|
|
499
|
+
if (count === 1) {
|
|
500
|
+
const [a, b] = ek.split('_').map(Number);
|
|
501
|
+
boundarySet.add(a);
|
|
502
|
+
boundarySet.add(b);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
for (let iter = 0; iter < 2; iter++) {
|
|
506
|
+
for (const lv of chartLocalVerts) {
|
|
507
|
+
if (boundarySet.has(lv))
|
|
508
|
+
continue;
|
|
509
|
+
const nbrs = localNeighbors.get(lv);
|
|
510
|
+
if (!nbrs || nbrs.size === 0)
|
|
511
|
+
continue;
|
|
512
|
+
let sumU = 0;
|
|
513
|
+
let sumV = 0;
|
|
514
|
+
for (const nb of nbrs) {
|
|
515
|
+
sumU += newUVs[nb * 2];
|
|
516
|
+
sumV += newUVs[nb * 2 + 1];
|
|
517
|
+
}
|
|
518
|
+
newUVs[lv * 2] = newUVs[lv * 2] * 0.65 + (sumU / nbrs.size) * 0.35;
|
|
519
|
+
newUVs[lv * 2 + 1] = newUVs[lv * 2 + 1] * 0.65 + (sumV / nbrs.size) * 0.35;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
// Apply unwrapped buffers to mesh
|
|
525
|
+
const vd = new VertexData();
|
|
526
|
+
vd.positions = newPositions;
|
|
527
|
+
vd.indices = newIndices;
|
|
528
|
+
vd.normals = newNormals;
|
|
529
|
+
vd.uvs = newUVs;
|
|
530
|
+
if (hasColors && newColors.length > 0) {
|
|
531
|
+
vd.colors = newColors;
|
|
532
|
+
}
|
|
533
|
+
vd.applyToMesh(mesh, true);
|
|
534
|
+
// Pack the UV islands with uniform texel density and margin padding
|
|
535
|
+
const packAnalysis = this.packUVIslands(mesh, {
|
|
536
|
+
marginPx,
|
|
537
|
+
textureResolution,
|
|
538
|
+
rotateOptimal,
|
|
539
|
+
normalizeScale: true,
|
|
540
|
+
});
|
|
541
|
+
if (options.targetTexelDensity && options.targetTexelDensity > 0) {
|
|
542
|
+
this.normalizeTexelDensity(mesh, options.targetTexelDensity, textureResolution, false);
|
|
543
|
+
}
|
|
544
|
+
const postPositions = Array.from(mesh.getVerticesData(VertexBuffer.PositionKind) || []);
|
|
545
|
+
const postIndices = Array.from(mesh.getIndices() || []);
|
|
546
|
+
const postNormals = Array.from(mesh.getVerticesData(VertexBuffer.NormalKind) || []);
|
|
547
|
+
const postUVs = Array.from(mesh.getVerticesData(VertexBuffer.UVKind) || []);
|
|
548
|
+
this.service.recordAction({
|
|
549
|
+
name: `UV Unwrap (${mesh.name})`,
|
|
550
|
+
undo: () => {
|
|
551
|
+
if (!mesh.isDisposed()) {
|
|
552
|
+
const uVd = new VertexData();
|
|
553
|
+
uVd.positions = prePositions;
|
|
554
|
+
uVd.indices = preIndices;
|
|
555
|
+
uVd.normals = preNormals;
|
|
556
|
+
if (preUVs)
|
|
557
|
+
uVd.uvs = preUVs;
|
|
558
|
+
uVd.applyToMesh(mesh, true);
|
|
559
|
+
this.onUVModified?.(mesh, this.analyzeUVs(mesh, textureResolution));
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
redo: () => {
|
|
563
|
+
if (!mesh.isDisposed()) {
|
|
564
|
+
const rVd = new VertexData();
|
|
565
|
+
rVd.positions = postPositions;
|
|
566
|
+
rVd.indices = postIndices;
|
|
567
|
+
rVd.normals = postNormals;
|
|
568
|
+
rVd.uvs = postUVs;
|
|
569
|
+
rVd.applyToMesh(mesh, true);
|
|
570
|
+
this.onUVModified?.(mesh, this.analyzeUVs(mesh, textureResolution));
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
});
|
|
574
|
+
this.refreshSeamOverlay(mesh);
|
|
575
|
+
this.onUVModified?.(mesh, packAnalysis);
|
|
576
|
+
return packAnalysis;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Extracts connected 2D UV islands from the mesh's current UV buffer.
|
|
580
|
+
*/
|
|
581
|
+
extractUVIslands(positions, indices, uvs, worldMatrix) {
|
|
582
|
+
const numTris = Math.floor(indices.length / 3);
|
|
583
|
+
const uvQuant = 100000;
|
|
584
|
+
const uvEdgeToTris = new Map();
|
|
585
|
+
const getUVKey = (vi) => {
|
|
586
|
+
const u = Math.round(uvs[vi * 2] * uvQuant);
|
|
587
|
+
const v = Math.round(uvs[vi * 2 + 1] * uvQuant);
|
|
588
|
+
return `${u}:${v}`;
|
|
589
|
+
};
|
|
590
|
+
for (let f = 0; f < numTris; f++) {
|
|
591
|
+
const i0 = indices[f * 3];
|
|
592
|
+
const i1 = indices[f * 3 + 1];
|
|
593
|
+
const i2 = indices[f * 3 + 2];
|
|
594
|
+
const k0 = getUVKey(i0);
|
|
595
|
+
const k1 = getUVKey(i1);
|
|
596
|
+
const k2 = getUVKey(i2);
|
|
597
|
+
const edges = [
|
|
598
|
+
k0 < k1 ? `${k0}|${k1}` : `${k1}|${k0}`,
|
|
599
|
+
k1 < k2 ? `${k1}|${k2}` : `${k2}|${k1}`,
|
|
600
|
+
k2 < k0 ? `${k2}|${k0}` : `${k0}|${k2}`,
|
|
601
|
+
];
|
|
602
|
+
for (const ek of edges) {
|
|
603
|
+
if (!uvEdgeToTris.has(ek))
|
|
604
|
+
uvEdgeToTris.set(ek, []);
|
|
605
|
+
uvEdgeToTris.get(ek).push(f);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const visited = new Uint8Array(numTris);
|
|
609
|
+
const islands = [];
|
|
610
|
+
for (let f = 0; f < numTris; f++) {
|
|
611
|
+
if (visited[f])
|
|
612
|
+
continue;
|
|
613
|
+
const faceIndices = [];
|
|
614
|
+
const vertexIndices = new Set();
|
|
615
|
+
const queue = [f];
|
|
616
|
+
visited[f] = 1;
|
|
617
|
+
while (queue.length > 0) {
|
|
618
|
+
const curr = queue.shift();
|
|
619
|
+
faceIndices.push(curr);
|
|
620
|
+
const i0 = indices[curr * 3];
|
|
621
|
+
const i1 = indices[curr * 3 + 1];
|
|
622
|
+
const i2 = indices[curr * 3 + 2];
|
|
623
|
+
vertexIndices.add(i0);
|
|
624
|
+
vertexIndices.add(i1);
|
|
625
|
+
vertexIndices.add(i2);
|
|
626
|
+
const k0 = getUVKey(i0);
|
|
627
|
+
const k1 = getUVKey(i1);
|
|
628
|
+
const k2 = getUVKey(i2);
|
|
629
|
+
const edges = [
|
|
630
|
+
k0 < k1 ? `${k0}|${k1}` : `${k1}|${k0}`,
|
|
631
|
+
k1 < k2 ? `${k1}|${k2}` : `${k2}|${k1}`,
|
|
632
|
+
k2 < k0 ? `${k2}|${k0}` : `${k0}|${k2}`,
|
|
633
|
+
];
|
|
634
|
+
for (const ek of edges) {
|
|
635
|
+
const nbrs = uvEdgeToTris.get(ek) || [];
|
|
636
|
+
for (const nb of nbrs) {
|
|
637
|
+
if (!visited[nb]) {
|
|
638
|
+
visited[nb] = 1;
|
|
639
|
+
queue.push(nb);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
let worldArea = 0;
|
|
645
|
+
let uvArea = 0;
|
|
646
|
+
let minU = Infinity;
|
|
647
|
+
let maxU = -Infinity;
|
|
648
|
+
let minV = Infinity;
|
|
649
|
+
let maxV = -Infinity;
|
|
650
|
+
for (const tri of faceIndices) {
|
|
651
|
+
const i0 = indices[tri * 3];
|
|
652
|
+
const i1 = indices[tri * 3 + 1];
|
|
653
|
+
const i2 = indices[tri * 3 + 2];
|
|
654
|
+
const p0 = Vector3.TransformCoordinates(new Vector3(positions[i0 * 3], positions[i0 * 3 + 1], positions[i0 * 3 + 2]), worldMatrix);
|
|
655
|
+
const p1 = Vector3.TransformCoordinates(new Vector3(positions[i1 * 3], positions[i1 * 3 + 1], positions[i1 * 3 + 2]), worldMatrix);
|
|
656
|
+
const p2 = Vector3.TransformCoordinates(new Vector3(positions[i2 * 3], positions[i2 * 3 + 1], positions[i2 * 3 + 2]), worldMatrix);
|
|
657
|
+
worldArea += Vector3.Cross(p1.subtract(p0), p2.subtract(p0)).length() * 0.5;
|
|
658
|
+
const u0 = uvs[i0 * 2];
|
|
659
|
+
const v0 = uvs[i0 * 2 + 1];
|
|
660
|
+
const u1 = uvs[i1 * 2];
|
|
661
|
+
const v1 = uvs[i1 * 2 + 1];
|
|
662
|
+
const u2 = uvs[i2 * 2];
|
|
663
|
+
const v2 = uvs[i2 * 2 + 1];
|
|
664
|
+
uvArea += Math.abs((u1 - u0) * (v2 - v0) - (u2 - u0) * (v1 - v0)) * 0.5;
|
|
665
|
+
}
|
|
666
|
+
for (const vi of vertexIndices) {
|
|
667
|
+
const u = uvs[vi * 2];
|
|
668
|
+
const v = uvs[vi * 2 + 1];
|
|
669
|
+
if (u < minU)
|
|
670
|
+
minU = u;
|
|
671
|
+
if (u > maxU)
|
|
672
|
+
maxU = u;
|
|
673
|
+
if (v < minV)
|
|
674
|
+
minV = v;
|
|
675
|
+
if (v > maxV)
|
|
676
|
+
maxV = v;
|
|
677
|
+
}
|
|
678
|
+
islands.push({
|
|
679
|
+
id: islands.length,
|
|
680
|
+
faceIndices,
|
|
681
|
+
vertexIndices,
|
|
682
|
+
worldArea,
|
|
683
|
+
uvArea,
|
|
684
|
+
minU,
|
|
685
|
+
maxU,
|
|
686
|
+
minV,
|
|
687
|
+
maxV,
|
|
688
|
+
widthU: Math.max(1e-5, maxU - minU),
|
|
689
|
+
heightV: Math.max(1e-5, maxV - minV),
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
return islands;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Normalizes Texel Density so all UV islands match a target Pixels-Per-Meter (px/m) resolution.
|
|
696
|
+
*/
|
|
697
|
+
normalizeTexelDensity(mesh, targetPxPerMeter = this.targetTexelDensity, textureResolution = this.textureResolution, fitInsideZeroOne = false) {
|
|
698
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
699
|
+
const indices = mesh.getIndices();
|
|
700
|
+
const rawUVs = mesh.getVerticesData(VertexBuffer.UVKind);
|
|
701
|
+
if (!positions || !indices || !rawUVs) {
|
|
702
|
+
return this.analyzeUVs(mesh, textureResolution);
|
|
703
|
+
}
|
|
704
|
+
const uvs = Array.from(rawUVs);
|
|
705
|
+
mesh.computeWorldMatrix(true);
|
|
706
|
+
const worldMat = mesh.getWorldMatrix();
|
|
707
|
+
const islands = this.extractUVIslands(positions, indices, uvs, worldMat);
|
|
708
|
+
const desiredRatio = Math.max(0.01, targetPxPerMeter / Math.max(64, textureResolution));
|
|
709
|
+
for (const island of islands) {
|
|
710
|
+
if (island.worldArea <= 1e-8 || island.uvArea <= 1e-10)
|
|
711
|
+
continue;
|
|
712
|
+
const currentLinearRatio = Math.sqrt(island.uvArea / island.worldArea);
|
|
713
|
+
const scaleFactor = desiredRatio / currentLinearRatio;
|
|
714
|
+
const centerU = (island.minU + island.maxU) * 0.5;
|
|
715
|
+
const centerV = (island.minV + island.maxV) * 0.5;
|
|
716
|
+
for (const vi of island.vertexIndices) {
|
|
717
|
+
uvs[vi * 2] = centerU + (uvs[vi * 2] - centerU) * scaleFactor;
|
|
718
|
+
uvs[vi * 2 + 1] = centerV + (uvs[vi * 2 + 1] - centerV) * scaleFactor;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
mesh.setVerticesData(VertexBuffer.UVKind, uvs, true);
|
|
722
|
+
if (fitInsideZeroOne) {
|
|
723
|
+
return this.packUVIslands(mesh, {
|
|
724
|
+
marginPx: this.marginPx,
|
|
725
|
+
textureResolution,
|
|
726
|
+
rotateOptimal: this.rotateOptimal,
|
|
727
|
+
normalizeScale: false,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
const stats = this.analyzeUVs(mesh, textureResolution);
|
|
731
|
+
this.onUVModified?.(mesh, stats);
|
|
732
|
+
return stats;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Packs 2D UV islands into the [0, 1] x [0, 1] UV square using a Shelf / Skyline 2D Bin-Packer
|
|
736
|
+
* with pixel padding and optional 90-degree rotation optimization.
|
|
737
|
+
*/
|
|
738
|
+
packUVIslands(mesh, options) {
|
|
739
|
+
const marginPx = options?.marginPx ?? this.marginPx;
|
|
740
|
+
const textureResolution = options?.textureResolution ?? this.textureResolution;
|
|
741
|
+
const rotateOptimal = options?.rotateOptimal ?? this.rotateOptimal;
|
|
742
|
+
const normalizeScale = options?.normalizeScale ?? true;
|
|
743
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
744
|
+
const indices = mesh.getIndices();
|
|
745
|
+
const rawUVs = mesh.getVerticesData(VertexBuffer.UVKind);
|
|
746
|
+
if (!positions || !indices || !rawUVs || rawUVs.length === 0) {
|
|
747
|
+
return this.analyzeUVs(mesh, textureResolution);
|
|
748
|
+
}
|
|
749
|
+
const uvs = Array.from(rawUVs);
|
|
750
|
+
mesh.computeWorldMatrix(true);
|
|
751
|
+
const worldMat = mesh.getWorldMatrix();
|
|
752
|
+
const islands = this.extractUVIslands(positions, indices, uvs, worldMat);
|
|
753
|
+
if (islands.length === 0) {
|
|
754
|
+
return this.analyzeUVs(mesh, textureResolution);
|
|
755
|
+
}
|
|
756
|
+
// Step 1: Equalize relative texel density across islands so face & armor have uniform density
|
|
757
|
+
if (normalizeScale) {
|
|
758
|
+
let totalWorldArea = 0;
|
|
759
|
+
for (const isl of islands)
|
|
760
|
+
totalWorldArea += isl.worldArea;
|
|
761
|
+
const avgDensity = totalWorldArea > 1e-8 ? 1.0 / Math.sqrt(totalWorldArea) : 1.0;
|
|
762
|
+
for (const isl of islands) {
|
|
763
|
+
if (isl.worldArea > 1e-8 && isl.uvArea > 1e-10) {
|
|
764
|
+
const currRatio = Math.sqrt(isl.uvArea / isl.worldArea);
|
|
765
|
+
const scale = avgDensity / currRatio;
|
|
766
|
+
for (const vi of isl.vertexIndices) {
|
|
767
|
+
uvs[vi * 2] = (uvs[vi * 2] - isl.minU) * scale;
|
|
768
|
+
uvs[vi * 2 + 1] = (uvs[vi * 2 + 1] - isl.minV) * scale;
|
|
769
|
+
}
|
|
770
|
+
isl.widthU *= scale;
|
|
771
|
+
isl.heightV *= scale;
|
|
772
|
+
isl.minU = 0;
|
|
773
|
+
isl.minV = 0;
|
|
774
|
+
isl.maxU = isl.widthU;
|
|
775
|
+
isl.maxV = isl.heightV;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
// Shift each island local origin to (0,0)
|
|
781
|
+
for (const isl of islands) {
|
|
782
|
+
for (const vi of isl.vertexIndices) {
|
|
783
|
+
uvs[vi * 2] -= isl.minU;
|
|
784
|
+
uvs[vi * 2 + 1] -= isl.minV;
|
|
785
|
+
}
|
|
786
|
+
isl.maxU = isl.widthU;
|
|
787
|
+
isl.maxV = isl.heightV;
|
|
788
|
+
isl.minU = 0;
|
|
789
|
+
isl.minV = 0;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
// Step 2: Optional 90-degree rotation so taller islands lay horizontally for denser shelf packing
|
|
793
|
+
if (rotateOptimal) {
|
|
794
|
+
for (const isl of islands) {
|
|
795
|
+
if (isl.heightV > isl.widthU * 1.15) {
|
|
796
|
+
const oldW = isl.widthU;
|
|
797
|
+
const oldH = isl.heightV;
|
|
798
|
+
for (const vi of isl.vertexIndices) {
|
|
799
|
+
const u = uvs[vi * 2];
|
|
800
|
+
const v = uvs[vi * 2 + 1];
|
|
801
|
+
uvs[vi * 2] = v;
|
|
802
|
+
uvs[vi * 2 + 1] = oldW - u;
|
|
803
|
+
}
|
|
804
|
+
isl.widthU = oldH;
|
|
805
|
+
isl.heightV = oldW;
|
|
806
|
+
isl.maxU = isl.widthU;
|
|
807
|
+
isl.maxV = isl.heightV;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// Step 3: Sort islands by height descending for Skyline/Shelf bin-packing
|
|
812
|
+
const sortedIslands = islands.slice().sort((a, b) => b.heightV - a.heightV);
|
|
813
|
+
let totalBoxArea = 0;
|
|
814
|
+
let maxIslandWidth = 0;
|
|
815
|
+
for (const isl of sortedIslands) {
|
|
816
|
+
totalBoxArea += isl.widthU * isl.heightV;
|
|
817
|
+
if (isl.widthU > maxIslandWidth)
|
|
818
|
+
maxIslandWidth = isl.widthU;
|
|
819
|
+
}
|
|
820
|
+
const padUV = Math.max(0.002, marginPx / Math.max(128, textureResolution));
|
|
821
|
+
const targetBinWidth = Math.max(maxIslandWidth + padUV * 2, Math.sqrt(totalBoxArea * 1.22) + padUV * Math.sqrt(sortedIslands.length));
|
|
822
|
+
let cursorX = padUV;
|
|
823
|
+
let cursorY = padUV;
|
|
824
|
+
let shelfHeight = 0;
|
|
825
|
+
let maxPackedX = 0;
|
|
826
|
+
let maxPackedY = 0;
|
|
827
|
+
for (const isl of sortedIslands) {
|
|
828
|
+
if (cursorX + isl.widthU + padUV > targetBinWidth && cursorX > padUV) {
|
|
829
|
+
cursorX = padUV;
|
|
830
|
+
cursorY += shelfHeight + padUV;
|
|
831
|
+
shelfHeight = 0;
|
|
832
|
+
}
|
|
833
|
+
for (const vi of isl.vertexIndices) {
|
|
834
|
+
uvs[vi * 2] += cursorX;
|
|
835
|
+
uvs[vi * 2 + 1] += cursorY;
|
|
836
|
+
}
|
|
837
|
+
cursorX += isl.widthU + padUV;
|
|
838
|
+
if (isl.heightV > shelfHeight)
|
|
839
|
+
shelfHeight = isl.heightV;
|
|
840
|
+
if (cursorX > maxPackedX)
|
|
841
|
+
maxPackedX = cursorX;
|
|
842
|
+
if (cursorY + isl.heightV + padUV > maxPackedY) {
|
|
843
|
+
maxPackedY = cursorY + isl.heightV + padUV;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
// Step 4: Uniformly scale the packed bin into [padUV, 1 - padUV] so it fits [0, 1] UV space cleanly
|
|
847
|
+
const extent = Math.max(1e-5, Math.max(maxPackedX, maxPackedY));
|
|
848
|
+
if (normalizeScale || extent > 1.0) {
|
|
849
|
+
const globalFitScale = (1.0 - padUV * 2) / extent;
|
|
850
|
+
for (let i = 0; i < uvs.length; i += 2) {
|
|
851
|
+
uvs[i] = padUV + (uvs[i] - padUV) * globalFitScale;
|
|
852
|
+
uvs[i + 1] = padUV + (uvs[i + 1] - padUV) * globalFitScale;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
mesh.setVerticesData(VertexBuffer.UVKind, uvs, true);
|
|
856
|
+
const stats = this.analyzeUVs(mesh, textureResolution);
|
|
857
|
+
this.onUVModified?.(mesh, stats);
|
|
858
|
+
return stats;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Computes comprehensive UV & Texel Density metrics for a mesh.
|
|
862
|
+
*/
|
|
863
|
+
analyzeUVs(mesh, textureResolution = this.textureResolution) {
|
|
864
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
865
|
+
const indices = mesh.getIndices();
|
|
866
|
+
const uvs = mesh.getVerticesData(VertexBuffer.UVKind);
|
|
867
|
+
const seamEdgeCount = Array.isArray(mesh.metadata?.uvSeams) ? mesh.metadata.uvSeams.length : 0;
|
|
868
|
+
if (!positions || !indices || !uvs || uvs.length === 0) {
|
|
869
|
+
return {
|
|
870
|
+
meshName: mesh?.name || 'None',
|
|
871
|
+
islandCount: 0,
|
|
872
|
+
seamEdgeCount,
|
|
873
|
+
worldSurfaceAreaM2: 0,
|
|
874
|
+
uvSurfaceArea: 0,
|
|
875
|
+
texelDensityPxPerMeter: 0,
|
|
876
|
+
uvCoveragePercent: 0,
|
|
877
|
+
overlapDetected: false,
|
|
878
|
+
textureResolution,
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
mesh.computeWorldMatrix(true);
|
|
882
|
+
const worldMat = mesh.getWorldMatrix();
|
|
883
|
+
const islands = this.extractUVIslands(positions, indices, uvs, worldMat);
|
|
884
|
+
let worldSurfaceAreaM2 = 0;
|
|
885
|
+
let uvSurfaceArea = 0;
|
|
886
|
+
for (const isl of islands) {
|
|
887
|
+
worldSurfaceAreaM2 += isl.worldArea;
|
|
888
|
+
uvSurfaceArea += isl.uvArea;
|
|
889
|
+
}
|
|
890
|
+
const texelDensityPxPerMeter = worldSurfaceAreaM2 > 1e-6
|
|
891
|
+
? Math.round(Math.sqrt(uvSurfaceArea / worldSurfaceAreaM2) * textureResolution)
|
|
892
|
+
: 0;
|
|
893
|
+
const uvCoveragePercent = Math.min(100, Math.round(uvSurfaceArea * 1000) / 10);
|
|
894
|
+
return {
|
|
895
|
+
meshName: mesh.name,
|
|
896
|
+
islandCount: islands.length,
|
|
897
|
+
seamEdgeCount,
|
|
898
|
+
worldSurfaceAreaM2: Math.round(worldSurfaceAreaM2 * 100) / 100,
|
|
899
|
+
uvSurfaceArea: Math.round(uvSurfaceArea * 1000) / 1000,
|
|
900
|
+
texelDensityPxPerMeter,
|
|
901
|
+
uvCoveragePercent,
|
|
902
|
+
overlapDetected: uvSurfaceArea > 1.05,
|
|
903
|
+
textureResolution,
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Toggles a high-contrast numbered UV Checkerboard preview material on the selected mesh.
|
|
908
|
+
*/
|
|
909
|
+
toggleCheckerPreview(mesh, forceState) {
|
|
910
|
+
const targetState = forceState !== undefined ? forceState : !this.checkerPreviewActive;
|
|
911
|
+
this.checkerPreviewActive = targetState;
|
|
912
|
+
if (targetState) {
|
|
913
|
+
if (!this.savedMaterials.has(mesh)) {
|
|
914
|
+
this.savedMaterials.set(mesh, mesh.material);
|
|
915
|
+
}
|
|
916
|
+
if (!this.checkerMaterial || this.checkerMaterial.getScene() !== this.scene) {
|
|
917
|
+
this.checkerMaterial = this.createCheckerboardMaterial();
|
|
918
|
+
}
|
|
919
|
+
mesh.material = this.checkerMaterial;
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
if (this.savedMaterials.has(mesh)) {
|
|
923
|
+
mesh.material = this.savedMaterials.get(mesh) || null;
|
|
924
|
+
this.savedMaterials.delete(mesh);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return this.checkerPreviewActive;
|
|
928
|
+
}
|
|
929
|
+
createCheckerboardMaterial() {
|
|
930
|
+
const mat = new StandardMaterial('editor_uv_checker_mat', this.scene);
|
|
931
|
+
const texSize = 512;
|
|
932
|
+
const dynTex = new DynamicTexture('editor_uv_checker_tex', texSize, this.scene, false);
|
|
933
|
+
const ctx = dynTex.getContext();
|
|
934
|
+
if (ctx) {
|
|
935
|
+
const cells = 8;
|
|
936
|
+
const cellSize = texSize / cells;
|
|
937
|
+
const palette = ['#2563eb', '#16a34a', '#d97706', '#dc2626', '#7c3aed', '#0891b2'];
|
|
938
|
+
for (let y = 0; y < cells; y++) {
|
|
939
|
+
for (let x = 0; x < cells; x++) {
|
|
940
|
+
const isEven = (x + y) % 2 === 0;
|
|
941
|
+
ctx.fillStyle = isEven ? '#1e293b' : '#0f172a';
|
|
942
|
+
ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
|
|
943
|
+
ctx.strokeStyle = palette[(x + y) % palette.length];
|
|
944
|
+
ctx.lineWidth = 2;
|
|
945
|
+
ctx.strokeRect(x * cellSize + 2, y * cellSize + 2, cellSize - 4, cellSize - 4);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
dynTex.update();
|
|
949
|
+
}
|
|
950
|
+
mat.diffuseTexture = dynTex;
|
|
951
|
+
mat.specularColor = new Color3(0.1, 0.1, 0.1);
|
|
952
|
+
mat.backFaceCulling = false;
|
|
953
|
+
return mat;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Renders the 2D UV map wireframe, islands, and grid into a <canvas> element.
|
|
957
|
+
*/
|
|
958
|
+
renderUVLayoutToCanvas(mesh, canvas) {
|
|
959
|
+
const ctx = canvas.getContext('2d');
|
|
960
|
+
if (!ctx)
|
|
961
|
+
return;
|
|
962
|
+
const w = canvas.width;
|
|
963
|
+
const h = canvas.height;
|
|
964
|
+
ctx.clearRect(0, 0, w, h);
|
|
965
|
+
// Draw dark background & UV grid
|
|
966
|
+
ctx.fillStyle = '#0d1117';
|
|
967
|
+
ctx.fillRect(0, 0, w, h);
|
|
968
|
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.07)';
|
|
969
|
+
ctx.lineWidth = 1;
|
|
970
|
+
const gridSteps = 8;
|
|
971
|
+
for (let i = 1; i < gridSteps; i++) {
|
|
972
|
+
const pos = (i / gridSteps) * w;
|
|
973
|
+
ctx.beginPath();
|
|
974
|
+
ctx.moveTo(pos, 0);
|
|
975
|
+
ctx.lineTo(pos, h);
|
|
976
|
+
ctx.stroke();
|
|
977
|
+
ctx.beginPath();
|
|
978
|
+
ctx.moveTo(0, pos);
|
|
979
|
+
ctx.lineTo(w, pos);
|
|
980
|
+
ctx.stroke();
|
|
981
|
+
}
|
|
982
|
+
// Draw [0, 1] border
|
|
983
|
+
ctx.strokeStyle = 'rgba(88, 166, 255, 0.35)';
|
|
984
|
+
ctx.strokeRect(0.5, 0.5, w - 1, h - 1);
|
|
985
|
+
if (!mesh || mesh.isDisposed())
|
|
986
|
+
return;
|
|
987
|
+
const uvs = mesh.getVerticesData(VertexBuffer.UVKind);
|
|
988
|
+
const indices = mesh.getIndices();
|
|
989
|
+
if (!uvs || !indices || uvs.length === 0)
|
|
990
|
+
return;
|
|
991
|
+
ctx.fillStyle = 'rgba(56, 189, 248, 0.16)';
|
|
992
|
+
ctx.strokeStyle = 'rgba(88, 166, 255, 0.78)';
|
|
993
|
+
ctx.lineWidth = 1;
|
|
994
|
+
const numTris = Math.floor(indices.length / 3);
|
|
995
|
+
for (let t = 0; t < numTris; t++) {
|
|
996
|
+
const i0 = indices[t * 3];
|
|
997
|
+
const i1 = indices[t * 3 + 1];
|
|
998
|
+
const i2 = indices[t * 3 + 2];
|
|
999
|
+
const x0 = uvs[i0 * 2] * w;
|
|
1000
|
+
const y0 = (1 - uvs[i0 * 2 + 1]) * h;
|
|
1001
|
+
const x1 = uvs[i1 * 2] * w;
|
|
1002
|
+
const y1 = (1 - uvs[i1 * 2 + 1]) * h;
|
|
1003
|
+
const x2 = uvs[i2 * 2] * w;
|
|
1004
|
+
const y2 = (1 - uvs[i2 * 2 + 1]) * h;
|
|
1005
|
+
ctx.beginPath();
|
|
1006
|
+
ctx.moveTo(x0, y0);
|
|
1007
|
+
ctx.lineTo(x1, y1);
|
|
1008
|
+
ctx.lineTo(x2, y2);
|
|
1009
|
+
ctx.closePath();
|
|
1010
|
+
ctx.fill();
|
|
1011
|
+
ctx.stroke();
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
dispose() {
|
|
1015
|
+
this.setActive(false);
|
|
1016
|
+
this.clearSeamOverlay();
|
|
1017
|
+
if (this.checkerMaterial) {
|
|
1018
|
+
this.checkerMaterial.dispose();
|
|
1019
|
+
this.checkerMaterial = null;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
//# sourceMappingURL=UVUnwrapController.js.map
|