@takram/three-geospatial 0.2.2 → 0.3.0
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/CHANGELOG.md +15 -0
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.js +1293 -1282
- package/build/index.js.map +1 -1
- package/build/r3f.cjs +1 -1
- package/build/r3f.cjs.map +1 -1
- package/build/r3f.js +28 -55
- package/build/r3f.js.map +1 -1
- package/build/shaders.cjs.map +1 -1
- package/build/shaders.js.map +1 -1
- package/build/shared.cjs.map +1 -1
- package/build/shared.js.map +1 -1
- package/package.json +1 -2
- package/src/DataTextureLoader.ts +134 -0
- package/src/EXR3DTextureLoader.ts +66 -0
- package/src/{EXR3DLoader.ts → EXRTextureLoader.ts} +25 -12
- package/src/STBNLoader.ts +28 -13
- package/src/TilingScheme.ts +1 -1
- package/src/TypedArrayLoader.ts +11 -21
- package/src/capabilities.ts +5 -0
- package/src/constants.ts +1 -0
- package/src/decorators.ts +0 -1
- package/src/defineShorthand.ts +1 -1
- package/src/index.ts +5 -3
- package/src/r3f/EastNorthUpFrame.tsx +2 -2
- package/src/r3f/EllipsoidMesh.tsx +3 -5
- package/src/r3f/index.ts +1 -1
- package/src/r3f/types.ts +1 -1
- package/src/typedArrayParsers.ts +1 -1
- package/src/types.ts +3 -1
- package/types/DataTextureLoader.d.ts +27 -0
- package/types/EXR3DTextureLoader.d.ts +11 -0
- package/types/EXRTextureLoader.d.ts +10 -0
- package/types/STBNLoader.d.ts +5 -1
- package/types/TypedArrayLoader.d.ts +4 -6
- package/types/capabilities.d.ts +2 -0
- package/types/index.d.ts +5 -3
- package/types/r3f/index.d.ts +1 -1
- package/types/types.d.ts +2 -1
- package/src/DataLoader.ts +0 -164
- package/src/Texture3DLoader.ts +0 -81
- package/types/DataLoader.d.ts +0 -29
- package/types/EXR3DLoader.d.ts +0 -6
- package/types/Texture3DLoader.d.ts +0 -4
@@ -1,20 +1,28 @@
|
|
1
|
-
import {
|
1
|
+
import { DataTexture, Loader, type LoadingManager } from 'three'
|
2
2
|
import { EXRLoader } from 'three-stdlib'
|
3
3
|
|
4
|
-
export
|
5
|
-
|
4
|
+
export interface EXRTextureLoaderOptions {
|
5
|
+
width?: number
|
6
|
+
height?: number
|
7
|
+
}
|
8
|
+
|
9
|
+
export class EXRTextureLoader extends Loader<DataTexture> {
|
10
|
+
options: EXRTextureLoaderOptions
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
constructor(options: EXRTextureLoaderOptions = {}, manager?: LoadingManager) {
|
13
|
+
super(manager)
|
14
|
+
this.options = options
|
10
15
|
}
|
11
16
|
|
12
17
|
override load(
|
13
18
|
url: string,
|
14
|
-
onLoad
|
19
|
+
onLoad?: (data: DataTexture) => void,
|
15
20
|
onProgress?: (event: ProgressEvent) => void,
|
16
21
|
onError?: (error: unknown) => void
|
17
|
-
):
|
22
|
+
): DataTexture {
|
23
|
+
const { width, height } = this.options
|
24
|
+
const texture = new DataTexture(null, width, height)
|
25
|
+
|
18
26
|
const loader = new EXRLoader(this.manager)
|
19
27
|
loader.setRequestHeader(this.requestHeader)
|
20
28
|
loader.setPath(this.path)
|
@@ -22,16 +30,19 @@ export class EXR3DLoader extends Loader<Data3DTexture> {
|
|
22
30
|
loader.load(
|
23
31
|
url,
|
24
32
|
exr => {
|
25
|
-
const {
|
26
|
-
|
27
|
-
|
33
|
+
const { image } = exr
|
34
|
+
texture.image = {
|
35
|
+
data: image.data,
|
36
|
+
width: width ?? image.width,
|
37
|
+
height: height ?? image.height
|
38
|
+
}
|
28
39
|
texture.type = exr.type
|
29
40
|
texture.format = exr.format
|
30
41
|
texture.colorSpace = exr.colorSpace
|
31
42
|
texture.needsUpdate = true
|
32
43
|
|
33
44
|
try {
|
34
|
-
onLoad(texture)
|
45
|
+
onLoad?.(texture)
|
35
46
|
} catch (error) {
|
36
47
|
if (onError != null) {
|
37
48
|
onError(error)
|
@@ -44,5 +55,7 @@ export class EXR3DLoader extends Loader<Data3DTexture> {
|
|
44
55
|
onProgress,
|
45
56
|
onError
|
46
57
|
)
|
58
|
+
|
59
|
+
return texture
|
47
60
|
}
|
48
61
|
}
|
package/src/STBNLoader.ts
CHANGED
@@ -1,21 +1,36 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
Data3DTexture,
|
3
|
+
NearestFilter,
|
4
|
+
RedFormat,
|
5
|
+
RepeatWrapping,
|
6
|
+
type LoadingManager
|
7
|
+
} from 'three'
|
2
8
|
|
3
9
|
import {
|
4
10
|
STBN_TEXTURE_DEPTH,
|
5
11
|
STBN_TEXTURE_HEIGHT,
|
6
12
|
STBN_TEXTURE_WIDTH
|
7
13
|
} from './constants'
|
8
|
-
import {
|
14
|
+
import { DataTextureLoader } from './DataTextureLoader'
|
9
15
|
import { parseUint8Array } from './typedArrayParsers'
|
10
16
|
|
11
|
-
export
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
export class STBNLoader extends DataTextureLoader<Data3DTexture> {
|
18
|
+
constructor(manager?: LoadingManager) {
|
19
|
+
super(
|
20
|
+
Data3DTexture,
|
21
|
+
parseUint8Array,
|
22
|
+
{
|
23
|
+
format: RedFormat,
|
24
|
+
minFilter: NearestFilter,
|
25
|
+
magFilter: NearestFilter,
|
26
|
+
wrapS: RepeatWrapping,
|
27
|
+
wrapT: RepeatWrapping,
|
28
|
+
wrapR: RepeatWrapping,
|
29
|
+
width: STBN_TEXTURE_WIDTH,
|
30
|
+
height: STBN_TEXTURE_HEIGHT,
|
31
|
+
depth: STBN_TEXTURE_DEPTH
|
32
|
+
},
|
33
|
+
manager
|
34
|
+
)
|
35
|
+
}
|
36
|
+
}
|
package/src/TilingScheme.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Vector2 } from 'three'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import type { GeodeticLike } from './Geodetic'
|
4
4
|
import { Rectangle, type RectangleLike } from './Rectangle'
|
5
5
|
import { TileCoordinate, type TileCoordinateLike } from './TileCoordinate'
|
6
6
|
|
package/src/TypedArrayLoader.ts
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
import { Loader } from 'three'
|
2
|
-
import { type Class } from 'type-fest'
|
1
|
+
import { Loader, type LoadingManager } from 'three'
|
3
2
|
|
4
3
|
import { ArrayBufferLoader } from './ArrayBufferLoader'
|
5
|
-
import {
|
6
|
-
import {
|
4
|
+
import type { TypedArray } from './typedArray'
|
5
|
+
import type { TypedArrayParser } from './typedArrayParsers'
|
7
6
|
|
8
|
-
export
|
9
|
-
|
7
|
+
export class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
|
8
|
+
parser: TypedArrayParser<T>
|
9
|
+
|
10
|
+
constructor(parser: TypedArrayParser<T>, manager?: LoadingManager) {
|
11
|
+
super(manager)
|
12
|
+
this.parser = parser
|
13
|
+
}
|
10
14
|
|
11
15
|
override load(
|
12
16
|
url: string,
|
@@ -22,7 +26,7 @@ export abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
|
|
22
26
|
url,
|
23
27
|
arrayBuffer => {
|
24
28
|
try {
|
25
|
-
onLoad(this.
|
29
|
+
onLoad(this.parser(arrayBuffer))
|
26
30
|
} catch (error) {
|
27
31
|
if (onError != null) {
|
28
32
|
onError(error)
|
@@ -37,17 +41,3 @@ export abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
|
|
37
41
|
)
|
38
42
|
}
|
39
43
|
}
|
40
|
-
|
41
|
-
export function createTypedArrayLoaderClass<T extends TypedArray>(
|
42
|
-
parser: TypedArrayParser<T>
|
43
|
-
): Class<TypedArrayLoader<T>> {
|
44
|
-
return class extends TypedArrayLoader<T> {
|
45
|
-
readonly parseTypedArray = parser
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
export function createTypedArrayLoader<T extends TypedArray>(
|
50
|
-
parser: TypedArrayParser<T>
|
51
|
-
): TypedArrayLoader<T> {
|
52
|
-
return new (createTypedArrayLoaderClass(parser))()
|
53
|
-
}
|
package/src/constants.ts
CHANGED
@@ -2,5 +2,6 @@ export const STBN_TEXTURE_WIDTH = 128
|
|
2
2
|
export const STBN_TEXTURE_HEIGHT = 128
|
3
3
|
export const STBN_TEXTURE_DEPTH = 64
|
4
4
|
|
5
|
+
// Reference to the latest assets.
|
5
6
|
const ref = '9627216cc50057994c98a2118f3c4a23765d43b9'
|
6
7
|
export const DEFAULT_STBN_URL = `https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${ref}/packages/core/assets/stbn.bin`
|
package/src/decorators.ts
CHANGED
package/src/defineShorthand.ts
CHANGED
package/src/index.ts
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
export * from './ArrayBufferLoader'
|
2
2
|
export * from './assertions'
|
3
3
|
export * from './bufferGeometry'
|
4
|
+
export * from './capabilities'
|
4
5
|
export * from './constants'
|
5
|
-
export * from './
|
6
|
+
export * from './DataTextureLoader'
|
6
7
|
export * from './decorators'
|
7
8
|
export * from './defineShorthand'
|
8
9
|
export * from './Ellipsoid'
|
9
10
|
export * from './EllipsoidGeometry'
|
10
|
-
export * from './
|
11
|
+
export * from './EXR3DTextureLoader'
|
12
|
+
export * from './EXRTextureLoader'
|
11
13
|
export * from './Geodetic'
|
12
14
|
export * from './math'
|
13
15
|
export * from './PointOfView'
|
@@ -19,5 +21,5 @@ export * from './TilingScheme'
|
|
19
21
|
export * from './typedArray'
|
20
22
|
export * from './TypedArrayLoader'
|
21
23
|
export * from './typedArrayParsers'
|
22
|
-
export * from './types'
|
24
|
+
export type * from './types'
|
23
25
|
export * from './unrollLoops'
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import type { ElementProps } from '@react-three/fiber'
|
2
2
|
import { useEffect, useMemo, type FC, type ReactNode } from 'react'
|
3
3
|
import { Group, Matrix4, Vector3 } from 'three'
|
4
|
-
import {
|
4
|
+
import type { SetOptional } from 'type-fest'
|
5
5
|
|
6
6
|
import { Ellipsoid } from '../Ellipsoid'
|
7
7
|
import { Geodetic, type GeodeticLike } from '../Geodetic'
|
@@ -3,9 +3,8 @@ import {
|
|
3
3
|
type ElementProps,
|
4
4
|
type ThreeElement
|
5
5
|
} from '@react-three/fiber'
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import { type Mesh } from 'three'
|
6
|
+
import type { FC } from 'react'
|
7
|
+
import type { Mesh } from 'three'
|
9
8
|
|
10
9
|
import { EllipsoidGeometry } from '../EllipsoidGeometry'
|
11
10
|
|
@@ -26,10 +25,9 @@ export const EllipsoidMesh: FC<EllipsoidMeshProps> = ({
|
|
26
25
|
children,
|
27
26
|
...props
|
28
27
|
}) => {
|
29
|
-
const ref = useRef<Mesh | null>(null)
|
30
28
|
extend({ EllipsoidGeometry })
|
31
29
|
return (
|
32
|
-
<mesh ref={
|
30
|
+
<mesh ref={forwardedRef} {...props}>
|
33
31
|
<ellipsoidGeometry args={args} />
|
34
32
|
{children}
|
35
33
|
</mesh>
|
package/src/r3f/index.ts
CHANGED
package/src/r3f/types.ts
CHANGED
package/src/typedArrayParsers.ts
CHANGED
package/src/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import type { FloatType, HalfFloatType, Uniform } from 'three'
|
2
2
|
|
3
3
|
export type Callable = (...args: any) => any
|
4
4
|
|
@@ -6,3 +6,5 @@ export type UniformMap<T> = Omit<Map<string, Uniform>, 'get'> & {
|
|
6
6
|
get: <K extends keyof T>(key: K) => T[K]
|
7
7
|
set: <K extends keyof T>(key: K, value: T[K]) => void
|
8
8
|
}
|
9
|
+
|
10
|
+
export type AnyFloatType = typeof FloatType | typeof HalfFloatType
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Loader, ColorSpace, Data3DTexture, DataTexture, LoadingManager, MagnificationTextureFilter, Mapping, MinificationTextureFilter, PixelFormat, TextureDataType, Wrapping } from 'three';
|
2
|
+
import { Class } from 'type-fest';
|
3
|
+
import { TypedArray } from './typedArray';
|
4
|
+
import { TypedArrayParser } from './typedArrayParsers';
|
5
|
+
export interface DataTextureLoaderOptions {
|
6
|
+
width?: number;
|
7
|
+
height?: number;
|
8
|
+
depth?: number;
|
9
|
+
mapping?: Mapping;
|
10
|
+
wrapS?: Wrapping;
|
11
|
+
wrapT?: Wrapping;
|
12
|
+
wrapR?: Wrapping;
|
13
|
+
magFilter?: MagnificationTextureFilter;
|
14
|
+
minFilter?: MinificationTextureFilter;
|
15
|
+
format?: PixelFormat;
|
16
|
+
type?: TextureDataType;
|
17
|
+
anisotropy?: number;
|
18
|
+
colorSpace?: ColorSpace;
|
19
|
+
manager?: LoadingManager;
|
20
|
+
}
|
21
|
+
export declare class DataTextureLoader<T extends DataTexture | Data3DTexture = DataTexture | Data3DTexture, U extends TypedArray = TypedArray> extends Loader<T> {
|
22
|
+
textureClass: Class<T>;
|
23
|
+
parser: TypedArrayParser<U>;
|
24
|
+
options: DataTextureLoaderOptions;
|
25
|
+
constructor(textureClass: Class<T>, parser: TypedArrayParser<U>, options?: DataTextureLoaderOptions, manager?: LoadingManager);
|
26
|
+
load(url: string, onLoad?: (data: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): T;
|
27
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Data3DTexture, Loader, LoadingManager } from 'three';
|
2
|
+
export interface EXR3DTextureLoaderOptions {
|
3
|
+
width?: number;
|
4
|
+
height?: number;
|
5
|
+
depth?: number;
|
6
|
+
}
|
7
|
+
export declare class EXR3DTextureLoader extends Loader<Data3DTexture> {
|
8
|
+
options: EXR3DTextureLoaderOptions;
|
9
|
+
constructor(options?: EXR3DTextureLoaderOptions, manager?: LoadingManager);
|
10
|
+
load(url: string, onLoad?: (data: Data3DTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): Data3DTexture;
|
11
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { DataTexture, Loader, LoadingManager } from 'three';
|
2
|
+
export interface EXRTextureLoaderOptions {
|
3
|
+
width?: number;
|
4
|
+
height?: number;
|
5
|
+
}
|
6
|
+
export declare class EXRTextureLoader extends Loader<DataTexture> {
|
7
|
+
options: EXRTextureLoaderOptions;
|
8
|
+
constructor(options?: EXRTextureLoaderOptions, manager?: LoadingManager);
|
9
|
+
load(url: string, onLoad?: (data: DataTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): DataTexture;
|
10
|
+
}
|
package/types/STBNLoader.d.ts
CHANGED
@@ -1 +1,5 @@
|
|
1
|
-
|
1
|
+
import { Data3DTexture, LoadingManager } from 'three';
|
2
|
+
import { DataTextureLoader } from './DataTextureLoader';
|
3
|
+
export declare class STBNLoader extends DataTextureLoader<Data3DTexture> {
|
4
|
+
constructor(manager?: LoadingManager);
|
5
|
+
}
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import { Loader } from 'three';
|
2
|
-
import { Class } from 'type-fest';
|
1
|
+
import { Loader, LoadingManager } from 'three';
|
3
2
|
import { TypedArray } from './typedArray';
|
4
3
|
import { TypedArrayParser } from './typedArrayParsers';
|
5
|
-
export declare
|
6
|
-
|
4
|
+
export declare class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
|
5
|
+
parser: TypedArrayParser<T>;
|
6
|
+
constructor(parser: TypedArrayParser<T>, manager?: LoadingManager);
|
7
7
|
load(url: string, onLoad: (data: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
|
8
8
|
}
|
9
|
-
export declare function createTypedArrayLoaderClass<T extends TypedArray>(parser: TypedArrayParser<T>): Class<TypedArrayLoader<T>>;
|
10
|
-
export declare function createTypedArrayLoader<T extends TypedArray>(parser: TypedArrayParser<T>): TypedArrayLoader<T>;
|
package/types/index.d.ts
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
export * from './ArrayBufferLoader';
|
2
2
|
export * from './assertions';
|
3
3
|
export * from './bufferGeometry';
|
4
|
+
export * from './capabilities';
|
4
5
|
export * from './constants';
|
5
|
-
export * from './
|
6
|
+
export * from './DataTextureLoader';
|
6
7
|
export * from './decorators';
|
7
8
|
export * from './defineShorthand';
|
8
9
|
export * from './Ellipsoid';
|
9
10
|
export * from './EllipsoidGeometry';
|
10
|
-
export * from './
|
11
|
+
export * from './EXR3DTextureLoader';
|
12
|
+
export * from './EXRTextureLoader';
|
11
13
|
export * from './Geodetic';
|
12
14
|
export * from './math';
|
13
15
|
export * from './PointOfView';
|
@@ -19,5 +21,5 @@ export * from './TilingScheme';
|
|
19
21
|
export * from './typedArray';
|
20
22
|
export * from './TypedArrayLoader';
|
21
23
|
export * from './typedArrayParsers';
|
22
|
-
export * from './types';
|
24
|
+
export type * from './types';
|
23
25
|
export * from './unrollLoops';
|
package/types/r3f/index.d.ts
CHANGED
package/types/types.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { Uniform } from 'three';
|
1
|
+
import { FloatType, HalfFloatType, Uniform } from 'three';
|
2
2
|
export type Callable = (...args: any) => any;
|
3
3
|
export type UniformMap<T> = Omit<Map<string, Uniform>, 'get'> & {
|
4
4
|
get: <K extends keyof T>(key: K) => T[K];
|
5
5
|
set: <K extends keyof T>(key: K, value: T[K]) => void;
|
6
6
|
};
|
7
|
+
export type AnyFloatType = typeof FloatType | typeof HalfFloatType;
|
package/src/DataLoader.ts
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
ByteType,
|
3
|
-
Data3DTexture,
|
4
|
-
DataTexture,
|
5
|
-
FloatType,
|
6
|
-
HalfFloatType,
|
7
|
-
IntType,
|
8
|
-
LinearFilter,
|
9
|
-
Loader,
|
10
|
-
RGBAFormat,
|
11
|
-
ShortType,
|
12
|
-
UnsignedByteType,
|
13
|
-
UnsignedIntType,
|
14
|
-
UnsignedShortType,
|
15
|
-
type TextureDataType
|
16
|
-
} from 'three'
|
17
|
-
import invariant from 'tiny-invariant'
|
18
|
-
import { type Class, type WritableKeysOf } from 'type-fest'
|
19
|
-
|
20
|
-
import { Float16Array, type TypedArray } from './typedArray'
|
21
|
-
import {
|
22
|
-
createTypedArrayLoaderClass,
|
23
|
-
type TypedArrayLoader
|
24
|
-
} from './TypedArrayLoader'
|
25
|
-
import { type TypedArrayParser } from './typedArrayParsers'
|
26
|
-
import { type Callable } from './types'
|
27
|
-
|
28
|
-
// TODO: Move to types
|
29
|
-
type ParameterProperties<T> = {
|
30
|
-
[K in WritableKeysOf<T> as T[K] extends Callable ? never : K]: T[K]
|
31
|
-
}
|
32
|
-
|
33
|
-
function getTextureDataType(array: TypedArray): TextureDataType {
|
34
|
-
// prettier-ignore
|
35
|
-
const type = (
|
36
|
-
array instanceof Int8Array ? ByteType :
|
37
|
-
array instanceof Uint8Array ? UnsignedByteType :
|
38
|
-
array instanceof Uint8ClampedArray ? UnsignedByteType :
|
39
|
-
array instanceof Int16Array ? ShortType :
|
40
|
-
array instanceof Uint16Array ? UnsignedShortType :
|
41
|
-
array instanceof Int32Array ? IntType :
|
42
|
-
array instanceof Uint32Array ? UnsignedIntType :
|
43
|
-
array instanceof Float16Array ? HalfFloatType :
|
44
|
-
array instanceof Float32Array ? FloatType :
|
45
|
-
array instanceof Float64Array ? FloatType :
|
46
|
-
null
|
47
|
-
)
|
48
|
-
invariant(type != null)
|
49
|
-
return type
|
50
|
-
}
|
51
|
-
|
52
|
-
export interface DataTextureParameters
|
53
|
-
extends Omit<Partial<ParameterProperties<DataTexture>>, 'image'> {
|
54
|
-
width?: number
|
55
|
-
height?: number
|
56
|
-
}
|
57
|
-
|
58
|
-
export interface Data3DTextureParameters
|
59
|
-
extends Omit<Partial<ParameterProperties<Data3DTexture>>, 'image'> {
|
60
|
-
width?: number
|
61
|
-
height?: number
|
62
|
-
depth?: number
|
63
|
-
}
|
64
|
-
|
65
|
-
const defaultDataTextureParameter = {
|
66
|
-
format: RGBAFormat,
|
67
|
-
minFilter: LinearFilter,
|
68
|
-
magFilter: LinearFilter
|
69
|
-
} satisfies DataTextureParameters & Data3DTextureParameters
|
70
|
-
|
71
|
-
export abstract class DataLoader<
|
72
|
-
T extends DataTexture | Data3DTexture = DataTexture | Data3DTexture,
|
73
|
-
U extends TypedArray = TypedArray
|
74
|
-
> extends Loader<T> {
|
75
|
-
abstract readonly Texture: Class<T>
|
76
|
-
abstract readonly TypedArrayLoader: Class<TypedArrayLoader<U>>
|
77
|
-
|
78
|
-
readonly parameters: DataTextureParameters & Data3DTextureParameters = {}
|
79
|
-
|
80
|
-
override load(
|
81
|
-
url: string,
|
82
|
-
onLoad: (data: T) => void,
|
83
|
-
onProgress?: (event: ProgressEvent) => void,
|
84
|
-
onError?: (error: unknown) => void
|
85
|
-
): void {
|
86
|
-
const texture = new this.Texture()
|
87
|
-
const loader = new this.TypedArrayLoader(this.manager)
|
88
|
-
loader.setRequestHeader(this.requestHeader)
|
89
|
-
loader.setPath(this.path)
|
90
|
-
loader.setWithCredentials(this.withCredentials)
|
91
|
-
loader.load(
|
92
|
-
url,
|
93
|
-
array => {
|
94
|
-
texture.image.data =
|
95
|
-
array instanceof Float16Array ? new Uint16Array(array.buffer) : array
|
96
|
-
const { width, height, depth, ...params } = this.parameters
|
97
|
-
if (width != null) {
|
98
|
-
texture.image.width = width
|
99
|
-
}
|
100
|
-
if (height != null) {
|
101
|
-
texture.image.height = height
|
102
|
-
}
|
103
|
-
if ('depth' in texture.image && depth != null) {
|
104
|
-
texture.image.depth = depth
|
105
|
-
}
|
106
|
-
|
107
|
-
// Populate the default texture type for the array type.
|
108
|
-
texture.type = getTextureDataType(array)
|
109
|
-
|
110
|
-
Object.assign(texture, params)
|
111
|
-
texture.needsUpdate = true
|
112
|
-
onLoad(texture)
|
113
|
-
},
|
114
|
-
onProgress,
|
115
|
-
onError
|
116
|
-
)
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
function createDataLoaderClass<
|
121
|
-
T extends DataTexture | Data3DTexture,
|
122
|
-
U extends TypedArray
|
123
|
-
>(
|
124
|
-
Texture: Class<T>,
|
125
|
-
parser: TypedArrayParser<U>,
|
126
|
-
parameters?: DataTextureParameters
|
127
|
-
): Class<DataLoader<T, U>> {
|
128
|
-
return class extends DataLoader<T, U> {
|
129
|
-
readonly Texture = Texture
|
130
|
-
readonly TypedArrayLoader = createTypedArrayLoaderClass(parser)
|
131
|
-
readonly parameters = {
|
132
|
-
...defaultDataTextureParameter,
|
133
|
-
...parameters
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
export function createData3DTextureLoaderClass<T extends TypedArray>(
|
139
|
-
parser: TypedArrayParser<T>,
|
140
|
-
parameters?: Data3DTextureParameters
|
141
|
-
): Class<DataLoader<Data3DTexture, T>> {
|
142
|
-
return createDataLoaderClass(Data3DTexture, parser, parameters)
|
143
|
-
}
|
144
|
-
|
145
|
-
export function createDataTextureLoaderClass<T extends TypedArray>(
|
146
|
-
parser: TypedArrayParser<T>,
|
147
|
-
parameters?: DataTextureParameters
|
148
|
-
): Class<DataLoader<DataTexture, T>> {
|
149
|
-
return createDataLoaderClass(DataTexture, parser, parameters)
|
150
|
-
}
|
151
|
-
|
152
|
-
export function createData3DTextureLoader<T extends TypedArray>(
|
153
|
-
parser: TypedArrayParser<T>,
|
154
|
-
parameters?: Data3DTextureParameters
|
155
|
-
): DataLoader<Data3DTexture, T> {
|
156
|
-
return new (createData3DTextureLoaderClass(parser, parameters))()
|
157
|
-
}
|
158
|
-
|
159
|
-
export function createDataTextureLoader<T extends TypedArray>(
|
160
|
-
parser: TypedArrayParser<T>,
|
161
|
-
parameters?: DataTextureParameters
|
162
|
-
): DataLoader<DataTexture, T> {
|
163
|
-
return new (createDataTextureLoaderClass(parser, parameters))()
|
164
|
-
}
|