three-stdlib 2.13.1 → 2.14.2
Sign up to get free protection for your applications and to get access to all the features.
- package/{Nodes-607e9ed8.js → Nodes-4f766d71.js} +0 -0
- package/{Nodes-627a8bdf.js → Nodes-9aa16d74.js} +0 -0
- package/geometries/TextGeometry.cjs.js +1 -1
- package/geometries/TextGeometry.d.ts +2 -0
- package/geometries/TextGeometry.js +6 -1
- package/index.cjs.js +1 -1
- package/lines/Line2.cjs.js +1 -1
- package/lines/Line2.d.ts +7 -5
- package/lines/Line2.js +2 -5
- package/lines/LineGeometry.cjs.js +1 -1
- package/lines/LineGeometry.d.ts +6 -8
- package/lines/LineGeometry.js +28 -39
- package/lines/LineMaterial.cjs.js +1 -1
- package/lines/LineMaterial.d.ts +23 -19
- package/lines/LineMaterial.js +263 -107
- package/lines/LineSegments2.cjs.js +1 -1
- package/lines/LineSegments2.d.ts +12 -20
- package/lines/LineSegments2.js +272 -125
- package/lines/LineSegmentsGeometry.cjs.js +1 -1
- package/lines/LineSegmentsGeometry.d.ts +18 -16
- package/lines/LineSegmentsGeometry.js +30 -40
- package/lines/Wireframe.cjs.js +1 -1
- package/lines/Wireframe.js +39 -39
- package/lines/WireframeGeometry2.cjs.js +1 -1
- package/lines/WireframeGeometry2.js +8 -9
- package/loaders/FontLoader.cjs.js +1 -1
- package/loaders/FontLoader.d.ts +5 -1
- package/loaders/FontLoader.js +10 -5
- package/loaders/KTX2Loader.cjs.js +1 -1
- package/loaders/KTX2Loader.js +493 -102
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/RGBMLoader.js +248 -177
- package/nodes/Nodes.cjs.js +1 -1
- package/nodes/core/NodeBuilder.js +5 -1
- package/nodes/loaders/NodeLoader.cjs.js +1 -1
- package/nodes/loaders/NodeObjectLoader.cjs.js +1 -1
- package/package.json +2 -2
- package/utils/WorkerPool.cjs.js +1 -0
- package/utils/WorkerPool.js +82 -0
package/lines/Wireframe.js
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
import {
|
1
|
+
import { Vector3, Mesh, InstancedInterleavedBuffer, InterleavedBufferAttribute } from 'three';
|
2
2
|
import { LineSegmentsGeometry } from './LineSegmentsGeometry.js';
|
3
3
|
import { LineMaterial } from './LineMaterial.js';
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
const _start = new Vector3();
|
6
|
+
|
7
|
+
const _end = new Vector3();
|
8
|
+
|
9
|
+
class Wireframe extends Mesh {
|
10
|
+
constructor(geometry = new LineSegmentsGeometry(), material = new LineMaterial({
|
10
11
|
color: Math.random() * 0xffffff
|
11
|
-
})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
});
|
12
|
+
})) {
|
13
|
+
super(geometry, material);
|
14
|
+
this.isWireframe = true;
|
15
|
+
this.type = 'Wireframe';
|
16
|
+
} // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
|
17
|
+
|
18
|
+
|
19
|
+
computeLineDistances() {
|
20
|
+
const geometry = this.geometry;
|
21
|
+
const instanceStart = geometry.attributes.instanceStart;
|
22
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
23
|
+
const lineDistances = new Float32Array(2 * instanceStart.count);
|
24
|
+
|
25
|
+
for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {
|
26
|
+
_start.fromBufferAttribute(instanceStart, i);
|
27
|
+
|
28
|
+
_end.fromBufferAttribute(instanceEnd, i);
|
29
|
+
|
30
|
+
lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
|
31
|
+
lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end);
|
32
|
+
}
|
33
|
+
|
34
|
+
const instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
|
35
|
+
|
36
|
+
geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
|
37
|
+
|
38
|
+
geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
|
39
|
+
|
40
|
+
return this;
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
44
|
|
45
45
|
export { Wireframe };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("./LineSegmentsGeometry.cjs.js");
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("./LineSegmentsGeometry.cjs.js");class t extends r.LineSegmentsGeometry{constructor(r){super(),this.isWireframeGeometry2=!0,this.type="WireframeGeometry2",this.fromWireframeGeometry(new e.WireframeGeometry(r))}}exports.WireframeGeometry2=t;
|
@@ -1,15 +1,14 @@
|
|
1
1
|
import { WireframeGeometry } from 'three';
|
2
2
|
import { LineSegmentsGeometry } from './LineSegmentsGeometry.js';
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class WireframeGeometry2 extends LineSegmentsGeometry {
|
5
|
+
constructor(geometry) {
|
6
|
+
super();
|
7
|
+
this.isWireframeGeometry2 = true;
|
8
|
+
this.type = 'WireframeGeometry2';
|
9
|
+
this.fromWireframeGeometry(new WireframeGeometry(geometry)); // set colors, maybe
|
10
|
+
}
|
9
11
|
|
10
|
-
|
11
|
-
constructor: WireframeGeometry2,
|
12
|
-
isWireframeGeometry2: true
|
13
|
-
});
|
12
|
+
}
|
14
13
|
|
15
14
|
export { WireframeGeometry2 };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e);class
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("three");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e);class n extends t.Loader{constructor(e){super(e)}load(e,r,s,n){const a=new t.FileLoader(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,(e=>{if("string"!=typeof e)throw new Error("unsupported data type");const t=JSON.parse(e),s=this.parse(t);r&&r(s)}),s,n)}parse(e){return new a(e)}}class a{constructor(e){s.default(this,"data",void 0),this.data=e}generateShapes(e,t=100,r){const s=[],n={letterSpacing:0,lineHeight:1,...r},a=function(e,t,r,s){const n=Array.from(e),a=t/r.resolution,i=(r.boundingBox.yMax-r.boundingBox.yMin+r.underlineThickness)*a,p=[];let l=0,u=0;for(let e=0;e<n.length;e++){const t=n[e];if("\n"===t)l=0,u-=i*s.lineHeight;else{const e=o(t,a,l,u,r);e&&(l+=e.offsetX+s.letterSpacing,p.push(e.path))}}return p}(e,t,this.data,n);for(let e=0,t=a.length;e<t;e++)Array.prototype.push.apply(s,a[e].toShapes(!1));return s}}function o(e,r,s,n,a){const o=a.glyphs[e]||a.glyphs["?"];if(!o)return void console.error('THREE.Font: character "'+e+'" does not exists in font family '+a.familyName+".");const i=new t.ShapePath;let p,l,u,c,h,d,f,y;if(o.o){const e=o._cachedOutline||(o._cachedOutline=o.o.split(" "));for(let t=0,a=e.length;t<a;){switch(e[t++]){case"m":p=parseInt(e[t++])*r+s,l=parseInt(e[t++])*r+n,i.moveTo(p,l);break;case"l":p=parseInt(e[t++])*r+s,l=parseInt(e[t++])*r+n,i.lineTo(p,l);break;case"q":u=parseInt(e[t++])*r+s,c=parseInt(e[t++])*r+n,h=parseInt(e[t++])*r+s,d=parseInt(e[t++])*r+n,i.quadraticCurveTo(h,d,u,c);break;case"b":u=parseInt(e[t++])*r+s,c=parseInt(e[t++])*r+n,h=parseInt(e[t++])*r+s,d=parseInt(e[t++])*r+n,f=parseInt(e[t++])*r+s,y=parseInt(e[t++])*r+n,i.bezierCurveTo(h,d,f,y,u,c)}}}return{offsetX:o.ha*r,path:i}}s.default(a,"isFont",void 0),s.default(a,"type",void 0),exports.Font=a,exports.FontLoader=n;
|
package/loaders/FontLoader.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { Loader } from 'three';
|
2
2
|
import type { LoadingManager, Shape } from 'three';
|
3
|
+
declare type Options = {
|
4
|
+
lineHeight: number;
|
5
|
+
letterSpacing: number;
|
6
|
+
};
|
3
7
|
export declare class FontLoader extends Loader {
|
4
8
|
constructor(manager?: LoadingManager);
|
5
9
|
load(url: string, onLoad?: (responseFont: Font) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): void;
|
@@ -27,6 +31,6 @@ export declare class Font {
|
|
27
31
|
static isFont: true;
|
28
32
|
static type: 'Font';
|
29
33
|
constructor(data: FontData);
|
30
|
-
generateShapes(text: string, size?: number): Shape[];
|
34
|
+
generateShapes(text: string, size?: number, _options?: Partial<Options>): Shape[];
|
31
35
|
}
|
32
36
|
export {};
|
package/loaders/FontLoader.js
CHANGED
@@ -31,9 +31,14 @@ class Font {
|
|
31
31
|
this.data = data;
|
32
32
|
}
|
33
33
|
|
34
|
-
generateShapes(text, size = 100) {
|
34
|
+
generateShapes(text, size = 100, _options) {
|
35
35
|
const shapes = [];
|
36
|
-
const
|
36
|
+
const options = {
|
37
|
+
letterSpacing: 0,
|
38
|
+
lineHeight: 1,
|
39
|
+
..._options
|
40
|
+
};
|
41
|
+
const paths = createPaths(text, size, this.data, options);
|
37
42
|
|
38
43
|
for (let p = 0, pl = paths.length; p < pl; p++) {
|
39
44
|
Array.prototype.push.apply(shapes, paths[p].toShapes(false));
|
@@ -48,7 +53,7 @@ _defineProperty(Font, "isFont", void 0);
|
|
48
53
|
|
49
54
|
_defineProperty(Font, "type", void 0);
|
50
55
|
|
51
|
-
function createPaths(text, size, data) {
|
56
|
+
function createPaths(text, size, data, options) {
|
52
57
|
const chars = Array.from(text);
|
53
58
|
const scale = size / data.resolution;
|
54
59
|
const line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
|
@@ -61,12 +66,12 @@ function createPaths(text, size, data) {
|
|
61
66
|
|
62
67
|
if (char === '\n') {
|
63
68
|
offsetX = 0;
|
64
|
-
offsetY -= line_height;
|
69
|
+
offsetY -= line_height * options.lineHeight;
|
65
70
|
} else {
|
66
71
|
const ret = createPath(char, scale, offsetX, offsetY, data);
|
67
72
|
|
68
73
|
if (ret) {
|
69
|
-
offsetX += ret.offsetX;
|
74
|
+
offsetX += ret.offsetX + options.letterSpacing;
|
70
75
|
paths.push(ret.path);
|
71
76
|
}
|
72
77
|
}
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("./BasisTextureLoader.cjs.js"),t=require("zstddec"),s=require("ktx-parse");class a extends e.CompressedTextureLoader{constructor(e){super(e),this.basisLoader=new r.BasisTextureLoader(e),this.zstd=new t.ZSTDDecoder,this.zstd.init(),"undefined"!=typeof MSC_TRANSCODER&&console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder". "msc_basis_transcoder" is no longer supported in three.js r125+.')}setTranscoderPath(e){return this.basisLoader.setTranscoderPath(e),this}setWorkerLimit(e){return this.basisLoader.setWorkerLimit(e),this}detectSupport(e){return this.basisLoader.detectSupport(e),this}dispose(){return this.basisLoader.dispose(),this}load(r,t,s,a){var o=this,n=new e.CompressedTexture;return new Promise((function(t,a){new e.FileLoader(o.manager).setPath(o.path).setResponseType("arraybuffer").load(r,t,s,a)})).then((function(e){o.parse(e,(function(e){n.copy(e),n.needsUpdate=!0,t&&t(n)}),a)})).catch(a),n}parse(t,a,n){var i=this,l=s.read(new Uint8Array(t));if(l.pixelDepth>0)throw new Error("THREE.KTX2Loader: Only 2D textures are currently supported.");if(l.layerCount>1)throw new Error("THREE.KTX2Loader: Array textures are not currently supported.");if(l.faceCount>1)throw new Error("THREE.KTX2Loader: Cube textures are not currently supported.");var h=o.getBasicDFD(l);return o.createLevels(l,this.zstd).then((function(e){var t=h.colorModel===s.KTX2Model.UASTC?r.BasisTextureLoader.BasisFormat.UASTC_4x4:r.BasisTextureLoader.BasisFormat.ETC1S,a={levels:e,width:l.pixelWidth,height:l.pixelHeight,basisFormat:t,hasAlpha:o.getAlpha(l)};return t===r.BasisTextureLoader.BasisFormat.ETC1S&&(a.globalData=l.globalData),i.basisLoader.parseInternalAsync(a)})).then((function(r){r.encoding=h.transferFunction===s.KTX2Transfer.SRGB?e.sRGBEncoding:e.LinearEncoding,r.premultiplyAlpha=o.getPremultiplyAlpha(l),a(r)})).catch(n),this}}var o={createLevels:async function(e,r){e.supercompressionScheme===s.KTX2SupercompressionScheme.ZSTD&&await r.init();for(var t=[],a=e.pixelWidth,o=e.pixelHeight,n=0;n<e.levels.length;n++){var i=Math.max(1,Math.floor(a/Math.pow(2,n))),l=Math.max(1,Math.floor(o/Math.pow(2,n))),h=e.levels[n].levelData;e.supercompressionScheme===s.KTX2SupercompressionScheme.ZSTD&&(h=r.decode(h,e.levels[n].uncompressedByteLength)),t.push({index:n,width:i,height:l,data:h})}return t},getBasicDFD:function(e){return e.dataFormatDescriptor[0]},getAlpha:function(e){var r=this.getBasicDFD(e);return r.colorModel===s.KTX2Model.UASTC?(15&r.samples[0].channelID)===s.KTX2ChannelUASTC.RGBA:2===r.samples.length&&(15&r.samples[1].channelID)===s.KTX2ChannelETC1S.AAA},getPremultiplyAlpha:function(e){return!!(this.getBasicDFD(e).flags&s.KTX2Flags.ALPHA_PREMULTIPLIED)}};exports.KTX2Loader=a;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("../utils/WorkerPool.cjs.js"),t=require("ktx-parse"),o=require("zstddec");const s=new WeakMap;let a,n=0;class i extends e.Loader{constructor(e){super(e),this.transcoderPath="",this.transcoderBinary=null,this.transcoderPending=null,this.workerPool=new r.WorkerPool,this.workerSourceURL="",this.workerConfig=null,"undefined"!=typeof MSC_TRANSCODER&&console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder". "msc_basis_transcoder" is no longer supported in three.js r125+.')}setTranscoderPath(e){return this.transcoderPath=e,this}setWorkerLimit(e){return this.workerPool.setWorkerLimit(e),this}detectSupport(e){return this.workerConfig={astcSupported:e.extensions.has("WEBGL_compressed_texture_astc"),etc1Supported:e.extensions.has("WEBGL_compressed_texture_etc1"),etc2Supported:e.extensions.has("WEBGL_compressed_texture_etc"),dxtSupported:e.extensions.has("WEBGL_compressed_texture_s3tc"),bptcSupported:e.extensions.has("EXT_texture_compression_bptc"),pvrtcSupported:e.extensions.has("WEBGL_compressed_texture_pvrtc")||e.extensions.has("WEBKIT_WEBGL_compressed_texture_pvrtc")},e.capabilities.isWebGL2&&(this.workerConfig.etc1Supported=!1),this}init(){if(!this.transcoderPending){const r=new e.FileLoader(this.manager);r.setPath(this.transcoderPath),r.setWithCredentials(this.withCredentials);const t=r.loadAsync("basis_transcoder.js"),o=new e.FileLoader(this.manager);o.setPath(this.transcoderPath),o.setResponseType("arraybuffer"),o.setWithCredentials(this.withCredentials);const s=o.loadAsync("basis_transcoder.wasm");this.transcoderPending=Promise.all([t,s]).then((([e,r])=>{const t=i.BasisWorker.toString(),o=["/* constants */","let _EngineFormat = "+JSON.stringify(i.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(i.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(i.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",t.substring(t.indexOf("{")+1,t.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([o])),this.transcoderBinary=r,this.workerPool.setWorkerCreator((()=>{const e=new Worker(this.workerSourceURL),r=this.transcoderBinary.slice(0);return e.postMessage({type:"init",config:this.workerConfig,transcoderBinary:r},[r]),e}))})),n>0&&console.warn("THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues. Use a single KTX2Loader instance, or call .dispose() on old instances."),n++}return this.transcoderPending}load(r,t,o,a){if(null===this.workerConfig)throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");const n=new e.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setWithCredentials(this.withCredentials),n.load(r,(e=>{if(s.has(e)){return s.get(e).promise.then(t).catch(a)}this._createTexture(e).then((e=>t?t(e):null)).catch(a)}),o,a)}_createTextureFrom(r){const{mipmaps:o,width:s,height:a,format:n,type:i,error:_,dfdTransferFn:T,dfdFlags:d}=r;if("error"===i)return Promise.reject(_);const R=new e.CompressedTexture(o,s,a,n,e.UnsignedByteType);return R.minFilter=1===o.length?e.LinearFilter:e.LinearMipmapLinearFilter,R.magFilter=e.LinearFilter,R.generateMipmaps=!1,R.needsUpdate=!0,R.encoding=T===t.KHR_DF_TRANSFER_SRGB?e.sRGBEncoding:e.LinearEncoding,R.premultiplyAlpha=!!(d&t.KHR_DF_FLAG_ALPHA_PREMULTIPLIED),R}_createTexture(r,n={}){const i=t.read(new Uint8Array(r));if(i.vkFormat!==t.VK_FORMAT_UNDEFINED)return async function(r){const{vkFormat:s,pixelWidth:n,pixelHeight:i,pixelDepth:R}=r;if(void 0===_[s])throw new Error("THREE.KTX2Loader: Unsupported vkFormat.");const c=r.levels[0];let F,p;if(r.supercompressionScheme===t.KHR_SUPERCOMPRESSION_NONE)F=c.levelData;else{if(r.supercompressionScheme!==t.KHR_SUPERCOMPRESSION_ZSTD)throw new Error("THREE.KTX2Loader: Unsupported supercompressionScheme.");a||(a=new Promise((async e=>{const r=new o.ZSTDDecoder;await r.init(),e(r)}))),F=(await a).decode(c.levelData,c.uncompressedByteLength)}p=T[s]===e.FloatType?new Float32Array(F.buffer,F.byteOffset,F.byteLength/Float32Array.BYTES_PER_ELEMENT):T[s]===e.HalfFloatType?new Uint16Array(F.buffer,F.byteOffset,F.byteLength/Uint16Array.BYTES_PER_ELEMENT):F;const m=0===R?new e.DataTexture(p,n,i):new e.Data3DTexture(p,n,i,R);return m.type=T[s],m.format=_[s],m.encoding=d[s]||e.LinearEncoding,m.needsUpdate=!0,Promise.resolve(m)}(i);const R=n,c=this.init().then((()=>this.workerPool.postMessage({type:"transcode",buffer:r,taskConfig:R},[r]))).then((e=>this._createTextureFrom(e.data)));return s.set(r,{promise:c}),c}dispose(){return this.workerPool.dispose(),this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),n--,this}}i.BasisFormat={ETC1S:0,UASTC_4x4:1},i.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},i.EngineFormat={RGBAFormat:e.RGBAFormat,RGBA_ASTC_4x4_Format:e.RGBA_ASTC_4x4_Format,RGBA_BPTC_Format:e.RGBA_BPTC_Format,RGBA_ETC2_EAC_Format:e.RGBA_ETC2_EAC_Format,RGBA_PVRTC_4BPPV1_Format:e.RGBA_PVRTC_4BPPV1_Format,RGBA_S3TC_DXT5_Format:e.RGBA_S3TC_DXT5_Format,RGB_ETC1_Format:e.RGB_ETC1_Format,RGB_ETC2_Format:e.RGB_ETC2_Format,RGB_PVRTC_4BPPV1_Format:e.RGB_PVRTC_4BPPV1_Format,RGB_S3TC_DXT1_Format:e.RGB_S3TC_DXT1_Format},i.BasisWorker=function(){let e,r,t;const o=_EngineFormat,s=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(n){const d=n.data;switch(d.type){case"init":e=d.config,R=d.transcoderBinary,r=new Promise((e=>{t={wasmBinary:R,onRuntimeInitialized:e},BASIS(t)})).then((()=>{t.initializeBasis(),void 0===t.KTX2File&&console.warn("THREE.KTX2Loader: Please update Basis Universal transcoder.")}));break;case"transcode":r.then((()=>{try{const{width:r,height:n,hasAlpha:R,mipmaps:c,format:F,dfdTransferFn:p,dfdFlags:m}=function(r){const n=new t.KTX2File(new Uint8Array(r));function d(){n.close(),n.delete()}if(!n.isValid())throw d(),new Error("THREE.KTX2Loader:\tInvalid or unsupported .ktx2 file");const R=n.isUASTC()?a.UASTC_4x4:a.ETC1S,c=n.getWidth(),F=n.getHeight(),p=n.getLevels(),m=n.getHasAlpha(),l=n.getDFDTransferFunc(),A=n.getDFDFlags(),{transcoderFormat:B,engineFormat:h}=function(r,t,n,d){let R,c;const F=r===a.ETC1S?i:_;for(let o=0;o<F.length;o++){const s=F[o];if(e[s.if]&&(s.basisFormat.includes(r)&&!(d&&s.transcoderFormat.length<2)&&(!s.needsPowerOfTwo||T(t)&&T(n))))return R=s.transcoderFormat[d?1:0],c=s.engineFormat[d?1:0],{transcoderFormat:R,engineFormat:c}}return console.warn("THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32."),R=s.RGBA32,c=o.RGBAFormat,{transcoderFormat:R,engineFormat:c}}(R,c,F,m);if(!c||!F||!p)throw d(),new Error("THREE.KTX2Loader:\tInvalid texture");if(!n.startTranscoding())throw d(),new Error("THREE.KTX2Loader: .startTranscoding failed");const S=[];for(let e=0;e<p;e++){const r=n.getImageLevelInfo(e,0,0),t=r.origWidth,o=r.origHeight,s=new Uint8Array(n.getImageTranscodedSizeInBytes(e,0,0,B));if(!n.transcodeImage(s,e,0,0,B,0,-1,-1))throw d(),new Error("THREE.KTX2Loader: .transcodeImage failed.");S.push({data:s,width:t,height:o})}return d(),{width:c,height:F,hasAlpha:m,mipmaps:S,format:h,dfdTransferFn:l,dfdFlags:A}}(d.buffer),l=[];for(let e=0;e<c.length;++e)l.push(c[e].data.buffer);self.postMessage({type:"transcode",id:d.id,width:r,height:n,hasAlpha:R,mipmaps:c,format:F,dfdTransferFn:p,dfdFlags:m},l)}catch(e){console.error(e),self.postMessage({type:"error",id:d.id,error:e.message})}}))}var R}));const n=[{if:"astcSupported",basisFormat:[a.UASTC_4x4],transcoderFormat:[s.ASTC_4x4,s.ASTC_4x4],engineFormat:[o.RGBA_ASTC_4x4_Format,o.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[s.BC7_M5,s.BC7_M5],engineFormat:[o.RGBA_BPTC_Format,o.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[s.BC1,s.BC3],engineFormat:[o.RGB_S3TC_DXT1_Format,o.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[s.ETC1,s.ETC2],engineFormat:[o.RGB_ETC2_Format,o.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[s.ETC1],engineFormat:[o.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[a.ETC1S,a.UASTC_4x4],transcoderFormat:[s.PVRTC1_4_RGB,s.PVRTC1_4_RGBA],engineFormat:[o.RGB_PVRTC_4BPPV1_Format,o.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],i=n.sort((function(e,r){return e.priorityETC1S-r.priorityETC1S})),_=n.sort((function(e,r){return e.priorityUASTC-r.priorityUASTC}));function T(e){return e<=2||0==(e&e-1)&&0!==e}};const _={[t.VK_FORMAT_R32G32B32A32_SFLOAT]:e.RGBAFormat,[t.VK_FORMAT_R16G16B16A16_SFLOAT]:e.RGBAFormat,[t.VK_FORMAT_R8G8B8A8_UNORM]:e.RGBAFormat,[t.VK_FORMAT_R8G8B8A8_SRGB]:e.RGBAFormat,[t.VK_FORMAT_R32G32_SFLOAT]:e.RGFormat,[t.VK_FORMAT_R16G16_SFLOAT]:e.RGFormat,[t.VK_FORMAT_R8G8_UNORM]:e.RGFormat,[t.VK_FORMAT_R8G8_SRGB]:e.RGFormat,[t.VK_FORMAT_R32_SFLOAT]:e.RedFormat,[t.VK_FORMAT_R16_SFLOAT]:e.RedFormat,[t.VK_FORMAT_R8_SRGB]:e.RedFormat,[t.VK_FORMAT_R8_UNORM]:e.RedFormat},T={[t.VK_FORMAT_R32G32B32A32_SFLOAT]:e.FloatType,[t.VK_FORMAT_R16G16B16A16_SFLOAT]:e.HalfFloatType,[t.VK_FORMAT_R8G8B8A8_UNORM]:e.UnsignedByteType,[t.VK_FORMAT_R8G8B8A8_SRGB]:e.UnsignedByteType,[t.VK_FORMAT_R32G32_SFLOAT]:e.FloatType,[t.VK_FORMAT_R16G16_SFLOAT]:e.HalfFloatType,[t.VK_FORMAT_R8G8_UNORM]:e.UnsignedByteType,[t.VK_FORMAT_R8G8_SRGB]:e.UnsignedByteType,[t.VK_FORMAT_R32_SFLOAT]:e.FloatType,[t.VK_FORMAT_R16_SFLOAT]:e.HalfFloatType,[t.VK_FORMAT_R8_SRGB]:e.UnsignedByteType,[t.VK_FORMAT_R8_UNORM]:e.UnsignedByteType},d={[t.VK_FORMAT_R8G8B8A8_SRGB]:e.sRGBEncoding,[t.VK_FORMAT_R8G8_SRGB]:e.sRGBEncoding,[t.VK_FORMAT_R8_SRGB]:e.sRGBEncoding};exports.KTX2Loader=i;
|