mesheditor 0.0.0-stage → 1.0.3

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.
Files changed (258) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +853 -2
  3. package/dist-lib/esm/AIAgentService.d.ts +106 -0
  4. package/dist-lib/esm/AIAgentService.js +1471 -0
  5. package/dist-lib/esm/MeshEditorApp.d.ts +412 -0
  6. package/dist-lib/esm/MeshEditorApp.js +9092 -0
  7. package/dist-lib/esm/MeshEditorService.d.ts +459 -0
  8. package/dist-lib/esm/MeshEditorService.js +7083 -0
  9. package/dist-lib/esm/Neural3DGeneratorService.d.ts +88 -0
  10. package/dist-lib/esm/Neural3DGeneratorService.js +1397 -0
  11. package/dist-lib/esm/adapters/BrowserPlatformAdapter.d.ts +16 -0
  12. package/dist-lib/esm/adapters/BrowserPlatformAdapter.js +25 -0
  13. package/dist-lib/esm/adapters/ElectronPlatformAdapter.d.ts +32 -0
  14. package/dist-lib/esm/adapters/ElectronPlatformAdapter.js +336 -0
  15. package/dist-lib/esm/adapters/HostAppAdapter.d.ts +54 -0
  16. package/dist-lib/esm/adapters/HostAppAdapter.js +75 -0
  17. package/dist-lib/esm/adapters/PlatformAdapter.d.ts +98 -0
  18. package/dist-lib/esm/adapters/PlatformAdapter.js +1 -0
  19. package/dist-lib/esm/adapters/index.d.ts +13 -0
  20. package/dist-lib/esm/adapters/index.js +15 -0
  21. package/dist-lib/esm/assets/fonts/Droid_Sans_Bold.json +1 -0
  22. package/dist-lib/esm/assets/fonts/Droid_Sans_Regular.json +1 -0
  23. package/dist-lib/esm/assets/fonts/Kenney_Future_Regular.json +1 -0
  24. package/dist-lib/esm/baking/TextureBaker.d.ts +84 -0
  25. package/dist-lib/esm/baking/TextureBaker.js +709 -0
  26. package/dist-lib/esm/builtInSkills.d.ts +19 -0
  27. package/dist-lib/esm/builtInSkills.js +186 -0
  28. package/dist-lib/esm/compression/ModelCompressor.d.ts +87 -0
  29. package/dist-lib/esm/compression/ModelCompressor.js +553 -0
  30. package/dist-lib/esm/decals/DecalController.d.ts +147 -0
  31. package/dist-lib/esm/decals/DecalController.js +1031 -0
  32. package/dist-lib/esm/decals/decalAssetUrls.d.ts +1 -0
  33. package/dist-lib/esm/decals/decalAssetUrls.js +16 -0
  34. package/dist-lib/esm/geometry/architecture.d.ts +114 -0
  35. package/dist-lib/esm/geometry/architecture.js +832 -0
  36. package/dist-lib/esm/geometry/bevelModifier.d.ts +59 -0
  37. package/dist-lib/esm/geometry/bevelModifier.js +345 -0
  38. package/dist-lib/esm/geometry/facetSurfaceUtils.d.ts +127 -0
  39. package/dist-lib/esm/geometry/facetSurfaceUtils.js +676 -0
  40. package/dist-lib/esm/geometry/roundedBox.d.ts +15 -0
  41. package/dist-lib/esm/geometry/roundedBox.js +133 -0
  42. package/dist-lib/esm/index.d.ts +21 -0
  43. package/dist-lib/esm/index.js +50 -0
  44. package/dist-lib/esm/pathExtrusion/PathExtrusionController.d.ts +59 -0
  45. package/dist-lib/esm/pathExtrusion/PathExtrusionController.js +483 -0
  46. package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.d.ts +76 -0
  47. package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.js +1792 -0
  48. package/dist-lib/esm/pathExtrusion/PathFactory.d.ts +95 -0
  49. package/dist-lib/esm/pathExtrusion/PathFactory.js +627 -0
  50. package/dist-lib/esm/pathExtrusion/index.d.ts +4 -0
  51. package/dist-lib/esm/pathExtrusion/index.js +4 -0
  52. package/dist-lib/esm/pathExtrusion/types.d.ts +50 -0
  53. package/dist-lib/esm/pathExtrusion/types.js +1 -0
  54. package/dist-lib/esm/plugin.d.ts +250 -0
  55. package/dist-lib/esm/plugin.js +144 -0
  56. package/dist-lib/esm/rigging/WeightPaintController.d.ts +162 -0
  57. package/dist-lib/esm/rigging/WeightPaintController.js +1421 -0
  58. package/dist-lib/esm/sculpting/SculptController.d.ts +146 -0
  59. package/dist-lib/esm/sculpting/SculptController.js +2038 -0
  60. package/dist-lib/esm/sdf/index.d.ts +2 -0
  61. package/dist-lib/esm/sdf/index.js +2 -0
  62. package/dist-lib/esm/sdf/sdfPrimitives.d.ts +97 -0
  63. package/dist-lib/esm/sdf/sdfPrimitives.js +402 -0
  64. package/dist-lib/esm/sdf/surfaceNets.d.ts +29 -0
  65. package/dist-lib/esm/sdf/surfaceNets.js +399 -0
  66. package/dist-lib/esm/styles.d.ts +11 -0
  67. package/dist-lib/esm/styles.js +32 -0
  68. package/dist-lib/esm/template.d.ts +12 -0
  69. package/dist-lib/esm/template.js +19 -0
  70. package/dist-lib/esm/textMesh/TextMeshController.d.ts +61 -0
  71. package/dist-lib/esm/textMesh/TextMeshController.js +405 -0
  72. package/dist-lib/esm/textures/AITextureGenerator.d.ts +119 -0
  73. package/dist-lib/esm/textures/AITextureGenerator.js +945 -0
  74. package/dist-lib/esm/textures/ExternalImageGeneratorService.d.ts +62 -0
  75. package/dist-lib/esm/textures/ExternalImageGeneratorService.js +879 -0
  76. package/dist-lib/esm/tools/AbstractTool.d.ts +68 -0
  77. package/dist-lib/esm/tools/AbstractTool.js +128 -0
  78. package/dist-lib/esm/tools/ToolExecutionContext.d.ts +40 -0
  79. package/dist-lib/esm/tools/ToolExecutionContext.js +1 -0
  80. package/dist-lib/esm/tools/ToolInterface.d.ts +104 -0
  81. package/dist-lib/esm/tools/ToolInterface.js +1 -0
  82. package/dist-lib/esm/tools/ToolRegistry.d.ts +43 -0
  83. package/dist-lib/esm/tools/ToolRegistry.js +115 -0
  84. package/dist-lib/esm/tools/builtin/ApplyMaterialTool.d.ts +34 -0
  85. package/dist-lib/esm/tools/builtin/ApplyMaterialTool.js +48 -0
  86. package/dist-lib/esm/tools/builtin/AutoUVMappingTool.d.ts +34 -0
  87. package/dist-lib/esm/tools/builtin/AutoUVMappingTool.js +54 -0
  88. package/dist-lib/esm/tools/builtin/BakeTexturesTool.d.ts +42 -0
  89. package/dist-lib/esm/tools/builtin/BakeTexturesTool.js +81 -0
  90. package/dist-lib/esm/tools/builtin/BooleanOperationTool.d.ts +51 -0
  91. package/dist-lib/esm/tools/builtin/BooleanOperationTool.js +86 -0
  92. package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.d.ts +78 -0
  93. package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.js +170 -0
  94. package/dist-lib/esm/tools/builtin/CloneArrayTool.d.ts +75 -0
  95. package/dist-lib/esm/tools/builtin/CloneArrayTool.js +115 -0
  96. package/dist-lib/esm/tools/builtin/CreateArchTool.d.ts +118 -0
  97. package/dist-lib/esm/tools/builtin/CreateArchTool.js +89 -0
  98. package/dist-lib/esm/tools/builtin/CreateColumnTool.d.ts +114 -0
  99. package/dist-lib/esm/tools/builtin/CreateColumnTool.js +105 -0
  100. package/dist-lib/esm/tools/builtin/CreateLatheTool.d.ts +87 -0
  101. package/dist-lib/esm/tools/builtin/CreateLatheTool.js +60 -0
  102. package/dist-lib/esm/tools/builtin/CreateMaterialTool.d.ts +114 -0
  103. package/dist-lib/esm/tools/builtin/CreateMaterialTool.js +212 -0
  104. package/dist-lib/esm/tools/builtin/CreateMoldingTool.d.ts +120 -0
  105. package/dist-lib/esm/tools/builtin/CreateMoldingTool.js +95 -0
  106. package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.d.ts +162 -0
  107. package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.js +302 -0
  108. package/dist-lib/esm/tools/builtin/CreateRoofTool.d.ts +120 -0
  109. package/dist-lib/esm/tools/builtin/CreateRoofTool.js +108 -0
  110. package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.d.ts +101 -0
  111. package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.js +79 -0
  112. package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.d.ts +224 -0
  113. package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.js +238 -0
  114. package/dist-lib/esm/tools/builtin/CreateStairsTool.d.ts +135 -0
  115. package/dist-lib/esm/tools/builtin/CreateStairsTool.js +119 -0
  116. package/dist-lib/esm/tools/builtin/CreateTextMeshTool.d.ts +94 -0
  117. package/dist-lib/esm/tools/builtin/CreateTextMeshTool.js +131 -0
  118. package/dist-lib/esm/tools/builtin/CreateTubeTool.d.ts +87 -0
  119. package/dist-lib/esm/tools/builtin/CreateTubeTool.js +59 -0
  120. package/dist-lib/esm/tools/builtin/CreateWallTool.d.ts +145 -0
  121. package/dist-lib/esm/tools/builtin/CreateWallTool.js +124 -0
  122. package/dist-lib/esm/tools/builtin/DecalTool.d.ts +76 -0
  123. package/dist-lib/esm/tools/builtin/DecalTool.js +143 -0
  124. package/dist-lib/esm/tools/builtin/DeleteMeshTool.d.ts +20 -0
  125. package/dist-lib/esm/tools/builtin/DeleteMeshTool.js +42 -0
  126. package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.d.ts +21 -0
  127. package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.js +96 -0
  128. package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.d.ts +114 -0
  129. package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.js +77 -0
  130. package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.d.ts +104 -0
  131. package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.js +68 -0
  132. package/dist-lib/esm/tools/builtin/FacetArcTool.d.ts +36 -0
  133. package/dist-lib/esm/tools/builtin/FacetArcTool.js +57 -0
  134. package/dist-lib/esm/tools/builtin/FacetCutThroughTool.d.ts +30 -0
  135. package/dist-lib/esm/tools/builtin/FacetCutThroughTool.js +49 -0
  136. package/dist-lib/esm/tools/builtin/FacetExtrudeTool.d.ts +30 -0
  137. package/dist-lib/esm/tools/builtin/FacetExtrudeTool.js +49 -0
  138. package/dist-lib/esm/tools/builtin/FacetInsetTool.d.ts +34 -0
  139. package/dist-lib/esm/tools/builtin/FacetInsetTool.js +55 -0
  140. package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.d.ts +131 -0
  141. package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.js +455 -0
  142. package/dist-lib/esm/tools/builtin/GenerateTextureTool.d.ts +87 -0
  143. package/dist-lib/esm/tools/builtin/GenerateTextureTool.js +216 -0
  144. package/dist-lib/esm/tools/builtin/GetSceneInfoTool.d.ts +11 -0
  145. package/dist-lib/esm/tools/builtin/GetSceneInfoTool.js +12 -0
  146. package/dist-lib/esm/tools/builtin/MergeMeshesTool.d.ts +28 -0
  147. package/dist-lib/esm/tools/builtin/MergeMeshesTool.js +56 -0
  148. package/dist-lib/esm/tools/builtin/PlanModelTool.d.ts +87 -0
  149. package/dist-lib/esm/tools/builtin/PlanModelTool.js +155 -0
  150. package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.d.ts +50 -0
  151. package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.js +116 -0
  152. package/dist-lib/esm/tools/builtin/RigWeightTool.d.ts +55 -0
  153. package/dist-lib/esm/tools/builtin/RigWeightTool.js +139 -0
  154. package/dist-lib/esm/tools/builtin/SculptMeshTool.d.ts +138 -0
  155. package/dist-lib/esm/tools/builtin/SculptMeshTool.js +255 -0
  156. package/dist-lib/esm/tools/builtin/SeparateMeshTool.d.ts +21 -0
  157. package/dist-lib/esm/tools/builtin/SeparateMeshTool.js +31 -0
  158. package/dist-lib/esm/tools/builtin/SolidifyMeshTool.d.ts +30 -0
  159. package/dist-lib/esm/tools/builtin/SolidifyMeshTool.js +57 -0
  160. package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.d.ts +66 -0
  161. package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.js +105 -0
  162. package/dist-lib/esm/tools/builtin/SubDSmoothTool.d.ts +23 -0
  163. package/dist-lib/esm/tools/builtin/SubDSmoothTool.js +37 -0
  164. package/dist-lib/esm/tools/builtin/SubdivideMeshTool.d.ts +23 -0
  165. package/dist-lib/esm/tools/builtin/SubdivideMeshTool.js +39 -0
  166. package/dist-lib/esm/tools/builtin/TransformMeshTool.d.ts +78 -0
  167. package/dist-lib/esm/tools/builtin/TransformMeshTool.js +69 -0
  168. package/dist-lib/esm/tools/builtin/UVUnwrapTool.d.ts +48 -0
  169. package/dist-lib/esm/tools/builtin/UVUnwrapTool.js +107 -0
  170. package/dist-lib/esm/tools/builtin/VoxelPainterTool.d.ts +60 -0
  171. package/dist-lib/esm/tools/builtin/VoxelPainterTool.js +153 -0
  172. package/dist-lib/esm/tools/builtin/index.d.ts +44 -0
  173. package/dist-lib/esm/tools/builtin/index.js +44 -0
  174. package/dist-lib/esm/tools/editor/AIAgentEditorTool.d.ts +18 -0
  175. package/dist-lib/esm/tools/editor/AIAgentEditorTool.js +43 -0
  176. package/dist-lib/esm/tools/editor/AITextureEditorTool.d.ts +15 -0
  177. package/dist-lib/esm/tools/editor/AITextureEditorTool.js +28 -0
  178. package/dist-lib/esm/tools/editor/AbstractEditorTool.d.ts +29 -0
  179. package/dist-lib/esm/tools/editor/AbstractEditorTool.js +56 -0
  180. package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.d.ts +17 -0
  181. package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.js +29 -0
  182. package/dist-lib/esm/tools/editor/BakingEditorTool.d.ts +21 -0
  183. package/dist-lib/esm/tools/editor/BakingEditorTool.js +44 -0
  184. package/dist-lib/esm/tools/editor/CSGEditorTool.d.ts +20 -0
  185. package/dist-lib/esm/tools/editor/CSGEditorTool.js +42 -0
  186. package/dist-lib/esm/tools/editor/CompressModelEditorTool.d.ts +20 -0
  187. package/dist-lib/esm/tools/editor/CompressModelEditorTool.js +48 -0
  188. package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.d.ts +17 -0
  189. package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.js +36 -0
  190. package/dist-lib/esm/tools/editor/DecalEditorTool.d.ts +17 -0
  191. package/dist-lib/esm/tools/editor/DecalEditorTool.js +36 -0
  192. package/dist-lib/esm/tools/editor/FacetEditorTool.d.ts +23 -0
  193. package/dist-lib/esm/tools/editor/FacetEditorTool.js +80 -0
  194. package/dist-lib/esm/tools/editor/MaterialEditorTool.d.ts +18 -0
  195. package/dist-lib/esm/tools/editor/MaterialEditorTool.js +43 -0
  196. package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.d.ts +17 -0
  197. package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.js +37 -0
  198. package/dist-lib/esm/tools/editor/OutlinerEditorTool.d.ts +17 -0
  199. package/dist-lib/esm/tools/editor/OutlinerEditorTool.js +34 -0
  200. package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.d.ts +26 -0
  201. package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.js +72 -0
  202. package/dist-lib/esm/tools/editor/RiggingEditorTool.d.ts +27 -0
  203. package/dist-lib/esm/tools/editor/RiggingEditorTool.js +66 -0
  204. package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.d.ts +17 -0
  205. package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.js +35 -0
  206. package/dist-lib/esm/tools/editor/SculptEditorTool.d.ts +28 -0
  207. package/dist-lib/esm/tools/editor/SculptEditorTool.js +70 -0
  208. package/dist-lib/esm/tools/editor/TextMeshEditorTool.d.ts +16 -0
  209. package/dist-lib/esm/tools/editor/TextMeshEditorTool.js +30 -0
  210. package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.d.ts +17 -0
  211. package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.js +28 -0
  212. package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.d.ts +27 -0
  213. package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.js +70 -0
  214. package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.d.ts +26 -0
  215. package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.js +68 -0
  216. package/dist-lib/esm/tools/editor/aiQuickPrompts.d.ts +30 -0
  217. package/dist-lib/esm/tools/editor/aiQuickPrompts.js +228 -0
  218. package/dist-lib/esm/tools/editor/index.d.ts +32 -0
  219. package/dist-lib/esm/tools/editor/index.js +54 -0
  220. package/dist-lib/esm/tools/editor/toolViews.d.ts +10 -0
  221. package/dist-lib/esm/tools/editor/toolViews.js +53 -0
  222. package/dist-lib/esm/tools/editorTools.d.ts +5 -0
  223. package/dist-lib/esm/tools/editorTools.js +5 -0
  224. package/dist-lib/esm/tools/index.d.ts +8 -0
  225. package/dist-lib/esm/tools/index.js +8 -0
  226. package/dist-lib/esm/tools/textureUtils.d.ts +18 -0
  227. package/dist-lib/esm/tools/textureUtils.js +288 -0
  228. package/dist-lib/esm/types.d.ts +164 -0
  229. package/dist-lib/esm/types.js +1 -0
  230. package/dist-lib/esm/uv/UVUnwrapController.d.ts +108 -0
  231. package/dist-lib/esm/uv/UVUnwrapController.js +1022 -0
  232. package/dist-lib/esm/voxel/CustomVoxelMesher.d.ts +15 -0
  233. package/dist-lib/esm/voxel/CustomVoxelMesher.js +169 -0
  234. package/dist-lib/esm/voxel/TextureAtlasManager.d.ts +54 -0
  235. package/dist-lib/esm/voxel/TextureAtlasManager.js +630 -0
  236. package/dist-lib/esm/voxel/VoxelPainterController.d.ts +100 -0
  237. package/dist-lib/esm/voxel/VoxelPainterController.js +671 -0
  238. package/dist-lib/esm/voxel/index.d.ts +4 -0
  239. package/dist-lib/esm/voxel/index.js +4 -0
  240. package/dist-lib/esm/voxel/types.d.ts +78 -0
  241. package/dist-lib/esm/voxel/types.js +1 -0
  242. package/dist-lib/esm/web-component/MeshEditorElement.d.ts +103 -0
  243. package/dist-lib/esm/web-component/MeshEditorElement.js +246 -0
  244. package/dist-lib/esm/web-component/index.d.ts +1 -0
  245. package/dist-lib/esm/web-component/index.js +1 -0
  246. package/dist-lib/index.umd.js +3 -0
  247. package/dist-lib/mesheditor.css +2 -0
  248. package/dist-lib/mesheditor.css.map +1 -0
  249. package/dist-lib/standalone/mesheditor-element.bundle.js +3 -0
  250. package/package.json +114 -4
  251. package/skills/README.md +48 -0
  252. package/skills/figure-sculptor.md +297 -0
  253. package/skills/image-to-mesh.md +18 -0
  254. package/skills/mesh-updater.md +27 -0
  255. package/skills/neural-3d-generator.md +53 -0
  256. package/skills/procedural-modeler.md +267 -0
  257. package/skills/voxel-painter.md +21 -0
  258. package/src/mesheditor.css +6477 -0
