@takram/three-geospatial 0.0.1-alpha.8 → 0.1.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/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './decorators'
7
7
  export * from './defineShorthand'
8
8
  export * from './Ellipsoid'
9
9
  export * from './EllipsoidGeometry'
10
+ export * from './EXR3DLoader'
10
11
  export * from './Geodetic'
11
12
  export * from './math'
12
13
  export * from './PointOfView'
package/src/typedArray.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ Float16Array,
3
+ type Float16ArrayConstructor
4
+ } from '@petamoriken/float16'
1
5
  import invariant from 'tiny-invariant'
2
6
 
3
7
  export type TypedArray =
@@ -8,6 +12,7 @@ export type TypedArray =
8
12
  | Uint16Array
9
13
  | Int32Array
10
14
  | Uint32Array
15
+ | Float16Array
11
16
  | Float32Array
12
17
  | Float64Array
13
18
 
@@ -19,9 +24,11 @@ export type TypedArrayConstructor =
19
24
  | Uint16ArrayConstructor
20
25
  | Int32ArrayConstructor
21
26
  | Uint32ArrayConstructor
27
+ | Float16ArrayConstructor
22
28
  | Float32ArrayConstructor
23
29
  | Float64ArrayConstructor
24
30
 
31
+ /** @deprecated */
25
32
  export type TypedArrayElementType =
26
33
  | 'int8'
27
34
  | 'uint8'
@@ -29,9 +36,11 @@ export type TypedArrayElementType =
29
36
  | 'uint16'
30
37
  | 'int32'
31
38
  | 'uint32'
39
+ | 'float16'
32
40
  | 'float32'
33
41
  | 'float64'
34
42
 
