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
@@ -19,6 +19,9 @@ class UILayer {
19
19
  this._private_signalModeChangedInternal = new Ferrsign2();
20
20
  this._private_signalRenderingInternal = new Ferrsign3();
21
21
  this._private_signalResizedInternal = new Ferrsign3();
22
+ this._private_signalConstraintAddedInternal = new Ferrsign2();
23
+ this._private_signalConstraintRemovedInternal = new Ferrsign2();
24
+ this._private_constraintRegistryInternal = [];
22
25
  if (options.width !== undefined) {
23
26
  assertValidPositiveNumber(options.width, "UILayer.constructor.options.width");
24
27
  }
@@ -64,6 +67,22 @@ class UILayer {
64
67
  get height() {
65
68
  return this._private_solverWrapperInternal.readVariableValue(this.hVariable);
66
69
  }
70
+ /** X coordinate of right edge */
71
+ get oppositeX() {
72
+ return this.x + this.width;
73
+ }
74
+ /** Y coordinate of top edge */
75
+ get oppositeY() {
76
+ return this.y + this.height;
77
+ }
78
+ /** X coordinate of horizontal center */
79
+ get centerX() {
80
+ return this.x + this.width / 2;
81
+ }
82
+ /** Y coordinate of vertical center */
83
+ get centerY() {
84
+ return this.y + this.height / 2;
85
+ }
67
86
  /** Current visibility and interactivity mode */
68
87
  get mode() {
69
88
  return this._private_modeInternal;
@@ -88,6 +107,18 @@ class UILayer {
88
107
  get signalResized() {
89
108
  return this._private_signalResizedInternal;
90
109
  }
110
+ /** Signal fired when a constraint is added */
111
+ get signalConstraintAdded() {
112
+ return this._private_signalConstraintAddedInternal;
113
+ }
114
+ /** Signal fired when a constraint is removed */
115
+ get signalConstraintRemoved() {
116
+ return this._private_signalConstraintRemovedInternal;
117
+ }
118
+ /** Constraint registry */
119
+ get constraintRegistry() {
120
+ return this._private_constraintRegistryInternal;
121
+ }
91
122
  /** Updates visibility and interactivity mode */
92
123
  set mode(value) {
93
124
  if (value !== this._private_modeInternal) {
@@ -95,6 +126,23 @@ class UILayer {
95
126
  this._private_signalModeChangedInternal.emit(this._private_modeInternal, this);
96
127
  }
97
128
  }
129
+ /** @internal */
130
+ addConstraint(constraint) {
131
+ if (this._private_constraintRegistryInternal.includes(constraint)) {
132
+ throw new Error(`UILayer.addConstraint: constraint is already added to this layer`);
133
+ }
134
+ this._private_constraintRegistryInternal.push(constraint);
135
+ this._private_signalConstraintAddedInternal.emit(this, constraint);
136
+ }
137
+ /** @internal */
138
+ removeConstraint(constraint) {
139
+ const index = this._private_constraintRegistryInternal.indexOf(constraint);
140
+ if (index === -1) {
141
+ throw new Error(`UILayer.removeConstraint: constraint is not found in this layer`);
142
+ }
143
+ this._private_constraintRegistryInternal.splice(index, 1);
144
+ this._private_signalConstraintRemovedInternal.emit(this, constraint);
145
+ }
98
146
  resizeInternal(width, height) {
99
147
  this._private_solverWrapperInternal.suggestVariableValue(this.wVariable, width);
100
148
  this._private_solverWrapperInternal.suggestVariableValue(this.hVariable, height);
@@ -103,8 +103,9 @@ function buildMaterial(source, uniformProperties, varyingProperties, transparenc
103
103
  gl_Position = projectionMatrix * a_instanceTransform * vec4(position, 1.0);
104
104
  }
105
105
  `;
106
- const alphaTestValue = 1 / 255;
107
- const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue);
106
+ const alphaTestValue = 0.0075;
107
+ const premultipliedAlpha = transparency === UITransparencyMode.BLEND;
108
+ const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue, premultipliedAlpha);
108
109
  return new ShaderMaterial({
109
110
  uniforms,
110
111
  vertexShader,
@@ -116,6 +117,7 @@ function buildMaterial(source, uniformProperties, varyingProperties, transparenc
116
117
  depthTest: false,
117
118
  side: DoubleSide,
118
119
  forceSinglePass: true,
120
+ premultipliedAlpha,
119
121
  });
120
122
  }
121
123
  function reconstructValue(referenceValue, array, offset) {
@@ -34,4 +34,4 @@ export declare function cloneGLProperties(properties: Record<string, GLProperty>
34
34
  export declare function extractZIndex(transform: Matrix4): number;
35
35
  /** Extracts zIndex from transform buffer at given instance index */
36
36
  export declare function extractZIndexFromBuffer(buffer: Float32Array, instanceIndex: number): number;
37
- export declare function buildGenericPlaneFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], source: string, alphaTestValue: number): string;
37
+ export declare function buildGenericPlaneFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], source: string, alphaTestValue: number, usePremultipliedAlpha: boolean): string;
@@ -177,7 +177,7 @@ function extractZIndex(transform) {
177
177
  function extractZIndexFromBuffer(buffer, instanceIndex) {
178
178
  return buffer[instanceIndex * 16 + 14];
179
179
  }
180
- function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue) {
180
+ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue, usePremultipliedAlpha) {
181
181
  return `
182
182
  // Defines
183
183
  #define PI 3.14159265359
@@ -217,7 +217,9 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
217
217
  discard;
218
218
  }
219
219
  #endif
220
+
220
221
  gl_FragColor = linearToOutputTexel(diffuseColor);
222
+ gl_FragColor = ${usePremultipliedAlpha ? "vec4(gl_FragColor.rgb * gl_FragColor.a, gl_FragColor.a)" : "gl_FragColor"};
221
223
  }
222
224
  `;
223
225
  }
@@ -25,6 +25,14 @@ export interface UIPlaneElement extends UIPointElement {
25
25
  readonly width: number;
26
26
  /** Height in world units */
27
27
  readonly height: number;
28
+ /** Opposite X coordinate in world units */
29
+ readonly oppositeX: number;
30
+ /** Opposite Y coordinate in world units */
31
+ readonly oppositeY: number;
32
+ /** Center X coordinate in world units */
33
+ readonly centerX: number;
34
+ /** Center Y coordinate in world units */
35
+ readonly centerY: number;
28
36
  }
29
37
  /**
30
38
  * Checks if object implements UILayerElement.
@@ -0,0 +1,26 @@
1
+ import type { UIAspectConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIAspectDebug implements UIConstraintDebug {
5
+ readonly constraint: UIAspectConstraint;
6
+ readonly tint: UIColor;
7
+ private readonly container;
8
+ private readonly diagonalMaterial;
9
+ private readonly diagonalGeometry;
10
+ private readonly diagonalLine;
11
+ private readonly textSprite;
12
+ private readonly textTexture;
13
+ private readonly spriteMaterial;
14
+ private readonly canvas;
15
+ private readonly context;
16
+ private visibleInternal;
17
+ private lastRenderedText;
18
+ constructor(constraint: UIAspectConstraint);
19
+ get visible(): boolean;
20
+ set visible(value: boolean);
21
+ destroy(): void;
22
+ private updateContainerVisibility;
23
+ private readonly onOrientationChanged;
24
+ private readonly onRendering;
25
+ private drawText;
26
+ }
@@ -0,0 +1,118 @@
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 { 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';
6
+ import { UIColor } from '../core/miscellaneous/color/UIColor.js';
7
+ import { UIOrientation } from '../core/miscellaneous/UIOrientation.js';
8
+
9
+ class UIAspectDebug {
10
+ constructor(constraint) {
11
+ this.constraint = constraint;
12
+ this.tint = new UIColor("cyan");
13
+ this._private_container = new Object3D();
14
+ this._private_diagonalMaterial = new LineMaterial({
15
+ linewidth: DEBUG_LINE_WIDTH,
16
+ transparent: true,
17
+ depthTest: false,
18
+ depthWrite: false,
19
+ });
20
+ this._private_diagonalGeometry = new LineGeometry();
21
+ this._private_diagonalLine = new Line2(this._private_diagonalGeometry, this._private_diagonalMaterial);
22
+ this._private_visibleInternal = true;
23
+ this._private_lastRenderedText = "";
24
+ this._private_onOrientationChanged = () => {
25
+ this._private_updateContainerVisibility();
26
+ };
27
+ this._private_onRendering = (renderer) => {
28
+ const tintDirty = this.tint.dirty;
29
+ if (tintDirty) {
30
+ this.tint.toThreeColor(this._private_diagonalMaterial.color);
31
+ this._private_diagonalMaterial.opacity = this.tint.a;
32
+ this._private_spriteMaterial.opacity = this.tint.a;
33
+ this.tint.setDirtyFalse();
34
+ }
35
+ renderer.getDrawingBufferSize(debugResolutionVector);
36
+ this._private_diagonalMaterial.resolution.copy(debugResolutionVector);
37
+ const { x, y, oppositeX, oppositeY, width, height, centerX, centerY } = this.constraint.element;
38
+ if (width <= 0 || height <= 0) {
39
+ return;
40
+ }
41
+ this._private_diagonalGeometry.setFromPoints([
42
+ new Vector3(x, y, 0),
43
+ new Vector3(oppositeX, oppositeY, 0),
44
+ ]);
45
+ const nextText = this.constraint.aspect.toFixed(2) + " (" + width.toFixed(0) + "×" + height.toFixed(0) + ")";
46
+ if (nextText !== this._private_lastRenderedText || tintDirty) {
47
+ this._private_drawText(nextText);
48
+ this._private_textTexture.needsUpdate = true;
49
+ this._private_lastRenderedText = nextText;
50
+ }
51
+ const dx = oppositeX - x;
52
+ const dy = oppositeY - y;
53
+ const angle = Math.atan2(dy, dx);
54
+ this._private_textSprite.position.set(centerX, centerY, 0);
55
+ this._private_textSprite.material.rotation = angle;
56
+ };
57
+ this._private_diagonalLine.renderOrder = DEBUG_RENDER_ORDER;
58
+ this._private_container.add(this._private_diagonalLine);
59
+ const canvas = document.createElement("canvas");
60
+ canvas.width = 256;
61
+ canvas.height = 64;
62
+ const context = canvas.getContext("2d");
63
+ if (context === null) {
64
+ throw new Error("Failed to get 2D context for debug text");
65
+ }
66
+ this._private_canvas = canvas;
67
+ this._private_context = context;
68
+ this._private_drawText("");
69
+ this._private_textTexture = new CanvasTexture(canvas);
70
+ this._private_spriteMaterial = new SpriteMaterial({
71
+ map: this._private_textTexture,
72
+ transparent: true,
73
+ depthTest: false,
74
+ depthWrite: false,
75
+ });
76
+ this._private_textSprite = new Sprite(this._private_spriteMaterial);
77
+ this._private_textSprite.renderOrder = DEBUG_RENDER_ORDER;
78
+ this._private_textSprite.scale.set(DEBUG_BADGE_SIZE, DEBUG_BADGE_SIZE * 0.25, 1);
79
+ this._private_container.add(this._private_textSprite);
80
+ this.constraint.layer.signalRendering.on(this._private_onRendering);
81
+ this.constraint.layer.signalOrientationChanged.on(this._private_onOrientationChanged);
82
+ this.constraint.layer.sceneWrapper.insertCustomObject(this._private_container);
83
+ this._private_updateContainerVisibility();
84
+ }
85
+ get visible() {
86
+ return this._private_visibleInternal;
87
+ }
88
+ set visible(value) {
89
+ if (value !== this._private_visibleInternal) {
90
+ this._private_visibleInternal = value;
91
+ this._private_updateContainerVisibility();
92
+ }
93
+ }
94
+ destroy() {
95
+ this.constraint.layer.signalRendering.off(this._private_onRendering);
96
+ this.constraint.layer.signalOrientationChanged.off(this._private_onOrientationChanged);
97
+ this.constraint.layer.sceneWrapper.removeCustomObject(this._private_container);
98
+ this._private_diagonalGeometry.dispose();
99
+ this._private_textTexture.dispose();
100
+ }
101
+ _private_updateContainerVisibility() {
102
+ const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
103
+ this.constraint.orientation === this.constraint.layer.orientation;
104
+ this._private_container.visible = this._private_visibleInternal && orientationActive;
105
+ }
106
+ _private_drawText(text) {
107
+ this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
108
+ this._private_context.fillStyle = DEBUG_BADGE_BACKGROUND_COLOR;
109
+ this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
110
+ this._private_context.fillStyle = this.tint.getHexStringRGB();
111
+ this._private_context.font = `${DEBUG_BADGE_FONT_SIZE}px ${DEBUG_BADGE_FONT_FAMILY}`;
112
+ this._private_context.textAlign = "center";
113
+ this._private_context.textBaseline = "middle";
114
+ this._private_context.fillText(text, this._private_canvas.width / 2, this._private_canvas.height / 2);
115
+ }
116
+ }
117
+
118
+ export { UIAspectDebug };
@@ -0,0 +1,7 @@
1
+ import type { UIConstraint } from "../core/constraints/UIConstraint";
2
+ export interface UIConstraintDebug {
3
+ get constraint(): UIConstraint;
4
+ get visible(): boolean;
5
+ set visible(value: boolean);
6
+ destroy(): void;
7
+ }
@@ -0,0 +1,26 @@
1
+ import type { UIHeightConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIHeightDebug implements UIConstraintDebug {
5
+ readonly constraint: UIHeightConstraint;
6
+ readonly tint: UIColor;
7
+ private readonly container;
8
+ private readonly lineMaterial;
9
+ private readonly lineGeometry;
10
+ private readonly line;
11
+ private readonly textSprite;
12
+ private readonly textTexture;
13
+ private readonly spriteMaterial;
14
+ private readonly canvas;
15
+ private readonly context;
16
+ private visibleInternal;
17
+ private lastRenderedText;
18
+ constructor(constraint: UIHeightConstraint);
19
+ get visible(): boolean;
20
+ set visible(value: boolean);
21
+ destroy(): void;
22
+ private updateContainerVisibility;
23
+ private readonly onOrientationChanged;
24
+ private readonly onRendering;
25
+ private drawText;
26
+ }
@@ -0,0 +1,111 @@
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 { 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';
6
+ import { UIColor } from '../core/miscellaneous/color/UIColor.js';
7
+ import { UIOrientation } from '../core/miscellaneous/UIOrientation.js';
8
+
9
+ class UIHeightDebug {
10
+ constructor(constraint) {
11
+ this.constraint = constraint;
12
+ this.tint = new UIColor("cyan");
13
+ this._private_container = new Object3D();
14
+ this._private_lineMaterial = new LineMaterial({
15
+ linewidth: DEBUG_LINE_WIDTH,
16
+ transparent: true,
17
+ depthTest: false,
18
+ depthWrite: false,
19
+ });
20
+ this._private_lineGeometry = new LineGeometry();
21
+ this._private_line = new Line2(this._private_lineGeometry, this._private_lineMaterial);
22
+ this._private_visibleInternal = true;
23
+ this._private_lastRenderedText = "";
24
+ this._private_onOrientationChanged = () => {
25
+ this._private_updateContainerVisibility();
26
+ };
27
+ this._private_onRendering = (renderer) => {
28
+ const tintDirty = this.tint.dirty;
29
+ if (tintDirty) {
30
+ this.tint.toThreeColor(this._private_lineMaterial.color);
31
+ this._private_lineMaterial.opacity = this.tint.a;
32
+ this._private_spriteMaterial.opacity = this.tint.a;
33
+ this.tint.setDirtyFalse();
34
+ }
35
+ renderer.getDrawingBufferSize(debugResolutionVector);
36
+ this._private_lineMaterial.resolution.copy(debugResolutionVector);
37
+ const { x, y, oppositeY, height, centerX, centerY } = this.constraint.element;
38
+ if (height <= 0) {
39
+ return;
40
+ }
41
+ this._private_lineGeometry.setFromPoints([new Vector3(x, y, 0), new Vector3(x, oppositeY, 0)]);
42
+ const nextText = "H: " + height.toFixed(0);
43
+ if (nextText !== this._private_lastRenderedText || tintDirty) {
44
+ this._private_drawText(nextText);
45
+ this._private_textTexture.needsUpdate = true;
46
+ this._private_lastRenderedText = nextText;
47
+ }
48
+ this._private_textSprite.position.set(centerX - 20, centerY, 0);
49
+ };
50
+ this._private_line.renderOrder = DEBUG_RENDER_ORDER;
51
+ this._private_container.add(this._private_line);
52
+ const canvas = document.createElement("canvas");
53
+ canvas.width = 256;
54
+ canvas.height = 64;
55
+ const context = canvas.getContext("2d");
56
+ if (context === null) {
57
+ throw new Error("Failed to get 2D context for debug text");
58
+ }
59
+ this._private_canvas = canvas;
60
+ this._private_context = context;
61
+ this._private_drawText("");
62
+ this._private_textTexture = new CanvasTexture(canvas);
63
+ this._private_spriteMaterial = new SpriteMaterial({
64
+ map: this._private_textTexture,
65
+ transparent: true,
66
+ depthTest: false,
67
+ depthWrite: false,
68
+ });
69
+ this._private_textSprite = new Sprite(this._private_spriteMaterial);
70
+ this._private_textSprite.renderOrder = DEBUG_RENDER_ORDER;
71
+ this._private_textSprite.scale.set(DEBUG_BADGE_SIZE, DEBUG_BADGE_SIZE * 0.25, 1);
72
+ this._private_container.add(this._private_textSprite);
73
+ this.constraint.layer.signalRendering.on(this._private_onRendering);
74
+ this.constraint.layer.signalOrientationChanged.on(this._private_onOrientationChanged);
75
+ this.constraint.layer.sceneWrapper.insertCustomObject(this._private_container);
76
+ this._private_updateContainerVisibility();
77
+ }
78
+ get visible() {
79
+ return this._private_visibleInternal;
80
+ }
81
+ set visible(value) {
82
+ if (value !== this._private_visibleInternal) {
83
+ this._private_visibleInternal = value;
84
+ this._private_updateContainerVisibility();
85
+ }
86
+ }
87
+ destroy() {
88
+ this.constraint.layer.signalRendering.off(this._private_onRendering);
89
+ this.constraint.layer.signalOrientationChanged.off(this._private_onOrientationChanged);
90
+ this.constraint.layer.sceneWrapper.removeCustomObject(this._private_container);
91
+ this._private_lineGeometry.dispose();
92
+ this._private_textTexture.dispose();
93
+ }
94
+ _private_updateContainerVisibility() {
95
+ const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
96
+ this.constraint.orientation === this.constraint.layer.orientation;
97
+ this._private_container.visible = this._private_visibleInternal && orientationActive;
98
+ }
99
+ _private_drawText(text) {
100
+ this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
101
+ this._private_context.fillStyle = DEBUG_BADGE_BACKGROUND_COLOR;
102
+ this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
103
+ this._private_context.fillStyle = this.tint.getHexStringRGB();
104
+ this._private_context.font = `${DEBUG_BADGE_FONT_SIZE}px ${DEBUG_BADGE_FONT_FAMILY}`;
105
+ this._private_context.textAlign = "center";
106
+ this._private_context.textBaseline = "middle";
107
+ this._private_context.fillText(text, this._private_canvas.width / 2, this._private_canvas.height / 2);
108
+ }
109
+ }
110
+
111
+ export { UIHeightDebug };
@@ -0,0 +1,29 @@
1
+ import type { UIHorizontalDistanceConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIHorizontalDistanceDebug implements UIConstraintDebug {
5
+ readonly constraint: UIHorizontalDistanceConstraint;
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: UIHorizontalDistanceConstraint);
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 UIHorizontalDistanceDebug {
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 anchorAX = isUIPlaneElement(elementA)
55
+ ? elementA.x + elementA.width * this.constraint.anchorA
56
+ : elementA.x;
57
+ const anchorAY = isUIPlaneElement(elementA) ? elementA.centerY : elementA.y;
58
+ const anchorBX = isUIPlaneElement(elementB)
59
+ ? elementB.x + elementB.width * this.constraint.anchorB
60
+ : elementB.x;
61
+ const anchorBY = isUIPlaneElement(elementB) ? elementB.centerY : elementB.y;
62
+ const midY = elementA instanceof UILayer
63
+ ? anchorBY
64
+ : elementB instanceof UILayer
65
+ ? anchorAY
66
+ : (anchorAY + anchorBY) / 2;
67
+ this._private_lineGeometry.setFromPoints([
68
+ new Vector3(anchorAX, midY, 0),
69
+ new Vector3(anchorBX, midY, 0),
70
+ ]);
71
+ const tickSize = 10;
72
+ this._private_tickGeometry.setPositions([
73
+ anchorAX,
74
+ midY - tickSize,
75
+ 0,
76
+ anchorAX,
77
+ midY + tickSize,
78
+ 0,
79
+ anchorBX,
80
+ midY - tickSize,
81
+ 0,
82
+ anchorBX,
83
+ midY + tickSize,
84
+ 0,
85
+ ]);
86
+ const nextText = "HD: " + 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((anchorAX + anchorBX) / 2, midY + 20, 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 { UIHorizontalDistanceDebug };
@@ -0,0 +1,29 @@
1
+ import type { UIHorizontalInterpolationConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIHorizontalInterpolationDebug implements UIConstraintDebug {
5
+ readonly constraint: UIHorizontalInterpolationConstraint;
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: UIHorizontalInterpolationConstraint);
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
+ }