laymur 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +2 -2
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +1 -1
  3. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +6 -6
  4. package/dist/core/constraints/UIConstraint.d.ts +1 -0
  5. package/dist/core/constraints/UIConstraint.js +4 -0
  6. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +1 -1
  7. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +5 -5
  8. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +2 -2
  9. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +14 -14
  10. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +3 -3
  11. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +20 -20
  12. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +2 -2
  13. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +5 -5
  14. package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +1 -0
  15. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +2 -2
  16. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +14 -14
  17. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +3 -3
  18. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +20 -20
  19. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +2 -2
  20. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +5 -5
  21. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +1 -1
  22. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +5 -5
  23. package/dist/core/layers/UILayer/UILayer.d.ts +18 -0
  24. package/dist/core/layers/UILayer/UILayer.js +48 -0
  25. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +4 -2
  26. package/dist/core/miscellaneous/generic-plane/shared.d.ts +1 -1
  27. package/dist/core/miscellaneous/generic-plane/shared.js +3 -1
  28. package/dist/core/miscellaneous/shared.d.ts +8 -0
  29. package/dist/debug/UIAspectDebug.d.ts +26 -0
  30. package/dist/debug/UIAspectDebug.js +118 -0
  31. package/dist/debug/UIConstraintDebug.d.ts +7 -0
  32. package/dist/debug/UIHeightDebug.d.ts +26 -0
  33. package/dist/debug/UIHeightDebug.js +111 -0
  34. package/dist/debug/UIHorizontalDistanceDebug.d.ts +29 -0
  35. package/dist/debug/UIHorizontalDistanceDebug.js +158 -0
  36. package/dist/debug/UIHorizontalInterpolationDebug.d.ts +29 -0
  37. package/dist/debug/UIHorizontalInterpolationDebug.js +145 -0
  38. package/dist/debug/UILayerDebug.d.ts +34 -0
  39. package/dist/debug/UILayerDebug.js +124 -0
  40. package/dist/debug/UIVerticalDistanceDebug.d.ts +29 -0
  41. package/dist/debug/UIVerticalDistanceDebug.js +158 -0
  42. package/dist/debug/UIVerticalInterpolationDebug.d.ts +29 -0
  43. package/dist/debug/UIVerticalInterpolationDebug.js +145 -0
  44. package/dist/debug/UIWidthDebug.d.ts +26 -0
  45. package/dist/debug/UIWidthDebug.js +111 -0
  46. package/dist/debug/index.d.ts +8 -0
  47. package/dist/debug/index.js +8 -0
  48. package/dist/debug/miscellaneous.d.ts +8 -0
  49. package/dist/debug/miscellaneous.js +11 -0
  50. package/dist/node_modules/three/examples/jsm/lines/Line2.js +56 -0
  51. package/dist/node_modules/three/examples/jsm/lines/LineGeometry.js +157 -0
  52. package/dist/node_modules/three/examples/jsm/lines/LineMaterial.js +691 -0
  53. package/dist/node_modules/three/examples/jsm/lines/LineSegments2.js +415 -0
  54. package/dist/node_modules/three/examples/jsm/lines/LineSegmentsGeometry.js +289 -0
  55. package/package.json +5 -1
