@takram/three-geospatial 0.1.0 → 0.2.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.
@@ -3,12 +3,7 @@ import { type Class } from 'type-fest'
3
3
 
4
4
  import { ArrayBufferLoader } from './ArrayBufferLoader'
5
5
  import { type TypedArray } from './typedArray'
6
- import {
7
- parseFloat32Array,
8
- parseInt16Array,
9
- parseUint16Array,
10
- type TypedArrayParser
11
- } from './typedArrayParsers'
6
+ import { type TypedArrayParser } from './typedArrayParsers'
12
7
 
13
8
  export abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
14
9
  abstract parseTypedArray(buffer: ArrayBuffer): T
@@ -56,15 +51,3 @@ export function createTypedArrayLoader<T extends TypedArray>(
56
51
  ): TypedArrayLoader<T> {
57
52
  return new (createTypedArrayLoaderClass(parser))()
58
53
  }
59
-
60
- /** @deprecated Use createTypedArrayLoaderClass instead. */
61
- export const Int16ArrayLoader =
62
- /*#__PURE__*/ createTypedArrayLoaderClass(parseInt16Array)
63
-
64
- /** @deprecated Use createTypedArrayLoaderClass instead. */
65
- export const Uint16ArrayLoader =
66
- /*#__PURE__*/ createTypedArrayLoaderClass(parseUint16Array)
67
-
68
- /** @deprecated Use createTypedArrayLoaderClass instead. */
69
- export const Float32ArrayLoader =
70
- /*#__PURE__*/ createTypedArrayLoaderClass(parseFloat32Array)
@@ -1,10 +1,36 @@
1
- import { Box3, BufferAttribute, BufferGeometry, Sphere, Vector3 } from 'three'
1
+ import {
2
+ Box3,
3
+ BufferAttribute,
4
+ BufferGeometry,
5
+ Sphere,
6
+ Vector3,
7
+ type TypedArray,
8
+ type Vector3Like
9
+ } from 'three'
2
10
 
3
- export interface BufferGeometryLike
4
- extends Pick<
5
- BufferGeometry,
6
- 'attributes' | 'index' | 'boundingBox' | 'boundingSphere'
7
- > {}
11
+ export interface BufferGeometryLike {
12
+ attributes: Record<
13
+ string,
14
+ {
15
+ array: TypedArray
16
+ itemSize: number
17
+ normalized?: boolean
18
+ }
19
+ >
20
+ index?: {
21
+ array: TypedArray
22
+ itemSize: number
23
+ normalized?: boolean
24
+ } | null
25
+ boundingBox?: {
26
+ min: Vector3Like
27
+ max: Vector3Like
28
+ } | null
29
+ boundingSphere?: {
30
+ center: Vector3Like
31
+ radius: number
32
+ } | null
33
+ }
8
34
 
9
35
  export function toBufferGeometryLike(
10
36
  geometry: BufferGeometry
package/src/constants.ts CHANGED
@@ -2,5 +2,5 @@ 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
- export const DEFAULT_STBN_URL =
6
- 'https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/9627216cc50057994c98a2118f3c4a23765d43b9/packages/core/assets/stbn.bin'
5
+ const ref = '9627216cc50057994c98a2118f3c4a23765d43b9'
6
+ export const DEFAULT_STBN_URL = `https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/${ref}/packages/core/assets/stbn.bin`
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  extend,
3
- type BufferGeometryNode,
4
- type MeshProps
3
+ type ElementProps,
4
+ type ThreeElement
5
5
  } from '@react-three/fiber'
6
6
  import { forwardRef, useRef } from 'react'
7
7
  import { mergeRefs } from 'react-merge-refs'
@@ -11,14 +11,12 @@ import { EllipsoidGeometry } from '../EllipsoidGeometry'
11
11
 
12
12
  declare module '@react-three/fiber' {
13
13
  interface ThreeElements {
14
- ellipsoidGeometry: BufferGeometryNode<
15
- EllipsoidGeometry,
16
- typeof EllipsoidGeometry
17
- >
14
+ ellipsoidGeometry: ThreeElement<typeof EllipsoidGeometry>
18
15
  }
19
16
  }
20
17
 
