laymur 0.25.2 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -34
- 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/UIAnchor/UIAnchor.d.ts +2 -2
- package/dist/core/elements/UIAnchor/UIAnchor.js +3 -2
- 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 +13 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +74 -5
- package/dist/core/elements/UIDummy/UIDummy.js +222 -29
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
- package/dist/core/elements/UIElement/UIElement.d.ts +37 -1
- package/dist/core/elements/UIElement/UIElement.js +84 -6
- 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 +4 -4
- 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 +17 -15
- 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 +21 -14
- 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 +8 -8
- package/dist/core/index.d.ts +60 -11
- package/dist/core/index.js +22 -7
- package/dist/core/layers/UILayer/UILayer.d.ts +45 -5
- package/dist/core/layers/UILayer/UILayer.js +103 -10
- 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/UIAffineMatrix3.d.ts +13 -0
- package/dist/core/miscellaneous/UIAffineMatrix3.js +13 -0
- package/dist/core/miscellaneous/area/UIArea.d.ts +10 -1
- package/dist/core/miscellaneous/area/UIArea.js +4 -1
- package/dist/core/miscellaneous/area/UIAreaCircle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaCircle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaPolygon.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaPolygon.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRectangle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.js +0 -1
- package/dist/core/miscellaneous/asserts.d.ts +23 -0
- package/dist/core/miscellaneous/asserts.js +44 -0
- package/dist/core/miscellaneous/canvas.js +7 -2
- package/dist/core/miscellaneous/color/UIColor.js +5 -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.d.ts +17 -3
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +88 -26
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.d.ts +9 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.js +29 -6
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +51 -11
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +2 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +47 -6
- package/dist/core/miscellaneous/generic-plane/shared.d.ts +15 -3
- package/dist/core/miscellaneous/generic-plane/shared.js +38 -7
- package/dist/core/miscellaneous/generic-plane/varyingPacking.d.ts +46 -0
- package/dist/core/miscellaneous/generic-plane/varyingPacking.js +170 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.d.ts +61 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.js +56 -0
- package/dist/core/miscellaneous/mask/UIMask.d.ts +84 -0
- package/dist/core/miscellaneous/mask/UIMask.js +265 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.d.ts +50 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +233 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +10 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.js +7 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +0 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js +0 -1
- package/dist/core/miscellaneous/micro/UIMicro.Internal.d.ts +3 -0
- package/dist/core/miscellaneous/micro/UIMicro.Internal.js +1 -0
- package/dist/core/miscellaneous/micro/UIMicro.d.ts +18 -1
- package/dist/core/miscellaneous/micro/UIMicro.js +23 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +19 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +16 -3
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
- 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.js +2 -2
- 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 +6 -2
- package/dist/core/miscellaneous/texture/UITextureView.js +13 -9
- 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/shaders/UIMask.d.ts +15 -0
- package/dist/core/shaders/UIMask.js +45 -0
- 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 +3 -1
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +1 -0
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +3 -0
- 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 +4 -0
- package/dist/debug/UIHeightDebug.js +4 -0
- package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
- package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
- package/dist/debug/UILayerDebug.d.ts +7 -0
- package/dist/debug/UILayerDebug.js +21 -0
- package/dist/debug/UIVerticalDistanceDebug.js +5 -0
- package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
- package/dist/debug/UIWidthDebug.js +4 -0
- package/dist/debug/index.d.ts +2 -0
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +0 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +12 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.js +2 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -12
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -6
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -5
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +10 -2
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -7
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +13 -4
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -10
- package/dist/particles/elements/UIEmitter.Internal.d.ts +21 -1
- package/dist/particles/elements/UIEmitter.Internal.js +6 -0
- package/dist/particles/elements/UIEmitter.d.ts +20 -11
- package/dist/particles/elements/UIEmitter.js +100 -54
- package/dist/particles/index.d.ts +7 -1
- package/dist/particles/index.js +4 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +19 -4
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +117 -83
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +8 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.js +41 -4
- package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
- package/dist/particles/miscellaneous/miscellaneous.js +72 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -4
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -5
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +11 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +4 -1
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +4 -0
- 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 +16 -1
- package/dist/particles/spawnModules/UISpawnModule.js +3 -1
- package/dist/particles/spawnModules/UISpawnOffset.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnOffset.js +0 -2
- package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +8 -1
- package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -7
- package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -5
- package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -6
- package/dist/particles/spawnModules/UISpawnRectangle.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRectangle.js +6 -6
- package/package.json +13 -4
- 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Matrix3 } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Matrix3 holding a 2D affine transform, such as a UV transform: its bottom row is taken as
|
|
4
|
+
* (0, 0, 1). As a shader property it is passed per instance as its six meaningful elements
|
|
5
|
+
* instead of nine, which saves a vertex attribute and a varying row on busy shaders. In GLSL
|
|
6
|
+
* it is still a mat3.
|
|
7
|
+
*
|
|
8
|
+
* The property keeps that layout for the lifetime of the element: a plain Matrix3 assigned to
|
|
9
|
+
* it later is read the same way, with its bottom row ignored. The other way round, a property
|
|
10
|
+
* created as a plain Matrix3 stays a full mat3 when a UIAffineMatrix3 is assigned to it.
|
|
11
|
+
*/
|
|
12
|
+
export declare class UIAffineMatrix3 extends Matrix3 {
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Matrix3 } from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Matrix3 holding a 2D affine transform, such as a UV transform: its bottom row is taken as
|
|
4
|
+
* (0, 0, 1). As a shader property it is passed per instance as its six meaningful elements
|
|
5
|
+
* instead of nine, which saves a vertex attribute and a varying row on busy shaders. In GLSL
|
|
6
|
+
* it is still a mat3.
|
|
7
|
+
*
|
|
8
|
+
* The property keeps that layout for the lifetime of the element: a plain Matrix3 assigned to
|
|
9
|
+
* it later is read the same way, with its bottom row ignored. The other way round, a property
|
|
10
|
+
* created as a plain Matrix3 stays a full mat3 when a UIAffineMatrix3 is assigned to it.
|
|
11
|
+
*/
|
|
12
|
+
export class UIAffineMatrix3 extends Matrix3 {
|
|
13
|
+
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Base class for interaction area shapes. Subclass it for a custom hit shape and assign it to
|
|
3
|
+
* `UIDummy.interactionArea`.
|
|
4
|
+
*/
|
|
2
5
|
export declare abstract class UIArea {
|
|
6
|
+
/**
|
|
7
|
+
* Whether a point hits the area.
|
|
8
|
+
* @param pointX X in element-local normalized space (0 = left edge, 1 = right edge)
|
|
9
|
+
* @param pointY Y in element-local normalized space (0 = bottom edge, 1 = top edge)
|
|
10
|
+
*/
|
|
11
|
+
abstract contains(pointX: number, pointY: number): boolean;
|
|
3
12
|
}
|
|
@@ -18,7 +18,6 @@ export class UIAreaCircle extends UIArea {
|
|
|
18
18
|
assertValidNonNegativeNumber(centerY, "UIAreaCircle.constructor.centerY");
|
|
19
19
|
assertValidNonNegativeNumber(radius, "UIAreaCircle.constructor.radius");
|
|
20
20
|
}
|
|
21
|
-
/** @internal */
|
|
22
21
|
contains(pointX, pointY) {
|
|
23
22
|
assertValidNumber(pointX, "UIAreaCircle.contains.pointX");
|
|
24
23
|
assertValidNumber(pointY, "UIAreaCircle.contains.pointY");
|
|
@@ -11,7 +11,6 @@ export class UIAreaPolygon extends UIArea {
|
|
|
11
11
|
super();
|
|
12
12
|
this.vertices = vertices;
|
|
13
13
|
}
|
|
14
|
-
/** @internal */
|
|
15
14
|
contains(pointX, pointY) {
|
|
16
15
|
assertValidNumber(pointX, "UIAreaPolygon.contains.pointX");
|
|
17
16
|
assertValidNumber(pointY, "UIAreaPolygon.contains.pointY");
|
|
@@ -21,7 +21,6 @@ export class UIAreaRectangle extends UIArea {
|
|
|
21
21
|
assertValidNonNegativeNumber(width, "UIAreaRectangle.constructor.width");
|
|
22
22
|
assertValidNonNegativeNumber(height, "UIAreaRectangle.constructor.height");
|
|
23
23
|
}
|
|
24
|
-
/** @internal */
|
|
25
24
|
contains(pointX, pointY) {
|
|
26
25
|
assertValidNumber(pointX, "UIAreaRectangle.contains.pointX");
|
|
27
26
|
assertValidNumber(pointY, "UIAreaRectangle.contains.pointY");
|
|
@@ -18,4 +18,5 @@ export declare class UIAreaRoundedRectangle extends UIArea {
|
|
|
18
18
|
* @param radius - Corner radius in normalized coordinates (0 to 1)
|
|
19
19
|
*/
|
|
20
20
|
constructor(x: number, y: number, width: number, height: number, radius: number);
|
|
21
|
+
contains(pointX: number, pointY: number): boolean;
|
|
21
22
|
}
|
|
@@ -27,7 +27,6 @@ export class UIAreaRoundedRectangle extends UIArea {
|
|
|
27
27
|
assertValidNonNegativeNumber(radius, "UIAreaRoundedRectangle.constructor.radius");
|
|
28
28
|
this.radius = Math.min(radius, Math.min(width, height) / 2);
|
|
29
29
|
}
|
|
30
|
-
/** @internal */
|
|
31
30
|
contains(pointX, pointY) {
|
|
32
31
|
assertValidNumber(pointX, "UIAreaRoundedRectangle.contains.pointX");
|
|
33
32
|
assertValidNumber(pointY, "UIAreaRoundedRectangle.contains.pointY");
|
|
@@ -18,6 +18,15 @@ export declare function assertValidNumber(value: number, subject: string): void;
|
|
|
18
18
|
* @throws If required exceeds the renderer's MAX_VERTEX_ATTRIBS
|
|
19
19
|
*/
|
|
20
20
|
export declare function assertVertexAttributeBudget(renderer: WebGLRenderer, required: number, subject: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Validates a shader fits the varying budget of the device. Like an attribute overflow, a
|
|
23
|
+
* program over the budget fails to link, which three.js only logs, and its mesh is not drawn.
|
|
24
|
+
* @param renderer Renderer the shader is drawn with
|
|
25
|
+
* @param required Number of varying rows (vec4 locations) the shader uses
|
|
26
|
+
* @param subject Value name for error messages
|
|
27
|
+
* @throws If required exceeds the renderer's MAX_VARYING_VECTORS
|
|
28
|
+
*/
|
|
29
|
+
export declare function assertVaryingBudget(renderer: WebGLRenderer, required: number, subject: string): void;
|
|
21
30
|
/**
|
|
22
31
|
* Validates value is positive (>= EPSILON).
|
|
23
32
|
* @param value Number to validate
|
|
@@ -70,3 +79,17 @@ export declare function assertValidConstraintElement(element: UILayerElement, su
|
|
|
70
79
|
* @throws If the layer is destroyed or a variable does not exist
|
|
71
80
|
*/
|
|
72
81
|
export declare function assertValidConstraintExpressions(layer: UILayer, expressions: UIExpression[], subject: string): UILayer;
|
|
82
|
+
/**
|
|
83
|
+
* Validates value is within [0, 1].
|
|
84
|
+
* @param value Number to validate
|
|
85
|
+
* @param subject Value name for error messages
|
|
86
|
+
* @throws If value is invalid or outside [0, 1]
|
|
87
|
+
*/
|
|
88
|
+
export declare function assertValidUnitNumber(value: number, subject: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Validates value is a non-negative integer.
|
|
91
|
+
* @param value Number to validate
|
|
92
|
+
* @param subject Value name for error messages
|
|
93
|
+
* @throws If value is invalid, negative or fractional
|
|
94
|
+
*/
|
|
95
|
+
export declare function assertValidNonNegativeInteger(value: number, subject: string): void;
|
|
@@ -33,6 +33,22 @@ export function assertVertexAttributeBudget(renderer, required, subject) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Validates a shader fits the varying budget of the device. Like an attribute overflow, a
|
|
38
|
+
* program over the budget fails to link, which three.js only logs, and its mesh is not drawn.
|
|
39
|
+
* @param renderer Renderer the shader is drawn with
|
|
40
|
+
* @param required Number of varying rows (vec4 locations) the shader uses
|
|
41
|
+
* @param subject Value name for error messages
|
|
42
|
+
* @throws If required exceeds the renderer's MAX_VARYING_VECTORS
|
|
43
|
+
*/
|
|
44
|
+
export function assertVaryingBudget(renderer, required, subject) {
|
|
45
|
+
if (process.env.NODE_ENV !== "production") {
|
|
46
|
+
const available = renderer.capabilities.maxVaryings;
|
|
47
|
+
if (required > available) {
|
|
48
|
+
throw new Error(`${subject}: shader needs ${required} varying vectors, the device supports ${available}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
36
52
|
/**
|
|
37
53
|
* Validates value is positive (>= EPSILON).
|
|
38
54
|
* @param value Number to validate
|
|
@@ -229,3 +245,31 @@ function assertNotDestroyed(value, name, subject) {
|
|
|
229
245
|
throw new Error(`${subject}: ${name} is destroyed`);
|
|
230
246
|
}
|
|
231
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Validates value is within [0, 1].
|
|
250
|
+
* @param value Number to validate
|
|
251
|
+
* @param subject Value name for error messages
|
|
252
|
+
* @throws If value is invalid or outside [0, 1]
|
|
253
|
+
*/
|
|
254
|
+
export function assertValidUnitNumber(value, subject) {
|
|
255
|
+
if (process.env.NODE_ENV !== "production") {
|
|
256
|
+
assertValidNumber(value, subject);
|
|
257
|
+
if (value < 0 || value > 1) {
|
|
258
|
+
throw new Error(`${subject}: value must be between 0 and 1, got ${value}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Validates value is a non-negative integer.
|
|
264
|
+
* @param value Number to validate
|
|
265
|
+
* @param subject Value name for error messages
|
|
266
|
+
* @throws If value is invalid, negative or fractional
|
|
267
|
+
*/
|
|
268
|
+
export function assertValidNonNegativeInteger(value, subject) {
|
|
269
|
+
if (process.env.NODE_ENV !== "production") {
|
|
270
|
+
assertValidNonNegativeNumber(value, subject);
|
|
271
|
+
if (!Number.isInteger(value)) {
|
|
272
|
+
throw new Error(`${subject}: value must be an integer, got ${value}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanvasTexture, ClampToEdgeWrapping, LinearFilter,
|
|
1
|
+
import { CanvasTexture, ClampToEdgeWrapping, LinearFilter, NoColorSpace, RGBAFormat, SRGBColorSpace, UnsignedByteType, UVMapping, } from "three";
|
|
2
2
|
import { checkOffscreenCanvasSupport, checkSRGBSupport } from "./webglCapabilities.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a canvas using OffscreenCanvas if available, otherwise falls back to HTMLCanvasElement.
|
|
@@ -23,7 +23,12 @@ export function createCanvas(width, height) {
|
|
|
23
23
|
* @returns 2D rendering context or null
|
|
24
24
|
*/
|
|
25
25
|
export function getCanvas2DContext(canvas) {
|
|
26
|
-
|
|
26
|
+
// Each branch calls getContext on a concrete type: on the union, TypeScript picks the overload
|
|
27
|
+
// depending on the order it checks types in, and may return the generic RenderingContext
|
|
28
|
+
return isOffscreenCanvas(canvas) ? canvas.getContext("2d") : canvas.getContext("2d");
|
|
29
|
+
}
|
|
30
|
+
function isOffscreenCanvas(canvas) {
|
|
31
|
+
return typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas;
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
34
|
* Creates a CanvasTexture with maximum WebGL1/WebGL2 compatibility.
|
|
@@ -16,6 +16,7 @@ export class UIColor {
|
|
|
16
16
|
this.rgbDirty = false;
|
|
17
17
|
this.hslDirty = false;
|
|
18
18
|
if (args.length > 0) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- Needed by tsc: no single overload of set() accepts unknown[], the rule misjudges overloaded methods
|
|
19
20
|
this.set(...args);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -340,10 +341,12 @@ export class UIColor {
|
|
|
340
341
|
/** Returns RGBA as 32-bit hex (RRGGBBAA) */
|
|
341
342
|
getHexRGBA() {
|
|
342
343
|
this.ensureRGBUpdatedFromHSL();
|
|
343
|
-
|
|
344
|
+
// Unsigned: a red of 128 or more sets the sign bit
|
|
345
|
+
return (((Math.round(this.rInternal * 255) << 24) |
|
|
344
346
|
(Math.round(this.gInternal * 255) << 16) |
|
|
345
347
|
(Math.round(this.bInternal * 255) << 8) |
|
|
346
|
-
Math.round(this.aInternal * 255))
|
|
348
|
+
Math.round(this.aInternal * 255)) >>>
|
|
349
|
+
0);
|
|
347
350
|
}
|
|
348
351
|
/** Returns RGB as 24-bit hex (RRGGBB) */
|
|
349
352
|
getHexRGB() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Matrix4 } from "three";
|
|
2
2
|
import { UIMicroAnchorMode } from "../miscellaneous/micro/UIMicro.Internal.js";
|
|
3
|
+
import type { UITextureTrim } from "./texture/UITextureView.Internal.js";
|
|
3
4
|
/**
|
|
4
5
|
* Computes element transform matrix.
|
|
5
6
|
* @returns Transform matrix (reused, do not store reference)
|
|
@@ -16,3 +17,14 @@ export declare function computeTransformMatrix(x: number, y: number, width: numb
|
|
|
16
17
|
* @returns Transform matrix (reused, do not store reference)
|
|
17
18
|
*/
|
|
18
19
|
export declare function computeTrimmedTransformMatrix(x: number, y: number, width: number, height: number, zIndex: number, microX: number, microY: number, microAnchorX: number, microAnchorY: number, microScaleX: number, microScaleY: number, microRotation: number, microAnchorMode: UIMicroAnchorMode, trimLeft: number, trimRight: number, trimTop: number, trimBottom: number): Matrix4;
|
|
20
|
+
/**
|
|
21
|
+
* Trim of a sprite drawn at a size other than its source size: the trim stretches with it.
|
|
22
|
+
* Returns a shared object, valid until the next call.
|
|
23
|
+
* @param trim Trim in source units
|
|
24
|
+
* @param width Drawn width
|
|
25
|
+
* @param height Drawn height
|
|
26
|
+
* @param sourceWidth Untrimmed source width
|
|
27
|
+
* @param sourceHeight Untrimmed source height
|
|
28
|
+
* @returns Trim in drawn units
|
|
29
|
+
*/
|
|
30
|
+
export declare function scaleTrim(trim: Readonly<UITextureTrim>, width: number, height: number, sourceWidth: number, sourceHeight: number): Readonly<UITextureTrim>;
|
|
@@ -5,6 +5,7 @@ const TEMP_QUATERNION = new Quaternion();
|
|
|
5
5
|
const TEMP_SCALE = new Vector3();
|
|
6
6
|
const TEMP_MATRIX = new Matrix4();
|
|
7
7
|
const Z_AXIS = new Vector3(0, 0, 1);
|
|
8
|
+
const TEMP_TRIM = { left: 0, right: 0, top: 0, bottom: 0 };
|
|
8
9
|
/**
|
|
9
10
|
* Computes element transform matrix.
|
|
10
11
|
* @returns Transform matrix (reused, do not store reference)
|
|
@@ -77,3 +78,22 @@ export function computeTrimmedTransformMatrix(x, y, width, height, zIndex, micro
|
|
|
77
78
|
TEMP_MATRIX.compose(TEMP_POSITION, TEMP_QUATERNION, TEMP_SCALE);
|
|
78
79
|
return TEMP_MATRIX;
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Trim of a sprite drawn at a size other than its source size: the trim stretches with it.
|
|
83
|
+
* Returns a shared object, valid until the next call.
|
|
84
|
+
* @param trim Trim in source units
|
|
85
|
+
* @param width Drawn width
|
|
86
|
+
* @param height Drawn height
|
|
87
|
+
* @param sourceWidth Untrimmed source width
|
|
88
|
+
* @param sourceHeight Untrimmed source height
|
|
89
|
+
* @returns Trim in drawn units
|
|
90
|
+
*/
|
|
91
|
+
export function scaleTrim(trim, width, height, sourceWidth, sourceHeight) {
|
|
92
|
+
const scaleX = sourceWidth > 0 ? width / sourceWidth : 1;
|
|
93
|
+
const scaleY = sourceHeight > 0 ? height / sourceHeight : 1;
|
|
94
|
+
TEMP_TRIM.left = trim.left * scaleX;
|
|
95
|
+
TEMP_TRIM.right = trim.right * scaleX;
|
|
96
|
+
TEMP_TRIM.top = trim.top * scaleY;
|
|
97
|
+
TEMP_TRIM.bottom = trim.bottom * scaleY;
|
|
98
|
+
return TEMP_TRIM;
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Ferrsign0 } from "ferrsign";
|
|
2
|
+
const MONITORS = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Tracks whether the WebGL context of a renderer is lost. One monitor per renderer, shared by
|
|
5
|
+
* every layer drawn with it.
|
|
6
|
+
*
|
|
7
|
+
* The renderer subscribes to the canvas events in its constructor, before any monitor exists, so
|
|
8
|
+
* by the time `signalRestored` fires the renderer has already recreated its GL state. Resources
|
|
9
|
+
* that live on the GPU only, such as render target contents, still have to be redrawn.
|
|
10
|
+
*
|
|
11
|
+
* The listeners stay on the canvas for its lifetime: the monitor holds no reference to the
|
|
12
|
+
* renderer and is collected together with the canvas.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export class UIContextMonitor {
|
|
16
|
+
constructor(renderer) {
|
|
17
|
+
this.signalLostInternal = new Ferrsign0();
|
|
18
|
+
this.signalRestoredInternal = new Ferrsign0();
|
|
19
|
+
this.onContextLost = () => {
|
|
20
|
+
if (!this.lostInternal) {
|
|
21
|
+
this.lostInternal = true;
|
|
22
|
+
this.signalLostInternal.emit();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.onContextRestored = () => {
|
|
26
|
+
if (this.lostInternal) {
|
|
27
|
+
this.lostInternal = false;
|
|
28
|
+
this.signalRestoredInternal.emit();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
this.lostInternal = renderer.getContext().isContextLost();
|
|
32
|
+
renderer.domElement.addEventListener("webglcontextlost", this.onContextLost);
|
|
33
|
+
renderer.domElement.addEventListener("webglcontextrestored", this.onContextRestored);
|
|
34
|
+
}
|
|
35
|
+
/** Whether the context is lost: nothing drawn until it is restored */
|
|
36
|
+
get lost() {
|
|
37
|
+
return this.lostInternal;
|
|
38
|
+
}
|
|
39
|
+
/** Signal fired when the context is lost */
|
|
40
|
+
get signalLost() {
|
|
41
|
+
return this.signalLostInternal;
|
|
42
|
+
}
|
|
43
|
+
/** Signal fired when the context is restored, after the renderer has recreated its GL state */
|
|
44
|
+
get signalRestored() {
|
|
45
|
+
return this.signalRestoredInternal;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Monitor of the renderer, created on first request.
|
|
49
|
+
* @param renderer Renderer to monitor
|
|
50
|
+
* @returns The monitor shared by all users of the renderer
|
|
51
|
+
*/
|
|
52
|
+
static for(renderer) {
|
|
53
|
+
let monitor = MONITORS.get(renderer);
|
|
54
|
+
if (monitor === undefined) {
|
|
55
|
+
monitor = new UIContextMonitor(renderer);
|
|
56
|
+
MONITORS.set(renderer, monitor);
|
|
57
|
+
}
|
|
58
|
+
return monitor;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -5,14 +5,28 @@ import type { PackedLayout } from "./UIGenericInstancedPlane.Layout.js";
|
|
|
5
5
|
export declare const INSTANCED_PLANE_GEOMETRY: InstancedBufferGeometry;
|
|
6
6
|
export declare const CAPACITY_STEP = 4;
|
|
7
7
|
export declare const INITIAL_CAPACITY = 1;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Flattens a property value into the array.
|
|
10
|
+
* @param affine Write a Matrix3 as a 2D affine transform: its three columns without the bottom row
|
|
11
|
+
*/
|
|
12
|
+
export declare function writePropertyToArray(value: UIProperty, array: Float32Array, offset: number, affine?: boolean): void;
|
|
9
13
|
export declare const BUILTIN_TRANSFORM = "instanceTransform";
|
|
10
14
|
export declare const BUILTIN_VISIBILITY = "instanceVisibility";
|
|
11
15
|
export declare const BUILTIN_BLEND = "instanceBlend";
|
|
12
16
|
export declare const BUILTIN_HSL = "instanceHSL";
|
|
13
|
-
|
|
17
|
+
/** Rows of the layer -> mask-local map, see MASK_DATA_SIZE; present on masked planes only */
|
|
18
|
+
export declare const BUILTIN_MASK_ROW0 = "instanceMaskRow0";
|
|
19
|
+
export declare const BUILTIN_MASK_ROW1 = "instanceMaskRow1";
|
|
20
|
+
/** Half width, half height, corner radius and softness of the mask */
|
|
21
|
+
export declare const BUILTIN_MASK_SHAPE = "instanceMaskShape";
|
|
22
|
+
/** Mask shape + 2 when inverted */
|
|
23
|
+
export declare const BUILTIN_MASK_MODE = "instanceMaskMode";
|
|
24
|
+
export declare function buildPlaneLayout(varyingProperties: Record<string, GLProperty>, masked: boolean): PackedLayout;
|
|
14
25
|
export declare function buildPackedAttribute(itemSize: number, capacity: number): InstancedBufferAttribute;
|
|
15
|
-
export declare function buildMaterial(source: string, uniformProperties: Record<string, GLProperty>, layout: PackedLayout, transparency: UITransparencyMode):
|
|
26
|
+
export declare function buildMaterial(source: string, uniformProperties: Record<string, GLProperty>, layout: PackedLayout, transparency: UITransparencyMode, masked: boolean): {
|
|
27
|
+
material: ShaderMaterial;
|
|
28
|
+
varyingRowCount: number;
|
|
29
|
+
};
|
|
16
30
|
/**
|
|
17
31
|
* Shift buffer region within the same array.
|
|
18
32
|
* Uses copyWithin for efficient memory moves with correct overlap handling.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DoubleSide, Float32BufferAttribute, InstancedBufferAttribute, InstancedBufferGeometry, Matrix3, Matrix4, ShaderMaterial, Uint16BufferAttribute, Vector2, Vector3, Vector4, } from "three";
|
|
2
|
+
import maskSource from "../../../shaders/UIMask.js";
|
|
2
3
|
import { UIColor } from "../../color/UIColor.js";
|
|
3
4
|
import { UITransparencyMode } from "../../UITransparencyMode.js";
|
|
4
5
|
import { buildGenericPlaneFragmentShader, resolveGLSLTypeInfo } from "../shared.js";
|
|
5
|
-
import {
|
|
6
|
+
import { isIdentifierReferenced, packVaryings } from "../varyingPacking.js";
|
|
7
|
+
import { buildPackedAttributeDeclarations, buildPackedFieldComponents, buildPackedFieldSpec, buildPackedLayout, resolvePackedField, } from "./UIGenericInstancedPlane.Layout.js";
|
|
6
8
|
export const INSTANCED_PLANE_GEOMETRY = (() => {
|
|
7
9
|
const geometry = new InstancedBufferGeometry();
|
|
8
10
|
const indices = new Uint16Array([0, 2, 1, 2, 3, 1]);
|
|
@@ -16,8 +18,21 @@ export const INSTANCED_PLANE_GEOMETRY = (() => {
|
|
|
16
18
|
export const CAPACITY_STEP = 4;
|
|
17
19
|
export const INITIAL_CAPACITY = 1;
|
|
18
20
|
const TEMP_COLOR_VECTOR = new Vector4();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Flattens a property value into the array.
|
|
23
|
+
* @param affine Write a Matrix3 as a 2D affine transform: its three columns without the bottom row
|
|
24
|
+
*/
|
|
25
|
+
export function writePropertyToArray(value, array, offset, affine = false) {
|
|
26
|
+
if (affine && value instanceof Matrix3) {
|
|
27
|
+
const elements = value.elements;
|
|
28
|
+
array[offset] = elements[0];
|
|
29
|
+
array[offset + 1] = elements[1];
|
|
30
|
+
array[offset + 2] = elements[3];
|
|
31
|
+
array[offset + 3] = elements[4];
|
|
32
|
+
array[offset + 4] = elements[6];
|
|
33
|
+
array[offset + 5] = elements[7];
|
|
34
|
+
}
|
|
35
|
+
else if (value instanceof UIColor) {
|
|
21
36
|
value.toGLSLColor(TEMP_COLOR_VECTOR);
|
|
22
37
|
array[offset] = TEMP_COLOR_VECTOR.x;
|
|
23
38
|
array[offset + 1] = TEMP_COLOR_VECTOR.y;
|
|
@@ -53,11 +68,23 @@ export const BUILTIN_TRANSFORM = "instanceTransform";
|
|
|
53
68
|
export const BUILTIN_VISIBILITY = "instanceVisibility";
|
|
54
69
|
export const BUILTIN_BLEND = "instanceBlend";
|
|
55
70
|
export const BUILTIN_HSL = "instanceHSL";
|
|
71
|
+
/** Rows of the layer -> mask-local map, see MASK_DATA_SIZE; present on masked planes only */
|
|
72
|
+
export const BUILTIN_MASK_ROW0 = "instanceMaskRow0";
|
|
73
|
+
export const BUILTIN_MASK_ROW1 = "instanceMaskRow1";
|
|
74
|
+
/** Half width, half height, corner radius and softness of the mask */
|
|
75
|
+
export const BUILTIN_MASK_SHAPE = "instanceMaskShape";
|
|
76
|
+
/** Mask shape + 2 when inverted */
|
|
77
|
+
export const BUILTIN_MASK_MODE = "instanceMaskMode";
|
|
56
78
|
/**
|
|
57
79
|
* Builtin fields only the vertex shader reads. Every other field, builtin blend and HSL included,
|
|
58
80
|
* is passed on to the fragment shader as a p_* varying.
|
|
59
81
|
*/
|
|
60
|
-
const BUILTIN_VERTEX_ONLY = [
|
|
82
|
+
const BUILTIN_VERTEX_ONLY = [
|
|
83
|
+
BUILTIN_TRANSFORM,
|
|
84
|
+
BUILTIN_VISIBILITY,
|
|
85
|
+
BUILTIN_MASK_ROW0,
|
|
86
|
+
BUILTIN_MASK_ROW1,
|
|
87
|
+
];
|
|
61
88
|
/**
|
|
62
89
|
* The transform is a Matrix4, but the plane is a unit quad at z = 0 and every element transform
|
|
63
90
|
* is affine: the z basis column only ever multiplies 0 and the bottom row is always (0, 0, 0, 1).
|
|
@@ -75,13 +102,16 @@ const BUILTIN_TRANSFORM_SPEC = {
|
|
|
75
102
|
{ sourceOffset: 12, size: 3 },
|
|
76
103
|
],
|
|
77
104
|
};
|
|
78
|
-
export function buildPlaneLayout(varyingProperties) {
|
|
105
|
+
export function buildPlaneLayout(varyingProperties, masked) {
|
|
79
106
|
const specs = [
|
|
80
107
|
BUILTIN_TRANSFORM_SPEC,
|
|
81
108
|
buildPackedFieldSpec(BUILTIN_VISIBILITY, resolveGLSLTypeInfo("number")),
|
|
82
109
|
buildPackedFieldSpec(BUILTIN_BLEND, resolveGLSLTypeInfo("number")),
|
|
83
110
|
buildPackedFieldSpec(BUILTIN_HSL, resolveGLSLTypeInfo("Vector3")),
|
|
84
111
|
];
|
|
112
|
+
if (masked) {
|
|
113
|
+
specs.push(buildPackedFieldSpec(BUILTIN_MASK_ROW0, resolveGLSLTypeInfo("Vector3")), buildPackedFieldSpec(BUILTIN_MASK_ROW1, resolveGLSLTypeInfo("Vector3")), buildPackedFieldSpec(BUILTIN_MASK_SHAPE, resolveGLSLTypeInfo("Vector4")), buildPackedFieldSpec(BUILTIN_MASK_MODE, resolveGLSLTypeInfo("number")));
|
|
114
|
+
}
|
|
85
115
|
for (const name in varyingProperties) {
|
|
86
116
|
specs.push(buildPackedFieldSpec(name, varyingProperties[name].glslTypeInfo));
|
|
87
117
|
}
|
|
@@ -90,11 +120,9 @@ export function buildPlaneLayout(varyingProperties) {
|
|
|
90
120
|
export function buildPackedAttribute(itemSize, capacity) {
|
|
91
121
|
return new InstancedBufferAttribute(new Float32Array(capacity * itemSize), itemSize);
|
|
92
122
|
}
|
|
93
|
-
export function buildMaterial(source, uniformProperties, layout, transparency) {
|
|
123
|
+
export function buildMaterial(source, uniformProperties, layout, transparency, masked) {
|
|
94
124
|
const uniforms = {};
|
|
95
125
|
const uniformDeclarations = [];
|
|
96
|
-
const varyingDeclarations = [];
|
|
97
|
-
const vertexAssignments = [];
|
|
98
126
|
for (const name in uniformProperties) {
|
|
99
127
|
const { value, glslTypeInfo } = uniformProperties[name];
|
|
100
128
|
uniforms[`p_${name}`] = {
|
|
@@ -102,26 +130,59 @@ export function buildMaterial(source, uniformProperties, layout, transparency) {
|
|
|
102
130
|
};
|
|
103
131
|
uniformDeclarations.push(`uniform ${glslTypeInfo.glslTypeName} p_${name};`);
|
|
104
132
|
}
|
|
133
|
+
// Every value the fragment shader may read, as p_* fields
|
|
134
|
+
const candidates = [
|
|
135
|
+
{ name: "p_uv", glslTypeName: "vec2", components: ["uv.x", "uv.y"] },
|
|
136
|
+
];
|
|
105
137
|
for (const [name, field] of layout.fields) {
|
|
106
|
-
if (BUILTIN_VERTEX_ONLY.includes(name)) {
|
|
107
|
-
|
|
138
|
+
if (!BUILTIN_VERTEX_ONLY.includes(name)) {
|
|
139
|
+
candidates.push({
|
|
140
|
+
name: `p_${name}`,
|
|
141
|
+
glslTypeName: field.glslTypeName,
|
|
142
|
+
components: buildPackedFieldComponents(layout, field),
|
|
143
|
+
affine: field.affine,
|
|
144
|
+
});
|
|
108
145
|
}
|
|
109
|
-
varyingDeclarations.push(`varying ${field.glslTypeName} p_${name};`);
|
|
110
|
-
vertexAssignments.push(`p_${name} = ${field.expression};`);
|
|
111
146
|
}
|
|
112
147
|
const visibility = resolvePackedField(layout, BUILTIN_VISIBILITY).expression;
|
|
113
148
|
const transform = resolvePackedField(layout, BUILTIN_TRANSFORM).expression;
|
|
149
|
+
let maskVertex = "";
|
|
150
|
+
if (masked) {
|
|
151
|
+
const row0 = resolvePackedField(layout, BUILTIN_MASK_ROW0).expression;
|
|
152
|
+
const row1 = resolvePackedField(layout, BUILTIN_MASK_ROW1).expression;
|
|
153
|
+
candidates.push({
|
|
154
|
+
name: "p_instanceMaskLocal",
|
|
155
|
+
glslTypeName: "vec2",
|
|
156
|
+
components: ["maskLocal.x", "maskLocal.y"],
|
|
157
|
+
});
|
|
158
|
+
// worldPosition.z carries the zIndex, the mask map only takes the plane position
|
|
159
|
+
maskVertex = `
|
|
160
|
+
vec3 maskPoint = vec3(worldPosition.xy, 1.0);
|
|
161
|
+
vec2 maskLocal = vec2(dot(${row0}, maskPoint), dot(${row1}, maskPoint));
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
const alphaTestValue = 0.0075;
|
|
165
|
+
const premultipliedAlpha = transparency === UITransparencyMode.BLEND;
|
|
166
|
+
const maskFragment = masked ? maskSource : undefined;
|
|
167
|
+
// Only fields the fragment shader reads take varyings: the blend factor, for one, is read by
|
|
168
|
+
// premultiplied shaders only. The shader without fields tells which ones it reads.
|
|
169
|
+
const unpackedFragment = buildGenericPlaneFragmentShader(uniformDeclarations, [], [], source, alphaTestValue, premultipliedAlpha, maskFragment);
|
|
170
|
+
const fields = candidates.filter(({ name }) => isIdentifierReferenced(unpackedFragment, name));
|
|
171
|
+
const packed = packVaryings(fields);
|
|
172
|
+
const fieldDeclarations = [...packed.declarations];
|
|
173
|
+
const fieldAssignments = [];
|
|
174
|
+
for (const { name, glslTypeName } of fields) {
|
|
175
|
+
fieldDeclarations.push(`${glslTypeName} ${name};`);
|
|
176
|
+
fieldAssignments.push(`${name} = ${packed.fragmentExpressions.get(name) ?? ""};`);
|
|
177
|
+
}
|
|
114
178
|
const vertexShader = `
|
|
115
179
|
${buildPackedAttributeDeclarations(layout).join("\n")}
|
|
116
180
|
|
|
117
181
|
// Uniforms
|
|
118
182
|
${uniformDeclarations.join("\n")}
|
|
119
183
|
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
varying vec2 p_uv;
|
|
123
|
-
|
|
124
|
-
${varyingDeclarations.join("\n")}
|
|
184
|
+
// Packed varyings
|
|
185
|
+
${packed.declarations.join("\n")}
|
|
125
186
|
|
|
126
187
|
void main() {
|
|
127
188
|
if (${visibility} < 0.5) {
|
|
@@ -129,19 +190,15 @@ export function buildMaterial(source, uniformProperties, layout, transparency) {
|
|
|
129
190
|
return;
|
|
130
191
|
}
|
|
131
192
|
|
|
132
|
-
${vertexAssignments.join("\n")}
|
|
133
|
-
|
|
134
|
-
p_position = position;
|
|
135
|
-
p_uv = uv;
|
|
136
|
-
|
|
137
193
|
vec3 worldPosition = ${transform} * vec3(position.xy, 1.0);
|
|
138
194
|
gl_Position = projectionMatrix * vec4(worldPosition, 1.0);
|
|
195
|
+
${maskVertex}
|
|
196
|
+
|
|
197
|
+
${packed.vertexAssignments.join("\n")}
|
|
139
198
|
}
|
|
140
199
|
`;
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue, premultipliedAlpha);
|
|
144
|
-
return new ShaderMaterial({
|
|
200
|
+
const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, fieldDeclarations, fieldAssignments, source, alphaTestValue, premultipliedAlpha, maskFragment);
|
|
201
|
+
const material = new ShaderMaterial({
|
|
145
202
|
uniforms,
|
|
146
203
|
vertexShader,
|
|
147
204
|
fragmentShader,
|
|
@@ -154,6 +211,11 @@ export function buildMaterial(source, uniformProperties, layout, transparency) {
|
|
|
154
211
|
forceSinglePass: true,
|
|
155
212
|
premultipliedAlpha,
|
|
156
213
|
});
|
|
214
|
+
if (masked) {
|
|
215
|
+
// fwidth on WebGL1 (three.js before r163); WebGL2 has derivatives built in
|
|
216
|
+
material.extensions.derivatives = true;
|
|
217
|
+
}
|
|
218
|
+
return { material, varyingRowCount: packed.rowCount };
|
|
157
219
|
}
|
|
158
220
|
/**
|
|
159
221
|
* Shift buffer region within the same array.
|
|
@@ -13,6 +13,8 @@ export interface PackedFieldSpec {
|
|
|
13
13
|
glslTypeName: string;
|
|
14
14
|
flatSize: number;
|
|
15
15
|
columns: readonly PackedColumnSpec[];
|
|
16
|
+
/** A mat3 stored as three columns of two, see GLTypeInfo.affine */
|
|
17
|
+
affine?: boolean;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* A column placed into the packed attribute attributeIndex, starting at its component
|
|
@@ -30,6 +32,8 @@ export interface PackedField {
|
|
|
30
32
|
glslTypeName: string;
|
|
31
33
|
columns: readonly PackedColumn[];
|
|
32
34
|
expression: string;
|
|
35
|
+
/** A mat3 stored as three columns of two, see GLTypeInfo.affine */
|
|
36
|
+
affine: boolean;
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* attributeSizes holds the item size (1..4) of each packed attribute. Two layouts with an equal
|
|
@@ -49,4 +53,9 @@ export declare function buildPackedFieldSpec(name: string, glslTypeInfo: GLTypeI
|
|
|
49
53
|
*/
|
|
50
54
|
export declare function buildPackedLayout(specs: readonly PackedFieldSpec[]): PackedLayout;
|
|
51
55
|
export declare function resolvePackedField(layout: PackedLayout, name: string): PackedField;
|
|
56
|
+
/**
|
|
57
|
+
* Vertex shader expressions of the scalar components of a packed field, in the order the GLSL
|
|
58
|
+
* constructor of its type takes them; used to pass the field on through packed varyings.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildPackedFieldComponents(layout: PackedLayout, field: PackedField): string[];
|
|
52
61
|
export declare function buildPackedAttributeDeclarations(layout: PackedLayout): string[];
|