@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,171 @@
|
|
|
1
|
+
import { LazyBrush } from 'lazy-brush';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
|
|
4
|
+
export interface LazyBrushConfig {
|
|
5
|
+
radius?: number;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
friction?: number;
|
|
8
|
+
initialPoint?: { x: number; y: number };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class LazyBrushManager {
|
|
12
|
+
private lazyBrush: LazyBrush;
|
|
13
|
+
private isEnabled: boolean;
|
|
14
|
+
private friction: number;
|
|
15
|
+
private hasStarted: boolean = false;
|
|
16
|
+
private currentStrokePoints: THREE.Vector2[] = [];
|
|
17
|
+
|
|
18
|
+
constructor(config: LazyBrushConfig = {}) {
|
|
19
|
+
this.lazyBrush = new LazyBrush({
|
|
20
|
+
radius: config.radius ?? 15, // Default radius for smoothing
|
|
21
|
+
enabled: config.enabled ?? true,
|
|
22
|
+
initialPoint: config.initialPoint ?? { x: 0, y: 0 }
|
|
23
|
+
});
|
|
24
|
+
this.isEnabled = config.enabled ?? true;
|
|
25
|
+
this.friction = config.friction ?? 0.5; // Default friction for moderate smoothing
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Updates the lazy brush configuration
|
|
30
|
+
*/
|
|
31
|
+
updateConfig(config: Partial<LazyBrushConfig>) {
|
|
32
|
+
if (config.radius !== undefined) {
|
|
33
|
+
this.lazyBrush.setRadius(config.radius);
|
|
34
|
+
}
|
|
35
|
+
if (config.enabled !== undefined) {
|
|
36
|
+
this.isEnabled = config.enabled;
|
|
37
|
+
// LazyBrush doesn't have an enable property, we'll handle it internally
|
|
38
|
+
}
|
|
39
|
+
if (config.friction !== undefined) {
|
|
40
|
+
this.friction = config.friction;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Starts a new stroke
|
|
46
|
+
*/
|
|
47
|
+
startStroke(point: THREE.Vector2) {
|
|
48
|
+
this.hasStarted = true;
|
|
49
|
+
this.currentStrokePoints = [];
|
|
50
|
+
|
|
51
|
+
if (this.isEnabled) {
|
|
52
|
+
// Update lazy brush with the starting point - force both pointer and brush to the same position
|
|
53
|
+
this.lazyBrush.update({ x: point.x, y: point.y }, { both: true });
|
|
54
|
+
this.currentStrokePoints.push(point.clone());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Updates the current stroke with a new point
|
|
60
|
+
* Returns an array of interpolated points to draw
|
|
61
|
+
*/
|
|
62
|
+
updateStroke(point: THREE.Vector2): THREE.Vector2[] {
|
|
63
|
+
if (!this.hasStarted) {
|
|
64
|
+
this.startStroke(point);
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!this.isEnabled) {
|
|
69
|
+
// If lazy brush is disabled, just return the direct line
|
|
70
|
+
const lastPoint = this.currentStrokePoints[this.currentStrokePoints.length - 1] || point;
|
|
71
|
+
this.currentStrokePoints.push(point.clone());
|
|
72
|
+
return [lastPoint, point];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Update the lazy brush with the new pointer position
|
|
76
|
+
this.lazyBrush.update({ x: point.x, y: point.y }, { friction: this.friction });
|
|
77
|
+
|
|
78
|
+
// Get the brush position (this is the smoothed position)
|
|
79
|
+
const brushPoint = this.lazyBrush.getBrushCoordinates();
|
|
80
|
+
|
|
81
|
+
// Check if the brush has moved enough to add a new point
|
|
82
|
+
if (this.lazyBrush.brushHasMoved()) {
|
|
83
|
+
const smoothedPoint = new THREE.Vector2(brushPoint.x, brushPoint.y);
|
|
84
|
+
|
|
85
|
+
// Get the last point we drew
|
|
86
|
+
const lastPoint = this.currentStrokePoints[this.currentStrokePoints.length - 1];
|
|
87
|
+
|
|
88
|
+
// Add the new smoothed point to our stroke
|
|
89
|
+
this.currentStrokePoints.push(smoothedPoint.clone());
|
|
90
|
+
|
|
91
|
+
// Removed console logging for performance
|
|
92
|
+
|
|
93
|
+
// Return the segment to draw
|
|
94
|
+
if (lastPoint) {
|
|
95
|
+
return [lastPoint, smoothedPoint];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Ends the current stroke
|
|
104
|
+
*/
|
|
105
|
+
endStroke() {
|
|
106
|
+
this.hasStarted = false;
|
|
107
|
+
this.currentStrokePoints = [];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Gets the current lazy pointer position
|
|
112
|
+
*/
|
|
113
|
+
getLazyPosition(): THREE.Vector2 | null {
|
|
114
|
+
if (!this.isEnabled || !this.hasStarted) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const lazyCoords = this.lazyBrush.getPointerCoordinates();
|
|
119
|
+
return new THREE.Vector2(lazyCoords.x, lazyCoords.y);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Gets the current brush position (smoothed)
|
|
124
|
+
*/
|
|
125
|
+
getBrushPosition(): THREE.Vector2 | null {
|
|
126
|
+
if (!this.isEnabled || !this.hasStarted) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const brushCoords = this.lazyBrush.getBrushCoordinates();
|
|
131
|
+
return new THREE.Vector2(brushCoords.x, brushCoords.y);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Resets the lazy brush
|
|
136
|
+
*/
|
|
137
|
+
reset() {
|
|
138
|
+
this.hasStarted = false;
|
|
139
|
+
this.currentStrokePoints = [];
|
|
140
|
+
this.lazyBrush.update({ x: 0, y: 0 }, { both: true });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns whether lazy brush is enabled
|
|
145
|
+
*/
|
|
146
|
+
get enabled(): boolean {
|
|
147
|
+
return this.isEnabled;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sets whether lazy brush is enabled
|
|
152
|
+
*/
|
|
153
|
+
set enabled(value: boolean) {
|
|
154
|
+
this.isEnabled = value;
|
|
155
|
+
// LazyBrush doesn't have an enable property, we'll handle it internally
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Gets the lazy radius
|
|
160
|
+
*/
|
|
161
|
+
get radius(): number {
|
|
162
|
+
return this.lazyBrush.radius;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Sets the lazy radius
|
|
167
|
+
*/
|
|
168
|
+
set radius(value: number) {
|
|
169
|
+
this.lazyBrush.setRadius(value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
export interface PerformanceMetrics {
|
|
4
|
+
frameTime: number;
|
|
5
|
+
fps: number;
|
|
6
|
+
drawCalls: number;
|
|
7
|
+
triangles: number;
|
|
8
|
+
textures: number;
|
|
9
|
+
geometries: number;
|
|
10
|
+
composerTime: number;
|
|
11
|
+
overlayTime: number;
|
|
12
|
+
weatherTime: number;
|
|
13
|
+
totalRenderTime: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PerformanceHistory {
|
|
17
|
+
timestamps: number[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const HISTORY_SIZE = 120; // Store last 120 frames (~2 seconds at 60fps)
|
|
21
|
+
|
|
22
|
+
// Performance metrics state
|
|
23
|
+
export const performanceMetrics: { value: PerformanceMetrics } = $state({
|
|
24
|
+
value: {
|
|
25
|
+
frameTime: 0,
|
|
26
|
+
fps: 0,
|
|
27
|
+
drawCalls: 0,
|
|
28
|
+
triangles: 0,
|
|
29
|
+
textures: 0,
|
|
30
|
+
geometries: 0,
|
|
31
|
+
composerTime: 0,
|
|
32
|
+
overlayTime: 0,
|
|
33
|
+
weatherTime: 0,
|
|
34
|
+
totalRenderTime: 0
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Historical data for graphing - just timestamps, calculate frame times from deltas
|
|
39
|
+
export const performanceHistory: { value: PerformanceHistory } = $state({
|
|
40
|
+
value: {
|
|
41
|
+
timestamps: []
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Timing helpers
|
|
46
|
+
let lastLogTime = 0;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Start timing a render pass
|
|
50
|
+
*/
|
|
51
|
+
export const startTiming = (): number => {
|
|
52
|
+
return performance.now();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* End timing a render pass and return elapsed time in ms
|
|
57
|
+
*/
|
|
58
|
+
export const endTiming = (startTime: number): number => {
|
|
59
|
+
return performance.now() - startTime;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Update metrics at the start of each frame
|
|
64
|
+
*/
|
|
65
|
+
export const beginFrame = (): number => {
|
|
66
|
+
return performance.now();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Update metrics at the end of each frame
|
|
71
|
+
*/
|
|
72
|
+
export const endFrame = (
|
|
73
|
+
_frameStartTime: number,
|
|
74
|
+
renderer: THREE.WebGLRenderer,
|
|
75
|
+
timings: {
|
|
76
|
+
composerTime: number;
|
|
77
|
+
overlayTime: number;
|
|
78
|
+
weatherTime?: number;
|
|
79
|
+
}
|
|
80
|
+
): void => {
|
|
81
|
+
const now = performance.now();
|
|
82
|
+
|
|
83
|
+
// Add timestamp to history
|
|
84
|
+
const history = performanceHistory.value;
|
|
85
|
+
history.timestamps.push(now);
|
|
86
|
+
|
|
87
|
+
// Trim history to size limit
|
|
88
|
+
while (history.timestamps.length > HISTORY_SIZE) {
|
|
89
|
+
history.timestamps.shift();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Calculate FPS from timestamps (frames / time elapsed)
|
|
93
|
+
// Use recent window for current FPS
|
|
94
|
+
const timestamps = history.timestamps;
|
|
95
|
+
let fps = 0;
|
|
96
|
+
let frameTime = 0;
|
|
97
|
+
|
|
98
|
+
if (timestamps.length >= 2) {
|
|
99
|
+
// Use last 30 frames or all available for FPS calculation
|
|
100
|
+
const sampleSize = Math.min(30, timestamps.length);
|
|
101
|
+
const oldestIdx = timestamps.length - sampleSize;
|
|
102
|
+
const elapsed = now - timestamps[oldestIdx];
|
|
103
|
+
|
|
104
|
+
if (elapsed > 0) {
|
|
105
|
+
fps = ((sampleSize - 1) / elapsed) * 1000;
|
|
106
|
+
frameTime = elapsed / (sampleSize - 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Update metrics
|
|
111
|
+
const info = renderer.info;
|
|
112
|
+
|
|
113
|
+
performanceMetrics.value = {
|
|
114
|
+
frameTime,
|
|
115
|
+
fps,
|
|
116
|
+
drawCalls: info.render.calls,
|
|
117
|
+
triangles: info.render.triangles,
|
|
118
|
+
textures: info.memory.textures,
|
|
119
|
+
geometries: info.memory.geometries,
|
|
120
|
+
composerTime: timings.composerTime,
|
|
121
|
+
overlayTime: timings.overlayTime,
|
|
122
|
+
weatherTime: timings.weatherTime ?? 0,
|
|
123
|
+
totalRenderTime: timings.composerTime + timings.overlayTime + (timings.weatherTime ?? 0)
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
performanceHistory.value = { ...history };
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Log metrics to console at specified rate
|
|
131
|
+
*/
|
|
132
|
+
export const logMetrics = (rate: number): void => {
|
|
133
|
+
const now = performance.now();
|
|
134
|
+
|
|
135
|
+
if (now - lastLogTime < rate) return;
|
|
136
|
+
|
|
137
|
+
const m = performanceMetrics.value;
|
|
138
|
+
console.log(
|
|
139
|
+
`[Perf] FPS: ${m.fps.toFixed(1)} | Frame: ${m.frameTime.toFixed(2)}ms | ` +
|
|
140
|
+
`Draw calls: ${m.drawCalls} | Triangles: ${m.triangles} | ` +
|
|
141
|
+
`Textures: ${m.textures} | Geometries: ${m.geometries} | ` +
|
|
142
|
+
`Composer: ${m.composerTime.toFixed(2)}ms | Overlay: ${m.overlayTime.toFixed(2)}ms`
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
lastLogTime = now;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get average FPS over the entire history window
|
|
150
|
+
*/
|
|
151
|
+
export const getAverageFps = (): number => {
|
|
152
|
+
const timestamps = performanceHistory.value.timestamps;
|
|
153
|
+
if (timestamps.length < 2) return 0;
|
|
154
|
+
|
|
155
|
+
const elapsed = timestamps[timestamps.length - 1] - timestamps[0];
|
|
156
|
+
if (elapsed <= 0) return 0;
|
|
157
|
+
|
|
158
|
+
return ((timestamps.length - 1) / elapsed) * 1000;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get the 1% low FPS (slowest 1% of frames)
|
|
163
|
+
*/
|
|
164
|
+
export const get1PercentLowFps = (): number => {
|
|
165
|
+
const timestamps = performanceHistory.value.timestamps;
|
|
166
|
+
if (timestamps.length < 10) return 0;
|
|
167
|
+
|
|
168
|
+
// Calculate frame times from timestamp deltas
|
|
169
|
+
const frameTimes: number[] = [];
|
|
170
|
+
for (let i = 1; i < timestamps.length; i++) {
|
|
171
|
+
frameTimes.push(timestamps[i] - timestamps[i - 1]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Sort descending (longest frame times first)
|
|
175
|
+
frameTimes.sort((a, b) => b - a);
|
|
176
|
+
|
|
177
|
+
// Get 99th percentile (1% slowest)
|
|
178
|
+
const p99Index = Math.max(0, Math.floor(frameTimes.length * 0.01));
|
|
179
|
+
const p99FrameTime = frameTimes[p99Index];
|
|
180
|
+
|
|
181
|
+
return p99FrameTime > 0 ? 1000 / p99FrameTime : 0;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get frame times calculated from timestamps (for graphing)
|
|
186
|
+
*/
|
|
187
|
+
export const getFrameTimes = (): number[] => {
|
|
188
|
+
const timestamps = performanceHistory.value.timestamps;
|
|
189
|
+
if (timestamps.length < 2) return [];
|
|
190
|
+
|
|
191
|
+
const frameTimes: number[] = [];
|
|
192
|
+
for (let i = 1; i < timestamps.length; i++) {
|
|
193
|
+
frameTimes.push(timestamps[i] - timestamps[i - 1]);
|
|
194
|
+
}
|
|
195
|
+
return frameTimes;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Reset all metrics and history
|
|
200
|
+
*/
|
|
201
|
+
export const resetMetrics = (): void => {
|
|
202
|
+
performanceMetrics.value = {
|
|
203
|
+
frameTime: 0,
|
|
204
|
+
fps: 0,
|
|
205
|
+
drawCalls: 0,
|
|
206
|
+
triangles: 0,
|
|
207
|
+
textures: 0,
|
|
208
|
+
geometries: 0,
|
|
209
|
+
composerTime: 0,
|
|
210
|
+
overlayTime: 0,
|
|
211
|
+
weatherTime: 0,
|
|
212
|
+
totalRenderTime: 0
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
performanceHistory.value = {
|
|
216
|
+
timestamps: []
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
lastLogTime = 0;
|
|
220
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
export function textureToBase64(texture: THREE.DataTexture): string {
|
|
4
|
+
if (!texture.image.data) {
|
|
5
|
+
throw new Error('Texture image data is null');
|
|
6
|
+
}
|
|
7
|
+
return texture.image.data.toString();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function base64ToTexture(base64: string) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const image = new Image();
|
|
13
|
+
image.src = base64;
|
|
14
|
+
|
|
15
|
+
image.onload = () => {
|
|
16
|
+
const texture = new THREE.Texture(image);
|
|
17
|
+
texture.needsUpdate = true; // Update the texture with the loaded image
|
|
18
|
+
resolve(texture);
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export { type HoveredMarker } from '../../types/awareness';
|
|
2
|
+
export {
|
|
3
|
+
AnnotationEffect,
|
|
4
|
+
AnnotationEffectDefaults,
|
|
5
|
+
getDefaultEffectProps,
|
|
6
|
+
type AnnotationEffectProps,
|
|
7
|
+
type AnnotationLayerData,
|
|
8
|
+
type AnnotationsLayerProps
|
|
9
|
+
} from './components/AnnotationLayer/types';
|
|
10
|
+
export { DrawMode, RenderMode, ToolType } from './components/DrawingLayer/types';
|
|
11
|
+
export { type EdgeOverlayProps } from './components/EdgeOverlayLayer/types';
|
|
12
|
+
export { type FogLayerProps } from './components/FogLayer/types';
|
|
13
|
+
export { type FogOfWarLayerProps } from './components/FogOfWarLayer/types';
|
|
14
|
+
export { GridMode, GridType, type GridLayerProps } from './components/GridLayer/types';
|
|
15
|
+
export { MapLayerType, type MapLayerProps } from './components/MapLayer/types';
|
|
16
|
+
export {
|
|
17
|
+
MarkerShape,
|
|
18
|
+
MarkerSize,
|
|
19
|
+
MarkerVisibility,
|
|
20
|
+
type Marker,
|
|
21
|
+
type MarkerLayerExports,
|
|
22
|
+
type MarkerLayerProps
|
|
23
|
+
} from './components/MarkerLayer/types';
|
|
24
|
+
export { MeasurementType, type MeasurementLayerProps } from './components/MeasurementLayer/types';
|
|
25
|
+
export { ParticleType, type ParticleSystemProps } from './components/ParticleSystem/types';
|
|
26
|
+
export { default as PerformanceDebugger } from './components/PerformanceDebugger/PerformanceDebugger.svelte';
|
|
27
|
+
export { default as PerformanceOverlay } from './components/PerformanceOverlay/PerformanceOverlay.svelte';
|
|
28
|
+
export { default as PointerInputManager } from './components/PointerInputManager/PointerInputManager.svelte';
|
|
29
|
+
export { SceneRotation, type PostProcessingProps, type SceneLayerProps } from './components/Scene/types';
|
|
30
|
+
export { default as Stage } from './components/Stage/Stage.svelte';
|
|
31
|
+
export * from './components/Stage/types';
|
|
32
|
+
export { AshPreset, LeavesPreset, RainPreset, SnowPreset } from './components/WeatherLayer/presets';
|
|
33
|
+
export {
|
|
34
|
+
WeatherType,
|
|
35
|
+
type DepthOfFieldConfig,
|
|
36
|
+
type WeatherLayerPreset,
|
|
37
|
+
type WeatherLayerProps
|
|
38
|
+
} from './components/WeatherLayer/types';
|
|
39
|
+
export { debugState, isDebugEnabled, setDebugEnabled } from './helpers/debugState.svelte';
|
|
40
|
+
export {
|
|
41
|
+
get1PercentLowFps,
|
|
42
|
+
getAverageFps,
|
|
43
|
+
getFrameTimes,
|
|
44
|
+
performanceHistory,
|
|
45
|
+
performanceMetrics,
|
|
46
|
+
resetMetrics,
|
|
47
|
+
type PerformanceHistory,
|
|
48
|
+
type PerformanceMetrics
|
|
49
|
+
} from './helpers/performanceMetrics.svelte';
|