laymur 0.18.1 → 0.19.1

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 (68) hide show
  1. package/README.md +44 -17
  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/color/UIColor.js +4 -4
  26. package/dist/core/miscellaneous/shared.d.ts +8 -0
  27. package/dist/debug/UIAspectDebug.d.ts +26 -0
  28. package/dist/debug/UIAspectDebug.js +118 -0
  29. package/dist/debug/UIConstraintDebug.d.ts +7 -0
  30. package/dist/debug/UIHeightDebug.d.ts +26 -0
  31. package/dist/debug/UIHeightDebug.js +111 -0
  32. package/dist/debug/UIHorizontalDistanceDebug.d.ts +29 -0
  33. package/dist/debug/UIHorizontalDistanceDebug.js +158 -0
  34. package/dist/debug/UIHorizontalInterpolationDebug.d.ts +29 -0
  35. package/dist/debug/UIHorizontalInterpolationDebug.js +145 -0
  36. package/dist/debug/UILayerDebug.d.ts +34 -0
  37. package/dist/debug/UILayerDebug.js +124 -0
  38. package/dist/debug/UIVerticalDistanceDebug.d.ts +29 -0
  39. package/dist/debug/UIVerticalDistanceDebug.js +158 -0
  40. package/dist/debug/UIVerticalInterpolationDebug.d.ts +29 -0
  41. package/dist/debug/UIVerticalInterpolationDebug.js +145 -0
  42. package/dist/debug/UIWidthDebug.d.ts +26 -0
  43. package/dist/debug/UIWidthDebug.js +111 -0
  44. package/dist/debug/index.d.ts +8 -0
  45. package/dist/debug/index.js +8 -0
  46. package/dist/debug/miscellaneous.d.ts +8 -0
  47. package/dist/debug/miscellaneous.js +11 -0
  48. package/dist/node_modules/three/examples/jsm/lines/Line2.js +56 -0
  49. package/dist/node_modules/three/examples/jsm/lines/LineGeometry.js +157 -0
  50. package/dist/node_modules/three/examples/jsm/lines/LineMaterial.js +691 -0
  51. package/dist/node_modules/three/examples/jsm/lines/LineSegments2.js +415 -0
  52. package/dist/node_modules/three/examples/jsm/lines/LineSegmentsGeometry.js +289 -0
  53. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +1 -1
  54. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +1 -1
  55. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +1 -1
  56. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +1 -1
  57. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +1 -1
  58. package/dist/particles/elements/UIEmitter.d.ts +1 -1
  59. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +1 -2
  60. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +1 -1
  61. package/dist/particles/miscellaneous/miscellaneous.d.ts +2 -1
  62. package/dist/particles/spawnModules/UISpawnOffset.d.ts +1 -1
  63. package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +1 -1
  64. package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +1 -1
  65. package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +1 -1
  66. package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +1 -1
  67. package/dist/particles/spawnModules/UISpawnRectangle.d.ts +1 -1
  68. package/package.json +5 -1
@@ -1,6 +1,7 @@
1
1
  import type { FerrsignView2, FerrsignView3 } from "ferrsign";
2
2
  import type { WebGLRenderer } from "three";
3
3
  import type { UIPlaneElement } from "../../miscellaneous/shared";
4
+ import type { UIConstraint } from "../../constraints/UIConstraint";
4
5
  import { UIInputWrapper } from "../../wrappers/UIInputWrapper/UIInputWrapper";
5
6
  import type { UILayerMode, UILayerOptions, UILayerOrientation } from "./UILayer.Internal";
6
7
  /** Base layer for UI rendering and layout management */
@@ -24,6 +25,9 @@ export declare abstract class UILayer implements UIPlaneElement {
24
25
  private readonly signalModeChangedInternal;
25
26
  private readonly signalRenderingInternal;
26
27
  private readonly signalResizedInternal;
28
+ private readonly signalConstraintAddedInternal;
29
+ private readonly signalConstraintRemovedInternal;
30
+ private readonly constraintRegistryInternal;
27
31
  constructor(options: Partial<UILayerOptions>);
28
32
  /** X coordinate in world units (always 0 for layers) */
29
33
  get x(): number;
@@ -33,6 +37,14 @@ export declare abstract class UILayer implements UIPlaneElement {
33
37
  get width(): number;
34
38
  /** Layer height in world units */
35
39
  get height(): number;
40
+ /** X coordinate of right edge */
41
+ get oppositeX(): number;
42
+ /** Y coordinate of top edge */
43
+ get oppositeY(): number;
44
+ /** X coordinate of horizontal center */
45
+ get centerX(): number;
46
+ /** Y coordinate of vertical center */
47
+ get centerY(): number;
36
48
  /** Current visibility and interactivity mode */
37
49
  get mode(): UILayerMode;
38
50
  /** Current orientation based on aspect ratio */
@@ -45,6 +57,12 @@ export declare abstract class UILayer implements UIPlaneElement {
45
57
  get signalRendering(): FerrsignView3<WebGLRenderer, number, UILayer>;
46
58
  /** Signal fired when layer resized */
47
59
  get signalResized(): FerrsignView3<number, number, UILayer>;
60
+ /** Signal fired when a constraint is added */
61
+ get signalConstraintAdded(): FerrsignView2<UILayer, UIConstraint>;
62
+ /** Signal fired when a constraint is removed */
63
+ get signalConstraintRemoved(): FerrsignView2<UILayer, UIConstraint>;
64
+ /** Constraint registry */
65
+ get constraintRegistry(): readonly UIConstraint[];
48
66
  /** Updates visibility and interactivity mode */
49
67
  set mode(value: UILayerMode);
50
68
  protected resizeInternal(width: number, height: number): void;
@@ -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);
@@ -367,10 +367,10 @@ class UIColor {
367
367
  setHexRGBA(hex) {
368
368
  assertValidNumber(hex, "UIColor.setHexRGBA.hex");
369
369
  this._private_ensureRGBUpdatedFromHSL();
370
- const r = ((hex >> 16) & 0xff) / 255;
371
- const g = ((hex >> 8) & 0xff) / 255;
372
- const b = (hex & 0xff) / 255;
373
- const a = ((hex >> 24) & 0xff) / 255;
370
+ const r = ((hex >> 24) & 0xff) / 255;
371
+ const g = ((hex >> 16) & 0xff) / 255;
372
+ const b = ((hex >> 8) & 0xff) / 255;
373
+ const a = (hex & 0xff) / 255;
374
374
  if (r !== this._private_rInternal ||
375
375
  g !== this._private_gInternal ||
376
376
  b !== this._private_bInternal ||
@@ -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
+ }