@takram/three-geospatial 0.2.2 → 0.4.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/index.cjs +1 -1
  3. package/build/index.cjs.map +1 -1
  4. package/build/index.js +1294 -1283
  5. package/build/index.js.map +1 -1
  6. package/build/r3f.cjs +1 -1
  7. package/build/r3f.cjs.map +1 -1
  8. package/build/r3f.js +28 -55
  9. package/build/r3f.js.map +1 -1
  10. package/build/shaders.cjs.map +1 -1
  11. package/build/shaders.js.map +1 -1
  12. package/build/shared.cjs +1 -1
  13. package/build/shared.cjs.map +1 -1
  14. package/build/shared.js +69 -65
  15. package/build/shared.js.map +1 -1
  16. package/package.json +1 -2
  17. package/src/DataTextureLoader.ts +134 -0
  18. package/src/EXR3DTextureLoader.ts +66 -0
  19. package/src/{EXR3DLoader.ts → EXRTextureLoader.ts} +25 -12
  20. package/src/Ellipsoid.ts +8 -0
  21. package/src/STBNLoader.ts +28 -13
  22. package/src/TilingScheme.ts +1 -1
  23. package/src/TypedArrayLoader.ts +11 -21
  24. package/src/capabilities.ts +5 -0
  25. package/src/constants.ts +1 -0
  26. package/src/decorators.ts +9 -5
  27. package/src/defineShorthand.ts +1 -1
  28. package/src/index.ts +5 -3
  29. package/src/r3f/EastNorthUpFrame.tsx +2 -2
  30. package/src/r3f/EllipsoidMesh.tsx +3 -5
  31. package/src/r3f/index.ts +1 -1
  32. package/src/r3f/types.ts +1 -1
  33. package/src/typedArrayParsers.ts +1 -1
  34. package/src/types.ts +3 -1
  35. package/types/DataTextureLoader.d.ts +27 -0
  36. package/types/EXR3DTextureLoader.d.ts +11 -0
  37. package/types/EXRTextureLoader.d.ts +10 -0
  38. package/types/Ellipsoid.d.ts +1 -0
  39. package/types/STBNLoader.d.ts +5 -1
  40. package/types/TypedArrayLoader.d.ts +4 -6
  41. package/types/bufferGeometry.d.ts +1 -1
  42. package/types/capabilities.d.ts +2 -0
  43. package/types/decorators.d.ts +8 -5
  44. package/types/index.d.ts +5 -3
  45. package/types/r3f/index.d.ts +1 -1
  46. package/types/types.d.ts +2 -1
  47. package/src/DataLoader.ts +0 -164
  48. package/src/Texture3DLoader.ts +0 -81
  49. package/types/DataLoader.d.ts +0 -29
  50. package/types/EXR3DLoader.d.ts +0 -6
  51. package/types/Texture3DLoader.d.ts +0 -4
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 './DataLoader'
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 './EXR3DLoader'
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 { type ElementProps } from '@react-three/fiber'
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 { type SetOptional } from 'type-fest'
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 { useRef, type FC } from 'react'
7
- import { mergeRefs } from 'react-merge-refs'
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={mergeRefs([ref, forwardedRef])} {...props}>
30
+ <mesh ref={forwardedRef} {...props}>
33
31
  <ellipsoidGeometry args={args} />
34
32
  {children}
35
33
  </mesh>
package/src/r3f/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './EastNorthUpFrame'
2
2
  export * from './EllipsoidMesh'
3
- export * from './types'
3
+ export type * from './types'
package/src/r3f/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type MathType, type MathTypes } from '@react-three/fiber'
1
+ import type { MathType, MathTypes } from '@react-three/fiber'
2
2
 
3
3
  export type OverwriteMathProps<T> = {
4
4
  [K in keyof T]: Exclude<T[K], undefined> extends MathTypes
@@ -1,6 +1,6 @@
1
1
  import { Float16Array, getFloat16 } from '@petamoriken/float16'
2
2
 
3
- import { type TypedArray, type TypedArrayConstructor } from './typedArray'
3
+ import type { TypedArray, TypedArrayConstructor } from './typedArray'
4
4
 
5
5
  let hostLittleEndian: boolean | undefined
6
6
 
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Uniform } from 'three'
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
+ }
@@ -12,6 +12,7 @@ export declare class Ellipsoid {
12
12
  getSurfaceNormal(position: Vector3, result?: Vector3): Vector3;
13
13
  getEastNorthUpVectors(position: Vector3, east?: Vector3, north?: Vector3, up?: Vector3): void;
14
14
  getEastNorthUpFrame(position: Vector3, result?: Matrix4): Matrix4;
15
+ getNorthUpEastFrame(position: Vector3, result?: Matrix4): Matrix4;
15
16
  getIntersection(ray: Ray, result?: Vector3): Vector3 | undefined;
16
17
  getOsculatingSphereCenter(surfacePosition: Vector3, radius: number, result?: Vector3): Vector3;
17
18
  getNormalAtHorizon(position: Vector3, direction: Vector3, result?: Vector3): Vector3;
@@ -1 +1,5 @@
1
- export declare const STBNLoader: import('type-fest').Class<import('./DataLoader').DataLoader<import('three').Data3DTexture, Uint8Array<ArrayBufferLike>>>;
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 abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
6
- abstract parseTypedArray(buffer: ArrayBuffer): T;
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>;
@@ -20,4 +20,4 @@ export interface BufferGeometryLike {
20
20
  } | null;
21
21
  }
