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,1792 @@
|
|
|
1
|
+
import { Vector3 } from '@babylonjs/core';
|
|
2
|
+
import { PathFactory } from './PathFactory';
|
|
3
|
+
const STYLE_ID = 'path-extrusion-studio-style';
|
|
4
|
+
const CSS = `
|
|
5
|
+
.pes-overlay {
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: 0;
|
|
8
|
+
background: transparent;
|
|
9
|
+
z-index: 100000;
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
}
|
|
16
|
+
.pes-dialog {
|
|
17
|
+
background: #181d29;
|
|
18
|
+
color: #e2e8f0;
|
|
19
|
+
width: min(780px, 95vw);
|
|
20
|
+
max-height: 90vh;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
border-radius: 12px;
|
|
24
|
+
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.75), 0 0 0 1px #2e384d;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
position: absolute;
|
|
27
|
+
pointer-events: auto;
|
|
28
|
+
}
|
|
29
|
+
.pes-header {
|
|
30
|
+
padding: 10px 16px;
|
|
31
|
+
background: #1e2433;
|
|
32
|
+
border-bottom: 1px solid #2e384d;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: space-between;
|
|
36
|
+
cursor: move;
|
|
37
|
+
user-select: none;
|
|
38
|
+
gap: 12px;
|
|
39
|
+
}
|
|
40
|
+
.pes-header-left {
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
gap: 10px;
|
|
44
|
+
min-width: 0;
|
|
45
|
+
flex: 1;
|
|
46
|
+
}
|
|
47
|
+
.pes-header-title {
|
|
48
|
+
font-size: 14px;
|
|
49
|
+
font-weight: 700;
|
|
50
|
+
color: #38bdf8;
|
|
51
|
+
display: flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
gap: 6px;
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
}
|
|
56
|
+
.pes-header-actions {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: 8px;
|
|
60
|
+
}
|
|
61
|
+
.pes-close-btn {
|
|
62
|
+
background: transparent;
|
|
63
|
+
border: none;
|
|
64
|
+
color: #94a3b8;
|
|
65
|
+
font-size: 18px;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
padding: 2px 6px;
|
|
68
|
+
border-radius: 4px;
|
|
69
|
+
line-height: 1;
|
|
70
|
+
}
|
|
71
|
+
.pes-close-btn:hover {
|
|
72
|
+
background: #334155;
|
|
73
|
+
color: #fff;
|
|
74
|
+
}
|
|
75
|
+
.pes-tabs {
|
|
76
|
+
display: flex;
|
|
77
|
+
background: #141824;
|
|
78
|
+
border-bottom: 1px solid #2e384d;
|
|
79
|
+
padding: 0 12px;
|
|
80
|
+
gap: 4px;
|
|
81
|
+
overflow-x: auto;
|
|
82
|
+
}
|
|
83
|
+
.pes-tab {
|
|
84
|
+
padding: 9px 14px;
|
|
85
|
+
font-size: 12px;
|
|
86
|
+
font-weight: 600;
|
|
87
|
+
color: #94a3b8;
|
|
88
|
+
border: none;
|
|
89
|
+
background: transparent;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
border-bottom: 2px solid transparent;
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: 6px;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
transition: all 0.15s ease;
|
|
97
|
+
}
|
|
98
|
+
.pes-tab:hover {
|
|
99
|
+
color: #f1f5f9;
|
|
100
|
+
}
|
|
101
|
+
.pes-tab.active {
|
|
102
|
+
color: #38bdf8;
|
|
103
|
+
border-bottom-color: #38bdf8;
|
|
104
|
+
background: rgba(56, 189, 248, 0.06);
|
|
105
|
+
}
|
|
106
|
+
.pes-body {
|
|
107
|
+
padding: 16px 20px;
|
|
108
|
+
overflow-y: auto;
|
|
109
|
+
flex: 1;
|
|
110
|
+
display: flex;
|
|
111
|
+
flex-direction: column;
|
|
112
|
+
gap: 14px;
|
|
113
|
+
}
|
|
114
|
+
.pes-section {
|
|
115
|
+
background: #1e2433;
|
|
116
|
+
border: 1px solid #2d3748;
|
|
117
|
+
border-radius: 8px;
|
|
118
|
+
padding: 12px 14px;
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: column;
|
|
121
|
+
gap: 10px;
|
|
122
|
+
}
|
|
123
|
+
.pes-section-title {
|
|
124
|
+
font-size: 11px;
|
|
125
|
+
font-weight: 700;
|
|
126
|
+
text-transform: uppercase;
|
|
127
|
+
letter-spacing: 0.6px;
|
|
128
|
+
color: #38bdf8;
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
justify-content: space-between;
|
|
132
|
+
}
|
|
133
|
+
.pes-row {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
gap: 10px;
|
|
137
|
+
}
|
|
138
|
+
.pes-row > label {
|
|
139
|
+
width: 150px;
|
|
140
|
+
min-width: 150px;
|
|
141
|
+
font-size: 12px;
|
|
142
|
+
color: #94a3b8;
|
|
143
|
+
flex-shrink: 0;
|
|
144
|
+
}
|
|
145
|
+
.pes-row-content {
|
|
146
|
+
flex: 1;
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 8px;
|
|
150
|
+
min-width: 0;
|
|
151
|
+
}
|
|
152
|
+
.pes-input {
|
|
153
|
+
background: #111520;
|
|
154
|
+
color: #f1f5f9;
|
|
155
|
+
border: 1px solid #334155;
|
|
156
|
+
border-radius: 6px;
|
|
157
|
+
padding: 5px 8px;
|
|
158
|
+
font-size: 12px;
|
|
159
|
+
outline: none;
|
|
160
|
+
box-sizing: border-box;
|
|
161
|
+
}
|
|
162
|
+
.pes-select {
|
|
163
|
+
appearance: none;
|
|
164
|
+
-webkit-appearance: none;
|
|
165
|
+
-moz-appearance: none;
|
|
166
|
+
color-scheme: dark;
|
|
167
|
+
background-color: #21262d;
|
|
168
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
|
|
169
|
+
background-repeat: no-repeat;
|
|
170
|
+
background-position: right 8px center;
|
|
171
|
+
background-size: 12px 12px;
|
|
172
|
+
color: #f1f5f9;
|
|
173
|
+
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
174
|
+
border-radius: 6px;
|
|
175
|
+
padding: 2px 26px 2px 8px;
|
|
176
|
+
font-size: 12px;
|
|
177
|
+
outline: none;
|
|
178
|
+
box-sizing: border-box;
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
transition: border-color 0.15s ease, background-color 0.15s ease;
|
|
181
|
+
}
|
|
182
|
+
.pes-input:focus {
|
|
183
|
+
border-color: #38bdf8;
|
|
184
|
+
}
|
|
185
|
+
.pes-select:hover {
|
|
186
|
+
background-color: #282e37;
|
|
187
|
+
border-color: rgba(255, 255, 255, 0.28);
|
|
188
|
+
}
|
|
189
|
+
.pes-select:focus {
|
|
190
|
+
background-color: #1c2128;
|
|
191
|
+
border-color: #38bdf8;
|
|
192
|
+
box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
|
|
193
|
+
}
|
|
194
|
+
.pes-select option {
|
|
195
|
+
background: #161b22;
|
|
196
|
+
color: #f0f6fc;
|
|
197
|
+
padding: 6px 10px;
|
|
198
|
+
}
|
|
199
|
+
.pes-input[type=number] {
|
|
200
|
+
width: 75px;
|
|
201
|
+
}
|
|
202
|
+
.pes-slider {
|
|
203
|
+
flex: 1;
|
|
204
|
+
height: 6px;
|
|
205
|
+
background: #334155;
|
|
206
|
+
border-radius: 3px;
|
|
207
|
+
outline: none;
|
|
208
|
+
accent-color: #38bdf8;
|
|
209
|
+
cursor: pointer;
|
|
210
|
+
}
|
|
211
|
+
.pes-btn {
|
|
212
|
+
background: #334155;
|
|
213
|
+
color: #f8fafc;
|
|
214
|
+
border: 1px solid #475569;
|
|
215
|
+
border-radius: 6px;
|
|
216
|
+
padding: 5px 10px;
|
|
217
|
+
font-size: 12px;
|
|
218
|
+
font-weight: 500;
|
|
219
|
+
cursor: pointer;
|
|
220
|
+
display: inline-flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
gap: 6px;
|
|
223
|
+
transition: all 0.15s ease;
|
|
224
|
+
user-select: none;
|
|
225
|
+
}
|
|
226
|
+
.pes-btn:hover {
|
|
227
|
+
background: #475569;
|
|
228
|
+
}
|
|
229
|
+
.pes-btn.primary {
|
|
230
|
+
background: #2563eb;
|
|
231
|
+
border-color: #3b82f6;
|
|
232
|
+
}
|
|
233
|
+
.pes-btn.primary:hover {
|
|
234
|
+
background: #1d4ed8;
|
|
235
|
+
}
|
|
236
|
+
.pes-btn.success {
|
|
237
|
+
background: #16a34a;
|
|
238
|
+
border-color: #22c55e;
|
|
239
|
+
}
|
|
240
|
+
.pes-btn.success:hover {
|
|
241
|
+
background: #15803d;
|
|
242
|
+
}
|
|
243
|
+
.pes-btn.accent {
|
|
244
|
+
background: #0284c7;
|
|
245
|
+
border-color: #38bdf8;
|
|
246
|
+
}
|
|
247
|
+
.pes-btn.accent:hover {
|
|
248
|
+
background: #0369a1;
|
|
249
|
+
}
|
|
250
|
+
.pes-btn.danger {
|
|
251
|
+
background: #dc2626;
|
|
252
|
+
border-color: #ef4444;
|
|
253
|
+
}
|
|
254
|
+
.pes-btn.danger:hover {
|
|
255
|
+
background: #b91c1c;
|
|
256
|
+
}
|
|
257
|
+
.pes-btn.small {
|
|
258
|
+
padding: 3px 6px;
|
|
259
|
+
font-size: 11px;
|
|
260
|
+
}
|
|
261
|
+
.pes-badge {
|
|
262
|
+
font-size: 10px;
|
|
263
|
+
padding: 2px 6px;
|
|
264
|
+
border-radius: 10px;
|
|
265
|
+
background: #0f766e;
|
|
266
|
+
color: #ccfbf1;
|
|
267
|
+
font-weight: 600;
|
|
268
|
+
letter-spacing: 0.3px;
|
|
269
|
+
}
|
|
270
|
+
.pes-footer {
|
|
271
|
+
padding: 10px 18px;
|
|
272
|
+
background: #1e2433;
|
|
273
|
+
border-top: 1px solid #2e384d;
|
|
274
|
+
display: flex;
|
|
275
|
+
justify-content: space-between;
|
|
276
|
+
align-items: center;
|
|
277
|
+
}
|
|
278
|
+
.pes-canvas-container {
|
|
279
|
+
display: flex;
|
|
280
|
+
flex-direction: column;
|
|
281
|
+
align-items: center;
|
|
282
|
+
background: #0b0f19;
|
|
283
|
+
border: 1px solid #334155;
|
|
284
|
+
border-radius: 8px;
|
|
285
|
+
padding: 12px;
|
|
286
|
+
gap: 10px;
|
|
287
|
+
width: 100%;
|
|
288
|
+
box-sizing: border-box;
|
|
289
|
+
}
|
|
290
|
+
.pes-canvas {
|
|
291
|
+
background: #0f172a;
|
|
292
|
+
border: 1px solid #1e293b;
|
|
293
|
+
border-radius: 6px;
|
|
294
|
+
cursor: grab;
|
|
295
|
+
display: block;
|
|
296
|
+
width: 100%;
|
|
297
|
+
max-width: 720px;
|
|
298
|
+
aspect-ratio: 2 / 1;
|
|
299
|
+
box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.6);
|
|
300
|
+
}
|
|
301
|
+
.pes-canvas-toolbar {
|
|
302
|
+
display: flex;
|
|
303
|
+
align-items: center;
|
|
304
|
+
gap: 6px;
|
|
305
|
+
flex-wrap: wrap;
|
|
306
|
+
width: 100%;
|
|
307
|
+
justify-content: center;
|
|
308
|
+
}
|
|
309
|
+
.pes-canvas-hint {
|
|
310
|
+
font-size: 11px;
|
|
311
|
+
color: #64748b;
|
|
312
|
+
text-align: center;
|
|
313
|
+
line-height: 1.4;
|
|
314
|
+
user-select: none;
|
|
315
|
+
}
|
|
316
|
+
.pes-table-container {
|
|
317
|
+
max-height: 160px;
|
|
318
|
+
overflow-y: auto;
|
|
319
|
+
border: 1px solid #334155;
|
|
320
|
+
border-radius: 6px;
|
|
321
|
+
background: #111520;
|
|
322
|
+
}
|
|
323
|
+
.pes-table {
|
|
324
|
+
width: 100%;
|
|
325
|
+
border-collapse: collapse;
|
|
326
|
+
font-size: 11px;
|
|
327
|
+
}
|
|
328
|
+
.pes-table th {
|
|
329
|
+
background: #1e2433;
|
|
330
|
+
color: #94a3b8;
|
|
331
|
+
text-align: left;
|
|
332
|
+
padding: 5px 8px;
|
|
333
|
+
position: sticky;
|
|
334
|
+
top: 0;
|
|
335
|
+
border-bottom: 1px solid #334155;
|
|
336
|
+
}
|
|
337
|
+
.pes-table td {
|
|
338
|
+
padding: 4px 8px;
|
|
339
|
+
border-bottom: 1px solid #1e293b;
|
|
340
|
+
}
|
|
341
|
+
.pes-table tr:hover {
|
|
342
|
+
background: rgba(56, 189, 248, 0.05);
|
|
343
|
+
}
|
|
344
|
+
`;
|
|
345
|
+
export class PathExtrusionStudio {
|
|
346
|
+
service;
|
|
347
|
+
controller;
|
|
348
|
+
onCloseCallback;
|
|
349
|
+
static instance = null;
|
|
350
|
+
overlay;
|
|
351
|
+
dialog;
|
|
352
|
+
activeTab = 'shape';
|
|
353
|
+
// Draggable state
|
|
354
|
+
isDragging = false;
|
|
355
|
+
dragStartX = 0;
|
|
356
|
+
dragStartY = 0;
|
|
357
|
+
dialogStartX = 0;
|
|
358
|
+
dialogStartY = 0;
|
|
359
|
+
// Header controls
|
|
360
|
+
pathSelect;
|
|
361
|
+
// Tabs
|
|
362
|
+
tabButtons = new Map();
|
|
363
|
+
tabContents = new Map();
|
|
364
|
+
// 2D Canvas Editor state
|
|
365
|
+
canvas;
|
|
366
|
+
ctx;
|
|
367
|
+
canvasWidth = 720;
|
|
368
|
+
canvasHeight = 360;
|
|
369
|
+
scale = 45; // pixels per world meter
|
|
370
|
+
panX = 0;
|
|
371
|
+
panY = 0;
|
|
372
|
+
isCanvasDragging = false;
|
|
373
|
+
isPanning = false;
|
|
374
|
+
panStartX = 0;
|
|
375
|
+
panStartY = 0;
|
|
376
|
+
draggedVertexIndex = null;
|
|
377
|
+
hoveredVertexIndex = null;
|
|
378
|
+
hoveredEdgeIndex = null;
|
|
379
|
+
snapGrid = 0.1; // meters
|
|
380
|
+
mouseWorldCoord = { x: 0, y: 0 };
|
|
381
|
+
// Preset parameters state
|
|
382
|
+
currentPreset = 'pipe';
|
|
383
|
+
presetSegments = 16;
|
|
384
|
+
presetRadius = 1.5;
|
|
385
|
+
presetWidth = 3;
|
|
386
|
+
presetHeight = 0.5;
|
|
387
|
+
presetDepth = 0.5;
|
|
388
|
+
presetThickness = 0.2;
|
|
389
|
+
presetExcludeBottom = 0;
|
|
390
|
+
presetStarPoints = 5;
|
|
391
|
+
presetOuterRadius = 2;
|
|
392
|
+
presetInnerRadius = 0.9;
|
|
393
|
+
// Throttled 3D update
|
|
394
|
+
updateTimer = null;
|
|
395
|
+
constructor(service, controller, onCloseCallback = () => { }) {
|
|
396
|
+
this.service = service;
|
|
397
|
+
this.controller = controller;
|
|
398
|
+
this.onCloseCallback = onCloseCallback;
|
|
399
|
+
this.injectStyle();
|
|
400
|
+
this.createDOM();
|
|
401
|
+
this.detectCurrentPreset();
|
|
402
|
+
this.renderActiveTab();
|
|
403
|
+
this.fitCanvasView();
|
|
404
|
+
PathExtrusionStudio.instance = this;
|
|
405
|
+
}
|
|
406
|
+
static open(service, controller, onClose = () => { }) {
|
|
407
|
+
if (PathExtrusionStudio.instance && document.body.contains(PathExtrusionStudio.instance.overlay)) {
|
|
408
|
+
PathExtrusionStudio.instance.refresh();
|
|
409
|
+
return PathExtrusionStudio.instance;
|
|
410
|
+
}
|
|
411
|
+
if (PathExtrusionStudio.instance) {
|
|
412
|
+
PathExtrusionStudio.instance.close();
|
|
413
|
+
}
|
|
414
|
+
return new PathExtrusionStudio(service, controller, onClose);
|
|
415
|
+
}
|
|
416
|
+
static close() {
|
|
417
|
+
if (PathExtrusionStudio.instance) {
|
|
418
|
+
PathExtrusionStudio.instance.close();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
static isOpen() {
|
|
422
|
+
return !!PathExtrusionStudio.instance;
|
|
423
|
+
}
|
|
424
|
+
injectStyle() {
|
|
425
|
+
if (document.getElementById(STYLE_ID))
|
|
426
|
+
return;
|
|
427
|
+
const style = document.createElement('style');
|
|
428
|
+
style.id = STYLE_ID;
|
|
429
|
+
style.textContent = CSS;
|
|
430
|
+
document.head.appendChild(style);
|
|
431
|
+
}
|
|
432
|
+
close() {
|
|
433
|
+
if (this.updateTimer) {
|
|
434
|
+
clearTimeout(this.updateTimer);
|
|
435
|
+
this.updateTimer = null;
|
|
436
|
+
}
|
|
437
|
+
if (this.overlay && this.overlay.parentNode) {
|
|
438
|
+
this.overlay.parentNode.removeChild(this.overlay);
|
|
439
|
+
}
|
|
440
|
+
PathExtrusionStudio.instance = null;
|
|
441
|
+
this.onCloseCallback();
|
|
442
|
+
}
|
|
443
|
+
refresh() {
|
|
444
|
+
this.updatePathDropdown();
|
|
445
|
+
this.renderActiveTab();
|
|
446
|
+
this.redrawCanvas();
|
|
447
|
+
}
|
|
448
|
+
getActivePath() {
|
|
449
|
+
return this.controller.activePath || undefined;
|
|
450
|
+
}
|
|
451
|
+
triggerWYSIWYGUpdate() {
|
|
452
|
+
if (this.updateTimer)
|
|
453
|
+
clearTimeout(this.updateTimer);
|
|
454
|
+
this.updateTimer = setTimeout(() => {
|
|
455
|
+
this.controller.updatePreviewMesh();
|
|
456
|
+
this.controller.onStateChanged?.();
|
|
457
|
+
}, 16);
|
|
458
|
+
}
|
|
459
|
+
// ─── DOM Building ──────────────────────────────────────────────────────────
|
|
460
|
+
createDOM() {
|
|
461
|
+
this.overlay = document.createElement('div');
|
|
462
|
+
this.overlay.className = 'pes-overlay';
|
|
463
|
+
this.dialog = document.createElement('div');
|
|
464
|
+
this.dialog.className = 'pes-dialog';
|
|
465
|
+
this.dialog.id = 'pathExtrusionStudioDialog';
|
|
466
|
+
this.dialog.addEventListener('keydown', (e) => {
|
|
467
|
+
e.stopPropagation();
|
|
468
|
+
if (e.key === 'Escape')
|
|
469
|
+
this.close();
|
|
470
|
+
});
|
|
471
|
+
this.dialog.addEventListener('keyup', (e) => e.stopPropagation());
|
|
472
|
+
// 1. Header
|
|
473
|
+
const header = document.createElement('div');
|
|
474
|
+
header.className = 'pes-header';
|
|
475
|
+
const headerLeft = document.createElement('div');
|
|
476
|
+
headerLeft.className = 'pes-header-left';
|
|
477
|
+
const headerTitle = document.createElement('div');
|
|
478
|
+
headerTitle.className = 'pes-header-title';
|
|
479
|
+
headerTitle.innerHTML = `<span>🛣️</span><span>Path Extrusion Studio</span>`;
|
|
480
|
+
this.pathSelect = document.createElement('select');
|
|
481
|
+
this.pathSelect.className = 'pes-select';
|
|
482
|
+
this.pathSelect.style.maxWidth = '260px';
|
|
483
|
+
this.pathSelect.onchange = () => {
|
|
484
|
+
this.controller.selectPath(this.pathSelect.value);
|
|
485
|
+
this.detectCurrentPreset();
|
|
486
|
+
this.renderActiveTab();
|
|
487
|
+
this.redrawCanvas();
|
|
488
|
+
};
|
|
489
|
+
this.updatePathDropdown();
|
|
490
|
+
headerLeft.append(headerTitle, this.pathSelect);
|
|
491
|
+
const headerActions = document.createElement('div');
|
|
492
|
+
headerActions.className = 'pes-header-actions';
|
|
493
|
+
const newBtn = document.createElement('button');
|
|
494
|
+
newBtn.className = 'pes-btn small primary';
|
|
495
|
+
newBtn.innerHTML = '➕ New';
|
|
496
|
+
newBtn.title = 'Add new path extrusion';
|
|
497
|
+
newBtn.onclick = () => {
|
|
498
|
+
this.controller.addNewPath();
|
|
499
|
+
this.detectCurrentPreset();
|
|
500
|
+
this.refresh();
|
|
501
|
+
};
|
|
502
|
+
const dupBtn = document.createElement('button');
|
|
503
|
+
dupBtn.className = 'pes-btn small';
|
|
504
|
+
dupBtn.innerHTML = '📑 Clone';
|
|
505
|
+
dupBtn.title = 'Clone active path extrusion';
|
|
506
|
+
dupBtn.onclick = () => {
|
|
507
|
+
this.controller.duplicateActivePathway();
|
|
508
|
+
this.refresh();
|
|
509
|
+
};
|
|
510
|
+
const delBtn = document.createElement('button');
|
|
511
|
+
delBtn.className = 'pes-btn small danger';
|
|
512
|
+
delBtn.innerHTML = '🗑️';
|
|
513
|
+
delBtn.title = 'Delete active path extrusion';
|
|
514
|
+
delBtn.onclick = () => {
|
|
515
|
+
if (confirm('Delete this path extrusion?')) {
|
|
516
|
+
this.controller.deleteActivePathway();
|
|
517
|
+
this.refresh();
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const closeBtn = document.createElement('button');
|
|
521
|
+
closeBtn.className = 'pes-close-btn';
|
|
522
|
+
closeBtn.innerHTML = '✕';
|
|
523
|
+
closeBtn.title = 'Close Studio';
|
|
524
|
+
closeBtn.onclick = () => this.close();
|
|
525
|
+
headerActions.append(newBtn, dupBtn, delBtn, closeBtn);
|
|
526
|
+
header.append(headerLeft, headerActions);
|
|
527
|
+
this.dialog.appendChild(header);
|
|
528
|
+
this.setupDraggableHeader(header);
|
|
529
|
+
// 2. Tabs
|
|
530
|
+
const tabsBar = document.createElement('div');
|
|
531
|
+
tabsBar.className = 'pes-tabs';
|
|
532
|
+
const createTabBtn = (id, label) => {
|
|
533
|
+
const btn = document.createElement('button');
|
|
534
|
+
btn.className = `pes-tab ${this.activeTab === id ? 'active' : ''}`;
|
|
535
|
+
btn.innerHTML = label;
|
|
536
|
+
btn.onclick = () => {
|
|
537
|
+
this.activeTab = id;
|
|
538
|
+
this.tabButtons.forEach((b, k) => b.classList.toggle('active', k === id));
|
|
539
|
+
this.tabContents.forEach((c, k) => (c.style.display = k === id ? 'flex' : 'none'));
|
|
540
|
+
if (id === 'shape') {
|
|
541
|
+
this.fitCanvasView();
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
this.tabButtons.set(id, btn);
|
|
545
|
+
tabsBar.appendChild(btn);
|
|
546
|
+
};
|
|
547
|
+
createTabBtn('shape', '🎨 2D Shape');
|
|
548
|
+
createTabBtn('mesh', '🧱 Extrusion Mesh & Materials');
|
|
549
|
+
createTabBtn('curve', '🛤️ Path Trajectory');
|
|
550
|
+
this.dialog.appendChild(tabsBar);
|
|
551
|
+
// 3. Body & Tab Contents
|
|
552
|
+
const body = document.createElement('div');
|
|
553
|
+
body.className = 'pes-body';
|
|
554
|
+
const shapeContent = document.createElement('div');
|
|
555
|
+
shapeContent.style.display = this.activeTab === 'shape' ? 'flex' : 'none';
|
|
556
|
+
shapeContent.style.flexDirection = 'column';
|
|
557
|
+
shapeContent.style.gap = '14px';
|
|
558
|
+
this.tabContents.set('shape', shapeContent);
|
|
559
|
+
body.appendChild(shapeContent);
|
|
560
|
+
const meshContent = document.createElement('div');
|
|
561
|
+
meshContent.style.display = this.activeTab === 'mesh' ? 'flex' : 'none';
|
|
562
|
+
meshContent.style.flexDirection = 'column';
|
|
563
|
+
meshContent.style.gap = '14px';
|
|
564
|
+
this.tabContents.set('mesh', meshContent);
|
|
565
|
+
body.appendChild(meshContent);
|
|
566
|
+
const curveContent = document.createElement('div');
|
|
567
|
+
curveContent.style.display = this.activeTab === 'curve' ? 'flex' : 'none';
|
|
568
|
+
curveContent.style.flexDirection = 'column';
|
|
569
|
+
curveContent.style.gap = '14px';
|
|
570
|
+
this.tabContents.set('curve', curveContent);
|
|
571
|
+
body.appendChild(curveContent);
|
|
572
|
+
this.dialog.appendChild(body);
|
|
573
|
+
// 4. Footer
|
|
574
|
+
const footer = document.createElement('div');
|
|
575
|
+
footer.className = 'pes-footer';
|
|
576
|
+
const leftFoot = document.createElement('div');
|
|
577
|
+
leftFoot.style.display = 'flex';
|
|
578
|
+
leftFoot.style.gap = '8px';
|
|
579
|
+
const rebuildBtn = document.createElement('button');
|
|
580
|
+
rebuildBtn.className = 'pes-btn accent';
|
|
581
|
+
rebuildBtn.innerHTML = '🔄 Rebuild Active Extrusion';
|
|
582
|
+
rebuildBtn.onclick = () => this.controller.rebuildActivePathway();
|
|
583
|
+
const rebuildAllBtn = document.createElement('button');
|
|
584
|
+
rebuildAllBtn.className = 'pes-btn';
|
|
585
|
+
rebuildAllBtn.innerHTML = '🔄 Rebuild All';
|
|
586
|
+
rebuildAllBtn.onclick = () => this.controller.rebuildAll();
|
|
587
|
+
leftFoot.append(rebuildBtn, rebuildAllBtn);
|
|
588
|
+
const rightFoot = document.createElement('div');
|
|
589
|
+
rightFoot.style.display = 'flex';
|
|
590
|
+
rightFoot.style.gap = '8px';
|
|
591
|
+
const bakeBtn = document.createElement('button');
|
|
592
|
+
bakeBtn.className = 'pes-btn success';
|
|
593
|
+
bakeBtn.innerHTML = '📦 Bake Mesh';
|
|
594
|
+
bakeBtn.title = 'Bake extrusion into a permanent 3D mesh in the scene';
|
|
595
|
+
bakeBtn.onclick = () => {
|
|
596
|
+
const mesh = this.controller.bakeMesh();
|
|
597
|
+
if (mesh) {
|
|
598
|
+
bakeBtn.innerHTML = 'Baked ✓';
|
|
599
|
+
setTimeout(() => (bakeBtn.innerHTML = '📦 Bake Mesh'), 2000);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const doneBtn = document.createElement('button');
|
|
603
|
+
doneBtn.className = 'pes-btn';
|
|
604
|
+
doneBtn.innerHTML = 'Done';
|
|
605
|
+
doneBtn.onclick = () => this.close();
|
|
606
|
+
rightFoot.append(bakeBtn, doneBtn);
|
|
607
|
+
footer.append(leftFoot, rightFoot);
|
|
608
|
+
this.dialog.appendChild(footer);
|
|
609
|
+
this.overlay.appendChild(this.dialog);
|
|
610
|
+
document.body.appendChild(this.overlay);
|
|
611
|
+
}
|
|
612
|
+
setupDraggableHeader(header) {
|
|
613
|
+
header.addEventListener('mousedown', (e) => {
|
|
614
|
+
if (e.target.tagName === 'BUTTON' || e.target.tagName === 'SELECT')
|
|
615
|
+
return;
|
|
616
|
+
this.isDragging = true;
|
|
617
|
+
this.dragStartX = e.clientX;
|
|
618
|
+
this.dragStartY = e.clientY;
|
|
619
|
+
const rect = this.dialog.getBoundingClientRect();
|
|
620
|
+
this.dialogStartX = rect.left;
|
|
621
|
+
this.dialogStartY = rect.top;
|
|
622
|
+
e.preventDefault();
|
|
623
|
+
});
|
|
624
|
+
window.addEventListener('mousemove', (e) => {
|
|
625
|
+
if (!this.isDragging)
|
|
626
|
+
return;
|
|
627
|
+
const dx = e.clientX - this.dragStartX;
|
|
628
|
+
const dy = e.clientY - this.dragStartY;
|
|
629
|
+
this.dialog.style.left = `${this.dialogStartX + dx}px`;
|
|
630
|
+
this.dialog.style.top = `${this.dialogStartY + dy}px`;
|
|
631
|
+
this.dialog.style.transform = 'none';
|
|
632
|
+
this.dialog.style.margin = '0';
|
|
633
|
+
});
|
|
634
|
+
window.addEventListener('mouseup', () => {
|
|
635
|
+
this.isDragging = false;
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
updatePathDropdown() {
|
|
639
|
+
if (!this.pathSelect)
|
|
640
|
+
return;
|
|
641
|
+
this.pathSelect.innerHTML = '';
|
|
642
|
+
const paths = this.controller.paths || [];
|
|
643
|
+
if (paths.length === 0) {
|
|
644
|
+
const opt = document.createElement('option');
|
|
645
|
+
opt.text = 'No path extrusions defined';
|
|
646
|
+
opt.value = '-1';
|
|
647
|
+
this.pathSelect.appendChild(opt);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
paths.forEach((p, idx) => {
|
|
651
|
+
const opt = document.createElement('option');
|
|
652
|
+
opt.value = p.id;
|
|
653
|
+
const shapeType = p.shape ? `${p.shape.length}p shape` : p.shapeConfig.shapeType;
|
|
654
|
+
opt.text = `${p.name || `Path Extrusion #${idx + 1}`} (${shapeType}, ${p.points.length} pts)`;
|
|
655
|
+
if (p.id === this.controller.activePathId)
|
|
656
|
+
opt.selected = true;
|
|
657
|
+
this.pathSelect.appendChild(opt);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
renderActiveTab() {
|
|
661
|
+
const p = this.getActivePath();
|
|
662
|
+
if (!p) {
|
|
663
|
+
this.tabContents.forEach((c) => {
|
|
664
|
+
c.innerHTML = `<div style="text-align:center; padding: 40px; color: #94a3b8;">
|
|
665
|
+
No path extrusions exist yet.<br><br>
|
|
666
|
+
<button class="pes-btn primary" id="pesCreateFirstBtn">➕ Create First Path Extrusion</button>
|
|
667
|
+
</div>`;
|
|
668
|
+
const btn = c.querySelector('#pesCreateFirstBtn');
|
|
669
|
+
if (btn)
|
|
670
|
+
btn.onclick = () => {
|
|
671
|
+
this.controller.addNewPath();
|
|
672
|
+
this.refresh();
|
|
673
|
+
};
|
|
674
|
+
});
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
this.renderShapeTab(p);
|
|
678
|
+
this.renderMeshTab(p);
|
|
679
|
+
this.renderCurveTab(p);
|
|
680
|
+
}
|
|
681
|
+
// ─── TAB 1: 2D Shape & Canvas ───────────────────────────────────────
|
|
682
|
+
renderShapeTab(p) {
|
|
683
|
+
const container = this.tabContents.get('shape');
|
|
684
|
+
if (!container)
|
|
685
|
+
return;
|
|
686
|
+
container.innerHTML = '';
|
|
687
|
+
// Section 1: Presets Toolbar
|
|
688
|
+
const presetSection = document.createElement('div');
|
|
689
|
+
presetSection.className = 'pes-section';
|
|
690
|
+
const pHeader = document.createElement('div');
|
|
691
|
+
pHeader.className = 'pes-section-title';
|
|
692
|
+
pHeader.innerHTML = '<span>📐 2D Shape Presets (PathFactory)</span>';
|
|
693
|
+
presetSection.appendChild(pHeader);
|
|
694
|
+
const presetRow = document.createElement('div');
|
|
695
|
+
presetRow.className = 'pes-row';
|
|
696
|
+
const presetLabel = document.createElement('label');
|
|
697
|
+
presetLabel.textContent = 'Shape Generator:';
|
|
698
|
+
const presetContent = document.createElement('div');
|
|
699
|
+
presetContent.className = 'pes-row-content';
|
|
700
|
+
const presetDropdown = document.createElement('select');
|
|
701
|
+
presetDropdown.className = 'pes-select';
|
|
702
|
+
presetDropdown.style.flex = '1';
|
|
703
|
+
const PRESETS = [
|
|
704
|
+
{ id: 'custom', label: '✏️ Custom Shape (Drawn on Canvas)' },
|
|
705
|
+
{ id: 'pipe', label: '⭕ Round Pipe (PathFactory.shapePipe)' },
|
|
706
|
+
{ id: 'flatPipe', label: '💊 Flat Pipe (PathFactory.shapeFlatPipe)' },
|
|
707
|
+
{ id: 'circle', label: '⚪ Circle Disc (PathFactory.shapeCircle)' },
|
|
708
|
+
{ id: 'rectangle', label: '⬛ Rectangle / Box (PathFactory.shapeRectangle)' },
|
|
709
|
+
{ id: 'uProfile', label: '🕳️ U-Profile / Gutter (PathFactory.shapeUProfile)' },
|
|
710
|
+
{ id: 'halfpipe', label: '🛹 Halfpipe (PathFactory.shapeHalfpipe)' },
|
|
711
|
+
{ id: 'triangle', label: '▲ Triangle (PathFactory.shapeTriangle)' },
|
|
712
|
+
{ id: 'ellipse', label: '⬭ Ellipse (PathFactory.shapeEllipse)' },
|
|
713
|
+
{ id: 'star', label: '⭐ Star (PathFactory.shapeStar)' },
|
|
714
|
+
{ id: 'horizontalLine', label: '━ Horizontal Track (PathFactory.shapeHorizontalLine)' },
|
|
715
|
+
{ id: 'verticalLine', label: '┃ Vertical Wall (PathFactory.shapeVerticalLine)' },
|
|
716
|
+
{ id: 'halfCircle', label: '◖ Half Circle (PathFactory.shapeHalfCircle)' },
|
|
717
|
+
];
|
|
718
|
+
PRESETS.forEach((item) => {
|
|
719
|
+
const opt = document.createElement('option');
|
|
720
|
+
opt.value = item.id;
|
|
721
|
+
opt.text = item.label;
|
|
722
|
+
if (item.id === this.currentPreset)
|
|
723
|
+
opt.selected = true;
|
|
724
|
+
presetDropdown.appendChild(opt);
|
|
725
|
+
});
|
|
726
|
+
presetContent.appendChild(presetDropdown);
|
|
727
|
+
presetRow.append(presetLabel, presetContent);
|
|
728
|
+
presetSection.appendChild(presetRow);
|
|
729
|
+
// Preset Dynamic Parameters Container
|
|
730
|
+
const paramsContainer = document.createElement('div');
|
|
731
|
+
paramsContainer.style.display = 'flex';
|
|
732
|
+
paramsContainer.style.flexDirection = 'column';
|
|
733
|
+
paramsContainer.style.gap = '8px';
|
|
734
|
+
presetSection.appendChild(paramsContainer);
|
|
735
|
+
const updatePresetParamsUI = () => {
|
|
736
|
+
paramsContainer.innerHTML = '';
|
|
737
|
+
if (this.currentPreset === 'custom')
|
|
738
|
+
return;
|
|
739
|
+
const addSlider = (label, min, max, step, value, onChange) => {
|
|
740
|
+
const row = document.createElement('div');
|
|
741
|
+
row.className = 'pes-row';
|
|
742
|
+
const lbl = document.createElement('label');
|
|
743
|
+
lbl.textContent = label;
|
|
744
|
+
const cnt = document.createElement('div');
|
|
745
|
+
cnt.className = 'pes-row-content';
|
|
746
|
+
const slider = document.createElement('input');
|
|
747
|
+
slider.type = 'range';
|
|
748
|
+
slider.className = 'pes-slider';
|
|
749
|
+
slider.min = min.toString();
|
|
750
|
+
slider.max = max.toString();
|
|
751
|
+
slider.step = step.toString();
|
|
752
|
+
slider.value = value.toString();
|
|
753
|
+
const num = document.createElement('input');
|
|
754
|
+
num.type = 'number';
|
|
755
|
+
num.className = 'pes-input';
|
|
756
|
+
num.min = min.toString();
|
|
757
|
+
num.max = max.toString();
|
|
758
|
+
num.step = step.toString();
|
|
759
|
+
num.value = value.toString();
|
|
760
|
+
const sync = (v) => {
|
|
761
|
+
slider.value = v.toString();
|
|
762
|
+
num.value = v.toString();
|
|
763
|
+
onChange(v);
|
|
764
|
+
this.applyPresetToActivePath();
|
|
765
|
+
};
|
|
766
|
+
slider.oninput = () => sync(parseFloat(slider.value));
|
|
767
|
+
num.onchange = () => sync(parseFloat(num.value));
|
|
768
|
+
cnt.append(slider, num);
|
|
769
|
+
row.append(lbl, cnt);
|
|
770
|
+
paramsContainer.appendChild(row);
|
|
771
|
+
};
|
|
772
|
+
if (this.currentPreset === 'pipe') {
|
|
773
|
+
addSlider('Segments:', 4, 32, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
774
|
+
addSlider('Radius:', 0.2, 8, 0.1, this.presetRadius, (v) => (this.presetRadius = v));
|
|
775
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
776
|
+
addSlider('Exclude Bottom Pts:', 0, 16, 1, this.presetExcludeBottom, (v) => (this.presetExcludeBottom = v));
|
|
777
|
+
}
|
|
778
|
+
else if (this.currentPreset === 'flatPipe') {
|
|
779
|
+
addSlider('Segments:', 4, 32, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
780
|
+
addSlider('Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
781
|
+
addSlider('Height:', 0.1, 5, 0.05, this.presetHeight, (v) => (this.presetHeight = v));
|
|
782
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
783
|
+
}
|
|
784
|
+
else if (this.currentPreset === 'circle') {
|
|
785
|
+
addSlider('Segments:', 4, 32, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
786
|
+
addSlider('Radius:', 0.2, 8, 0.1, this.presetRadius, (v) => (this.presetRadius = v));
|
|
787
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
788
|
+
}
|
|
789
|
+
else if (this.currentPreset === 'rectangle') {
|
|
790
|
+
addSlider('Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
791
|
+
addSlider('Height:', 0.1, 5, 0.05, this.presetHeight, (v) => (this.presetHeight = v));
|
|
792
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
793
|
+
}
|
|
794
|
+
else if (this.currentPreset === 'uProfile') {
|
|
795
|
+
addSlider('Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
796
|
+
addSlider('Wall Height:', 0.1, 5, 0.05, this.presetHeight, (v) => (this.presetHeight = v));
|
|
797
|
+
addSlider('Thickness:', 0.05, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
798
|
+
}
|
|
799
|
+
else if (this.currentPreset === 'halfpipe') {
|
|
800
|
+
addSlider('Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
801
|
+
addSlider('Height:', 0.1, 5, 0.05, this.presetHeight, (v) => (this.presetHeight = v));
|
|
802
|
+
addSlider('Depth:', 0.1, 5, 0.05, this.presetDepth, (v) => (this.presetDepth = v));
|
|
803
|
+
addSlider('Thickness:', 0.05, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
804
|
+
}
|
|
805
|
+
else if (this.currentPreset === 'triangle') {
|
|
806
|
+
addSlider('Base Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
807
|
+
addSlider('Height:', 0.2, 8, 0.1, this.presetHeight, (v) => (this.presetHeight = v));
|
|
808
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
809
|
+
}
|
|
810
|
+
else if (this.currentPreset === 'ellipse') {
|
|
811
|
+
addSlider('Segments:', 4, 32, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
812
|
+
addSlider('Width:', 0.5, 10, 0.1, this.presetWidth, (v) => (this.presetWidth = v));
|
|
813
|
+
addSlider('Height:', 0.1, 5, 0.05, this.presetHeight, (v) => (this.presetHeight = v));
|
|
814
|
+
addSlider('Thickness:', 0, 2, 0.05, this.presetThickness, (v) => (this.presetThickness = v));
|
|
815
|
+
}
|
|
816
|
+
else if (this.currentPreset === 'star') {
|
|
817
|
+
addSlider('Star Points:', 3, 12, 1, this.presetStarPoints, (v) => (this.presetStarPoints = v));
|
|
818
|
+
addSlider('Outer Radius:', 0.5, 8, 0.1, this.presetOuterRadius, (v) => (this.presetOuterRadius = v));
|
|
819
|
+
addSlider('Inner Radius:', 0.2, 5, 0.1, this.presetInnerRadius, (v) => (this.presetInnerRadius = v));
|
|
820
|
+
}
|
|
821
|
+
else if (this.currentPreset === 'horizontalLine') {
|
|
822
|
+
addSlider('Width:', 0.5, 15, 0.2, this.presetWidth, (v) => (this.presetWidth = v));
|
|
823
|
+
addSlider('Segments:', 2, 16, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
824
|
+
}
|
|
825
|
+
else if (this.currentPreset === 'verticalLine') {
|
|
826
|
+
addSlider('Height:', 0.5, 15, 0.2, this.presetHeight, (v) => (this.presetHeight = v));
|
|
827
|
+
addSlider('Segments:', 2, 16, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
828
|
+
}
|
|
829
|
+
else if (this.currentPreset === 'halfCircle') {
|
|
830
|
+
addSlider('Segments:', 4, 32, 1, this.presetSegments, (v) => (this.presetSegments = v));
|
|
831
|
+
addSlider('Radius:', 0.2, 8, 0.1, this.presetRadius, (v) => (this.presetRadius = v));
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
presetDropdown.onchange = () => {
|
|
835
|
+
this.currentPreset = presetDropdown.value;
|
|
836
|
+
updatePresetParamsUI();
|
|
837
|
+
if (this.currentPreset !== 'custom') {
|
|
838
|
+
this.applyPresetToActivePath();
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
updatePresetParamsUI();
|
|
842
|
+
container.appendChild(presetSection);
|
|
843
|
+
// Section 2: Interactive 2D Canvas Editor
|
|
844
|
+
const canvasSection = document.createElement('div');
|
|
845
|
+
canvasSection.className = 'pes-section';
|
|
846
|
+
const cHeader = document.createElement('div');
|
|
847
|
+
cHeader.className = 'pes-section-title';
|
|
848
|
+
cHeader.innerHTML = `
|
|
849
|
+
<span>🎨 Interactive 2D Cross-Section Canvas</span>
|
|
850
|
+
<div style="display:flex; gap:12px; align-items:center;">
|
|
851
|
+
<span id="pesCanvasZoom" style="color:#38bdf8; font-size:11px; font-weight:600;">Scale: 45 px/m</span>
|
|
852
|
+
<span id="pesMouseCoord" style="color:#94a3b8; font-size:11px;">X: 0.00m, Y: 0.00m</span>
|
|
853
|
+
</div>
|
|
854
|
+
`;
|
|
855
|
+
canvasSection.appendChild(cHeader);
|
|
856
|
+
const canvasContainer = document.createElement('div');
|
|
857
|
+
canvasContainer.className = 'pes-canvas-container';
|
|
858
|
+
this.canvas = document.createElement('canvas');
|
|
859
|
+
this.canvas.className = 'pes-canvas';
|
|
860
|
+
this.canvas.width = this.canvasWidth;
|
|
861
|
+
this.canvas.height = this.canvasHeight;
|
|
862
|
+
this.ctx = this.canvas.getContext('2d');
|
|
863
|
+
this.setupCanvasInteractions();
|
|
864
|
+
canvasContainer.appendChild(this.canvas);
|
|
865
|
+
// Canvas Toolbar
|
|
866
|
+
const toolbar = document.createElement('div');
|
|
867
|
+
toolbar.className = 'pes-canvas-toolbar';
|
|
868
|
+
const fitBtn = document.createElement('button');
|
|
869
|
+
fitBtn.className = 'pes-btn small accent';
|
|
870
|
+
fitBtn.innerHTML = '🎯 Fit View';
|
|
871
|
+
fitBtn.title = 'Automatically frame all shape points within the canvas';
|
|
872
|
+
fitBtn.onclick = () => this.fitCanvasView();
|
|
873
|
+
const zoomInBtn = document.createElement('button');
|
|
874
|
+
zoomInBtn.className = 'pes-btn small';
|
|
875
|
+
zoomInBtn.innerHTML = '➕ Zoom In';
|
|
876
|
+
zoomInBtn.onclick = () => {
|
|
877
|
+
this.scale = Math.min(400, this.scale * 1.25);
|
|
878
|
+
this.redrawCanvas();
|
|
879
|
+
};
|
|
880
|
+
const zoomOutBtn = document.createElement('button');
|
|
881
|
+
zoomOutBtn.className = 'pes-btn small';
|
|
882
|
+
zoomOutBtn.innerHTML = '➖ Zoom Out';
|
|
883
|
+
zoomOutBtn.onclick = () => {
|
|
884
|
+
this.scale = Math.max(2, this.scale * 0.8);
|
|
885
|
+
this.redrawCanvas();
|
|
886
|
+
};
|
|
887
|
+
const resetPanBtn = document.createElement('button');
|
|
888
|
+
resetPanBtn.className = 'pes-btn small';
|
|
889
|
+
resetPanBtn.innerHTML = '↺ Center View';
|
|
890
|
+
resetPanBtn.title = 'Reset pan and scale to default center';
|
|
891
|
+
resetPanBtn.onclick = () => {
|
|
892
|
+
this.panX = 0;
|
|
893
|
+
this.panY = 0;
|
|
894
|
+
this.scale = 45;
|
|
895
|
+
this.redrawCanvas();
|
|
896
|
+
};
|
|
897
|
+
const shape = p.shape;
|
|
898
|
+
const isClosed = shape?.closedShape ?? p.shapeConfig.closedShape ?? true;
|
|
899
|
+
const closedBtn = document.createElement('button');
|
|
900
|
+
closedBtn.className = `pes-btn small ${isClosed ? 'accent' : ''}`;
|
|
901
|
+
closedBtn.innerHTML = `🔲 Closed: ${isClosed ? 'Yes' : 'No'}`;
|
|
902
|
+
closedBtn.onclick = () => {
|
|
903
|
+
if (p.shape) {
|
|
904
|
+
p.shape.closedShape = !isClosed;
|
|
905
|
+
p.shapeConfig.closedShape = !isClosed;
|
|
906
|
+
this.currentPreset = 'custom';
|
|
907
|
+
this.renderActiveTab();
|
|
908
|
+
this.triggerWYSIWYGUpdate();
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const flipHBtn = document.createElement('button');
|
|
912
|
+
flipHBtn.className = 'pes-btn small';
|
|
913
|
+
flipHBtn.innerHTML = '↔️ Flip H';
|
|
914
|
+
flipHBtn.onclick = () => {
|
|
915
|
+
if (p.shape) {
|
|
916
|
+
p.shape.forEach((pt) => (pt.x = -pt.x));
|
|
917
|
+
this.currentPreset = 'custom';
|
|
918
|
+
this.renderActiveTab();
|
|
919
|
+
this.triggerWYSIWYGUpdate();
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
const flipVBtn = document.createElement('button');
|
|
923
|
+
flipVBtn.className = 'pes-btn small';
|
|
924
|
+
flipVBtn.innerHTML = '↕️ Flip V';
|
|
925
|
+
flipVBtn.onclick = () => {
|
|
926
|
+
if (p.shape) {
|
|
927
|
+
p.shape.forEach((pt) => (pt.y = -pt.y));
|
|
928
|
+
this.currentPreset = 'custom';
|
|
929
|
+
this.renderActiveTab();
|
|
930
|
+
this.triggerWYSIWYGUpdate();
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const centerBtn = document.createElement('button');
|
|
934
|
+
centerBtn.className = 'pes-btn small';
|
|
935
|
+
centerBtn.innerHTML = '🎯 Center Shape';
|
|
936
|
+
centerBtn.onclick = () => this.centerShape();
|
|
937
|
+
const snapSelect = document.createElement('select');
|
|
938
|
+
snapSelect.className = 'pes-select small';
|
|
939
|
+
snapSelect.innerHTML = `
|
|
940
|
+
<option value="0.05">Snap: 0.05</option>
|
|
941
|
+
<option value="0.1" selected>Snap: 0.10</option>
|
|
942
|
+
<option value="0.25">Snap: 0.25</option>
|
|
943
|
+
<option value="0">Snap: Off</option>
|
|
944
|
+
`;
|
|
945
|
+
snapSelect.onchange = () => (this.snapGrid = parseFloat(snapSelect.value));
|
|
946
|
+
toolbar.append(fitBtn, zoomInBtn, zoomOutBtn, resetPanBtn, closedBtn, flipHBtn, flipVBtn, centerBtn, snapSelect);
|
|
947
|
+
canvasContainer.appendChild(toolbar);
|
|
948
|
+
const hint = document.createElement('div');
|
|
949
|
+
hint.className = 'pes-canvas-hint';
|
|
950
|
+
hint.innerHTML = '💡 <b>Controls:</b> Drag vertices • Click edge to add point • Right-click vertex to delete • Drag background to pan • Wheel to zoom';
|
|
951
|
+
canvasContainer.appendChild(hint);
|
|
952
|
+
canvasSection.appendChild(canvasContainer);
|
|
953
|
+
// Section 3: Vertex Coordinates Table
|
|
954
|
+
const tableSection = document.createElement('div');
|
|
955
|
+
tableSection.className = 'pes-section';
|
|
956
|
+
const tHeader = document.createElement('div');
|
|
957
|
+
tHeader.className = 'pes-section-title';
|
|
958
|
+
const numPoints = p.shape ? p.shape.length : 0;
|
|
959
|
+
const solidHalf = p.shape?.solidHalfCount || p.shapeConfig.solidHalfCount || 0;
|
|
960
|
+
tHeader.innerHTML = `<span>📋 Shape Vertices (${numPoints} points, solidHalf: ${solidHalf})</span>`;
|
|
961
|
+
tableSection.appendChild(tHeader);
|
|
962
|
+
const tableWrap = document.createElement('div');
|
|
963
|
+
tableWrap.className = 'pes-table-container';
|
|
964
|
+
const table = document.createElement('table');
|
|
965
|
+
table.className = 'pes-table';
|
|
966
|
+
table.innerHTML = `
|
|
967
|
+
<thead>
|
|
968
|
+
<tr>
|
|
969
|
+
<th>#</th>
|
|
970
|
+
<th>X (Right)</th>
|
|
971
|
+
<th>Y (Up)</th>
|
|
972
|
+
<th>Ring</th>
|
|
973
|
+
<th style="width:40px;"></th>
|
|
974
|
+
</tr>
|
|
975
|
+
</thead>
|
|
976
|
+
<tbody></tbody>
|
|
977
|
+
`;
|
|
978
|
+
const tbody = table.querySelector('tbody');
|
|
979
|
+
if (p.shape) {
|
|
980
|
+
p.shape.forEach((pt, i) => {
|
|
981
|
+
const tr = document.createElement('tr');
|
|
982
|
+
const isInner = solidHalf > 0 && i >= solidHalf;
|
|
983
|
+
tr.innerHTML = `
|
|
984
|
+
<td style="color:${isInner ? '#fb923c' : '#38bdf8'}; font-weight:600;">${i}</td>
|
|
985
|
+
<td><input type="number" step="0.05" class="pes-input" style="width:70px; padding:2px 4px;" value="${pt.x.toFixed(2)}" data-idx="${i}" data-coord="x"></td>
|
|
986
|
+
<td><input type="number" step="0.05" class="pes-input" style="width:70px; padding:2px 4px;" value="${pt.y.toFixed(2)}" data-idx="${i}" data-coord="y"></td>
|
|
987
|
+
<td style="font-size:10px; color:${isInner ? '#fb923c' : '#94a3b8'};">${isInner ? 'Inner Ring' : 'Outer Loop'}</td>
|
|
988
|
+
<td><button class="pes-btn small danger" style="padding:1px 5px;" data-del="${i}">✕</button></td>
|
|
989
|
+
`;
|
|
990
|
+
tr.querySelectorAll('input').forEach((inp) => {
|
|
991
|
+
inp.onchange = (e) => {
|
|
992
|
+
const target = e.target;
|
|
993
|
+
const idx = parseInt(target.dataset.idx, 10);
|
|
994
|
+
const coord = target.dataset.coord;
|
|
995
|
+
p.shape[idx][coord] = parseFloat(target.value) || 0;
|
|
996
|
+
this.currentPreset = 'custom';
|
|
997
|
+
this.redrawCanvas();
|
|
998
|
+
this.triggerWYSIWYGUpdate();
|
|
999
|
+
};
|
|
1000
|
+
});
|
|
1001
|
+
tr.querySelector('button')?.addEventListener('click', () => {
|
|
1002
|
+
if (p.shape && p.shape.length > 3) {
|
|
1003
|
+
p.shape.splice(i, 1);
|
|
1004
|
+
this.currentPreset = 'custom';
|
|
1005
|
+
this.renderActiveTab();
|
|
1006
|
+
this.redrawCanvas();
|
|
1007
|
+
this.triggerWYSIWYGUpdate();
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
tbody.appendChild(tr);
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
tableWrap.appendChild(table);
|
|
1014
|
+
tableSection.appendChild(tableWrap);
|
|
1015
|
+
container.append(presetSection, canvasSection, tableSection);
|
|
1016
|
+
}
|
|
1017
|
+
detectCurrentPreset() {
|
|
1018
|
+
const p = this.getActivePath();
|
|
1019
|
+
if (!p) {
|
|
1020
|
+
this.currentPreset = 'pipe';
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
this.currentPreset = p.shapeConfig.shapeType || 'custom';
|
|
1024
|
+
}
|
|
1025
|
+
applyPresetToActivePath() {
|
|
1026
|
+
const p = this.getActivePath();
|
|
1027
|
+
if (!p)
|
|
1028
|
+
return;
|
|
1029
|
+
let points = [];
|
|
1030
|
+
switch (this.currentPreset) {
|
|
1031
|
+
case 'pipe':
|
|
1032
|
+
points = PathFactory.shapePipe(this.presetSegments, this.presetRadius, this.presetThickness, this.presetExcludeBottom);
|
|
1033
|
+
break;
|
|
1034
|
+
case 'flatPipe':
|
|
1035
|
+
points = PathFactory.shapeFlatPipe(this.presetSegments, this.presetWidth, this.presetHeight, this.presetThickness);
|
|
1036
|
+
break;
|
|
1037
|
+
case 'circle':
|
|
1038
|
+
points = PathFactory.shapeCircle(this.presetSegments, this.presetRadius, this.presetThickness);
|
|
1039
|
+
break;
|
|
1040
|
+
case 'rectangle':
|
|
1041
|
+
points = PathFactory.shapeRectangle(this.presetWidth, this.presetHeight, this.presetThickness);
|
|
1042
|
+
break;
|
|
1043
|
+
case 'uProfile':
|
|
1044
|
+
points = PathFactory.shapeUProfile(this.presetWidth, this.presetHeight, this.presetThickness);
|
|
1045
|
+
break;
|
|
1046
|
+
case 'halfpipe':
|
|
1047
|
+
points = PathFactory.shapeHalfpipe(this.presetWidth, this.presetHeight, this.presetDepth, this.presetThickness);
|
|
1048
|
+
break;
|
|
1049
|
+
case 'triangle':
|
|
1050
|
+
points = PathFactory.shapeTriangle(this.presetWidth, this.presetHeight, this.presetThickness);
|
|
1051
|
+
break;
|
|
1052
|
+
case 'ellipse':
|
|
1053
|
+
points = PathFactory.shapeEllipse(this.presetSegments, this.presetWidth, this.presetHeight, this.presetThickness);
|
|
1054
|
+
break;
|
|
1055
|
+
case 'star':
|
|
1056
|
+
points = PathFactory.shapeStar(this.presetStarPoints, this.presetOuterRadius, this.presetInnerRadius);
|
|
1057
|
+
break;
|
|
1058
|
+
case 'horizontalLine':
|
|
1059
|
+
points = PathFactory.shapeHorizontalLine(this.presetWidth, this.presetSegments);
|
|
1060
|
+
break;
|
|
1061
|
+
case 'verticalLine':
|
|
1062
|
+
points = PathFactory.shapeVerticalLine(this.presetHeight, this.presetSegments);
|
|
1063
|
+
break;
|
|
1064
|
+
case 'halfCircle':
|
|
1065
|
+
points = PathFactory.shapeHalfCircle(this.presetSegments, this.presetRadius);
|
|
1066
|
+
break;
|
|
1067
|
+
default:
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
p.shape = points;
|
|
1071
|
+
p.shapeConfig.shapeType = this.currentPreset;
|
|
1072
|
+
p.shapeConfig.solidHalfCount = points.solidHalfCount;
|
|
1073
|
+
p.shapeConfig.closedShape = points.closedShape;
|
|
1074
|
+
const dims = this.getShapeDimensions(points);
|
|
1075
|
+
p.shapeConfig.width = parseFloat(dims.width.toFixed(2));
|
|
1076
|
+
p.shapeConfig.height = parseFloat(dims.height.toFixed(2));
|
|
1077
|
+
this.fitCanvasView();
|
|
1078
|
+
this.redrawCanvas();
|
|
1079
|
+
this.triggerWYSIWYGUpdate();
|
|
1080
|
+
}
|
|
1081
|
+
getShapeDimensions(shape) {
|
|
1082
|
+
if (!shape || shape.length === 0)
|
|
1083
|
+
return { width: 4, height: 1 };
|
|
1084
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
1085
|
+
for (const p of shape) {
|
|
1086
|
+
minX = Math.min(minX, p.x);
|
|
1087
|
+
maxX = Math.max(maxX, p.x);
|
|
1088
|
+
minY = Math.min(minY, p.y);
|
|
1089
|
+
maxY = Math.max(maxY, p.y);
|
|
1090
|
+
}
|
|
1091
|
+
return {
|
|
1092
|
+
width: Math.max(0.01, maxX - minX),
|
|
1093
|
+
height: Math.max(0.01, maxY - minY),
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
centerShape() {
|
|
1097
|
+
const p = this.getActivePath();
|
|
1098
|
+
if (!p || !p.shape || p.shape.length === 0)
|
|
1099
|
+
return;
|
|
1100
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
1101
|
+
for (const pt of p.shape) {
|
|
1102
|
+
minX = Math.min(minX, pt.x);
|
|
1103
|
+
maxX = Math.max(maxX, pt.x);
|
|
1104
|
+
minY = Math.min(minY, pt.y);
|
|
1105
|
+
maxY = Math.max(maxY, pt.y);
|
|
1106
|
+
}
|
|
1107
|
+
const midX = (minX + maxX) / 2;
|
|
1108
|
+
const midY = (minY + maxY) / 2;
|
|
1109
|
+
for (const pt of p.shape) {
|
|
1110
|
+
pt.x -= midX;
|
|
1111
|
+
pt.y -= midY;
|
|
1112
|
+
}
|
|
1113
|
+
this.currentPreset = 'custom';
|
|
1114
|
+
this.renderActiveTab();
|
|
1115
|
+
this.redrawCanvas();
|
|
1116
|
+
this.triggerWYSIWYGUpdate();
|
|
1117
|
+
}
|
|
1118
|
+
updateVertexTable(p) {
|
|
1119
|
+
const tableContainer = this.tabContents.get('shape')?.querySelector('.pes-table tbody');
|
|
1120
|
+
if (!tableContainer || !p.shape)
|
|
1121
|
+
return;
|
|
1122
|
+
const inputs = tableContainer.querySelectorAll('input[data-idx]');
|
|
1123
|
+
inputs.forEach((inp) => {
|
|
1124
|
+
const idx = parseInt(inp.dataset.idx, 10);
|
|
1125
|
+
const coord = inp.dataset.coord;
|
|
1126
|
+
if (p.shape && p.shape[idx]) {
|
|
1127
|
+
inp.value = p.shape[idx][coord].toFixed(2);
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
fitCanvasView() {
|
|
1132
|
+
const p = this.getActivePath();
|
|
1133
|
+
if (!p || !p.shape || p.shape.length === 0) {
|
|
1134
|
+
this.scale = 45;
|
|
1135
|
+
this.panX = 0;
|
|
1136
|
+
this.panY = 0;
|
|
1137
|
+
this.redrawCanvas();
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
1141
|
+
for (const pt of p.shape) {
|
|
1142
|
+
minX = Math.min(minX, pt.x);
|
|
1143
|
+
maxX = Math.max(maxX, pt.x);
|
|
1144
|
+
minY = Math.min(minY, pt.y);
|
|
1145
|
+
maxY = Math.max(maxY, pt.y);
|
|
1146
|
+
}
|
|
1147
|
+
const spanX = Math.max(0.4, maxX - minX);
|
|
1148
|
+
const spanY = Math.max(0.4, maxY - minY);
|
|
1149
|
+
const scaleX = (this.canvasWidth * 0.75) / spanX;
|
|
1150
|
+
const scaleY = (this.canvasHeight * 0.75) / spanY;
|
|
1151
|
+
this.scale = Math.max(2, Math.min(300, Math.min(scaleX, scaleY)));
|
|
1152
|
+
const midX = (minX + maxX) / 2;
|
|
1153
|
+
const midY = (minY + maxY) / 2;
|
|
1154
|
+
this.panX = -midX * this.scale;
|
|
1155
|
+
this.panY = midY * this.scale;
|
|
1156
|
+
this.redrawCanvas();
|
|
1157
|
+
}
|
|
1158
|
+
// ─── 2D Canvas Drawing & Interactions ──────────────────────────────────────
|
|
1159
|
+
setupCanvasInteractions() {
|
|
1160
|
+
const canvas = this.canvas;
|
|
1161
|
+
const getCanvasCoords = (e) => {
|
|
1162
|
+
const rect = canvas.getBoundingClientRect();
|
|
1163
|
+
const scaleFactorX = this.canvasWidth / rect.width;
|
|
1164
|
+
const scaleFactorY = this.canvasHeight / rect.height;
|
|
1165
|
+
const cx = (e.clientX - rect.left) * scaleFactorX;
|
|
1166
|
+
const cy = (e.clientY - rect.top) * scaleFactorY;
|
|
1167
|
+
return { cx, cy, scaleFactorX, scaleFactorY };
|
|
1168
|
+
};
|
|
1169
|
+
const toWorld = (cx, cy) => {
|
|
1170
|
+
const originX = this.canvasWidth / 2 + this.panX;
|
|
1171
|
+
const originY = this.canvasHeight / 2 + this.panY;
|
|
1172
|
+
const x = (cx - originX) / this.scale;
|
|
1173
|
+
const y = (originY - cy) / this.scale;
|
|
1174
|
+
return { x, y };
|
|
1175
|
+
};
|
|
1176
|
+
const toCanvas = (wx, wy) => {
|
|
1177
|
+
const originX = this.canvasWidth / 2 + this.panX;
|
|
1178
|
+
const originY = this.canvasHeight / 2 + this.panY;
|
|
1179
|
+
const cx = originX + wx * this.scale;
|
|
1180
|
+
const cy = originY - wy * this.scale;
|
|
1181
|
+
return { cx, cy };
|
|
1182
|
+
};
|
|
1183
|
+
canvas.addEventListener('mousedown', (e) => {
|
|
1184
|
+
const { cx, cy } = getCanvasCoords(e);
|
|
1185
|
+
const p = this.getActivePath();
|
|
1186
|
+
if (!p || !p.shape)
|
|
1187
|
+
return;
|
|
1188
|
+
const shape = p.shape;
|
|
1189
|
+
// 1. Check vertex pick
|
|
1190
|
+
let foundIdx = null;
|
|
1191
|
+
for (let i = 0; i < shape.length; i++) {
|
|
1192
|
+
const { cx: px, cy: py } = toCanvas(shape[i].x, shape[i].y);
|
|
1193
|
+
const dist = Math.hypot(cx - px, cy - py);
|
|
1194
|
+
if (dist <= 9) {
|
|
1195
|
+
foundIdx = i;
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (e.button === 0) {
|
|
1200
|
+
if (foundIdx !== null) {
|
|
1201
|
+
this.isCanvasDragging = true;
|
|
1202
|
+
this.draggedVertexIndex = foundIdx;
|
|
1203
|
+
canvas.style.cursor = 'grabbing';
|
|
1204
|
+
}
|
|
1205
|
+
else if (this.hoveredEdgeIndex !== null) {
|
|
1206
|
+
// Edge pick: insert vertex
|
|
1207
|
+
const world = toWorld(cx, cy);
|
|
1208
|
+
const insertIdx = this.hoveredEdgeIndex + 1;
|
|
1209
|
+
shape.splice(insertIdx, 0, new Vector3(world.x, world.y, 0));
|
|
1210
|
+
this.isCanvasDragging = true;
|
|
1211
|
+
this.draggedVertexIndex = insertIdx;
|
|
1212
|
+
this.currentPreset = 'custom';
|
|
1213
|
+
this.renderActiveTab();
|
|
1214
|
+
this.triggerWYSIWYGUpdate();
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
// Panning
|
|
1218
|
+
this.isPanning = true;
|
|
1219
|
+
this.panStartX = e.clientX;
|
|
1220
|
+
this.panStartY = e.clientY;
|
|
1221
|
+
canvas.style.cursor = 'grabbing';
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
else if (e.button === 1) {
|
|
1225
|
+
this.isPanning = true;
|
|
1226
|
+
this.panStartX = e.clientX;
|
|
1227
|
+
this.panStartY = e.clientY;
|
|
1228
|
+
canvas.style.cursor = 'grabbing';
|
|
1229
|
+
}
|
|
1230
|
+
else if (e.button === 2) {
|
|
1231
|
+
if (foundIdx !== null && shape.length > 3) {
|
|
1232
|
+
shape.splice(foundIdx, 1);
|
|
1233
|
+
this.currentPreset = 'custom';
|
|
1234
|
+
this.renderActiveTab();
|
|
1235
|
+
this.triggerWYSIWYGUpdate();
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
canvas.addEventListener('mousemove', (e) => {
|
|
1240
|
+
const { cx, cy, scaleFactorX, scaleFactorY } = getCanvasCoords(e);
|
|
1241
|
+
const world = toWorld(cx, cy);
|
|
1242
|
+
this.mouseWorldCoord = world;
|
|
1243
|
+
const coordEl = document.getElementById('pesMouseCoord');
|
|
1244
|
+
if (coordEl)
|
|
1245
|
+
coordEl.textContent = `X: ${world.x.toFixed(2)}m, Y: ${world.y.toFixed(2)}m`;
|
|
1246
|
+
if (this.isPanning) {
|
|
1247
|
+
const dx = (e.clientX - this.panStartX) * scaleFactorX;
|
|
1248
|
+
const dy = (e.clientY - this.panStartY) * scaleFactorY;
|
|
1249
|
+
this.panStartX = e.clientX;
|
|
1250
|
+
this.panStartY = e.clientY;
|
|
1251
|
+
this.panX += dx;
|
|
1252
|
+
this.panY += dy;
|
|
1253
|
+
this.redrawCanvas();
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
const p = this.getActivePath();
|
|
1257
|
+
if (!p || !p.shape)
|
|
1258
|
+
return;
|
|
1259
|
+
const shape = p.shape;
|
|
1260
|
+
if (this.isCanvasDragging && this.draggedVertexIndex !== null) {
|
|
1261
|
+
let finalX = world.x;
|
|
1262
|
+
let finalY = world.y;
|
|
1263
|
+
if (this.snapGrid > 0) {
|
|
1264
|
+
finalX = Math.round(finalX / this.snapGrid) * this.snapGrid;
|
|
1265
|
+
finalY = Math.round(finalY / this.snapGrid) * this.snapGrid;
|
|
1266
|
+
}
|
|
1267
|
+
shape[this.draggedVertexIndex].x = finalX;
|
|
1268
|
+
shape[this.draggedVertexIndex].y = finalY;
|
|
1269
|
+
this.currentPreset = 'custom';
|
|
1270
|
+
this.redrawCanvas();
|
|
1271
|
+
this.triggerWYSIWYGUpdate();
|
|
1272
|
+
}
|
|
1273
|
+
else {
|
|
1274
|
+
// Vertex hover
|
|
1275
|
+
this.hoveredVertexIndex = null;
|
|
1276
|
+
for (let i = 0; i < shape.length; i++) {
|
|
1277
|
+
const { cx: px, cy: py } = toCanvas(shape[i].x, shape[i].y);
|
|
1278
|
+
if (Math.hypot(cx - px, cy - py) <= 9) {
|
|
1279
|
+
this.hoveredVertexIndex = i;
|
|
1280
|
+
break;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
// Edge hover
|
|
1284
|
+
this.hoveredEdgeIndex = null;
|
|
1285
|
+
if (this.hoveredVertexIndex === null && shape.length >= 2) {
|
|
1286
|
+
for (let i = 0; i < shape.length; i++) {
|
|
1287
|
+
const nextI = (i + 1) % shape.length;
|
|
1288
|
+
const p1 = toCanvas(shape[i].x, shape[i].y);
|
|
1289
|
+
const p2 = toCanvas(shape[nextI].x, shape[nextI].y);
|
|
1290
|
+
const dist = this.distToSegment({ x: cx, y: cy }, { x: p1.cx, y: p1.cy }, { x: p2.cx, y: p2.cy });
|
|
1291
|
+
if (dist <= 6) {
|
|
1292
|
+
this.hoveredEdgeIndex = i;
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
canvas.style.cursor =
|
|
1298
|
+
this.hoveredVertexIndex !== null ? 'pointer' : this.hoveredEdgeIndex !== null ? 'cell' : 'grab';
|
|
1299
|
+
this.redrawCanvas();
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
const handleMouseUp = () => {
|
|
1303
|
+
const p = this.getActivePath();
|
|
1304
|
+
if (this.isCanvasDragging) {
|
|
1305
|
+
this.isCanvasDragging = false;
|
|
1306
|
+
this.draggedVertexIndex = null;
|
|
1307
|
+
if (p)
|
|
1308
|
+
this.updateVertexTable(p);
|
|
1309
|
+
}
|
|
1310
|
+
if (this.isPanning) {
|
|
1311
|
+
this.isPanning = false;
|
|
1312
|
+
canvas.style.cursor = 'grab';
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
canvas.addEventListener('mouseup', handleMouseUp);
|
|
1316
|
+
canvas.addEventListener('mouseleave', handleMouseUp);
|
|
1317
|
+
canvas.addEventListener('contextmenu', (e) => e.preventDefault());
|
|
1318
|
+
canvas.addEventListener('dblclick', (e) => {
|
|
1319
|
+
const { cx, cy } = getCanvasCoords(e);
|
|
1320
|
+
const world = toWorld(cx, cy);
|
|
1321
|
+
const p = this.getActivePath();
|
|
1322
|
+
if (!p || !p.shape)
|
|
1323
|
+
return;
|
|
1324
|
+
p.shape.push(new Vector3(world.x, world.y, 0));
|
|
1325
|
+
this.currentPreset = 'custom';
|
|
1326
|
+
this.renderActiveTab();
|
|
1327
|
+
this.triggerWYSIWYGUpdate();
|
|
1328
|
+
});
|
|
1329
|
+
canvas.addEventListener('wheel', (e) => {
|
|
1330
|
+
e.preventDefault();
|
|
1331
|
+
const { cx, cy } = getCanvasCoords(e);
|
|
1332
|
+
const world = toWorld(cx, cy);
|
|
1333
|
+
const zoomFactor = e.deltaY < 0 ? 1.15 : 0.85;
|
|
1334
|
+
const newScale = Math.max(2, Math.min(400, this.scale * zoomFactor));
|
|
1335
|
+
this.panX = cx - this.canvasWidth / 2 - world.x * newScale;
|
|
1336
|
+
this.panY = cy - this.canvasHeight / 2 + world.y * newScale;
|
|
1337
|
+
this.scale = newScale;
|
|
1338
|
+
this.redrawCanvas();
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
distToSegment(p, v, w) {
|
|
1342
|
+
const l2 = Math.hypot(v.x - w.x, v.y - w.y) ** 2;
|
|
1343
|
+
if (l2 === 0)
|
|
1344
|
+
return Math.hypot(p.x - v.x, p.y - v.y);
|
|
1345
|
+
let t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
|
|
1346
|
+
t = Math.max(0, Math.min(1, t));
|
|
1347
|
+
return Math.hypot(p.x - (v.x + t * (w.x - v.x)), p.y - (v.y + t * (w.y - v.y)));
|
|
1348
|
+
}
|
|
1349
|
+
redrawCanvas() {
|
|
1350
|
+
if (!this.ctx || !this.canvas)
|
|
1351
|
+
return;
|
|
1352
|
+
const ctx = this.ctx;
|
|
1353
|
+
const width = this.canvasWidth;
|
|
1354
|
+
const height = this.canvasHeight;
|
|
1355
|
+
ctx.clearRect(0, 0, width, height);
|
|
1356
|
+
const originX = width / 2 + this.panX;
|
|
1357
|
+
const originY = height / 2 + this.panY;
|
|
1358
|
+
// Zoom/scale display
|
|
1359
|
+
const zoomEl = document.getElementById('pesCanvasZoom');
|
|
1360
|
+
if (zoomEl) {
|
|
1361
|
+
zoomEl.textContent = `Scale: ${this.scale.toFixed(1)} px/m (${Math.round((this.scale / 45) * 100)}%)`;
|
|
1362
|
+
}
|
|
1363
|
+
// 1. Dynamic Background Grid
|
|
1364
|
+
ctx.strokeStyle = '#1e293b';
|
|
1365
|
+
ctx.lineWidth = 1;
|
|
1366
|
+
const targetPixelSpacing = 40;
|
|
1367
|
+
const rawStep = targetPixelSpacing / this.scale;
|
|
1368
|
+
const niceSteps = [0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20];
|
|
1369
|
+
let gridMeterStep = niceSteps[niceSteps.length - 1];
|
|
1370
|
+
for (const s of niceSteps) {
|
|
1371
|
+
if (s >= rawStep) {
|
|
1372
|
+
gridMeterStep = s;
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
const pixelStep = gridMeterStep * this.scale;
|
|
1377
|
+
const startX = ((originX % pixelStep) + pixelStep) % pixelStep;
|
|
1378
|
+
for (let x = startX; x < width; x += pixelStep) {
|
|
1379
|
+
ctx.beginPath();
|
|
1380
|
+
ctx.moveTo(x, 0);
|
|
1381
|
+
ctx.lineTo(x, height);
|
|
1382
|
+
ctx.stroke();
|
|
1383
|
+
}
|
|
1384
|
+
const startY = ((originY % pixelStep) + pixelStep) % pixelStep;
|
|
1385
|
+
for (let y = startY; y < height; y += pixelStep) {
|
|
1386
|
+
ctx.beginPath();
|
|
1387
|
+
ctx.moveTo(0, y);
|
|
1388
|
+
ctx.lineTo(width, y);
|
|
1389
|
+
ctx.stroke();
|
|
1390
|
+
}
|
|
1391
|
+
// 2. Axes
|
|
1392
|
+
ctx.lineWidth = 1.5;
|
|
1393
|
+
ctx.strokeStyle = '#38bdf8';
|
|
1394
|
+
ctx.beginPath();
|
|
1395
|
+
ctx.moveTo(0, originY);
|
|
1396
|
+
ctx.lineTo(width, originY);
|
|
1397
|
+
ctx.stroke();
|
|
1398
|
+
ctx.strokeStyle = '#22c55e';
|
|
1399
|
+
ctx.beginPath();
|
|
1400
|
+
ctx.moveTo(originX, 0);
|
|
1401
|
+
ctx.lineTo(originX, height);
|
|
1402
|
+
ctx.stroke();
|
|
1403
|
+
ctx.fillStyle = '#f8fafc';
|
|
1404
|
+
ctx.beginPath();
|
|
1405
|
+
ctx.arc(originX, originY, 3, 0, Math.PI * 2);
|
|
1406
|
+
ctx.fill();
|
|
1407
|
+
ctx.font = '9px monospace';
|
|
1408
|
+
ctx.fillStyle = '#64748b';
|
|
1409
|
+
ctx.fillText(`X (${gridMeterStep}m/div)`, width - 75, Math.max(14, Math.min(height - 6, originY - 4)));
|
|
1410
|
+
ctx.fillText('Y', Math.max(4, Math.min(width - 14, originX + 4)), 12);
|
|
1411
|
+
// 3. Draw Cross-section Shape
|
|
1412
|
+
const p = this.getActivePath();
|
|
1413
|
+
if (!p || !p.shape || p.shape.length < 2)
|
|
1414
|
+
return;
|
|
1415
|
+
const shape = p.shape;
|
|
1416
|
+
const solidHalf = shape.solidHalfCount || p.shapeConfig.solidHalfCount || 0;
|
|
1417
|
+
const isClosed = shape.closedShape ?? p.shapeConfig.closedShape ?? true;
|
|
1418
|
+
const toCanvas = (wx, wy) => ({
|
|
1419
|
+
x: originX + wx * this.scale,
|
|
1420
|
+
y: originY - wy * this.scale,
|
|
1421
|
+
});
|
|
1422
|
+
if (solidHalf > 0) {
|
|
1423
|
+
// Solid annular shape (outer loop + inner ring)
|
|
1424
|
+
const outerCount = solidHalf;
|
|
1425
|
+
const innerCount = shape.length - solidHalf;
|
|
1426
|
+
// Outer path
|
|
1427
|
+
ctx.beginPath();
|
|
1428
|
+
const p0 = toCanvas(shape[0].x, shape[0].y);
|
|
1429
|
+
ctx.moveTo(p0.x, p0.y);
|
|
1430
|
+
for (let i = 1; i < outerCount; i++) {
|
|
1431
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1432
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1433
|
+
}
|
|
1434
|
+
if (isClosed)
|
|
1435
|
+
ctx.closePath();
|
|
1436
|
+
ctx.strokeStyle = '#38bdf8';
|
|
1437
|
+
ctx.lineWidth = 2.5;
|
|
1438
|
+
ctx.stroke();
|
|
1439
|
+
// Inner path
|
|
1440
|
+
if (innerCount > 1) {
|
|
1441
|
+
ctx.beginPath();
|
|
1442
|
+
const pi0 = toCanvas(shape[solidHalf].x, shape[solidHalf].y);
|
|
1443
|
+
ctx.moveTo(pi0.x, pi0.y);
|
|
1444
|
+
for (let i = solidHalf + 1; i < shape.length; i++) {
|
|
1445
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1446
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1447
|
+
}
|
|
1448
|
+
if (isClosed)
|
|
1449
|
+
ctx.closePath();
|
|
1450
|
+
ctx.strokeStyle = '#fb923c';
|
|
1451
|
+
ctx.lineWidth = 2;
|
|
1452
|
+
ctx.stroke();
|
|
1453
|
+
}
|
|
1454
|
+
// Shaded fill between rings
|
|
1455
|
+
ctx.fillStyle = 'rgba(56, 189, 248, 0.15)';
|
|
1456
|
+
ctx.beginPath();
|
|
1457
|
+
ctx.moveTo(p0.x, p0.y);
|
|
1458
|
+
for (let i = 1; i < outerCount; i++) {
|
|
1459
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1460
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1461
|
+
}
|
|
1462
|
+
if (isClosed)
|
|
1463
|
+
ctx.closePath();
|
|
1464
|
+
for (let i = solidHalf; i < shape.length; i++) {
|
|
1465
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1466
|
+
if (i === solidHalf)
|
|
1467
|
+
ctx.moveTo(pt.x, pt.y);
|
|
1468
|
+
else
|
|
1469
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1470
|
+
}
|
|
1471
|
+
if (isClosed)
|
|
1472
|
+
ctx.closePath();
|
|
1473
|
+
ctx.fill('evenodd');
|
|
1474
|
+
}
|
|
1475
|
+
else {
|
|
1476
|
+
ctx.beginPath();
|
|
1477
|
+
const p0 = toCanvas(shape[0].x, shape[0].y);
|
|
1478
|
+
ctx.moveTo(p0.x, p0.y);
|
|
1479
|
+
for (let i = 1; i < shape.length; i++) {
|
|
1480
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1481
|
+
ctx.lineTo(pt.x, pt.y);
|
|
1482
|
+
}
|
|
1483
|
+
if (isClosed) {
|
|
1484
|
+
ctx.closePath();
|
|
1485
|
+
ctx.fillStyle = 'rgba(56, 189, 248, 0.18)';
|
|
1486
|
+
ctx.fill();
|
|
1487
|
+
}
|
|
1488
|
+
ctx.strokeStyle = '#38bdf8';
|
|
1489
|
+
ctx.lineWidth = 2.5;
|
|
1490
|
+
ctx.stroke();
|
|
1491
|
+
}
|
|
1492
|
+
// 4. Draw Vertex Handles
|
|
1493
|
+
let pointsOffscreen = 0;
|
|
1494
|
+
for (let i = 0; i < shape.length; i++) {
|
|
1495
|
+
const pt = toCanvas(shape[i].x, shape[i].y);
|
|
1496
|
+
if (pt.x < 0 || pt.x > width || pt.y < 0 || pt.y > height) {
|
|
1497
|
+
pointsOffscreen++;
|
|
1498
|
+
}
|
|
1499
|
+
const isHovered = this.hoveredVertexIndex === i;
|
|
1500
|
+
const isInner = solidHalf > 0 && i >= solidHalf;
|
|
1501
|
+
ctx.beginPath();
|
|
1502
|
+
ctx.arc(pt.x, pt.y, isHovered ? 7 : 4.5, 0, Math.PI * 2);
|
|
1503
|
+
ctx.fillStyle = isInner ? '#fb923c' : i === 0 ? '#f59e0b' : '#38bdf8';
|
|
1504
|
+
ctx.fill();
|
|
1505
|
+
ctx.strokeStyle = '#f8fafc';
|
|
1506
|
+
ctx.lineWidth = 1.5;
|
|
1507
|
+
ctx.stroke();
|
|
1508
|
+
if (isHovered) {
|
|
1509
|
+
ctx.fillStyle = '#ffffff';
|
|
1510
|
+
ctx.font = '10px sans-serif';
|
|
1511
|
+
ctx.fillText(`#${i} (${shape[i].x.toFixed(2)}, ${shape[i].y.toFixed(2)})`, pt.x + 8, pt.y - 8);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
// 5. Offscreen warning
|
|
1515
|
+
if (pointsOffscreen > 0) {
|
|
1516
|
+
ctx.fillStyle = 'rgba(239, 68, 68, 0.88)';
|
|
1517
|
+
ctx.beginPath();
|
|
1518
|
+
const bx = 10;
|
|
1519
|
+
const by = height - 30;
|
|
1520
|
+
const bw = 260;
|
|
1521
|
+
const bh = 20;
|
|
1522
|
+
if (ctx.roundRect)
|
|
1523
|
+
ctx.roundRect(bx, by, bw, bh, 4);
|
|
1524
|
+
else
|
|
1525
|
+
ctx.rect(bx, by, bw, bh);
|
|
1526
|
+
ctx.fill();
|
|
1527
|
+
ctx.fillStyle = '#ffffff';
|
|
1528
|
+
ctx.font = 'bold 11px sans-serif';
|
|
1529
|
+
ctx.fillText(`⚠️ ${pointsOffscreen} points out of view — Click [Fit View]`, bx + 6, by + 14);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
// ─── TAB 2: Extrusion Mesh & Materials ────────────────────────────────────
|
|
1533
|
+
renderMeshTab(p) {
|
|
1534
|
+
const container = this.tabContents.get('mesh');
|
|
1535
|
+
if (!container)
|
|
1536
|
+
return;
|
|
1537
|
+
container.innerHTML = '';
|
|
1538
|
+
// Dimensions
|
|
1539
|
+
const dimSec = document.createElement('div');
|
|
1540
|
+
dimSec.className = 'pes-section';
|
|
1541
|
+
dimSec.innerHTML = '<div class="pes-section-title"><span>📐 Dimensions & Elevation</span></div>';
|
|
1542
|
+
const addNumRow = (label, min, max, step, val, onChange) => {
|
|
1543
|
+
const row = document.createElement('div');
|
|
1544
|
+
row.className = 'pes-row';
|
|
1545
|
+
const lbl = document.createElement('label');
|
|
1546
|
+
lbl.textContent = label;
|
|
1547
|
+
const cnt = document.createElement('div');
|
|
1548
|
+
cnt.className = 'pes-row-content';
|
|
1549
|
+
const slider = document.createElement('input');
|
|
1550
|
+
slider.type = 'range';
|
|
1551
|
+
slider.className = 'pes-slider';
|
|
1552
|
+
slider.min = min.toString();
|
|
1553
|
+
slider.max = max.toString();
|
|
1554
|
+
slider.step = step.toString();
|
|
1555
|
+
slider.value = (val || 0).toString();
|
|
1556
|
+
const num = document.createElement('input');
|
|
1557
|
+
num.type = 'number';
|
|
1558
|
+
num.className = 'pes-input';
|
|
1559
|
+
num.min = min.toString();
|
|
1560
|
+
num.max = max.toString();
|
|
1561
|
+
num.step = step.toString();
|
|
1562
|
+
num.value = (val || 0).toString();
|
|
1563
|
+
const sync = (v) => {
|
|
1564
|
+
slider.value = v.toString();
|
|
1565
|
+
num.value = v.toString();
|
|
1566
|
+
onChange(v);
|
|
1567
|
+
this.triggerWYSIWYGUpdate();
|
|
1568
|
+
};
|
|
1569
|
+
slider.oninput = () => sync(parseFloat(slider.value));
|
|
1570
|
+
num.onchange = () => sync(parseFloat(num.value));
|
|
1571
|
+
cnt.append(slider, num);
|
|
1572
|
+
row.append(lbl, cnt);
|
|
1573
|
+
dimSec.appendChild(row);
|
|
1574
|
+
};
|
|
1575
|
+
const dims = this.getShapeDimensions(p.shape);
|
|
1576
|
+
const initialWidth = p.shapeConfig.width ?? parseFloat(dims.width.toFixed(2));
|
|
1577
|
+
const initialHeight = p.shapeConfig.height ?? parseFloat(dims.height.toFixed(2));
|
|
1578
|
+
addNumRow('Width:', 0.5, 30, 0.25, initialWidth, (newWidth) => {
|
|
1579
|
+
if (p.shape && p.shape.length > 0) {
|
|
1580
|
+
const curW = this.getShapeDimensions(p.shape).width;
|
|
1581
|
+
if (curW > 0.001) {
|
|
1582
|
+
const factor = newWidth / curW;
|
|
1583
|
+
for (const pt of p.shape) {
|
|
1584
|
+
pt.x *= factor;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
this.currentPreset = 'custom';
|
|
1588
|
+
this.fitCanvasView();
|
|
1589
|
+
}
|
|
1590
|
+
p.shapeConfig.width = newWidth;
|
|
1591
|
+
});
|
|
1592
|
+
addNumRow('Height:', 0.1, 10, 0.05, initialHeight, (newHeight) => {
|
|
1593
|
+
if (p.shape && p.shape.length > 0) {
|
|
1594
|
+
const curH = this.getShapeDimensions(p.shape).height;
|
|
1595
|
+
if (curH > 0.001) {
|
|
1596
|
+
const factor = newHeight / curH;
|
|
1597
|
+
for (const pt of p.shape) {
|
|
1598
|
+
pt.y *= factor;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
this.currentPreset = 'custom';
|
|
1602
|
+
this.fitCanvasView();
|
|
1603
|
+
}
|
|
1604
|
+
p.shapeConfig.height = newHeight;
|
|
1605
|
+
});
|
|
1606
|
+
addNumRow('Y-Offset (Elevation):', -5, 15, 0.1, p.shapeConfig.yOffset || 0, (v) => (p.shapeConfig.yOffset = v));
|
|
1607
|
+
addNumRow('Spline Smoothness:', 1, 40, 1, p.shapeConfig.smoothSteps || 10, (v) => (p.shapeConfig.smoothSteps = v));
|
|
1608
|
+
// Cap ends toggle
|
|
1609
|
+
const capRow = document.createElement('div');
|
|
1610
|
+
capRow.className = 'pes-row';
|
|
1611
|
+
const capLbl = document.createElement('label');
|
|
1612
|
+
capLbl.textContent = 'Cap Ends:';
|
|
1613
|
+
const capCnt = document.createElement('div');
|
|
1614
|
+
capCnt.className = 'pes-row-content';
|
|
1615
|
+
const capCheck = document.createElement('input');
|
|
1616
|
+
capCheck.type = 'checkbox';
|
|
1617
|
+
capCheck.checked = p.shapeConfig.capEnds ?? false;
|
|
1618
|
+
capCheck.onchange = () => {
|
|
1619
|
+
p.shapeConfig.capEnds = capCheck.checked;
|
|
1620
|
+
this.triggerWYSIWYGUpdate();
|
|
1621
|
+
};
|
|
1622
|
+
const capDesc = document.createElement('span');
|
|
1623
|
+
capDesc.style.fontSize = '11px';
|
|
1624
|
+
capDesc.style.color = '#94a3b8';
|
|
1625
|
+
capDesc.textContent = 'Generate solid manifold end caps at start and end of path';
|
|
1626
|
+
capCnt.append(capCheck, capDesc);
|
|
1627
|
+
capRow.append(capLbl, capCnt);
|
|
1628
|
+
dimSec.appendChild(capRow);
|
|
1629
|
+
container.appendChild(dimSec);
|
|
1630
|
+
// Materials
|
|
1631
|
+
const matSec = document.createElement('div');
|
|
1632
|
+
matSec.className = 'pes-section';
|
|
1633
|
+
matSec.innerHTML = '<div class="pes-section-title"><span>🎨 Materials & Shading</span></div>';
|
|
1634
|
+
// Color picker
|
|
1635
|
+
const colRow = document.createElement('div');
|
|
1636
|
+
colRow.className = 'pes-row';
|
|
1637
|
+
const colLbl = document.createElement('label');
|
|
1638
|
+
colLbl.textContent = 'Albedo Color:';
|
|
1639
|
+
const colCnt = document.createElement('div');
|
|
1640
|
+
colCnt.className = 'pes-row-content';
|
|
1641
|
+
const colInput = document.createElement('input');
|
|
1642
|
+
colInput.type = 'color';
|
|
1643
|
+
colInput.value = p.shapeConfig.color || '#38bdf8';
|
|
1644
|
+
const colHex = document.createElement('span');
|
|
1645
|
+
colHex.style.fontSize = '12px';
|
|
1646
|
+
colHex.style.fontFamily = 'monospace';
|
|
1647
|
+
colHex.textContent = colInput.value;
|
|
1648
|
+
colInput.oninput = () => {
|
|
1649
|
+
p.shapeConfig.color = colInput.value;
|
|
1650
|
+
colHex.textContent = colInput.value;
|
|
1651
|
+
this.triggerWYSIWYGUpdate();
|
|
1652
|
+
};
|
|
1653
|
+
colCnt.append(colInput, colHex);
|
|
1654
|
+
colRow.append(colLbl, colCnt);
|
|
1655
|
+
matSec.appendChild(colRow);
|
|
1656
|
+
// Roughness & Metallic
|
|
1657
|
+
const addMatSlider = (label, val, onChange) => {
|
|
1658
|
+
const row = document.createElement('div');
|
|
1659
|
+
row.className = 'pes-row';
|
|
1660
|
+
const lbl = document.createElement('label');
|
|
1661
|
+
lbl.textContent = label;
|
|
1662
|
+
const cnt = document.createElement('div');
|
|
1663
|
+
cnt.className = 'pes-row-content';
|
|
1664
|
+
const slider = document.createElement('input');
|
|
1665
|
+
slider.type = 'range';
|
|
1666
|
+
slider.className = 'pes-slider';
|
|
1667
|
+
slider.min = '0';
|
|
1668
|
+
slider.max = '1';
|
|
1669
|
+
slider.step = '0.05';
|
|
1670
|
+
slider.value = (val ?? 0.4).toString();
|
|
1671
|
+
const num = document.createElement('span');
|
|
1672
|
+
num.style.fontSize = '12px';
|
|
1673
|
+
num.style.width = '35px';
|
|
1674
|
+
num.textContent = slider.value;
|
|
1675
|
+
slider.oninput = () => {
|
|
1676
|
+
num.textContent = slider.value;
|
|
1677
|
+
onChange(parseFloat(slider.value));
|
|
1678
|
+
this.triggerWYSIWYGUpdate();
|
|
1679
|
+
};
|
|
1680
|
+
cnt.append(slider, num);
|
|
1681
|
+
row.append(lbl, cnt);
|
|
1682
|
+
matSec.appendChild(row);
|
|
1683
|
+
};
|
|
1684
|
+
addMatSlider('Roughness:', p.shapeConfig.roughness ?? 0.4, (v) => (p.shapeConfig.roughness = v));
|
|
1685
|
+
addMatSlider('Metallic:', p.shapeConfig.metallic ?? 0.1, (v) => (p.shapeConfig.metallic = v));
|
|
1686
|
+
container.appendChild(matSec);
|
|
1687
|
+
}
|
|
1688
|
+
// ─── TAB 3: Path Trajectory & Curve ───────────────────────────────────────
|
|
1689
|
+
renderCurveTab(p) {
|
|
1690
|
+
const container = this.tabContents.get('curve');
|
|
1691
|
+
if (!container)
|
|
1692
|
+
return;
|
|
1693
|
+
container.innerHTML = '';
|
|
1694
|
+
const ptsSec = document.createElement('div');
|
|
1695
|
+
ptsSec.className = 'pes-section';
|
|
1696
|
+
ptsSec.innerHTML = `<div class="pes-section-title"><span>📍 Spline Waypoints (${p.points.length} points)</span></div>`;
|
|
1697
|
+
// Quick Actions Toolbar
|
|
1698
|
+
const actRow = document.createElement('div');
|
|
1699
|
+
actRow.style.display = 'flex';
|
|
1700
|
+
actRow.style.gap = '6px';
|
|
1701
|
+
actRow.style.flexWrap = 'wrap';
|
|
1702
|
+
const addBtn = document.createElement('button');
|
|
1703
|
+
addBtn.className = 'pes-btn small primary';
|
|
1704
|
+
addBtn.innerHTML = '➕ Add Point';
|
|
1705
|
+
addBtn.onclick = () => {
|
|
1706
|
+
const last = p.points[p.points.length - 1] || { x: 0, y: 0.1, z: 0 };
|
|
1707
|
+
this.controller.addPoint(new Vector3(last.x + 1.5, last.y, last.z + 1.5));
|
|
1708
|
+
this.renderActiveTab();
|
|
1709
|
+
};
|
|
1710
|
+
const reverseBtn = document.createElement('button');
|
|
1711
|
+
reverseBtn.className = 'pes-btn small';
|
|
1712
|
+
reverseBtn.innerHTML = '🔄 Reverse Points';
|
|
1713
|
+
reverseBtn.onclick = () => {
|
|
1714
|
+
p.points.reverse();
|
|
1715
|
+
this.controller.refreshScene();
|
|
1716
|
+
this.renderActiveTab();
|
|
1717
|
+
};
|
|
1718
|
+
const removeBtn = document.createElement('button');
|
|
1719
|
+
removeBtn.className = 'pes-btn small';
|
|
1720
|
+
removeBtn.innerHTML = '➖ Remove Selected';
|
|
1721
|
+
removeBtn.onclick = () => {
|
|
1722
|
+
this.controller.removeSelectedPoint();
|
|
1723
|
+
this.renderActiveTab();
|
|
1724
|
+
};
|
|
1725
|
+
const clearBtn = document.createElement('button');
|
|
1726
|
+
clearBtn.className = 'pes-btn small danger';
|
|
1727
|
+
clearBtn.innerHTML = '🗑️ Clear All';
|
|
1728
|
+
clearBtn.onclick = () => {
|
|
1729
|
+
if (confirm('Clear all waypoints?')) {
|
|
1730
|
+
this.controller.clearPoints();
|
|
1731
|
+
this.renderActiveTab();
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
actRow.append(addBtn, reverseBtn, removeBtn, clearBtn);
|
|
1735
|
+
ptsSec.appendChild(actRow);
|
|
1736
|
+
// Points Table
|
|
1737
|
+
const tableWrap = document.createElement('div');
|
|
1738
|
+
tableWrap.className = 'pes-table-container';
|
|
1739
|
+
tableWrap.style.maxHeight = '220px';
|
|
1740
|
+
const table = document.createElement('table');
|
|
1741
|
+
table.className = 'pes-table';
|
|
1742
|
+
table.innerHTML = `
|
|
1743
|
+
<thead>
|
|
1744
|
+
<tr>
|
|
1745
|
+
<th>#</th>
|
|
1746
|
+
<th>X</th>
|
|
1747
|
+
<th>Y</th>
|
|
1748
|
+
<th>Z</th>
|
|
1749
|
+
<th style="width:30px;"></th>
|
|
1750
|
+
</tr>
|
|
1751
|
+
</thead>
|
|
1752
|
+
<tbody></tbody>
|
|
1753
|
+
`;
|
|
1754
|
+
const tbody = table.querySelector('tbody');
|
|
1755
|
+
p.points.forEach((pt, i) => {
|
|
1756
|
+
const tr = document.createElement('tr');
|
|
1757
|
+
const isSelected = i === this.controller.selectedPointIndex;
|
|
1758
|
+
if (isSelected)
|
|
1759
|
+
tr.style.background = 'rgba(56, 189, 248, 0.12)';
|
|
1760
|
+
tr.innerHTML = `
|
|
1761
|
+
<td style="color:${isSelected ? '#fbbf24' : '#38bdf8'}; font-weight:600;">${i}</td>
|
|
1762
|
+
<td><input type="number" step="0.5" class="pes-input" style="width:65px; padding:2px 4px;" value="${pt.x.toFixed(2)}" data-idx="${i}" data-c="x"></td>
|
|
1763
|
+
<td><input type="number" step="0.5" class="pes-input" style="width:65px; padding:2px 4px;" value="${pt.y.toFixed(2)}" data-idx="${i}" data-c="y"></td>
|
|
1764
|
+
<td><input type="number" step="0.5" class="pes-input" style="width:65px; padding:2px 4px;" value="${pt.z.toFixed(2)}" data-idx="${i}" data-c="z"></td>
|
|
1765
|
+
<td><button class="pes-btn small danger" style="padding:1px 5px;" data-del="${i}">✕</button></td>
|
|
1766
|
+
`;
|
|
1767
|
+
tr.querySelectorAll('input').forEach((inp) => {
|
|
1768
|
+
inp.onchange = (e) => {
|
|
1769
|
+
const target = e.target;
|
|
1770
|
+
const idx = parseInt(target.dataset.idx, 10);
|
|
1771
|
+
const coord = target.dataset.c;
|
|
1772
|
+
p.points[idx][coord] = parseFloat(target.value) || 0;
|
|
1773
|
+
this.controller.refreshScene();
|
|
1774
|
+
};
|
|
1775
|
+
});
|
|
1776
|
+
tr.querySelector('button')?.addEventListener('click', () => {
|
|
1777
|
+
p.points.splice(i, 1);
|
|
1778
|
+
this.controller.refreshScene();
|
|
1779
|
+
this.renderActiveTab();
|
|
1780
|
+
});
|
|
1781
|
+
tbody.appendChild(tr);
|
|
1782
|
+
});
|
|
1783
|
+
tableWrap.appendChild(table);
|
|
1784
|
+
ptsSec.appendChild(tableWrap);
|
|
1785
|
+
const tip = document.createElement('div');
|
|
1786
|
+
tip.style.fontSize = '11px';
|
|
1787
|
+
tip.style.color = '#94a3b8';
|
|
1788
|
+
tip.innerHTML = '💡 <i>Tip: Hold <b>Shift</b> and click anywhere on the 3D ground or meshes to append points, or click any waypoint sphere to attach the 3D Gizmo and drag it in 3D space!</i>';
|
|
1789
|
+
ptsSec.appendChild(tip);
|
|
1790
|
+
container.appendChild(ptsSec);
|
|
1791
|
+
}
|
|
1792
|
+
}
|