@@ -0,0 +1,399 @@
1
+ import { Color3, Vector3, VertexData } from '@babylonjs/core';
2
+ import { computeSdfNormal, evaluateSdfColor, evaluateSdfScene, } from './sdfPrimitives';
3
+ const CUBE_CORNERS = [
4
+ [0, 0, 0],
5
+ [1, 0, 0],
6
+ [0, 1, 0],
7
+ [1, 1, 0],
8
+ [0, 0, 1],
9
+ [1, 0, 1],
10
+ [0, 1, 1],
11
+ [1, 1, 1],
12
+ ];
13
+ const CUBE_EDGES = [
14
+ [0, 1],
15
+ [2, 3],
16
+ [4, 5],
17
+ [6, 7], // X-aligned edges
18
+ [0, 2],
19
+ [1, 3],
20
+ [4, 6],
21
+ [5, 7], // Y-aligned edges
22
+ [0, 4],
23
+ [1, 5],
24
+ [2, 6],
25
+ [3, 7], // Z-aligned edges
26
+ ];
27
+ /**
28
+ * Extracts a crack-free, watertight indexed triangle mesh from compiled SDF primitives
29
+ * using Surface Nets with Newton isosurface projection, Taubin/Laplacian smoothing,
30
+ * analytical SDF gradient normals, and box/triplanar UVs.
31
+ */
32
+ export function extractSdfSurfaceNets(parts, options = {}) {
33
+ if (!parts || parts.length === 0) {
34
+ throw new Error('Cannot extract SDF mesh: no SDF parts provided.');
35
+ }
36
+ // 1. Compute overall bounding box from union/intersect parts (or all parts if none are union)
37
+ let minX = Infinity;
38
+ let minY = Infinity;
39
+ let minZ = Infinity;
40
+ let maxX = -Infinity;
41
+ let maxY = -Infinity;
42
+ let maxZ = -Infinity;
43
+ const positiveParts = parts.filter((p) => p.op !== 'subtract');
44
+ const boundSource = positiveParts.length > 0 ? positiveParts : parts;
45
+ for (const p of boundSource) {
46
+ if (p.shape === 'plane')
47
+ continue;
48
+ minX = Math.min(minX, p.boundsMin.x);
49
+ minY = Math.min(minY, p.boundsMin.y);
50
+ minZ = Math.min(minZ, p.boundsMin.z);
51
+ maxX = Math.max(maxX, p.boundsMax.x);
52
+ maxY = Math.max(maxY, p.boundsMax.y);
53
+ maxZ = Math.max(maxZ, p.boundsMax.z);
54
+ }
55
+ if (!Number.isFinite(minX) || !Number.isFinite(maxX)) {
56
+ minX = -1;
57
+ minY = -1;
58
+ minZ = -1;
59
+ maxX = 1;
60
+ maxY = 1;
61
+ maxZ = 1;
62
+ }
63
+ const spanX = Math.max(0.05, maxX - minX);
64
+ const spanY = Math.max(0.05, maxY - minY);
65
+ const spanZ = Math.max(0.05, maxZ - minZ);
66
+ const maxSpan = Math.max(spanX, spanY, spanZ);
67
+ const longestAxisCells = Math.max(16, Math.min(128, Math.round(options.resolution || 56)));
68
+ const cellSize = maxSpan / longestAxisCells;
69
+ // Add 2-cell margin on each side so the zero-isosurface is strictly enclosed
70
+ const margin = cellSize * 2.2;
71
+ const originX = minX - margin;
72
+ const originY = minY - margin;
73
+ const originZ = minZ - margin;
74
+ const totalX = spanX + margin * 2;
75
+ const totalY = spanY + margin * 2;
76
+ const totalZ = spanZ + margin * 2;
77
+ const nx = Math.max(6, Math.min(136, Math.ceil(totalX / cellSize)));
78
+ const ny = Math.max(6, Math.min(136, Math.ceil(totalY / cellSize)));
79
+ const nz = Math.max(6, Math.min(136, Math.ceil(totalZ / cellSize)));
80
+ const gxCount = nx + 1;
81
+ const gyCount = ny + 1;
82
+ const gzCount = nz + 1;
83
+ const strideY = gxCount;
84
+ const strideZ = gxCount * gyCount;
85
+ // 2. Sample SDF on grid corners
86
+ const grid = new Float32Array(gxCount * gyCount * gzCount);
87
+ for (let iz = 0; iz < gzCount; iz++) {
88
+ const wz = originZ + iz * cellSize;
89
+ const zOff = iz * strideZ;
90
+ for (let iy = 0; iy < gyCount; iy++) {
91
+ const wy = originY + iy * cellSize;
92
+ const yzOff = zOff + iy * strideY;
93
+ for (let ix = 0; ix < gxCount; ix++) {
94
+ const wx = originX + ix * cellSize;
95
+ grid[yzOff + ix] = evaluateSdfScene(parts, wx, wy, wz);
96
+ }
97
+ }
98
+ }
99
+ // 3. Identify active cells with sign changes and place dual vertices
100
+ const cellStrideY = nx;
101
+ const cellStrideZ = nx * ny;
102
+ const cellVertIndex = new Int32Array(nx * ny * nz);
103
+ cellVertIndex.fill(-1);
104
+ const posArray = [];
105
+ const cornerVals = new Float32Array(8);
106
+ const cornerX = new Float32Array(8);
107
+ const cornerY = new Float32Array(8);
108
+ const cornerZ = new Float32Array(8);
109
+ const eps = Math.max(1e-4, cellSize * 0.25);
110
+ for (let cz = 0; cz < nz; cz++) {
111
+ for (let cy = 0; cy < ny; cy++) {
112
+ for (let cx = 0; cx < nx; cx++) {
113
+ let mask = 0;
114
+ for (let c = 0; c < 8; c++) {
115
+ const [dx, dy, dz] = CUBE_CORNERS[c];
116
+ const gx = cx + dx;
117
+ const gy = cy + dy;
118
+ const gz = cz + dz;
119
+ const val = grid[gz * strideZ + gy * strideY + gx];
120
+ cornerVals[c] = val;
121
+ if (val < 0) {
122
+ mask |= 1 << c;
123
+ }
124
+ }
125
+ if (mask === 0 || mask === 255) {
126
+ continue;
127
+ }
128
+ for (let c = 0; c < 8; c++) {
129
+ const [dx, dy, dz] = CUBE_CORNERS[c];
130
+ cornerX[c] = originX + (cx + dx) * cellSize;
131
+ cornerY[c] = originY + (cy + dy) * cellSize;
132
+ cornerZ[c] = originZ + (cz + dz) * cellSize;
133
+ }
134
+ // Average all sign-changing edge intersections
135
+ let sumX = 0;
136
+ let sumY = 0;
137
+ let sumZ = 0;
138
+ let crossings = 0;
139
+ for (let e = 0; e < 12; e++) {
140
+ const [c0, c1] = CUBE_EDGES[e];
141
+ const v0 = cornerVals[c0];
142
+ const v1 = cornerVals[c1];
143
+ if ((v0 < 0) !== (v1 < 0)) {
144
+ const denom = v0 - v1;
145
+ const t = Math.abs(denom) > 1e-8 ? Math.max(0, Math.min(1, v0 / denom)) : 0.5;
146
+ sumX += cornerX[c0] + (cornerX[c1] - cornerX[c0]) * t;
147
+ sumY += cornerY[c0] + (cornerY[c1] - cornerY[c0]) * t;
148
+ sumZ += cornerZ[c0] + (cornerZ[c1] - cornerZ[c0]) * t;
149
+ crossings++;
150
+ }
151
+ }
152
+ let vx = crossings > 0 ? sumX / crossings : originX + (cx + 0.5) * cellSize;
153
+ let vy = crossings > 0 ? sumY / crossings : originY + (cy + 0.5) * cellSize;
154
+ let vz = crossings > 0 ? sumZ / crossings : originZ + (cz + 0.5) * cellSize;
155
+ // Project 1 damped Newton step onto exact SDF zero-isosurface, clamped to cell bounds
156
+ const dVal = evaluateSdfScene(parts, vx, vy, vz);
157
+ if (Math.abs(dVal) < cellSize * 0.85) {
158
+ const n = computeSdfNormal(parts, vx, vy, vz, eps);
159
+ const step = Math.max(-cellSize * 0.4, Math.min(cellSize * 0.4, dVal * 0.75));
160
+ vx -= n.x * step;
161
+ vy -= n.y * step;
162
+ vz -= n.z * step;
163
+ }
164
+ const vIdx = posArray.length / 3;
165
+ posArray.push(vx, vy, vz);
166
+ cellVertIndex[cz * cellStrideZ + cy * cellStrideY + cx] = vIdx;
167
+ }
168
+ }
169
+ }
170
+ // 4. Emit quads across interior grid edges where sign changes
171
+ const indices = [];
172
+ const getCellVert = (cx, cy, cz) => cellVertIndex[cz * cellStrideZ + cy * cellStrideY + cx];
173
+ const emitQuad = (v0, v1, v2, v3, flip) => {
174
+ if (v0 < 0 || v1 < 0 || v2 < 0 || v3 < 0)
175
+ return;
176
+ if (flip) {
177
+ indices.push(v0, v2, v1, v0, v3, v2);
178
+ }
179
+ else {
180
+ indices.push(v0, v1, v2, v0, v2, v3);
181
+ }
182
+ };
183
+ // X-aligned edges: between (ix, iy, iz) and (ix+1, iy, iz), surrounded by 4 cells in (iy-1..iy, iz-1..iz)
184
+ for (let iz = 1; iz < nz; iz++) {
185
+ for (let iy = 1; iy < ny; iy++) {
186
+ for (let ix = 0; ix < nx; ix++) {
187
+ const s0 = grid[iz * strideZ + iy * strideY + ix];
188
+ const s1 = grid[iz * strideZ + iy * strideY + (ix + 1)];
189
+ if ((s0 < 0) !== (s1 < 0)) {
190
+ const v0 = getCellVert(ix, iy - 1, iz - 1);
191
+ const v1 = getCellVert(ix, iy, iz - 1);
192
+ const v2 = getCellVert(ix, iy, iz);
193
+ const v3 = getCellVert(ix, iy - 1, iz);
194
+ // (v1-v0) is +Y, (v2-v0) is +Y+Z => (v1-v0)x(v2-v0) points in +X
195
+ // If s0 < 0 and s1 >= 0, outward gradient is +X, so flip = false
196
+ emitQuad(v0, v1, v2, v3, s0 >= 0);
197
+ }
198
+ }
199
+ }
200
+ }
201
+ // Y-aligned edges: between (ix, iy, iz) and (ix, iy+1, iz), surrounded by 4 cells in (ix-1..ix, iz-1..iz)
202
+ for (let iz = 1; iz < nz; iz++) {
203
+ for (let iy = 0; iy < ny; iy++) {
204
+ for (let ix = 1; ix < nx; ix++) {
205
+ const s0 = grid[iz * strideZ + iy * strideY + ix];
206
+ const s1 = grid[iz * strideZ + (iy + 1) * strideY + ix];
207
+ if ((s0 < 0) !== (s1 < 0)) {
208
+ const v0 = getCellVert(ix - 1, iy, iz - 1);
209
+ const v1 = getCellVert(ix - 1, iy, iz);
210
+ const v2 = getCellVert(ix, iy, iz);
211
+ const v3 = getCellVert(ix, iy, iz - 1);
212
+ // (v1-v0) is +Z, (v2-v0) is +X+Z => (v1-v0)x(v2-v0) points in +Y
213
+ emitQuad(v0, v1, v2, v3, s0 >= 0);
214
+ }
215
+ }
216
+ }
217
+ }
218
+ // Z-aligned edges: between (ix, iy, iz) and (ix, iy, iz+1), surrounded by 4 cells in (ix-1..ix, iy-1..iy)
219
+ for (let iz = 0; iz < nz; iz++) {
220
+ for (let iy = 1; iy < ny; iy++) {
221
+ for (let ix = 1; ix < nx; ix++) {
222
+ const s0 = grid[iz * strideZ + iy * strideY + ix];
223
+ const s1 = grid[(iz + 1) * strideZ + iy * strideY + ix];
224
+ if ((s0 < 0) !== (s1 < 0)) {
225
+ const v0 = getCellVert(ix - 1, iy - 1, iz);
226
+ const v1 = getCellVert(ix, iy - 1, iz);
227
+ const v2 = getCellVert(ix, iy, iz);
228
+ const v3 = getCellVert(ix - 1, iy, iz);
229
+ // (v1-v0) is +X, (v2-v0) is +X+Y => (v1-v0)x(v2-v0) points in +Z
230
+ emitQuad(v0, v1, v2, v3, s0 >= 0);
231
+ }
232
+ }
233
+ }
234
+ }
235
+ const vertCount = posArray.length / 3;
236
+ let positions = new Float32Array(posArray);
237
+ // 5. Optional Taubin / Laplacian surface smoothing + SDF re-projection
238
+ const smoothIterations = Math.max(0, Math.min(5, options.smoothIterations ?? 1));
239
+ if (smoothIterations > 0 && vertCount > 0 && indices.length > 0) {
240
+ const adjOffsets = new Int32Array(vertCount + 1);
241
+ const degCounts = new Int32Array(vertCount);
242
+ for (let i = 0; i < indices.length; i += 3) {
243
+ const a = indices[i];
244
+ const b = indices[i + 1];
245
+ const c = indices[i + 2];
246
+ degCounts[a] += 2;
247
+ degCounts[b] += 2;
248
+ degCounts[c] += 2;
249
+ }
250
+ for (let v = 0; v < vertCount; v++) {
251
+ adjOffsets[v + 1] = adjOffsets[v] + degCounts[v];
252
+ }
253
+ const adjList = new Int32Array(adjOffsets[vertCount]);
254
+ const cursor = new Int32Array(adjOffsets);
255
+ for (let i = 0; i < indices.length; i += 3) {
256
+ const a = indices[i];
257
+ const b = indices[i + 1];
258
+ const c = indices[i + 2];
259
+ adjList[cursor[a]++] = b;
260
+ adjList[cursor[a]++] = c;
261
+ adjList[cursor[b]++] = a;
262
+ adjList[cursor[b]++] = c;
263
+ adjList[cursor[c]++] = a;
264
+ adjList[cursor[c]++] = b;
265
+ }
266
+ const nextPositions = new Float32Array(positions.length);
267
+ const lambda = 0.35;
268
+ for (let iter = 0; iter < smoothIterations; iter++) {
269
+ for (let v = 0; v < vertCount; v++) {
270
+ const start = adjOffsets[v];
271
+ const end = adjOffsets[v + 1];
272
+ const count = end - start;
273
+ const idx = v * 3;
274
+ if (count === 0) {
275
+ nextPositions[idx] = positions[idx];
276
+ nextPositions[idx + 1] = positions[idx + 1];
277
+ nextPositions[idx + 2] = positions[idx + 2];
278
+ continue;
279
+ }
280
+ let ax = 0;
281
+ let ay = 0;
282
+ let az = 0;
283
+ for (let k = start; k < end; k++) {
284
+ const nb = adjList[k] * 3;
285
+ ax += positions[nb];
286
+ ay += positions[nb + 1];
287
+ az += positions[nb + 2];
288
+ }
289
+ ax /= count;
290
+ ay /= count;
291
+ az /= count;
292
+ let nxPos = positions[idx] + (ax - positions[idx]) * lambda;
293
+ let nyPos = positions[idx + 1] + (ay - positions[idx + 1]) * lambda;
294
+ let nzPos = positions[idx + 2] + (az - positions[idx + 2]) * lambda;
295
+ // Re-project toward exact SDF surface so volume never shrinks
296
+ const dVal = evaluateSdfScene(parts, nxPos, nyPos, nzPos);
297
+ if (Math.abs(dVal) < cellSize) {
298
+ const n = computeSdfNormal(parts, nxPos, nyPos, nzPos, eps);
299
+ nxPos -= n.x * dVal * 0.6;
300
+ nyPos -= n.y * dVal * 0.6;
301
+ nzPos -= n.z * dVal * 0.6;
302
+ }
303
+ nextPositions[idx] = nxPos;
304
+ nextPositions[idx + 1] = nyPos;
305
+ nextPositions[idx + 2] = nzPos;
306
+ }
307
+ positions.set(nextPositions);
308
+ }
309
+ }
310
+ // 6. Compute analytical SDF normals, UVs, bounds, and optional vertex colors
311
+ const normals = new Float32Array(vertCount * 3);
312
+ const uvs = new Float32Array(vertCount * 2);
313
+ const hasPartColors = options.computeVertexColors !== false && parts.some((p) => p.color !== null);
314
+ const colors = hasPartColors ? new Float32Array(vertCount * 4) : null;
315
+ const fallbackColor = Color3.FromHexString(options.defaultColor && /^#[0-9a-fA-F]{6}$/.test(options.defaultColor)
316
+ ? options.defaultColor
317
+ : '#d9b38c');
318
+ let actualMinX = Infinity;
319
+ let actualMinY = Infinity;
320
+ let actualMinZ = Infinity;
321
+ let actualMaxX = -Infinity;
322
+ let actualMaxY = -Infinity;
323
+ let actualMaxZ = -Infinity;
324
+ for (let v = 0; v < vertCount; v++) {
325
+ const idx = v * 3;
326
+ const vx = positions[idx];
327
+ const vy = positions[idx + 1];
328
+ const vz = positions[idx + 2];
329
+ if (vx < actualMinX)
330
+ actualMinX = vx;
331
+ if (vy < actualMinY)
332
+ actualMinY = vy;
333
+ if (vz < actualMinZ)
334
+ actualMinZ = vz;
335
+ if (vx > actualMaxX)
336
+ actualMaxX = vx;
337
+ if (vy > actualMaxY)
338
+ actualMaxY = vy;
339
+ if (vz > actualMaxZ)
340
+ actualMaxZ = vz;
341
+ const n = computeSdfNormal(parts, vx, vy, vz, eps);
342
+ normals[idx] = n.x;
343
+ normals[idx + 1] = n.y;
344
+ normals[idx + 2] = n.z;
345
+ // Dominant-axis triplanar UV projection
346
+ const ax = Math.abs(n.x);
347
+ const ay = Math.abs(n.y);
348
+ const az = Math.abs(n.z);
349
+ const uvIdx = v * 2;
350
+ if (ay >= ax && ay >= az) {
351
+ uvs[uvIdx] = (vx - minX) / spanX;
352
+ uvs[uvIdx + 1] = (vz - minZ) / spanZ;
353
+ }
354
+ else if (ax >= ay && ax >= az) {
355
+ uvs[uvIdx] = (vz - minZ) / spanZ;
356
+ uvs[uvIdx + 1] = (vy - minY) / spanY;
357
+ }
358
+ else {
359
+ uvs[uvIdx] = (vx - minX) / spanX;
360
+ uvs[uvIdx + 1] = (vy - minY) / spanY;
361
+ }
362
+ if (colors) {
363
+ const c = evaluateSdfColor(parts, vx, vy, vz, fallbackColor);
364
+ const cIdx = v * 4;
365
+ colors[cIdx] = c.r;
366
+ colors[cIdx + 1] = c.g;
367
+ colors[cIdx + 2] = c.b;
368
+ colors[cIdx + 3] = 1.0;
369
+ }
370
+ }
371
+ if (!Number.isFinite(actualMinX)) {
372
+ actualMinX = 0;
373
+ actualMinY = 0;
374
+ actualMinZ = 0;
375
+ actualMaxX = 0;
376
+ actualMaxY = 0;
377
+ actualMaxZ = 0;
378
+ }
379
+ const vertexData = new VertexData();
380
+ vertexData.positions = positions;
381
+ vertexData.indices = indices;
382
+ vertexData.normals = normals;
383
+ vertexData.uvs = uvs;
384
+ if (colors) {
385
+ vertexData.colors = colors;
386
+ }
387
+ const bMin = new Vector3(actualMinX, actualMinY, actualMinZ);
388
+ const bMax = new Vector3(actualMaxX, actualMaxY, actualMaxZ);
389
+ return {
390
+ vertexData,
391
+ resolution: { nx, ny, nz, cellSize },
392
+ bounds: {
393
+ min: bMin,
394
+ max: bMax,
395
+ size: bMax.subtract(bMin),
396
+ },
397
+ hasVertexColors: !!colors,
398
+ };
399
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Auto-generated inline CSS styles for Mesh Editor.
3
+ * Allows Web Components (<mesh-editor>) and NPM library consumers
4
+ * to mount the editor with zero external CSS configuration required.
5
+ */
6
+ export declare const MESH_EDITOR_CSS: string;
7
+ /**
8
+ * Injects the Mesh Editor stylesheet into the document head or a ShadowRoot
9
+ * if it is not already present.
10
+ */
11
+ export declare function ensureMeshEditorStyles(target?: Document | ShadowRoot): void;