laymur 0.13.8 → 0.14.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/dist/index.js +125 -47
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/miscellaneous/area/UIAreaPolygon.d.ts +1 -1
- package/dist/miscellaneous/asserts.d.ts +0 -1
- package/dist/miscellaneous/canvas.d.ts +22 -4
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +1 -1
- package/dist/miscellaneous/math.d.ts +5 -0
- package/dist/miscellaneous/webglCapabilities.d.ts +2 -0
- package/package.json +3 -3
- package/dist/miscellaneous/checkSRGBSupport.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathUtils, Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture,
|
|
1
|
+
import { MathUtils, Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture, UVMapping, ClampToEdgeWrapping, LinearFilter, RGBAFormat, UnsignedByteType, SRGBColorSpace, NoColorSpace, WebGLRenderTarget, PerspectiveCamera, Ray } from 'three';
|
|
2
2
|
|
|
3
3
|
class t {
|
|
4
4
|
constructor(t, i) {
|
|
@@ -2556,19 +2556,106 @@ class UIColor {
|
|
|
2556
2556
|
}
|
|
2557
2557
|
}
|
|
2558
2558
|
|
|
2559
|
-
|
|
2559
|
+
/**
|
|
2560
|
+
* Checks real OffscreenCanvas support as a texture source
|
|
2561
|
+
*/
|
|
2562
|
+
function checkOffscreenCanvasSupportInternal() {
|
|
2560
2563
|
var _a;
|
|
2561
|
-
|
|
2562
|
-
|
|
2564
|
+
if (typeof OffscreenCanvas === "undefined") {
|
|
2565
|
+
return false;
|
|
2566
|
+
}
|
|
2567
|
+
const testCanvasElement = document.createElement("canvas");
|
|
2568
|
+
testCanvasElement.width = 4;
|
|
2569
|
+
testCanvasElement.height = 4;
|
|
2570
|
+
const gl = (_a = testCanvasElement.getContext("webgl")) !== null && _a !== void 0 ? _a : testCanvasElement.getContext("webgl2");
|
|
2563
2571
|
if (!gl) {
|
|
2564
2572
|
return false;
|
|
2565
2573
|
}
|
|
2566
|
-
|
|
2574
|
+
try {
|
|
2575
|
+
const offscreenCanvas = new OffscreenCanvas(4, 4);
|
|
2576
|
+
const offscreenContext = offscreenCanvas.getContext("2d");
|
|
2577
|
+
if (!offscreenContext) {
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
offscreenContext.fillStyle = "#ff0000";
|
|
2581
|
+
offscreenContext.fillRect(0, 0, 4, 4);
|
|
2582
|
+
const texture = gl.createTexture();
|
|
2583
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2584
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, offscreenCanvas);
|
|
2585
|
+
if (gl.getError() !== gl.NO_ERROR) {
|
|
2586
|
+
gl.deleteTexture(texture);
|
|
2587
|
+
return false;
|
|
2588
|
+
}
|
|
2589
|
+
const framebuffer = gl.createFramebuffer();
|
|
2590
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
2591
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
2592
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
2593
|
+
gl.deleteFramebuffer(framebuffer);
|
|
2594
|
+
gl.deleteTexture(texture);
|
|
2595
|
+
return false;
|
|
2596
|
+
}
|
|
2597
|
+
const pixelData = new Uint8Array(4);
|
|
2598
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
|
|
2599
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
2600
|
+
gl.deleteFramebuffer(framebuffer);
|
|
2601
|
+
gl.deleteTexture(texture);
|
|
2602
|
+
// Check that the read pixel is red (with tolerance)
|
|
2603
|
+
const isRedPixel = pixelData[0] > 200 && pixelData[1] < 50 && pixelData[2] < 50 && pixelData[3] > 200;
|
|
2604
|
+
if (!isRedPixel) {
|
|
2605
|
+
return false;
|
|
2606
|
+
}
|
|
2567
2607
|
return true;
|
|
2608
|
+
} catch (error) {
|
|
2609
|
+
return false;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* Checks sRGB support
|
|
2614
|
+
*/
|
|
2615
|
+
function checkSRGBSupportInternal() {
|
|
2616
|
+
var _a;
|
|
2617
|
+
const canvasElement = document.createElement("canvas");
|
|
2618
|
+
const gl = (_a = canvasElement.getContext("webgl2")) !== null && _a !== void 0 ? _a : canvasElement.getContext("webgl");
|
|
2619
|
+
if (!gl) {
|
|
2620
|
+
return false;
|
|
2621
|
+
}
|
|
2622
|
+
if (gl instanceof WebGL2RenderingContext) {
|
|
2623
|
+
try {
|
|
2624
|
+
const texture = gl.createTexture();
|
|
2625
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2626
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.SRGB8_ALPHA8, 2, 2);
|
|
2627
|
+
const errorCode = gl.getError();
|
|
2628
|
+
gl.deleteTexture(texture);
|
|
2629
|
+
return errorCode === gl.NO_ERROR;
|
|
2630
|
+
} catch (_b) {
|
|
2631
|
+
return false;
|
|
2632
|
+
}
|
|
2568
2633
|
}
|
|
2569
|
-
|
|
2634
|
+
const extension = gl.getExtension("EXT_sRGB");
|
|
2635
|
+
if (!extension) {
|
|
2636
|
+
return false;
|
|
2637
|
+
}
|
|
2638
|
+
try {
|
|
2639
|
+
const texture = gl.createTexture();
|
|
2640
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2641
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, extension.SRGB_ALPHA_EXT, 2, 2, 0, extension.SRGB_ALPHA_EXT, gl.UNSIGNED_BYTE, null);
|
|
2642
|
+
const errorCode = gl.getError();
|
|
2643
|
+
gl.deleteTexture(texture);
|
|
2644
|
+
return errorCode === gl.NO_ERROR;
|
|
2645
|
+
} catch (_c) {
|
|
2646
|
+
return false;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
let OFFSCREEN_CANVAS_SUPPORTED_INTERNAL;
|
|
2650
|
+
let SRGB_SUPPORTED_INTERNAL;
|
|
2651
|
+
const checkOffscreenCanvasSupport = () => {
|
|
2652
|
+
OFFSCREEN_CANVAS_SUPPORTED_INTERNAL !== null && OFFSCREEN_CANVAS_SUPPORTED_INTERNAL !== void 0 ? OFFSCREEN_CANVAS_SUPPORTED_INTERNAL : OFFSCREEN_CANVAS_SUPPORTED_INTERNAL = checkOffscreenCanvasSupportInternal();
|
|
2653
|
+
return OFFSCREEN_CANVAS_SUPPORTED_INTERNAL;
|
|
2654
|
+
};
|
|
2655
|
+
const checkSRGBSupport = () => {
|
|
2656
|
+
SRGB_SUPPORTED_INTERNAL !== null && SRGB_SUPPORTED_INTERNAL !== void 0 ? SRGB_SUPPORTED_INTERNAL : SRGB_SUPPORTED_INTERNAL = checkSRGBSupportInternal();
|
|
2657
|
+
return SRGB_SUPPORTED_INTERNAL;
|
|
2570
2658
|
};
|
|
2571
|
-
const SRGB_SUPPORTED = checkSRGBSupport();
|
|
2572
2659
|
|
|
2573
2660
|
const DEFAULT_ALPHA_TEST = 0.5;
|
|
2574
2661
|
const GLSL_TYPE_INFO_FLOAT = Object.freeze({
|
|
@@ -2734,7 +2821,7 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
|
|
|
2734
2821
|
return `
|
|
2735
2822
|
// Defines
|
|
2736
2823
|
#define PI 3.14159265359
|
|
2737
|
-
#define SRGB_SUPPORTED ${
|
|
2824
|
+
#define SRGB_SUPPORTED ${checkSRGBSupport() ? '1' : '0'}
|
|
2738
2825
|
|
|
2739
2826
|
// Uniforms
|
|
2740
2827
|
${uniformDeclarations.join("\n")}
|
|
@@ -4401,6 +4488,8 @@ class UILayer extends i {
|
|
|
4401
4488
|
}
|
|
4402
4489
|
}
|
|
4403
4490
|
|
|
4491
|
+
const EPSILON = 1e-6;
|
|
4492
|
+
|
|
4404
4493
|
/**
|
|
4405
4494
|
* Checks if object implements UILayerElement.
|
|
4406
4495
|
* @param obj Object to check
|
|
@@ -4426,7 +4515,6 @@ function isUIPlaneElement(obj) {
|
|
|
4426
4515
|
return typeof obj === "object" && obj !== null && "wVariable" in obj && typeof obj.wVariable === "number" && "hVariable" in obj && typeof obj.hVariable === "number" && "width" in obj && typeof obj.width === "number" && "height" in obj && typeof obj.height === "number";
|
|
4427
4516
|
}
|
|
4428
4517
|
|
|
4429
|
-
const EPSILON = 1e-6;
|
|
4430
4518
|
/**
|
|
4431
4519
|
* Validates value is finite number within safe range.
|
|
4432
4520
|
* @param value Number to validate
|
|
@@ -6568,42 +6656,37 @@ class UIAnimatedImage extends UIElement {
|
|
|
6568
6656
|
}
|
|
6569
6657
|
|
|
6570
6658
|
/**
|
|
6571
|
-
* Creates a canvas
|
|
6572
|
-
* Uses OffscreenCanvas when available, falls back to HTMLCanvasElement otherwise.
|
|
6659
|
+
* Creates a canvas using OffscreenCanvas if available, otherwise falls back to HTMLCanvasElement.
|
|
6573
6660
|
*
|
|
6574
6661
|
* @param width - Canvas width in pixels
|
|
6575
6662
|
* @param height - Canvas height in pixels
|
|
6576
6663
|
* @returns Canvas instance
|
|
6577
6664
|
*/
|
|
6578
6665
|
function createCanvas(width, height) {
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6666
|
+
if (checkOffscreenCanvasSupport()) {
|
|
6667
|
+
return new OffscreenCanvas(width, height);
|
|
6668
|
+
}
|
|
6669
|
+
const canvasElement = document.createElement("canvas");
|
|
6670
|
+
canvasElement.width = width;
|
|
6671
|
+
canvasElement.height = height;
|
|
6672
|
+
return canvasElement;
|
|
6673
|
+
}
|
|
6674
|
+
/**
|
|
6675
|
+
* Creates a CanvasTexture with maximum WebGL1/WebGL2 compatibility.
|
|
6676
|
+
* - ClampToEdge wrapping (required for NPOT in WebGL1)
|
|
6677
|
+
* - Linear filtering without mipmaps (NPOT-safe)
|
|
6678
|
+
* - RGBA/UnsignedByte format (no extensions needed)
|
|
6679
|
+
* - sRGB colorspace only if supported
|
|
6680
|
+
*
|
|
6681
|
+
* @param canvas - Source canvas
|
|
6682
|
+
* @returns Configured CanvasTexture
|
|
6683
|
+
*/
|
|
6684
|
+
function createCanvasTexture(canvas) {
|
|
6685
|
+
const texture = new CanvasTexture(canvas, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearFilter, RGBAFormat, UnsignedByteType, 1);
|
|
6686
|
+
texture.colorSpace = checkSRGBSupport() ? SRGBColorSpace : NoColorSpace;
|
|
6687
|
+
texture.generateMipmaps = false;
|
|
6688
|
+
return texture;
|
|
6583
6689
|
}
|
|
6584
|
-
// /** Canvas type that works both in main thread and workers */
|
|
6585
|
-
// export type UICanvas = OffscreenCanvas | HTMLCanvasElement;
|
|
6586
|
-
// /** 2D rendering context type for UICanvas */
|
|
6587
|
-
// export type UICanvasRenderingContext2D =
|
|
6588
|
-
// | OffscreenCanvasRenderingContext2D
|
|
6589
|
-
// | CanvasRenderingContext2D;
|
|
6590
|
-
// /**
|
|
6591
|
-
// * Creates a canvas with OffscreenCanvas fallback to HTMLCanvasElement.
|
|
6592
|
-
// * Uses OffscreenCanvas when available, falls back to HTMLCanvasElement otherwise.
|
|
6593
|
-
// *
|
|
6594
|
-
// * @param width - Canvas width in pixels
|
|
6595
|
-
// * @param height - Canvas height in pixels
|
|
6596
|
-
// * @returns Canvas instance
|
|
6597
|
-
// */
|
|
6598
|
-
// export function createCanvas(width: number, height: number): UICanvas {
|
|
6599
|
-
// if (typeof OffscreenCanvas !== "undefined") {
|
|
6600
|
-
// return new OffscreenCanvas(width, height);
|
|
6601
|
-
// }
|
|
6602
|
-
// const canvas = document.createElement("canvas");
|
|
6603
|
-
// canvas.width = width;
|
|
6604
|
-
// canvas.height = height;
|
|
6605
|
-
// return canvas;
|
|
6606
|
-
// }
|
|
6607
6690
|
|
|
6608
6691
|
const GRAPHICS_DEFAULT_WIDTH = 2;
|
|
6609
6692
|
const GRAPHICS_DEFAULT_HEIGHT = 2;
|
|
@@ -6627,10 +6710,7 @@ class UIGraphics extends UIElement {
|
|
|
6627
6710
|
if (!context) {
|
|
6628
6711
|
throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
|
|
6629
6712
|
}
|
|
6630
|
-
const texture =
|
|
6631
|
-
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
6632
|
-
texture.minFilter = LinearFilter;
|
|
6633
|
-
texture.magFilter = LinearFilter;
|
|
6713
|
+
const texture = createCanvasTexture(canvas);
|
|
6634
6714
|
texture.needsUpdate = true;
|
|
6635
6715
|
super(layer, source$4, {
|
|
6636
6716
|
texture: texture,
|
|
@@ -7235,7 +7315,7 @@ class UIProgressMaskFunctionDirectional extends UIProgressMaskFunction {
|
|
|
7235
7315
|
/** Fill direction as normalized vector */
|
|
7236
7316
|
this.direction = new Vector2();
|
|
7237
7317
|
this._private_cachedDirection = new Vector2();
|
|
7238
|
-
this.direction.
|
|
7318
|
+
this.direction.set(direction.x, direction.y).normalize();
|
|
7239
7319
|
this._private_cachedDirection.copy(this.direction);
|
|
7240
7320
|
}
|
|
7241
7321
|
/** @internal */
|
|
@@ -8196,8 +8276,7 @@ class UIText extends UIElement {
|
|
|
8196
8276
|
if (!context) {
|
|
8197
8277
|
throw new Error("UIText.constructor: failed to create canvas context");
|
|
8198
8278
|
}
|
|
8199
|
-
const texture =
|
|
8200
|
-
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8279
|
+
const texture = createCanvasTexture(canvas);
|
|
8201
8280
|
texture.needsUpdate = true;
|
|
8202
8281
|
const color = new UIColor(options.color);
|
|
8203
8282
|
super(layer, source$4, {
|
|
@@ -8396,8 +8475,7 @@ class UIText extends UIElement {
|
|
|
8396
8475
|
}
|
|
8397
8476
|
if (resolutionDirty) {
|
|
8398
8477
|
this._private_texture.dispose();
|
|
8399
|
-
this._private_texture =
|
|
8400
|
-
this._private_texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8478
|
+
this._private_texture = createCanvasTexture(this._private_canvas);
|
|
8401
8479
|
this._private_texture.needsUpdate = true;
|
|
8402
8480
|
properties !== null && properties !== void 0 ? properties : properties = {};
|
|
8403
8481
|
properties["texture"] = this._private_texture;
|