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
@@ -0,0 +1,26 @@
1
+ import type { UIWidthConstraint } from "../core";
2
+ import { UIColor } from "../core";
3
+ import type { UIConstraintDebug } from "./UIConstraintDebug";
4
+ export declare class UIWidthDebug implements UIConstraintDebug {
5
+ readonly constraint: UIWidthConstraint;
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: UIWidthConstraint);
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 UIWidthDebug {
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, oppositeX, width, centerX, centerY } = this.constraint.element;
38
+ if (width <= 0) {
39
+ return;
40
+ }
41
+ this._private_lineGeometry.setFromPoints([new Vector3(x, y, 0), new Vector3(oppositeX, y, 0)]);
42
+ const nextText = "W: " + width.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, centerY - 20, 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 { UIWidthDebug };
@@ -0,0 +1,8 @@
1
+ export { UIAspectDebug } from "./UIAspectDebug";
2
+ export { UIHeightDebug } from "./UIHeightDebug";
3
+ export { UIHorizontalDistanceDebug } from "./UIHorizontalDistanceDebug";
4
+ export { UIHorizontalInterpolationDebug } from "./UIHorizontalInterpolationDebug";
5
+ export { UILayerDebug } from "./UILayerDebug";
6
+ export { UIVerticalDistanceDebug } from "./UIVerticalDistanceDebug";
7
+ export { UIVerticalInterpolationDebug } from "./UIVerticalInterpolationDebug";
8
+ export { UIWidthDebug } from "./UIWidthDebug";
@@ -0,0 +1,8 @@
1
+ export { UIAspectDebug } from './UIAspectDebug.js';
2
+ export { UIHeightDebug } from './UIHeightDebug.js';
3
+ export { UIHorizontalDistanceDebug } from './UIHorizontalDistanceDebug.js';
4
+ export { UIHorizontalInterpolationDebug } from './UIHorizontalInterpolationDebug.js';
5
+ export { UILayerDebug } from './UILayerDebug.js';
6
+ export { UIVerticalDistanceDebug } from './UIVerticalDistanceDebug.js';
7
+ export { UIVerticalInterpolationDebug } from './UIVerticalInterpolationDebug.js';
8
+ export { UIWidthDebug } from './UIWidthDebug.js';
@@ -0,0 +1,8 @@
1
+ import { Vector2 } from "three";
2
+ export declare const DEBUG_RENDER_ORDER = 8192;
3
+ export declare const DEBUG_LINE_WIDTH = 2;
4
+ export declare const DEBUG_BADGE_SIZE = 150;
5
+ export declare const DEBUG_BADGE_FONT_SIZE = 30;
6
+ export declare const DEBUG_BADGE_FONT_FAMILY = "monospace";
7
+ export declare const DEBUG_BADGE_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.8)";
8
+ export declare const debugResolutionVector: Vector2;
@@ -0,0 +1,11 @@
1
+ import { Vector2 } from 'three';
2
+
3
+ const DEBUG_RENDER_ORDER = 8192;
4
+ const DEBUG_LINE_WIDTH = 2;
5
+ const DEBUG_BADGE_SIZE = 150;
6
+ const DEBUG_BADGE_FONT_SIZE = 30;
7
+ const DEBUG_BADGE_FONT_FAMILY = "monospace";
8
+ const DEBUG_BADGE_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.8)";
9
+ const debugResolutionVector = new Vector2();
10
+
11
+ export { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector };
@@ -0,0 +1,56 @@
1
+ import { LineSegments2 } from './LineSegments2.js';
2
+ import { LineGeometry } from './LineGeometry.js';
3
+ import { LineMaterial } from './LineMaterial.js';
4
+
5
+ /**
6
+ * A polyline drawn between vertices.
7
+ *
8
+ * This adds functionality beyond {@link Line}, like arbitrary line width and changing width to
9
+ * be in world units.It extends {@link LineSegments2}, simplifying constructing segments from a
10
+ * chain of points.
11
+ *
12
+ * This module can only be used with {@link WebGLRenderer}. When using {@link WebGPURenderer},
13
+ * import the class from `lines/webgpu/Line2.js`.
14
+ *
15
+ * ```js
16
+ * const geometry = new LineGeometry();
17
+ * geometry.setPositions( positions );
18
+ * geometry.setColors( colors );
19
+ *
20
+ * const material = new LineMaterial( { linewidth: 5, vertexColors: true } };
21
+ *
22
+ * const line = new Line2( geometry, material );
23
+ * scene.add( line );
24
+ * ```
25
+ *
26
+ * @augments LineSegments2
27
+ * @three_import import { Line2 } from 'three/addons/lines/Line2.js';
28
+ */
29
+ class Line2 extends LineSegments2 {
30
+
31
+ /**
32
+ * Constructs a new wide line.
33
+ *
34
+ * @param {LineGeometry} [geometry] - The line geometry.
35
+ * @param {LineMaterial} [material] - The line material.
36
+ */
37
+ constructor( geometry = new LineGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
38
+
39
+ super( geometry, material );
40
+
41
+ /**
42
+ * This flag can be used for type testing.
43
+ *
44
+ * @type {boolean}
45
+ * @readonly
46
+ * @default true
47
+ */
48
+ this.isLine2 = true;
49
+
50
+ this.type = 'Line2';
51
+
52
+ }
53
+
54
+ }
55
+
56
+ export { Line2 };
@@ -0,0 +1,157 @@
1
+ import { LineSegmentsGeometry } from './LineSegmentsGeometry.js';
2
+
3
+ /**
4
+ * A chain of vertices, forming a polyline.
5
+ *
6
+ * This is used in {@link Line2} to describe the shape.
7
+ *
8
+ * ```js
9
+ * const points = [
10
+ * new THREE.Vector3( - 10, 0, 0 ),
11
+ * new THREE.Vector3( 0, 5, 0 ),
12
+ * new THREE.Vector3( 10, 0, 0 ),
13
+ * ];
14
+ *
15
+ * const geometry = new LineGeometry();
16
+ * geometry.setFromPoints( points );
17
+ * ```
18
+ *
19
+ * @augments LineSegmentsGeometry
20
+ * @three_import import { LineLineGeometry2 } from 'three/addons/lines/LineGeometry.js';
21
+ */
22
+ class LineGeometry extends LineSegmentsGeometry {
23
+
24
+ /**
25
+ * Constructs a new line geometry.
26
+ */
27
+ constructor() {
28
+
29
+ super();
30
+
31
+ /**
32
+ * This flag can be used for type testing.
33
+ *
34
+ * @type {boolean}
35
+ * @readonly
36
+ * @default true
37
+ */
38
+ this.isLineGeometry = true;
39
+
40
+ this.type = 'LineGeometry';
41
+
42
+ }
43
+
44
+ /**
45
+ * Sets the given line positions for this geometry.
46
+ *
47
+ * @param {Float32Array|Array<number>} array - The position data to set.
48
+ * @return {LineGeometry} A reference to this geometry.
49
+ */
50
+ setPositions( array ) {
51
+
52
+ // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
53
+
54
+ const length = array.length - 3;
55
+ const points = new Float32Array( 2 * length );
56
+
57
+ for ( let i = 0; i < length; i += 3 ) {
58
+
59
+ points[ 2 * i ] = array[ i ];
60
+ points[ 2 * i + 1 ] = array[ i + 1 ];
61
+ points[ 2 * i + 2 ] = array[ i + 2 ];
62
+
63
+ points[ 2 * i + 3 ] = array[ i + 3 ];
64
+ points[ 2 * i + 4 ] = array[ i + 4 ];
65
+ points[ 2 * i + 5 ] = array[ i + 5 ];
66
+
67
+ }
68
+
69
+ super.setPositions( points );
70
+
71
+ return this;
72
+
73
+ }
74
+
75
+ /**
76
+ * Sets the given line colors for this geometry.
77
+ *
78
+ * @param {Float32Array|Array<number>} array - The position data to set.
79
+ * @return {LineGeometry} A reference to this geometry.
80
+ */
81
+ setColors( array ) {
82
+
83
+ // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
84
+
85
+ const length = array.length - 3;
86
+ const colors = new Float32Array( 2 * length );
87
+
88
+ for ( let i = 0; i < length; i += 3 ) {
89
+
90
+ colors[ 2 * i ] = array[ i ];
91
+ colors[ 2 * i + 1 ] = array[ i + 1 ];
92
+ colors[ 2 * i + 2 ] = array[ i + 2 ];
93
+
94
+ colors[ 2 * i + 3 ] = array[ i + 3 ];
95
+ colors[ 2 * i + 4 ] = array[ i + 4 ];
96
+ colors[ 2 * i + 5 ] = array[ i + 5 ];
97
+
98
+ }
99
+
100
+ super.setColors( colors );
101
+
102
+ return this;
103
+
104
+ }
105
+
106
+ /**
107
+ * Setups this line segments geometry from the given sequence of points.
108
+ *
109
+ * @param {Array<Vector3|Vector2>} points - An array of points in 2D or 3D space.
110
+ * @return {LineGeometry} A reference to this geometry.
111
+ */
112
+ setFromPoints( points ) {
113
+
114
+ // converts a vector3 or vector2 array to pairs format
115
+
116
+ const length = points.length - 1;
117
+ const positions = new Float32Array( 6 * length );
118
+
119
+ for ( let i = 0; i < length; i ++ ) {
120
+
121
+ positions[ 6 * i ] = points[ i ].x;
122
+ positions[ 6 * i + 1 ] = points[ i ].y;
123
+ positions[ 6 * i + 2 ] = points[ i ].z || 0;
124
+
125
+ positions[ 6 * i + 3 ] = points[ i + 1 ].x;
126
+ positions[ 6 * i + 4 ] = points[ i + 1 ].y;
127
+ positions[ 6 * i + 5 ] = points[ i + 1 ].z || 0;
128
+
129
+ }
130
+
131
+ super.setPositions( positions );
132
+
133
+ return this;
134
+
135
+ }
136
+
137
+ /**
138
+ * Setups this line segments geometry from the given line.
139
+ *
140
+ * @param {Line} line - The line that should be used as a data source for this geometry.
141
+ * @return {LineGeometry} A reference to this geometry.
142
+ */
143
+ fromLine( line ) {
144
+
145
+ const geometry = line.geometry;
146
+
147
+ this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
148
+
149
+ // set colors, maybe
150
+
151
+ return this;
152
+
153
+ }
154
+
155
+ }
156
+
157
+ export { LineGeometry };