@naanouff/w3dts-loader-images 0.0.0-stage → 0.0.19
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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @naanouff/w3dts-loader-images
|
|
2
|
+
|
|
3
|
+
Textures 2D LDR (`fetch` / `Blob` + `TextureLoader` du core). Facade du composite [`@naanouff/w3dts-loaders`](../loaders/README.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAC/B,KAAK,uBAAuB,GAC7B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TextureData, TextureLoaderOptions } from '../../core/src/index.ts';
|
|
2
|
+
export type LoadImageTextureOptions = TextureLoaderOptions & {
|
|
3
|
+
/**
|
|
4
|
+
* When set (positive), decode so max(width, height) is at most this value (aspect preserved).
|
|
5
|
+
* Reduces main-thread decode cost for very large images (two-step `createImageBitmap` when resize applies).
|
|
6
|
+
*/
|
|
7
|
+
maxDecodeDimension?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Loads an LDR image (PNG, JPEG, WebP, etc.) from a URL or `Blob`/`File` and returns GPU texture data
|
|
11
|
+
* via {@link TextureLoader.create} (fetch + `createImageBitmap` for URLs).
|
|
12
|
+
*
|
|
13
|
+
* Does not support Radiance `.hdr` for string URLs — use `TextureLoader.create` or `TextureLoader.createFromHDRBuffer`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadImageTexture(device: GPUDevice, urlOrBlob: string | Blob, options?: LoadImageTextureOptions): Promise<TextureData>;
|
|
16
|
+
/**
|
|
17
|
+
* Decodes `buffer` as an image with the given MIME type and uploads via {@link loadImageTexture}.
|
|
18
|
+
* Useful for tests or callers that already have bytes (no `fetch`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadImageTextureFromArrayBuffer(device: GPUDevice, buffer: ArrayBuffer, mimeType: string, options?: LoadImageTextureOptions): Promise<TextureData>;
|
|
21
|
+
//# sourceMappingURL=loadImageTexture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadImageTexture.d.ts","sourceRoot":"","sources":["../src/loadImageTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,oBAAoB,EAE1B,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GAAG;IAC3D;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AA4DF;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,WAAW,CAAC,CAgCtB;AAED;;;GAGG;AACH,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,WAAW,CAAC,CAGtB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { yieldToMain as d, TextureLoader as o } from "@naanouff/w3dts-core";
|
|
2
|
+
function l(r, e, t) {
|
|
3
|
+
if (r <= t && e <= t) return [r, e];
|
|
4
|
+
const a = Math.min(t / r, t / e);
|
|
5
|
+
return [Math.max(1, Math.round(r * a)), Math.max(1, Math.round(e * a))];
|
|
6
|
+
}
|
|
7
|
+
function m(r) {
|
|
8
|
+
if (!r) return {};
|
|
9
|
+
const { maxDecodeDimension: e, ...t } = r;
|
|
10
|
+
return t;
|
|
11
|
+
}
|
|
12
|
+
async function g(r) {
|
|
13
|
+
if (r instanceof Blob) return r;
|
|
14
|
+
const e = await fetch(r);
|
|
15
|
+
if (!e.ok) throw new Error(`Failed to fetch image: ${r}`);
|
|
16
|
+
return e.blob();
|
|
17
|
+
}
|
|
18
|
+
async function x(r, e, t) {
|
|
19
|
+
const a = t == null ? void 0 : t.maxDecodeDimension, n = (t == null ? void 0 : t.flipY) ?? !0, c = m(t);
|
|
20
|
+
if (a == null || a <= 0) {
|
|
21
|
+
const h = await createImageBitmap(e);
|
|
22
|
+
try {
|
|
23
|
+
return o.fromImageBitmap(r, h, { ...c, flipY: n });
|
|
24
|
+
} finally {
|
|
25
|
+
h.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const i = await createImageBitmap(e), f = i.width, s = i.height, [y, w] = l(f, s, a);
|
|
29
|
+
if (f <= a && s <= a)
|
|
30
|
+
try {
|
|
31
|
+
return o.fromImageBitmap(r, i, { ...c, flipY: n });
|
|
32
|
+
} finally {
|
|
33
|
+
i.close();
|
|
34
|
+
}
|
|
35
|
+
i.close(), await d();
|
|
36
|
+
const u = await createImageBitmap(e, { resizeWidth: y, resizeHeight: w });
|
|
37
|
+
try {
|
|
38
|
+
return o.fromImageBitmap(r, u, { ...c, flipY: n });
|
|
39
|
+
} finally {
|
|
40
|
+
u.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function D(r, e, t) {
|
|
44
|
+
const a = t == null ? void 0 : t.maxDecodeDimension;
|
|
45
|
+
if (a != null && a > 0) {
|
|
46
|
+
if (typeof e == "string" && (e.split("?")[0] ?? e).toLowerCase().endsWith(".hdr"))
|
|
47
|
+
throw new Error(
|
|
48
|
+
"loadImageTexture: .hdr is not supported here; use TextureLoader.create or createFromHDRBuffer."
|
|
49
|
+
);
|
|
50
|
+
const c = await g(e);
|
|
51
|
+
return await d(), x(r, c, t);
|
|
52
|
+
}
|
|
53
|
+
if (typeof e == "string") {
|
|
54
|
+
if ((e.split("?")[0] ?? e).toLowerCase().endsWith(".hdr"))
|
|
55
|
+
throw new Error(
|
|
56
|
+
"loadImageTexture: .hdr is not supported here; use TextureLoader.create or createFromHDRBuffer."
|
|
57
|
+
);
|
|
58
|
+
return o.create(r, e, m(t));
|
|
59
|
+
}
|
|
60
|
+
const n = URL.createObjectURL(e);
|
|
61
|
+
try {
|
|
62
|
+
return await o.create(r, n, m(t));
|
|
63
|
+
} finally {
|
|
64
|
+
URL.revokeObjectURL(n);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function I(r, e, t, a) {
|
|
68
|
+
const n = new Blob([e], { type: t });
|
|
69
|
+
return D(r, n, a);
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
D as loadImageTexture,
|
|
73
|
+
I as loadImageTextureFromArrayBuffer
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@naanouff/w3dts-core")):typeof define=="function"&&define.amd?define(["exports","@naanouff/w3dts-core"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.W3dtsLoaderImages={},i.W3dtsCore))})(this,function(i,n){"use strict";function l(r,e,t){if(r<=t&&e<=t)return[r,e];const a=Math.min(t/r,t/e);return[Math.max(1,Math.round(r*a)),Math.max(1,Math.round(e*a))]}function u(r){if(!r)return{};const{maxDecodeDimension:e,...t}=r;return t}async function x(r){if(r instanceof Blob)return r;const e=await fetch(r);if(!e.ok)throw new Error(`Failed to fetch image: ${r}`);return e.blob()}async function g(r,e,t){const a=t==null?void 0:t.maxDecodeDimension,o=(t==null?void 0:t.flipY)??!0,f=u(t);if(a==null||a<=0){const y=await createImageBitmap(e);try{return n.TextureLoader.fromImageBitmap(r,y,{...f,flipY:o})}finally{y.close()}}const c=await createImageBitmap(e),s=c.width,d=c.height,[p,L]=l(s,d,a);if(s<=a&&d<=a)try{return n.TextureLoader.fromImageBitmap(r,c,{...f,flipY:o})}finally{c.close()}c.close(),await n.yieldToMain();const h=await createImageBitmap(e,{resizeWidth:p,resizeHeight:L});try{return n.TextureLoader.fromImageBitmap(r,h,{...f,flipY:o})}finally{h.close()}}async function m(r,e,t){const a=t==null?void 0:t.maxDecodeDimension;if(a!=null&&a>0){if(typeof e=="string"&&(e.split("?")[0]??e).toLowerCase().endsWith(".hdr"))throw new Error("loadImageTexture: .hdr is not supported here; use TextureLoader.create or createFromHDRBuffer.");const f=await x(e);return await n.yieldToMain(),g(r,f,t)}if(typeof e=="string"){if((e.split("?")[0]??e).toLowerCase().endsWith(".hdr"))throw new Error("loadImageTexture: .hdr is not supported here; use TextureLoader.create or createFromHDRBuffer.");return n.TextureLoader.create(r,e,u(t))}const o=URL.createObjectURL(e);try{return await n.TextureLoader.create(r,o,u(t))}finally{URL.revokeObjectURL(o)}}async function T(r,e,t,a){const o=new Blob([e],{type:t});return m(r,o,a)}i.loadImageTexture=m,i.loadImageTextureFromArrayBuffer=T,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naanouff/w3dts-loader-images",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.19",
|
|
4
|
+
"description": "LDR image texture loading (fetch/Blob + TextureLoader) for W3DTS.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"homepage": "https://github.com/naanouff/w3dts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/naanouff/w3dts.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/w3dts-loader-images.umd.js",
|
|
13
|
+
"module": "./dist/w3dts-loader-images.es.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/w3dts-loader-images.es.js",
|
|
19
|
+
"require": "./dist/w3dts-loader-images.umd.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org",
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@naanouff/w3dts-core": "0.0.38"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@webgpu/types": "^0.1.40"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@webgpu/types": "^0.1.40",
|
|
37
|
+
"typescript": "^5.5.4",
|
|
38
|
+
"vite": "^5.4.21",
|
|
39
|
+
"vite-plugin-dts": "^4.0.3",
|
|
40
|
+
"vitest": "^3.2.7"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "vite build",
|
|
44
|
+
"test": "vitest --run --config vitest.config.ts",
|
|
45
|
+
"check": "tsc --noEmit -p ./tsconfig.json"
|
|
46
|
+
}
|
|
6
47
|
}
|