22
22
  export declare function toBufferGeometryLike(geometry: BufferGeometry): [BufferGeometryLike, ArrayBuffer[]];
23
- export declare function fromBufferGeometryLike(input: BufferGeometryLike, result?: BufferGeometry<import('three').NormalBufferAttributes>): BufferGeometry;
23
+ export declare function fromBufferGeometryLike(input: BufferGeometryLike, result?: BufferGeometry<import('three').NormalBufferAttributes, import('three').BufferGeometryEventMap>): BufferGeometry;
@@ -0,0 +1,2 @@
1
+ import { WebGLRenderer } from 'three';
2
+ export declare function isFloatLinearSupported(renderer: WebGLRenderer): boolean;
@@ -1,21 +1,24 @@
1
- import { Material } from 'three';
1
+ interface MaterialLike {
2
+ defines?: Record<string, string>;
3
+ set needsUpdate(value: boolean);
4
+ }
2
5
  interface EffectLike {
3
6
  defines: Map<string, string>;
4
7
  }
5
- export declare function define(name: string): <T extends Material | EffectLike, K extends keyof T>(target: T[K] extends boolean ? T : never, propertyKey: K) => void;
8
+ export declare function define(name: string): <T extends MaterialLike | EffectLike, K extends keyof T>(target: T[K] extends boolean ? T : never, propertyKey: K) => void;
6
9
  export interface DefineIntDecoratorOptions {
7
10
  min?: number;
8
11
  max?: number;
9
12
  }
10
- export declare function defineInt(name: string, { min, max }?: DefineIntDecoratorOptions): <T extends Material | EffectLike, K extends keyof T>(target: T[K] extends number ? T : never, propertyKey: K) => void;
13
+ export declare function defineInt(name: string, { min, max }?: DefineIntDecoratorOptions): <T extends MaterialLike | EffectLike, K extends keyof T>(target: T[K] extends number ? T : never, propertyKey: K) => void;
11
14
  export interface DefineFloatDecoratorOptions {
12
15
  min?: number;
13
16
  max?: number;
14
17
  precision?: number;
15
18
  }
16
- export declare function defineFloat(name: string, { min, max, precision }?: DefineFloatDecoratorOptions): <T extends Material | EffectLike, K extends keyof T>(target: T[K] extends number ? T : never, propertyKey: K) => void;
19
+ export declare function defineFloat(name: string, { min, max, precision }?: DefineFloatDecoratorOptions): <T extends MaterialLike | EffectLike, K extends keyof T>(target: T[K] extends number ? T : never, propertyKey: K) => void;
17
20
  export interface DefineExpressionDecoratorOptions {
18
21
  validate?: (value: string) => boolean;
19
22
  }
20
- export declare function defineExpression(name: string, { validate }?: DefineExpressionDecoratorOptions): <T extends Material | EffectLike, K extends keyof T>(target: T[K] extends string ? T : never, propertyKey: K) => void;
23
+ export declare function defineExpression(name: string, { validate }?: DefineExpressionDecoratorOptions): <T extends MaterialLike | EffectLike, K extends keyof T>(target: T[K] extends string ? T : never, propertyKey: K) => void;
21
24
  export {};
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 './DataLoader';
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 './EXR3DLoader';
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,3 +1,3 @@
1
1
  export * from './EastNorthUpFrame';
2
2
  export * from './EllipsoidMesh';