43
+ /** @deprecated Use getTypedArrayTextureDataType instead */
35
44
  export function getTypedArrayElementType(
36
45
  array: TypedArray
37
46
  ): TypedArrayElementType {
@@ -44,6 +53,7 @@ export function getTypedArrayElementType(
44
53
  array instanceof Uint16Array ? 'uint16' :
45
54
  array instanceof Int32Array ? 'int32' :
46
55
  array instanceof Uint32Array ? 'uint32' :
56
+ array instanceof Float16Array ? 'float16' :
47
57
  array instanceof Float32Array ? 'float32' :
48
58
  array instanceof Float64Array ? 'float64' :
49
59
  null
@@ -51,3 +61,20 @@ export function getTypedArrayElementType(
51
61
  invariant(type != null)
52
62
  return type
53
63
  }
64
+
65
+ export function isTypedArray(value: unknown): value is TypedArray {
66
+ return (
67
+ value instanceof Int8Array ||
68
+ value instanceof Uint8Array ||
69
+ value instanceof Uint8ClampedArray ||
70
+ value instanceof Int16Array ||
71
+ value instanceof Uint16Array ||
72
+ value instanceof Int32Array ||
73
+ value instanceof Uint32Array ||
74
+ value instanceof Float16Array ||
75
+ value instanceof Float32Array ||
76
+ value instanceof Float64Array
77
+ )
78
+ }
79
+
80
+ export { Float16Array }
@@ -1,3 +1,5 @@
1
+ import { Float16Array, getFloat16 } from '@petamoriken/float16'
2
+
1
3
  import { type TypedArray, type TypedArrayConstructor } from './typedArray'
2
4
 
3
5
  let hostLittleEndian: boolean | undefined
@@ -12,11 +14,13 @@ function isHostLittleEndian(): boolean {
12
14
  return hostLittleEndian
13
15
  }
14
16
 
15
- type GetValue = keyof {
16
- [K in keyof DataView as DataView[K] extends (byteOffset: number) => number
17
- ? K
18
- : never]: DataView[K]
19
- }
17
+ type GetValue =
18
+ | keyof {
19
+ [K in keyof DataView as DataView[K] extends (byteOffset: number) => number
20
+ ? K
21
+ : never]: DataView[K]
22
+ }
23
+ | 'getFloat16'
20
24
 
21
25
  function parseTypedArray<T extends TypedArrayConstructor, K extends GetValue>(
22
26
  buffer: ArrayBuffer,
@@ -32,9 +36,15 @@ function parseTypedArray<K extends GetValue>(
32
36
  littleEndian = true
33
37
  ): TypedArray {
34
38
  if (littleEndian === isHostLittleEndian()) {
39
+ // eslint-disable-next-line
40
+ // @ts-ignore False positive type error in Node.js
35
41
  return new TypedArray(buffer)
36
42
  }
37
- const data = new DataView(buffer)
43
+ const data = Object.assign(new DataView(buffer), {
44
+ getFloat16(this: DataView, byteOffset: number, littleEndian?: boolean) {
45
+ return getFloat16(this, byteOffset, littleEndian)
46
+ }
47
+ })
38
48
  const array = new TypedArray(data.byteLength / TypedArray.BYTES_PER_ELEMENT)
39
49
  for (
40
50
  let index = 0, byteIndex = 0;
@@ -77,6 +87,11 @@ export const parseUint32Array: TypedArrayParser<Uint32Array> = (
77
87
  littleEndian
78
88
  ) => parseTypedArray(buffer, Uint32Array, 'getUint32', littleEndian)
79
89
 
90
+ export const parseFloat16Array: TypedArrayParser<Float16Array> = (
91
+ buffer,
92
+ littleEndian
93
+ ) => parseTypedArray(buffer, Float16Array, 'getFloat16', littleEndian)
94
+
80
95
  export const parseFloat32Array: TypedArrayParser<Float32Array> = (
81
96
  buffer,
82
97
  littleEndian
@@ -1,8 +1,9 @@
1
1
  import { Callable } from './types';
2
2
  import { TypedArrayParser } from './typedArrayParsers';
3
3
  import { TypedArrayLoader } from './TypedArrayLoader';
4
+ import { TypedArray } from './typedArray';
4
5
  import { Class, WritableKeysOf } from 'type-fest';
5
- import { Data3DTexture, DataTexture, Loader, TypedArray } from 'three';
6
+ import { Data3DTexture, DataTexture, Loader } from 'three';
6
7
 
7
8
  type ParameterProperties<T> = {
8
9
  [K in WritableKeysOf<T> as T[K] extends Callable ? never : K]: T[K];
@@ -26,12 +27,4 @@ export declare function createData3DTextureLoaderClass<T extends TypedArray>(par
26
27
  export declare function createDataTextureLoaderClass<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: DataTextureParameters): Class<DataLoader<DataTexture, T>>;
27
28
  export declare function createData3DTextureLoader<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: Data3DTextureParameters): DataLoader<Data3DTexture, T>;
28
29
  export declare function createDataTextureLoader<T extends TypedArray>(parser: TypedArrayParser<T>, parameters?: DataTextureParameters): DataLoader<DataTexture, T>;
29
- /** @deprecated Use createDataTextureLoaderClass instead. */
30
- export declare const Int16Data2DLoader: Class<DataLoader<DataTexture, Int16Array<ArrayBufferLike>>>;
31
- /** @deprecated Use createDataTextureLoaderClass instead. */
32
- export declare const Uint16Data2DLoader: Class<DataLoader<DataTexture, Uint16Array<ArrayBufferLike>>>;
33
- /** @deprecated Use createDataTextureLoaderClass instead. */
34
- export declare const Float32Data2DLoader: Class<DataLoader<DataTexture, Float32Array<ArrayBufferLike>>>;
35
- /** @deprecated Use createData3DTextureLoaderClass instead. */
36
- export declare const Float32Data3DLoader: Class<DataLoader<Data3DTexture, Float32Array<ArrayBufferLike>>>;
37
30
  export {};
@@ -0,0 +1,7 @@
1
+ import { Data3DTexture, Loader } from 'three';
2
+
3
+ export declare class EXR3DLoader extends Loader<Data3DTexture> {
4
+ depth?: number;
5
+ setDepth(value: number): this;
6
+ load(url: string, onLoad: (data: Data3DTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
7
+ }
@@ -1,6 +1,7 @@
1
1
  import { TypedArrayParser } from './typedArrayParsers';
2
+ import { TypedArray } from './typedArray';
2
3
  import { Class } from 'type-fest';
3
- import { Loader, TypedArray } from 'three';
4
+ import { Loader } from 'three';
4
5
 
5
6
  export declare abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
6
7
  abstract parseTypedArray(buffer: ArrayBuffer): T;
package/types/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './decorators';
7
7
  export * from './defineShorthand';
8
8
  export * from './Ellipsoid';
9
9
  export * from './EllipsoidGeometry';
10
+ export * from './EXR3DLoader';
10
11
  export * from './Geodetic';
11
12
  export * from './math';
12
13
  export * from './PointOfView';
@@ -1,4 +1,10 @@
1
- export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
2
- export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
3
- export type TypedArrayElementType = 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'float32' | 'float64';
1
+ import { Float16Array, Float16ArrayConstructor } from '@petamoriken/float16';
2
+
3
+ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float16Array | Float32Array | Float64Array;
4
+ export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float16ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
5
+ /** @deprecated */
6
+ export type TypedArrayElementType = 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'float16' | 'float32' | 'float64';
7
+ /** @deprecated Use getTypedArrayTextureDataType instead */
4
8
  export declare function getTypedArrayElementType(array: TypedArray): TypedArrayElementType;
9
+ export declare function isTypedArray(value: unknown): value is TypedArray;
10
+ export { Float16Array };
@@ -1,4 +1,5 @@
1
1
  import { TypedArray } from './typedArray';
2
+ import { Float16Array } from '@petamoriken/float16';
2
3
 
3
4
  export type TypedArrayParser<T extends TypedArray> = (buffer: ArrayBuffer, littleEndian?: boolean) => T;
4
5
  export declare const parseUint8Array: TypedArrayParser<Uint8Array>;
@@ -7,5 +8,6 @@ export declare const parseUint16Array: TypedArrayParser<Uint16Array>;
7
8
  export declare const parseInt16Array: TypedArrayParser<Int16Array>;
8
9
  export declare const parseInt32Array: TypedArrayParser<Int32Array>;
9
10
  export declare const parseUint32Array: TypedArrayParser<Uint32Array>;
11
+ export declare const parseFloat16Array: TypedArrayParser<Float16Array>;
10
12
  export declare const parseFloat32Array: TypedArrayParser<Float32Array>;
11
13
  export declare const parseFloat64Array: TypedArrayParser<Float64Array>;