@takram/three-geospatial 0.0.1-alpha.5 → 0.0.1-alpha.6
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 -43
- package/build/index.cjs.map +1 -1
- package/build/index.js +328 -771
- package/build/index.js.map +1 -1
- package/build/shaders.cjs +276 -0
- package/build/shaders.cjs.map +1 -0
- package/build/shaders.js +286 -0
- package/build/shaders.js.map +1 -0
- package/package.json +7 -3
- package/src/DataLoader.ts +1 -0
- package/src/Texture3DLoader.ts +81 -0
- package/src/bufferGeometry.ts +2 -2
- package/src/constants.ts +3 -0
- package/src/index.ts +3 -10
- package/src/r3f/index.ts +1 -0
- package/src/r3f/types.ts +64 -0
- package/src/resolveIncludes.test.ts +21 -0
- package/src/resolveIncludes.ts +22 -0
- package/src/shaders/depth.glsl +3 -1
- package/src/shaders/generators.glsl +9 -0
- package/src/shaders/index.ts +17 -0
- package/src/shaders/math.glsl +52 -0
- package/src/shaders/poissonDisk.glsl +21 -0
- package/src/shaders/raySphereIntersection.glsl +134 -0
- package/src/shaders/turbo.glsl +9 -0
- package/src/types.ts +5 -51
- package/src/unrollLoops.ts +23 -0
- package/types/DataLoader.d.ts +4 -4
- package/types/Texture3DLoader.d.ts +5 -0
- package/types/TypedArrayLoader.d.ts +3 -3
- package/types/constants.d.ts +3 -0
- package/types/index.d.ts +3 -3
- package/types/r3f/index.d.ts +1 -0
- package/types/r3f/types.d.ts +22 -0
- package/types/resolveIncludes.d.ts +5 -0
- package/types/shaders/index.d.ts +8 -0
- package/types/types.d.ts +5 -20
- package/types/unrollLoops.d.ts +1 -0
package/build/shaders.js
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
const n = `// cSpell:words logdepthbuf
|
2
|
+
|
3
|
+
float reverseLogDepth(const float depth, const float near, const float far) {
|
4
|
+
#ifdef USE_LOGDEPTHBUF
|
5
|
+
float d = pow(2.0, depth * log2(far + 1.0)) - 1.0;
|
6
|
+
float a = far / (far - near);
|
7
|
+
float b = far * near / (near - far);
|
8
|
+
return a + b / d;
|
9
|
+
#else // USE_LOGDEPTHBUF
|
10
|
+
return depth;
|
11
|
+
#endif // USE_LOGDEPTHBUF
|
12
|
+
}
|
13
|
+
|
14
|
+
float linearizeDepth(const float depth, const float near, const float far) {
|
15
|
+
float ndc = depth * 2.0 - 1.0;
|
16
|
+
return 2.0 * near * far / (far + near - ndc * (far - near));
|
17
|
+
}
|
18
|
+
`, e = `float checker(const vec2 uv, const vec2 repeats) {
|
19
|
+
vec2 c = floor(repeats * uv);
|
20
|
+
float result = mod(c.x + c.y, 2.0);
|
21
|
+
return sign(result);
|
22
|
+
}
|
23
|
+
|
24
|
+
float checker(const vec2 uv, const float repeats) {
|
25
|
+
return checker(uv, vec2(repeats));
|
26
|
+
}
|
27
|
+
`, t = `#if !defined(saturate)
|
28
|
+
#define saturate(a) clamp(a, 0.0, 1.0)
|
29
|
+
#endif // !defined(saturate)
|
30
|
+
|
31
|
+
float inverseLerp(const float x, const float y, const float a) {
|
32
|
+
return (a - x) / (y - x);
|
33
|
+
}
|
34
|
+
|
35
|
+
vec2 inverseLerp(const vec2 x, const vec2 y, const vec2 a) {
|
36
|
+
return (a - x) / (y - x);
|
37
|
+
}
|
38
|
+
|
39
|
+
vec3 inverseLerp(const vec3 x, const vec3 y, const vec3 a) {
|
40
|
+
return (a - x) / (y - x);
|
41
|
+
}
|
42
|
+
|
43
|
+
vec4 inverseLerp(const vec4 x, const vec4 y, const vec4 a) {
|
44
|
+
return (a - x) / (y - x);
|
45
|
+
}
|
46
|
+
|
47
|
+
float remap(const float x, const float min1, const float max1, const float min2, const float max2) {
|
48
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
49
|
+
}
|
50
|
+
|
51
|
+
vec2 remap(const vec2 x, const vec2 min1, const vec2 max1, const vec2 min2, const vec2 max2) {
|
52
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
53
|
+
}
|
54
|
+
|
55
|
+
vec3 remap(const vec3 x, const vec3 min1, const vec3 max1, const vec3 min2, const vec3 max2) {
|
56
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
57
|
+
}
|
58
|
+
|
59
|
+
vec4 remap(const vec4 x, const vec4 min1, const vec4 max1, const vec4 min2, const vec4 max2) {
|
60
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
61
|
+
}
|
62
|
+
|
63
|
+
// Implicitly remap to 0 and 1
|
64
|
+
float remap(const float x, const float min1, const float max1) {
|
65
|
+
return (x - min1) / (max1 - min1);
|
66
|
+
}
|
67
|
+
|
68
|
+
vec2 remap(const vec2 x, const vec2 min1, const vec2 max1) {
|
69
|
+
return (x - min1) / (max1 - min1);
|
70
|
+
}
|
71
|
+
|
72
|
+
vec3 remap(const vec3 x, const vec3 min1, const vec3 max1) {
|
73
|
+
return (x - min1) / (max1 - min1);
|
74
|
+
}
|
75
|
+
|
76
|
+
vec4 remap(const vec4 x, const vec4 min1, const vec4 max1) {
|
77
|
+
return (x - min1) / (max1 - min1);
|
78
|
+
}
|
79
|
+
`, c = `// Reference: https://jcgt.org/published/0003/02/01/paper.pdf
|
80
|
+
|
81
|
+
vec2 signNotZero(vec2 v) {
|
82
|
+
return vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);
|
83
|
+
}
|
84
|
+
|
85
|
+
vec2 packNormalToVec2(vec3 v) {
|
86
|
+
vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));
|
87
|
+
return v.z <= 0.0
|
88
|
+
? (1.0 - abs(p.yx)) * signNotZero(p)
|
89
|
+
: p;
|
90
|
+
}
|
91
|
+
|
92
|
+
vec3 unpackVec2ToNormal(vec2 e) {
|
93
|
+
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
|
94
|
+
if (v.z < 0.0) {
|
95
|
+
v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
|
96
|
+
}
|
97
|
+
return normalize(v);
|
98
|
+
}
|
99
|
+
`, o = `// Taken from: https://developer.download.nvidia.com/whitepapers/2008/PCSS_Integration.pdf
|
100
|
+
const vec2 poissonDisk[16] = vec2[16](
|
101
|
+
vec2(-0.94201624, -0.39906216),
|
102
|
+
vec2(0.94558609, -0.76890725),
|
103
|
+
vec2(-0.094184101, -0.9293887),
|
104
|
+
vec2(0.34495938, 0.2938776),
|
105
|
+
vec2(-0.91588581, 0.45771432),
|
106
|
+
vec2(-0.81544232, -0.87912464),
|
107
|
+
vec2(-0.38277543, 0.27676845),
|
108
|
+
vec2(0.97484398, 0.75648379),
|
109
|
+
vec2(0.44323325, -0.97511554),
|
110
|
+
vec2(0.53742981, -0.4737342),
|
111
|
+
vec2(-0.26496911, -0.41893023),
|
112
|
+
vec2(0.79197514, 0.19090188),
|
113
|
+
vec2(-0.2418884, 0.99706507),
|
114
|
+
vec2(-0.81409955, 0.9143759),
|
115
|
+
vec2(0.19984126, 0.78641367),
|
116
|
+
vec2(0.14383161, -0.1410079)
|
117
|
+
);
|
118
|
+
|
119
|
+
#define POISSON_DISK_COUNT (16)
|
120
|
+
`, r = `float raySphereFirstIntersection(
|
121
|
+
const vec3 origin,
|
122
|
+
const vec3 direction,
|
123
|
+
const vec3 center,
|
124
|
+
const float radius
|
125
|
+
) {
|
126
|
+
vec3 a = origin - center;
|
127
|
+
float b = 2.0 * dot(direction, a);
|
128
|
+
float c = dot(a, a) - radius * radius;
|
129
|
+
float discriminant = b * b - 4.0 * c;
|
130
|
+
return discriminant < 0.0
|
131
|
+
? -1.0
|
132
|
+
: (-b - sqrt(discriminant)) * 0.5;
|
133
|
+
}
|
134
|
+
|
135
|
+
float raySphereFirstIntersection(const vec3 origin, const vec3 direction, const float radius) {
|
136
|
+
return raySphereFirstIntersection(origin, direction, vec3(0.0), radius);
|
137
|
+
}
|
138
|
+
|
139
|
+
vec4 raySphereFirstIntersection(
|
140
|
+
const vec3 origin,
|
141
|
+
const vec3 direction,
|
142
|
+
const vec3 center,
|
143
|
+
const vec4 radius
|
144
|
+
) {
|
145
|
+
vec3 a = origin - center;
|
146
|
+
float b = 2.0 * dot(direction, a);
|
147
|
+
vec4 c = dot(a, a) - radius * radius;
|
148
|
+
vec4 discriminant = b * b - 4.0 * c;
|
149
|
+
vec4 mask = step(discriminant, vec4(0.0));
|
150
|
+
return mix((-b - sqrt(max(vec4(0.0), discriminant))) * 0.5, vec4(-1.0), mask);
|
151
|
+
}
|
152
|
+
|
153
|
+
vec4 raySphereFirstIntersection(const vec3 origin, const vec3 direction, const vec4 radius) {
|
154
|
+
return raySphereFirstIntersection(origin, direction, vec3(0.0), radius);
|
155
|
+
}
|
156
|
+
|
157
|
+
float raySphereSecondIntersection(
|
158
|
+
const vec3 origin,
|
159
|
+
const vec3 direction,
|
160
|
+
const vec3 center,
|
161
|
+
const float radius
|
162
|
+
) {
|
163
|
+
vec3 a = origin - center;
|
164
|
+
float b = 2.0 * dot(direction, a);
|
165
|
+
float c = dot(a, a) - radius * radius;
|
166
|
+
float discriminant = b * b - 4.0 * c;
|
167
|
+
return discriminant < 0.0
|
168
|
+
? -1.0
|
169
|
+
: (-b + sqrt(discriminant)) * 0.5;
|
170
|
+
}
|
171
|
+
|
172
|
+
float raySphereSecondIntersection(const vec3 origin, const vec3 direction, const float radius) {
|
173
|
+
return raySphereSecondIntersection(origin, direction, vec3(0.0), radius);
|
174
|
+
}
|
175
|
+
|
176
|
+
vec4 raySphereSecondIntersection(
|
177
|
+
const vec3 origin,
|
178
|
+
const vec3 direction,
|
179
|
+
const vec3 center,
|
180
|
+
const vec4 radius
|
181
|
+
) {
|
182
|
+
vec3 a = origin - center;
|
183
|
+
float b = 2.0 * dot(direction, a);
|
184
|
+
vec4 c = dot(a, a) - radius * radius;
|
185
|
+
vec4 discriminant = b * b - 4.0 * c;
|
186
|
+
vec4 mask = step(discriminant, vec4(0.0));
|
187
|
+
return mix((-b + sqrt(max(vec4(0.0), discriminant))) * 0.5, vec4(-1.0), mask);
|
188
|
+
}
|
189
|
+
|
190
|
+
vec4 raySphereSecondIntersection(const vec3 origin, const vec3 direction, const vec4 radius) {
|
191
|
+
return raySphereSecondIntersection(origin, direction, vec3(0.0), radius);
|
192
|
+
}
|
193
|
+
|
194
|
+
void raySphereIntersections(
|
195
|
+
const vec3 origin,
|
196
|
+
const vec3 direction,
|
197
|
+
const vec3 center,
|
198
|
+
const float radius,
|
199
|
+
out float intersection1,
|
200
|
+
out float intersection2
|
201
|
+
) {
|
202
|
+
vec3 a = origin - center;
|
203
|
+
float b = 2.0 * dot(direction, a);
|
204
|
+
float c = dot(a, a) - radius * radius;
|
205
|
+
float discriminant = b * b - 4.0 * c;
|
206
|
+
if (discriminant < 0.0) {
|
207
|
+
intersection1 = -1.0;
|
208
|
+
intersection2 = -1.0;
|
209
|
+
return;
|
210
|
+
} else {
|
211
|
+
float Q = sqrt(discriminant);
|
212
|
+
intersection1 = (-b - Q) * 0.5;
|
213
|
+
intersection2 = (-b + Q) * 0.5;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
void raySphereIntersections(
|
218
|
+
const vec3 origin,
|
219
|
+
const vec3 direction,
|
220
|
+
const float radius,
|
221
|
+
out float intersection1,
|
222
|
+
out float intersection2
|
223
|
+
) {
|
224
|
+
raySphereIntersections(origin, direction, vec3(0.0), radius, intersection1, intersection2);
|
225
|
+
}
|
226
|
+
|
227
|
+
void raySphereIntersections(
|
228
|
+
const vec3 origin,
|
229
|
+
const vec3 direction,
|
230
|
+
const vec3 center,
|
231
|
+
const vec4 radius,
|
232
|
+
out vec4 intersection1,
|
233
|
+
out vec4 intersection2
|
234
|
+
) {
|
235
|
+
vec3 a = origin - center;
|
236
|
+
float b = 2.0 * dot(direction, a);
|
237
|
+
vec4 c = dot(a, a) - radius * radius;
|
238
|
+
vec4 discriminant = b * b - 4.0 * c;
|
239
|
+
vec4 mask = step(discriminant, vec4(0.0));
|
240
|
+
vec4 Q = sqrt(max(vec4(0.0), discriminant));
|
241
|
+
intersection1 = mix((-b - Q) * 0.5, vec4(-1.0), mask);
|
242
|
+
intersection2 = mix((-b + Q) * 0.5, vec4(-1.0), mask);
|
243
|
+
}
|
244
|
+
|
245
|
+
void raySphereIntersections(
|
246
|
+
const vec3 origin,
|
247
|
+
const vec3 direction,
|
248
|
+
const vec4 radius,
|
249
|
+
out vec4 intersection1,
|
250
|
+
out vec4 intersection2
|
251
|
+
) {
|
252
|
+
raySphereIntersections(origin, direction, vec3(0.0), radius, intersection1, intersection2);
|
253
|
+
}
|
254
|
+
`, i = `vec3 screenToView(
|
255
|
+
const vec2 uv,
|
256
|
+
const float depth,
|
257
|
+
const float viewZ,
|
258
|
+
const mat4 projectionMatrix,
|
259
|
+
const mat4 inverseProjectionMatrix
|
260
|
+
) {
|
261
|
+
vec4 clip = vec4(vec3(uv, depth) * 2.0 - 1.0, 1.0);
|
262
|
+
float clipW = projectionMatrix[2][3] * viewZ + projectionMatrix[3][3];
|
263
|
+
clip *= clipW;
|
264
|
+
return (inverseProjectionMatrix * clip).xyz;
|
265
|
+
}
|
266
|
+
`, s = `// A fifth-order polynomial approximation of Turbo color map.
|
267
|
+
// See: https://observablehq.com/@mbostock/turbo
|
268
|
+
// prettier-ignore
|
269
|
+
vec3 turbo(const float x) {
|
270
|
+
float r = 0.1357 + x * (4.5974 - x * (42.3277 - x * (130.5887 - x * (150.5666 - x * 58.1375))));
|
271
|
+
float g = 0.0914 + x * (2.1856 + x * (4.8052 - x * (14.0195 - x * (4.2109 + x * 2.7747))));
|
272
|
+
float b = 0.1067 + x * (12.5925 - x * (60.1097 - x * (109.0745 - x * (88.5066 - x * 26.8183))));
|
273
|
+
return vec3(r, g, b);
|
274
|
+
}
|
275
|
+
`, a = n, v = e, d = t, m = c, f = o, x = r, l = i, p = s;
|
276
|
+
export {
|
277
|
+
a as depth,
|
278
|
+
v as generators,
|
279
|
+
d as math,
|
280
|
+
m as packing,
|
281
|
+
f as poissonDisk,
|
282
|
+
x as raySphereIntersection,
|
283
|
+
l as transform,
|
284
|
+
p as turbo
|
285
|
+
};
|
286
|
+
//# sourceMappingURL=shaders.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shaders.js","sources":["../src/shaders/depth.glsl?raw","../src/shaders/generators.glsl?raw","../src/shaders/math.glsl?raw","../src/shaders/packing.glsl?raw","../src/shaders/poissonDisk.glsl?raw","../src/shaders/raySphereIntersection.glsl?raw","../src/shaders/transform.glsl?raw","../src/shaders/turbo.glsl?raw","../src/shaders/index.ts"],"sourcesContent":null,"names":["_depth","_generators","_math","_packing","_poissonDisk","_raySphereIntersection","_transform","_turbo","depth","generators","math","packing","poissonDisk","raySphereIntersection","transform","turbo"],"mappings":"AAAA,MAAeA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCAAC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GCSFC,IAAgBR,GAChBS,IAAqBR,GACrBS,IAAeR,GACfS,IAAkBR,GAClBS,IAAsBR,GACtBS,IAAgCR,GAChCS,IAAoBR,GACpBS,IAAgBR;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@takram/three-geospatial",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.6",
|
4
4
|
"license": "MIT",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -13,6 +13,11 @@
|
|
13
13
|
"import": "./build/r3f.js",
|
14
14
|
"require": "./build/r3f.cjs",
|
15
15
|
"types": "./types/r3f/index.d.ts"
|
16
|
+
},
|
17
|
+
"./shaders": {
|
18
|
+
"import": "./build/shaders.js",
|
19
|
+
"require": "./build/shaders.cjs",
|
20
|
+
"types": "./types/shaders/index.d.ts"
|
16
21
|
}
|
17
22
|
},
|
18
23
|
"main": "./build/index.cjs",
|
@@ -26,10 +31,9 @@
|
|
26
31
|
"README.md"
|
27
32
|
],
|
28
33
|
"dependencies": {
|
29
|
-
"lodash-es": "^4.17.21",
|
30
34
|
"react-merge-refs": "^2.1.1",
|
31
35
|
"tiny-invariant": "^1.3.3",
|
32
|
-
"type-fest": "^4.
|
36
|
+
"type-fest": "^4.33.0"
|
33
37
|
},
|
34
38
|
"peerDependencies": {
|
35
39
|
"@react-three/fiber": ">=8.17.10",
|
package/src/DataLoader.ts
CHANGED
@@ -0,0 +1,81 @@
|
|
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.wrapR = RepeatWrapping
|
63
|
+
texture.wrapT = 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
|
+
}
|
package/src/bufferGeometry.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { pick } from 'lodash-es'
|
2
1
|
import { Box3, BufferAttribute, BufferGeometry, Sphere, Vector3 } from 'three'
|
3
2
|
|
4
3
|
export type BufferGeometryLike = Pick<
|
@@ -9,8 +8,9 @@ export type BufferGeometryLike = Pick<
|
|
9
8
|
export function toBufferGeometryLike(
|
10
9
|
geometry: BufferGeometry
|
11
10
|
): [BufferGeometryLike, ArrayBuffer[]] {
|
11
|
+
const { attributes, index, boundingBox, boundingSphere } = geometry
|
12
12
|
return [
|
13
|
-
|
13
|
+
{ attributes, index, boundingBox, boundingSphere },
|
14
14
|
[
|
15
15
|
...Object.values(geometry.attributes).map(
|
16
16
|
attribute => attribute.array.buffer
|
package/src/constants.ts
ADDED
package/src/index.ts
CHANGED
@@ -1,16 +1,7 @@
|
|
1
|
-
/// <reference types="vite-plugin-glsl/ext" />
|
2
|
-
|
3
|
-
import depth from './shaders/depth.glsl'
|
4
|
-
import packing from './shaders/packing.glsl'
|
5
|
-
import transform from './shaders/transform.glsl'
|
6
|
-
|
7
|
-
export const depthShader: string = depth
|
8
|
-
export const packingShader: string = packing
|
9
|
-
export const transformShader: string = transform
|
10
|
-
|
11
1
|
export * from './ArrayBufferLoader'
|
12
2
|
export * from './assertions'
|
13
3
|
export * from './bufferGeometry'
|
4
|
+
export * from './constants'
|
14
5
|
export * from './DataLoader'
|
15
6
|
export * from './Ellipsoid'
|
16
7
|
export * from './EllipsoidGeometry'
|
@@ -18,9 +9,11 @@ export * from './Geodetic'
|
|
18
9
|
export * from './math'
|
19
10
|
export * from './PointOfView'
|
20
11
|
export * from './Rectangle'
|
12
|
+
export * from './resolveIncludes'
|
21
13
|
export * from './TileCoordinate'
|
22
14
|
export * from './TilingScheme'
|
23
15
|
export * from './typedArray'
|
24
16
|
export * from './TypedArrayLoader'
|
25
17
|
export * from './typedArrayParsers'
|
26
18
|
export * from './types'
|
19
|
+
export * from './unrollLoops'
|
package/src/r3f/index.ts
CHANGED
package/src/r3f/types.ts
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
import {
|
2
|
+
type Color,
|
3
|
+
type ExtendedColors,
|
4
|
+
type NodeProps,
|
5
|
+
type Overwrite,
|
6
|
+
type Vector2,
|
7
|
+
type Vector3,
|
8
|
+
type Vector4
|
9
|
+
} from '@react-three/fiber'
|
10
|
+
import {
|
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 ExtendedVectors<T> = {
|
21
|
+
[K in keyof T]:
|
22
|
+
Vector2Impl extends T[K] ? Vector2 | T[K] :
|
23
|
+
Vector3Impl extends T[K] ? Vector3 | T[K] :
|
24
|
+
Vector4Impl extends T[K] ? Vector4 | T[K] :
|
25
|
+
T[K]
|
26
|
+
}
|
27
|
+
|
28
|
+
export type ExtendedProps<T> = ExtendedColors<ExtendedVectors<T>>
|
29
|
+
|
30
|
+
// @react-three/fiber's NonFunctionKeys cannot exclude partial functions.
|
31
|
+
// This excludes callback properties, which may be undesirable behavior.
|
32
|
+
type NonFunctionKeys<T> = keyof {
|
33
|
+
[K in keyof T as Callable extends T[K] ? never : K]: any
|
34
|
+
}
|
35
|
+
|
36
|
+
// prettier-ignore
|
37
|
+
type WritableNonExtendableKeysOf<T> =
|
38
|
+
| WritableKeysOf<T>
|
39
|
+
| keyof {
|
40
|
+
[K in keyof T as
|
41
|
+
Vector2Impl extends T[K] ? K :
|
42
|
+
Vector3Impl extends T[K] ? K :
|
43
|
+
Vector4Impl extends T[K] ? K :
|
44
|
+
Color extends T[K] ? K :
|
45
|
+
never
|
46
|
+
]: any
|
47
|
+
}
|
48
|
+
|
49
|
+
export type PassThoughInstanceProps<
|
50
|
+
RefType,
|
51
|
+
Args extends readonly any[],
|
52
|
+
Props
|
53
|
+
> = Overwrite<
|
54
|
+
ExtendedProps<{
|
55
|
+
[K in NonFunctionKeys<Props> as K extends WritableNonExtendableKeysOf<Props>
|
56
|
+
? K
|
57
|
+
: never]: Props[K]
|
58
|
+
}>,
|
59
|
+
NodeProps<RefType, Args>
|
60
|
+
>
|
61
|
+
|
62
|
+
export type ExpandNestedProps<T, Prop extends keyof T & string> = {
|
63
|
+
[K in keyof T[Prop] as K extends string ? `${Prop}-${K}` : never]: T[Prop][K]
|
64
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { resolveIncludes } from './resolveIncludes'
|
2
|
+
|
3
|
+
describe('resolveIncludes', () => {
|
4
|
+
test('delimited paths', () => {
|
5
|
+
expect(
|
6
|
+
resolveIncludes('#include "scope/lib"', {
|
7
|
+
scope: {
|
8
|
+
lib: 'imported'
|
9
|
+
}
|
10
|
+
})
|
11
|
+
).toBe('imported')
|
12
|
+
|
13
|
+
expect(() =>
|
14
|
+
resolveIncludes('#include "scope/lib"', {
|
15
|
+
other: {
|
16
|
+
lib: 'imported'
|
17
|
+
}
|
18
|
+
})
|
19
|
+
).toThrow()
|
20
|
+
})
|
21
|
+
})
|
@@ -0,0 +1,22 @@
|
|
1
|
+
const includePattern = /^[ \t]*#include +"([\w\d./]+)"/gm
|
2
|
+
|
3
|
+
interface Includes {
|
4
|
+
[key: string]: string | Includes
|
5
|
+
}
|
6
|
+
|
7
|
+
export function resolveIncludes(source: string, includes: Includes): string {
|
8
|
+
return source.replace(includePattern, (match, path: string) => {
|
9
|
+
const components = path.split('/')
|
10
|
+
const include = components.reduce<string | Includes | undefined>(
|
11
|
+
(parent, component) =>
|
12
|
+
typeof parent !== 'string' && parent != null
|
13
|
+
? parent[component]
|
14
|
+
: undefined,
|
15
|
+
includes
|
16
|
+
)
|
17
|
+
if (typeof include !== 'string') {
|
18
|
+
throw new Error(`Could not find include for ${path}.`)
|
19
|
+
}
|
20
|
+
return resolveIncludes(include, includes)
|
21
|
+
})
|
22
|
+
}
|
package/src/shaders/depth.glsl
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
// cSpell:words logdepthbuf
|
2
|
+
|
1
3
|
float reverseLogDepth(const float depth, const float near, const float far) {
|
2
4
|
#ifdef USE_LOGDEPTHBUF
|
3
5
|
float d = pow(2.0, depth * log2(far + 1.0)) - 1.0;
|
4
6
|
float a = far / (far - near);
|
5
7
|
float b = far * near / (near - far);
|
6
8
|
return a + b / d;
|
7
|
-
#else
|
9
|
+
#else // USE_LOGDEPTHBUF
|
8
10
|
return depth;
|
9
11
|
#endif // USE_LOGDEPTHBUF
|
10
12
|
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import _depth from './depth.glsl?raw'
|
2
|
+
import _generators from './generators.glsl?raw'
|
3
|
+
import _math from './math.glsl?raw'
|
4
|
+
import _packing from './packing.glsl?raw'
|
5
|
+
import _poissonDisk from './poissonDisk.glsl?raw'
|
6
|
+
import _raySphereIntersection from './raySphereIntersection.glsl?raw'
|
7
|
+
import _transform from './transform.glsl?raw'
|
8
|
+
import _turbo from './turbo.glsl?raw'
|
9
|
+
|
10
|
+
export const depth: string = _depth
|
11
|
+
export const generators: string = _generators
|
12
|
+
export const math: string = _math
|
13
|
+
export const packing: string = _packing
|
14
|
+
export const poissonDisk: string = _poissonDisk
|
15
|
+
export const raySphereIntersection: string = _raySphereIntersection
|
16
|
+
export const transform: string = _transform
|
17
|
+
export const turbo: string = _turbo
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#if !defined(saturate)
|
2
|
+
#define saturate(a) clamp(a, 0.0, 1.0)
|
3
|
+
#endif // !defined(saturate)
|
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
|
+
float remap(const float x, const float min1, const float max1, const float min2, const float max2) {
|
22
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
23
|
+
}
|
24
|
+
|
25
|
+
vec2 remap(const vec2 x, const vec2 min1, const vec2 max1, const vec2 min2, const vec2 max2) {
|
26
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
27
|
+
}
|
28
|
+
|
29
|
+
vec3 remap(const vec3 x, const vec3 min1, const vec3 max1, const vec3 min2, const vec3 max2) {
|
30
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
31
|
+
}
|
32
|
+
|
33
|
+
vec4 remap(const vec4 x, const vec4 min1, const vec4 max1, const vec4 min2, const vec4 max2) {
|
34
|
+
return min2 + (x - min1) / (max1 - min1) * (max2 - min2);
|
35
|
+
}
|
36
|
+
|
37
|
+
// Implicitly remap to 0 and 1
|
38
|
+
float remap(const float x, const float min1, const float max1) {
|
39
|
+
return (x - min1) / (max1 - min1);
|
40
|
+
}
|
41
|
+
|
42
|
+
vec2 remap(const vec2 x, const vec2 min1, const vec2 max1) {
|
43
|
+
return (x - min1) / (max1 - min1);
|
44
|
+
}
|
45
|
+
|
46
|
+
vec3 remap(const vec3 x, const vec3 min1, const vec3 max1) {
|
47
|
+
return (x - min1) / (max1 - min1);
|
48
|
+
}
|
49
|
+
|
50
|
+
vec4 remap(const vec4 x, const vec4 min1, const vec4 max1) {
|
51
|
+
return (x - min1) / (max1 - min1);
|
52
|
+
}
|