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.
- package/LICENSE +201 -0
- package/README.md +853 -2
- package/dist-lib/esm/AIAgentService.d.ts +106 -0
- package/dist-lib/esm/AIAgentService.js +1471 -0
- package/dist-lib/esm/MeshEditorApp.d.ts +412 -0
- package/dist-lib/esm/MeshEditorApp.js +9092 -0
- package/dist-lib/esm/MeshEditorService.d.ts +459 -0
- package/dist-lib/esm/MeshEditorService.js +7083 -0
- package/dist-lib/esm/Neural3DGeneratorService.d.ts +88 -0
- package/dist-lib/esm/Neural3DGeneratorService.js +1397 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.d.ts +16 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.js +25 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.d.ts +32 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.js +336 -0
- package/dist-lib/esm/adapters/HostAppAdapter.d.ts +54 -0
- package/dist-lib/esm/adapters/HostAppAdapter.js +75 -0
- package/dist-lib/esm/adapters/PlatformAdapter.d.ts +98 -0
- package/dist-lib/esm/adapters/PlatformAdapter.js +1 -0
- package/dist-lib/esm/adapters/index.d.ts +13 -0
- package/dist-lib/esm/adapters/index.js +15 -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 +84 -0
- package/dist-lib/esm/baking/TextureBaker.js +709 -0
- package/dist-lib/esm/builtInSkills.d.ts +19 -0
- package/dist-lib/esm/builtInSkills.js +186 -0
- package/dist-lib/esm/compression/ModelCompressor.d.ts +87 -0
- package/dist-lib/esm/compression/ModelCompressor.js +553 -0
- package/dist-lib/esm/decals/DecalController.d.ts +147 -0
- package/dist-lib/esm/decals/DecalController.js +1031 -0
- package/dist-lib/esm/decals/decalAssetUrls.d.ts +1 -0
- package/dist-lib/esm/decals/decalAssetUrls.js +16 -0
- package/dist-lib/esm/geometry/architecture.d.ts +114 -0
- package/dist-lib/esm/geometry/architecture.js +832 -0
- package/dist-lib/esm/geometry/bevelModifier.d.ts +59 -0
- package/dist-lib/esm/geometry/bevelModifier.js +345 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.d.ts +127 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.js +676 -0
- package/dist-lib/esm/geometry/roundedBox.d.ts +15 -0
- package/dist-lib/esm/geometry/roundedBox.js +133 -0
- package/dist-lib/esm/index.d.ts +21 -0
- package/dist-lib/esm/index.js +50 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.d.ts +59 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.js +483 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.d.ts +76 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.js +1792 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.d.ts +95 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.js +627 -0
- package/dist-lib/esm/pathExtrusion/index.d.ts +4 -0
- package/dist-lib/esm/pathExtrusion/index.js +4 -0
- package/dist-lib/esm/pathExtrusion/types.d.ts +50 -0
- package/dist-lib/esm/pathExtrusion/types.js +1 -0
- package/dist-lib/esm/plugin.d.ts +250 -0
- package/dist-lib/esm/plugin.js +144 -0
- package/dist-lib/esm/rigging/WeightPaintController.d.ts +162 -0
- package/dist-lib/esm/rigging/WeightPaintController.js +1421 -0
- package/dist-lib/esm/sculpting/SculptController.d.ts +146 -0
- package/dist-lib/esm/sculpting/SculptController.js +2038 -0
- package/dist-lib/esm/sdf/index.d.ts +2 -0
- package/dist-lib/esm/sdf/index.js +2 -0
- package/dist-lib/esm/sdf/sdfPrimitives.d.ts +97 -0
- package/dist-lib/esm/sdf/sdfPrimitives.js +402 -0
- package/dist-lib/esm/sdf/surfaceNets.d.ts +29 -0
- package/dist-lib/esm/sdf/surfaceNets.js +399 -0
- package/dist-lib/esm/styles.d.ts +11 -0
- package/dist-lib/esm/styles.js +32 -0
- package/dist-lib/esm/template.d.ts +12 -0
- package/dist-lib/esm/template.js +19 -0
- package/dist-lib/esm/textMesh/TextMeshController.d.ts +61 -0
- package/dist-lib/esm/textMesh/TextMeshController.js +405 -0
- package/dist-lib/esm/textures/AITextureGenerator.d.ts +119 -0
- package/dist-lib/esm/textures/AITextureGenerator.js +945 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.d.ts +62 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.js +879 -0
- package/dist-lib/esm/tools/AbstractTool.d.ts +68 -0
- package/dist-lib/esm/tools/AbstractTool.js +128 -0
- package/dist-lib/esm/tools/ToolExecutionContext.d.ts +40 -0
- package/dist-lib/esm/tools/ToolExecutionContext.js +1 -0
- package/dist-lib/esm/tools/ToolInterface.d.ts +104 -0
- package/dist-lib/esm/tools/ToolInterface.js +1 -0
- package/dist-lib/esm/tools/ToolRegistry.d.ts +43 -0
- package/dist-lib/esm/tools/ToolRegistry.js +115 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.js +48 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.js +54 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.d.ts +42 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.js +81 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.d.ts +51 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.js +86 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.d.ts +78 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.js +170 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.d.ts +75 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.js +115 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.d.ts +118 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.js +89 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.js +105 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.js +60 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.js +212 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.d.ts +120 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.js +95 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.d.ts +162 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.js +302 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.d.ts +120 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.js +108 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.d.ts +101 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.js +79 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.d.ts +224 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.js +238 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.d.ts +135 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.js +119 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.d.ts +94 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.js +131 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.js +59 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.d.ts +145 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.js +124 -0
- package/dist-lib/esm/tools/builtin/DecalTool.d.ts +76 -0
- package/dist-lib/esm/tools/builtin/DecalTool.js +143 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.d.ts +20 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.js +42 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.d.ts +21 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.js +96 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.js +77 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.d.ts +104 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.js +68 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.d.ts +36 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.js +57 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.js +49 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.js +49 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.js +55 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.d.ts +131 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.js +455 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.js +216 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.d.ts +11 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.js +12 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.d.ts +28 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.js +56 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.js +155 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.d.ts +50 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.js +116 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.d.ts +55 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.js +139 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.d.ts +138 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.js +255 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.d.ts +21 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.js +31 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.js +57 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.d.ts +66 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.js +105 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.d.ts +23 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.js +37 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.d.ts +23 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.js +39 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.d.ts +78 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.js +69 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.d.ts +48 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.js +107 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.d.ts +60 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.js +153 -0
- package/dist-lib/esm/tools/builtin/index.d.ts +44 -0
- package/dist-lib/esm/tools/builtin/index.js +44 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.js +43 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.d.ts +15 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.js +28 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.d.ts +29 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.js +56 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.js +29 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.d.ts +21 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.js +44 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.d.ts +20 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.js +42 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.d.ts +20 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.js +48 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.js +36 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.js +36 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.d.ts +23 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.js +80 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.js +43 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.js +37 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.js +34 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.d.ts +26 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.js +72 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.js +66 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.js +35 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.d.ts +28 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.js +70 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.d.ts +16 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.js +30 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.js +28 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.js +70 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.d.ts +26 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.js +68 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.d.ts +30 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.js +228 -0
- package/dist-lib/esm/tools/editor/index.d.ts +32 -0
- package/dist-lib/esm/tools/editor/index.js +54 -0
- package/dist-lib/esm/tools/editor/toolViews.d.ts +10 -0
- package/dist-lib/esm/tools/editor/toolViews.js +53 -0
- package/dist-lib/esm/tools/editorTools.d.ts +5 -0
- package/dist-lib/esm/tools/editorTools.js +5 -0
- package/dist-lib/esm/tools/index.d.ts +8 -0
- package/dist-lib/esm/tools/index.js +8 -0
- package/dist-lib/esm/tools/textureUtils.d.ts +18 -0
- package/dist-lib/esm/tools/textureUtils.js +288 -0
- package/dist-lib/esm/types.d.ts +164 -0
- package/dist-lib/esm/types.js +1 -0
- package/dist-lib/esm/uv/UVUnwrapController.d.ts +108 -0
- package/dist-lib/esm/uv/UVUnwrapController.js +1022 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.d.ts +15 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.js +169 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.d.ts +54 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.js +630 -0
- package/dist-lib/esm/voxel/VoxelPainterController.d.ts +100 -0
- package/dist-lib/esm/voxel/VoxelPainterController.js +671 -0
- package/dist-lib/esm/voxel/index.d.ts +4 -0
- package/dist-lib/esm/voxel/index.js +4 -0
- package/dist-lib/esm/voxel/types.d.ts +78 -0
- package/dist-lib/esm/voxel/types.js +1 -0
- package/dist-lib/esm/web-component/MeshEditorElement.d.ts +103 -0
- package/dist-lib/esm/web-component/MeshEditorElement.js +246 -0
- package/dist-lib/esm/web-component/index.d.ts +1 -0
- package/dist-lib/esm/web-component/index.js +1 -0
- package/dist-lib/index.umd.js +3 -0
- package/dist-lib/mesheditor.css +2 -0
- package/dist-lib/mesheditor.css.map +1 -0
- package/dist-lib/standalone/mesheditor-element.bundle.js +3 -0
- package/package.json +114 -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,97 @@
|
|
|
1
|
+
import { Color3, Matrix, Vector3 } from '@babylonjs/core';
|
|
2
|
+
export type SdfShapeType = 'sphere' | 'ellipsoid' | 'box' | 'capsule' | 'round_cone' | 'cylinder' | 'torus' | 'cone' | 'plane';
|
|
3
|
+
export type SdfOperationType = 'union' | 'subtract' | 'intersect';
|
|
4
|
+
export interface SdfVec3Input {
|
|
5
|
+
x?: number;
|
|
6
|
+
y?: number;
|
|
7
|
+
z?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SdfPartDefinition {
|
|
10
|
+
shape: SdfShapeType;
|
|
11
|
+
op?: SdfOperationType;
|
|
12
|
+
blend?: number;
|
|
13
|
+
center?: SdfVec3Input | [number, number, number];
|
|
14
|
+
size?: SdfVec3Input | [number, number, number];
|
|
15
|
+
radius?: number;
|
|
16
|
+
endRadius?: number;
|
|
17
|
+
thickness?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
rounding?: number;
|
|
20
|
+
start?: SdfVec3Input | [number, number, number];
|
|
21
|
+
end?: SdfVec3Input | [number, number, number];
|
|
22
|
+
rotationDegrees?: SdfVec3Input | [number, number, number];
|
|
23
|
+
color?: string;
|
|
24
|
+
mirrorX?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface CompiledSdfPart {
|
|
27
|
+
shape: SdfShapeType;
|
|
28
|
+
op: SdfOperationType;
|
|
29
|
+
blend: number;
|
|
30
|
+
center: Vector3;
|
|
31
|
+
halfSize: Vector3;
|
|
32
|
+
radius: number;
|
|
33
|
+
endRadius: number;
|
|
34
|
+
thickness: number;
|
|
35
|
+
height: number;
|
|
36
|
+
rounding: number;
|
|
37
|
+
start: Vector3;
|
|
38
|
+
end: Vector3;
|
|
39
|
+
hasLocalTransform: boolean;
|
|
40
|
+
invRotation: Matrix;
|
|
41
|
+
boundsMin: Vector3;
|
|
42
|
+
boundsMax: Vector3;
|
|
43
|
+
color: Color3 | null;
|
|
44
|
+
}
|
|
45
|
+
export declare function parseSdfVec3(v: any, defX?: number, defY?: number, defZ?: number): Vector3;
|
|
46
|
+
/**
|
|
47
|
+
* Polynomial smooth minimum (Inigo Quilez) returning both blended distance and interpolation factor h in [0, 1].
|
|
48
|
+
*/
|
|
49
|
+
export declare function smoothMin(a: number, b: number, k: number): {
|
|
50
|
+
dist: number;
|
|
51
|
+
weightB: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Smooth subtraction of shape d2 from shape d1 with blend radius k.
|
|
55
|
+
*/
|
|
56
|
+
export declare function smoothSubtract(d1: number, d2: number, k: number): {
|
|
57
|
+
dist: number;
|
|
58
|
+
weightB: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Smooth intersection of shape d1 and shape d2 with blend radius k.
|
|
62
|
+
*/
|
|
63
|
+
export declare function smoothIntersect(d1: number, d2: number, k: number): {
|
|
64
|
+
dist: number;
|
|
65
|
+
weightB: number;
|
|
66
|
+
};
|
|
67
|
+
export declare function sdSphere(px: number, py: number, pz: number, r: number): number;
|
|
68
|
+
export declare function sdEllipsoid(px: number, py: number, pz: number, rx: number, ry: number, rz: number): number;
|
|
69
|
+
export declare function sdRoundBox(px: number, py: number, pz: number, hx: number, hy: number, hz: number, r: number): number;
|
|
70
|
+
export declare function sdCapsule(px: number, py: number, pz: number, ax: number, ay: number, az: number, bx: number, by: number, bz: number, r: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Tapered capsule / round cone from point A (radius r1) to point B (radius r2).
|
|
73
|
+
*/
|
|
74
|
+
export declare function sdRoundCone(px: number, py: number, pz: number, ax: number, ay: number, az: number, bx: number, by: number, bz: number, r1: number, r2: number): number;
|
|
75
|
+
export declare function sdCappedCylinder(px: number, py: number, pz: number, halfHeight: number, radius: number, rounding?: number): number;
|
|
76
|
+
export declare function sdCappedCone(px: number, py: number, pz: number, halfHeight: number, rBottom: number, rTop: number): number;
|
|
77
|
+
export declare function sdTorus(px: number, py: number, pz: number, majorRadius: number, minorRadius: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* Compiles raw part definitions into fast-evaluatable SDF primitives, optionally mirroring across X = 0.
|
|
80
|
+
*/
|
|
81
|
+
export declare function compileSdfParts(parts: SdfPartDefinition[], symmetryX?: boolean): CompiledSdfPart[];
|
|
82
|
+
/**
|
|
83
|
+
* Evaluates a single compiled SDF primitive at world point (wx, wy, wz).
|
|
84
|
+
*/
|
|
85
|
+
export declare function evaluateCompiledPart(part: CompiledSdfPart, wx: number, wy: number, wz: number): number;
|
|
86
|
+
/**
|
|
87
|
+
* Evaluates the composite SDF scene at (wx, wy, wz).
|
|
88
|
+
*/
|
|
89
|
+
export declare function evaluateSdfScene(parts: CompiledSdfPart[], wx: number, wy: number, wz: number): number;
|
|
90
|
+
/**
|
|
91
|
+
* Evaluates composite SDF color at a surface point using smooth blend weights.
|
|
92
|
+
*/
|
|
93
|
+
export declare function evaluateSdfColor(parts: CompiledSdfPart[], wx: number, wy: number, wz: number, defaultColor: Color3): Color3;
|
|
94
|
+
/**
|
|
95
|
+
* Computes analytical SDF gradient normal via central differences.
|
|
96
|
+
*/
|
|
97
|
+
export declare function computeSdfNormal(parts: CompiledSdfPart[], wx: number, wy: number, wz: number, eps?: number): Vector3;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Color3, Matrix, Quaternion, Vector3 } from '@babylonjs/core';
|
|
2
|
+
export function parseSdfVec3(v, defX = 0, defY = 0, defZ = 0) {
|
|
3
|
+
if (Array.isArray(v)) {
|
|
4
|
+
return new Vector3(Number.isFinite(Number(v[0])) ? Number(v[0]) : defX, Number.isFinite(Number(v[1])) ? Number(v[1]) : defY, Number.isFinite(Number(v[2])) ? Number(v[2]) : defZ);
|
|
5
|
+
}
|
|
6
|
+
if (v && typeof v === 'object') {
|
|
7
|
+
return new Vector3(Number.isFinite(Number(v.x)) ? Number(v.x) : defX, Number.isFinite(Number(v.y)) ? Number(v.y) : defY, Number.isFinite(Number(v.z)) ? Number(v.z) : defZ);
|
|
8
|
+
}
|
|
9
|
+
return new Vector3(defX, defY, defZ);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Polynomial smooth minimum (Inigo Quilez) returning both blended distance and interpolation factor h in [0, 1].
|
|
13
|
+
*/
|
|
14
|
+
export function smoothMin(a, b, k) {
|
|
15
|
+
if (k <= 1e-6) {
|
|
16
|
+
return b < a ? { dist: b, weightB: 1 } : { dist: a, weightB: 0 };
|
|
17
|
+
}
|
|
18
|
+
const h = Math.max(k - Math.abs(a - b), 0.0) / k;
|
|
19
|
+
const m = h * h * 0.25;
|
|
20
|
+
const dist = Math.min(a, b) - m * k;
|
|
21
|
+
const weightB = a < b ? m * 2.0 : 1.0 - m * 2.0;
|
|
22
|
+
return { dist, weightB };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Smooth subtraction of shape d2 from shape d1 with blend radius k.
|
|
26
|
+
*/
|
|
27
|
+
export function smoothSubtract(d1, d2, k) {
|
|
28
|
+
if (k <= 1e-6) {
|
|
29
|
+
return -d2 > d1 ? { dist: -d2, weightB: 1 } : { dist: d1, weightB: 0 };
|
|
30
|
+
}
|
|
31
|
+
const h = Math.max(0.5 - (0.5 * (d2 + d1)) / k, 0.0);
|
|
32
|
+
const clampedH = Math.min(h, 1.0);
|
|
33
|
+
const dist = d1 + (-d2 - d1) * clampedH + k * clampedH * (1.0 - clampedH);
|
|
34
|
+
return { dist, weightB: clampedH };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Smooth intersection of shape d1 and shape d2 with blend radius k.
|
|
38
|
+
*/
|
|
39
|
+
export function smoothIntersect(d1, d2, k) {
|
|
40
|
+
if (k <= 1e-6) {
|
|
41
|
+
return d2 > d1 ? { dist: d2, weightB: 1 } : { dist: d1, weightB: 0 };
|
|
42
|
+
}
|
|
43
|
+
const h = Math.max(0.5 - (0.5 * (d2 - d1)) / k, 0.0);
|
|
44
|
+
const clampedH = Math.min(h, 1.0);
|
|
45
|
+
const dist = d2 + (d1 - d2) * clampedH + k * clampedH * (1.0 - clampedH);
|
|
46
|
+
return { dist, weightB: clampedH };
|
|
47
|
+
}
|
|
48
|
+
/* =========================================================================
|
|
49
|
+
EXACT / ANALYTICAL SIGNED DISTANCE FUNCTIONS (Inigo Quilez)
|
|
50
|
+
========================================================================= */
|
|
51
|
+
export function sdSphere(px, py, pz, r) {
|
|
52
|
+
return Math.hypot(px, py, pz) - r;
|
|
53
|
+
}
|
|
54
|
+
export function sdEllipsoid(px, py, pz, rx, ry, rz) {
|
|
55
|
+
const safeRx = Math.max(1e-4, rx);
|
|
56
|
+
const safeRy = Math.max(1e-4, ry);
|
|
57
|
+
const safeRz = Math.max(1e-4, rz);
|
|
58
|
+
const k0 = Math.hypot(px / safeRx, py / safeRy, pz / safeRz);
|
|
59
|
+
if (k0 < 1e-8) {
|
|
60
|
+
return -Math.min(safeRx, safeRy, safeRz);
|
|
61
|
+
}
|
|
62
|
+
const k1 = Math.hypot(px / (safeRx * safeRx), py / (safeRy * safeRy), pz / (safeRz * safeRz));
|
|
63
|
+
return (k0 * (k0 - 1.0)) / k1;
|
|
64
|
+
}
|
|
65
|
+
export function sdRoundBox(px, py, pz, hx, hy, hz, r) {
|
|
66
|
+
const maxR = Math.min(hx, hy, hz);
|
|
67
|
+
const rad = Math.max(0, Math.min(r, maxR));
|
|
68
|
+
const qx = Math.abs(px) - (hx - rad);
|
|
69
|
+
const qy = Math.abs(py) - (hy - rad);
|
|
70
|
+
const qz = Math.abs(pz) - (hz - rad);
|
|
71
|
+
const outDist = Math.hypot(Math.max(qx, 0), Math.max(qy, 0), Math.max(qz, 0));
|
|
72
|
+
const inDist = Math.min(Math.max(qx, qy, qz), 0);
|
|
73
|
+
return outDist + inDist - rad;
|
|
74
|
+
}
|
|
75
|
+
export function sdCapsule(px, py, pz, ax, ay, az, bx, by, bz, r) {
|
|
76
|
+
const pax = px - ax;
|
|
77
|
+
const pay = py - ay;
|
|
78
|
+
const paz = pz - az;
|
|
79
|
+
const bax = bx - ax;
|
|
80
|
+
const bay = by - ay;
|
|
81
|
+
const baz = bz - az;
|
|
82
|
+
const baDot = bax * bax + bay * bay + baz * baz;
|
|
83
|
+
const h = baDot > 1e-8 ? Math.max(0, Math.min(1, (pax * bax + pay * bay + paz * baz) / baDot)) : 0;
|
|
84
|
+
return Math.hypot(pax - bax * h, pay - bay * h, paz - baz * h) - r;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Tapered capsule / round cone from point A (radius r1) to point B (radius r2).
|
|
88
|
+
*/
|
|
89
|
+
export function sdRoundCone(px, py, pz, ax, ay, az, bx, by, bz, r1, r2) {
|
|
90
|
+
const bax = bx - ax;
|
|
91
|
+
const bay = by - ay;
|
|
92
|
+
const baz = bz - az;
|
|
93
|
+
const l2 = bax * bax + bay * bay + baz * baz;
|
|
94
|
+
if (l2 < 1e-8) {
|
|
95
|
+
return sdSphere(px - ax, py - ay, pz - az, Math.max(r1, r2));
|
|
96
|
+
}
|
|
97
|
+
const rr = r1 - r2;
|
|
98
|
+
const a2 = l2 - rr * rr;
|
|
99
|
+
if (a2 <= 1e-8) {
|
|
100
|
+
return sdCapsule(px, py, pz, ax, ay, az, bx, by, bz, Math.max(r1, r2));
|
|
101
|
+
}
|
|
102
|
+
const il2 = 1.0 / l2;
|
|
103
|
+
const pax = px - ax;
|
|
104
|
+
const pay = py - ay;
|
|
105
|
+
const paz = pz - az;
|
|
106
|
+
const y = pax * bax + pay * bay + paz * baz;
|
|
107
|
+
const z = y - l2;
|
|
108
|
+
const xox = pax * l2 - bax * y;
|
|
109
|
+
const xoy = pay * l2 - bay * y;
|
|
110
|
+
const xoz = paz * l2 - baz * y;
|
|
111
|
+
const x2 = (xox * xox + xoy * xoy + xoz * xoz) * il2;
|
|
112
|
+
const y2 = y * y * l2;
|
|
113
|
+
const z2 = z * z * l2;
|
|
114
|
+
const k = Math.sign(rr) * rr * rr * x2;
|
|
115
|
+
if (Math.sign(z) * a2 * z2 > k) {
|
|
116
|
+
return Math.sqrt(x2 + z2) * il2 - r2;
|
|
117
|
+
}
|
|
118
|
+
if (Math.sign(y) * a2 * y2 < k) {
|
|
119
|
+
return Math.sqrt(x2 + y2) * il2 - r1;
|
|
120
|
+
}
|
|
121
|
+
return (Math.sqrt(x2 * a2 * il2) + y * rr) * il2 - r1;
|
|
122
|
+
}
|
|
123
|
+
export function sdCappedCylinder(px, py, pz, halfHeight, radius, rounding = 0) {
|
|
124
|
+
const rad = Math.max(0, Math.min(rounding, Math.min(halfHeight, radius)));
|
|
125
|
+
const dx = Math.hypot(px, pz) - (radius - rad);
|
|
126
|
+
const dy = Math.abs(py) - (halfHeight - rad);
|
|
127
|
+
return Math.min(Math.max(dx, dy), 0) + Math.hypot(Math.max(dx, 0), Math.max(dy, 0)) - rad;
|
|
128
|
+
}
|
|
129
|
+
export function sdCappedCone(px, py, pz, halfHeight, rBottom, rTop) {
|
|
130
|
+
const qx = Math.hypot(px, pz);
|
|
131
|
+
const qy = py;
|
|
132
|
+
const k1x = rTop;
|
|
133
|
+
const k1y = halfHeight;
|
|
134
|
+
const k2x = rTop - rBottom;
|
|
135
|
+
const k2y = 2.0 * halfHeight;
|
|
136
|
+
const cax = qx - Math.min(qx, qy < 0.0 ? rBottom : rTop);
|
|
137
|
+
const cay = Math.abs(qy) - halfHeight;
|
|
138
|
+
const denom = k2x * k2x + k2y * k2y;
|
|
139
|
+
const t = denom > 1e-8 ? Math.max(0, Math.min(1, ((k1x - qx) * k2x + (k1y - qy) * k2y) / denom)) : 0;
|
|
140
|
+
const cbx = qx - k1x + k2x * t;
|
|
141
|
+
const cby = qy - k1y + k2y * t;
|
|
142
|
+
const s = cbx < 0.0 && cay < 0.0 ? -1.0 : 1.0;
|
|
143
|
+
return s * Math.sqrt(Math.min(cax * cax + cay * cay, cbx * cbx + cby * cby));
|
|
144
|
+
}
|
|
145
|
+
export function sdTorus(px, py, pz, majorRadius, minorRadius) {
|
|
146
|
+
const qx = Math.hypot(px, pz) - majorRadius;
|
|
147
|
+
return Math.hypot(qx, py) - minorRadius;
|
|
148
|
+
}
|
|
149
|
+
function normalizeColorHex(hex) {
|
|
150
|
+
if (!hex || typeof hex !== 'string')
|
|
151
|
+
return null;
|
|
152
|
+
let clean = hex.trim();
|
|
153
|
+
if (/^[0-9a-fA-F]{6}$/.test(clean))
|
|
154
|
+
clean = '#' + clean;
|
|
155
|
+
if (/^#[0-9a-fA-F]{3}$/.test(clean)) {
|
|
156
|
+
clean =
|
|
157
|
+
'#' +
|
|
158
|
+
clean
|
|
159
|
+
.slice(1)
|
|
160
|
+
.split('')
|
|
161
|
+
.map((c) => c + c)
|
|
162
|
+
.join('');
|
|
163
|
+
}
|
|
164
|
+
if (/^#[0-9a-fA-F]{6}$/.test(clean)) {
|
|
165
|
+
return Color3.FromHexString(clean);
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
function compileSinglePart(part) {
|
|
170
|
+
const shape = (part.shape || 'sphere').toLowerCase();
|
|
171
|
+
const op = part.op === 'subtract' || part.op === 'intersect' ? part.op : 'union';
|
|
172
|
+
const defaultBlend = op === 'union' ? 0.05 : 0.02;
|
|
173
|
+
const blend = Math.max(0, Math.min(2.0, Number.isFinite(Number(part.blend)) ? Number(part.blend) : defaultBlend));
|
|
174
|
+
const center = parseSdfVec3(part.center, 0, 0, 0);
|
|
175
|
+
const rawSize = parseSdfVec3(part.size, 0.5, 0.5, 0.5);
|
|
176
|
+
const halfSize = new Vector3(Math.max(0.005, Math.abs(rawSize.x) * 0.5), Math.max(0.005, Math.abs(rawSize.y) * 0.5), Math.max(0.005, Math.abs(rawSize.z) * 0.5));
|
|
177
|
+
const radius = Math.max(0.005, Number.isFinite(Number(part.radius)) ? Number(part.radius) : 0.25);
|
|
178
|
+
const endRadius = Math.max(0.002, Number.isFinite(Number(part.endRadius)) ? Number(part.endRadius) : radius);
|
|
179
|
+
const thickness = Math.max(0.005, Number.isFinite(Number(part.thickness)) ? Number(part.thickness) : radius * 0.35);
|
|
180
|
+
const height = Math.max(0.01, Number.isFinite(Number(part.height)) ? Number(part.height) : rawSize.y || radius * 2);
|
|
181
|
+
const rounding = Math.max(0, Number.isFinite(Number(part.rounding)) ? Number(part.rounding) : 0);
|
|
182
|
+
const hasStart = part.start !== undefined;
|
|
183
|
+
const hasEnd = part.end !== undefined;
|
|
184
|
+
const start = hasStart
|
|
185
|
+
? parseSdfVec3(part.start, center.x, center.y - height * 0.5, center.z)
|
|
186
|
+
: new Vector3(center.x, center.y - height * 0.5, center.z);
|
|
187
|
+
const end = hasEnd
|
|
188
|
+
? parseSdfVec3(part.end, center.x, center.y + height * 0.5, center.z)
|
|
189
|
+
: new Vector3(center.x, center.y + height * 0.5, center.z);
|
|
190
|
+
const rotDeg = parseSdfVec3(part.rotationDegrees, 0, 0, 0);
|
|
191
|
+
const hasRot = Math.abs(rotDeg.x) > 1e-4 || Math.abs(rotDeg.y) > 1e-4 || Math.abs(rotDeg.z) > 1e-4;
|
|
192
|
+
let invRotation = Matrix.Identity();
|
|
193
|
+
if (hasRot) {
|
|
194
|
+
const q = Quaternion.FromEulerAngles((rotDeg.x * Math.PI) / 180, (rotDeg.y * Math.PI) / 180, (rotDeg.z * Math.PI) / 180);
|
|
195
|
+
Matrix.FromQuaternionToRef(q.invert(), invRotation);
|
|
196
|
+
}
|
|
197
|
+
// Compute generous world-space AABB for fast distance culling
|
|
198
|
+
let boundsMin;
|
|
199
|
+
let boundsMax;
|
|
200
|
+
if ((shape === 'capsule' || shape === 'round_cone') && (hasStart || hasEnd)) {
|
|
201
|
+
const maxR = Math.max(radius, endRadius) + blend + 0.05;
|
|
202
|
+
boundsMin = new Vector3(Math.min(start.x, end.x) - maxR, Math.min(start.y, end.y) - maxR, Math.min(start.z, end.z) - maxR);
|
|
203
|
+
boundsMax = new Vector3(Math.max(start.x, end.x) + maxR, Math.max(start.y, end.y) + maxR, Math.max(start.z, end.z) + maxR);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
let maxExtent = radius;
|
|
207
|
+
if (shape === 'box' || shape === 'ellipsoid') {
|
|
208
|
+
maxExtent = hasRot
|
|
209
|
+
? Math.hypot(halfSize.x, halfSize.y, halfSize.z)
|
|
210
|
+
: Math.max(halfSize.x, halfSize.y, halfSize.z);
|
|
211
|
+
}
|
|
212
|
+
else if (shape === 'cylinder' || shape === 'cone') {
|
|
213
|
+
maxExtent = Math.hypot(Math.max(radius, endRadius), height * 0.5);
|
|
214
|
+
}
|
|
215
|
+
else if (shape === 'torus') {
|
|
216
|
+
maxExtent = radius + thickness;
|
|
217
|
+
}
|
|
218
|
+
else if (shape === 'capsule' || shape === 'round_cone') {
|
|
219
|
+
maxExtent = height * 0.5 + Math.max(radius, endRadius);
|
|
220
|
+
}
|
|
221
|
+
const pad = maxExtent + blend + 0.05;
|
|
222
|
+
boundsMin = new Vector3(center.x - pad, center.y - pad, center.z - pad);
|
|
223
|
+
boundsMax = new Vector3(center.x + pad, center.y + pad, center.z + pad);
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
shape,
|
|
227
|
+
op,
|
|
228
|
+
blend,
|
|
229
|
+
center,
|
|
230
|
+
halfSize,
|
|
231
|
+
radius,
|
|
232
|
+
endRadius,
|
|
233
|
+
thickness,
|
|
234
|
+
height,
|
|
235
|
+
rounding,
|
|
236
|
+
start,
|
|
237
|
+
end,
|
|
238
|
+
hasLocalTransform: hasRot,
|
|
239
|
+
invRotation,
|
|
240
|
+
boundsMin,
|
|
241
|
+
boundsMax,
|
|
242
|
+
color: normalizeColorHex(part.color),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Compiles raw part definitions into fast-evaluatable SDF primitives, optionally mirroring across X = 0.
|
|
247
|
+
*/
|
|
248
|
+
export function compileSdfParts(parts, symmetryX = false) {
|
|
249
|
+
const compiled = [];
|
|
250
|
+
for (const p of parts) {
|
|
251
|
+
const base = compileSinglePart(p);
|
|
252
|
+
compiled.push(base);
|
|
253
|
+
const shouldMirror = p.mirrorX !== undefined ? p.mirrorX : symmetryX;
|
|
254
|
+
if (shouldMirror) {
|
|
255
|
+
const isOffCenter = Math.abs(base.center.x) > 1e-4 ||
|
|
256
|
+
Math.abs(base.start.x) > 1e-4 ||
|
|
257
|
+
Math.abs(base.end.x) > 1e-4;
|
|
258
|
+
if (isOffCenter) {
|
|
259
|
+
const rotDeg = parseSdfVec3(p.rotationDegrees, 0, 0, 0);
|
|
260
|
+
const mirroredDef = {
|
|
261
|
+
...p,
|
|
262
|
+
center: { x: -base.center.x, y: base.center.y, z: base.center.z },
|
|
263
|
+
start: { x: -base.start.x, y: base.start.y, z: base.start.z },
|
|
264
|
+
end: { x: -base.end.x, y: base.end.y, z: base.end.z },
|
|
265
|
+
rotationDegrees: { x: rotDeg.x, y: -rotDeg.y, z: -rotDeg.z },
|
|
266
|
+
mirrorX: false,
|
|
267
|
+
};
|
|
268
|
+
compiled.push(compileSinglePart(mirroredDef));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return compiled;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Evaluates a single compiled SDF primitive at world point (wx, wy, wz).
|
|
276
|
+
*/
|
|
277
|
+
export function evaluateCompiledPart(part, wx, wy, wz) {
|
|
278
|
+
if (part.shape === 'capsule' || part.shape === 'round_cone') {
|
|
279
|
+
if (!part.hasLocalTransform) {
|
|
280
|
+
if (Math.abs(part.radius - part.endRadius) > 1e-4 || part.shape === 'round_cone') {
|
|
281
|
+
return sdRoundCone(wx, wy, wz, part.start.x, part.start.y, part.start.z, part.end.x, part.end.y, part.end.z, part.radius, part.endRadius);
|
|
282
|
+
}
|
|
283
|
+
return sdCapsule(wx, wy, wz, part.start.x, part.start.y, part.start.z, part.end.x, part.end.y, part.end.z, part.radius);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
let lx = wx - part.center.x;
|
|
287
|
+
let ly = wy - part.center.y;
|
|
288
|
+
let lz = wz - part.center.z;
|
|
289
|
+
if (part.hasLocalTransform) {
|
|
290
|
+
const m = part.invRotation.m;
|
|
291
|
+
const rx = lx * m[0] + ly * m[4] + lz * m[8];
|
|
292
|
+
const ry = lx * m[1] + ly * m[5] + lz * m[9];
|
|
293
|
+
const rz = lx * m[2] + ly * m[6] + lz * m[10];
|
|
294
|
+
lx = rx;
|
|
295
|
+
ly = ry;
|
|
296
|
+
lz = rz;
|
|
297
|
+
}
|
|
298
|
+
switch (part.shape) {
|
|
299
|
+
case 'sphere':
|
|
300
|
+
return sdSphere(lx, ly, lz, part.radius);
|
|
301
|
+
case 'ellipsoid':
|
|
302
|
+
return sdEllipsoid(lx, ly, lz, part.halfSize.x, part.halfSize.y, part.halfSize.z);
|
|
303
|
+
case 'box':
|
|
304
|
+
return sdRoundBox(lx, ly, lz, part.halfSize.x, part.halfSize.y, part.halfSize.z, part.rounding);
|
|
305
|
+
case 'cylinder':
|
|
306
|
+
return sdCappedCylinder(lx, ly, lz, part.height * 0.5, part.radius, part.rounding);
|
|
307
|
+
case 'cone':
|
|
308
|
+
return sdCappedCone(lx, ly, lz, part.height * 0.5, part.radius, part.endRadius);
|
|
309
|
+
case 'torus':
|
|
310
|
+
return sdTorus(lx, ly, lz, part.radius, part.thickness);
|
|
311
|
+
case 'capsule':
|
|
312
|
+
case 'round_cone':
|
|
313
|
+
return sdRoundCone(lx, ly, lz, 0, -part.height * 0.5, 0, 0, part.height * 0.5, 0, part.radius, part.endRadius);
|
|
314
|
+
case 'plane':
|
|
315
|
+
return ly;
|
|
316
|
+
default:
|
|
317
|
+
return sdSphere(lx, ly, lz, part.radius);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Evaluates the composite SDF scene at (wx, wy, wz).
|
|
322
|
+
*/
|
|
323
|
+
export function evaluateSdfScene(parts, wx, wy, wz) {
|
|
324
|
+
let d = 1e6;
|
|
325
|
+
for (let i = 0; i < parts.length; i++) {
|
|
326
|
+
const p = parts[i];
|
|
327
|
+
// Fast AABB distance lower bound check for union parts when already near surface
|
|
328
|
+
if (p.op === 'union' && d < 1e5) {
|
|
329
|
+
const dx = wx < p.boundsMin.x ? p.boundsMin.x - wx : wx > p.boundsMax.x ? wx - p.boundsMax.x : 0;
|
|
330
|
+
const dy = wy < p.boundsMin.y ? p.boundsMin.y - wy : wy > p.boundsMax.y ? wy - p.boundsMax.y : 0;
|
|
331
|
+
const dz = wz < p.boundsMin.z ? p.boundsMin.z - wz : wz > p.boundsMax.z ? wz - p.boundsMax.z : 0;
|
|
332
|
+
if (dx > d + p.blend || dy > d + p.blend || dz > d + p.blend) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const pd = evaluateCompiledPart(p, wx, wy, wz);
|
|
337
|
+
if (i === 0) {
|
|
338
|
+
d = pd;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (p.op === 'union') {
|
|
342
|
+
d = smoothMin(d, pd, p.blend).dist;
|
|
343
|
+
}
|
|
344
|
+
else if (p.op === 'subtract') {
|
|
345
|
+
d = smoothSubtract(d, pd, p.blend).dist;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
d = smoothIntersect(d, pd, p.blend).dist;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return d;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Evaluates composite SDF color at a surface point using smooth blend weights.
|
|
355
|
+
*/
|
|
356
|
+
export function evaluateSdfColor(parts, wx, wy, wz, defaultColor) {
|
|
357
|
+
let d = 1e6;
|
|
358
|
+
let r = defaultColor.r;
|
|
359
|
+
let g = defaultColor.g;
|
|
360
|
+
let b = defaultColor.b;
|
|
361
|
+
for (let i = 0; i < parts.length; i++) {
|
|
362
|
+
const p = parts[i];
|
|
363
|
+
const pd = evaluateCompiledPart(p, wx, wy, wz);
|
|
364
|
+
const pc = p.color || defaultColor;
|
|
365
|
+
if (i === 0) {
|
|
366
|
+
d = pd;
|
|
367
|
+
r = pc.r;
|
|
368
|
+
g = pc.g;
|
|
369
|
+
b = pc.b;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
let res;
|
|
373
|
+
if (p.op === 'union') {
|
|
374
|
+
res = smoothMin(d, pd, p.blend);
|
|
375
|
+
}
|
|
376
|
+
else if (p.op === 'subtract') {
|
|
377
|
+
res = smoothSubtract(d, pd, p.blend);
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
res = smoothIntersect(d, pd, p.blend);
|
|
381
|
+
}
|
|
382
|
+
d = res.dist;
|
|
383
|
+
const w = res.weightB;
|
|
384
|
+
r = r * (1 - w) + pc.r * w;
|
|
385
|
+
g = g * (1 - w) + pc.g * w;
|
|
386
|
+
b = b * (1 - w) + pc.b * w;
|
|
387
|
+
}
|
|
388
|
+
return new Color3(r, g, b);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Computes analytical SDF gradient normal via central differences.
|
|
392
|
+
*/
|
|
393
|
+
export function computeSdfNormal(parts, wx, wy, wz, eps = 0.002) {
|
|
394
|
+
const dx = evaluateSdfScene(parts, wx + eps, wy, wz) - evaluateSdfScene(parts, wx - eps, wy, wz);
|
|
395
|
+
const dy = evaluateSdfScene(parts, wx, wy + eps, wz) - evaluateSdfScene(parts, wx, wy - eps, wz);
|
|
396
|
+
const dz = evaluateSdfScene(parts, wx, wy, wz + eps) - evaluateSdfScene(parts, wx, wy, wz - eps);
|
|
397
|
+
const len = Math.hypot(dx, dy, dz);
|
|
398
|
+
if (len < 1e-9) {
|
|
399
|
+
return new Vector3(0, 1, 0);
|
|
400
|
+
}
|
|
401
|
+
return new Vector3(dx / len, dy / len, dz / len);
|
|
402
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Vector3, VertexData } from '@babylonjs/core';
|
|
2
|
+
import { CompiledSdfPart } from './sdfPrimitives';
|
|
3
|
+
export interface SurfaceNetsOptions {
|
|
4
|
+
resolution?: number;
|
|
5
|
+
smoothIterations?: number;
|
|
6
|
+
defaultColor?: string;
|
|
7
|
+
computeVertexColors?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SurfaceNetsResult {
|
|
10
|
+
vertexData: VertexData;
|
|
11
|
+
resolution: {
|
|
12
|
+
nx: number;
|
|
13
|
+
ny: number;
|
|
14
|
+
nz: number;
|
|
15
|
+
cellSize: number;
|
|
16
|
+
};
|
|
17
|
+
bounds: {
|
|
18
|
+
min: Vector3;
|
|
19
|
+
max: Vector3;
|
|
20
|
+
size: Vector3;
|
|
21
|
+
};
|
|
22
|
+
hasVertexColors: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extracts a crack-free, watertight indexed triangle mesh from compiled SDF primitives
|
|
26
|
+
* using Surface Nets with Newton isosurface projection, Taubin/Laplacian smoothing,
|
|
27
|
+
* analytical SDF gradient normals, and box/triplanar UVs.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractSdfSurfaceNets(parts: CompiledSdfPart[], options?: SurfaceNetsOptions): SurfaceNetsResult;
|