@tableslayer/ui 0.1.3 → 0.1.4
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/package.json +2 -13
- package/src/lib/components/Avatar/Avatar.svelte +82 -0
- package/src/lib/components/Avatar/AvatarFileInput.svelte +85 -0
- package/src/lib/components/Avatar/AvatarPopover.svelte +34 -0
- package/src/lib/components/Avatar/index.ts +4 -0
- package/src/lib/components/Avatar/types.ts +24 -0
- package/src/lib/components/BrushSizeSlider/BrushSizeSlider.svelte +174 -0
- package/src/lib/components/BrushSizeSlider/index.ts +1 -0
- package/src/lib/components/Button/Button.svelte +182 -0
- package/src/lib/components/Button/ConfirmActionButton.svelte +98 -0
- package/src/lib/components/Button/IconButton.svelte +121 -0
- package/src/lib/components/Button/RadioButton.svelte +93 -0
- package/src/lib/components/Button/index.ts +5 -0
- package/src/lib/components/Button/types.ts +54 -0
- package/src/lib/components/CardFan/CardFan.svelte +165 -0
- package/src/lib/components/CardFan/index.ts +2 -0
- package/src/lib/components/CardFan/types.ts +6 -0
- package/src/lib/components/CodeBlock/Code.svelte +7 -0
- package/src/lib/components/CodeBlock/CodeBlock.svelte +102 -0
- package/src/lib/components/CodeBlock/index.ts +3 -0
- package/src/lib/components/CodeBlock/types.ts +10 -0
- package/src/lib/components/ColorMode/ColorMode.svelte +8 -0
- package/src/lib/components/ColorMode/index.ts +2 -0
- package/src/lib/components/ColorMode/types.ts +12 -0
- package/src/lib/components/ColorPicker/ColorPicker.svelte +838 -0
- package/src/lib/components/ColorPicker/ColorPickerSwatch.svelte +32 -0
- package/src/lib/components/ColorPicker/index.ts +3 -0
- package/src/lib/components/ColorPicker/types.ts +51 -0
- package/src/lib/components/ContextMenu/ContextMenu.svelte +86 -0
- package/src/lib/components/ContextMenu/index.ts +2 -0
- package/src/lib/components/ContextMenu/types.ts +15 -0
- package/src/lib/components/DrawingSliders/DrawingSliders.svelte +379 -0
- package/src/lib/components/DrawingSliders/index.ts +1 -0
- package/src/lib/components/Editor/Editor.svelte +825 -0
- package/src/lib/components/Editor/index.ts +1 -0
- package/src/lib/components/FogSliders/FogSliders.svelte +33 -0
- package/src/lib/components/FogSliders/index.ts +1 -0
- package/src/lib/components/Hr/Hr.svelte +15 -0
- package/src/lib/components/Hr/index.ts +1 -0
- package/src/lib/components/Icon/Icon.svelte +6 -0
- package/src/lib/components/Icon/index.ts +2 -0
- package/src/lib/components/Icon/types.ts +20 -0
- package/src/lib/components/Input/DualInputSlider.svelte +126 -0
- package/src/lib/components/Input/FileInput.svelte +176 -0
- package/src/lib/components/Input/FormControl.svelte +150 -0
- package/src/lib/components/Input/FormError.svelte +37 -0
- package/src/lib/components/Input/Input.svelte +56 -0
- package/src/lib/components/Input/InputCheckbox.svelte +99 -0
- package/src/lib/components/Input/InputSlider.svelte +86 -0
- package/src/lib/components/Input/Label.svelte +19 -0
- package/src/lib/components/Input/index.ts +9 -0
- package/src/lib/components/Input/types.ts +39 -0
- package/src/lib/components/Link/Link.svelte +41 -0
- package/src/lib/components/Link/LinkBox.svelte +20 -0
- package/src/lib/components/Link/LinkOverlay.svelte +23 -0
- package/src/lib/components/Link/index.ts +4 -0
- package/src/lib/components/Link/types.ts +17 -0
- package/src/lib/components/Loading/Loader.svelte +60 -0
- package/src/lib/components/Loading/Skeleton.svelte +9 -0
- package/src/lib/components/Loading/index.ts +2 -0
- package/src/lib/components/Logo/Logo.svelte +16 -0
- package/src/lib/components/Logo/index.ts +1 -0
- package/src/lib/components/MarkerTooltip/MarkerTooltip.svelte +435 -0
- package/src/lib/components/MarkerTooltip/index.ts +1 -0
- package/src/lib/components/Menu/SelectorMenu.svelte +280 -0
- package/src/lib/components/Menu/index.ts +2 -0
- package/src/lib/components/Menu/types.ts +17 -0
- package/src/lib/components/MyCounterButton.svelte +11 -0
- package/src/lib/components/Panel/index.ts +2 -0
- package/src/lib/components/Panel/panel.svelte +18 -0
- package/src/lib/components/Panel/types.ts +8 -0
- package/src/lib/components/PersistButton/PersistButton.svelte +100 -0
- package/src/lib/components/PersistButton/index.ts +1 -0
- package/src/lib/components/Popover/Popover.svelte +81 -0
- package/src/lib/components/Popover/index.ts +2 -0
- package/src/lib/components/Popover/types.ts +19 -0
- package/src/lib/components/PropsTable/PropsTable.svelte +107 -0
- package/src/lib/components/RadialMenu/EffectPreview.svelte +36 -0
- package/src/lib/components/RadialMenu/EffectPreviewScene.svelte +194 -0
- package/src/lib/components/RadialMenu/RadialMenu.svelte +503 -0
- package/src/lib/components/RadialMenu/RadialMenuItem.svelte +176 -0
- package/src/lib/components/RadialMenu/index.ts +2 -0
- package/src/lib/components/RadialMenu/types.ts +35 -0
- package/src/lib/components/Select/Select.svelte +342 -0
- package/src/lib/components/Select/index.ts +2 -0
- package/src/lib/components/Select/types.ts +22 -0
- package/src/lib/components/Spacer/Spacer.svelte +14 -0
- package/src/lib/components/Spacer/index.ts +2 -0
- package/src/lib/components/Spacer/types.ts +5 -0
- package/src/lib/components/Stage/components/AnnotationLayer/AnnotationLayer.svelte +445 -0
- package/src/lib/components/Stage/components/AnnotationLayer/AnnotationMaterial.svelte +167 -0
- package/src/lib/components/Stage/components/AnnotationLayer/types.ts +196 -0
- package/src/lib/components/Stage/components/CursorLayer/CursorLayer.svelte +148 -0
- package/src/lib/components/Stage/components/CursorLayer/cursor.svg +26 -0
- package/src/lib/components/Stage/components/CursorLayer/index.ts +2 -0
- package/src/lib/components/Stage/components/CursorLayer/types.ts +23 -0
- package/src/lib/components/Stage/components/DrawingLayer/DrawingMaterial.svelte +364 -0
- package/src/lib/components/Stage/components/DrawingLayer/types.ts +65 -0
- package/src/lib/components/Stage/components/EdgeOverlayLayer/EdgeOverlayLayer.svelte +72 -0
- package/src/lib/components/Stage/components/EdgeOverlayLayer/types.ts +34 -0
- package/src/lib/components/Stage/components/FogLayer/FogLayer.svelte +75 -0
- package/src/lib/components/Stage/components/FogLayer/types.ts +51 -0
- package/src/lib/components/Stage/components/FogOfWarLayer/FogOfWarLayer.svelte +249 -0
- package/src/lib/components/Stage/components/FogOfWarLayer/FogOfWarMaterial.svelte +200 -0
- package/src/lib/components/Stage/components/FogOfWarLayer/types.ts +116 -0
- package/src/lib/components/Stage/components/GridLayer/GridLayer.svelte +20 -0
- package/src/lib/components/Stage/components/GridLayer/GridMaterial.svelte +69 -0
- package/src/lib/components/Stage/components/GridLayer/types.ts +79 -0
- package/src/lib/components/Stage/components/LayerInput/LayerInput.svelte +300 -0
- package/src/lib/components/Stage/components/MapLayer/MapLayer.svelte +196 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/GifDataSource.ts +265 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/IMapDataSource.ts +55 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/ImageDataSource.ts +87 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/VideoDataSource.ts +150 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/dataSourceFactory.ts +48 -0
- package/src/lib/components/Stage/components/MapLayer/dataSources/index.ts +16 -0
- package/src/lib/components/Stage/components/MapLayer/types.ts +58 -0
- package/src/lib/components/Stage/components/MarkerLayer/MarkerLayer.svelte +398 -0
- package/src/lib/components/Stage/components/MarkerLayer/MarkerToken.svelte +262 -0
- package/src/lib/components/Stage/components/MarkerLayer/types.ts +126 -0
- package/src/lib/components/Stage/components/MeasurementLayer/MeasurementLayer.svelte +364 -0
- package/src/lib/components/Stage/components/MeasurementLayer/MeasurementManager.svelte +473 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/BaseMeasurement.ts +427 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/BeamMeasurement.ts +105 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/CircleMeasurement.ts +98 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/ConeMeasurement.ts +163 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/LineMeasurement.ts +102 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/RectangleMeasurement.ts +120 -0
- package/src/lib/components/Stage/components/MeasurementLayer/measurements/index.ts +7 -0
- package/src/lib/components/Stage/components/MeasurementLayer/types.ts +94 -0
- package/src/lib/components/Stage/components/MeasurementLayer/utils/canvasDrawing.ts +357 -0
- package/src/lib/components/Stage/components/MeasurementLayer/utils/distanceCalculations.ts +170 -0
- package/src/lib/components/Stage/components/ParticleSystem/ParticleSystem.svelte +220 -0
- package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/ash.png +0 -0
- package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/leaves.png +0 -0
- package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/rain.png +0 -0
- package/src/lib/components/Stage/components/ParticleSystem/particles/atlases/snow.png +0 -0
- package/src/lib/components/Stage/components/ParticleSystem/rng.js +20 -0
- package/src/lib/components/Stage/components/ParticleSystem/types.ts +95 -0
- package/src/lib/components/Stage/components/PerformanceDebugger/PerformanceDebugger.svelte +144 -0
- package/src/lib/components/Stage/components/PerformanceDebugger/index.ts +1 -0
- package/src/lib/components/Stage/components/PerformanceOverlay/PerformanceOverlay.svelte +208 -0
- package/src/lib/components/Stage/components/PerformanceOverlay/index.ts +1 -0
- package/src/lib/components/Stage/components/PointerInputManager/PointerInputManager.svelte +201 -0
- package/src/lib/components/Stage/components/Scene/Scene.svelte +651 -0
- package/src/lib/components/Stage/components/Scene/luts.ts +24 -0
- package/src/lib/components/Stage/components/Scene/types.ts +225 -0
- package/src/lib/components/Stage/components/Stage/Stage.svelte +332 -0
- package/src/lib/components/Stage/components/Stage/types.ts +136 -0
- package/src/lib/components/Stage/components/WeatherLayer/WeatherLayer.svelte +135 -0
- package/src/lib/components/Stage/components/WeatherLayer/presets/AshPreset.ts +71 -0
- package/src/lib/components/Stage/components/WeatherLayer/presets/LeavesPreset.ts +70 -0
- package/src/lib/components/Stage/components/WeatherLayer/presets/RainPreset.ts +68 -0
- package/src/lib/components/Stage/components/WeatherLayer/presets/SnowPreset.ts +70 -0
- package/src/lib/components/Stage/components/WeatherLayer/presets/index.ts +6 -0
- package/src/lib/components/Stage/components/WeatherLayer/types.ts +35 -0
- package/src/lib/components/Stage/helpers/clippingPlaneStore.svelte.ts +28 -0
- package/src/lib/components/Stage/helpers/debugState.svelte.ts +18 -0
- package/src/lib/components/Stage/helpers/grid.ts +548 -0
- package/src/lib/components/Stage/helpers/lazyBrush.ts +171 -0
- package/src/lib/components/Stage/helpers/performanceMetrics.svelte.ts +220 -0
- package/src/lib/components/Stage/helpers/utils.ts +21 -0
- package/src/lib/components/Stage/index.ts +49 -0
- package/src/lib/components/Stage/shaders/AnnotationEffects.frag +1070 -0
- package/src/lib/components/Stage/shaders/Annotations.frag +29 -0
- package/src/lib/components/Stage/shaders/Drawing.frag +83 -0
- package/src/lib/components/Stage/shaders/Drawing.vert +5 -0
- package/src/lib/components/Stage/shaders/Fog.frag +147 -0
- package/src/lib/components/Stage/shaders/FractalNoise.frag +96 -0
- package/src/lib/components/Stage/shaders/GridShader.frag +174 -0
- package/src/lib/components/Stage/shaders/Overlay.frag +23 -0
- package/src/lib/components/Stage/shaders/Overlay.vert +0 -0
- package/src/lib/components/Stage/shaders/Particles.frag +27 -0
- package/src/lib/components/Stage/shaders/Particles.vert +51 -0
- package/src/lib/components/Stage/shaders/ToolOutline.frag +59 -0
- package/src/lib/components/Stage/shaders/default.vert +8 -0
- package/src/lib/components/Stage/types.ts +4 -0
- package/src/lib/components/Table/Table.svelte +16 -0
- package/src/lib/components/Table/Td.svelte +17 -0
- package/src/lib/components/Table/Th.svelte +18 -0
- package/src/lib/components/Table/index.ts +4 -0
- package/src/lib/components/Table/types.ts +14 -0
- package/src/lib/components/Text/Text.svelte +23 -0
- package/src/lib/components/Text/index.ts +2 -0
- package/src/lib/components/Text/types.ts +12 -0
- package/src/lib/components/Title/Title.svelte +54 -0
- package/src/lib/components/Title/index.ts +2 -0
- package/src/lib/components/Title/types.ts +9 -0
- package/src/lib/components/Toast/Toast.svelte +155 -0
- package/src/lib/components/Toast/index.ts +5 -0
- package/src/lib/components/Toast/toastCookie.ts +24 -0
- package/src/lib/components/Toast/types.ts +6 -0
- package/src/lib/components/ToolTip/ToolTip.svelte +70 -0
- package/src/lib/components/ToolTip/index.ts +2 -0
- package/src/lib/components/ToolTip/types.ts +14 -0
- package/src/lib/components/index.ts +32 -0
- package/src/lib/components/types.ts +0 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/styles/globals.css +108 -0
- package/src/lib/styles/normalize.css +9 -0
- package/src/lib/styles/reset.css +133 -0
- package/src/lib/styles/utilities.css +179 -0
- package/src/lib/styles/vars.css +1103 -0
- package/src/lib/types/awareness.ts +17 -0
- package/src/lib/utils/rle.ts +217 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
import type { DisplayProps } from '../../Stage/types';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
import type { GridLayerProps } from '../../GridLayer/types';
|
|
7
|
+
import { MeasurementType, type MeasurementLayerProps } from '../types';
|
|
8
|
+
import { drawCircle } from '../utils/canvasDrawing';
|
|
9
|
+
import { BaseMeasurement } from './BaseMeasurement';
|
|
10
|
+
|
|
11
|
+
export class ConeMeasurement extends BaseMeasurement {
|
|
12
|
+
private coneAngle: number;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
startPoint: THREE.Vector2,
|
|
16
|
+
measurementProps: MeasurementLayerProps,
|
|
17
|
+
displayProps: DisplayProps,
|
|
18
|
+
gridProps: GridLayerProps
|
|
19
|
+
) {
|
|
20
|
+
super(MeasurementType.Cone, startPoint, measurementProps, displayProps, gridProps);
|
|
21
|
+
this.coneAngle = measurementProps.coneAngle;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
renderShape(): void {
|
|
25
|
+
// Calculate cone parameters
|
|
26
|
+
const radius = this.startPoint.distanceTo(this.endPoint);
|
|
27
|
+
const direction = this.endPoint.clone().sub(this.startPoint);
|
|
28
|
+
const centerAngle = Math.atan2(direction.y, direction.x);
|
|
29
|
+
|
|
30
|
+
// Convert cone angle from degrees to radians and calculate start/end angles
|
|
31
|
+
const coneAngleRad = (this.coneAngle * Math.PI) / 180;
|
|
32
|
+
const startAngle = centerAngle - coneAngleRad / 2;
|
|
33
|
+
const endAngle = centerAngle + coneAngleRad / 2;
|
|
34
|
+
|
|
35
|
+
// Create canvas for the cone
|
|
36
|
+
const canvas = document.createElement('canvas');
|
|
37
|
+
const context = canvas.getContext('2d', { colorSpace: 'srgb' })!;
|
|
38
|
+
|
|
39
|
+
// Calculate canvas size - accommodate full cone plus padding
|
|
40
|
+
const padding = Math.max(this.markerSize + this.outlineThickness, 40);
|
|
41
|
+
const canvasSize = (radius + padding) * 2;
|
|
42
|
+
|
|
43
|
+
canvas.width = Math.max(canvasSize, 100);
|
|
44
|
+
canvas.height = Math.max(canvasSize, 100);
|
|
45
|
+
|
|
46
|
+
// Clear canvas
|
|
47
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
48
|
+
|
|
49
|
+
// Canvas center coordinates
|
|
50
|
+
const canvasCenterX = canvas.width / 2;
|
|
51
|
+
const canvasCenterY = canvas.height / 2;
|
|
52
|
+
|
|
53
|
+
// Draw cone with dashed pattern
|
|
54
|
+
if (radius > 0) {
|
|
55
|
+
// First draw the fill
|
|
56
|
+
context.fillStyle = this.color;
|
|
57
|
+
context.globalAlpha = 0.2;
|
|
58
|
+
context.beginPath();
|
|
59
|
+
context.moveTo(canvasCenterX, canvasCenterY);
|
|
60
|
+
context.arc(canvasCenterX, canvasCenterY, radius, -startAngle, -endAngle, true);
|
|
61
|
+
context.closePath();
|
|
62
|
+
context.fill();
|
|
63
|
+
context.globalAlpha = 1.0;
|
|
64
|
+
|
|
65
|
+
// Draw the outline with dashed pattern if needed
|
|
66
|
+
if (this.outlineThickness > 0) {
|
|
67
|
+
context.strokeStyle = this.outlineColor;
|
|
68
|
+
context.lineWidth = this.thickness + this.outlineThickness * 2;
|
|
69
|
+
context.setLineDash([20, 10]); // Dashed pattern
|
|
70
|
+
|
|
71
|
+
// Draw the arc
|
|
72
|
+
context.beginPath();
|
|
73
|
+
context.arc(canvasCenterX, canvasCenterY, radius, -startAngle, -endAngle, true);
|
|
74
|
+
context.stroke();
|
|
75
|
+
|
|
76
|
+
// Draw the sides
|
|
77
|
+
context.beginPath();
|
|
78
|
+
context.moveTo(canvasCenterX, canvasCenterY);
|
|
79
|
+
context.lineTo(canvasCenterX + Math.cos(-startAngle) * radius, canvasCenterY + Math.sin(-startAngle) * radius);
|
|
80
|
+
context.stroke();
|
|
81
|
+
|
|
82
|
+
context.beginPath();
|
|
83
|
+
context.moveTo(canvasCenterX, canvasCenterY);
|
|
84
|
+
context.lineTo(canvasCenterX + Math.cos(-endAngle) * radius, canvasCenterY + Math.sin(-endAngle) * radius);
|
|
85
|
+
context.stroke();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Draw the main stroke with dashed pattern
|
|
89
|
+
context.strokeStyle = this.color;
|
|
90
|
+
context.lineWidth = this.thickness;
|
|
91
|
+
context.setLineDash([20, 10]); // Dashed pattern
|
|
92
|
+
|
|
93
|
+
// Draw the arc
|
|
94
|
+
context.beginPath();
|
|
95
|
+
context.arc(canvasCenterX, canvasCenterY, radius, -startAngle, -endAngle, true);
|
|
96
|
+
context.stroke();
|
|
97
|
+
|
|
98
|
+
// Draw the sides
|
|
99
|
+
context.beginPath();
|
|
100
|
+
context.moveTo(canvasCenterX, canvasCenterY);
|
|
101
|
+
context.lineTo(canvasCenterX + Math.cos(-startAngle) * radius, canvasCenterY + Math.sin(-startAngle) * radius);
|
|
102
|
+
context.stroke();
|
|
103
|
+
|
|
104
|
+
context.beginPath();
|
|
105
|
+
context.moveTo(canvasCenterX, canvasCenterY);
|
|
106
|
+
context.lineTo(canvasCenterX + Math.cos(-endAngle) * radius, canvasCenterY + Math.sin(-endAngle) * radius);
|
|
107
|
+
context.stroke();
|
|
108
|
+
|
|
109
|
+
// Reset dash pattern for other elements
|
|
110
|
+
context.setLineDash([]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Draw center point (cone origin)
|
|
114
|
+
drawCircle(
|
|
115
|
+
context,
|
|
116
|
+
canvasCenterX,
|
|
117
|
+
canvasCenterY,
|
|
118
|
+
this.markerSize / 2,
|
|
119
|
+
this.color,
|
|
120
|
+
this.outlineColor,
|
|
121
|
+
this.outlineThickness
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Draw point at the center of the cone's end arc (invert Y for canvas coordinates)
|
|
125
|
+
const endPointX = canvasCenterX + Math.cos(centerAngle) * radius;
|
|
126
|
+
const endPointY = canvasCenterY - Math.sin(centerAngle) * radius;
|
|
127
|
+
drawCircle(
|
|
128
|
+
context,
|
|
129
|
+
endPointX,
|
|
130
|
+
endPointY,
|
|
131
|
+
this.markerSize / 2,
|
|
132
|
+
this.color,
|
|
133
|
+
this.outlineColor,
|
|
134
|
+
this.outlineThickness
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Draw points at the cone's edges (invert Y for canvas coordinates)
|
|
138
|
+
const startEdgeX = canvasCenterX + Math.cos(startAngle) * radius;
|
|
139
|
+
const startEdgeY = canvasCenterY - Math.sin(startAngle) * radius;
|
|
140
|
+
drawCircle(
|
|
141
|
+
context,
|
|
142
|
+
startEdgeX,
|
|
143
|
+
startEdgeY,
|
|
144
|
+
this.markerSize / 2,
|
|
145
|
+
this.color,
|
|
146
|
+
this.outlineColor,
|
|
147
|
+
this.outlineThickness
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const endEdgeX = canvasCenterX + Math.cos(endAngle) * radius;
|
|
151
|
+
const endEdgeY = canvasCenterY - Math.sin(endAngle) * radius;
|
|
152
|
+
drawCircle(context, endEdgeX, endEdgeY, this.markerSize / 2, this.color, this.outlineColor, this.outlineThickness);
|
|
153
|
+
|
|
154
|
+
// Create texture from canvas
|
|
155
|
+
const texture = new THREE.CanvasTexture(canvas);
|
|
156
|
+
texture.needsUpdate = true;
|
|
157
|
+
|
|
158
|
+
this.updateShapeMesh(new THREE.PlaneGeometry(canvas.width, canvas.height), texture);
|
|
159
|
+
|
|
160
|
+
// Position the cone at the start point (cone origin) in world coordinates
|
|
161
|
+
this.shapeMesh.position.set(this.startPoint.x, this.startPoint.y, 0);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
import type { DisplayProps } from '../../Stage/types';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
import type { GridLayerProps } from '../../GridLayer/types';
|
|
7
|
+
import { MeasurementType, type MeasurementLayerProps } from '../types';
|
|
8
|
+
import { drawCircle } from '../utils/canvasDrawing';
|
|
9
|
+
import { BaseMeasurement } from './BaseMeasurement';
|
|
10
|
+
|
|
11
|
+
export class LineMeasurement extends BaseMeasurement {
|
|
12
|
+
constructor(
|
|
13
|
+
startPoint: THREE.Vector2,
|
|
14
|
+
measurementProps: MeasurementLayerProps,
|
|
15
|
+
displayProps: DisplayProps,
|
|
16
|
+
gridProps: GridLayerProps
|
|
17
|
+
) {
|
|
18
|
+
super(MeasurementType.Line, startPoint, measurementProps, displayProps, gridProps);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
renderShape(): void {
|
|
22
|
+
// Create canvas for the line
|
|
23
|
+
const canvas = document.createElement('canvas');
|
|
24
|
+
const context = canvas.getContext('2d', { colorSpace: 'srgb' })!;
|
|
25
|
+
|
|
26
|
+
// Calculate the bounding box of the line
|
|
27
|
+
const minX = Math.min(this.startPoint.x, this.endPoint.x);
|
|
28
|
+
const maxX = Math.max(this.startPoint.x, this.endPoint.x);
|
|
29
|
+
const minY = Math.min(this.startPoint.y, this.endPoint.y);
|
|
30
|
+
const maxY = Math.max(this.startPoint.y, this.endPoint.y);
|
|
31
|
+
|
|
32
|
+
// Add padding for line thickness and circles at endpoints
|
|
33
|
+
const endpointRadius = (this.markerSize + this.outlineThickness) * 2;
|
|
34
|
+
const padding = Math.max(endpointRadius, 20);
|
|
35
|
+
const width = maxX - minX + padding * 2;
|
|
36
|
+
const height = maxY - minY + padding * 2;
|
|
37
|
+
|
|
38
|
+
canvas.width = width;
|
|
39
|
+
canvas.height = height;
|
|
40
|
+
|
|
41
|
+
// Clear canvas
|
|
42
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
43
|
+
|
|
44
|
+
// Transform coordinates: Three.js world space -> Canvas space
|
|
45
|
+
// Canvas origin is top-left, Three.js origin is center of the plane
|
|
46
|
+
const startX = this.startPoint.x - minX + padding;
|
|
47
|
+
const startY = canvas.height - (this.startPoint.y - minY + padding); // Invert Y
|
|
48
|
+
const endX = this.endPoint.x - minX + padding;
|
|
49
|
+
const endY = canvas.height - (this.endPoint.y - minY + padding); // Invert Y
|
|
50
|
+
|
|
51
|
+
// Draw the line with dashed pattern
|
|
52
|
+
// First draw the outline if needed
|
|
53
|
+
if (this.outlineThickness > 0) {
|
|
54
|
+
context.strokeStyle = this.outlineColor;
|
|
55
|
+
context.lineWidth = this.thickness + this.outlineThickness * 2;
|
|
56
|
+
context.lineCap = 'round';
|
|
57
|
+
context.lineJoin = 'round';
|
|
58
|
+
|
|
59
|
+
// Set dash pattern for outline
|
|
60
|
+
const dashLength = 20;
|
|
61
|
+
const gapLength = 10;
|
|
62
|
+
context.setLineDash([dashLength, gapLength]);
|
|
63
|
+
|
|
64
|
+
context.beginPath();
|
|
65
|
+
context.moveTo(startX, startY);
|
|
66
|
+
context.lineTo(endX, endY);
|
|
67
|
+
context.stroke();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Draw the main line with dashed pattern
|
|
71
|
+
context.strokeStyle = this.color;
|
|
72
|
+
context.lineWidth = this.thickness;
|
|
73
|
+
context.lineCap = 'round';
|
|
74
|
+
context.lineJoin = 'round';
|
|
75
|
+
|
|
76
|
+
// Set dash pattern - adjust based on line thickness for good visual proportion
|
|
77
|
+
const dashLength = 20;
|
|
78
|
+
const gapLength = 10;
|
|
79
|
+
context.setLineDash([dashLength, gapLength]);
|
|
80
|
+
|
|
81
|
+
context.beginPath();
|
|
82
|
+
context.moveTo(startX, startY);
|
|
83
|
+
context.lineTo(endX, endY);
|
|
84
|
+
context.stroke();
|
|
85
|
+
|
|
86
|
+
// Reset dash pattern for other elements
|
|
87
|
+
context.setLineDash([]);
|
|
88
|
+
|
|
89
|
+
// Start point circle
|
|
90
|
+
drawCircle(context, startX, startY, this.markerSize / 2, this.color, this.outlineColor, this.outlineThickness);
|
|
91
|
+
|
|
92
|
+
// End point circle
|
|
93
|
+
drawCircle(context, endX, endY, this.markerSize / 2, this.color, this.outlineColor, this.outlineThickness);
|
|
94
|
+
|
|
95
|
+
// Create texture from canvas
|
|
96
|
+
const texture = new THREE.CanvasTexture(canvas);
|
|
97
|
+
texture.needsUpdate = true;
|
|
98
|
+
|
|
99
|
+
this.updateShapeMesh(new THREE.PlaneGeometry(canvas.width, canvas.height), texture);
|
|
100
|
+
this.shapeMesh.position.set(minX + width / 2 - padding, minY + height / 2 - padding, 0);
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/lib/components/Stage/components/MeasurementLayer/measurements/RectangleMeasurement.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
import type { DisplayProps } from '../../Stage/types';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
import type { GridLayerProps } from '../../GridLayer/types';
|
|
7
|
+
import { MeasurementType, type MeasurementLayerProps } from '../types';
|
|
8
|
+
import { drawCircle } from '../utils/canvasDrawing';
|
|
9
|
+
import { BaseMeasurement } from './BaseMeasurement';
|
|
10
|
+
|
|
11
|
+
export class RectangleMeasurement extends BaseMeasurement {
|
|
12
|
+
constructor(
|
|
13
|
+
startPoint: THREE.Vector2,
|
|
14
|
+
measurementProps: MeasurementLayerProps,
|
|
15
|
+
displayProps: DisplayProps,
|
|
16
|
+
gridProps: GridLayerProps
|
|
17
|
+
) {
|
|
18
|
+
super(MeasurementType.Square, startPoint, measurementProps, displayProps, gridProps);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
renderShape(): void {
|
|
22
|
+
// Calculate the distance from center to mouse position
|
|
23
|
+
const distance = this.startPoint.distanceTo(this.endPoint);
|
|
24
|
+
|
|
25
|
+
// For a square, use the same distance for both width and height
|
|
26
|
+
// This creates a square where the distance from center to edge equals the distance to the mouse
|
|
27
|
+
const halfSize = distance;
|
|
28
|
+
const squareSize = halfSize * 2;
|
|
29
|
+
|
|
30
|
+
// Create canvas for the square
|
|
31
|
+
const canvas = document.createElement('canvas');
|
|
32
|
+
const context = canvas.getContext('2d', { colorSpace: 'srgb' })!;
|
|
33
|
+
|
|
34
|
+
// Add padding for outline and corner points
|
|
35
|
+
const padding = Math.max(this.markerSize + this.outlineThickness, 40);
|
|
36
|
+
const canvasSize = squareSize + padding * 2;
|
|
37
|
+
|
|
38
|
+
canvas.width = Math.max(canvasSize, 100);
|
|
39
|
+
canvas.height = Math.max(canvasSize, 100);
|
|
40
|
+
|
|
41
|
+
// Clear canvas
|
|
42
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
43
|
+
|
|
44
|
+
// Canvas center coordinates
|
|
45
|
+
const canvasCenterX = canvas.width / 2;
|
|
46
|
+
const canvasCenterY = canvas.height / 2;
|
|
47
|
+
|
|
48
|
+
// Calculate square position on canvas (centered)
|
|
49
|
+
const rectX = canvasCenterX - halfSize;
|
|
50
|
+
const rectY = canvasCenterY - halfSize;
|
|
51
|
+
|
|
52
|
+
// Draw square with dashed pattern
|
|
53
|
+
if (squareSize > 0) {
|
|
54
|
+
// First draw the fill
|
|
55
|
+
context.fillStyle = this.color;
|
|
56
|
+
context.globalAlpha = 0.2;
|
|
57
|
+
context.fillRect(rectX, rectY, squareSize, squareSize);
|
|
58
|
+
context.globalAlpha = 1.0;
|
|
59
|
+
|
|
60
|
+
// Draw the outline with dashed pattern if needed
|
|
61
|
+
if (this.outlineThickness > 0) {
|
|
62
|
+
context.strokeStyle = this.outlineColor;
|
|
63
|
+
context.lineWidth = this.thickness + this.outlineThickness * 2;
|
|
64
|
+
context.setLineDash([20, 10]); // Dashed pattern
|
|
65
|
+
context.strokeRect(rectX, rectY, squareSize, squareSize);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Draw the main stroke with dashed pattern
|
|
69
|
+
context.strokeStyle = this.color;
|
|
70
|
+
context.lineWidth = this.thickness;
|
|
71
|
+
context.setLineDash([20, 10]); // Dashed pattern
|
|
72
|
+
context.strokeRect(rectX, rectY, squareSize, squareSize);
|
|
73
|
+
|
|
74
|
+
// Reset dash pattern for other elements
|
|
75
|
+
context.setLineDash([]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Draw center point (like circle measurement)
|
|
79
|
+
drawCircle(
|
|
80
|
+
context,
|
|
81
|
+
canvasCenterX,
|
|
82
|
+
canvasCenterY,
|
|
83
|
+
this.markerSize / 2,
|
|
84
|
+
this.color,
|
|
85
|
+
this.outlineColor,
|
|
86
|
+
this.outlineThickness
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Draw corner points
|
|
90
|
+
const cornerRadius = this.markerSize / 2;
|
|
91
|
+
|
|
92
|
+
// Top-left corner
|
|
93
|
+
drawCircle(context, rectX, rectY, cornerRadius, this.color, this.outlineColor, this.outlineThickness);
|
|
94
|
+
|
|
95
|
+
// Top-right corner
|
|
96
|
+
drawCircle(context, rectX + squareSize, rectY, cornerRadius, this.color, this.outlineColor, this.outlineThickness);
|
|
97
|
+
|
|
98
|
+
// Bottom-right corner
|
|
99
|
+
drawCircle(
|
|
100
|
+
context,
|
|
101
|
+
rectX + squareSize,
|
|
102
|
+
rectY + squareSize,
|
|
103
|
+
cornerRadius,
|
|
104
|
+
this.color,
|
|
105
|
+
this.outlineColor,
|
|
106
|
+
this.outlineThickness
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Bottom-left corner
|
|
110
|
+
drawCircle(context, rectX, rectY + squareSize, cornerRadius, this.color, this.outlineColor, this.outlineThickness);
|
|
111
|
+
|
|
112
|
+
const texture = new THREE.CanvasTexture(canvas);
|
|
113
|
+
texture.needsUpdate = true;
|
|
114
|
+
|
|
115
|
+
this.updateShapeMesh(new THREE.PlaneGeometry(canvas.width, canvas.height), texture);
|
|
116
|
+
|
|
117
|
+
// Position the square at the center point (startPoint), like circle measurement
|
|
118
|
+
this.shapeMesh.position.set(this.startPoint.x, this.startPoint.y, 0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BaseMeasurement, type IMeasurement } from './BaseMeasurement';
|
|
2
|
+
export { LineMeasurement } from './LineMeasurement';
|
|
3
|
+
// TODO: Add other measurement types as they are implemented
|
|
4
|
+
// export { CircleMeasurement } from './CircleMeasurement';
|
|
5
|
+
// export { BeamMeasurement } from './BeamMeasurement';
|
|
6
|
+
// export { ConeMeasurement } from './ConeMeasurement';
|
|
7
|
+
// export { SquareMeasurement } from './SquareMeasurement';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
export enum MeasurementType {
|
|
4
|
+
Line = 1,
|
|
5
|
+
Beam = 2,
|
|
6
|
+
Cone = 3,
|
|
7
|
+
Circle = 4,
|
|
8
|
+
Square = 5
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Removed SnapType enum - using boolean instead
|
|
12
|
+
|
|
13
|
+
export interface Measurement {
|
|
14
|
+
id: string;
|
|
15
|
+
type: MeasurementType;
|
|
16
|
+
startPoint: THREE.Vector2;
|
|
17
|
+
endPoint: THREE.Vector2;
|
|
18
|
+
distance: number;
|
|
19
|
+
unit: string;
|
|
20
|
+
createdAt: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MeasurementLayerProps {
|
|
24
|
+
/**
|
|
25
|
+
* The type of measurement to display
|
|
26
|
+
*/
|
|
27
|
+
type: MeasurementType;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether to snap to grid
|
|
31
|
+
*/
|
|
32
|
+
snapToGrid: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Enable DMG 252 diagonal movement rules (only applies when snapping to square grid)
|
|
36
|
+
* First diagonal = 5ft, second = 10ft, alternating
|
|
37
|
+
*/
|
|
38
|
+
enableDMG252: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Auto-hide delay in milliseconds (default 3000ms)
|
|
42
|
+
*/
|
|
43
|
+
autoHideDelay: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Color of the measurement line
|
|
47
|
+
*/
|
|
48
|
+
color: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Thickness of the measurement line
|
|
52
|
+
*/
|
|
53
|
+
thickness: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Diameter of the measurement markers/points
|
|
57
|
+
*/
|
|
58
|
+
markerSize: number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Opacity of the measurement
|
|
62
|
+
*/
|
|
63
|
+
opacity: number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether to show distance text
|
|
67
|
+
*/
|
|
68
|
+
showDistance: boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Thickness of the text outline
|
|
72
|
+
*/
|
|
73
|
+
outlineThickness: number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Color of the text outline
|
|
77
|
+
*/
|
|
78
|
+
outlineColor: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Width of beam measurements in world grid units
|
|
82
|
+
*/
|
|
83
|
+
beamWidth: number;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Angle of cone measurements in degrees
|
|
87
|
+
*/
|
|
88
|
+
coneAngle: number;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Fadeout animation duration in milliseconds (default 500ms)
|
|
92
|
+
*/
|
|
93
|
+
fadeoutTime: number;
|
|
94
|
+
}
|