laymur 0.13.7 → 0.14.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/dist/index.js +116 -25
- 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 +3 -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,99 @@ class UIColor {
|
|
|
2556
2556
|
}
|
|
2557
2557
|
}
|
|
2558
2558
|
|
|
2559
|
-
|
|
2560
|
-
|
|
2559
|
+
/**
|
|
2560
|
+
* Checks if WebGL2 is available.
|
|
2561
|
+
*/
|
|
2562
|
+
function checkWebGL2Support() {
|
|
2561
2563
|
const canvas = document.createElement("canvas");
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
+
return canvas.getContext("webgl2") !== null;
|
|
2565
|
+
}
|
|
2566
|
+
/**
|
|
2567
|
+
* Checks real OffscreenCanvas support as a texture source
|
|
2568
|
+
*/
|
|
2569
|
+
function checkOffscreenCanvasSupport() {
|
|
2570
|
+
var _a;
|
|
2571
|
+
if (typeof OffscreenCanvas === "undefined") return false;
|
|
2572
|
+
const testCanvasElement = document.createElement("canvas");
|
|
2573
|
+
testCanvasElement.width = 4;
|
|
2574
|
+
testCanvasElement.height = 4;
|
|
2575
|
+
const gl = (_a = testCanvasElement.getContext("webgl")) !== null && _a !== void 0 ? _a : testCanvasElement.getContext("webgl2");
|
|
2576
|
+
if (!gl) return false;
|
|
2577
|
+
try {
|
|
2578
|
+
const offscreenCanvas = new OffscreenCanvas(4, 4);
|
|
2579
|
+
const offscreenContext = offscreenCanvas.getContext("2d");
|
|
2580
|
+
if (!offscreenContext) return false;
|
|
2581
|
+
offscreenContext.fillStyle = "#ff0000";
|
|
2582
|
+
offscreenContext.fillRect(0, 0, 4, 4);
|
|
2583
|
+
const texture = gl.createTexture();
|
|
2584
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2585
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, offscreenCanvas);
|
|
2586
|
+
if (gl.getError() !== gl.NO_ERROR) {
|
|
2587
|
+
gl.deleteTexture(texture);
|
|
2588
|
+
return false;
|
|
2589
|
+
}
|
|
2590
|
+
const framebuffer = gl.createFramebuffer();
|
|
2591
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
2592
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
2593
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
2594
|
+
gl.deleteFramebuffer(framebuffer);
|
|
2595
|
+
gl.deleteTexture(texture);
|
|
2596
|
+
return false;
|
|
2597
|
+
}
|
|
2598
|
+
const pixelData = new Uint8Array(4);
|
|
2599
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
|
|
2600
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
2601
|
+
gl.deleteFramebuffer(framebuffer);
|
|
2602
|
+
gl.deleteTexture(texture);
|
|
2603
|
+
// Check that the read pixel is red (with tolerance)
|
|
2604
|
+
const isRedPixel = pixelData[0] > 200 && pixelData[1] < 50 && pixelData[2] < 50 && pixelData[3] > 200;
|
|
2605
|
+
if (!isRedPixel) return false;
|
|
2606
|
+
return true;
|
|
2607
|
+
} catch (error) {
|
|
2564
2608
|
return false;
|
|
2565
2609
|
}
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
* Checks sRGB support
|
|
2613
|
+
*/
|
|
2614
|
+
function checkSRGBSupport() {
|
|
2615
|
+
var _a;
|
|
2616
|
+
const canvasElement = document.createElement("canvas");
|
|
2617
|
+
const gl = (_a = canvasElement.getContext("webgl2")) !== null && _a !== void 0 ? _a : canvasElement.getContext("webgl");
|
|
2618
|
+
if (!gl) return false;
|
|
2566
2619
|
if (gl instanceof WebGL2RenderingContext) {
|
|
2567
|
-
|
|
2620
|
+
try {
|
|
2621
|
+
const texture = gl.createTexture();
|
|
2622
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2623
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.SRGB8_ALPHA8, 2, 2);
|
|
2624
|
+
const errorCode = gl.getError();
|
|
2625
|
+
gl.deleteTexture(texture);
|
|
2626
|
+
return errorCode === gl.NO_ERROR;
|
|
2627
|
+
} catch (_b) {
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2568
2630
|
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2631
|
+
const extension = gl.getExtension("EXT_sRGB");
|
|
2632
|
+
if (!extension) return false;
|
|
2633
|
+
try {
|
|
2634
|
+
const texture = gl.createTexture();
|
|
2635
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
2636
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, extension.SRGB_ALPHA_EXT, 2, 2, 0, extension.SRGB_ALPHA_EXT, gl.UNSIGNED_BYTE, null);
|
|
2637
|
+
const errorCode = gl.getError();
|
|
2638
|
+
gl.deleteTexture(texture);
|
|
2639
|
+
return errorCode === gl.NO_ERROR;
|
|
2640
|
+
} catch (_c) {
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
const WEBGL2_SUPPORTED = checkWebGL2Support();
|
|
2645
|
+
const OFFSCREEN_CANVAS_SUPPORTED = checkOffscreenCanvasSupport();
|
|
2571
2646
|
const SRGB_SUPPORTED = checkSRGBSupport();
|
|
2647
|
+
console.log("[WebGL] Capabilities:", {
|
|
2648
|
+
webgl2: WEBGL2_SUPPORTED,
|
|
2649
|
+
offscreenCanvas: OFFSCREEN_CANVAS_SUPPORTED,
|
|
2650
|
+
srgb: SRGB_SUPPORTED
|
|
2651
|
+
});
|
|
2572
2652
|
|
|
2573
2653
|
const DEFAULT_ALPHA_TEST = 0.5;
|
|
2574
2654
|
const GLSL_TYPE_INFO_FLOAT = Object.freeze({
|
|
@@ -4401,6 +4481,8 @@ class UILayer extends i {
|
|
|
4401
4481
|
}
|
|
4402
4482
|
}
|
|
4403
4483
|
|
|
4484
|
+
const EPSILON = 1e-6;
|
|
4485
|
+
|
|
4404
4486
|
/**
|
|
4405
4487
|
* Checks if object implements UILayerElement.
|
|
4406
4488
|
* @param obj Object to check
|
|
@@ -4426,7 +4508,6 @@ function isUIPlaneElement(obj) {
|
|
|
4426
4508
|
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
4509
|
}
|
|
4428
4510
|
|
|
4429
|
-
const EPSILON = 1e-6;
|
|
4430
4511
|
/**
|
|
4431
4512
|
* Validates value is finite number within safe range.
|
|
4432
4513
|
* @param value Number to validate
|
|
@@ -6568,21 +6649,36 @@ class UIAnimatedImage extends UIElement {
|
|
|
6568
6649
|
}
|
|
6569
6650
|
|
|
6570
6651
|
/**
|
|
6571
|
-
* Creates a canvas
|
|
6572
|
-
* Uses OffscreenCanvas when available, falls back to HTMLCanvasElement otherwise.
|
|
6652
|
+
* Creates a canvas using OffscreenCanvas if available, otherwise falls back to HTMLCanvasElement.
|
|
6573
6653
|
*
|
|
6574
6654
|
* @param width - Canvas width in pixels
|
|
6575
6655
|
* @param height - Canvas height in pixels
|
|
6576
6656
|
* @returns Canvas instance
|
|
6577
6657
|
*/
|
|
6578
6658
|
function createCanvas(width, height) {
|
|
6579
|
-
if (
|
|
6659
|
+
if (OFFSCREEN_CANVAS_SUPPORTED) {
|
|
6580
6660
|
return new OffscreenCanvas(width, height);
|
|
6581
6661
|
}
|
|
6582
|
-
const
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
return
|
|
6662
|
+
const canvasElement = document.createElement("canvas");
|
|
6663
|
+
canvasElement.width = width;
|
|
6664
|
+
canvasElement.height = height;
|
|
6665
|
+
return canvasElement;
|
|
6666
|
+
}
|
|
6667
|
+
/**
|
|
6668
|
+
* Creates a CanvasTexture with maximum WebGL1/WebGL2 compatibility.
|
|
6669
|
+
* - ClampToEdge wrapping (required for NPOT in WebGL1)
|
|
6670
|
+
* - Linear filtering without mipmaps (NPOT-safe)
|
|
6671
|
+
* - RGBA/UnsignedByte format (no extensions needed)
|
|
6672
|
+
* - sRGB colorspace only if supported
|
|
6673
|
+
*
|
|
6674
|
+
* @param canvas - Source canvas
|
|
6675
|
+
* @returns Configured CanvasTexture
|
|
6676
|
+
*/
|
|
6677
|
+
function createCanvasTexture(canvas) {
|
|
6678
|
+
const texture = new CanvasTexture(canvas, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearFilter, RGBAFormat, UnsignedByteType, 1);
|
|
6679
|
+
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
6680
|
+
texture.generateMipmaps = false;
|
|
6681
|
+
return texture;
|
|
6586
6682
|
}
|
|
6587
6683
|
|
|
6588
6684
|
const GRAPHICS_DEFAULT_WIDTH = 2;
|
|
@@ -6607,10 +6703,7 @@ class UIGraphics extends UIElement {
|
|
|
6607
6703
|
if (!context) {
|
|
6608
6704
|
throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
|
|
6609
6705
|
}
|
|
6610
|
-
const texture =
|
|
6611
|
-
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
6612
|
-
texture.minFilter = LinearFilter;
|
|
6613
|
-
texture.magFilter = LinearFilter;
|
|
6706
|
+
const texture = createCanvasTexture(canvas);
|
|
6614
6707
|
texture.needsUpdate = true;
|
|
6615
6708
|
super(layer, source$4, {
|
|
6616
6709
|
texture: texture,
|
|
@@ -7215,7 +7308,7 @@ class UIProgressMaskFunctionDirectional extends UIProgressMaskFunction {
|
|
|
7215
7308
|
/** Fill direction as normalized vector */
|
|
7216
7309
|
this.direction = new Vector2();
|
|
7217
7310
|
this._private_cachedDirection = new Vector2();
|
|
7218
|
-
this.direction.
|
|
7311
|
+
this.direction.set(direction.x, direction.y).normalize();
|
|
7219
7312
|
this._private_cachedDirection.copy(this.direction);
|
|
7220
7313
|
}
|
|
7221
7314
|
/** @internal */
|
|
@@ -8176,8 +8269,7 @@ class UIText extends UIElement {
|
|
|
8176
8269
|
if (!context) {
|
|
8177
8270
|
throw new Error("UIText.constructor: failed to create canvas context");
|
|
8178
8271
|
}
|
|
8179
|
-
const texture =
|
|
8180
|
-
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8272
|
+
const texture = createCanvasTexture(canvas);
|
|
8181
8273
|
texture.needsUpdate = true;
|
|
8182
8274
|
const color = new UIColor(options.color);
|
|
8183
8275
|
super(layer, source$4, {
|
|
@@ -8376,8 +8468,7 @@ class UIText extends UIElement {
|
|
|
8376
8468
|
}
|
|
8377
8469
|
if (resolutionDirty) {
|
|
8378
8470
|
this._private_texture.dispose();
|
|
8379
|
-
this._private_texture =
|
|
8380
|
-
this._private_texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8471
|
+
this._private_texture = createCanvasTexture(this._private_canvas);
|
|
8381
8472
|
this._private_texture.needsUpdate = true;
|
|
8382
8473
|
properties !== null && properties !== void 0 ? properties : properties = {};
|
|
8383
8474
|
properties["texture"] = this._private_texture;
|