@@ -0,0 +1,145 @@
1
+ import { Object3D, Vector3, CanvasTexture, SpriteMaterial, Sprite } from 'three';
2
+ import { Line2 } from '../node_modules/three/examples/jsm/lines/Line2.js';
3
+ import { LineGeometry } from '../node_modules/three/examples/jsm/lines/LineGeometry.js';
4
+ import { LineMaterial } from '../node_modules/three/examples/jsm/lines/LineMaterial.js';
5
+ import { isUIPlaneElement } from '../core/miscellaneous/shared.js';
6
+ import { DEBUG_LINE_WIDTH, debugResolutionVector, DEBUG_RENDER_ORDER, DEBUG_BADGE_SIZE, DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_FONT_FAMILY } from './miscellaneous.js';
7
+ import { UIColor } from '../core/miscellaneous/color/UIColor.js';
8
+ import { UIOrientation } from '../core/miscellaneous/UIOrientation.js';
9
+
10
+ class UIHorizontalInterpolationDebug {
11
+ constructor(constraint) {
12
+ this.constraint = constraint;
13
+ this.tint = new UIColor("cyan");
14
+ this._private_container = new Object3D();
15
+ this._private_baseLineMaterial = new LineMaterial({
16
+ linewidth: DEBUG_LINE_WIDTH,
17
+ transparent: true,
18
+ depthTest: false,
19
+ depthWrite: false,
20
+ });
21
+ this._private_baseLineGeometry = new LineGeometry();
22
+ this._private_baseLine = new Line2(this._private_baseLineGeometry, this._private_baseLineMaterial);
23
+ this._private_markerMaterial = new LineMaterial({
24
+ linewidth: DEBUG_LINE_WIDTH,
25
+ transparent: true,
26
+ depthTest: false,
27
+ depthWrite: false,
28
+ });
29
+ this._private_markerGeometry = new LineGeometry();
30
+ this._private_markerLine = new Line2(this._private_markerGeometry, this._private_markerMaterial);
31
+ this._private_visibleInternal = true;
32
+ this._private_lastRenderedText = "";
33
+ this._private_onOrientationChanged = () => {
34
+ this._private_updateContainerVisibility();
35
+ };
36
+ this._private_onRendering = (renderer) => {
37
+ const tintDirty = this.tint.dirty;
38
+ if (tintDirty) {
39
+ this.tint.toThreeColor(this._private_baseLineMaterial.color);
40
+ this._private_baseLineMaterial.opacity = this.tint.a;
41
+ this.tint.toThreeColor(this._private_markerMaterial.color);
42
+ this._private_markerMaterial.opacity = this.tint.a;
43
+ this._private_spriteMaterial.opacity = this.tint.a;
44
+ this.tint.setDirtyFalse();
45
+ }
46
+ renderer.getDrawingBufferSize(debugResolutionVector);
47
+ this._private_baseLineMaterial.resolution.copy(debugResolutionVector);
48
+ this._private_markerMaterial.resolution.copy(debugResolutionVector);
49
+ const elementA = this.constraint.a;
50
+ const elementB = this.constraint.b;
51
+ const elementC = this.constraint.c;
52
+ const anchorAX = isUIPlaneElement(elementA)
53
+ ? elementA.x + elementA.width * this.constraint.anchorA
54
+ : elementA.x;
55
+ const anchorAY = isUIPlaneElement(elementA) ? elementA.centerY : elementA.y;
56
+ const anchorBX = isUIPlaneElement(elementB)
57
+ ? elementB.x + elementB.width * this.constraint.anchorB
58
+ : elementB.x;
59
+ const anchorBY = isUIPlaneElement(elementB) ? elementB.centerY : elementB.y;
60
+ const anchorCX = isUIPlaneElement(elementC)
61
+ ? elementC.x + elementC.width * this.constraint.anchorC
62
+ : elementC.x;
63
+ const midY = (anchorAY + anchorBY) / 2;
64
+ this._private_baseLineGeometry.setFromPoints([
65
+ new Vector3(anchorAX, midY, 0),
66
+ new Vector3(anchorBX, midY, 0),
67
+ ]);
68
+ const markerSize = 12;
69
+ this._private_markerGeometry.setFromPoints([
70
+ new Vector3(anchorCX, midY - markerSize, 0),
71
+ new Vector3(anchorCX, midY + markerSize, 0),
72
+ ]);
73
+ const nextText = "hi: " + this.constraint.t.toFixed(2);
74
+ if (nextText !== this._private_lastRenderedText || tintDirty) {
75
+ this._private_drawText(nextText);
76
+ this._private_textTexture.needsUpdate = true;
77
+ this._private_lastRenderedText = nextText;
78
+ }
79
+ this._private_textSprite.position.set(anchorCX, midY + 20, 0);
80
+ };
81
+ this._private_baseLine.renderOrder = DEBUG_RENDER_ORDER;
82
+ this._private_markerLine.renderOrder = DEBUG_RENDER_ORDER;
83
+ this._private_container.add(this._private_baseLine);
84
+ this._private_container.add(this._private_markerLine);
85
+ const canvas = document.createElement("canvas");
86
+ canvas.width = 256;
87
+ canvas.height = 64;
88
+ const context = canvas.getContext("2d");
89
+ if (context === null) {
90
+ throw new Error("Failed to get 2D context for debug text");
91
+ }
92
+ this._private_canvas = canvas;
93
+ this._private_context = context;
94
+ this._private_drawText("");
95
+ this._private_textTexture = new CanvasTexture(canvas);
96
+ this._private_spriteMaterial = new SpriteMaterial({
97
+ map: this._private_textTexture,
98
+ transparent: true,
99
+ depthTest: false,
100
+ depthWrite: false,
101
+ });
102
+ this._private_textSprite = new Sprite(this._private_spriteMaterial);
103
+ this._private_textSprite.renderOrder = DEBUG_RENDER_ORDER;
104
+ this._private_textSprite.scale.set(DEBUG_BADGE_SIZE, DEBUG_BADGE_SIZE * 0.25, 1);
105
+ this._private_container.add(this._private_textSprite);
106
+ this.constraint.layer.signalRendering.on(this._private_onRendering);
107
+ this.constraint.layer.signalOrientationChanged.on(this._private_onOrientationChanged);
108
+ this.constraint.layer.sceneWrapper.insertCustomObject(this._private_container);
109
+ this._private_updateContainerVisibility();
110
+ }
111
+ get visible() {
112
+ return this._private_visibleInternal;
113
+ }
114
+ set visible(value) {
115
+ if (value !== this._private_visibleInternal) {
116
+ this._private_visibleInternal = value;
117
+ this._private_updateContainerVisibility();
118
+ }
119
+ }
120
+ destroy() {
121
+ this.constraint.layer.signalRendering.off(this._private_onRendering);
122
+ this.constraint.layer.signalOrientationChanged.off(this._private_onOrientationChanged);
123
+ this.constraint.layer.sceneWrapper.removeCustomObject(this._private_container);
124
+ this._private_baseLineGeometry.dispose();
125
+ this._private_markerGeometry.dispose();
126
+ this._private_textTexture.dispose();
127
+ }
128
+ _private_updateContainerVisibility() {
129
+ const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
130
+ this.constraint.orientation === this.constraint.layer.orientation;
131
+ this._private_container.visible = this._private_visibleInternal && orientationActive;
132
+ }
133
+ _private_drawText(text) {
134
+ this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
135
+ this._private_context.fillStyle = DEBUG_BADGE_BACKGROUND_COLOR;
136
+ this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
137
+ this._private_context.fillStyle = this.tint.getHexStringRGB();
138
+ this._private_context.font = `${DEBUG_BADGE_FONT_SIZE}px ${DEBUG_BADGE_FONT_FAMILY}`;
139
+ this._private_context.textAlign = "center";
140
+ this._private_context.textBaseline = "middle";
141
+ this._private_context.fillText(text, this._private_canvas.width / 2, this._private_canvas.height / 2);
142
+ }
143
+ }
144
+
145
+ export { UIHorizontalInterpolationDebug };
@@ -0,0 +1,34 @@
1
+ import { type UILayer } from "../core";
2
+ export interface UILayerDebugOptions {
3
+ showAspect: boolean;
4
+ showHeight: boolean;
5
+ showWidth: boolean;
6
+ showHorizontalDistance: boolean;
7
+ showHorizontalInterpolation: boolean;
8
+ showVerticalDistance: boolean;
9
+ showVerticalInterpolation: boolean;
10
+ }
11
+ export declare class UILayerDebug {
12
+ layer: UILayer;
13
+ private readonly debug;
14
+ private showAspectInternal;
15
+ private showHeightInternal;
16
+ private showWidthInternal;
17
+ private showHorizontalDistanceInternal;
18
+ private showHorizontalInterpolationInternal;
19
+ private showVerticalDistanceInternal;
20
+ private showVerticalInterpolationInternal;
21
+ constructor(layer: UILayer, options?: Partial<UILayerDebugOptions>);
22
+ set showAspect(value: boolean);
23
+ set showHeight(value: boolean);
24
+ set showWidth(value: boolean);
25
+ set showHorizontalDistance(value: boolean);
26
+ set showHorizontalInterpolation(value: boolean);
27
+ set showVerticalDistance(value: boolean);
28
+ set showVerticalInterpolation(value: boolean);
29
+ destroy(): void;
30
+ private addDebug;
31
+ private setVisibility;
32
+ private readonly onConstraintAdded;
33
+ private readonly onConstraintRemoved;
34
+ }
@@ -0,0 +1,124 @@
1
+ import { UIAspectDebug } from './UIAspectDebug.js';
2
+ import { UIHeightDebug } from './UIHeightDebug.js';
3
+ import { UIHorizontalDistanceDebug } from './UIHorizontalDistanceDebug.js';
4
+ import { UIHorizontalInterpolationDebug } from './UIHorizontalInterpolationDebug.js';
5
+ import { UIVerticalDistanceDebug } from './UIVerticalDistanceDebug.js';
6
+ import { UIVerticalInterpolationDebug } from './UIVerticalInterpolationDebug.js';
7
+ import { UIWidthDebug } from './UIWidthDebug.js';
8
+ import { UIAspectConstraint } from '../core/constraints/UIAspectConstraint/UIAspectConstraint.js';
9
+ import { UIHeightConstraint } from '../core/constraints/UIHeightConstraint/UIHeightConstraint.js';
10
+ import { UIWidthConstraint } from '../core/constraints/UIWidthConstraint/UIWidthConstraint.js';
11
+ import { UIHorizontalDistanceConstraint } from '../core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js';
12
+ import { UIHorizontalInterpolationConstraint } from '../core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js';
13
+ import { UIVerticalDistanceConstraint } from '../core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js';
14
+ import { UIVerticalInterpolationConstraint } from '../core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js';
15
+
16
+ class UILayerDebug {
17
+ constructor(layer, options) {
18
+ this.layer = layer;
19
+ this._private_debug = [];
20
+ this._private_onConstraintAdded = (layer, constraint) => {
21
+ this._private_addDebug(constraint);
22
+ };
23
+ this._private_onConstraintRemoved = (layer, constraint) => {
24
+ const index = this._private_debug.findIndex((d) => d.constraint === constraint);
25
+ if (index !== -1) {
26
+ this._private_debug[index].destroy();
27
+ this._private_debug.splice(index, 1);
28
+ }
29
+ };
30
+ this._private_showAspectInternal = options?.showAspect ?? true;
31
+ this._private_showHeightInternal = options?.showHeight ?? true;
32
+ this._private_showWidthInternal = options?.showWidth ?? true;
33
+ this._private_showHorizontalDistanceInternal = options?.showHorizontalDistance ?? true;
34
+ this._private_showHorizontalInterpolationInternal = options?.showHorizontalInterpolation ?? true;
35
+ this._private_showVerticalDistanceInternal = options?.showVerticalDistance ?? true;
36
+ this._private_showVerticalInterpolationInternal = options?.showVerticalInterpolation ?? true;
37
+ for (const constraint of this.layer.constraintRegistry) {
38
+ this._private_addDebug(constraint);
39
+ }
40
+ this.layer.signalConstraintAdded.on(this._private_onConstraintAdded);
41
+ this.layer.signalConstraintRemoved.on(this._private_onConstraintRemoved);
42
+ }
43
+ set showAspect(value) {
44
+ this._private_showAspectInternal = value;
45
+ this._private_setVisibility(UIAspectConstraint, value);
46
+ }
47
+ set showHeight(value) {
48
+ this._private_showHeightInternal = value;
49
+ this._private_setVisibility(UIHeightConstraint, value);
50
+ }
51
+ set showWidth(value) {
52
+ this._private_showWidthInternal = value;
53
+ this._private_setVisibility(UIWidthConstraint, value);
54
+ }
55
+ set showHorizontalDistance(value) {
56
+ this._private_showHorizontalDistanceInternal = value;
57
+ this._private_setVisibility(UIHorizontalDistanceConstraint, value);
58
+ }
59
+ set showHorizontalInterpolation(value) {
60
+ this._private_showHorizontalInterpolationInternal = value;
61
+ this._private_setVisibility(UIHorizontalInterpolationConstraint, value);
62
+ }
63
+ set showVerticalDistance(value) {
64
+ this._private_showVerticalDistanceInternal = value;
65
+ this._private_setVisibility(UIVerticalDistanceConstraint, value);
66
+ }
67
+ set showVerticalInterpolation(value) {
68
+ this._private_showVerticalInterpolationInternal = value;
69
+ this._private_setVisibility(UIVerticalInterpolationConstraint, value);
70
+ }
71
+ destroy() {
72
+ this.layer.signalConstraintAdded.off(this._private_onConstraintAdded);
73
+ this.layer.signalConstraintRemoved.off(this._private_onConstraintRemoved);
74
+ for (const debug of this._private_debug) {
75
+ debug.destroy();
76
+ }
77
+ this._private_debug.length = 0;
78
+ }
79
+ _private_addDebug(constraint) {
80
+ let debug = null;
81
+ if (constraint instanceof UIAspectConstraint) {
82
+ debug = new UIAspectDebug(constraint);
83
+ debug.visible = this._private_showAspectInternal;
84
+ }
85
+ else if (constraint instanceof UIHeightConstraint) {
86
+ debug = new UIHeightDebug(constraint);
87
+ debug.visible = this._private_showHeightInternal;
88
+ }
89
+ else if (constraint instanceof UIWidthConstraint) {
90
+ debug = new UIWidthDebug(constraint);
91
+ debug.visible = this._private_showWidthInternal;
92
+ }
93
+ else if (constraint instanceof UIHorizontalDistanceConstraint) {
94
+ debug = new UIHorizontalDistanceDebug(constraint);
95
+ debug.visible = this._private_showHorizontalDistanceInternal;
96
+ }
97
+ else if (constraint instanceof UIHorizontalInterpolationConstraint) {
98
+ debug = new UIHorizontalInterpolationDebug(constraint);
99
+ debug.visible = this._private_showHorizontalInterpolationInternal;
100
+ }
101
+ else if (constraint instanceof UIVerticalDistanceConstraint) {
102
+ debug = new UIVerticalDistanceDebug(constraint);
103
+ debug.visible = this._private_showVerticalDistanceInternal;
104
+ }
105
+ else if (constraint instanceof UIVerticalInterpolationConstraint) {
106
+ debug = new UIVerticalInterpolationDebug(constraint);
107
+ debug.visible = this._private_showVerticalInterpolationInternal;
108
+ }
109
+ if (debug) {
110
+ this._private_debug.push(debug);
111
+ }
112
+ }
113
+ _private_setVisibility(
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- any is necessary here because the constraint class constructor signature is unknown
115
+ constraintClass, visible) {
116
+ for (const debug of this._private_debug) {
117
+ if (debug.constraint instanceof constraintClass) {
118
+ debug.visible = visible;
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ export { UILayerDebug };
@@ -0,0 +1,29 @@
1
+ import type { UIVerticalDistanceConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIVerticalDistanceDebug implements UIConstraintDebug {
5
+ readonly constraint: UIVerticalDistanceConstraint;
6
+ readonly tint: UIColor;
7
+ private readonly container;
8
+ private readonly lineMaterial;
9
+ private readonly lineGeometry;
10
+ private readonly line;
11
+ private readonly tickMaterial;
12
+ private readonly tickGeometry;
13
+ private readonly tickLine;
14
+ private readonly textSprite;
15
+ private readonly textTexture;
16
+ private readonly spriteMaterial;
17
+ private readonly canvas;
18
+ private readonly context;
19
+ private visibleInternal;
20
+ private lastRenderedText;
21
+ constructor(constraint: UIVerticalDistanceConstraint);
22
+ get visible(): boolean;
23
+ set visible(value: boolean);
24
+ destroy(): void;
25
+ private updateContainerVisibility;
26
+ private readonly onOrientationChanged;
27
+ private readonly onRendering;
28
+ private drawText;
29
+ }
@@ -0,0 +1,158 @@
1
+ import { Object3D, Vector3, CanvasTexture, SpriteMaterial, Sprite } from 'three';
2
+ import { Line2 } from '../node_modules/three/examples/jsm/lines/Line2.js';
3
+ import { LineGeometry } from '../node_modules/three/examples/jsm/lines/LineGeometry.js';
4
+ import { LineMaterial } from '../node_modules/three/examples/jsm/lines/LineMaterial.js';
5
+ import { LineSegments2 } from '../node_modules/three/examples/jsm/lines/LineSegments2.js';
6
+ import { LineSegmentsGeometry } from '../node_modules/three/examples/jsm/lines/LineSegmentsGeometry.js';
7
+ import { isUIPlaneElement } from '../core/miscellaneous/shared.js';
8
+ import { DEBUG_LINE_WIDTH, debugResolutionVector, DEBUG_RENDER_ORDER, DEBUG_BADGE_SIZE, DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_FONT_FAMILY } from './miscellaneous.js';
9
+ import { UIColor } from '../core/miscellaneous/color/UIColor.js';
10
+ import { UIOrientation } from '../core/miscellaneous/UIOrientation.js';
11
+ import { UILayer } from '../core/layers/UILayer/UILayer.js';
12
+
13
+ class UIVerticalDistanceDebug {
14
+ constructor(constraint) {
15
+ this.constraint = constraint;
16
+ this.tint = new UIColor("cyan");
17
+ this._private_container = new Object3D();
18
+ this._private_lineMaterial = new LineMaterial({
19
+ linewidth: DEBUG_LINE_WIDTH,
20
+ transparent: true,
21
+ depthTest: false,
22
+ depthWrite: false,
23
+ });
24
+ this._private_lineGeometry = new LineGeometry();
25
+ this._private_line = new Line2(this._private_lineGeometry, this._private_lineMaterial);
26
+ this._private_tickMaterial = new LineMaterial({
27
+ linewidth: DEBUG_LINE_WIDTH,
28
+ transparent: true,
29
+ depthTest: false,
30
+ depthWrite: false,
31
+ });
32
+ this._private_tickGeometry = new LineSegmentsGeometry();
33
+ this._private_tickLine = new LineSegments2(this._private_tickGeometry, this._private_tickMaterial);
34
+ this._private_visibleInternal = true;
35
+ this._private_lastRenderedText = "";
36
+ this._private_onOrientationChanged = () => {
37
+ this._private_updateContainerVisibility();
38
+ };
39
+ this._private_onRendering = (renderer) => {
40
+ const tintDirty = this.tint.dirty;
41
+ if (tintDirty) {
42
+ this.tint.toThreeColor(this._private_lineMaterial.color);
43
+ this._private_lineMaterial.opacity = this.tint.a;
44
+ this.tint.toThreeColor(this._private_tickMaterial.color);
45
+ this._private_tickMaterial.opacity = this.tint.a;
46
+ this._private_spriteMaterial.opacity = this.tint.a;
47
+ this.tint.setDirtyFalse();
48
+ }
49
+ renderer.getDrawingBufferSize(debugResolutionVector);
50
+ this._private_lineMaterial.resolution.copy(debugResolutionVector);
51
+ this._private_tickMaterial.resolution.copy(debugResolutionVector);
52
+ const elementA = this.constraint.a;
53
+ const elementB = this.constraint.b;
54
+ const anchorAY = isUIPlaneElement(elementA)
55
+ ? elementA.y + elementA.height * this.constraint.anchorA
56
+ : elementA.y;
57
+ const anchorAX = isUIPlaneElement(elementA) ? elementA.centerX : elementA.x;
58
+ const anchorBY = isUIPlaneElement(elementB)
59
+ ? elementB.y + elementB.height * this.constraint.anchorB
60
+ : elementB.y;
61
+ const anchorBX = isUIPlaneElement(elementB) ? elementB.centerX : elementB.x;
62
+ const midX = elementA instanceof UILayer
63
+ ? anchorBX
64
+ : elementB instanceof UILayer
65
+ ? anchorAX
66
+ : (anchorAX + anchorBX) / 2;
67
+ this._private_lineGeometry.setFromPoints([
68
+ new Vector3(midX, anchorAY, 0),
69
+ new Vector3(midX, anchorBY, 0),
70
+ ]);
71
+ const tickSize = 10;
72
+ this._private_tickGeometry.setPositions([
73
+ midX - tickSize,
74
+ anchorAY,
75
+ 0,
76
+ midX + tickSize,
77
+ anchorAY,
78
+ 0,
79
+ midX - tickSize,
80
+ anchorBY,
81
+ 0,
82
+ midX + tickSize,
83
+ anchorBY,
84
+ 0,
85
+ ]);
86
+ const nextText = "VD: " + this.constraint.distance.toFixed(0);
87
+ if (nextText !== this._private_lastRenderedText || tintDirty) {
88
+ this._private_drawText(nextText);
89
+ this._private_textTexture.needsUpdate = true;
90
+ this._private_lastRenderedText = nextText;
91
+ }
92
+ this._private_textSprite.position.set(midX + 20, (anchorAY + anchorBY) / 2, 0);
93
+ };
94
+ this._private_line.renderOrder = DEBUG_RENDER_ORDER;
95
+ this._private_tickLine.renderOrder = DEBUG_RENDER_ORDER;
96
+ this._private_container.add(this._private_line);
97
+ this._private_container.add(this._private_tickLine);
98
+ const canvas = document.createElement("canvas");
99
+ canvas.width = 256;
100
+ canvas.height = 64;
101
+ const context = canvas.getContext("2d");
102
+ if (context === null) {
103
+ throw new Error("Failed to get 2D context for debug text");
104
+ }
105
+ this._private_canvas = canvas;
106
+ this._private_context = context;
107
+ this._private_drawText("");
108
+ this._private_textTexture = new CanvasTexture(canvas);
109
+ this._private_spriteMaterial = new SpriteMaterial({
110
+ map: this._private_textTexture,
111
+ transparent: true,
112
+ depthTest: false,
113
+ depthWrite: false,
114
+ });
115
+ this._private_textSprite = new Sprite(this._private_spriteMaterial);
116
+ this._private_textSprite.renderOrder = DEBUG_RENDER_ORDER;
117
+ this._private_textSprite.scale.set(DEBUG_BADGE_SIZE, DEBUG_BADGE_SIZE * 0.25, 1);
118
+ this._private_container.add(this._private_textSprite);
119
+ this.constraint.layer.signalRendering.on(this._private_onRendering);
120
+ this.constraint.layer.signalOrientationChanged.on(this._private_onOrientationChanged);
121
+ this.constraint.layer.sceneWrapper.insertCustomObject(this._private_container);
122
+ this._private_updateContainerVisibility();
123
+ }
124
+ get visible() {
125
+ return this._private_visibleInternal;
126
+ }
127
+ set visible(value) {
128
+ if (value !== this._private_visibleInternal) {
129
+ this._private_visibleInternal = value;
130
+ this._private_updateContainerVisibility();
131
+ }
132
+ }
133
+ destroy() {
134
+ this.constraint.layer.signalRendering.off(this._private_onRendering);
135
+ this.constraint.layer.signalOrientationChanged.off(this._private_onOrientationChanged);
136
+ this.constraint.layer.sceneWrapper.removeCustomObject(this._private_container);
137
+ this._private_lineGeometry.dispose();
138
+ this._private_tickGeometry.dispose();
139
+ this._private_textTexture.dispose();
140
+ }
141
+ _private_updateContainerVisibility() {
142
+ const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
143
+ this.constraint.orientation === this.constraint.layer.orientation;
144
+ this._private_container.visible = this._private_visibleInternal && orientationActive;
145
+ }
146
+ _private_drawText(text) {
147
+ this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
148
+ this._private_context.fillStyle = DEBUG_BADGE_BACKGROUND_COLOR;
149
+ this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
150
+ this._private_context.fillStyle = this.tint.getHexStringRGB();
151
+ this._private_context.font = `${DEBUG_BADGE_FONT_SIZE}px ${DEBUG_BADGE_FONT_FAMILY}`;
152
+ this._private_context.textAlign = "center";
153
+ this._private_context.textBaseline = "middle";
154
+ this._private_context.fillText(text, this._private_canvas.width / 2, this._private_canvas.height / 2);
155
+ }
156
+ }
157
+
158
+ export { UIVerticalDistanceDebug };
@@ -0,0 +1,29 @@
1
+ import type { UIVerticalInterpolationConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIVerticalInterpolationDebug implements UIConstraintDebug {
5
+ readonly constraint: UIVerticalInterpolationConstraint;
6
+ readonly tint: UIColor;
7
+ private readonly container;
8
+ private readonly baseLineMaterial;
9
+ private readonly baseLineGeometry;
10
+ private readonly baseLine;
11
+ private readonly markerMaterial;
12
+ private readonly markerGeometry;
13
+ private readonly markerLine;
14
+ private readonly textSprite;
15
+ private readonly textTexture;
16
+ private readonly spriteMaterial;
17
+ private readonly canvas;
18
+ private readonly context;
19
+ private visibleInternal;
20
+ private lastRenderedText;
21
+ constructor(constraint: UIVerticalInterpolationConstraint);
22
+ get visible(): boolean;
23
+ set visible(value: boolean);
24
+ destroy(): void;
25
+ private updateContainerVisibility;
26
+ private readonly onOrientationChanged;
27
+ private readonly onRendering;
28
+ private drawText;
29
+ }
@@ -0,0 +1,145 @@
1
+ import { Object3D, Vector3, CanvasTexture, SpriteMaterial, Sprite } from 'three';
2
+ import { Line2 } from '../node_modules/three/examples/jsm/lines/Line2.js';
3
+ import { LineGeometry } from '../node_modules/three/examples/jsm/lines/LineGeometry.js';
4
+ import { LineMaterial } from '../node_modules/three/examples/jsm/lines/LineMaterial.js';
5
+ import { isUIPlaneElement } from '../core/miscellaneous/shared.js';
6
+ import { DEBUG_LINE_WIDTH, debugResolutionVector, DEBUG_RENDER_ORDER, DEBUG_BADGE_SIZE, DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_FONT_FAMILY } from './miscellaneous.js';
7
+ import { UIColor } from '../core/miscellaneous/color/UIColor.js';
8
+ import { UIOrientation } from '../core/miscellaneous/UIOrientation.js';
9
+
10
+ class UIVerticalInterpolationDebug {
11
+ constructor(constraint) {
12
+ this.constraint = constraint;
13
+ this.tint = new UIColor("cyan");
14
+ this._private_container = new Object3D();
15
+ this._private_baseLineMaterial = new LineMaterial({
16
+ linewidth: DEBUG_LINE_WIDTH,
17
+ transparent: true,
18
+ depthTest: false,
19
+ depthWrite: false,
20
+ });
21
+ this._private_baseLineGeometry = new LineGeometry();
22
+ this._private_baseLine = new Line2(this._private_baseLineGeometry, this._private_baseLineMaterial);
23
+ this._private_markerMaterial = new LineMaterial({
24
+ linewidth: DEBUG_LINE_WIDTH,
25
+ transparent: true,
26
+ depthTest: false,
27
+ depthWrite: false,
28
+ });
29
+ this._private_markerGeometry = new LineGeometry();
30
+ this._private_markerLine = new Line2(this._private_markerGeometry, this._private_markerMaterial);
31
+ this._private_visibleInternal = true;
32
+ this._private_lastRenderedText = "";
33
+ this._private_onOrientationChanged = () => {
34
+ this._private_updateContainerVisibility();
35
+ };
36
+ this._private_onRendering = (renderer) => {
37
+ const tintDirty = this.tint.dirty;
38
+ if (tintDirty) {
39
+ this.tint.toThreeColor(this._private_baseLineMaterial.color);
40
+ this._private_baseLineMaterial.opacity = this.tint.a;
41
+ this.tint.toThreeColor(this._private_markerMaterial.color);
42
+ this._private_markerMaterial.opacity = this.tint.a;
43
+ this._private_spriteMaterial.opacity = this.tint.a;
44
+ this.tint.setDirtyFalse();
45
+ }
46
+ renderer.getDrawingBufferSize(debugResolutionVector);
47
+ this._private_baseLineMaterial.resolution.copy(debugResolutionVector);
48
+ this._private_markerMaterial.resolution.copy(debugResolutionVector);
49
+ const elementA = this.constraint.a;
50
+ const elementB = this.constraint.b;
51
+ const elementC = this.constraint.c;
52
+ const anchorAY = isUIPlaneElement(elementA)
53
+ ? elementA.y + elementA.height * this.constraint.anchorA
54
+ : elementA.y;
55
+ const anchorAX = isUIPlaneElement(elementA) ? elementA.centerX : elementA.x;
56
+ const anchorBY = isUIPlaneElement(elementB)
57
+ ? elementB.y + elementB.height * this.constraint.anchorB
58
+ : elementB.y;
59
+ const anchorBX = isUIPlaneElement(elementB) ? elementB.centerX : elementB.x;
60
+ const anchorCY = isUIPlaneElement(elementC)
61
+ ? elementC.y + elementC.height * this.constraint.anchorC
62
+ : elementC.y;
63
+ const midX = (anchorAX + anchorBX) / 2;
64
+ this._private_baseLineGeometry.setFromPoints([
65
+ new Vector3(midX, anchorAY, 0),
66
+ new Vector3(midX, anchorBY, 0),
67
+ ]);
68
+ const markerSize = 12;
69
+ this._private_markerGeometry.setFromPoints([
70
+ new Vector3(midX - markerSize, anchorCY, 0),
71
+ new Vector3(midX + markerSize, anchorCY, 0),
72
+ ]);
73
+ const nextText = "vi: " + this.constraint.t.toFixed(2);
74
+ if (nextText !== this._private_lastRenderedText || tintDirty) {
75
+ this._private_drawText(nextText);
76
+ this._private_textTexture.needsUpdate = true;
77
+ this._private_lastRenderedText = nextText;
78
+ }
79
+ this._private_textSprite.position.set(midX + 20, anchorCY, 0);
80
+ };
81
+ this._private_baseLine.renderOrder = DEBUG_RENDER_ORDER;
82
+ this._private_markerLine.renderOrder = DEBUG_RENDER_ORDER;
83
+ this._private_container.add(this._private_baseLine);
84
+ this._private_container.add(this._private_markerLine);
85
+ const canvas = document.createElement("canvas");
86
+ canvas.width = 256;
87
+ canvas.height = 64;
88
+ const context = canvas.getContext("2d");
89
+ if (context === null) {
90
+ throw new Error("Failed to get 2D context for debug text");
91
+ }
92
+ this._private_canvas = canvas;
93
+ this._private_context = context;
94
+ this._private_drawText("");
95
+ this._private_textTexture = new CanvasTexture(canvas);
96
+ this._private_spriteMaterial = new SpriteMaterial({
97
+ map: this._private_textTexture,
98
+ transparent: true,
99
+ depthTest: false,
100
+ depthWrite: false,
101
+ });
102
+ this._private_textSprite = new Sprite(this._private_spriteMaterial);
103
+ this._private_textSprite.renderOrder = DEBUG_RENDER_ORDER;
104
+ this._private_textSprite.scale.set(DEBUG_BADGE_SIZE, DEBUG_BADGE_SIZE * 0.25, 1);
105
+ this._private_container.add(this._private_textSprite);
106
+ this.constraint.layer.signalRendering.on(this._private_onRendering);
107
+ this.constraint.layer.signalOrientationChanged.on(this._private_onOrientationChanged);
108
+ this.constraint.layer.sceneWrapper.insertCustomObject(this._private_container);
109
+ this._private_updateContainerVisibility();
110
+ }
111
+ get visible() {
112
+ return this._private_visibleInternal;
113
+ }
114
+ set visible(value) {
115
+ if (value !== this._private_visibleInternal) {
116
+ this._private_visibleInternal = value;
117
+ this._private_updateContainerVisibility();
118
+ }
119
+ }
120
+ destroy() {
121
+ this.constraint.layer.signalRendering.off(this._private_onRendering);
122
+ this.constraint.layer.signalOrientationChanged.off(this._private_onOrientationChanged);
123
+ this.constraint.layer.sceneWrapper.removeCustomObject(this._private_container);
124
+ this._private_baseLineGeometry.dispose();
125
+ this._private_markerGeometry.dispose();
126
+ this._private_textTexture.dispose();
127
+ }
128
+ _private_updateContainerVisibility() {
129
+ const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
130
+ this.constraint.orientation === this.constraint.layer.orientation;
131
+ this._private_container.visible = this._private_visibleInternal && orientationActive;
132
+ }
133
+ _private_drawText(text) {
134
+ this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
135
+ this._private_context.fillStyle = DEBUG_BADGE_BACKGROUND_COLOR;
136
+ this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
137
+ this._private_context.fillStyle = this.tint.getHexStringRGB();
138
+ this._private_context.font = `${DEBUG_BADGE_FONT_SIZE}px ${DEBUG_BADGE_FONT_FAMILY}`;
139
+ this._private_context.textAlign = "center";
140
+ this._private_context.textBaseline = "middle";
141
+ this._private_context.fillText(text, this._private_canvas.width / 2, this._private_canvas.height / 2);
142
+ }
143
+ }
144
+
145
+ export { UIVerticalInterpolationDebug };