21
- export interface EllipsoidMeshProps extends Omit<MeshProps, 'args'> {
18
+ export interface EllipsoidMeshProps
19
+ extends Omit<ElementProps<typeof Mesh>, 'args'> {
22
20
  args?: ConstructorParameters<typeof EllipsoidGeometry>
23
21
  }
24
22
 
package/src/r3f/types.ts CHANGED
@@ -1,63 +1,13 @@
1
- import {
2
- type NodeProps,
3
- type Overwrite,
4
- type Color as R3FColor,
5
- type Vector2 as R3FVector2,
6
- type Vector3 as R3FVector3,
7
- type Vector4 as R3FVector4
8
- } from '@react-three/fiber'
9
- import {
10
- type Color as ColorImpl,
11
- type Vector2 as Vector2Impl,
12
- type Vector3 as Vector3Impl,
13
- type Vector4 as Vector4Impl
14
- } from 'three'
15
- import { type WritableKeysOf } from 'type-fest'
16
-
17
- import { type Callable } from '../types'
18
-
19
- // prettier-ignore
20
- export type ExtendedProps<T> = {
21
- [K in keyof T]:
22
- Vector2Impl extends T[K] ? R3FVector2 | T[K] :
23
- Vector3Impl extends T[K] ? R3FVector3 | T[K] :
24
- Vector4Impl extends T[K] ? R3FVector4 | T[K] :
25
- ColorImpl extends T[K] ? R3FColor | T[K] :
26
- T[K]
27
- }
28
-
29
- // @react-three/fiber's NonFunctionKeys cannot exclude partial functions.
30
- // This excludes callback properties, which may be undesirable behavior.
31
- type NonFunctionKeys<T> = keyof {
32
- [K in keyof T as Callable extends T[K] ? never : K]: any
1
+ import { type MathType, type MathTypes } from '@react-three/fiber'
2
+
3
+ export type OverwriteMathProps<T> = {
4
+ [K in keyof T]: Exclude<T[K], undefined> extends MathTypes
5
+ ? T[K] extends undefined
6
+ ? MathType<Exclude<T[K], undefined>> | undefined
7
+ : MathType<Exclude<T[K], undefined>>
8
+ : T[K]
33
9
  }
34
10
 
35
- // prettier-ignore
36
- type WritableNonExtendableKeysOf<T> =
37
- | WritableKeysOf<T>
38
- | keyof {
39
- [K in keyof T as
40
- Vector2Impl extends T[K] ? K :
41
- Vector3Impl extends T[K] ? K :
42
- Vector4Impl extends T[K] ? K :
43
- ColorImpl extends T[K] ? K :
44
- never
45
- ]: any
46
- }
47
-
48
- export type PassThoughInstanceProps<
49
- RefType,
50
- Args extends readonly any[],
51
- Props
52
- > = Overwrite<
53
- ExtendedProps<{
54
- [K in NonFunctionKeys<Props> as K extends WritableNonExtendableKeysOf<Props>
55
- ? K
56
- : never]: Props[K]
57
- }>,
58
- NodeProps<RefType, Args>
59
- >
60
-
61
11
  export type ExpandNestedProps<T, Prop extends keyof T & string> = {
62
12
  [K in keyof NonNullable<T[Prop]> as K extends string
63
13
  ? `${Prop}-${K}`
package/src/typedArray.ts CHANGED
@@ -2,7 +2,6 @@ import {
2
2
  Float16Array,
3
3
  type Float16ArrayConstructor
4
4
  } from '@petamoriken/float16'
5
- import invariant from 'tiny-invariant'
6
5
 
7
6
  export type TypedArray =
8
7
  | Int8Array
@@ -28,40 +27,6 @@ export type TypedArrayConstructor =
28
27
  | Float32ArrayConstructor
29
28
  | Float64ArrayConstructor
30
29
 
31
- /** @deprecated */
32
- export type TypedArrayElementType =
33
- | 'int8'
34
- | 'uint8'
35
- | 'int16'
36
- | 'uint16'
37
- | 'int32'
38
- | 'uint32'
39
- | 'float16'
40
- | 'float32'
41
- | 'float64'
42
-
43
- /** @deprecated Use getTypedArrayTextureDataType instead */
44
- export function getTypedArrayElementType(
45
- array: TypedArray
46
- ): TypedArrayElementType {
47
- // prettier-ignore
48
- const type = (
49
- array instanceof Int8Array ? 'int8' :
50
- array instanceof Uint8Array ? 'uint8' :
51
- array instanceof Uint8ClampedArray ? 'uint8' :
52
- array instanceof Int16Array ? 'int16' :
53
- array instanceof Uint16Array ? 'uint16' :
54
- array instanceof Int32Array ? 'int32' :
55
- array instanceof Uint32Array ? 'uint32' :
56
- array instanceof Float16Array ? 'float16' :
57
- array instanceof Float32Array ? 'float32' :
58
- array instanceof Float64Array ? 'float64' :
59
- null
60
- )
61
- invariant(type != null)
62
- return type
63
- }
64
-
65
30
  export function isTypedArray(value: unknown): value is TypedArray {
66
31
  return (
67
32
  value instanceof Int8Array ||
@@ -1,5 +1,4 @@
1
1
  import { Loader } from 'three';
2
-
3
2
  export declare class ArrayBufferLoader extends Loader<ArrayBuffer> {
4
3
  load(url: string, onLoad: (data: ArrayBuffer) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
5
4
  }
@@ -1,10 +1,9 @@
1
- import { Callable } from './types';
2
- import { TypedArrayParser } from './typedArrayParsers';
3
- import { TypedArrayLoader } from './TypedArrayLoader';
4
- import { TypedArray } from './typedArray';
5
- import { Class, WritableKeysOf } from 'type-fest';
6
1
  import { Data3DTexture, DataTexture, Loader } from 'three';
7
-
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';
8
7
  type ParameterProperties<T> = {
9
8
  [K in WritableKeysOf<T> as T[K] extends Callable ? never : K]: T[K];
10
9
  };
@@ -1,5 +1,4 @@
1
1
  import { Data3DTexture, Loader } from 'three';
2
-
3
2
  export declare class EXR3DLoader extends Loader<Data3DTexture> {
4
3
  depth?: number;
5
4
  setDepth(value: number): this;
@@ -1,6 +1,5 @@
1
- import { ProjectOnEllipsoidSurfaceOptions } from './helpers/projectOnEllipsoidSurface';
2
1
  import { Matrix4, Vector3, Ray } from 'three';
3
-
2
+ import { ProjectOnEllipsoidSurfaceOptions } from './helpers/projectOnEllipsoidSurface';
4
3
  export declare class Ellipsoid {
5
4
  static readonly WGS84: Ellipsoid;
6
5
  readonly radii: Vector3;
@@ -1,5 +1,4 @@
1
1
  import { BufferGeometry, Vector3 } from 'three';
2
-
3
2
  export interface EllipsoidGeometryParameters {
4
3
  radii: Vector3;
5
4
  longitudeSegments?: number;
@@ -1,7 +1,6 @@
1
- import { ProjectOnEllipsoidSurfaceOptions } from './helpers/projectOnEllipsoidSurface';
2
- import { Ellipsoid } from './Ellipsoid';
3
1
  import { Vector3 } from 'three';
4
-
2
+ import { Ellipsoid } from './Ellipsoid';
3
+ import { ProjectOnEllipsoidSurfaceOptions } from './helpers/projectOnEllipsoidSurface';
5
4
  export type GeodeticTuple = [number, number, number];
6
5
  export interface GeodeticLike {
7
6
  readonly longitude: number;
@@ -1,6 +1,5 @@
1
- import { Ellipsoid } from './Ellipsoid';
2
1
  import { Quaternion, Vector3, Camera } from 'three';
3
-
2
+ import { Ellipsoid } from './Ellipsoid';
4
3
  export declare class PointOfView {
5
4
  private _distance;
6
5
  heading: number;
@@ -1,5 +1,4 @@
1
1
  import { Geodetic } from './Geodetic';
2
-
3
2
  export type RectangleTuple = [number, number, number, number];
4
3
  export interface RectangleLike {
5
4
  readonly west: number;
@@ -1,5 +1,4 @@
1
1
  import { Data3DTexture, Loader } from 'three';
2
-
3
2
  export declare class Texture3DLoader extends Loader<Data3DTexture> {
4
3
  load(url: string, onLoad: (data: Data3DTexture) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
5
4
  }
@@ -1,8 +1,7 @@
1
- import { TileCoordinate, TileCoordinateLike } from './TileCoordinate';
2
- import { Rectangle, RectangleLike } from './Rectangle';
3
- import { GeodeticLike } from './Geodetic';
4
1
  import { Vector2 } from 'three';
5
-
2
+ import { GeodeticLike } from './Geodetic';
3
+ import { Rectangle, RectangleLike } from './Rectangle';
4
+ import { TileCoordinate, TileCoordinateLike } from './TileCoordinate';
6
5
  export interface TilingSchemeLike {
7
6
  readonly width: number;
8
7
  readonly height: number;
@@ -1,17 +1,10 @@
1
- import { TypedArrayParser } from './typedArrayParsers';
2
- import { TypedArray } from './typedArray';
3
- import { Class } from 'type-fest';
4
1
  import { Loader } from 'three';
5
-
2
+ import { Class } from 'type-fest';
3
+ import { TypedArray } from './typedArray';
4
+ import { TypedArrayParser } from './typedArrayParsers';
6
5
  export declare abstract class TypedArrayLoader<T extends TypedArray> extends Loader<T> {
7
6
  abstract parseTypedArray(buffer: ArrayBuffer): T;
8
7
  load(url: string, onLoad: (data: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (error: unknown) => void): void;
9
8
  }
10
9
  export declare function createTypedArrayLoaderClass<T extends TypedArray>(parser: TypedArrayParser<T>): Class<TypedArrayLoader<T>>;
11
10
  export declare function createTypedArrayLoader<T extends TypedArray>(parser: TypedArrayParser<T>): TypedArrayLoader<T>;
12
- /** @deprecated Use createTypedArrayLoaderClass instead. */
13
- export declare const Int16ArrayLoader: Class<TypedArrayLoader<Int16Array<ArrayBufferLike>>>;
14
- /** @deprecated Use createTypedArrayLoaderClass instead. */
15
- export declare const Uint16ArrayLoader: Class<TypedArrayLoader<Uint16Array<ArrayBufferLike>>>;
16
- /** @deprecated Use createTypedArrayLoaderClass instead. */
17
- export declare const Float32ArrayLoader: Class<TypedArrayLoader<Float32Array<ArrayBufferLike>>>;
@@ -1,6 +1,23 @@
1
- import { BufferGeometry } from 'three';
2
-
3
- export interface BufferGeometryLike extends Pick<BufferGeometry, 'attributes' | 'index' | 'boundingBox' | 'boundingSphere'> {
1
+ import { BufferGeometry, TypedArray, Vector3Like } from 'three';
2
+ export interface BufferGeometryLike {
3
+ attributes: Record<string, {
4
+ array: TypedArray;
5
+ itemSize: number;
6
+ normalized?: boolean;
7
+ }>;
8
+ index?: {
9
+ array: TypedArray;
10
+ itemSize: number;
11
+ normalized?: boolean;
12
+ } | null;
13
+ boundingBox?: {
14
+ min: Vector3Like;
15
+ max: Vector3Like;
16
+ } | null;
17
+ boundingSphere?: {
18
+ center: Vector3Like;
19
+ radius: number;
20
+ } | null;
4
21
  }
5
22
  export declare function toBufferGeometryLike(geometry: BufferGeometry): [BufferGeometryLike, ArrayBuffer[]];
6
23
  export declare function fromBufferGeometryLike(input: BufferGeometryLike, result?: BufferGeometry<import('three').NormalBufferAttributes>): BufferGeometry;
@@ -1,5 +1,4 @@
1
1
  import { Material } from 'three';
2
-
3
2
  interface EffectLike {
4
3
  defines: Map<string, string>;
5
4
  }
@@ -1,5 +1,4 @@
1
1
  import { Uniform } from 'three';
2
-
3
2
  export type PropertyShorthand<Args extends readonly unknown[]> = Args extends readonly [infer T, infer K, ...infer Rest] ? K extends readonly string[] ? K[number] extends keyof T ? Rest extends readonly unknown[] ? {
4
3
  [P in K[number]]: T[P];
5
4
  } & PropertyShorthand<Rest> : {
@@ -1,5 +1,4 @@
1
1
  import { Vector3 } from 'three';
2
-
3
2
  export interface ProjectOnEllipsoidSurfaceOptions {
4
3
  centerTolerance?: number;
5
4
  }
@@ -1,9 +1,8 @@
1
- import { GeodeticLike } from '../Geodetic';
2
- import { Ellipsoid } from '../Ellipsoid';
3
- import { SetOptional } from 'type-fest';
4
- import { Group } from 'three';
5
1
  import { ReactNode } from 'react';
6
-
2
+ import { Group } from 'three';
3
+ import { SetOptional } from 'type-fest';
4
+ import { Ellipsoid } from '../Ellipsoid';
5
+ import { GeodeticLike } from '../Geodetic';
7
6
  declare class EastNorthUpFrameGroup extends Group {
8
7
  set(longitude: number, latitude: number, height: number, ellipsoid?: Ellipsoid): void;
9
8
  }
@@ -1,13 +1,12 @@
1
- import { EllipsoidGeometry } from '../EllipsoidGeometry';
1
+ import { ElementProps, ThreeElement } from '@react-three/fiber';
2
2
  import { Mesh } from 'three';
3
- import { BufferGeometryNode, MeshProps } from '@react-three/fiber';
4
-
3
+ import { EllipsoidGeometry } from '../EllipsoidGeometry';
5
4
  declare module '@react-three/fiber' {
6
5
  interface ThreeElements {
7
- ellipsoidGeometry: BufferGeometryNode<EllipsoidGeometry, typeof EllipsoidGeometry>;
6
+ ellipsoidGeometry: ThreeElement<typeof EllipsoidGeometry>;
8
7
  }
9
8
  }
10
- export interface EllipsoidMeshProps extends Omit<MeshProps, 'args'> {
9
+ export interface EllipsoidMeshProps extends Omit<ElementProps<typeof Mesh>, 'args'> {
11
10
  args?: ConstructorParameters<typeof EllipsoidGeometry>;
12
11
  }
13
12
  export declare const EllipsoidMesh: import('react').ForwardRefExoticComponent<Omit<EllipsoidMeshProps, "ref"> & import('react').RefAttributes<Mesh<import('three').BufferGeometry<import('three').NormalBufferAttributes>, import('three').Material | import('three').Material[], import('three').Object3DEventMap>>>;
@@ -1,21 +1,7 @@
1
- import { Callable } from '../types';
2
- import { WritableKeysOf } from 'type-fest';
3
- import { Color as ColorImpl, Vector2 as Vector2Impl, Vector3 as Vector3Impl, Vector4 as Vector4Impl } from 'three';
4
- import { NodeProps, Overwrite, Color as R3FColor, Vector2 as R3FVector2, Vector3 as R3FVector3, Vector4 as R3FVector4 } from '@react-three/fiber';
5
-
6
- export type ExtendedProps<T> = {
7
- [K in keyof T]: Vector2Impl extends T[K] ? R3FVector2 | T[K] : Vector3Impl extends T[K] ? R3FVector3 | T[K] : Vector4Impl extends T[K] ? R3FVector4 | T[K] : ColorImpl extends T[K] ? R3FColor | T[K] : T[K];
1
+ import { MathType, MathTypes } from '@react-three/fiber';
2
+ export type OverwriteMathProps<T> = {
3
+ [K in keyof T]: Exclude<T[K], undefined> extends MathTypes ? T[K] extends undefined ? MathType<Exclude<T[K], undefined>> | undefined : MathType<Exclude<T[K], undefined>> : T[K];
8
4
  };
9
- type NonFunctionKeys<T> = keyof {
10
- [K in keyof T as Callable extends T[K] ? never : K]: any;
11
- };
12
- type WritableNonExtendableKeysOf<T> = WritableKeysOf<T> | keyof {
13
- [K in keyof T as Vector2Impl extends T[K] ? K : Vector3Impl extends T[K] ? K : Vector4Impl extends T[K] ? K : ColorImpl extends T[K] ? K : never]: any;
14
- };
15
- export type PassThoughInstanceProps<RefType, Args extends readonly any[], Props> = Overwrite<ExtendedProps<{
16
- [K in NonFunctionKeys<Props> as K extends WritableNonExtendableKeysOf<Props> ? K : never]: Props[K];
17
- }>, NodeProps<RefType, Args>>;
18
5
  export type ExpandNestedProps<T, Prop extends keyof T & string> = {
19
6
  [K in keyof NonNullable<T[Prop]> as K extends string ? `${Prop}-${K}` : 'never']: NonNullable<T[Prop]>[K];
20
7
  };
21
- export {};
@@ -1,10 +1,5 @@
1
1
  import { Float16Array, Float16ArrayConstructor } from '@petamoriken/float16';
2
-
3
2
  export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float16Array | Float32Array | Float64Array;
4
3
  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 */
8
- export declare function getTypedArrayElementType(array: TypedArray): TypedArrayElementType;
9
4
  export declare function isTypedArray(value: unknown): value is TypedArray;
10
5
  export { Float16Array };
@@ -1,6 +1,5 @@
1
- import { TypedArray } from './typedArray';
2
1
  import { Float16Array } from '@petamoriken/float16';
3
-
2
+ import { TypedArray } from './typedArray';
4
3
  export type TypedArrayParser<T extends TypedArray> = (buffer: ArrayBuffer, littleEndian?: boolean) => T;
5
4
  export declare const parseUint8Array: TypedArrayParser<Uint8Array>;
6
5
  export declare const parseInt8Array: TypedArrayParser<Int8Array>;
package/types/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Uniform } from 'three';
2
-
3
2
  export type Callable = (...args: any) => any;
4
3
  export type UniformMap<T> = Omit<Map<string, Uniform>, 'get'> & {
5
4
  get: <K extends keyof T>(key: K) => T[K];