@lightningjs/renderer 0.9.2 → 0.9.4
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/exports/main-api.d.ts +1 -1
- package/dist/src/core/CoreNode.js +40 -0
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreShaderManager.d.ts +3 -2
- package/dist/src/core/CoreShaderManager.js +1 -1
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/CoreTextureManager.d.ts +35 -0
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/TextureList.d.ts +1 -0
- package/dist/src/core/TextureList.js +34 -0
- package/dist/src/core/TextureList.js.map +1 -0
- package/dist/src/core/lib/ImageWorker.d.ts +0 -1
- package/dist/src/core/lib/ImageWorker.js +1 -6
- package/dist/src/core/lib/ImageWorker.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +2 -0
- package/dist/src/core/lib/utils.js +21 -0
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/renderers/SpecificNode.d.ts +1 -0
- package/dist/src/core/renderers/SpecificNode.js +19 -0
- package/dist/src/core/renderers/SpecificNode.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +25 -0
- package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/newShader/abcMock.d.ts +1 -0
- package/dist/src/core/renderers/webgl/newShader/abcMock.js +2 -0
- package/dist/src/core/renderers/webgl/newShader/abcMock.js.map +1 -0
- package/dist/src/core/renderers/webgl/newShader/effectsMock.d.ts +13 -0
- package/dist/src/core/renderers/webgl/newShader/effectsMock.js +62 -0
- package/dist/src/core/renderers/webgl/newShader/effectsMock.js.map +1 -0
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.d.ts +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +2 -1
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.js +7 -4
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/effectsMock.d.ts +13 -0
- package/dist/src/effectsMock.js +62 -0
- package/dist/src/effectsMock.js.map +1 -0
- package/dist/src/main-api/DynamicShaderController.d.ts +34 -0
- package/dist/src/main-api/DynamicShaderController.js +54 -0
- package/dist/src/main-api/DynamicShaderController.js.map +1 -0
- package/dist/src/main-api/Renderer.d.ts +29 -14
- package/dist/src/main-api/Renderer.js +19 -14
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/main-api/ShaderController.d.ts +36 -0
- package/dist/src/main-api/ShaderController.js +32 -0
- package/dist/src/main-api/ShaderController.js.map +1 -0
- package/dist/src/main-api/utils.d.ts +1 -1
- package/dist/src/render-drivers/utils.js +6 -1
- package/dist/src/render-drivers/utils.js.map +1 -1
- package/dist/src/test.d.ts +1 -0
- package/dist/src/test.js +4 -0
- package/dist/src/test.js.map +1 -0
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/main-api.ts +2 -0
- package/package.json +1 -1
- package/src/core/CoreNode.ts +45 -0
- package/src/core/CoreShaderManager.ts +7 -2
- package/src/core/CoreTextureManager.ts +39 -0
- package/src/core/lib/ImageWorker.ts +1 -7
- package/src/core/lib/utils.ts +27 -0
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +27 -0
- package/src/core/renderers/webgl/shaders/DynamicShader.ts +1 -1
- package/src/core/renderers/webgl/shaders/effects/BorderEffect.ts +2 -1
- package/src/core/textures/ImageTexture.ts +8 -4
- package/src/render-drivers/utils.ts +6 -1
|
@@ -125,11 +125,6 @@ export class ImageWorkerManager {
|
|
|
125
125
|
return worker;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
private convertUrlToAbsolute(url: string): string {
|
|
129
|
-
const absoluteUrl = new URL(url, self.location.href);
|
|
130
|
-
return absoluteUrl.href;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
128
|
getImage(
|
|
134
129
|
src: string,
|
|
135
130
|
premultiplyAlpha: boolean | null,
|
|
@@ -137,14 +132,13 @@ export class ImageWorkerManager {
|
|
|
137
132
|
return new Promise((resolve, reject) => {
|
|
138
133
|
try {
|
|
139
134
|
if (this.workers) {
|
|
140
|
-
const absoluteSrcUrl = this.convertUrlToAbsolute(src);
|
|
141
135
|
const id = this.nextId++;
|
|
142
136
|
this.messageManager[id] = [resolve, reject];
|
|
143
137
|
const nextWorker = this.getNextWorker();
|
|
144
138
|
if (nextWorker) {
|
|
145
139
|
nextWorker.postMessage({
|
|
146
140
|
id,
|
|
147
|
-
src:
|
|
141
|
+
src: src,
|
|
148
142
|
premultiplyAlpha,
|
|
149
143
|
});
|
|
150
144
|
}
|
package/src/core/lib/utils.ts
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
export const PROTOCOL_REGEX = /^(data|ftps?|https?):/;
|
|
21
|
+
|
|
20
22
|
export type RGBA = [r: number, g: number, b: number, a: number];
|
|
21
23
|
export const getNormalizedRgbaComponents = (rgba: number): RGBA => {
|
|
22
24
|
const r = rgba >>> 24;
|
|
@@ -248,3 +250,28 @@ export function isBoundPositive(bound: Bound): boolean {
|
|
|
248
250
|
export function isRectPositive(rect: Rect): boolean {
|
|
249
251
|
return rect.width > 0 && rect.height > 0;
|
|
250
252
|
}
|
|
253
|
+
|
|
254
|
+
export function convertUrlToAbsolute(url: string): string {
|
|
255
|
+
// handle local file imports if the url isn't remote resource or data blob
|
|
256
|
+
if (self.location.protocol === 'file:' && !PROTOCOL_REGEX.test(url)) {
|
|
257
|
+
const path = self.location.pathname.split('/');
|
|
258
|
+
path.pop();
|
|
259
|
+
const basePath = path.join('/');
|
|
260
|
+
const baseUrl = self.location.protocol + '//' + basePath;
|
|
261
|
+
|
|
262
|
+
// check if url has a leading dot
|
|
263
|
+
if (url.charAt(0) === '.') {
|
|
264
|
+
url = url.slice(1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// check if url has a leading slash
|
|
268
|
+
if (url.charAt(0) === '/') {
|
|
269
|
+
url = url.slice(1);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return baseUrl + '/' + url;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const absoluteUrl = new URL(url, self.location.href);
|
|
276
|
+
return absoluteUrl.href;
|
|
277
|
+
}
|
|
@@ -50,6 +50,7 @@ import { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
|
50
50
|
import { RenderTexture } from '../../textures/RenderTexture.js';
|
|
51
51
|
import type { CoreNode } from '../../CoreNode.js';
|
|
52
52
|
import { WebGlCoreCtxRenderTexture } from './WebGlCoreCtxRenderTexture.js';
|
|
53
|
+
import { ImageTexture } from '../../textures/ImageTexture.js';
|
|
53
54
|
|
|
54
55
|
const WORDS_PER_QUAD = 24;
|
|
55
56
|
// const BYTES_PER_QUAD = WORDS_PER_QUAD * 4;
|
|
@@ -298,6 +299,32 @@ export class WebGlCoreRenderer extends CoreRenderer {
|
|
|
298
299
|
texture = texture.parentTexture;
|
|
299
300
|
}
|
|
300
301
|
|
|
302
|
+
const resizeMode = textureOptions?.resizeMode ?? false;
|
|
303
|
+
|
|
304
|
+
if (texture instanceof ImageTexture) {
|
|
305
|
+
if (resizeMode && texture.dimensions) {
|
|
306
|
+
const { width: tw, height: th } = texture.dimensions;
|
|
307
|
+
if (resizeMode.type === 'cover') {
|
|
308
|
+
const scaleX = width / tw;
|
|
309
|
+
const scaleY = height / th;
|
|
310
|
+
const scale = Math.max(scaleX, scaleY);
|
|
311
|
+
const precision = 1 / scale;
|
|
312
|
+
// Determine based on width
|
|
313
|
+
if (scale && scaleX && scaleX < scale) {
|
|
314
|
+
const desiredSize = precision * width;
|
|
315
|
+
texCoordX1 = (1 - desiredSize / tw) * (resizeMode.clipX ?? 0.5);
|
|
316
|
+
texCoordX2 = texCoordX1 + desiredSize / tw;
|
|
317
|
+
}
|
|
318
|
+
// Determine based on height
|
|
319
|
+
if (scale && scaleY && scaleY < scale) {
|
|
320
|
+
const desiredSize = precision * height;
|
|
321
|
+
texCoordY1 = (1 - desiredSize / th) * (resizeMode.clipY ?? 0.5);
|
|
322
|
+
texCoordY2 = texCoordY1 + desiredSize / th;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
301
328
|
// Flip texture coordinates if dictated by texture options
|
|
302
329
|
if (flipX) {
|
|
303
330
|
[texCoordX1, texCoordX2] = [texCoordX2, texCoordX1];
|
|
@@ -65,7 +65,7 @@ type MapEffectDescs<T extends keyof EffectMap> = T extends keyof EffectMap
|
|
|
65
65
|
? SpecificEffectDesc<T>
|
|
66
66
|
: never;
|
|
67
67
|
|
|
68
|
-
type EffectDesc = MapEffectDescs<keyof EffectMap>;
|
|
68
|
+
export type EffectDesc = MapEffectDescs<keyof EffectMap>;
|
|
69
69
|
|
|
70
70
|
export interface DynamicShaderProps
|
|
71
71
|
extends DimensionsShaderProp,
|
|
@@ -76,7 +76,8 @@ export class BorderEffect extends ShaderEffect {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
static override onEffectMask = `
|
|
79
|
-
float
|
|
79
|
+
float intR = shaderMask + 1.0;
|
|
80
|
+
float mask = clamp(intR + width, 0.0, 1.0) - clamp(intR, 0.0, 1.0);
|
|
80
81
|
return mix(shaderColor, mix(shaderColor, maskColor, maskColor.a), mask);
|
|
81
82
|
`;
|
|
82
83
|
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
isCompressedTextureContainer,
|
|
24
24
|
loadCompressedTexture,
|
|
25
25
|
} from '../lib/textureCompression.js';
|
|
26
|
+
import { convertUrlToAbsolute } from '../lib/utils.js';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Properties of the {@link ImageTexture}
|
|
@@ -108,13 +109,16 @@ export class ImageTexture extends Texture {
|
|
|
108
109
|
return loadCompressedTexture(src);
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
// Convert relative URL to absolute URL
|
|
113
|
+
const absoluteSrc = convertUrlToAbsolute(src);
|
|
114
|
+
|
|
111
115
|
if (this.txManager.imageWorkerManager) {
|
|
112
116
|
return await this.txManager.imageWorkerManager.getImage(
|
|
113
|
-
|
|
117
|
+
absoluteSrc,
|
|
114
118
|
premultiplyAlpha,
|
|
115
119
|
);
|
|
116
120
|
} else if (this.txManager.hasCreateImageBitmap) {
|
|
117
|
-
const response = await fetch(
|
|
121
|
+
const response = await fetch(absoluteSrc);
|
|
118
122
|
const blob = await response.blob();
|
|
119
123
|
const hasAlphaChannel =
|
|
120
124
|
premultiplyAlpha ?? this.hasAlphaChannel(blob.type);
|
|
@@ -131,7 +135,7 @@ export class ImageTexture extends Texture {
|
|
|
131
135
|
if (!(src.substr(0, 5) === 'data:')) {
|
|
132
136
|
img.crossOrigin = 'Anonymous';
|
|
133
137
|
}
|
|
134
|
-
img.src =
|
|
138
|
+
img.src = absoluteSrc;
|
|
135
139
|
await new Promise<void>((resolve, reject) => {
|
|
136
140
|
img.onload = () => resolve();
|
|
137
141
|
img.onerror = () => reject(new Error(`Failed to load image`));
|
|
@@ -162,7 +166,7 @@ export class ImageTexture extends Texture {
|
|
|
162
166
|
return {
|
|
163
167
|
src: props.src ?? '',
|
|
164
168
|
premultiplyAlpha: props.premultiplyAlpha ?? true, // null,
|
|
165
|
-
key: props.key ?? null
|
|
169
|
+
key: props.key ?? null,
|
|
166
170
|
};
|
|
167
171
|
}
|
|
168
172
|
|
|
@@ -58,7 +58,12 @@ export async function loadCoreExtension(
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export function santizeCustomDataMap(d: CustomDataMap): CustomDataMap {
|
|
61
|
-
const validTypes = {
|
|
61
|
+
const validTypes = {
|
|
62
|
+
boolean: true,
|
|
63
|
+
string: true,
|
|
64
|
+
number: true,
|
|
65
|
+
undefined: true,
|
|
66
|
+
};
|
|
62
67
|
|
|
63
68
|
const keys = Object.keys(d);
|
|
64
69
|
for (let i = 0; i < keys.length; i++) {
|