@takram/three-geospatial 0.0.1-alpha.6 → 0.0.1-alpha.7
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/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.js +295 -236
- package/build/index.js.map +1 -1
- package/build/r3f.js +2 -2
- package/build/shaders.cjs +144 -23
- package/build/shaders.cjs.map +1 -1
- package/build/shaders.js +153 -31
- package/build/shaders.js.map +1 -1
- package/package.json +1 -1
- package/src/STBNLoader.ts +21 -0
- package/src/constants.ts +3 -0
- package/src/defineShorthand.ts +68 -0
- package/src/index.ts +2 -0
- package/src/math.ts +36 -1
- package/src/r3f/types.ts +11 -12
- package/src/shaders/cascadedShadowMaps.glsl +79 -0
- package/src/shaders/index.ts +2 -0
- package/src/shaders/math.glsl +56 -16
- package/src/shaders/poissonDisk.glsl +2 -0
- package/src/typedArrayParsers.ts +19 -8
- package/types/STBNLoader.d.ts +1 -0
- package/types/constants.d.ts +1 -0
- package/types/defineShorthand.d.ts +16 -0
- package/types/index.d.ts +2 -0
- package/types/math.d.ts +4 -1
- package/types/r3f/types.d.ts +5 -6
- package/types/shaders/index.d.ts +1 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
import { type Uniform } from 'three'
|
2
|
+
|
3
|
+
// TODO: Make mutable value types (e.g. vectors, matrices) read-only.
|
4
|
+
|
5
|
+
// Maps argument of type [T1, K1[], T2, K2[], ...] to:
|
6
|
+
// { [K in K1]: T1[K],
|
7
|
+
// [K in K2]: T2[K], ... }
|
8
|
+
export type PropertyShorthand<Args extends readonly unknown[]> =
|
9
|
+
Args extends readonly [infer T, infer K, ...infer Rest]
|
10
|
+
? K extends readonly string[]
|
11
|
+
? K[number] extends keyof T
|
12
|
+
? Rest extends readonly unknown[]
|
13
|
+
? { [P in K[number]]: T[P] } & PropertyShorthand<Rest>
|
14
|
+
: { [P in K[number]]: T[P] }
|
15
|
+
: never // K must be keyof T
|
16
|
+
: never // K must be an array
|
17
|
+
: {} // Termination
|
18
|
+
|
19
|
+
export function definePropertyShorthand<T, Args extends readonly unknown[]>(
|
20
|
+
destination: T,
|
21
|
+
...sourceKeysArgs: [...Args]
|
22
|
+
): T & PropertyShorthand<Args> {
|
23
|
+
const descriptors: PropertyDescriptorMap = {}
|
24
|
+
for (let i = 0; i < sourceKeysArgs.length; i += 2) {
|
25
|
+
const source = sourceKeysArgs[i]
|
26
|
+
const keys = sourceKeysArgs[i + 1] as ReadonlyArray<keyof typeof source>
|
27
|
+
for (const key of keys) {
|
28
|
+
descriptors[key] = {
|
29
|
+
enumerable: true,
|
30
|
+
get: () => source[key],
|
31
|
+
set: (value: any) => {
|
32
|
+
source[key] = value
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
Object.defineProperties(destination, descriptors)
|
38
|
+
return destination as T & PropertyShorthand<Args>
|
39
|
+
}
|
40
|
+
|
41
|
+
// The argument of defineUniformShorthand can also be variadic, but I can't
|
42
|
+
// think of any practical use cases for it.
|
43
|
+
|
44
|
+
export type UniformShorthand<
|
45
|
+
T extends { uniforms: Record<K, Uniform> },
|
46
|
+
K extends keyof T['uniforms']
|
47
|
+
> = {
|
48
|
+
[P in K]: T['uniforms'][P] extends Uniform<infer U> ? U : never
|
49
|
+
}
|
50
|
+
|
51
|
+
export function defineUniformShorthand<
|
52
|
+
T,
|
53
|
+
S extends { uniforms: Record<K, Uniform> },
|
54
|
+
K extends keyof S['uniforms']
|
55
|
+
>(destination: T, source: S, keys: readonly K[]): T & UniformShorthand<S, K> {
|
56
|
+
const descriptors: PropertyDescriptorMap = {}
|
57
|
+
for (const key of keys) {
|
58
|
+
descriptors[key] = {
|
59
|
+
enumerable: true,
|
60
|
+
get: () => source.uniforms[key].value,
|
61
|
+
set: (value: S['uniforms'][K]) => {
|
62
|
+
source.uniforms[key].value = value
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
Object.defineProperties(destination, descriptors)
|
67
|
+
return destination as T & UniformShorthand<S, K>
|
68
|
+
}
|
package/src/index.ts
CHANGED
@@ -3,6 +3,7 @@ export * from './assertions'
|
|
3
3
|
export * from './bufferGeometry'
|
4
4
|
export * from './constants'
|
5
5
|
export * from './DataLoader'
|
6
|
+
export * from './defineShorthand'
|
6
7
|
export * from './Ellipsoid'
|
7
8
|
export * from './EllipsoidGeometry'
|
8
9
|
export * from './Geodetic'
|
@@ -10,6 +11,7 @@ export * from './math'
|
|
10
11
|
export * from './PointOfView'
|
11
12
|
export * from './Rectangle'
|
12
13
|
export * from './resolveIncludes'
|
14
|
+
export * from './STBNLoader'
|
13
15
|
export * from './TileCoordinate'
|
14
16
|
export * from './TilingScheme'
|
15
17
|
export * from './typedArray'
|
package/src/math.ts
CHANGED
@@ -10,7 +10,42 @@ export const isPowerOfTwo = MathUtils.isPowerOfTwo
|
|
10
10
|
export const ceilPowerOfTwo = MathUtils.ceilPowerOfTwo
|
11
11
|
export const floorPowerOfTwo = MathUtils.floorPowerOfTwo
|
12
12
|
export const normalize = MathUtils.normalize
|
13
|
-
|
13
|
+
|
14
|
+
export function remap(x: number, min1: number, max1: number): number
|
15
|
+
export function remap(
|
16
|
+
x: number,
|
17
|
+
min1: number,
|
18
|
+
max1: number,
|
19
|
+
min2: number,
|
20
|
+
max2: number
|
21
|
+
): number
|
22
|
+
export function remap(
|
23
|
+
x: number,
|
24
|
+
min1: number,
|
25
|
+
max1: number,
|
26
|
+
min2 = 0,
|
27
|
+
max2 = 1
|
28
|
+
): number {
|
29
|
+
return MathUtils.mapLinear(x, min1, max1, min2, max2)
|
30
|
+
}
|
31
|
+
|
32
|
+
export function remapClamped(x: number, min1: number, max1: number): number
|
33
|
+
export function remapClamped(
|
34
|
+
x: number,
|
35
|
+
min1: number,
|
36
|
+
max1: number,
|
37
|
+
min2: number,
|
38
|
+
max2: number
|
39
|
+
): number
|
40
|
+
export function remapClamped(
|
41
|
+
x: number,
|
42
|
+
min1: number,
|
43
|
+
max1: number,
|
44
|
+
min2 = 0,
|
45
|
+
max2 = 1
|
46
|
+
): number {
|
47
|
+
return clamp(MathUtils.mapLinear(x, min1, max1, min2, max2), min2, max2)
|
48
|
+
}
|
14
49
|
|
15
50
|
// Prefer glsl's argument order which differs from that of MathUtils.
|
16
51
|
export function smoothstep(min: number, max: number, x: number): number {
|
package/src/r3f/types.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import {
|
2
|
-
type Color,
|
3
|
-
type ExtendedColors,
|
4
2
|
type NodeProps,
|
5
3
|
type Overwrite,
|
6
|
-
type
|
7
|
-
type
|
8
|
-
type
|
4
|
+
type Color as R3FColor,
|
5
|
+
type Vector2 as R3FVector2,
|
6
|
+
type Vector3 as R3FVector3,
|
7
|
+
type Vector4 as R3FVector4
|
9
8
|
} from '@react-three/fiber'
|
10
9
|
import {
|
10
|
+
type Color as ColorImpl,
|
11
11
|
type Vector2 as Vector2Impl,
|
12
12
|
type Vector3 as Vector3Impl,
|
13
13
|
type Vector4 as Vector4Impl
|
@@ -17,16 +17,15 @@ import { type WritableKeysOf } from 'type-fest'
|
|
17
17
|
import { type Callable } from '../types'
|
18
18
|
|
19
19
|
// prettier-ignore
|
20
|
-
export type
|
20
|
+
export type ExtendedProps<T> = {
|
21
21
|
[K in keyof T]:
|
22
|
-
Vector2Impl extends T[K] ?
|
23
|
-
Vector3Impl extends T[K] ?
|
24
|
-
Vector4Impl extends T[K] ?
|
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] :
|
25
26
|
T[K]
|
26
27
|
}
|
27
28
|
|
28
|
-
export type ExtendedProps<T> = ExtendedColors<ExtendedVectors<T>>
|
29
|
-
|
30
29
|
// @react-three/fiber's NonFunctionKeys cannot exclude partial functions.
|
31
30
|
// This excludes callback properties, which may be undesirable behavior.
|
32
31
|
type NonFunctionKeys<T> = keyof {
|
@@ -41,7 +40,7 @@ type WritableNonExtendableKeysOf<T> =
|
|
41
40
|
Vector2Impl extends T[K] ? K :
|
42
41
|
Vector3Impl extends T[K] ? K :
|
43
42
|
Vector4Impl extends T[K] ? K :
|
44
|
-
|
43
|
+
ColorImpl extends T[K] ? K :
|
45
44
|
never
|
46
45
|
]: any
|
47
46
|
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// Reference: https://github.com/mrdoob/three.js/blob/r171/examples/jsm/csm/CSMShader.js
|
2
|
+
|
3
|
+
#ifndef SHADOW_CASCADE_COUNT
|
4
|
+
#error "SHADOW_CASCADE_COUNT macro must be defined."
|
5
|
+
#endif // SHADOW_CASCADE_COUNT
|
6
|
+
|
7
|
+
int getCascadeIndex(
|
8
|
+
const mat4 viewMatrix,
|
9
|
+
const vec3 worldPosition,
|
10
|
+
const vec2 intervals[SHADOW_CASCADE_COUNT],
|
11
|
+
const float near,
|
12
|
+
const float far
|
13
|
+
) {
|
14
|
+
vec4 viewPosition = viewMatrix * vec4(worldPosition, 1.0);
|
15
|
+
float depth = viewZToOrthographicDepth(viewPosition.z, near, far);
|
16
|
+
vec2 interval;
|
17
|
+
#pragma unroll_loop_start
|
18
|
+
for (int i = 0; i < 4; ++i) {
|
19
|
+
#if UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT
|
20
|
+
interval = intervals[i];
|
21
|
+
if (depth >= interval.x && depth < interval.y) {
|
22
|
+
return UNROLLED_LOOP_INDEX;
|
23
|
+
}
|
24
|
+
#endif // UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT
|
25
|
+
}
|
26
|
+
#pragma unroll_loop_end
|
27
|
+
return SHADOW_CASCADE_COUNT - 1;
|
28
|
+
}
|
29
|
+
|
30
|
+
int getFadedCascadeIndex(
|
31
|
+
const mat4 viewMatrix,
|
32
|
+
const vec3 worldPosition,
|
33
|
+
const vec2 intervals[SHADOW_CASCADE_COUNT],
|
34
|
+
const float near,
|
35
|
+
const float far,
|
36
|
+
const float jitter
|
37
|
+
) {
|
38
|
+
vec4 viewPosition = viewMatrix * vec4(worldPosition, 1.0);
|
39
|
+
float depth = viewZToOrthographicDepth(viewPosition.z, near, far);
|
40
|
+
|
41
|
+
vec2 interval;
|
42
|
+
float intervalCenter;
|
43
|
+
float closestEdge;
|
44
|
+
float margin;
|
45
|
+
int nextIndex = -1;
|
46
|
+
int prevIndex = -1;
|
47
|
+
float alpha;
|
48
|
+
|
49
|
+
#pragma unroll_loop_start
|
50
|
+
for (int i = 0; i < 4; ++i) {
|
51
|
+
#if UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT
|
52
|
+
interval = intervals[i];
|
53
|
+
intervalCenter = (interval.x + interval.y) * 0.5;
|
54
|
+
closestEdge = depth < intervalCenter ? interval.x : interval.y;
|
55
|
+
margin = closestEdge * closestEdge * 0.5;
|
56
|
+
interval += margin * vec2(-0.5, 0.5);
|
57
|
+
|
58
|
+
#if UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT - 1
|
59
|
+
if (depth >= interval.x && depth < interval.y) {
|
60
|
+
prevIndex = nextIndex;
|
61
|
+
nextIndex = UNROLLED_LOOP_INDEX;
|
62
|
+
alpha = saturate(min(depth - interval.x, interval.y - depth) / margin);
|
63
|
+
}
|
64
|
+
#else // UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT - 1
|
65
|
+
// Don't fade out the last cascade.
|
66
|
+
if (depth >= interval.x) {
|
67
|
+
prevIndex = nextIndex;
|
68
|
+
nextIndex = UNROLLED_LOOP_INDEX;
|
69
|
+
alpha = saturate((depth - interval.x) / margin);
|
70
|
+
}
|
71
|
+
#endif // UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT - 1
|
72
|
+
#endif // UNROLLED_LOOP_INDEX < SHADOW_CASCADE_COUNT
|
73
|
+
}
|
74
|
+
#pragma unroll_loop_end
|
75
|
+
|
76
|
+
return jitter <= alpha
|
77
|
+
? nextIndex
|
78
|
+
: prevIndex;
|
79
|
+
}
|
package/src/shaders/index.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import _cascadedShadowMaps from './cascadedShadowMaps.glsl?raw'
|
1
2
|
import _depth from './depth.glsl?raw'
|
2
3
|
import _generators from './generators.glsl?raw'
|
3
4
|
import _math from './math.glsl?raw'
|
@@ -7,6 +8,7 @@ import _raySphereIntersection from './raySphereIntersection.glsl?raw'
|
|
7
8
|
import _transform from './transform.glsl?raw'
|
8
9
|
import _turbo from './turbo.glsl?raw'
|
9
10
|
|
11
|
+
export const cascadedShadowMaps: string = _cascadedShadowMaps
|
10
12
|
export const depth: string = _depth
|
11
13
|
export const generators: string = _generators
|
12
14
|
export const math: string = _math
|
package/src/shaders/math.glsl
CHANGED
@@ -2,22 +2,6 @@
|
|
2
2
|
#define saturate(a) clamp(a, 0.0, 1.0)
|
3
3
|
#endif // !defined(saturate)
|
4
4
|
|
5
|
-
float inverseLerp(const float x, const float y, const float a) {
|
6
|
-
return (a - x) / (y - x);
|
7
|
-
}
|
8
|
-
|
9
|
-
vec2 inverseLerp(const vec2 x, const vec2 y, const vec2 a) {
|
10
|
-
return (a - x) / (y - x);
|
11
|
-
}
|
12
|
-
|
13
|
-
vec3 inverseLerp(const vec3 x, const vec3 y, const vec3 a) {
|
14
|
-
return (a - x) / (y - x);
|
15
|
-
}
|
16
|
-
|
17
|
-
vec4 inverseLerp(const vec4 x, const vec4 y, const vec4 a) {
|
18
|
-
return (a - x) / (y - x);
|
19
|
-
}
|
20
|
-
|
21
5
|
float remap(const float x, const float min1, const float max1, const float min2, const float max2) {
|
22
6
|
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
23
7
|
}
|
@@ -34,6 +18,46 @@ vec4 remap(const vec4 x, const vec4 min1, const vec4 max1, const vec4 min2, cons
|
|
34
18
|
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
35
19
|
}
|
36
20
|
|
21
|
+
float remapClamped(
|
22
|
+
const float x,
|
23
|
+
const float min1,
|
24
|
+
const float max1,
|
25
|
+
const float min2,
|
26
|
+
const float max2
|
27
|
+
) {
|
28
|
+
return clamp(min2 + (x - min1) / (max1 - min1) * (max2 - min2), min2, max2);
|
29
|
+
}
|
30
|
+
|
31
|
+
vec2 remapClamped(
|
32
|
+
const vec2 x,
|
33
|
+
const vec2 min1,
|
34
|
+
const vec2 max1,
|
35
|
+
const vec2 min2,
|
36
|
+
const vec2 max2
|
37
|
+
) {
|
38
|
+
return clamp(min2 + (x - min1) / (max1 - min1) * (max2 - min2), min2, max2);
|
39
|
+
}
|
40
|
+
|
41
|
+
vec3 remapClamped(
|
42
|
+
const vec3 x,
|
43
|
+
const vec3 min1,
|
44
|
+
const vec3 max1,
|
45
|
+
const vec3 min2,
|
46
|
+
const vec3 max2
|
47
|
+
) {
|
48
|
+
return clamp(min2 + (x - min1) / (max1 - min1) * (max2 - min2), min2, max2);
|
49
|
+
}
|
50
|
+
|
51
|
+
vec4 remapClamped(
|
52
|
+
const vec4 x,
|
53
|
+
const vec4 min1,
|
54
|
+
const vec4 max1,
|
55
|
+
const vec4 min2,
|
56
|
+
const vec4 max2
|
57
|
+
) {
|
58
|
+
return clamp(min2 + (x - min1) / (max1 - min1) * (max2 - min2), min2, max2);
|
59
|
+
}
|
60
|
+
|
37
61
|
// Implicitly remap to 0 and 1
|
38
62
|
float remap(const float x, const float min1, const float max1) {
|
39
63
|
return (x - min1) / (max1 - min1);
|
@@ -50,3 +74,19 @@ vec3 remap(const vec3 x, const vec3 min1, const vec3 max1) {
|
|
50
74
|
vec4 remap(const vec4 x, const vec4 min1, const vec4 max1) {
|
51
75
|
return (x - min1) / (max1 - min1);
|
52
76
|
}
|
77
|
+
|
78
|
+
float remapClamped(const float x, const float min1, const float max1) {
|
79
|
+
return saturate((x - min1) / (max1 - min1));
|
80
|
+
}
|
81
|
+
|
82
|
+
vec2 remapClamped(const vec2 x, const vec2 min1, const vec2 max1) {
|
83
|
+
return saturate((x - min1) / (max1 - min1));
|
84
|
+
}
|
85
|
+
|
86
|
+
vec3 remapClamped(const vec3 x, const vec3 min1, const vec3 max1) {
|
87
|
+
return saturate((x - min1) / (max1 - min1));
|
88
|
+
}
|
89
|
+
|
90
|
+
vec4 remapClamped(const vec4 x, const vec4 min1, const vec4 max1) {
|
91
|
+
return saturate((x - min1) / (max1 - min1));
|
92
|
+
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
// TODO: Maybe switch to Vogel disk with IGN:
|
2
|
+
// https://www.gamedev.net/tutorials/programming/graphics/contact-hardening-soft-shadows-made-fast-r4906/
|
1
3
|
// Taken from: https://developer.download.nvidia.com/whitepapers/2008/PCSS_Integration.pdf
|
2
4
|
const vec2 poissonDisk[16] = vec2[16](
|
3
5
|
vec2(-0.94201624, -0.39906216),
|
package/src/typedArrayParsers.ts
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
import { type TypedArray, type TypedArrayConstructor } from './typedArray'
|
2
2
|
|
3
|
+
let hostLittleEndian: boolean | undefined
|
4
|
+
|
5
|
+
function isHostLittleEndian(): boolean {
|
6
|
+
if (hostLittleEndian != null) {
|
7
|
+
return hostLittleEndian
|
8
|
+
}
|
9
|
+
const a = new Uint32Array([0x10000000])
|
10
|
+
const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)
|
11
|
+
hostLittleEndian = b[0] === 0
|
12
|
+
return hostLittleEndian
|
13
|
+
}
|
14
|
+
|
3
15
|
type GetValue = keyof {
|
4
16
|
[K in keyof DataView as DataView[K] extends (byteOffset: number) => number
|
5
17
|
? K
|
@@ -19,6 +31,9 @@ function parseTypedArray<K extends GetValue>(
|
|
19
31
|
getValue: K,
|
20
32
|
littleEndian = true
|
21
33
|
): TypedArray {
|
34
|
+
if (littleEndian === isHostLittleEndian()) {
|
35
|
+
return new TypedArray(buffer)
|
36
|
+
}
|
22
37
|
const data = new DataView(buffer)
|
23
38
|
const array = new TypedArray(data.byteLength / TypedArray.BYTES_PER_ELEMENT)
|
24
39
|
for (
|
@@ -36,15 +51,11 @@ export type TypedArrayParser<T extends TypedArray> = (
|
|
36
51
|
littleEndian?: boolean
|
37
52
|
) => T
|
38
53
|
|
39
|
-
export const parseUint8Array: TypedArrayParser<Uint8Array> =
|
40
|
-
buffer
|
41
|
-
littleEndian
|
42
|
-
) => parseTypedArray(buffer, Uint8Array, 'getUint8', littleEndian)
|
54
|
+
export const parseUint8Array: TypedArrayParser<Uint8Array> = buffer =>
|
55
|
+
new Uint8Array(buffer)
|
43
56
|
|
44
|
-
export const parseInt8Array: TypedArrayParser<Int8Array> =
|
45
|
-
buffer
|
46
|
-
littleEndian
|
47
|
-
) => parseTypedArray(buffer, Int8Array, 'getInt8', littleEndian)
|
57
|
+
export const parseInt8Array: TypedArrayParser<Int8Array> = buffer =>
|
58
|
+
new Int8Array(buffer)
|
48
59
|
|
49
60
|
export const parseUint16Array: TypedArrayParser<Uint16Array> = (
|
50
61
|
buffer,
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const STBNLoader: import('type-fest').Class<import('./DataLoader').DataLoader<import('three').Data3DTexture, Uint8Array<ArrayBufferLike>>>;
|
package/types/constants.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare const STBN_TEXTURE_WIDTH = 128;
|
2
2
|
export declare const STBN_TEXTURE_HEIGHT = 128;
|
3
3
|
export declare const STBN_TEXTURE_DEPTH = 64;
|
4
|
+
export declare const DEFAULT_STBN_URL = "https://media.githubusercontent.com/media/takram-design-engineering/three-geospatial/9627216cc50057994c98a2118f3c4a23765d43b9/packages/core/assets/stbn.bin";
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Uniform } from 'three';
|
2
|
+
|
3
|
+
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
|
+
[P in K[number]]: T[P];
|
5
|
+
} & PropertyShorthand<Rest> : {
|
6
|
+
[P in K[number]]: T[P];
|
7
|
+
} : never : never : {};
|
8
|
+
export declare function definePropertyShorthand<T, Args extends readonly unknown[]>(destination: T, ...sourceKeysArgs: [...Args]): T & PropertyShorthand<Args>;
|
9
|
+
export type UniformShorthand<T extends {
|
10
|
+
uniforms: Record<K, Uniform>;
|
11
|
+
}, K extends keyof T['uniforms']> = {
|
12
|
+
[P in K]: T['uniforms'][P] extends Uniform<infer U> ? U : never;
|
13
|
+
};
|
14
|
+
export declare function defineUniformShorthand<T, S extends {
|
15
|
+
uniforms: Record<K, Uniform>;
|
16
|
+
}, K extends keyof S['uniforms']>(destination: T, source: S, keys: readonly K[]): T & UniformShorthand<S, K>;
|
package/types/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ export * from './assertions';
|
|
3
3
|
export * from './bufferGeometry';
|
4
4
|
export * from './constants';
|
5
5
|
export * from './DataLoader';
|
6
|
+
export * from './defineShorthand';
|
6
7
|
export * from './Ellipsoid';
|
7
8
|
export * from './EllipsoidGeometry';
|
8
9
|
export * from './Geodetic';
|
@@ -10,6 +11,7 @@ export * from './math';
|
|
10
11
|
export * from './PointOfView';
|
11
12
|
export * from './Rectangle';
|
12
13
|
export * from './resolveIncludes';
|
14
|
+
export * from './STBNLoader';
|
13
15
|
export * from './TileCoordinate';
|
14
16
|
export * from './TilingScheme';
|
15
17
|
export * from './typedArray';
|
package/types/math.d.ts
CHANGED
@@ -8,7 +8,10 @@ export declare const isPowerOfTwo: typeof import('three/src/math/MathUtils.js').
|
|
8
8
|
export declare const ceilPowerOfTwo: typeof import('three/src/math/MathUtils.js').ceilPowerOfTwo;
|
9
9
|
export declare const floorPowerOfTwo: typeof import('three/src/math/MathUtils.js').floorPowerOfTwo;
|
10
10
|
export declare const normalize: typeof import('three/src/math/MathUtils.js').normalize;
|
11
|
-
export declare
|
11
|
+
export declare function remap(x: number, min1: number, max1: number): number;
|
12
|
+
export declare function remap(x: number, min1: number, max1: number, min2: number, max2: number): number;
|
13
|
+
export declare function remapClamped(x: number, min1: number, max1: number): number;
|
14
|
+
export declare function remapClamped(x: number, min1: number, max1: number, min2: number, max2: number): number;
|
12
15
|
export declare function smoothstep(min: number, max: number, x: number): number;
|
13
16
|
export declare function saturate(x: number): number;
|
14
17
|
export declare function closeTo(a: number, b: number, relativeEpsilon: number, absoluteEpsilon?: number): boolean;
|
package/types/r3f/types.d.ts
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
import { Callable } from '../types';
|
2
2
|
import { WritableKeysOf } from 'type-fest';
|
3
|
-
import { Vector2 as Vector2Impl, Vector3 as Vector3Impl, Vector4 as Vector4Impl } from 'three';
|
4
|
-
import {
|
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
5
|
|
6
|
-
export type
|
7
|
-
[K in keyof T]: Vector2Impl extends T[K] ?
|
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];
|
8
8
|
};
|
9
|
-
export type ExtendedProps<T> = ExtendedColors<ExtendedVectors<T>>;
|
10
9
|
type NonFunctionKeys<T> = keyof {
|
11
10
|
[K in keyof T as Callable extends T[K] ? never : K]: any;
|
12
11
|
};
|
13
12
|
type WritableNonExtendableKeysOf<T> = WritableKeysOf<T> | keyof {
|
14
|
-
[K in keyof T as Vector2Impl extends T[K] ? K : Vector3Impl extends T[K] ? K : Vector4Impl extends T[K] ? K :
|
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;
|
15
14
|
};
|
16
15
|
export type PassThoughInstanceProps<RefType, Args extends readonly any[], Props> = Overwrite<ExtendedProps<{
|
17
16
|
[K in NonFunctionKeys<Props> as K extends WritableNonExtendableKeysOf<Props> ? K : never]: Props[K];
|
package/types/shaders/index.d.ts
CHANGED