laymur 0.26.0 → 0.27.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.
- package/README.md +80 -36
- package/dist/core/constraints/UICustomConstraint.d.ts +1 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/builders/UIConstraint2DBuilder.d.ts +2 -3
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +10 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +42 -5
- package/dist/core/elements/UIDummy/UIDummy.js +119 -25
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
- package/dist/core/elements/UIElement/UIElement.d.ts +14 -0
- package/dist/core/elements/UIElement/UIElement.js +34 -3
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.js +2 -2
- package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
- package/dist/core/elements/UIImage/UIImage.js +10 -8
- package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
- package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
- package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
- package/dist/core/elements/UIProgress/UIProgress.js +15 -10
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
- package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
- package/dist/core/elements/UIScene/UIScene.js +18 -12
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
- package/dist/core/elements/UIText/UIText.d.ts +3 -3
- package/dist/core/elements/UIText/UIText.js +6 -6
- package/dist/core/index.d.ts +44 -41
- package/dist/core/index.js +12 -9
- package/dist/core/layers/UILayer/UILayer.d.ts +40 -4
- package/dist/core/layers/UILayer/UILayer.js +70 -9
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
- package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
- package/dist/core/miscellaneous/asserts.d.ts +14 -0
- package/dist/core/miscellaneous/asserts.js +28 -0
- package/dist/core/miscellaneous/canvas.js +10 -2
- package/dist/core/miscellaneous/color/UIColor.js +4 -2
- package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
- package/dist/core/miscellaneous/computeTransform.js +20 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +2 -1
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +1 -1
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +2 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +7 -4
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +13 -6
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +1 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +3 -3
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +1 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +3 -3
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
- package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
- package/dist/core/miscellaneous/texture/UITextureView.d.ts +4 -1
- package/dist/core/miscellaneous/texture/UITextureView.js +10 -7
- package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
- package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
- package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
- package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
- package/dist/core/miscellaneous/webglCapabilities.js +61 -55
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +1 -1
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
- package/dist/debug/UIAspectDebug.js +8 -7
- package/dist/debug/UIHeightDebug.js +8 -4
- package/dist/debug/UIHorizontalDistanceDebug.js +9 -7
- package/dist/debug/UIHorizontalInterpolationDebug.js +16 -10
- package/dist/debug/UILayerDebug.d.ts +7 -0
- package/dist/debug/UILayerDebug.js +21 -0
- package/dist/debug/UIVerticalDistanceDebug.js +9 -7
- package/dist/debug/UIVerticalInterpolationDebug.js +16 -10
- package/dist/debug/UIWidthDebug.js +8 -4
- package/dist/debug/index.d.ts +1 -1
- package/dist/debug/miscellaneous.d.ts +7 -0
- package/dist/debug/miscellaneous.js +11 -1
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +1 -1
- package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +5 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +2 -2
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -10
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +1 -1
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -4
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +1 -1
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -3
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +2 -2
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -8
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +4 -3
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -5
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +1 -1
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -8
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +7 -5
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -8
- package/dist/particles/elements/UIEmitter.Internal.d.ts +15 -2
- package/dist/particles/elements/UIEmitter.Internal.js +6 -0
- package/dist/particles/elements/UIEmitter.d.ts +19 -3
- package/dist/particles/elements/UIEmitter.js +100 -54
- package/dist/particles/index.d.ts +3 -2
- package/dist/particles/index.js +1 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +8 -2
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +16 -11
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.js +37 -2
- package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
- package/dist/particles/miscellaneous/miscellaneous.js +72 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -2
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -3
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +3 -2
- package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
- package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
- package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
- package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
- package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
- package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
- package/dist/particles/spawnModules/UISpawnModule.d.ts +5 -2
- package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +2 -2
- package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +1 -1
- package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -3
- package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +1 -1
- package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -3
- package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +1 -1
- package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -3
- package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +1 -1
- package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -4
- package/dist/particles/spawnModules/UISpawnRectangle.d.ts +1 -1
- package/dist/particles/spawnModules/UISpawnRectangle.js +6 -4
- package/package.json +34 -22
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
|
@@ -33,6 +33,27 @@ export class UILayerDebug {
|
|
|
33
33
|
this.layer.signalConstraintAdded.on(this.onConstraintAdded);
|
|
34
34
|
this.layer.signalConstraintRemoved.on(this.onConstraintRemoved);
|
|
35
35
|
}
|
|
36
|
+
get showAspect() {
|
|
37
|
+
return this.showAspectInternal;
|
|
38
|
+
}
|
|
39
|
+
get showHeight() {
|
|
40
|
+
return this.showHeightInternal;
|
|
41
|
+
}
|
|
42
|
+
get showWidth() {
|
|
43
|
+
return this.showWidthInternal;
|
|
44
|
+
}
|
|
45
|
+
get showHorizontalDistance() {
|
|
46
|
+
return this.showHorizontalDistanceInternal;
|
|
47
|
+
}
|
|
48
|
+
get showHorizontalInterpolation() {
|
|
49
|
+
return this.showHorizontalInterpolationInternal;
|
|
50
|
+
}
|
|
51
|
+
get showVerticalDistance() {
|
|
52
|
+
return this.showVerticalDistanceInternal;
|
|
53
|
+
}
|
|
54
|
+
get showVerticalInterpolation() {
|
|
55
|
+
return this.showVerticalInterpolationInternal;
|
|
56
|
+
}
|
|
36
57
|
set showAspect(value) {
|
|
37
58
|
this.showAspectInternal = value;
|
|
38
59
|
this.setVisibility(UIAspectConstraint, value);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanvasTexture, Object3D, Sprite, SpriteMaterial
|
|
1
|
+
import { CanvasTexture, Object3D, Sprite, SpriteMaterial } from "three";
|
|
2
2
|
import { Line2 } from "three/addons/lines/Line2.js";
|
|
3
3
|
import { LineGeometry } from "three/addons/lines/LineGeometry.js";
|
|
4
4
|
import { LineMaterial } from "three/addons/lines/LineMaterial.js";
|
|
@@ -6,7 +6,7 @@ import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
|
|
|
6
6
|
import { LineSegmentsGeometry } from "three/addons/lines/LineSegmentsGeometry.js";
|
|
7
7
|
import { UIColor, UILayer, UIOrientation } from "../core/index.js";
|
|
8
8
|
import { isUIPlaneElement } from "../core/miscellaneous/shared.js";
|
|
9
|
-
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, } from "./miscellaneous.js";
|
|
9
|
+
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, updateDebugResolution, } from "./miscellaneous.js";
|
|
10
10
|
export class UIVerticalDistanceDebug {
|
|
11
11
|
constructor(constraint) {
|
|
12
12
|
this.constraint = constraint;
|
|
@@ -34,6 +34,8 @@ export class UIVerticalDistanceDebug {
|
|
|
34
34
|
this.updateContainerVisibility();
|
|
35
35
|
};
|
|
36
36
|
this.onRendering = (renderer) => {
|
|
37
|
+
// Also on creation: a constraint is announced before its orientation is set
|
|
38
|
+
this.updateContainerVisibility();
|
|
37
39
|
const tintDirty = this.tint.dirty;
|
|
38
40
|
if (tintDirty) {
|
|
39
41
|
this.tint.toThreeColor(this.lineMaterial.color);
|
|
@@ -43,7 +45,7 @@ export class UIVerticalDistanceDebug {
|
|
|
43
45
|
this.spriteMaterial.opacity = this.tint.a;
|
|
44
46
|
this.tint.setDirtyFalse();
|
|
45
47
|
}
|
|
46
|
-
renderer
|
|
48
|
+
updateDebugResolution(renderer);
|
|
47
49
|
this.lineMaterial.resolution.copy(debugResolutionVector);
|
|
48
50
|
this.tickMaterial.resolution.copy(debugResolutionVector);
|
|
49
51
|
const elementA = this.constraint.a;
|
|
@@ -61,10 +63,7 @@ export class UIVerticalDistanceDebug {
|
|
|
61
63
|
: elementB instanceof UILayer
|
|
62
64
|
? anchorAX
|
|
63
65
|
: (anchorAX + anchorBX) / 2;
|
|
64
|
-
this.lineGeometry.
|
|
65
|
-
new Vector3(midX, anchorAY, 0),
|
|
66
|
-
new Vector3(midX, anchorBY, 0),
|
|
67
|
-
]);
|
|
66
|
+
this.lineGeometry.setPositions([midX, anchorAY, 0, midX, anchorBY, 0]);
|
|
68
67
|
const tickSize = 10;
|
|
69
68
|
this.tickGeometry.setPositions([
|
|
70
69
|
midX - tickSize,
|
|
@@ -134,6 +133,9 @@ export class UIVerticalDistanceDebug {
|
|
|
134
133
|
this.lineGeometry.dispose();
|
|
135
134
|
this.tickGeometry.dispose();
|
|
136
135
|
this.textTexture.dispose();
|
|
136
|
+
this.lineMaterial.dispose();
|
|
137
|
+
this.tickMaterial.dispose();
|
|
138
|
+
this.spriteMaterial.dispose();
|
|
137
139
|
}
|
|
138
140
|
updateContainerVisibility() {
|
|
139
141
|
const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CanvasTexture, Object3D, Sprite, SpriteMaterial
|
|
1
|
+
import { CanvasTexture, Object3D, Sprite, SpriteMaterial } from "three";
|
|
2
2
|
import { Line2 } from "three/addons/lines/Line2.js";
|
|
3
3
|
import { LineGeometry } from "three/addons/lines/LineGeometry.js";
|
|
4
4
|
import { LineMaterial } from "three/addons/lines/LineMaterial.js";
|
|
5
5
|
import { UIColor, UIOrientation } from "../core/index.js";
|
|
6
6
|
import { isUIPlaneElement } from "../core/miscellaneous/shared.js";
|
|
7
|
-
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, } from "./miscellaneous.js";
|
|
7
|
+
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, updateDebugResolution, } from "./miscellaneous.js";
|
|
8
8
|
export class UIVerticalInterpolationDebug {
|
|
9
9
|
constructor(constraint) {
|
|
10
10
|
this.constraint = constraint;
|
|
@@ -32,6 +32,8 @@ export class UIVerticalInterpolationDebug {
|
|
|
32
32
|
this.updateContainerVisibility();
|
|
33
33
|
};
|
|
34
34
|
this.onRendering = (renderer) => {
|
|
35
|
+
// Also on creation: a constraint is announced before its orientation is set
|
|
36
|
+
this.updateContainerVisibility();
|
|
35
37
|
const tintDirty = this.tint.dirty;
|
|
36
38
|
if (tintDirty) {
|
|
37
39
|
this.tint.toThreeColor(this.baseLineMaterial.color);
|
|
@@ -41,7 +43,7 @@ export class UIVerticalInterpolationDebug {
|
|
|
41
43
|
this.spriteMaterial.opacity = this.tint.a;
|
|
42
44
|
this.tint.setDirtyFalse();
|
|
43
45
|
}
|
|
44
|
-
renderer
|
|
46
|
+
updateDebugResolution(renderer);
|
|
45
47
|
this.baseLineMaterial.resolution.copy(debugResolutionVector);
|
|
46
48
|
this.markerMaterial.resolution.copy(debugResolutionVector);
|
|
47
49
|
const elementA = this.constraint.a;
|
|
@@ -59,14 +61,15 @@ export class UIVerticalInterpolationDebug {
|
|
|
59
61
|
? elementC.y + elementC.height * this.constraint.anchorC
|
|
60
62
|
: elementC.y;
|
|
61
63
|
const midX = (anchorAX + anchorBX) / 2;
|
|
62
|
-
this.baseLineGeometry.
|
|
63
|
-
new Vector3(midX, anchorAY, 0),
|
|
64
|
-
new Vector3(midX, anchorBY, 0),
|
|
65
|
-
]);
|
|
64
|
+
this.baseLineGeometry.setPositions([midX, anchorAY, 0, midX, anchorBY, 0]);
|
|
66
65
|
const markerSize = 12;
|
|
67
|
-
this.markerGeometry.
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
this.markerGeometry.setPositions([
|
|
67
|
+
midX - markerSize,
|
|
68
|
+
anchorCY,
|
|
69
|
+
0,
|
|
70
|
+
midX + markerSize,
|
|
71
|
+
anchorCY,
|
|
72
|
+
0,
|
|
70
73
|
]);
|
|
71
74
|
const nextText = "vi: " + this.constraint.t.toFixed(2);
|
|
72
75
|
if (nextText !== this.lastRenderedText || tintDirty) {
|
|
@@ -122,6 +125,9 @@ export class UIVerticalInterpolationDebug {
|
|
|
122
125
|
this.baseLineGeometry.dispose();
|
|
123
126
|
this.markerGeometry.dispose();
|
|
124
127
|
this.textTexture.dispose();
|
|
128
|
+
this.baseLineMaterial.dispose();
|
|
129
|
+
this.markerMaterial.dispose();
|
|
130
|
+
this.spriteMaterial.dispose();
|
|
125
131
|
}
|
|
126
132
|
updateContainerVisibility() {
|
|
127
133
|
const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CanvasTexture, Object3D, Sprite, SpriteMaterial
|
|
1
|
+
import { CanvasTexture, Object3D, Sprite, SpriteMaterial } from "three";
|
|
2
2
|
import { Line2 } from "three/addons/lines/Line2.js";
|
|
3
3
|
import { LineGeometry } from "three/addons/lines/LineGeometry.js";
|
|
4
4
|
import { LineMaterial } from "three/addons/lines/LineMaterial.js";
|
|
5
5
|
import { UIColor, UIOrientation } from "../core/index.js";
|
|
6
|
-
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, } from "./miscellaneous.js";
|
|
6
|
+
import { DEBUG_BADGE_BACKGROUND_COLOR, DEBUG_BADGE_FONT_FAMILY, DEBUG_BADGE_FONT_SIZE, DEBUG_BADGE_SIZE, DEBUG_LINE_WIDTH, DEBUG_RENDER_ORDER, debugResolutionVector, updateDebugResolution, } from "./miscellaneous.js";
|
|
7
7
|
export class UIWidthDebug {
|
|
8
8
|
constructor(constraint) {
|
|
9
9
|
this.constraint = constraint;
|
|
@@ -23,6 +23,8 @@ export class UIWidthDebug {
|
|
|
23
23
|
this.updateContainerVisibility();
|
|
24
24
|
};
|
|
25
25
|
this.onRendering = (renderer) => {
|
|
26
|
+
// Also on creation: a constraint is announced before its orientation is set
|
|
27
|
+
this.updateContainerVisibility();
|
|
26
28
|
const tintDirty = this.tint.dirty;
|
|
27
29
|
if (tintDirty) {
|
|
28
30
|
this.tint.toThreeColor(this.lineMaterial.color);
|
|
@@ -30,13 +32,13 @@ export class UIWidthDebug {
|
|
|
30
32
|
this.spriteMaterial.opacity = this.tint.a;
|
|
31
33
|
this.tint.setDirtyFalse();
|
|
32
34
|
}
|
|
33
|
-
renderer
|
|
35
|
+
updateDebugResolution(renderer);
|
|
34
36
|
this.lineMaterial.resolution.copy(debugResolutionVector);
|
|
35
37
|
const { x, y, oppositeX, width, centerX, centerY } = this.constraint.element;
|
|
36
38
|
if (width <= 0) {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
|
-
this.lineGeometry.
|
|
41
|
+
this.lineGeometry.setPositions([x, y, 0, oppositeX, y, 0]);
|
|
40
42
|
const nextText = "W: " + width.toFixed(0);
|
|
41
43
|
if (nextText !== this.lastRenderedText || tintDirty) {
|
|
42
44
|
this.drawText(nextText);
|
|
@@ -88,6 +90,8 @@ export class UIWidthDebug {
|
|
|
88
90
|
this.constraint.layer.sceneWrapper.removeCustomObject(this.container);
|
|
89
91
|
this.lineGeometry.dispose();
|
|
90
92
|
this.textTexture.dispose();
|
|
93
|
+
this.lineMaterial.dispose();
|
|
94
|
+
this.spriteMaterial.dispose();
|
|
91
95
|
}
|
|
92
96
|
updateContainerVisibility() {
|
|
93
97
|
const orientationActive = this.constraint.orientation === UIOrientation.ALWAYS ||
|
package/dist/debug/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export type { UIConstraintDebug } from "./UIConstraintDebug.js";
|
|
|
3
3
|
export { UIHeightDebug } from "./UIHeightDebug.js";
|
|
4
4
|
export { UIHorizontalDistanceDebug } from "./UIHorizontalDistanceDebug.js";
|
|
5
5
|
export { UIHorizontalInterpolationDebug } from "./UIHorizontalInterpolationDebug.js";
|
|
6
|
-
export { UILayerDebug } from "./UILayerDebug.js";
|
|
7
6
|
export type { UILayerDebugOptions } from "./UILayerDebug.js";
|
|
7
|
+
export { UILayerDebug } from "./UILayerDebug.js";
|
|
8
8
|
export { UIVerticalDistanceDebug } from "./UIVerticalDistanceDebug.js";
|
|
9
9
|
export { UIVerticalInterpolationDebug } from "./UIVerticalInterpolationDebug.js";
|
|
10
10
|
export { UIWidthDebug } from "./UIWidthDebug.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WebGLRenderer } from "three";
|
|
1
2
|
import { Vector2 } from "three";
|
|
2
3
|
export declare const DEBUG_RENDER_ORDER = 8192;
|
|
3
4
|
export declare const DEBUG_LINE_WIDTH = 2;
|
|
@@ -6,3 +7,9 @@ export declare const DEBUG_BADGE_FONT_SIZE = 30;
|
|
|
6
7
|
export declare const DEBUG_BADGE_FONT_FAMILY = "monospace";
|
|
7
8
|
export declare const DEBUG_BADGE_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.8)";
|
|
8
9
|
export declare const debugResolutionVector: Vector2;
|
|
10
|
+
/**
|
|
11
|
+
* Sets `debugResolutionVector` to the size of the current viewport, the value three.js 0.165 and
|
|
12
|
+
* later write into `LineMaterial.resolution` before each draw. Earlier versions keep the value
|
|
13
|
+
* set here, so line widths are the same on every version.
|
|
14
|
+
*/
|
|
15
|
+
export declare function updateDebugResolution(renderer: WebGLRenderer): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector2 } from "three";
|
|
1
|
+
import { Vector2, Vector4 } from "three";
|
|
2
2
|
export const DEBUG_RENDER_ORDER = 8192;
|
|
3
3
|
export const DEBUG_LINE_WIDTH = 2;
|
|
4
4
|
export const DEBUG_BADGE_SIZE = 150;
|
|
@@ -6,3 +6,13 @@ export const DEBUG_BADGE_FONT_SIZE = 30;
|
|
|
6
6
|
export const DEBUG_BADGE_FONT_FAMILY = "monospace";
|
|
7
7
|
export const DEBUG_BADGE_BACKGROUND_COLOR = "rgba(0, 0, 0, 0.8)";
|
|
8
8
|
export const debugResolutionVector = new Vector2();
|
|
9
|
+
const debugViewport = new Vector4();
|
|
10
|
+
/**
|
|
11
|
+
* Sets `debugResolutionVector` to the size of the current viewport, the value three.js 0.165 and
|
|
12
|
+
* later write into `LineMaterial.resolution` before each draw. Earlier versions keep the value
|
|
13
|
+
* set here, so line widths are the same on every version.
|
|
14
|
+
*/
|
|
15
|
+
export function updateDebugResolution(renderer) {
|
|
16
|
+
renderer.getViewport(debugViewport);
|
|
17
|
+
debugResolutionVector.set(debugViewport.z, debugViewport.w);
|
|
18
|
+
}
|
|
@@ -17,7 +17,7 @@ export declare class UIBehaviorDirectionalGravity extends UIBehaviorModule<{
|
|
|
17
17
|
/**
|
|
18
18
|
* @param direction - Acceleration vector in units/second^2
|
|
19
19
|
*/
|
|
20
|
-
constructor(direction:
|
|
20
|
+
constructor(direction: UIVector2Config);
|
|
21
21
|
/** Acceleration vector in units/second^2 */
|
|
22
22
|
get direction(): Vector2Like;
|
|
23
23
|
/** Acceleration vector in units/second^2 */
|
|
@@ -12,9 +12,13 @@ export declare abstract class UIBehaviorModule<T extends Record<string, UIProper
|
|
|
12
12
|
/**
|
|
13
13
|
* Advances the particles in [0, instanceCount) by deltaTime seconds.
|
|
14
14
|
* @param properties Per-particle buffers of the required properties
|
|
15
|
+
* @param instanceCount Number of live particles
|
|
16
|
+
* @param deltaTime Frame step in seconds
|
|
17
|
+
* @param randomSalt Salt for `particleRandomStream`: random values of the module are
|
|
18
|
+
* independent of those of other modules, also of another instance of the same module
|
|
15
19
|
*/
|
|
16
20
|
abstract update(properties: {
|
|
17
21
|
[K in keyof T]: InstancedBufferAttribute;
|
|
18
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
22
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
19
23
|
destroy?(): void;
|
|
20
24
|
}
|
|
@@ -23,7 +23,7 @@ export declare class UIBehaviorPointGravity extends UIBehaviorModule<{
|
|
|
23
23
|
* @param exponent - Distance power exponent range. Accepts number, tuple, or range object
|
|
24
24
|
* @param threshold - Minimum distance range. Accepts number, tuple, or range object
|
|
25
25
|
*/
|
|
26
|
-
constructor(center:
|
|
26
|
+
constructor(center: UIVector2Config, strength: UIRangeConfig, exponent?: UIRangeConfig, threshold?: UIRangeConfig);
|
|
27
27
|
/** Gravity center position */
|
|
28
28
|
get center(): Vector2Like;
|
|
29
29
|
/** Force multiplier range */
|
|
@@ -42,5 +42,5 @@ export declare class UIBehaviorPointGravity extends UIBehaviorModule<{
|
|
|
42
42
|
set threshold(value: UIRangeConfig);
|
|
43
43
|
update(properties: {
|
|
44
44
|
builtin: InstancedBufferAttribute;
|
|
45
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
45
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
|
-
import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
|
|
3
|
-
import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y,
|
|
2
|
+
import { assertValidNumber, assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
|
|
3
|
+
import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
|
|
4
4
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
5
|
/**
|
|
6
6
|
* Applies gravity attraction toward a point.
|
|
@@ -27,8 +27,8 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
|
|
|
27
27
|
assertValidNumber(this.exponentInternal.min, "UIBehaviorPointGravity.constructor.exponent.min");
|
|
28
28
|
assertValidNumber(this.exponentInternal.max, "UIBehaviorPointGravity.constructor.exponent.max");
|
|
29
29
|
this.thresholdInternal = resolveUIRangeConfig(threshold);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
assertValidPositiveNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.constructor.threshold.min");
|
|
31
|
+
assertValidPositiveNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.constructor.threshold.max");
|
|
32
32
|
}
|
|
33
33
|
/** Gravity center position */
|
|
34
34
|
get center() {
|
|
@@ -67,26 +67,29 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
|
|
|
67
67
|
/** Minimum distance range */
|
|
68
68
|
set threshold(value) {
|
|
69
69
|
this.thresholdInternal = resolveUIRangeConfig(value);
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
assertValidPositiveNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
|
|
71
|
+
assertValidPositiveNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
|
|
72
72
|
}
|
|
73
|
-
update(properties, instanceCount, deltaTime) {
|
|
73
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
74
74
|
const { builtin } = properties;
|
|
75
75
|
const { array, itemSize } = builtin;
|
|
76
|
+
const thresholdStream = particleRandomStream(randomSalt, 0);
|
|
77
|
+
const strengthStream = particleRandomStream(randomSalt, 1);
|
|
78
|
+
const exponentStream = particleRandomStream(randomSalt, 2);
|
|
76
79
|
for (let i = 0; i < instanceCount; i++) {
|
|
77
80
|
const itemOffset = i * itemSize;
|
|
78
81
|
const dx = this.centerInternal.x - array[itemOffset + BUILTIN_OFFSET_POSITION_X];
|
|
79
82
|
const dy = this.centerInternal.y - array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
|
|
80
|
-
const thresholdT = array
|
|
83
|
+
const thresholdT = particleRandom(array, itemOffset, thresholdStream);
|
|
81
84
|
const threshold = MathUtils.lerp(this.threshold.min, this.threshold.max, thresholdT);
|
|
82
85
|
const thresholdSquared = threshold * threshold;
|
|
83
86
|
const distanceSquared = dx * dx + dy * dy;
|
|
84
87
|
if (distanceSquared < thresholdSquared) {
|
|
85
88
|
continue;
|
|
86
89
|
}
|
|
87
|
-
const strengthT = array
|
|
90
|
+
const strengthT = particleRandom(array, itemOffset, strengthStream);
|
|
88
91
|
const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
|
|
89
|
-
const exponentT = array
|
|
92
|
+
const exponentT = particleRandom(array, itemOffset, exponentStream);
|
|
90
93
|
const exponent = MathUtils.lerp(this.exponentInternal.min, this.exponentInternal.max, exponentT);
|
|
91
94
|
const distance = Math.sqrt(distanceSquared);
|
|
92
95
|
const forceMagnitude = strength / Math.pow(distance, exponent);
|
|
@@ -44,5 +44,5 @@ export declare class UIBehaviorScaleOscillation extends UIBehaviorModule<{
|
|
|
44
44
|
set aspect(value: UIAspectConfig);
|
|
45
45
|
update(properties: {
|
|
46
46
|
builtin: InstancedBufferAttribute;
|
|
47
|
-
}, instanceCount: number): void;
|
|
47
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
48
48
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
2
|
import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
|
|
3
|
-
import { BUILTIN_OFFSET_AGE,
|
|
3
|
+
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
4
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
5
|
/**
|
|
6
6
|
* Oscillates particle scale along one axis, like a paper piece turning its edge to the viewer.
|
|
@@ -61,14 +61,16 @@ export class UIBehaviorScaleOscillation extends UIBehaviorModule {
|
|
|
61
61
|
this.aspectInternal = resolveAspect(value);
|
|
62
62
|
assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOscillation.aspect");
|
|
63
63
|
}
|
|
64
|
-
update(properties, instanceCount) {
|
|
64
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
65
65
|
const { builtin } = properties;
|
|
66
66
|
const { array, itemSize } = builtin;
|
|
67
|
+
const frequencyStream = particleRandomStream(randomSalt, 0);
|
|
68
|
+
const phaseStream = particleRandomStream(randomSalt, 1);
|
|
67
69
|
for (let i = 0; i < instanceCount; i++) {
|
|
68
70
|
const itemOffset = i * itemSize;
|
|
69
|
-
const frequencyT = array
|
|
71
|
+
const frequencyT = particleRandom(array, itemOffset, frequencyStream);
|
|
70
72
|
const frequency = MathUtils.lerp(this.frequencyInternal.min, this.frequencyInternal.max, frequencyT);
|
|
71
|
-
const phase = array
|
|
73
|
+
const phase = particleRandom(array, itemOffset, phaseStream) * Math.PI * 2;
|
|
72
74
|
const angle = array[itemOffset + BUILTIN_OFFSET_AGE] * frequency * Math.PI * 2 + phase;
|
|
73
75
|
const factor = 1 - this.depthInternal * (1 - Math.cos(angle));
|
|
74
76
|
if (this.axisInternal === "x") {
|
|
@@ -25,5 +25,5 @@ export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
|
|
|
25
25
|
set aspect(value: UIAspectConfig);
|
|
26
26
|
update(properties: {
|
|
27
27
|
builtin: InstancedBufferAttribute;
|
|
28
|
-
}, instanceCount: number): void;
|
|
28
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
29
29
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
2
|
import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
|
|
3
|
-
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME,
|
|
3
|
+
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
4
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
5
|
/**
|
|
6
6
|
* Animates particle scale over lifetime.
|
|
@@ -37,15 +37,16 @@ export class UIBehaviorScaleOverLife extends UIBehaviorModule {
|
|
|
37
37
|
this.aspectInternal = resolveAspect(value);
|
|
38
38
|
assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOverLife.aspect");
|
|
39
39
|
}
|
|
40
|
-
update(properties, instanceCount) {
|
|
40
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
41
41
|
const { builtin } = properties;
|
|
42
42
|
const { array, itemSize } = builtin;
|
|
43
|
+
const scaleStream = particleRandomStream(randomSalt, 0);
|
|
43
44
|
for (let i = 0; i < instanceCount; i++) {
|
|
44
45
|
const itemOffset = i * itemSize;
|
|
45
46
|
const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
|
|
46
47
|
const segment = (this.scales.length - 1) * lifeT;
|
|
47
48
|
const index = Math.floor(segment);
|
|
48
|
-
const scaleT = array
|
|
49
|
+
const scaleT = particleRandom(array, itemOffset, scaleStream);
|
|
49
50
|
const localT = segment - index;
|
|
50
51
|
const scaleRange0 = this.scales[index];
|
|
51
52
|
const scaleRange1 = this.scales[index + 1];
|
|
@@ -16,12 +16,12 @@ export declare class UIBehaviorTorqueDamping extends UIBehaviorModule<{
|
|
|
16
16
|
/**
|
|
17
17
|
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
18
18
|
*/
|
|
19
|
-
constructor(damping:
|
|
19
|
+
constructor(damping: UIRangeConfig);
|
|
20
20
|
/** Damping coefficient range (0-1) */
|
|
21
21
|
get damping(): UIRange;
|
|
22
22
|
/** Damping coefficient range (0-1) */
|
|
23
23
|
set damping(value: UIRangeConfig);
|
|
24
24
|
update(properties: {
|
|
25
25
|
builtin: InstancedBufferAttribute;
|
|
26
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
26
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
27
27
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
|
-
import {
|
|
3
|
-
import { BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_TORQUE, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
2
|
+
import { assertValidUnitNumber, BUILTIN_OFFSET_TORQUE, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
3
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
4
|
/**
|
|
6
5
|
* Reduces particle angular velocity over time.
|
|
@@ -15,8 +14,8 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
|
|
|
15
14
|
super();
|
|
16
15
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
17
16
|
this.dampingInternal = resolveUIRangeConfig(damping);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.constructor.damping.min`);
|
|
18
|
+
assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.constructor.damping.max`);
|
|
20
19
|
}
|
|
21
20
|
/** Damping coefficient range (0-1) */
|
|
22
21
|
get damping() {
|
|
@@ -25,15 +24,16 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
|
|
|
25
24
|
/** Damping coefficient range (0-1) */
|
|
26
25
|
set damping(value) {
|
|
27
26
|
this.dampingInternal = resolveUIRangeConfig(value);
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
|
|
28
|
+
assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
|
|
30
29
|
}
|
|
31
|
-
update(properties, instanceCount, deltaTime) {
|
|
30
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
32
31
|
const { builtin } = properties;
|
|
33
32
|
const { array, itemSize } = builtin;
|
|
33
|
+
const dampingStream = particleRandomStream(randomSalt, 0);
|
|
34
34
|
for (let i = 0; i < instanceCount; i++) {
|
|
35
35
|
const itemOffset = i * itemSize;
|
|
36
|
-
const dampingT = array
|
|
36
|
+
const dampingT = particleRandom(array, itemOffset, dampingStream);
|
|
37
37
|
const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
|
|
38
38
|
array[itemOffset + BUILTIN_OFFSET_TORQUE] *= dampingFactor;
|
|
39
39
|
}
|
|
@@ -4,7 +4,8 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Applies noise-based angular acceleration to particles.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
|
|
8
|
+
* detail in layer units; around 0.005 gives a smooth change over a few hundred units.
|
|
8
9
|
*/
|
|
9
10
|
export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
|
|
10
11
|
builtin: "Matrix4";
|
|
@@ -18,7 +19,7 @@ export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
|
|
|
18
19
|
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
19
20
|
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
20
21
|
*/
|
|
21
|
-
constructor(scale:
|
|
22
|
+
constructor(scale: UIRangeConfig, strength: UIRangeConfig);
|
|
22
23
|
/** Noise frequency range */
|
|
23
24
|
get scale(): UIRange;
|
|
24
25
|
/** Force multiplier range */
|
|
@@ -29,5 +30,5 @@ export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
|
|
|
29
30
|
set strength(value: UIRangeConfig);
|
|
30
31
|
update(properties: {
|
|
31
32
|
builtin: InstancedBufferAttribute;
|
|
32
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
33
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
33
34
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
2
|
import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
|
|
3
|
-
import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y,
|
|
3
|
+
import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_TORQUE, generateNoise2D, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
4
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
5
|
/**
|
|
6
6
|
* Applies noise-based angular acceleration to particles.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
|
|
9
|
+
* detail in layer units; around 0.005 gives a smooth change over a few hundred units.
|
|
9
10
|
*/
|
|
10
11
|
export class UIBehaviorTorqueNoise extends UIBehaviorModule {
|
|
11
12
|
/**
|
|
@@ -42,15 +43,17 @@ export class UIBehaviorTorqueNoise extends UIBehaviorModule {
|
|
|
42
43
|
assertValidNonNegativeNumber(this.strengthInternal.min, `UIBehaviorTorqueNoise.strength.min`);
|
|
43
44
|
assertValidNonNegativeNumber(this.strengthInternal.max, `UIBehaviorTorqueNoise.strength.max`);
|
|
44
45
|
}
|
|
45
|
-
update(properties, instanceCount, deltaTime) {
|
|
46
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
46
47
|
const { builtin } = properties;
|
|
47
48
|
const { array, itemSize } = builtin;
|
|
49
|
+
const scaleStream = particleRandomStream(randomSalt, 0);
|
|
50
|
+
const strengthStream = particleRandomStream(randomSalt, 1);
|
|
48
51
|
for (let i = 0; i < instanceCount; i++) {
|
|
49
52
|
const itemOffset = i * itemSize;
|
|
50
|
-
const scaleT = array
|
|
53
|
+
const scaleT = particleRandom(array, itemOffset, scaleStream);
|
|
51
54
|
const scale = MathUtils.lerp(this.scaleInternal.min, this.scaleInternal.max, scaleT);
|
|
52
55
|
const noise = generateNoise2D(array[itemOffset + BUILTIN_OFFSET_POSITION_X] * scale, array[itemOffset + BUILTIN_OFFSET_POSITION_Y] * scale);
|
|
53
|
-
const strengthT = array
|
|
56
|
+
const strengthT = particleRandom(array, itemOffset, strengthStream);
|
|
54
57
|
const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
|
|
55
58
|
array[itemOffset + BUILTIN_OFFSET_TORQUE] += noise * strength * deltaTime;
|
|
56
59
|
}
|
|
@@ -23,5 +23,5 @@ export declare class UIBehaviorVelocityDamping extends UIBehaviorModule<{
|
|
|
23
23
|
set damping(value: UIRangeConfig);
|
|
24
24
|
update(properties: {
|
|
25
25
|
builtin: InstancedBufferAttribute;
|
|
26
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
26
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
27
27
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MathUtils } from "three";
|
|
2
|
-
import {
|
|
3
|
-
import { BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
2
|
+
import { assertValidUnitNumber, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
3
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
5
4
|
/**
|
|
6
5
|
* Reduces particle velocity over time.
|
|
@@ -15,8 +14,8 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
|
|
|
15
14
|
super();
|
|
16
15
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
17
16
|
this.dampingInternal = resolveUIRangeConfig(damping);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.constructor.damping.min`);
|
|
18
|
+
assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.constructor.damping.max`);
|
|
20
19
|
}
|
|
21
20
|
/** Damping coefficient range (0-1) */
|
|
22
21
|
get damping() {
|
|
@@ -25,15 +24,16 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
|
|
|
25
24
|
/** Damping coefficient range (0-1) */
|
|
26
25
|
set damping(value) {
|
|
27
26
|
this.dampingInternal = resolveUIRangeConfig(value);
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
|
|
28
|
+
assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
|
|
30
29
|
}
|
|
31
|
-
update(properties, instanceCount, deltaTime) {
|
|
30
|
+
update(properties, instanceCount, deltaTime, randomSalt) {
|
|
32
31
|
const { builtin } = properties;
|
|
33
32
|
const { array, itemSize } = builtin;
|
|
33
|
+
const dampingStream = particleRandomStream(randomSalt, 0);
|
|
34
34
|
for (let i = 0; i < instanceCount; i++) {
|
|
35
35
|
const itemOffset = i * itemSize;
|
|
36
|
-
const dampingT = array
|
|
36
|
+
const dampingT = particleRandom(array, itemOffset, dampingStream);
|
|
37
37
|
const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
|
|
38
38
|
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] *= dampingFactor;
|
|
39
39
|
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] *= dampingFactor;
|
|
@@ -2,9 +2,11 @@ import type { InstancedBufferAttribute } from "three";
|
|
|
2
2
|
import { type UIRange, type UIRangeConfig } from "../miscellaneous/miscellaneous.js";
|
|
3
3
|
import { UIBehaviorModule } from "./UIBehaviorModule.js";
|
|
4
4
|
/**
|
|
5
|
-
* Applies noise-based acceleration to particles.
|
|
5
|
+
* Applies noise-based acceleration to particles: a still flow field that particles drift through.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
|
|
8
|
+
* detail in layer units. A detail much smaller than the distance a particle moves in a frame
|
|
9
|
+
* turns the drift into jitter.
|
|
8
10
|
*/
|
|
9
11
|
export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
|
|
10
12
|
builtin: "Matrix4";
|
|
@@ -15,10 +17,10 @@ export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
|
|
|
15
17
|
private scaleInternal;
|
|
16
18
|
private strengthInternal;
|
|
17
19
|
/**
|
|
18
|
-
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
20
|
+
* @param scale - Noise frequency range in 1 / layer units. Accepts number, tuple, or range object
|
|
19
21
|
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
20
22
|
*/
|
|
21
|
-
constructor(scale?:
|
|
23
|
+
constructor(scale?: UIRangeConfig, strength?: UIRangeConfig);
|
|
22
24
|
/** Noise frequency range */
|
|
23
25
|
get scale(): UIRange;
|
|
24
26
|
/** Force multiplier range */
|
|
@@ -29,5 +31,5 @@ export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
|
|
|
29
31
|
set strength(value: UIRangeConfig);
|
|
30
32
|
update(properties: {
|
|
31
33
|
builtin: InstancedBufferAttribute;
|
|
32
|
-
}, instanceCount: number, deltaTime: number): void;
|
|
34
|
+
}, instanceCount: number, deltaTime: number, randomSalt: number): void;
|
|
33
35
|
}
|