This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,26 @@
import { GraphicsContext } from '../../../../scene/graphics/shared/GraphicsContext';
import { type LoaderParser } from '../LoaderParser';
import type { TextureSourceOptions } from '../../../../rendering/renderers/shared/texture/sources/TextureSource';
import type { Texture } from '../../../../rendering/renderers/shared/texture/Texture';
/**
* Configuration for the [loadSVG]{@link assets.loadSVG} plugin.
* @see assets.loadSVG
* @memberof assets
*/
export interface LoadSVGConfig {
/**
* The crossOrigin value to use for loading the SVG as an image.
* @default 'anonymous'
*/
crossOrigin: HTMLImageElement['crossOrigin'];
/**
* When set to `true`, loading and decoding images will happen with `new Image()`,
* @default false
*/
parseAsGraphicsContext: boolean;
}
/**
* A simple loader plugin for loading json data
* @memberof assets
*/
export declare const loadSvg: LoaderParser<Texture | GraphicsContext, TextureSourceOptions & LoadSVGConfig, LoadSVGConfig>;

View File

@@ -0,0 +1,75 @@
'use strict';
var adapter = require('../../../../environment/adapter.js');
var Extensions = require('../../../../extensions/Extensions.js');
var ImageSource = require('../../../../rendering/renderers/shared/texture/sources/ImageSource.js');
var GraphicsContext = require('../../../../scene/graphics/shared/GraphicsContext.js');
var getResolutionOfUrl = require('../../../../utils/network/getResolutionOfUrl.js');
var checkDataUrl = require('../../../utils/checkDataUrl.js');
var checkExtension = require('../../../utils/checkExtension.js');
var LoaderParser = require('../LoaderParser.js');
var createTexture = require('./utils/createTexture.js');
"use strict";
const validSVGExtension = ".svg";
const validSVGMIME = "image/svg+xml";
const loadSvg = {
extension: {
type: Extensions.ExtensionType.LoadParser,
priority: LoaderParser.LoaderParserPriority.Low,
name: "loadSVG"
},
name: "loadSVG",
config: {
crossOrigin: "anonymous",
parseAsGraphicsContext: false
},
test(url) {
return checkDataUrl.checkDataUrl(url, validSVGMIME) || checkExtension.checkExtension(url, validSVGExtension);
},
async load(url, asset, loader) {
if (asset.data.parseAsGraphicsContext ?? this.config.parseAsGraphicsContext) {
return loadAsGraphics(url);
}
return loadAsTexture(url, asset, loader, this.config.crossOrigin);
},
unload(asset) {
asset.destroy(true);
}
};
async function loadAsTexture(url, asset, loader, crossOrigin) {
const response = await adapter.DOMAdapter.get().fetch(url);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const image = new Image();
image.src = blobUrl;
image.crossOrigin = crossOrigin;
await image.decode();
URL.revokeObjectURL(blobUrl);
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
const resolution = asset.data?.resolution || getResolutionOfUrl.getResolutionOfUrl(url);
const width = asset.data?.width ?? image.width;
const height = asset.data?.height ?? image.height;
canvas.width = width * resolution;
canvas.height = height * resolution;
context.drawImage(image, 0, 0, width * resolution, height * resolution);
const { parseAsGraphicsContext: _p, ...rest } = asset.data;
const base = new ImageSource.ImageSource({
resource: canvas,
alphaMode: "premultiply-alpha-on-upload",
resolution,
...rest
});
return createTexture.createTexture(base, loader, url);
}
async function loadAsGraphics(url) {
const response = await adapter.DOMAdapter.get().fetch(url);
const svgSource = await response.text();
const context = new GraphicsContext.GraphicsContext();
context.svg(svgSource);
return context;
}
exports.loadSvg = loadSvg;
//# sourceMappingURL=loadSVG.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,73 @@
import { DOMAdapter } from '../../../../environment/adapter.mjs';
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { ImageSource } from '../../../../rendering/renderers/shared/texture/sources/ImageSource.mjs';
import { GraphicsContext } from '../../../../scene/graphics/shared/GraphicsContext.mjs';
import { getResolutionOfUrl } from '../../../../utils/network/getResolutionOfUrl.mjs';
import { checkDataUrl } from '../../../utils/checkDataUrl.mjs';
import { checkExtension } from '../../../utils/checkExtension.mjs';
import { LoaderParserPriority } from '../LoaderParser.mjs';
import { createTexture } from './utils/createTexture.mjs';
"use strict";
const validSVGExtension = ".svg";
const validSVGMIME = "image/svg+xml";
const loadSvg = {
extension: {
type: ExtensionType.LoadParser,
priority: LoaderParserPriority.Low,
name: "loadSVG"
},
name: "loadSVG",
config: {
crossOrigin: "anonymous",
parseAsGraphicsContext: false
},
test(url) {
return checkDataUrl(url, validSVGMIME) || checkExtension(url, validSVGExtension);
},
async load(url, asset, loader) {
if (asset.data.parseAsGraphicsContext ?? this.config.parseAsGraphicsContext) {
return loadAsGraphics(url);
}
return loadAsTexture(url, asset, loader, this.config.crossOrigin);
},
unload(asset) {
asset.destroy(true);
}
};
async function loadAsTexture(url, asset, loader, crossOrigin) {
const response = await DOMAdapter.get().fetch(url);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const image = new Image();
image.src = blobUrl;
image.crossOrigin = crossOrigin;
await image.decode();
URL.revokeObjectURL(blobUrl);
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
const resolution = asset.data?.resolution || getResolutionOfUrl(url);
const width = asset.data?.width ?? image.width;
const height = asset.data?.height ?? image.height;
canvas.width = width * resolution;
canvas.height = height * resolution;
context.drawImage(image, 0, 0, width * resolution, height * resolution);
const { parseAsGraphicsContext: _p, ...rest } = asset.data;
const base = new ImageSource({
resource: canvas,
alphaMode: "premultiply-alpha-on-upload",
resolution,
...rest
});
return createTexture(base, loader, url);
}
async function loadAsGraphics(url) {
const response = await DOMAdapter.get().fetch(url);
const svgSource = await response.text();
const context = new GraphicsContext();
context.svg(svgSource);
return context;
}
export { loadSvg };
//# sourceMappingURL=loadSVG.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
import type { TextureSourceOptions } from '../../../../rendering/renderers/shared/texture/sources/TextureSource';
import type { Texture } from '../../../../rendering/renderers/shared/texture/Texture';
import type { ResolvedAsset } from '../../../types';
import type { LoaderParser } from '../LoaderParser';
/**
* Configuration for the [loadTextures]{@link assets.loadTextures} plugin.
* @see assets.loadTextures
* @memberof assets
*/
export interface LoadTextureConfig {
/**
* When set to `true`, loading and decoding images will happen with Worker thread,
* if available on the browser. This is much more performant as network requests
* and decoding can be expensive on the CPU. However, not all environments support
* Workers, in some cases it can be helpful to disable by setting to `false`.
* @default true
*/
preferWorkers: boolean;
/**
* When set to `true`, loading and decoding images will happen with `createImageBitmap`,
* otherwise it will use `new Image()`.
* @default true
*/
preferCreateImageBitmap: boolean;
/**
* The crossOrigin value to use for images when `preferCreateImageBitmap` is `false`.
* @default 'anonymous'
*/
crossOrigin: HTMLImageElement['crossOrigin'];
}
/**
* Returns a promise that resolves an ImageBitmaps.
* This function is designed to be used by a worker.
* Part of WorkerManager!
* @param url - The image to load an image bitmap for
* @ignore
*/
export declare function loadImageBitmap(url: string, asset?: ResolvedAsset<TextureSourceOptions<any>>): Promise<ImageBitmap>;
/**
* A simple plugin to load our textures!
* This makes use of imageBitmaps where available.
* We load the `ImageBitmap` on a different thread using workers if possible.
* We can then use the `ImageBitmap` as a source for a Pixi texture
*
* You can customize the behavior of this loader by setting the `config` property.
* Which can be found [here]{@link assets.LoadTextureConfig}
* ```js
* // Set the config
* import { loadTextures } from 'pixi.js';
*
* loadTextures.config = {
* // If true we will use a worker to load the ImageBitmap
* preferWorkers: true,
* // If false we will use new Image() instead of createImageBitmap,
* // we'll also disable the use of workers as it requires createImageBitmap
* preferCreateImageBitmap: true,
* crossOrigin: 'anonymous',
* };
* ```
* @memberof assets
*/
export declare const loadTextures: LoaderParser<Texture, TextureSourceOptions, LoadTextureConfig>;

