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,1422 @@
|
|
|
1
|
+
import { Bone, Color3, Matrix, Mesh, MeshBuilder, PointerEventTypes, Quaternion, Skeleton, StandardMaterial, TransformNode, Vector3, VertexBuffer, VertexData, } from '@babylonjs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Controller for Skeleton Auto-Rigging, Envelope Skinning, Interactive 3D Weight Painting,
|
|
4
|
+
* Weight Heatmap Visualization, and Real-Time Bone Pose Testing.
|
|
5
|
+
*/
|
|
6
|
+
export class WeightPaintController {
|
|
7
|
+
service;
|
|
8
|
+
scene;
|
|
9
|
+
isActive = false;
|
|
10
|
+
brushMode = 'add';
|
|
11
|
+
radius = 0.35;
|
|
12
|
+
strength = 0.5;
|
|
13
|
+
targetWeight = 1.0;
|
|
14
|
+
symmetryX = true;
|
|
15
|
+
showHeatmap = true;
|
|
16
|
+
showBoneOverlay = true;
|
|
17
|
+
activeBoneIndex = 0;
|
|
18
|
+
isPainting = false;
|
|
19
|
+
activeMesh = null;
|
|
20
|
+
strokePreStates = new Map();
|
|
21
|
+
cursorRing = null;
|
|
22
|
+
boneOverlayMesh = null;
|
|
23
|
+
activeBoneMarker = null;
|
|
24
|
+
originalColorsMap = new Map();
|
|
25
|
+
originalVertexColorFlag = new Map();
|
|
26
|
+
originalMaterialMap = new Map();
|
|
27
|
+
heatmapMaterial = null;
|
|
28
|
+
onStateChanged;
|
|
29
|
+
onWeightsModified;
|
|
30
|
+
constructor(service) {
|
|
31
|
+
this.service = service;
|
|
32
|
+
this.scene = service.scene;
|
|
33
|
+
this.initCursor();
|
|
34
|
+
this.initPointerHandling();
|
|
35
|
+
}
|
|
36
|
+
initCursor() {
|
|
37
|
+
if (this.cursorRing)
|
|
38
|
+
return;
|
|
39
|
+
this.cursorRing = MeshBuilder.CreateDisc('editor_weight_paint_cursor', { radius: this.radius, tessellation: 36 }, this.scene);
|
|
40
|
+
const mat = new StandardMaterial('editor_weight_paint_cursor_mat', this.scene);
|
|
41
|
+
mat.diffuseColor = new Color3(1.0, 0.55, 0.15);
|
|
42
|
+
mat.emissiveColor = new Color3(1.0, 0.55, 0.15);
|
|
43
|
+
mat.wireframe = true;
|
|
44
|
+
mat.disableLighting = true;
|
|
45
|
+
mat.backFaceCulling = false;
|
|
46
|
+
this.cursorRing.material = mat;
|
|
47
|
+
this.cursorRing.isPickable = false;
|
|
48
|
+
this.cursorRing.isVisible = false;
|
|
49
|
+
}
|
|
50
|
+
setRadius(newRadius) {
|
|
51
|
+
this.radius = Math.max(0.02, Math.min(newRadius, 3.0));
|
|
52
|
+
const scale = this.radius / 0.35;
|
|
53
|
+
if (this.cursorRing && !this.cursorRing.isDisposed()) {
|
|
54
|
+
this.cursorRing.scaling.set(scale, scale, scale);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
setStrength(newStrength) {
|
|
58
|
+
this.strength = Math.max(0.02, Math.min(newStrength, 1.0));
|
|
59
|
+
}
|
|
60
|
+
setBrushMode(mode) {
|
|
61
|
+
this.brushMode = mode;
|
|
62
|
+
}
|
|
63
|
+
setActiveBoneIndex(index) {
|
|
64
|
+
this.activeBoneIndex = Math.max(0, index);
|
|
65
|
+
const mesh = this.getActiveTargetMesh();
|
|
66
|
+
if (mesh) {
|
|
67
|
+
const targets = this.getTargetMeshes(mesh);
|
|
68
|
+
if (this.showHeatmap && this.isActive) {
|
|
69
|
+
for (const t of targets) {
|
|
70
|
+
this.updateWeightHeatmap(t);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (this.showBoneOverlay && this.isActive) {
|
|
74
|
+
this.refreshBoneOverlay(mesh);
|
|
75
|
+
}
|
|
76
|
+
this.onWeightsModified?.(mesh, this.analyzeWeights(mesh));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
setActive(active) {
|
|
80
|
+
this.isActive = active;
|
|
81
|
+
if (this.cursorRing)
|
|
82
|
+
this.cursorRing.isVisible = false;
|
|
83
|
+
const canvas = this.service.canvas;
|
|
84
|
+
if (canvas) {
|
|
85
|
+
canvas.style.cursor = active ? 'crosshair' : 'default';
|
|
86
|
+
}
|
|
87
|
+
const mesh = this.getActiveTargetMesh();
|
|
88
|
+
const targets = this.getTargetMeshes(mesh);
|
|
89
|
+
if (active) {
|
|
90
|
+
if (this.service.sculptController?.isActive) {
|
|
91
|
+
this.service.sculptController.setActive(false);
|
|
92
|
+
}
|
|
93
|
+
if (this.service.voxelPainter?.isActive) {
|
|
94
|
+
this.service.voxelPainter.setActive(false);
|
|
95
|
+
}
|
|
96
|
+
if (this.service.pathExtrusion?.isActive) {
|
|
97
|
+
this.service.pathExtrusion.setActive(false);
|
|
98
|
+
}
|
|
99
|
+
if (this.service.uvUnwrapController?.isActive) {
|
|
100
|
+
this.service.uvUnwrapController.setActive(false);
|
|
101
|
+
}
|
|
102
|
+
this.service.gizmoManager?.attachToNode(null);
|
|
103
|
+
if (this.service.highlightLayer) {
|
|
104
|
+
this.service.highlightLayer.removeAllMeshes();
|
|
105
|
+
}
|
|
106
|
+
for (const t of targets) {
|
|
107
|
+
if (this.showHeatmap)
|
|
108
|
+
this.updateWeightHeatmap(t);
|
|
109
|
+
}
|
|
110
|
+
if (mesh && this.showBoneOverlay)
|
|
111
|
+
this.refreshBoneOverlay(mesh);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (this.isPainting) {
|
|
115
|
+
this.endPaintStroke();
|
|
116
|
+
}
|
|
117
|
+
const meshesToRestore = new Set([
|
|
118
|
+
...targets,
|
|
119
|
+
...this.originalColorsMap.keys(),
|
|
120
|
+
...this.originalMaterialMap.keys(),
|
|
121
|
+
]);
|
|
122
|
+
for (const m of meshesToRestore) {
|
|
123
|
+
if (!m.isDisposed())
|
|
124
|
+
this.restoreOriginalVertexColors(m);
|
|
125
|
+
}
|
|
126
|
+
this.clearBoneOverlay();
|
|
127
|
+
if (this.service.selectedMesh && !this.service.isGizmoMesh(this.service.selectedMesh)) {
|
|
128
|
+
this.service.gizmoManager?.attachToNode(this.service.selectedMesh);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.onStateChanged?.(active);
|
|
132
|
+
}
|
|
133
|
+
getActiveTargetMesh() {
|
|
134
|
+
if (this.service.selectedMesh &&
|
|
135
|
+
!this.service.isEditorHelper(this.service.selectedMesh) &&
|
|
136
|
+
!this.service.selectedMesh.isDisposed() &&
|
|
137
|
+
this.service.selectedMesh.getTotalVertices() > 0) {
|
|
138
|
+
return this.service.selectedMesh;
|
|
139
|
+
}
|
|
140
|
+
const first = this.service.importedMeshes.find((m) => !this.service.isEditorHelper(m) && !m.isDisposed() && m.getTotalVertices() > 0);
|
|
141
|
+
return first || null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns all meshes in the scene that share the same skeleton or character group as `primaryMesh`.
|
|
145
|
+
* Essential for multi-part models (e.g. Mario cap, head, body, hands, boots) so heatmaps,
|
|
146
|
+
* bone influence stats, and weight painting operate simultaneously across the entire character!
|
|
147
|
+
*/
|
|
148
|
+
getTargetMeshes(primaryMesh) {
|
|
149
|
+
const root = primaryMesh || this.getActiveTargetMesh();
|
|
150
|
+
if (!root || root.isDisposed())
|
|
151
|
+
return [];
|
|
152
|
+
const scene = root.getScene() || this.scene;
|
|
153
|
+
if (root.skeleton) {
|
|
154
|
+
const skel = root.skeleton;
|
|
155
|
+
const skinnedMeshes = scene.meshes.filter((m) => m instanceof Mesh &&
|
|
156
|
+
!m.isDisposed() &&
|
|
157
|
+
!this.service.isEditorHelper(m) &&
|
|
158
|
+
!this.service.isGizmoMesh(m) &&
|
|
159
|
+
m !== this.service.gridMesh &&
|
|
160
|
+
m.skeleton === skel &&
|
|
161
|
+
m.getTotalVertices() > 0);
|
|
162
|
+
if (skinnedMeshes.length > 0)
|
|
163
|
+
return skinnedMeshes;
|
|
164
|
+
}
|
|
165
|
+
if (this.service.selectedNodes.length > 1) {
|
|
166
|
+
const selected = this.service.selectedNodes.filter((m) => m instanceof Mesh &&
|
|
167
|
+
!m.isDisposed() &&
|
|
168
|
+
!this.service.isEditorHelper(m) &&
|
|
169
|
+
!this.service.isGizmoMesh(m) &&
|
|
170
|
+
m.getTotalVertices() > 0);
|
|
171
|
+
if (selected.includes(root))
|
|
172
|
+
return selected;
|
|
173
|
+
}
|
|
174
|
+
if (root.parent) {
|
|
175
|
+
const siblings = (root.parent.getChildMeshes() || []).filter((m) => m instanceof Mesh &&
|
|
176
|
+
!m.isDisposed() &&
|
|
177
|
+
!this.service.isEditorHelper(m) &&
|
|
178
|
+
!this.service.isGizmoMesh(m) &&
|
|
179
|
+
m !== this.service.gridMesh &&
|
|
180
|
+
m.getTotalVertices() > 0);
|
|
181
|
+
if (siblings.length > 1)
|
|
182
|
+
return siblings;
|
|
183
|
+
}
|
|
184
|
+
const visibleMeshes = this.service.importedMeshes.filter((m) => m instanceof Mesh &&
|
|
185
|
+
!this.service.isEditorHelper(m) &&
|
|
186
|
+
!this.service.isGizmoMesh(m) &&
|
|
187
|
+
!m.isDisposed() &&
|
|
188
|
+
m.isVisible &&
|
|
189
|
+
m.getTotalVertices() > 0);
|
|
190
|
+
if (visibleMeshes.length > 1 && visibleMeshes.includes(root)) {
|
|
191
|
+
return visibleMeshes;
|
|
192
|
+
}
|
|
193
|
+
return [root];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Generates a complete hierarchical game-ready Skeleton fitted to `mesh`'s bounding box
|
|
197
|
+
* and binds smooth capsule envelope weights (4 bone influences per vertex).
|
|
198
|
+
*/
|
|
199
|
+
createAutoRig(mesh, preset = 'humanoid') {
|
|
200
|
+
const targets = this.getTargetMeshes(mesh);
|
|
201
|
+
let minW = new Vector3(Infinity, Infinity, Infinity);
|
|
202
|
+
let maxW = new Vector3(-Infinity, -Infinity, -Infinity);
|
|
203
|
+
for (const t of targets) {
|
|
204
|
+
t.computeWorldMatrix(true);
|
|
205
|
+
t.refreshBoundingInfo();
|
|
206
|
+
const b = t.getBoundingInfo().boundingBox;
|
|
207
|
+
minW = Vector3.Minimize(minW, b.minimumWorld);
|
|
208
|
+
maxW = Vector3.Maximize(maxW, b.maximumWorld);
|
|
209
|
+
}
|
|
210
|
+
const width = Math.max(0.2, maxW.x - minW.x);
|
|
211
|
+
const height = Math.max(0.2, maxW.y - minW.y);
|
|
212
|
+
const depth = Math.max(0.2, maxW.z - minW.z);
|
|
213
|
+
const cx = (minW.x + maxW.x) * 0.5;
|
|
214
|
+
const cz = (minW.z + maxW.z) * 0.5;
|
|
215
|
+
const bottomY = minW.y;
|
|
216
|
+
const specs = [];
|
|
217
|
+
const addBone = (name, parentName, hx, hy, hz, tx, ty, tz) => {
|
|
218
|
+
const parentIndex = parentName ? specs.findIndex((s) => s.name === parentName) : -1;
|
|
219
|
+
specs.push({
|
|
220
|
+
name,
|
|
221
|
+
parentIndex,
|
|
222
|
+
headWorldPos: new Vector3(cx + hx * width * 0.5, bottomY + hy * height, cz + hz * depth * 0.5),
|
|
223
|
+
tailWorldPos: new Vector3(cx + tx * width * 0.5, bottomY + ty * height, cz + tz * depth * 0.5),
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
if (preset === 'humanoid') {
|
|
227
|
+
// 20-Bone Unreal / Unity Standard Humanoid Skeleton Hierarchy
|
|
228
|
+
addBone('Root', null, 0, 0.0, 0, 0, 0.48, 0);
|
|
229
|
+
addBone('Hips', 'Root', 0, 0.48, 0, 0, 0.56, 0);
|
|
230
|
+
addBone('Spine', 'Hips', 0, 0.56, 0, 0, 0.68, 0);
|
|
231
|
+
addBone('Chest', 'Spine', 0, 0.68, 0, 0, 0.80, 0);
|
|
232
|
+
addBone('Neck', 'Chest', 0, 0.80, 0, 0, 0.86, 0);
|
|
233
|
+
addBone('Head', 'Neck', 0, 0.86, 0, 0, 0.99, 0);
|
|
234
|
+
// Left Arm
|
|
235
|
+
addBone('Shoulder_L', 'Chest', 0.08, 0.78, 0, 0.24, 0.78, 0);
|
|
236
|
+
addBone('UpperArm_L', 'Shoulder_L', 0.24, 0.78, 0, 0.55, 0.76, 0);
|
|
237
|
+
addBone('ForeArm_L', 'UpperArm_L', 0.55, 0.76, 0, 0.82, 0.75, 0);
|
|
238
|
+
addBone('Hand_L', 'ForeArm_L', 0.82, 0.75, 0, 0.96, 0.75, 0);
|
|
239
|
+
// Right Arm
|
|
240
|
+
addBone('Shoulder_R', 'Chest', -0.08, 0.78, 0, -0.24, 0.78, 0);
|
|
241
|
+
addBone('UpperArm_R', 'Shoulder_R', -0.24, 0.78, 0, -0.55, 0.76, 0);
|
|
242
|
+
addBone('ForeArm_R', 'UpperArm_R', -0.55, 0.76, 0, -0.82, 0.75, 0);
|
|
243
|
+
addBone('Hand_R', 'ForeArm_R', -0.82, 0.75, 0, -0.96, 0.75, 0);
|
|
244
|
+
// Left Leg
|
|
245
|
+
addBone('UpLeg_L', 'Hips', 0.18, 0.48, 0, 0.19, 0.26, 0);
|
|
246
|
+
addBone('Leg_L', 'UpLeg_L', 0.19, 0.26, 0, 0.19, 0.05, 0);
|
|
247
|
+
addBone('Foot_L', 'Leg_L', 0.19, 0.05, 0, 0.19, 0.01, 0.25);
|
|
248
|
+
// Right Leg
|
|
249
|
+
addBone('UpLeg_R', 'Hips', -0.18, 0.48, 0, -0.19, 0.26, 0);
|
|
250
|
+
addBone('Leg_R', 'UpLeg_R', -0.19, 0.26, 0, -0.19, 0.05, 0);
|
|
251
|
+
addBone('Foot_R', 'Leg_R', -0.19, 0.05, 0, -0.19, 0.01, 0.25);
|
|
252
|
+
}
|
|
253
|
+
else if (preset === 'chibi') {
|
|
254
|
+
// 20-Bone Chibi / Cartoon / Stylized Biped (Large Head, Low Shoulder/Arm Axis, Short Legs)
|
|
255
|
+
// Perfectly proportioned for Mario, mascot figures, dwarfs & stylized heroes
|
|
256
|
+
addBone('Root', null, 0, 0.0, 0, 0, 0.36, 0);
|
|
257
|
+
addBone('Hips', 'Root', 0, 0.36, 0, 0, 0.44, 0);
|
|
258
|
+
addBone('Spine', 'Hips', 0, 0.44, 0, 0, 0.52, 0);
|
|
259
|
+
addBone('Chest', 'Spine', 0, 0.52, 0, 0, 0.59, 0);
|
|
260
|
+
addBone('Neck', 'Chest', 0, 0.59, 0, 0, 0.65, 0);
|
|
261
|
+
addBone('Head', 'Neck', 0, 0.65, 0, 0, 0.99, 0);
|
|
262
|
+
// Left Arm (horizontal line through sleeves at ~0.58-0.59)
|
|
263
|
+
addBone('Shoulder_L', 'Chest', 0.08, 0.59, 0, 0.22, 0.58, 0);
|
|
264
|
+
addBone('UpperArm_L', 'Shoulder_L', 0.22, 0.58, 0, 0.52, 0.58, 0);
|
|
265
|
+
addBone('ForeArm_L', 'UpperArm_L', 0.52, 0.58, 0, 0.78, 0.57, 0);
|
|
266
|
+
addBone('Hand_L', 'ForeArm_L', 0.78, 0.57, 0, 0.95, 0.57, 0);
|
|
267
|
+
// Right Arm
|
|
268
|
+
addBone('Shoulder_R', 'Chest', -0.08, 0.59, 0, -0.22, 0.58, 0);
|
|
269
|
+
addBone('UpperArm_R', 'Shoulder_R', -0.22, 0.58, 0, -0.52, 0.58, 0);
|
|
270
|
+
addBone('ForeArm_R', 'UpperArm_R', -0.52, 0.58, 0, -0.78, 0.57, 0);
|
|
271
|
+
addBone('Hand_R', 'ForeArm_R', -0.78, 0.57, 0, -0.95, 0.57, 0);
|
|
272
|
+
// Left Leg
|
|
273
|
+
addBone('UpLeg_L', 'Hips', 0.18, 0.36, 0, 0.19, 0.20, 0);
|
|
274
|
+
addBone('Leg_L', 'UpLeg_L', 0.19, 0.20, 0, 0.19, 0.05, 0);
|
|
275
|
+
addBone('Foot_L', 'Leg_L', 0.19, 0.05, 0, 0.19, 0.01, 0.25);
|
|
276
|
+
// Right Leg
|
|
277
|
+
addBone('UpLeg_R', 'Hips', -0.18, 0.36, 0, -0.19, 0.20, 0);
|
|
278
|
+
addBone('Leg_R', 'UpLeg_R', -0.19, 0.20, 0, -0.19, 0.05, 0);
|
|
279
|
+
addBone('Foot_R', 'Leg_R', -0.19, 0.05, 0, -0.19, 0.01, 0.25);
|
|
280
|
+
}
|
|
281
|
+
else if (preset === 'quadruped') {
|
|
282
|
+
addBone('Root', null, 0, 0.0, 0, 0, 0.55, -0.4);
|
|
283
|
+
addBone('Pelvis', 'Root', 0, 0.55, -0.4, 0, 0.58, -0.1);
|
|
284
|
+
addBone('Spine1', 'Pelvis', 0, 0.58, -0.1, 0, 0.60, 0.25);
|
|
285
|
+
addBone('Chest', 'Spine1', 0, 0.60, 0.25, 0, 0.64, 0.55);
|
|
286
|
+
addBone('Neck', 'Chest', 0, 0.64, 0.55, 0, 0.78, 0.75);
|
|
287
|
+
addBone('Head', 'Neck', 0, 0.78, 0.75, 0, 0.82, 0.96);
|
|
288
|
+
addBone('Tail', 'Pelvis', 0, 0.55, -0.4, 0, 0.45, -0.95);
|
|
289
|
+
// Front & Back Legs
|
|
290
|
+
addBone('FrontLeg_L', 'Chest', 0.35, 0.55, 0.45, 0.35, 0.02, 0.48);
|
|
291
|
+
addBone('FrontLeg_R', 'Chest', -0.35, 0.55, 0.45, -0.35, 0.02, 0.48);
|
|
292
|
+
addBone('BackLeg_L', 'Pelvis', 0.35, 0.55, -0.40, 0.35, 0.02, -0.42);
|
|
293
|
+
addBone('BackLeg_R', 'Pelvis', -0.35, 0.55, -0.40, -0.35, 0.02, -0.42);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// 5-Bone Articulated Spine / Prop Chain
|
|
297
|
+
addBone('Root', null, 0, 0.0, 0, 0, 0.2, 0);
|
|
298
|
+
addBone('Segment_1', 'Root', 0, 0.2, 0, 0, 0.45, 0);
|
|
299
|
+
addBone('Segment_2', 'Segment_1', 0, 0.45, 0, 0, 0.7, 0);
|
|
300
|
+
addBone('Segment_3', 'Segment_2', 0, 0.7, 0, 0, 0.9, 0);
|
|
301
|
+
addBone('Tip', 'Segment_3', 0, 0.9, 0, 0, 1.0, 0);
|
|
302
|
+
}
|
|
303
|
+
const skeleton = new Skeleton(`${mesh.name}_Skeleton`, `${mesh.name}_skel_id`, this.scene);
|
|
304
|
+
const createdBones = [];
|
|
305
|
+
const createdNodes = [];
|
|
306
|
+
const rootParent = mesh.parent;
|
|
307
|
+
let invParentMat = null;
|
|
308
|
+
if (rootParent && 'getWorldMatrix' in rootParent) {
|
|
309
|
+
rootParent.computeWorldMatrix(true);
|
|
310
|
+
invParentMat = Matrix.Invert(rootParent.getWorldMatrix());
|
|
311
|
+
}
|
|
312
|
+
for (let i = 0; i < specs.length; i++) {
|
|
313
|
+
const spec = specs[i];
|
|
314
|
+
const parentBone = spec.parentIndex >= 0 ? createdBones[spec.parentIndex] : null;
|
|
315
|
+
const parentNode = spec.parentIndex >= 0 ? createdNodes[spec.parentIndex] : rootParent;
|
|
316
|
+
const localOffset = spec.parentIndex >= 0
|
|
317
|
+
? spec.headWorldPos.subtract(specs[spec.parentIndex].headWorldPos)
|
|
318
|
+
: invParentMat
|
|
319
|
+
? Vector3.TransformCoordinates(spec.headWorldPos, invParentMat)
|
|
320
|
+
: spec.headWorldPos.clone();
|
|
321
|
+
const localMat = Matrix.Translation(localOffset.x, localOffset.y, localOffset.z);
|
|
322
|
+
const bone = new Bone(spec.name, skeleton, parentBone, localMat, localMat.clone());
|
|
323
|
+
const tNode = new TransformNode(spec.name, this.scene);
|
|
324
|
+
if (parentNode) {
|
|
325
|
+
tNode.parent = parentNode;
|
|
326
|
+
}
|
|
327
|
+
tNode.position.copyFrom(localOffset);
|
|
328
|
+
tNode.metadata = { isBoneNode: true, skeletonId: skeleton.id };
|
|
329
|
+
bone.linkTransformNode(tNode);
|
|
330
|
+
createdBones.push(bone);
|
|
331
|
+
createdNodes.push(tNode);
|
|
332
|
+
}
|
|
333
|
+
const serializedSpecs = specs.map((s) => ({
|
|
334
|
+
name: s.name,
|
|
335
|
+
parentIndex: s.parentIndex,
|
|
336
|
+
head: [s.headWorldPos.x, s.headWorldPos.y, s.headWorldPos.z],
|
|
337
|
+
tail: [s.tailWorldPos.x, s.tailWorldPos.y, s.tailWorldPos.z],
|
|
338
|
+
rotationDeg: [0, 0, 0],
|
|
339
|
+
}));
|
|
340
|
+
for (const t of targets) {
|
|
341
|
+
t.skeleton = skeleton;
|
|
342
|
+
if (!t.metadata)
|
|
343
|
+
t.metadata = {};
|
|
344
|
+
t.metadata.rigBoneSpecs = serializedSpecs;
|
|
345
|
+
const rawPos = t.getVerticesData(VertexBuffer.PositionKind);
|
|
346
|
+
if (rawPos) {
|
|
347
|
+
t.metadata.bindPosePositions = Array.from(rawPos);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
this.autoBindSkinWeights(mesh, skeleton);
|
|
351
|
+
this.activeBoneIndex = Math.min(1, specs.length - 1);
|
|
352
|
+
if (this.isActive) {
|
|
353
|
+
for (const t of targets) {
|
|
354
|
+
if (this.showHeatmap)
|
|
355
|
+
this.updateWeightHeatmap(t);
|
|
356
|
+
}
|
|
357
|
+
if (this.showBoneOverlay)
|
|
358
|
+
this.refreshBoneOverlay(mesh);
|
|
359
|
+
}
|
|
360
|
+
this.onWeightsModified?.(mesh, this.analyzeWeights(mesh));
|
|
361
|
+
return skeleton;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Computes automatic smooth envelope skin weights (4 influences per vertex, normalized to 1.0)
|
|
365
|
+
* across all target meshes sharing `mesh`'s character skeleton.
|
|
366
|
+
*/
|
|
367
|
+
autoBindSkinWeights(mesh, skeleton) {
|
|
368
|
+
const targets = this.getTargetMeshes(mesh);
|
|
369
|
+
const skel = skeleton || mesh.skeleton;
|
|
370
|
+
for (const t of targets) {
|
|
371
|
+
this.bindSingleMeshSkinWeights(t, t.skeleton || skel);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Binds skin weights to an individual mesh based on distance from world-space vertices
|
|
376
|
+
* to bone capsule segments.
|
|
377
|
+
*/
|
|
378
|
+
bindSingleMeshSkinWeights(mesh, skeleton) {
|
|
379
|
+
const skel = skeleton || mesh.skeleton;
|
|
380
|
+
if (!skel)
|
|
381
|
+
return;
|
|
382
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
383
|
+
if (!positions)
|
|
384
|
+
return;
|
|
385
|
+
const specs = this.getBoneSegments(mesh, skel);
|
|
386
|
+
if (specs.length === 0)
|
|
387
|
+
return;
|
|
388
|
+
mesh.computeWorldMatrix(true);
|
|
389
|
+
const worldMat = mesh.getWorldMatrix();
|
|
390
|
+
const numVerts = Math.floor(positions.length / 3);
|
|
391
|
+
const matrixIndices = new Float32Array(numVerts * 4);
|
|
392
|
+
const matrixWeights = new Float32Array(numVerts * 4);
|
|
393
|
+
const vLocal = new Vector3();
|
|
394
|
+
const vPos = new Vector3();
|
|
395
|
+
for (let i = 0; i < numVerts; i++) {
|
|
396
|
+
vLocal.set(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]);
|
|
397
|
+
Vector3.TransformCoordinatesToRef(vLocal, worldMat, vPos);
|
|
398
|
+
// Calculate inverse-distance-fourth weights to all bones
|
|
399
|
+
const influences = [];
|
|
400
|
+
for (let b = 0; b < specs.length; b++) {
|
|
401
|
+
const seg = specs[b];
|
|
402
|
+
const dist = this.distancePointToSegment(vPos, seg.headWorldPos, seg.tailWorldPos);
|
|
403
|
+
const w = 1.0 / Math.pow(dist + 0.04, 3.2);
|
|
404
|
+
influences.push({ boneIdx: b, weight: w });
|
|
405
|
+
}
|
|
406
|
+
// Sort descending and pick top 4 bone influences
|
|
407
|
+
influences.sort((a, b) => b.weight - a.weight);
|
|
408
|
+
const top4 = influences.slice(0, 4);
|
|
409
|
+
while (top4.length < 4) {
|
|
410
|
+
top4.push({ boneIdx: 0, weight: 0 });
|
|
411
|
+
}
|
|
412
|
+
const sum = top4[0].weight + top4[1].weight + top4[2].weight + top4[3].weight || 1;
|
|
413
|
+
for (let k = 0; k < 4; k++) {
|
|
414
|
+
matrixIndices[i * 4 + k] = top4[k].boneIdx;
|
|
415
|
+
matrixWeights[i * 4 + k] = top4[k].weight / sum;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
this.setMeshMatrixIndices(mesh, matrixIndices);
|
|
419
|
+
mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, matrixWeights, true);
|
|
420
|
+
if (this.isActive && this.showHeatmap) {
|
|
421
|
+
this.updateWeightHeatmap(mesh);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
getBoneSegments(mesh, skeleton) {
|
|
425
|
+
const skel = skeleton || mesh.skeleton;
|
|
426
|
+
if (!skel)
|
|
427
|
+
return [];
|
|
428
|
+
if (Array.isArray(mesh.metadata?.rigBoneSpecs) && mesh.metadata.rigBoneSpecs.length === skel.bones.length) {
|
|
429
|
+
return mesh.metadata.rigBoneSpecs.map((s) => ({
|
|
430
|
+
name: s.name,
|
|
431
|
+
parentIndex: s.parentIndex,
|
|
432
|
+
headWorldPos: new Vector3(s.head[0], s.head[1], s.head[2]),
|
|
433
|
+
tailWorldPos: new Vector3(s.tail[0], s.tail[1], s.tail[2]),
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
// Check if any sibling mesh sharing this skeleton has stored rigBoneSpecs
|
|
437
|
+
const scene = mesh.getScene() || this.scene;
|
|
438
|
+
const siblingWithSpecs = scene.meshes.find((m) => m instanceof Mesh &&
|
|
439
|
+
m.skeleton === skel &&
|
|
440
|
+
Array.isArray(m.metadata?.rigBoneSpecs) &&
|
|
441
|
+
m.metadata.rigBoneSpecs.length === skel.bones.length);
|
|
442
|
+
if (siblingWithSpecs) {
|
|
443
|
+
return siblingWithSpecs.metadata.rigBoneSpecs.map((s) => ({
|
|
444
|
+
name: s.name,
|
|
445
|
+
parentIndex: s.parentIndex,
|
|
446
|
+
headWorldPos: new Vector3(s.head[0], s.head[1], s.head[2]),
|
|
447
|
+
tailWorldPos: new Vector3(s.tail[0], s.tail[1], s.tail[2]),
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
// Fallback for imported GLTF skeletons
|
|
451
|
+
const bones = skel.bones;
|
|
452
|
+
const specs = [];
|
|
453
|
+
for (let i = 0; i < bones.length; i++) {
|
|
454
|
+
const b = bones[i];
|
|
455
|
+
const pIdx = b.getParent() ? bones.indexOf(b.getParent()) : -1;
|
|
456
|
+
const tNode = b.getTransformNode();
|
|
457
|
+
const pos = tNode ? tNode.getAbsolutePosition().clone() : b.getAbsolutePosition();
|
|
458
|
+
const child = bones.find((c) => c.getParent() === b);
|
|
459
|
+
const childTNode = child?.getTransformNode();
|
|
460
|
+
const tail = childTNode
|
|
461
|
+
? childTNode.getAbsolutePosition().clone()
|
|
462
|
+
: child
|
|
463
|
+
? child.getAbsolutePosition()
|
|
464
|
+
: pos.add(new Vector3(0, 0.15, 0));
|
|
465
|
+
specs.push({
|
|
466
|
+
name: b.name || `Bone_${i}`,
|
|
467
|
+
parentIndex: pIdx,
|
|
468
|
+
headWorldPos: pos.clone(),
|
|
469
|
+
tailWorldPos: tail.clone(),
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return specs;
|
|
473
|
+
}
|
|
474
|
+
distancePointToSegment(p, a, b) {
|
|
475
|
+
const ab = b.subtract(a);
|
|
476
|
+
const lenSq = ab.lengthSquared();
|
|
477
|
+
if (lenSq < 1e-10)
|
|
478
|
+
return Vector3.Distance(p, a);
|
|
479
|
+
const t = Math.max(0, Math.min(1, Vector3.Dot(p.subtract(a), ab) / lenSq));
|
|
480
|
+
const proj = a.add(ab.scale(t));
|
|
481
|
+
return Vector3.Distance(p, proj);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Returns the effective weight [0, 1] of `boneIndex` at vertex `vertexIndex`.
|
|
485
|
+
*/
|
|
486
|
+
getVertexBoneWeight(indicesData, weightsData, vertexIndex, boneIndex) {
|
|
487
|
+
let total = 0;
|
|
488
|
+
const base = vertexIndex * 4;
|
|
489
|
+
for (let k = 0; k < 4; k++) {
|
|
490
|
+
if (Math.round(indicesData[base + k]) === boneIndex) {
|
|
491
|
+
total += weightsData[base + k];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return Math.max(0, Math.min(1, total));
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Sets the weight of `boneIndex` on vertex `vertexIndex` to `newWeight` and automatically
|
|
498
|
+
* normalizes all 4 bone weights on that vertex so their sum equals 1.0.
|
|
499
|
+
*/
|
|
500
|
+
setVertexBoneWeightNormalized(indicesData, weightsData, vertexIndex, boneIndex, newWeight) {
|
|
501
|
+
const clampedTarget = Math.max(0, Math.min(1, newWeight));
|
|
502
|
+
const base = vertexIndex * 4;
|
|
503
|
+
// Collect existing 4 slots
|
|
504
|
+
const slots = [];
|
|
505
|
+
let targetSlotIdx = -1;
|
|
506
|
+
for (let k = 0; k < 4; k++) {
|
|
507
|
+
const b = Math.round(indicesData[base + k]);
|
|
508
|
+
const w = Math.max(0, weightsData[base + k]);
|
|
509
|
+
if (b === boneIndex && targetSlotIdx === -1) {
|
|
510
|
+
targetSlotIdx = k;
|
|
511
|
+
}
|
|
512
|
+
slots.push({ bone: b, weight: w });
|
|
513
|
+
}
|
|
514
|
+
if (targetSlotIdx === -1) {
|
|
515
|
+
// Replace the slot with the smallest weight
|
|
516
|
+
let minIdx = 0;
|
|
517
|
+
for (let k = 1; k < 4; k++) {
|
|
518
|
+
if (slots[k].weight < slots[minIdx].weight) {
|
|
519
|
+
minIdx = k;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
targetSlotIdx = minIdx;
|
|
523
|
+
slots[targetSlotIdx].bone = boneIndex;
|
|
524
|
+
}
|
|
525
|
+
slots[targetSlotIdx].weight = clampedTarget;
|
|
526
|
+
// Normalize the remaining 3 slots so total sum = 1.0
|
|
527
|
+
let otherSum = 0;
|
|
528
|
+
for (let k = 0; k < 4; k++) {
|
|
529
|
+
if (k !== targetSlotIdx)
|
|
530
|
+
otherSum += slots[k].weight;
|
|
531
|
+
}
|
|
532
|
+
const remainder = Math.max(0, 1.0 - clampedTarget);
|
|
533
|
+
if (otherSum > 1e-6) {
|
|
534
|
+
const scale = remainder / otherSum;
|
|
535
|
+
for (let k = 0; k < 4; k++) {
|
|
536
|
+
if (k !== targetSlotIdx) {
|
|
537
|
+
slots[k].weight *= scale;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else if (remainder > 1e-6) {
|
|
542
|
+
// Assign remaining weight to root bone (0) or another slot
|
|
543
|
+
const fallbackSlot = targetSlotIdx === 0 ? 1 : 0;
|
|
544
|
+
if (slots[fallbackSlot].bone === boneIndex) {
|
|
545
|
+
slots[fallbackSlot].bone = boneIndex === 0 ? 1 : 0;
|
|
546
|
+
}
|
|
547
|
+
slots[fallbackSlot].weight = remainder;
|
|
548
|
+
}
|
|
549
|
+
for (let k = 0; k < 4; k++) {
|
|
550
|
+
indicesData[base + k] = slots[k].bone;
|
|
551
|
+
weightsData[base + k] = slots[k].weight;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Applies a 3D Weight Paint brush stroke (Add, Subtract, Smooth, or Replace) at `worldHitPoint`.
|
|
556
|
+
* Automatically targets all parts of the character sharing the skeleton so painting seamlessly
|
|
557
|
+
* deforms vertices across mesh seams without borders.
|
|
558
|
+
*/
|
|
559
|
+
applyWeightBrushStroke(mesh, worldHitPoint, boneIndex = this.activeBoneIndex) {
|
|
560
|
+
const targets = this.getTargetMeshes(mesh);
|
|
561
|
+
let totalModified = 0;
|
|
562
|
+
for (const target of targets) {
|
|
563
|
+
totalModified += this.paintSingleMesh(target, worldHitPoint, boneIndex);
|
|
564
|
+
}
|
|
565
|
+
if (this.showHeatmap) {
|
|
566
|
+
for (const target of targets) {
|
|
567
|
+
this.updateSingleMeshHeatmap(target, boneIndex);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
this.onWeightsModified?.(mesh, this.analyzeWeights(mesh));
|
|
571
|
+
return totalModified;
|
|
572
|
+
}
|
|
573
|
+
paintSingleMesh(mesh, worldHitPoint, boneIndex) {
|
|
574
|
+
if (!mesh.skeleton) {
|
|
575
|
+
const skel = this.getActiveTargetMesh()?.skeleton;
|
|
576
|
+
if (skel)
|
|
577
|
+
mesh.skeleton = skel;
|
|
578
|
+
else
|
|
579
|
+
this.createAutoRig(mesh, 'humanoid');
|
|
580
|
+
}
|
|
581
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
582
|
+
let mIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
583
|
+
let mWeights = mesh.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
584
|
+
if (!positions)
|
|
585
|
+
return 0;
|
|
586
|
+
if (!mIndices || !mWeights) {
|
|
587
|
+
this.bindSingleMeshSkinWeights(mesh, mesh.skeleton);
|
|
588
|
+
mIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
589
|
+
mWeights = mesh.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
590
|
+
}
|
|
591
|
+
if (!mIndices || !mWeights)
|
|
592
|
+
return 0;
|
|
593
|
+
const indicesArr = new Float32Array(mIndices);
|
|
594
|
+
const weightsArr = new Float32Array(mWeights);
|
|
595
|
+
mesh.computeWorldMatrix(true);
|
|
596
|
+
const invWorld = mesh.getWorldMatrix().clone().invert();
|
|
597
|
+
const localHit = Vector3.TransformCoordinates(worldHitPoint, invWorld);
|
|
598
|
+
const row0 = mesh.getWorldMatrix().getRow(0);
|
|
599
|
+
const worldScale = row0 ? Math.max(0.001, Math.sqrt(row0.x * row0.x + row0.y * row0.y + row0.z * row0.z)) : 1.0;
|
|
600
|
+
const localRadius = this.radius / worldScale;
|
|
601
|
+
const localRadiusSq = localRadius * localRadius;
|
|
602
|
+
// Quick bounding box check: if localHit is far outside this mesh's bounding box, skip it
|
|
603
|
+
const bbox = mesh.getBoundingInfo().boundingBox;
|
|
604
|
+
if (localHit.x < bbox.minimum.x - localRadius ||
|
|
605
|
+
localHit.x > bbox.maximum.x + localRadius ||
|
|
606
|
+
localHit.y < bbox.minimum.y - localRadius ||
|
|
607
|
+
localHit.y > bbox.maximum.y + localRadius ||
|
|
608
|
+
localHit.z < bbox.minimum.z - localRadius ||
|
|
609
|
+
localHit.z > bbox.maximum.z + localRadius) {
|
|
610
|
+
return 0;
|
|
611
|
+
}
|
|
612
|
+
// Identify mirrored bone index if symmetryX is enabled (e.g. UpperArm_L <-> UpperArm_R)
|
|
613
|
+
let mirrorBoneIndex = boneIndex;
|
|
614
|
+
if (this.symmetryX && mesh.skeleton) {
|
|
615
|
+
const activeBoneName = mesh.skeleton.bones[boneIndex]?.name || '';
|
|
616
|
+
let mirrorName = '';
|
|
617
|
+
if (activeBoneName.endsWith('_L')) {
|
|
618
|
+
mirrorName = activeBoneName.slice(0, -2) + '_R';
|
|
619
|
+
}
|
|
620
|
+
else if (activeBoneName.endsWith('_R')) {
|
|
621
|
+
mirrorName = activeBoneName.slice(0, -2) + '_L';
|
|
622
|
+
}
|
|
623
|
+
if (mirrorName) {
|
|
624
|
+
const foundIdx = mesh.skeleton.bones.findIndex((b) => b.name === mirrorName);
|
|
625
|
+
if (foundIdx !== -1)
|
|
626
|
+
mirrorBoneIndex = foundIdx;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const numVerts = Math.floor(positions.length / 3);
|
|
630
|
+
let modifiedCount = 0;
|
|
631
|
+
const paintAroundLocalPoint = (center, targetBone) => {
|
|
632
|
+
// Precompute average weight in brush radius if mode === 'smooth'
|
|
633
|
+
let avgBrushWeight = 0;
|
|
634
|
+
let inRadiusCount = 0;
|
|
635
|
+
if (this.brushMode === 'smooth') {
|
|
636
|
+
for (let i = 0; i < numVerts; i++) {
|
|
637
|
+
const dx = positions[i * 3] - center.x;
|
|
638
|
+
const dy = positions[i * 3 + 1] - center.y;
|
|
639
|
+
const dz = positions[i * 3 + 2] - center.z;
|
|
640
|
+
if (dx * dx + dy * dy + dz * dz <= localRadiusSq) {
|
|
641
|
+
avgBrushWeight += this.getVertexBoneWeight(indicesArr, weightsArr, i, targetBone);
|
|
642
|
+
inRadiusCount++;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (inRadiusCount > 0)
|
|
646
|
+
avgBrushWeight /= inRadiusCount;
|
|
647
|
+
}
|
|
648
|
+
for (let i = 0; i < numVerts; i++) {
|
|
649
|
+
const dx = positions[i * 3] - center.x;
|
|
650
|
+
const dy = positions[i * 3 + 1] - center.y;
|
|
651
|
+
const dz = positions[i * 3 + 2] - center.z;
|
|
652
|
+
const distSq = dx * dx + dy * dy + dz * dz;
|
|
653
|
+
if (distSq > localRadiusSq)
|
|
654
|
+
continue;
|
|
655
|
+
const dist = Math.sqrt(distSq);
|
|
656
|
+
const falloff = 0.5 * (1.0 + Math.cos((dist / localRadius) * Math.PI));
|
|
657
|
+
const currW = this.getVertexBoneWeight(indicesArr, weightsArr, i, targetBone);
|
|
658
|
+
let nextW = currW;
|
|
659
|
+
const delta = Math.min(1.0, this.strength * falloff * 0.8);
|
|
660
|
+
if (this.brushMode === 'add') {
|
|
661
|
+
nextW = Math.min(1.0, currW + delta);
|
|
662
|
+
}
|
|
663
|
+
else if (this.brushMode === 'subtract') {
|
|
664
|
+
nextW = Math.max(0.0, currW - delta);
|
|
665
|
+
}
|
|
666
|
+
else if (this.brushMode === 'replace') {
|
|
667
|
+
nextW = currW + (this.targetWeight - currW) * Math.min(1.0, this.strength * falloff);
|
|
668
|
+
}
|
|
669
|
+
else if (this.brushMode === 'smooth') {
|
|
670
|
+
nextW = currW + (avgBrushWeight - currW) * Math.min(1.0, this.strength * falloff * 0.75);
|
|
671
|
+
}
|
|
672
|
+
this.setVertexBoneWeightNormalized(indicesArr, weightsArr, i, targetBone, nextW);
|
|
673
|
+
modifiedCount++;
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
paintAroundLocalPoint(localHit, boneIndex);
|
|
677
|
+
if (this.symmetryX && Math.abs(localHit.x) > 0.02) {
|
|
678
|
+
const symLocalHit = new Vector3(-localHit.x, localHit.y, localHit.z);
|
|
679
|
+
paintAroundLocalPoint(symLocalHit, mirrorBoneIndex);
|
|
680
|
+
}
|
|
681
|
+
if (modifiedCount > 0) {
|
|
682
|
+
this.setMeshMatrixIndices(mesh, indicesArr);
|
|
683
|
+
mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, weightsArr, true);
|
|
684
|
+
}
|
|
685
|
+
return modifiedCount;
|
|
686
|
+
}
|
|
687
|
+
getOrCreateHeatmapMaterial(targetScene = this.scene) {
|
|
688
|
+
if (targetScene !== this.scene) {
|
|
689
|
+
const mat = new StandardMaterial('editor_weight_heatmap_mat', targetScene);
|
|
690
|
+
mat.disableLighting = true;
|
|
691
|
+
mat.emissiveColor = new Color3(1, 1, 1);
|
|
692
|
+
mat.diffuseColor = new Color3(1, 1, 1);
|
|
693
|
+
mat.backFaceCulling = false;
|
|
694
|
+
return mat;
|
|
695
|
+
}
|
|
696
|
+
if (!this.heatmapMaterial || this.heatmapMaterial._isDisposed) {
|
|
697
|
+
this.heatmapMaterial = new StandardMaterial('editor_weight_heatmap_mat', this.scene);
|
|
698
|
+
this.heatmapMaterial.disableLighting = true;
|
|
699
|
+
this.heatmapMaterial.emissiveColor = new Color3(1, 1, 1);
|
|
700
|
+
this.heatmapMaterial.diffuseColor = new Color3(1, 1, 1);
|
|
701
|
+
this.heatmapMaterial.backFaceCulling = false;
|
|
702
|
+
}
|
|
703
|
+
return this.heatmapMaterial;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Updates the real-time Vertex Color Weight Heatmap (Blue 0.0 -> Cyan -> Green -> Yellow -> Red 1.0)
|
|
707
|
+
* on all target meshes for `activeBoneIndex`.
|
|
708
|
+
*/
|
|
709
|
+
updateWeightHeatmap(mesh, boneIndex = this.activeBoneIndex) {
|
|
710
|
+
const targets = this.getTargetMeshes(mesh);
|
|
711
|
+
for (const t of targets) {
|
|
712
|
+
this.updateSingleMeshHeatmap(t, boneIndex);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
updateSingleMeshHeatmap(mesh, boneIndex) {
|
|
716
|
+
const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
717
|
+
const mIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
718
|
+
const mWeights = mesh.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
719
|
+
if (!positions)
|
|
720
|
+
return;
|
|
721
|
+
if (!this.originalColorsMap.has(mesh)) {
|
|
722
|
+
const existingColors = mesh.getVerticesData(VertexBuffer.ColorKind);
|
|
723
|
+
this.originalColorsMap.set(mesh, existingColors ? Array.from(existingColors) : null);
|
|
724
|
+
this.originalVertexColorFlag.set(mesh, mesh.useVertexColors);
|
|
725
|
+
}
|
|
726
|
+
if (!this.originalMaterialMap.has(mesh) && mesh.material) {
|
|
727
|
+
this.originalMaterialMap.set(mesh, mesh.material);
|
|
728
|
+
}
|
|
729
|
+
// Switch to pure unlit vertex color heatmap material so dark textures never turn black
|
|
730
|
+
mesh.material = this.getOrCreateHeatmapMaterial(mesh.getScene() || this.scene);
|
|
731
|
+
// Remove selection highlight glow so it does not drown out the heatmap colors with bright blue
|
|
732
|
+
if (this.service.highlightLayer) {
|
|
733
|
+
this.service.highlightLayer.removeMesh(mesh);
|
|
734
|
+
}
|
|
735
|
+
const numVerts = Math.floor(positions.length / 3);
|
|
736
|
+
const colors = new Float32Array(numVerts * 4);
|
|
737
|
+
for (let i = 0; i < numVerts; i++) {
|
|
738
|
+
const w = mIndices && mWeights
|
|
739
|
+
? this.getVertexBoneWeight(mIndices, mWeights, i, boneIndex)
|
|
740
|
+
: 0;
|
|
741
|
+
const [r, g, b] = this.weightToHeatmapRGB(w);
|
|
742
|
+
colors[i * 4] = r;
|
|
743
|
+
colors[i * 4 + 1] = g;
|
|
744
|
+
colors[i * 4 + 2] = b;
|
|
745
|
+
colors[i * 4 + 3] = 1.0;
|
|
746
|
+
}
|
|
747
|
+
mesh.setVerticesData(VertexBuffer.ColorKind, colors, true);
|
|
748
|
+
mesh.useVertexColors = true;
|
|
749
|
+
}
|
|
750
|
+
restoreOriginalVertexColors(mesh) {
|
|
751
|
+
const targets = mesh ? this.getTargetMeshes(mesh) : Array.from(this.originalMaterialMap.keys());
|
|
752
|
+
for (const t of targets) {
|
|
753
|
+
this.restoreSingleMeshVertexColors(t);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
restoreSingleMeshVertexColors(mesh) {
|
|
757
|
+
if (this.originalMaterialMap.has(mesh)) {
|
|
758
|
+
mesh.material = this.originalMaterialMap.get(mesh);
|
|
759
|
+
this.originalMaterialMap.delete(mesh);
|
|
760
|
+
}
|
|
761
|
+
if (this.originalColorsMap.has(mesh)) {
|
|
762
|
+
const orig = this.originalColorsMap.get(mesh);
|
|
763
|
+
const origFlag = this.originalVertexColorFlag.get(mesh) ?? false;
|
|
764
|
+
if (orig) {
|
|
765
|
+
mesh.setVerticesData(VertexBuffer.ColorKind, orig, true);
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
mesh.removeVerticesData(VertexBuffer.ColorKind);
|
|
769
|
+
}
|
|
770
|
+
mesh.useVertexColors = origFlag;
|
|
771
|
+
this.originalColorsMap.delete(mesh);
|
|
772
|
+
this.originalVertexColorFlag.delete(mesh);
|
|
773
|
+
}
|
|
774
|
+
if (this.service.selectedMesh === mesh && this.service.highlightLayer && !this.isActive) {
|
|
775
|
+
this.service.highlightLayer.addMesh(mesh, new Color3(0.2, 0.6, 1.0));
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
weightToHeatmapRGB(w) {
|
|
779
|
+
const t = Math.max(0, Math.min(1, w));
|
|
780
|
+
if (t < 0.25) {
|
|
781
|
+
const k = t / 0.25;
|
|
782
|
+
return [0.08 * (1 - k) + 0.05 * k, 0.20 * (1 - k) + 0.78 * k, 0.85 * (1 - k) + 0.92 * k];
|
|
783
|
+
}
|
|
784
|
+
else if (t < 0.5) {
|
|
785
|
+
const k = (t - 0.25) / 0.25;
|
|
786
|
+
return [0.05 * (1 - k) + 0.15 * k, 0.78 * (1 - k) + 0.88 * k, 0.92 * (1 - k) + 0.20 * k];
|
|
787
|
+
}
|
|
788
|
+
else if (t < 0.75) {
|
|
789
|
+
const k = (t - 0.5) / 0.25;
|
|
790
|
+
return [0.15 * (1 - k) + 0.96 * k, 0.88 * (1 - k) + 0.86 * k, 0.20 * (1 - k) + 0.08 * k];
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
const k = (t - 0.75) / 0.25;
|
|
794
|
+
return [0.96 * (1 - k) + 0.96 * k, 0.86 * (1 - k) + 0.14 * k, 0.08 * (1 - k) + 0.10 * k];
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Rotates the active bone (and its descendant bone chain) by `(pitchDeg, yawDeg, rollDeg)` and
|
|
799
|
+
* deforms all target character meshes using Linear Blend Skinning (LBS) so the artist can test joint deformation!
|
|
800
|
+
*/
|
|
801
|
+
poseActiveBone(mesh, pitchDeg, yawDeg = 0, rollDeg = 0) {
|
|
802
|
+
const targets = this.getTargetMeshes(mesh);
|
|
803
|
+
for (const t of targets) {
|
|
804
|
+
this.poseSingleMeshActiveBone(t, pitchDeg, yawDeg, rollDeg);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
poseSingleMeshActiveBone(mesh, pitchDeg, yawDeg = 0, rollDeg = 0) {
|
|
808
|
+
if (!mesh.skeleton)
|
|
809
|
+
return;
|
|
810
|
+
const specs = this.getBoneSegments(mesh, mesh.skeleton);
|
|
811
|
+
if (specs.length === 0 || this.activeBoneIndex >= specs.length)
|
|
812
|
+
return;
|
|
813
|
+
const rawPos = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
814
|
+
if (!rawPos)
|
|
815
|
+
return;
|
|
816
|
+
if (!mesh.metadata)
|
|
817
|
+
mesh.metadata = {};
|
|
818
|
+
if (!mesh.metadata.bindPosePositions || mesh.metadata.bindPosePositions.length !== rawPos.length) {
|
|
819
|
+
mesh.metadata.bindPosePositions = Array.from(rawPos);
|
|
820
|
+
}
|
|
821
|
+
const bindPos = mesh.metadata.bindPosePositions;
|
|
822
|
+
const mIndices = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
823
|
+
const mWeights = mesh.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
824
|
+
if (!mIndices || !mWeights)
|
|
825
|
+
return;
|
|
826
|
+
// Find all descendant bones of activeBoneIndex (including activeBoneIndex itself)
|
|
827
|
+
const affectedBones = new Set([this.activeBoneIndex]);
|
|
828
|
+
let added = true;
|
|
829
|
+
while (added) {
|
|
830
|
+
added = false;
|
|
831
|
+
for (let i = 0; i < specs.length; i++) {
|
|
832
|
+
if (!affectedBones.has(i) && specs[i].parentIndex >= 0 && affectedBones.has(specs[i].parentIndex)) {
|
|
833
|
+
affectedBones.add(i);
|
|
834
|
+
added = true;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
mesh.computeWorldMatrix(true);
|
|
839
|
+
const invWorld = mesh.getWorldMatrix().clone().invert();
|
|
840
|
+
const pivot = Vector3.TransformCoordinates(specs[this.activeBoneIndex].headWorldPos, invWorld);
|
|
841
|
+
const quat = Quaternion.FromEulerAngles((pitchDeg * Math.PI) / 180, (yawDeg * Math.PI) / 180, (rollDeg * Math.PI) / 180);
|
|
842
|
+
const rotMat = new Matrix();
|
|
843
|
+
quat.toRotationMatrix(rotMat);
|
|
844
|
+
const numVerts = Math.floor(bindPos.length / 3);
|
|
845
|
+
const deformed = new Float32Array(bindPos.length);
|
|
846
|
+
const pOrig = new Vector3();
|
|
847
|
+
const pRot = new Vector3();
|
|
848
|
+
for (let i = 0; i < numVerts; i++) {
|
|
849
|
+
pOrig.set(bindPos[i * 3], bindPos[i * 3 + 1], bindPos[i * 3 + 2]);
|
|
850
|
+
let affectedWeight = 0;
|
|
851
|
+
const base = i * 4;
|
|
852
|
+
for (let k = 0; k < 4; k++) {
|
|
853
|
+
const bIdx = Math.round(mIndices[base + k]);
|
|
854
|
+
if (affectedBones.has(bIdx)) {
|
|
855
|
+
affectedWeight += mWeights[base + k];
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (affectedWeight <= 1e-5) {
|
|
859
|
+
deformed[i * 3] = pOrig.x;
|
|
860
|
+
deformed[i * 3 + 1] = pOrig.y;
|
|
861
|
+
deformed[i * 3 + 2] = pOrig.z;
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
const rel = pOrig.subtract(pivot);
|
|
865
|
+
Vector3.TransformCoordinatesToRef(rel, rotMat, pRot);
|
|
866
|
+
pRot.addInPlace(pivot);
|
|
867
|
+
const blended = Vector3.Lerp(pOrig, pRot, Math.min(1, affectedWeight));
|
|
868
|
+
deformed[i * 3] = blended.x;
|
|
869
|
+
deformed[i * 3 + 1] = blended.y;
|
|
870
|
+
deformed[i * 3 + 2] = blended.z;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
mesh.setVerticesData(VertexBuffer.PositionKind, deformed, true);
|
|
874
|
+
const indices = mesh.getIndices();
|
|
875
|
+
if (indices) {
|
|
876
|
+
const norms = [];
|
|
877
|
+
VertexData.ComputeNormals(deformed, indices, norms);
|
|
878
|
+
mesh.setVerticesData(VertexBuffer.NormalKind, norms, true);
|
|
879
|
+
}
|
|
880
|
+
mesh.refreshBoundingInfo();
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Restores all target character meshes back to clean Bind Pose (T-Pose / rest pose).
|
|
884
|
+
*/
|
|
885
|
+
resetBindPose(mesh) {
|
|
886
|
+
const targets = this.getTargetMeshes(mesh);
|
|
887
|
+
for (const t of targets) {
|
|
888
|
+
this.resetSingleMeshBindPose(t);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
resetSingleMeshBindPose(mesh) {
|
|
892
|
+
const bindPos = mesh.metadata?.bindPosePositions;
|
|
893
|
+
if (!bindPos)
|
|
894
|
+
return;
|
|
895
|
+
mesh.setVerticesData(VertexBuffer.PositionKind, bindPos.slice(), true);
|
|
896
|
+
const indices = mesh.getIndices();
|
|
897
|
+
if (indices) {
|
|
898
|
+
const norms = [];
|
|
899
|
+
VertexData.ComputeNormals(bindPos, indices, norms);
|
|
900
|
+
mesh.setVerticesData(VertexBuffer.NormalKind, norms, true);
|
|
901
|
+
}
|
|
902
|
+
mesh.refreshBoundingInfo();
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Dynamically adjusts the heights of the arms/shoulders and hips/legs across the skeleton
|
|
906
|
+
* and automatically re-binds envelope skin weights so the rig matches any stylized character!
|
|
907
|
+
*/
|
|
908
|
+
adjustBoneHeights(mesh, armRatio, hipRatio) {
|
|
909
|
+
if (!mesh || !mesh.skeleton)
|
|
910
|
+
return;
|
|
911
|
+
const specs = this.getBoneSegments(mesh, mesh.skeleton);
|
|
912
|
+
if (specs.length === 0)
|
|
913
|
+
return;
|
|
914
|
+
const targets = this.getTargetMeshes(mesh);
|
|
915
|
+
let minW = new Vector3(Infinity, Infinity, Infinity);
|
|
916
|
+
let maxW = new Vector3(-Infinity, -Infinity, -Infinity);
|
|
917
|
+
for (const t of targets) {
|
|
918
|
+
t.computeWorldMatrix(true);
|
|
919
|
+
t.refreshBoundingInfo();
|
|
920
|
+
const b = t.getBoundingInfo().boundingBox;
|
|
921
|
+
minW = Vector3.Minimize(minW, b.minimumWorld);
|
|
922
|
+
maxW = Vector3.Maximize(maxW, b.maximumWorld);
|
|
923
|
+
}
|
|
924
|
+
const height = Math.max(0.2, maxW.y - minW.y);
|
|
925
|
+
const bottomY = minW.y;
|
|
926
|
+
const armY = bottomY + armRatio * height;
|
|
927
|
+
const hipY = bottomY + hipRatio * height;
|
|
928
|
+
const chestY = bottomY + (hipRatio + (armRatio - hipRatio) * 0.75) * height;
|
|
929
|
+
const neckY = bottomY + Math.min(0.95, armRatio + 0.06) * height;
|
|
930
|
+
for (const s of specs) {
|
|
931
|
+
if (s.name.includes('Arm') || s.name.includes('Shoulder') || s.name.includes('Hand')) {
|
|
932
|
+
s.headWorldPos.y = armY;
|
|
933
|
+
s.tailWorldPos.y = armY;
|
|
934
|
+
}
|
|
935
|
+
else if (s.name === 'Chest') {
|
|
936
|
+
s.headWorldPos.y = chestY;
|
|
937
|
+
s.tailWorldPos.y = armY;
|
|
938
|
+
}
|
|
939
|
+
else if (s.name === 'Neck') {
|
|
940
|
+
s.headWorldPos.y = armY;
|
|
941
|
+
s.tailWorldPos.y = neckY;
|
|
942
|
+
}
|
|
943
|
+
else if (s.name === 'Head') {
|
|
944
|
+
s.headWorldPos.y = neckY;
|
|
945
|
+
}
|
|
946
|
+
else if (s.name === 'Hips') {
|
|
947
|
+
s.headWorldPos.y = hipY;
|
|
948
|
+
s.tailWorldPos.y = chestY;
|
|
949
|
+
}
|
|
950
|
+
else if (s.name === 'Root') {
|
|
951
|
+
s.tailWorldPos.y = hipY;
|
|
952
|
+
}
|
|
953
|
+
else if (s.name.includes('UpLeg')) {
|
|
954
|
+
s.headWorldPos.y = hipY;
|
|
955
|
+
s.tailWorldPos.y = bottomY + hipRatio * 0.5 * height;
|
|
956
|
+
}
|
|
957
|
+
else if (s.name.includes('Leg_')) {
|
|
958
|
+
s.headWorldPos.y = bottomY + hipRatio * 0.5 * height;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
this.syncBonesWithSpecs(mesh, specs);
|
|
962
|
+
if (this.showBoneOverlay) {
|
|
963
|
+
this.refreshBoneOverlay(mesh);
|
|
964
|
+
}
|
|
965
|
+
for (const t of targets) {
|
|
966
|
+
this.bindSingleMeshSkinWeights(t, t.skeleton || mesh.skeleton);
|
|
967
|
+
if (this.showHeatmap && this.isActive) {
|
|
968
|
+
this.updateSingleMeshHeatmap(t, this.activeBoneIndex);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
this.onWeightsModified?.(mesh, this.analyzeWeights(mesh));
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Nudges the active joint/bone position by a world delta vector and recalculates weights.
|
|
975
|
+
*/
|
|
976
|
+
nudgeActiveBone(mesh, delta) {
|
|
977
|
+
if (!mesh || !mesh.skeleton)
|
|
978
|
+
return;
|
|
979
|
+
const specs = this.getBoneSegments(mesh, mesh.skeleton);
|
|
980
|
+
const idx = Math.min(this.activeBoneIndex, specs.length - 1);
|
|
981
|
+
if (!specs[idx])
|
|
982
|
+
return;
|
|
983
|
+
specs[idx].headWorldPos.addInPlace(delta);
|
|
984
|
+
specs[idx].tailWorldPos.addInPlace(delta);
|
|
985
|
+
this.syncBonesWithSpecs(mesh, specs);
|
|
986
|
+
if (this.showBoneOverlay) {
|
|
987
|
+
this.refreshBoneOverlay(mesh);
|
|
988
|
+
}
|
|
989
|
+
const targets = this.getTargetMeshes(mesh);
|
|
990
|
+
for (const t of targets) {
|
|
991
|
+
this.bindSingleMeshSkinWeights(t, t.skeleton || mesh.skeleton);
|
|
992
|
+
if (this.showHeatmap && this.isActive) {
|
|
993
|
+
this.updateSingleMeshHeatmap(t, this.activeBoneIndex);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
this.onWeightsModified?.(mesh, this.analyzeWeights(mesh));
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Synchronizes bone local matrices and linked TransformNodes with updated specs.
|
|
1000
|
+
*/
|
|
1001
|
+
syncBonesWithSpecs(mesh, customSpecs) {
|
|
1002
|
+
if (!mesh || !mesh.skeleton)
|
|
1003
|
+
return;
|
|
1004
|
+
const specs = customSpecs || this.getBoneSegments(mesh, mesh.skeleton);
|
|
1005
|
+
const bones = mesh.skeleton.bones;
|
|
1006
|
+
const rootParent = mesh.parent;
|
|
1007
|
+
let invParentMat = null;
|
|
1008
|
+
if (rootParent && 'getWorldMatrix' in rootParent) {
|
|
1009
|
+
rootParent.computeWorldMatrix(true);
|
|
1010
|
+
invParentMat = Matrix.Invert(rootParent.getWorldMatrix());
|
|
1011
|
+
}
|
|
1012
|
+
for (let i = 0; i < specs.length && i < bones.length; i++) {
|
|
1013
|
+
const spec = specs[i];
|
|
1014
|
+
const bone = bones[i];
|
|
1015
|
+
const pIdx = spec.parentIndex;
|
|
1016
|
+
const headPos = spec.headWorldPos;
|
|
1017
|
+
const parentHeadPos = pIdx >= 0 && specs[pIdx]
|
|
1018
|
+
? specs[pIdx].headWorldPos
|
|
1019
|
+
: Vector3.Zero();
|
|
1020
|
+
const localOffset = pIdx >= 0
|
|
1021
|
+
? headPos.subtract(parentHeadPos)
|
|
1022
|
+
: invParentMat
|
|
1023
|
+
? Vector3.TransformCoordinates(headPos, invParentMat)
|
|
1024
|
+
: headPos.clone();
|
|
1025
|
+
const localMat = Matrix.Translation(localOffset.x, localOffset.y, localOffset.z);
|
|
1026
|
+
bone.updateMatrix(localMat);
|
|
1027
|
+
bone.getBaseMatrix().copyFrom(localMat);
|
|
1028
|
+
let tNode = bone.getTransformNode();
|
|
1029
|
+
if (!tNode) {
|
|
1030
|
+
const pBone = bone.getParent();
|
|
1031
|
+
const pNode = pBone ? pBone.getTransformNode() : rootParent;
|
|
1032
|
+
tNode = new TransformNode(spec.name, this.scene);
|
|
1033
|
+
if (pNode)
|
|
1034
|
+
tNode.parent = pNode;
|
|
1035
|
+
tNode.metadata = { isBoneNode: true, skeletonId: mesh.skeleton.id };
|
|
1036
|
+
bone.linkTransformNode(tNode);
|
|
1037
|
+
}
|
|
1038
|
+
tNode.position.copyFrom(localOffset);
|
|
1039
|
+
}
|
|
1040
|
+
const serializedSpecs = specs.map((s) => ({
|
|
1041
|
+
name: s.name,
|
|
1042
|
+
parentIndex: s.parentIndex,
|
|
1043
|
+
head: [s.headWorldPos.x, s.headWorldPos.y, s.headWorldPos.z],
|
|
1044
|
+
tail: [s.tailWorldPos.x, s.tailWorldPos.y, s.tailWorldPos.z],
|
|
1045
|
+
rotationDeg: [0, 0, 0],
|
|
1046
|
+
}));
|
|
1047
|
+
const targets = this.getTargetMeshes(mesh);
|
|
1048
|
+
for (const t of targets) {
|
|
1049
|
+
if (!t.metadata)
|
|
1050
|
+
t.metadata = {};
|
|
1051
|
+
t.metadata.rigBoneSpecs = serializedSpecs;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Ensures every bone in skeleton has a linked TransformNode so GLTF2Export writes out skins & joints.
|
|
1056
|
+
*/
|
|
1057
|
+
ensureSkeletonLinkedTransformNodes(skeleton, mesh) {
|
|
1058
|
+
for (const bone of skeleton.bones) {
|
|
1059
|
+
if (!bone.getTransformNode()) {
|
|
1060
|
+
const parentBone = bone.getParent();
|
|
1061
|
+
const parentNode = parentBone ? parentBone.getTransformNode() : mesh.parent;
|
|
1062
|
+
const tNode = new TransformNode(bone.name || 'Bone', this.scene);
|
|
1063
|
+
if (parentNode) {
|
|
1064
|
+
tNode.parent = parentNode;
|
|
1065
|
+
}
|
|
1066
|
+
tNode.metadata = { isBoneNode: true, skeletonId: skeleton.id };
|
|
1067
|
+
const localMat = bone.getLocalMatrix();
|
|
1068
|
+
const scaling = new Vector3();
|
|
1069
|
+
const rot = new Quaternion();
|
|
1070
|
+
const trans = new Vector3();
|
|
1071
|
+
localMat.decompose(scaling, rot, trans);
|
|
1072
|
+
tNode.position.copyFrom(trans);
|
|
1073
|
+
tNode.rotationQuaternion = rot;
|
|
1074
|
+
tNode.scaling.copyFrom(scaling);
|
|
1075
|
+
bone.linkTransformNode(tNode);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Prepares all meshes in the scene for clean GLTF/GLB/OBJ export by restoring
|
|
1081
|
+
* original materials, removing temporary weight heatmap vertex colors,
|
|
1082
|
+
* resetting pose tests, and ensuring all bones have linked transform nodes.
|
|
1083
|
+
*/
|
|
1084
|
+
prepareMeshesForExport() {
|
|
1085
|
+
// 1. Reset any active pose bend test to bind pose
|
|
1086
|
+
for (const mesh of this.scene.meshes) {
|
|
1087
|
+
if (mesh instanceof Mesh && mesh.metadata?.bindPosePositions) {
|
|
1088
|
+
this.resetBindPose(mesh);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
// 2. Restore all original materials and vertex colors
|
|
1092
|
+
const meshesWithHeatmap = new Set([
|
|
1093
|
+
...this.originalMaterialMap.keys(),
|
|
1094
|
+
...this.originalColorsMap.keys(),
|
|
1095
|
+
]);
|
|
1096
|
+
for (const mesh of meshesWithHeatmap) {
|
|
1097
|
+
if (mesh.isDisposed())
|
|
1098
|
+
continue;
|
|
1099
|
+
this.restoreOriginalVertexColors(mesh);
|
|
1100
|
+
}
|
|
1101
|
+
// Double check any mesh that might still have heatmap material or temporary colors
|
|
1102
|
+
for (const mesh of this.scene.meshes) {
|
|
1103
|
+
if (mesh instanceof Mesh) {
|
|
1104
|
+
if (mesh.material && mesh.material.name === 'editor_weight_heatmap_mat') {
|
|
1105
|
+
if (this.originalMaterialMap.has(mesh)) {
|
|
1106
|
+
mesh.material = this.originalMaterialMap.get(mesh);
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
mesh.material = null;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
// 3. Ensure all skeletons on meshes have linked transform nodes so GLTF2Export writes skins & joints
|
|
1115
|
+
for (const mesh of this.scene.meshes) {
|
|
1116
|
+
if (mesh instanceof Mesh && mesh.skeleton) {
|
|
1117
|
+
this.ensureSkeletonLinkedTransformNodes(mesh.skeleton, mesh);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
// 4. Ensure joint matrices indices are stored as UNSIGNED_BYTE (or UNSIGNED_SHORT) vertex buffers
|
|
1121
|
+
// to prevent Babylon GLTF exporter from calculating mismatched byte offsets across submeshes
|
|
1122
|
+
for (const mesh of this.scene.meshes) {
|
|
1123
|
+
if (mesh instanceof Mesh && mesh.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {
|
|
1124
|
+
const vb = mesh.getVertexBuffer(VertexBuffer.MatricesIndicesKind);
|
|
1125
|
+
if (vb && vb.type === VertexBuffer.FLOAT) {
|
|
1126
|
+
const raw = mesh.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
1127
|
+
if (raw) {
|
|
1128
|
+
this.setMeshMatrixIndices(mesh, raw);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Sets MatricesIndicesKind as an UNSIGNED_BYTE (or UNSIGNED_SHORT) vertex buffer.
|
|
1136
|
+
* Standard glTF requires integer types (UNSIGNED_BYTE / UNSIGNED_SHORT) for JOINTS_0.
|
|
1137
|
+
* If stored as floats in Babylon, the glTF serializer converts the buffer to bytes but
|
|
1138
|
+
* incorrectly computes submesh accessor byteOffsets using the float byteStride (16),
|
|
1139
|
+
* causing bufferView overflow and corrupt GLB files!
|
|
1140
|
+
*/
|
|
1141
|
+
setMeshMatrixIndices(mesh, indices) {
|
|
1142
|
+
const numIndices = indices.length;
|
|
1143
|
+
let maxIdx = 0;
|
|
1144
|
+
for (let i = 0; i < numIndices; i++) {
|
|
1145
|
+
if (indices[i] > maxIdx)
|
|
1146
|
+
maxIdx = indices[i];
|
|
1147
|
+
}
|
|
1148
|
+
if (maxIdx < 256) {
|
|
1149
|
+
const uint8Arr = indices instanceof Uint8Array ? indices : new Uint8Array(numIndices);
|
|
1150
|
+
if (!(indices instanceof Uint8Array)) {
|
|
1151
|
+
for (let i = 0; i < numIndices; i++) {
|
|
1152
|
+
uint8Arr[i] = Math.round(indices[i]);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
const vb = new VertexBuffer(mesh.getEngine(), uint8Arr, VertexBuffer.MatricesIndicesKind, false, false, 4, false, 0, 4, VertexBuffer.UNSIGNED_BYTE);
|
|
1156
|
+
mesh.setVerticesBuffer(vb);
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
const uint16Arr = indices instanceof Uint16Array ? indices : new Uint16Array(numIndices);
|
|
1160
|
+
if (!(indices instanceof Uint16Array)) {
|
|
1161
|
+
for (let i = 0; i < numIndices; i++) {
|
|
1162
|
+
uint16Arr[i] = Math.round(indices[i]);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
const vb = new VertexBuffer(mesh.getEngine(), uint16Arr, VertexBuffer.MatricesIndicesKind, false, false, 4, false, 0, 4, VertexBuffer.UNSIGNED_SHORT);
|
|
1166
|
+
mesh.setVerticesBuffer(vb);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Re-activates the weight heatmap and bone overlay after an export completes.
|
|
1171
|
+
*/
|
|
1172
|
+
restoreMeshesAfterExport() {
|
|
1173
|
+
const mesh = this.activeMesh || this.getActiveTargetMesh();
|
|
1174
|
+
if (this.isActive && mesh && !mesh.isDisposed()) {
|
|
1175
|
+
if (this.showHeatmap) {
|
|
1176
|
+
this.updateWeightHeatmap(mesh);
|
|
1177
|
+
}
|
|
1178
|
+
if (this.showBoneOverlay) {
|
|
1179
|
+
this.refreshBoneOverlay(mesh);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Renders a 3D bone wireframe overlay and active joint sphere in the viewport.
|
|
1185
|
+
*/
|
|
1186
|
+
refreshBoneOverlay(mesh) {
|
|
1187
|
+
this.clearBoneOverlay();
|
|
1188
|
+
if (!mesh || mesh.isDisposed() || !mesh.skeleton)
|
|
1189
|
+
return;
|
|
1190
|
+
const specs = this.getBoneSegments(mesh, mesh.skeleton);
|
|
1191
|
+
if (specs.length === 0)
|
|
1192
|
+
return;
|
|
1193
|
+
const lines = [];
|
|
1194
|
+
for (let i = 0; i < specs.length; i++) {
|
|
1195
|
+
const s = specs[i];
|
|
1196
|
+
lines.push([s.headWorldPos.clone(), s.tailWorldPos.clone()]);
|
|
1197
|
+
}
|
|
1198
|
+
this.boneOverlayMesh = MeshBuilder.CreateLineSystem('editor_rig_bone_helpers', { lines }, this.scene);
|
|
1199
|
+
this.boneOverlayMesh.color = new Color3(0.25, 0.88, 0.98);
|
|
1200
|
+
this.boneOverlayMesh.isPickable = false;
|
|
1201
|
+
this.boneOverlayMesh.renderingGroupId = 2;
|
|
1202
|
+
const activeSpec = specs[Math.min(this.activeBoneIndex, specs.length - 1)];
|
|
1203
|
+
if (activeSpec) {
|
|
1204
|
+
this.activeBoneMarker = MeshBuilder.CreateSphere('editor_rig_active_bone_marker', { diameter: 0.08, segments: 10 }, this.scene);
|
|
1205
|
+
this.activeBoneMarker.position.copyFrom(activeSpec.headWorldPos);
|
|
1206
|
+
const mat = new StandardMaterial('editor_rig_active_marker_mat', this.scene);
|
|
1207
|
+
mat.emissiveColor = new Color3(1.0, 0.35, 0.1);
|
|
1208
|
+
mat.disableLighting = true;
|
|
1209
|
+
this.activeBoneMarker.material = mat;
|
|
1210
|
+
this.activeBoneMarker.isPickable = false;
|
|
1211
|
+
this.activeBoneMarker.renderingGroupId = 2;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
clearBoneOverlay() {
|
|
1215
|
+
if (this.boneOverlayMesh) {
|
|
1216
|
+
this.boneOverlayMesh.dispose();
|
|
1217
|
+
this.boneOverlayMesh = null;
|
|
1218
|
+
}
|
|
1219
|
+
if (this.activeBoneMarker) {
|
|
1220
|
+
if (this.activeBoneMarker.material)
|
|
1221
|
+
this.activeBoneMarker.material.dispose();
|
|
1222
|
+
this.activeBoneMarker.dispose();
|
|
1223
|
+
this.activeBoneMarker = null;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
analyzeWeights(primaryMesh) {
|
|
1227
|
+
const root = primaryMesh || this.getActiveTargetMesh();
|
|
1228
|
+
if (!root || root.isDisposed() || !root.skeleton) {
|
|
1229
|
+
return {
|
|
1230
|
+
meshName: root?.name || 'None',
|
|
1231
|
+
hasSkeleton: false,
|
|
1232
|
+
boneCount: 0,
|
|
1233
|
+
activeBoneName: 'None',
|
|
1234
|
+
activeBoneIndex: 0,
|
|
1235
|
+
influencedVertexCount: 0,
|
|
1236
|
+
averageActiveWeight: 0,
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
const targets = this.getTargetMeshes(root);
|
|
1240
|
+
const bones = root.skeleton.bones;
|
|
1241
|
+
const boneIdx = Math.min(this.activeBoneIndex, Math.max(0, bones.length - 1));
|
|
1242
|
+
const activeBoneName = bones[boneIdx]?.name || `Bone_${boneIdx}`;
|
|
1243
|
+
let influencedVertexCount = 0;
|
|
1244
|
+
let sumWeight = 0;
|
|
1245
|
+
for (const m of targets) {
|
|
1246
|
+
const mIndices = m.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
1247
|
+
const mWeights = m.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
1248
|
+
const numVerts = m.getTotalVertices();
|
|
1249
|
+
if (mIndices && mWeights && numVerts > 0) {
|
|
1250
|
+
for (let i = 0; i < numVerts; i++) {
|
|
1251
|
+
const w = this.getVertexBoneWeight(mIndices, mWeights, i, boneIdx);
|
|
1252
|
+
if (w > 0.01) {
|
|
1253
|
+
influencedVertexCount++;
|
|
1254
|
+
sumWeight += w;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
const meshDisplayName = targets.length > 1
|
|
1260
|
+
? `${root.name} (+${targets.length - 1} parts)`
|
|
1261
|
+
: root.name;
|
|
1262
|
+
return {
|
|
1263
|
+
meshName: meshDisplayName,
|
|
1264
|
+
hasSkeleton: true,
|
|
1265
|
+
boneCount: bones.length,
|
|
1266
|
+
activeBoneName,
|
|
1267
|
+
activeBoneIndex: boneIdx,
|
|
1268
|
+
influencedVertexCount,
|
|
1269
|
+
averageActiveWeight: influencedVertexCount > 0 ? Math.round((sumWeight / influencedVertexCount) * 100) / 100 : 0,
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
initPointerHandling() {
|
|
1273
|
+
if (typeof window !== 'undefined') {
|
|
1274
|
+
window.addEventListener('pointerup', () => {
|
|
1275
|
+
if (this.isActive && this.isPainting) {
|
|
1276
|
+
this.endPaintStroke();
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
this.scene.onPointerObservable.add((pointerInfo) => {
|
|
1281
|
+
if (!this.isActive)
|
|
1282
|
+
return;
|
|
1283
|
+
const evt = pointerInfo.event;
|
|
1284
|
+
const isLeft = evt ? evt.button === 0 : true;
|
|
1285
|
+
switch (pointerInfo.type) {
|
|
1286
|
+
case PointerEventTypes.POINTERDOWN:
|
|
1287
|
+
if (isLeft)
|
|
1288
|
+
this.handlePointerDown(pointerInfo);
|
|
1289
|
+
break;
|
|
1290
|
+
case PointerEventTypes.POINTERMOVE:
|
|
1291
|
+
this.handlePointerMove(pointerInfo);
|
|
1292
|
+
break;
|
|
1293
|
+
case PointerEventTypes.POINTERUP:
|
|
1294
|
+
if (isLeft && this.isPainting)
|
|
1295
|
+
this.endPaintStroke();
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
handlePointerDown(pointerInfo) {
|
|
1301
|
+
const pick = pointerInfo.pickInfo;
|
|
1302
|
+
if (!pick ||
|
|
1303
|
+
!pick.hit ||
|
|
1304
|
+
!pick.pickedPoint ||
|
|
1305
|
+
!(pick.pickedMesh instanceof Mesh) ||
|
|
1306
|
+
this.service.isGizmoMesh(pick.pickedMesh) ||
|
|
1307
|
+
this.service.isEditorHelper(pick.pickedMesh) ||
|
|
1308
|
+
pick.pickedMesh === this.service.gridMesh) {
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
const mesh = pick.pickedMesh;
|
|
1312
|
+
this.activeMesh = mesh;
|
|
1313
|
+
this.isPainting = true;
|
|
1314
|
+
if (this.scene.activeCamera) {
|
|
1315
|
+
this.scene.activeCamera.detachControl();
|
|
1316
|
+
}
|
|
1317
|
+
this.strokePreStates.clear();
|
|
1318
|
+
const targets = this.getTargetMeshes(mesh);
|
|
1319
|
+
for (const t of targets) {
|
|
1320
|
+
const preW = t.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
1321
|
+
const preI = t.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
1322
|
+
if (preW && preI) {
|
|
1323
|
+
this.strokePreStates.set(t, {
|
|
1324
|
+
weights: Array.from(preW),
|
|
1325
|
+
indices: Array.from(preI),
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
this.applyWeightBrushStroke(mesh, pick.pickedPoint, this.activeBoneIndex);
|
|
1330
|
+
}
|
|
1331
|
+
handlePointerMove(pointerInfo) {
|
|
1332
|
+
const pick = pointerInfo.pickInfo;
|
|
1333
|
+
if (pick &&
|
|
1334
|
+
pick.hit &&
|
|
1335
|
+
pick.pickedPoint &&
|
|
1336
|
+
pick.pickedMesh instanceof Mesh &&
|
|
1337
|
+
!this.service.isGizmoMesh(pick.pickedMesh) &&
|
|
1338
|
+
!this.service.isEditorHelper(pick.pickedMesh) &&
|
|
1339
|
+
pick.pickedMesh !== this.service.gridMesh) {
|
|
1340
|
+
if (this.cursorRing) {
|
|
1341
|
+
this.cursorRing.isVisible = true;
|
|
1342
|
+
this.cursorRing.position.copyFrom(pick.pickedPoint);
|
|
1343
|
+
const normal = pick.getNormal(true) || Vector3.Up();
|
|
1344
|
+
this.cursorRing.lookAt(pick.pickedPoint.add(normal));
|
|
1345
|
+
}
|
|
1346
|
+
if (this.isPainting && this.activeMesh) {
|
|
1347
|
+
this.applyWeightBrushStroke(this.activeMesh, pick.pickedPoint, this.activeBoneIndex);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
else if (this.cursorRing) {
|
|
1351
|
+
this.cursorRing.isVisible = false;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
endPaintStroke() {
|
|
1355
|
+
this.isPainting = false;
|
|
1356
|
+
if (this.scene.activeCamera && this.service.canvas) {
|
|
1357
|
+
this.scene.activeCamera.attachControl(this.service.canvas, true);
|
|
1358
|
+
}
|
|
1359
|
+
const modifiedMeshes = [];
|
|
1360
|
+
for (const [m, pre] of this.strokePreStates.entries()) {
|
|
1361
|
+
if (m.isDisposed())
|
|
1362
|
+
continue;
|
|
1363
|
+
const postW = Array.from(m.getVerticesData(VertexBuffer.MatricesWeightsKind) || []);
|
|
1364
|
+
const postI = Array.from(m.getVerticesData(VertexBuffer.MatricesIndicesKind) || []);
|
|
1365
|
+
let changed = false;
|
|
1366
|
+
if (postW.length !== pre.weights.length) {
|
|
1367
|
+
changed = true;
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
for (let i = 0; i < postW.length; i++) {
|
|
1371
|
+
if (Math.abs(postW[i] - pre.weights[i]) > 1e-4) {
|
|
1372
|
+
changed = true;
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
if (changed) {
|
|
1378
|
+
modifiedMeshes.push({ mesh: m, preW: pre.weights, preI: pre.indices, postW, postI });
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
if (modifiedMeshes.length > 0) {
|
|
1382
|
+
this.service.recordAction({
|
|
1383
|
+
name: `Weight Paint (${modifiedMeshes.map((x) => x.mesh.name).join(', ')})`,
|
|
1384
|
+
undo: () => {
|
|
1385
|
+
for (const item of modifiedMeshes) {
|
|
1386
|
+
if (!item.mesh.isDisposed()) {
|
|
1387
|
+
this.setMeshMatrixIndices(item.mesh, item.preI);
|
|
1388
|
+
item.mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, item.preW, true);
|
|
1389
|
+
if (this.showHeatmap && this.isActive)
|
|
1390
|
+
this.updateWeightHeatmap(item.mesh);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
this.onWeightsModified?.(modifiedMeshes[0].mesh, this.analyzeWeights(modifiedMeshes[0].mesh));
|
|
1394
|
+
},
|
|
1395
|
+
redo: () => {
|
|
1396
|
+
for (const item of modifiedMeshes) {
|
|
1397
|
+
if (!item.mesh.isDisposed()) {
|
|
1398
|
+
this.setMeshMatrixIndices(item.mesh, item.postI);
|
|
1399
|
+
item.mesh.setVerticesData(VertexBuffer.MatricesWeightsKind, item.postW, true);
|
|
1400
|
+
if (this.showHeatmap && this.isActive)
|
|
1401
|
+
this.updateWeightHeatmap(item.mesh);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
this.onWeightsModified?.(modifiedMeshes[0].mesh, this.analyzeWeights(modifiedMeshes[0].mesh));
|
|
1405
|
+
},
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
this.strokePreStates.clear();
|
|
1409
|
+
this.activeMesh = null;
|
|
1410
|
+
}
|
|
1411
|
+
dispose() {
|
|
1412
|
+
this.setActive(false);
|
|
1413
|
+
this.clearBoneOverlay();
|
|
1414
|
+
if (this.cursorRing) {
|
|
1415
|
+
if (this.cursorRing.material)
|
|
1416
|
+
this.cursorRing.material.dispose();
|
|
1417
|
+
this.cursorRing.dispose();
|
|
1418
|
+
this.cursorRing = null;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
//# sourceMappingURL=WeightPaintController.js.map
|