3
- export * from './types';
3
+ export type * from './types';
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
- }
@@ -1,81 +0,0 @@
1
- import {
2
- Data3DTexture,
3
- ImageLoader,
4
- LinearFilter,
5
- Loader,
6
- RepeatWrapping
7
- } from 'three'
8
-
9
- export class Texture3DLoader extends Loader<Data3DTexture> {
10
- override load(
11
- url: string,
12
- onLoad: (data: Data3DTexture) => void,
13
- onProgress?: (event: ProgressEvent) => void,
14
- onError?: (error: unknown) => void
15
- ): void {
16
- const loader = new ImageLoader(this.manager)
17
- loader.setRequestHeader(this.requestHeader)
18
- loader.setPath(this.path)
19
- loader.setWithCredentials(this.withCredentials)
20
- loader.load(
21
- url,
22
- image => {
23
- const canvas = document.createElement('canvas')
24
- const context = canvas.getContext('2d')
25
- if (context == null) {
26
- onError?.(new Error('Could not obtain canvas context.'))
27
- return
28
- }
29
-
30
- // Assume cubic 3D texture.
31
- const { width, height } = image
32
- const size = Math.min(width, height)
33
- canvas.width = width
34
- canvas.height = height
35
- context.drawImage(image, 0, 0)
36
- const imageData = context.getImageData(0, 0, width, height).data
37
- let data: Uint8Array
38
-
39
- if (width < height) {
40
- data = new Uint8Array(imageData.buffer)
41
- } else {
42
- data = new Uint8Array(imageData.length)
43
- const sizeSq = size ** 2
44
- for (let z = 0; z < size; ++z) {
45
- for (let y = 0; y < size; ++y) {
46
- for (let x = 0; x < size; ++x) {
47
- const src = (x + z * size + y * sizeSq) * 4
48
- const dest = (x + y * size + z * sizeSq) * 4
49
- data[dest + 0] = imageData[src + 0]
50
- data[dest + 1] = imageData[src + 1]
51
- data[dest + 2] = imageData[src + 2]
52
- data[dest + 3] = imageData[src + 3]
53
- }
54
- }
55
- }
56
- }
57
-
58
- const texture = new Data3DTexture(data, size, size, size)
59
- texture.minFilter = LinearFilter
60
- texture.magFilter = LinearFilter
61
- texture.wrapS = RepeatWrapping
62
- texture.wrapT = RepeatWrapping
63
- texture.wrapR = RepeatWrapping
64
- texture.needsUpdate = true
65
-
66
- try {
67
- onLoad(texture)
68
- } catch (error) {
69
- if (onError != null) {
70
- onError(error)
71
- } else {
72
- console.error(error)
73
- }
74
- this.manager.itemError(url)
75
- }
76
- },
77
- onProgress,
78
- onError
79
- )
80
- }
81
- }
@@ -1,29 +0,0 @@
1
- import { Data3DTexture, DataTexture, Loader } from 'three';
2
- import { Class, WritableKeysOf } from 'type-fest';
3
- import { TypedArray } from './typedArray';
4
- import { TypedArrayLoader } from './TypedArrayLoader';
5
- import { TypedArrayParser } from './typedArrayParsers';
6
- import { Callable } from './types';
7
- type ParameterProperties<T> = {
8
- [K in WritableKeysOf<T> as T[K] extends Callable ? never : K]: T[K];
9
- };
10
- export interface DataTextureParameters extends Omit<Partial<ParameterProperties<DataTexture>>, 'image'> {
11
- width?: number;
12
- height?: number;
13
- }
14
- export interface Data3DTextureParameters extends Omit<Partial<ParameterProperties<Data3DTexture>>, 'image'> {
15
- width?: number;
16
- height?: number;
17
- depth?: number;
18
- }
19
- export declare abstract class DataLoader<T extends DataTexture | Data3DTexture = DataTexture | Data3DTexture, U extends TypedArray = TypedArray> extends Loader<T> {
20
- abstract readonly Texture: Class<T>;
21
- abstract readonly TypedArrayLoader: Class<TypedArrayLoader<U>>;
22
- readonly parameters: DataTextureParameters & Data3DTextureParameters;
23
- load(url: string, onLoad: (data: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
24
- }
25
- export declare function createData3DTextureLoaderClass<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: Data3DTextureParameters): Class<DataLoader<Data3DTexture, T>>;
26
- export declare function createDataTextureLoaderClass<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: DataTextureParameters): Class<DataLoader<DataTexture, T>>;
27
- export declare function createData3DTextureLoader<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: Data3DTextureParameters): DataLoader<Data3DTexture, T>;
28
- export declare function createDataTextureLoader<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: DataTextureParameters): DataLoader<DataTexture, T>;
29
- export {};
@@ -1,6 +0,0 @@
1
- import { Data3DTexture, Loader } from 'three';
2
- export declare class EXR3DLoader extends Loader<Data3DTexture> {
3
- depth?: number;
4
- setDepth(value: number): this;
5
- load(url: string, onLoad: (data: Data3DTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
6
- }
@@ -1,4 +0,0 @@
1
- import { Data3DTexture, Loader } from 'three';
2
- export declare class Texture3DLoader extends Loader<Data3DTexture> {
3
- load(url: string, onLoad: (data: Data3DTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
4
- }