diff --git a/src/index.ts b/src/index.ts index 0fd6e1d40..cffa3716b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,6 @@ export { version } from "../package.json"; export * from "./core/index.js"; export * from "./enums/index.js"; export * from "./effects/index.js"; -export * from "./loaders/index.js"; export * from "./materials/index.js"; export * from "./passes/index.js"; export * from "./textures/index.js"; diff --git a/src/loaders/LUT3dlLoader.ts b/src/loaders/LUT3dlLoader.ts deleted file mode 100644 index 550d4c1be..000000000 --- a/src/loaders/LUT3dlLoader.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { FileLoader, Loader, LoadingManager } from "three"; -import { LookupTexture } from "../textures/lut/LookupTexture.js"; - -/** - * A 3D LUT loader that supports the .3dl file format. - * - * Based on an implementation by Garrett Johnson. - * @see https://github.com/gkjohnson/threejs-sandbox/tree/master/3d-lut - * @see http://download.autodesk.com/us/systemdocs/help/2011/lustre/index.html?url=./files/WSc4e151a45a3b785a24c3d9a411df9298473-7ffd.htm,topicNumber=d0e9492 - * @group Loaders - */ - -export class LUT3dlLoader extends Loader { - - /** - * Loads a LUT. - * - * @param url - The URL of the CUBE-file. - * @param onLoad - A callback that receives the loaded lookup texture. - * @param onProgress - A progress callback that receives the XMLHttpRequest instance. - * @param onError - An error callback that receives the URL of the file that failed to load. - * @return A promise that returns the lookup texture. - */ - - override async load(url: string, onLoad = (_: LookupTexture) => {}, onProgress = (_: ProgressEvent) => {}, - onError = (_: string) => {}): Promise { - - const externalManager = this.manager; - const internalManager = new LoadingManager(); - - const loader = new FileLoader(internalManager); - loader.setPath(this.path); - loader.setResponseType("text"); - - return new Promise((resolve, reject) => { - - internalManager.onError = (url) => { - - externalManager.itemError(url); - - if(onError !== null && onError !== undefined) { - - onError(`Failed to load ${url}`); - - } - - reject(new Error(`Failed to load ${url}`)); - - }; - - externalManager.itemStart(url); - - loader.load(url, (data) => { - - try { - - const result = this.parse(data as string); - externalManager.itemEnd(url); - onLoad(result); - resolve(result); - - } catch(e) { - - console.error(e); - internalManager.onError(url); - - } - - }, onProgress); - - }); - - } - - /** - * Parses the given data. - * - * @param input - The LUT data. - * @return The lookup texture. - */ - - parse(input: string): LookupTexture { - - const regExpGridInfo = /^[\d ]+$/m; - const regExpDataPoints = /^([\d.e+-]+) +([\d.e+-]+) +([\d.e+-]+) *$/gm; - - // The first line describes the positions of values on the LUT grid. - let result = regExpGridInfo.exec(input); - - if(result === null) { - - throw new Error("Missing grid information"); - - } - - const gridLines = result[0].trim().split(/\s+/g).map((n) => Number(n)); - const gridStep = gridLines[1] - gridLines[0]; - const size = gridLines.length; - const sizeSq = size ** 2; - - for(let i = 1, l = gridLines.length; i < l; ++i) { - - if(gridStep !== (gridLines[i] - gridLines[i - 1])) { - - throw new Error("Inconsistent grid size"); - - } - - } - - const data = new Float32Array(size ** 3 * 4); - let maxValue = 0.0; - let index = 0; - - while((result = regExpDataPoints.exec(input)) !== null) { - - const r = Number(result[1]); - const g = Number(result[2]); - const b = Number(result[3]); - - maxValue = Math.max(maxValue, r, g, b); - - const bLayer = index % size; - const gLayer = Math.floor(index / size) % size; - const rLayer = Math.floor(index / (sizeSq)) % size; - - // b grows first, then g, then r. - const d4 = (bLayer * sizeSq + gLayer * size + rLayer) * 4; - data[d4 + 0] = r; - data[d4 + 1] = g; - data[d4 + 2] = b; - data[d4 + 3] = 1.0; - - ++index; - - } - - // Determine the bit depth and scale the values to [0.0, 1.0]. - const bits = Math.ceil(Math.log2(maxValue)); - const maxBitValue = Math.pow(2, bits); - - for(let i = 0, l = data.length; i < l; i += 4) { - - data[i + 0] /= maxBitValue; - data[i + 1] /= maxBitValue; - data[i + 2] /= maxBitValue; - - } - - return new LookupTexture(data, size); - - } - -} diff --git a/src/loaders/LUTCubeLoader.ts b/src/loaders/LUTCubeLoader.ts deleted file mode 100644 index 1c6982a6e..000000000 --- a/src/loaders/LUTCubeLoader.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { FileLoader, Loader, LoadingManager, Vector3 } from "three"; -import { LookupTexture } from "../textures/lut/LookupTexture.js"; - -/** - * A 3D LUT loader that supports the .cube file format. - * - * Based on an implementation by Garrett Johnson. - * @see https://github.com/gkjohnson/threejs-sandbox/tree/master/3d-lut - * @see https://wwwimages2.adobe.com/content/dam/acom/en/products/speedgrade/cc/pdfs/cube-lut-specification-1.0.pdf - * @group Loaders - */ - -export class LUTCubeLoader extends Loader { - - /** - * Loads a LUT. - * - * @param url - The URL of the CUBE-file. - * @param onLoad - A callback that receives the loaded lookup texture. - * @param onProgress - A progress callback that receives the XMLHttpRequest instance. - * @param onError - An error callback that receives the URL of the file that failed to load. - * @return A promise that returns the lookup texture. - */ - - override async load(url: string, onLoad = (_: LookupTexture) => {}, onProgress = (_: ProgressEvent) => {}, - onError = (_: string) => {}): Promise { - - const externalManager = this.manager; - const internalManager = new LoadingManager(); - - const loader = new FileLoader(internalManager); - loader.setPath(this.path); - loader.setResponseType("text"); - - return new Promise((resolve, reject) => { - - internalManager.onError = (url) => { - - externalManager.itemError(url); - - if(onError !== null && onError !== undefined) { - - onError(`Failed to load ${url}`); - - } - - reject(new Error(`Failed to load ${url}`)); - - }; - - externalManager.itemStart(url); - - loader.load(url, (data) => { - - try { - - const result = this.parse(data as string); - externalManager.itemEnd(url); - onLoad(result); - resolve(result); - - } catch(e) { - - console.error(e); - internalManager.onError(url); - - } - - }, onProgress); - - }); - - } - - /** - * Parses the given data. - * - * @param input - The LUT data. - * @return The lookup texture. - */ - - parse(input: string): LookupTexture { - - const regExpTitle = /TITLE +"([^"]*)"/; - const regExpSize = /LUT_3D_SIZE +(\d+)/; - const regExpDomainMin = /DOMAIN_MIN +([\d.]+) +([\d.]+) +([\d.]+)/; - const regExpDomainMax = /DOMAIN_MAX +([\d.]+) +([\d.]+) +([\d.]+)/; - const regExpDataPoints = /^([\d.e+-]+) +([\d.e+-]+) +([\d.e+-]+) *$/gm; - - let result = regExpTitle.exec(input); - const title = (result !== null) ? result[1] : null; - - result = regExpSize.exec(input); - - if(result === null) { - - throw new Error("Missing LUT_3D_SIZE information"); - - } - - const size = Number(result[1]); - const data = new Float32Array(size ** 3 * 4); - - const domainMin = new Vector3(0, 0, 0); - const domainMax = new Vector3(1, 1, 1); - - result = regExpDomainMin.exec(input); - - if(result !== null) { - - domainMin.set(Number(result[1]), Number(result[2]), Number(result[3])); - - } - - result = regExpDomainMax.exec(input); - - if(result !== null) { - - domainMax.set(Number(result[1]), Number(result[2]), Number(result[3])); - - } - - if(domainMin.x > domainMax.x || domainMin.y > domainMax.y || domainMin.z > domainMax.z) { - - domainMin.set(0, 0, 0); - domainMax.set(1, 1, 1); - - throw new Error("Invalid input domain"); - - } - - let i = 0; - - while((result = regExpDataPoints.exec(input)) !== null) { - - data[i++] = Number(result[1]); - data[i++] = Number(result[2]); - data[i++] = Number(result[3]); - data[i++] = 1.0; - - } - - const lut = new LookupTexture(data, size); - lut.domainMin.copy(domainMin); - lut.domainMax.copy(domainMax); - - if(title !== null) { - - lut.name = title; - - } - - return lut; - - } - -} diff --git a/src/loaders/index.ts b/src/loaders/index.ts deleted file mode 100644 index cc5a381ab..000000000 --- a/src/loaders/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./LUT3dlLoader.js"; -export * from "./LUTCubeLoader.js";