View File

@@ -0,0 +1,81 @@
'use strict';
var adapter = require('../../../../environment/adapter.js');
var Extensions = require('../../../../extensions/Extensions.js');
var ImageSource = require('../../../../rendering/renderers/shared/texture/sources/ImageSource.js');
var getResolutionOfUrl = require('../../../../utils/network/getResolutionOfUrl.js');
var checkDataUrl = require('../../../utils/checkDataUrl.js');
var checkExtension = require('../../../utils/checkExtension.js');
var WorkerManager = require('../../workers/WorkerManager.js');
var LoaderParser = require('../LoaderParser.js');
var createTexture = require('./utils/createTexture.js');
"use strict";
const validImageExtensions = [".jpeg", ".jpg", ".png", ".webp", ".avif"];
const validImageMIMEs = [
"image/jpeg",
"image/png",
"image/webp",
"image/avif"
];
async function loadImageBitmap(url, asset) {
const response = await adapter.DOMAdapter.get().fetch(url);
if (!response.ok) {
throw new Error(`[loadImageBitmap] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
}
const imageBlob = await response.blob();
return asset?.data?.alphaMode === "premultiplied-alpha" ? createImageBitmap(imageBlob, { premultiplyAlpha: "none" }) : createImageBitmap(imageBlob);
}
const loadTextures = {
name: "loadTextures",
extension: {
type: Extensions.ExtensionType.LoadParser,
priority: LoaderParser.LoaderParserPriority.High,
name: "loadTextures"
},
config: {
preferWorkers: true,
preferCreateImageBitmap: true,
crossOrigin: "anonymous"
},
test(url) {
return checkDataUrl.checkDataUrl(url, validImageMIMEs) || checkExtension.checkExtension(url, validImageExtensions);
},
async load(url, asset, loader) {
let src = null;
if (globalThis.createImageBitmap && this.config.preferCreateImageBitmap) {
if (this.config.preferWorkers && await WorkerManager.WorkerManager.isImageBitmapSupported()) {
src = await WorkerManager.WorkerManager.loadImageBitmap(url, asset);
} else {
src = await loadImageBitmap(url, asset);
}
} else {
src = await new Promise((resolve) => {
src = new Image();
src.crossOrigin = this.config.crossOrigin;
src.src = url;
if (src.complete) {
resolve(src);
} else {
src.onload = () => {
resolve(src);
};
}
});
}
const base = new ImageSource.ImageSource({
resource: src,
alphaMode: "premultiply-alpha-on-upload",
resolution: asset.data?.resolution || getResolutionOfUrl.getResolutionOfUrl(url),
...asset.data
});
return createTexture.createTexture(base, loader, url);
},
unload(texture) {
texture.destroy(true);
}
};
exports.loadImageBitmap = loadImageBitmap;
exports.loadTextures = loadTextures;
//# sourceMappingURL=loadTextures.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
import { DOMAdapter } from '../../../../environment/adapter.mjs';
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { ImageSource } from '../../../../rendering/renderers/shared/texture/sources/ImageSource.mjs';
import { getResolutionOfUrl } from '../../../../utils/network/getResolutionOfUrl.mjs';
import { checkDataUrl } from '../../../utils/checkDataUrl.mjs';
import { checkExtension } from '../../../utils/checkExtension.mjs';
import { WorkerManager } from '../../workers/WorkerManager.mjs';
import { LoaderParserPriority } from '../LoaderParser.mjs';
import { createTexture } from './utils/createTexture.mjs';
"use strict";
const validImageExtensions = [".jpeg", ".jpg", ".png", ".webp", ".avif"];
const validImageMIMEs = [
"image/jpeg",
"image/png",
"image/webp",
"image/avif"
];
async function loadImageBitmap(url, asset) {
const response = await DOMAdapter.get().fetch(url);
if (!response.ok) {
throw new Error(`[loadImageBitmap] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
}
const imageBlob = await response.blob();
return asset?.data?.alphaMode === "premultiplied-alpha" ? createImageBitmap(imageBlob, { premultiplyAlpha: "none" }) : createImageBitmap(imageBlob);
}
const loadTextures = {
name: "loadTextures",
extension: {
type: ExtensionType.LoadParser,
priority: LoaderParserPriority.High,
name: "loadTextures"
},
config: {
preferWorkers: true,
preferCreateImageBitmap: true,
crossOrigin: "anonymous"
},
test(url) {
return checkDataUrl(url, validImageMIMEs) || checkExtension(url, validImageExtensions);
},
async load(url, asset, loader) {
let src = null;
if (globalThis.createImageBitmap && this.config.preferCreateImageBitmap) {
if (this.config.preferWorkers && await WorkerManager.isImageBitmapSupported()) {
src = await WorkerManager.loadImageBitmap(url, asset);
} else {
src = await loadImageBitmap(url, asset);
}
} else {
src = await new Promise((resolve) => {
src = new Image();
src.crossOrigin = this.config.crossOrigin;
src.src = url;
if (src.complete) {
resolve(src);
} else {
src.onload = () => {
resolve(src);
};
}
});
}
const base = new ImageSource({
resource: src,
alphaMode: "premultiply-alpha-on-upload",
resolution: asset.data?.resolution || getResolutionOfUrl(url),
...asset.data
});
return createTexture(base, loader, url);
},
unload(texture) {
texture.destroy(true);
}
};
export { loadImageBitmap, loadTextures };
//# sourceMappingURL=loadTextures.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import type { VideoSourceOptions } from '../../../../rendering/renderers/shared/texture/sources/VideoSource';
import type { Texture } from '../../../../rendering/renderers/shared/texture/Texture';
import type { ResolvedAsset } from '../../../types';
import type { Loader } from '../../Loader';
/**
* Set cross origin based detecting the url and the crossorigin
* @param element - Element to apply crossOrigin
* @param url - URL to check
* @param crossorigin - Cross origin value to use
* @memberof assets
*/
export declare function crossOrigin(element: HTMLImageElement | HTMLVideoElement, url: string, crossorigin?: boolean | string): void;
/**
* Preload a video element
* @param element - Video element to preload
*/
export declare function preloadVideo(element: HTMLVideoElement): Promise<void>;
/**
* Sets the `crossOrigin` property for this resource based on if the url
* for this resource is cross-origin. If crossOrigin was manually set, this
* function does nothing.
* Nipped from the resource loader!
* @ignore
* @param url - The url to test.
* @param {object} [loc=window.location] - The location object to test against.
* @returns The crossOrigin value to use (or empty string for none).
* @memberof assets
*/
export declare function determineCrossOrigin(url: string, loc?: Location): string;
/**
* A simple plugin to load video textures.
*
* You can pass VideoSource options to the loader via the .data property of the asset descriptor
* when using Asset.load().
* ```js
* // Set the data
* const texture = await Assets.load({
* src: './assets/city.mp4',
* data: {
* preload: true,
* autoPlay: true,
* },
* });
* ```
* @memberof assets
*/
export declare const loadVideoTextures: {
name: string;
extension: {
type: ExtensionType.LoadParser;
name: string;
};
test(url: string): boolean;
load<T>(url: string, asset: ResolvedAsset<VideoSourceOptions>, loader: Loader): Promise<Texture>;
unload(texture: Texture): void;
};

View File

@@ -0,0 +1,121 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var VideoSource = require('../../../../rendering/renderers/shared/texture/sources/VideoSource.js');
var detectVideoAlphaMode = require('../../../../utils/browser/detectVideoAlphaMode.js');
var getResolutionOfUrl = require('../../../../utils/network/getResolutionOfUrl.js');
var checkDataUrl = require('../../../utils/checkDataUrl.js');
var checkExtension = require('../../../utils/checkExtension.js');
var createTexture = require('./utils/createTexture.js');
"use strict";
const validVideoExtensions = [".mp4", ".m4v", ".webm", ".ogg", ".ogv", ".h264", ".avi", ".mov"];
const validVideoMIMEs = validVideoExtensions.map((ext) => `video/${ext.substring(1)}`);
function crossOrigin(element, url, crossorigin) {
if (crossorigin === void 0 && !url.startsWith("data:")) {
element.crossOrigin = determineCrossOrigin(url);
} else if (crossorigin !== false) {
element.crossOrigin = typeof crossorigin === "string" ? crossorigin : "anonymous";
}
}
function preloadVideo(element) {
return new Promise((resolve, reject) => {
element.addEventListener("canplaythrough", loaded);
element.addEventListener("error", error);
element.load();
function loaded() {
cleanup();
resolve();
}
function error(err) {
cleanup();
reject(err);
}
function cleanup() {
element.removeEventListener("canplaythrough", loaded);
element.removeEventListener("error", error);
}
});
}
function determineCrossOrigin(url, loc = globalThis.location) {
if (url.startsWith("data:")) {
return "";
}
loc = loc || globalThis.location;
const parsedUrl = new URL(url, document.baseURI);
if (parsedUrl.hostname !== loc.hostname || parsedUrl.port !== loc.port || parsedUrl.protocol !== loc.protocol) {
return "anonymous";
}
return "";
}
const loadVideoTextures = {
name: "loadVideo",
extension: {
type: Extensions.ExtensionType.LoadParser,
name: "loadVideo"
},
test(url) {
const isValidDataUrl = checkDataUrl.checkDataUrl(url, validVideoMIMEs);
const isValidExtension = checkExtension.checkExtension(url, validVideoExtensions);
return isValidDataUrl || isValidExtension;
},
async load(url, asset, loader) {
const options = {
...VideoSource.VideoSource.defaultOptions,
resolution: asset.data?.resolution || getResolutionOfUrl.getResolutionOfUrl(url),
alphaMode: asset.data?.alphaMode || await detectVideoAlphaMode.detectVideoAlphaMode(),
...asset.data
};
const videoElement = document.createElement("video");
const attributeMap = {
preload: options.autoLoad !== false ? "auto" : void 0,
"webkit-playsinline": options.playsinline !== false ? "" : void 0,
playsinline: options.playsinline !== false ? "" : void 0,
muted: options.muted === true ? "" : void 0,
loop: options.loop === true ? "" : void 0,
autoplay: options.autoPlay !== false ? "" : void 0
};
Object.keys(attributeMap).forEach((key) => {
const value = attributeMap[key];
if (value !== void 0)
videoElement.setAttribute(key, value);
});
if (options.muted === true) {
videoElement.muted = true;
}
crossOrigin(videoElement, url, options.crossorigin);
const sourceElement = document.createElement("source");
let mime;
if (url.startsWith("data:")) {
mime = url.slice(5, url.indexOf(";"));
} else if (!url.startsWith("blob:")) {
const ext = url.split("?")[0].slice(url.lastIndexOf(".") + 1).toLowerCase();
mime = VideoSource.VideoSource.MIME_TYPES[ext] || `video/${ext}`;
}
sourceElement.src = url;
if (mime) {
sourceElement.type = mime;
}
return new Promise((resolve) => {
const onCanPlay = async () => {
const base = new VideoSource.VideoSource({ ...options, resource: videoElement });
videoElement.removeEventListener("canplay", onCanPlay);
if (asset.data.preload) {
await preloadVideo(videoElement);
}
resolve(createTexture.createTexture(base, loader, url));
};
videoElement.addEventListener("canplay", onCanPlay);
videoElement.appendChild(sourceElement);
});
},
unload(texture) {
texture.destroy(true);
}
};
exports.crossOrigin = crossOrigin;
exports.determineCrossOrigin = determineCrossOrigin;
exports.loadVideoTextures = loadVideoTextures;
exports.preloadVideo = preloadVideo;
//# sourceMappingURL=loadVideoTextures.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,116 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { VideoSource } from '../../../../rendering/renderers/shared/texture/sources/VideoSource.mjs';
import { detectVideoAlphaMode } from '../../../../utils/browser/detectVideoAlphaMode.mjs';
import { getResolutionOfUrl } from '../../../../utils/network/getResolutionOfUrl.mjs';
import { checkDataUrl } from '../../../utils/checkDataUrl.mjs';
import { checkExtension } from '../../../utils/checkExtension.mjs';
import { createTexture } from './utils/createTexture.mjs';
"use strict";
const validVideoExtensions = [".mp4", ".m4v", ".webm", ".ogg", ".ogv", ".h264", ".avi", ".mov"];
const validVideoMIMEs = validVideoExtensions.map((ext) => `video/${ext.substring(1)}`);
function crossOrigin(element, url, crossorigin) {
if (crossorigin === void 0 && !url.startsWith("data:")) {
element.crossOrigin = determineCrossOrigin(url);
} else if (crossorigin !== false) {
element.crossOrigin = typeof crossorigin === "string" ? crossorigin : "anonymous";
}
}
function preloadVideo(element) {
return new Promise((resolve, reject) => {
element.addEventListener("canplaythrough", loaded);
element.addEventListener("error", error);
element.load();
function loaded() {
cleanup();
resolve();
}
function error(err) {
cleanup();
reject(err);
}
function cleanup() {
element.removeEventListener("canplaythrough", loaded);
element.removeEventListener("error", error);
}
});
}
function determineCrossOrigin(url, loc = globalThis.location) {
if (url.startsWith("data:")) {
return "";
}
loc = loc || globalThis.location;
const parsedUrl = new URL(url, document.baseURI);
if (parsedUrl.hostname !== loc.hostname || parsedUrl.port !== loc.port || parsedUrl.protocol !== loc.protocol) {
return "anonymous";
}
return "";
}
const loadVideoTextures = {
name: "loadVideo",
extension: {
type: ExtensionType.LoadParser,
name: "loadVideo"
},
test(url) {
const isValidDataUrl = checkDataUrl(url, validVideoMIMEs);
const isValidExtension = checkExtension(url, validVideoExtensions);
return isValidDataUrl || isValidExtension;
},
async load(url, asset, loader) {
const options = {
...VideoSource.defaultOptions,
resolution: asset.data?.resolution || getResolutionOfUrl(url),
alphaMode: asset.data?.alphaMode || await detectVideoAlphaMode(),
...asset.data
};
const videoElement = document.createElement("video");
const attributeMap = {
preload: options.autoLoad !== false ? "auto" : void 0,
"webkit-playsinline": options.playsinline !== false ? "" : void 0,
playsinline: options.playsinline !== false ? "" : void 0,
muted: options.muted === true ? "" : void 0,
loop: options.loop === true ? "" : void 0,
autoplay: options.autoPlay !== false ? "" : void 0
};
Object.keys(attributeMap).forEach((key) => {
const value = attributeMap[key];
if (value !== void 0)
videoElement.setAttribute(key, value);
});
if (options.muted === true) {
videoElement.muted = true;
}
crossOrigin(videoElement, url, options.crossorigin);
const sourceElement = document.createElement("source");
let mime;
if (url.startsWith("data:")) {
mime = url.slice(5, url.indexOf(";"));
} else if (!url.startsWith("blob:")) {
const ext = url.split("?")[0].slice(url.lastIndexOf(".") + 1).toLowerCase();
mime = VideoSource.MIME_TYPES[ext] || `video/${ext}`;
}
sourceElement.src = url;
if (mime) {
sourceElement.type = mime;
}
return new Promise((resolve) => {
const onCanPlay = async () => {
const base = new VideoSource({ ...options, resource: videoElement });
videoElement.removeEventListener("canplay", onCanPlay);
if (asset.data.preload) {
await preloadVideo(videoElement);
}
resolve(createTexture(base, loader, url));
};
videoElement.addEventListener("canplay", onCanPlay);
videoElement.appendChild(sourceElement);
});
},
unload(texture) {
texture.destroy(true);
}
};
export { crossOrigin, determineCrossOrigin, loadVideoTextures, preloadVideo };
//# sourceMappingURL=loadVideoTextures.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture';
import type { TextureSource } from '../../../../../rendering/renderers/shared/texture/sources/TextureSource';
import type { Loader } from '../../../Loader';
/**
* Creates a texture from a source and adds it to the cache.
* @param source - source of the texture
* @param loader - loader
* @param url - url of the texture
* @ignore
*/
export declare function createTexture(source: TextureSource, loader: Loader, url: string): Texture<TextureSource<any>>;

View File

@@ -0,0 +1,37 @@
'use strict';
var Texture = require('../../../../../rendering/renderers/shared/texture/Texture.js');
var warn = require('../../../../../utils/logging/warn.js');
var Cache = require('../../../../cache/Cache.js');
"use strict";
function createTexture(source, loader, url) {
source.label = url;
source._sourceOrigin = url;
const texture = new Texture.Texture({
source,
label: url
});
const unload = () => {
delete loader.promiseCache[url];
if (Cache.Cache.has(url)) {
Cache.Cache.remove(url);
}
};
texture.source.once("destroy", () => {
if (loader.promiseCache[url]) {
warn.warn("[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the TextureSource.");
unload();
}
});
texture.once("destroy", () => {
if (!source.destroyed) {
warn.warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture.");
unload();
}
});
return texture;
}
exports.createTexture = createTexture;
//# sourceMappingURL=createTexture.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createTexture.js","sources":["../../../../../../src/assets/loader/parsers/textures/utils/createTexture.ts"],"sourcesContent":["import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture';\nimport { warn } from '../../../../../utils/logging/warn';\nimport { Cache } from '../../../../cache/Cache';\n\nimport type { TextureSource } from '../../../../../rendering/renderers/shared/texture/sources/TextureSource';\nimport type { Loader } from '../../../Loader';\n\n/**\n * Creates a texture from a source and adds it to the cache.\n * @param source - source of the texture\n * @param loader - loader\n * @param url - url of the texture\n * @ignore\n */\nexport function createTexture(source: TextureSource, loader: Loader, url: string)\n{\n source.label = url;\n source._sourceOrigin = url;\n\n const texture = new Texture({\n source,\n label: url,\n });\n\n const unload = () =>\n {\n delete loader.promiseCache[url];\n\n if (Cache.has(url))\n {\n Cache.remove(url);\n }\n };\n\n // remove the promise from the loader and the url from the cache when the texture is destroyed\n texture.source.once('destroy', () =>\n {\n if (loader.promiseCache[url])\n {\n // #if _DEBUG\n warn('[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the TextureSource.');\n // #endif\n\n unload();\n }\n });\n\n texture.once('destroy', () =>\n {\n if (!source.destroyed)\n {\n // #if _DEBUG\n warn('[Assets] A Texture managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the Texture.');\n // #endif\n\n unload();\n }\n });\n\n return texture;\n}\n"],"names":["Texture","Cache","warn"],"mappings":";;;;;;;AAcgB,SAAA,aAAA,CAAc,MAAuB,EAAA,MAAA,EAAgB,GACrE,EAAA;AACI,EAAA,MAAA,CAAO,KAAQ,GAAA,GAAA,CAAA;AACf,EAAA,MAAA,CAAO,aAAgB,GAAA,GAAA,CAAA;AAEvB,EAAM,MAAA,OAAA,GAAU,IAAIA,eAAQ,CAAA;AAAA,IACxB,MAAA;AAAA,IACA,KAAO,EAAA,GAAA;AAAA,GACV,CAAA,CAAA;AAED,EAAA,MAAM,SAAS,MACf;AACI,IAAO,OAAA,MAAA,CAAO,aAAa,GAAG,CAAA,CAAA;AAE9B,IAAI,IAAAC,WAAA,CAAM,GAAI,CAAA,GAAG,CACjB,EAAA;AACI,MAAAA,WAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,KACpB;AAAA,GACJ,CAAA;AAGA,EAAQ,OAAA,CAAA,MAAA,CAAO,IAAK,CAAA,SAAA,EAAW,MAC/B;AACI,IAAI,IAAA,MAAA,CAAO,YAAa,CAAA,GAAG,CAC3B,EAAA;AAEI,MAAAC,SAAA,CAAK,4IAC0D,CAAA,CAAA;AAG/D,MAAO,MAAA,EAAA,CAAA;AAAA,KACX;AAAA,GACH,CAAA,CAAA;AAED,EAAQ,OAAA,CAAA,IAAA,CAAK,WAAW,MACxB;AACI,IAAI,IAAA,CAAC,OAAO,SACZ,EAAA;AAEI,MAAAA,SAAA,CAAK,gIACsD,CAAA,CAAA;AAG3D,MAAO,MAAA,EAAA,CAAA;AAAA,KACX;AAAA,GACH,CAAA,CAAA;AAED,EAAO,OAAA,OAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,35 @@
import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture.mjs';
import { warn } from '../../../../../utils/logging/warn.mjs';
import { Cache } from '../../../../cache/Cache.mjs';
"use strict";
function createTexture(source, loader, url) {
source.label = url;
source._sourceOrigin = url;
const texture = new Texture({
source,
label: url
});
const unload = () => {
delete loader.promiseCache[url];
if (Cache.has(url)) {
Cache.remove(url);
}
};
texture.source.once("destroy", () => {
if (loader.promiseCache[url]) {
warn("[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the TextureSource.");
unload();
}
});
texture.once("destroy", () => {
if (!source.destroyed) {
warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture.");
unload();
}
});
return texture;
}
export { createTexture };
//# sourceMappingURL=createTexture.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createTexture.mjs","sources":["../../../../../../src/assets/loader/parsers/textures/utils/createTexture.ts"],"sourcesContent":["import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture';\nimport { warn } from '../../../../../utils/logging/warn';\nimport { Cache } from '../../../../cache/Cache';\n\nimport type { TextureSource } from '../../../../../rendering/renderers/shared/texture/sources/TextureSource';\nimport type { Loader } from '../../../Loader';\n\n/**\n * Creates a texture from a source and adds it to the cache.\n * @param source - source of the texture\n * @param loader - loader\n * @param url - url of the texture\n * @ignore\n */\nexport function createTexture(source: TextureSource, loader: Loader, url: string)\n{\n source.label = url;\n source._sourceOrigin = url;\n\n const texture = new Texture({\n source,\n label: url,\n });\n\n const unload = () =>\n {\n delete loader.promiseCache[url];\n\n if (Cache.has(url))\n {\n Cache.remove(url);\n }\n };\n\n // remove the promise from the loader and the url from the cache when the texture is destroyed\n texture.source.once('destroy', () =>\n {\n if (loader.promiseCache[url])\n {\n // #if _DEBUG\n warn('[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the TextureSource.');\n // #endif\n\n unload();\n }\n });\n\n texture.once('destroy', () =>\n {\n if (!source.destroyed)\n {\n // #if _DEBUG\n warn('[Assets] A Texture managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the Texture.');\n // #endif\n\n unload();\n }\n });\n\n return texture;\n}\n"],"names":[],"mappings":";;;;;AAcgB,SAAA,aAAA,CAAc,MAAuB,EAAA,MAAA,EAAgB,GACrE,EAAA;AACI,EAAA,MAAA,CAAO,KAAQ,GAAA,GAAA,CAAA;AACf,EAAA,MAAA,CAAO,aAAgB,GAAA,GAAA,CAAA;AAEvB,EAAM,MAAA,OAAA,GAAU,IAAI,OAAQ,CAAA;AAAA,IACxB,MAAA;AAAA,IACA,KAAO,EAAA,GAAA;AAAA,GACV,CAAA,CAAA;AAED,EAAA,MAAM,SAAS,MACf;AACI,IAAO,OAAA,MAAA,CAAO,aAAa,GAAG,CAAA,CAAA;AAE9B,IAAI,IAAA,KAAA,CAAM,GAAI,CAAA,GAAG,CACjB,EAAA;AACI,MAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,KACpB;AAAA,GACJ,CAAA;AAGA,EAAQ,OAAA,CAAA,MAAA,CAAO,IAAK,CAAA,SAAA,EAAW,MAC/B;AACI,IAAI,IAAA,MAAA,CAAO,YAAa,CAAA,GAAG,CAC3B,EAAA;AAEI,MAAA,IAAA,CAAK,4IAC0D,CAAA,CAAA;AAG/D,MAAO,MAAA,EAAA,CAAA;AAAA,KACX;AAAA,GACH,CAAA,CAAA;AAED,EAAQ,OAAA,CAAA,IAAA,CAAK,WAAW,MACxB;AACI,IAAI,IAAA,CAAC,OAAO,SACZ,EAAA;AAEI,MAAA,IAAA,CAAK,gIACsD,CAAA,CAAA;AAG3D,MAAO,MAAA,EAAA,CAAA;AAAA,KACX;AAAA,GACH,CAAA,CAAA;AAED,EAAO,OAAA,OAAA,CAAA;AACX;;;;"}