@null3d/wind 0.0.0-stage → 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/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/README.md +84 -2
- package/THIRD-PARTY-NOTICES.txt +37 -0
- package/dist/wind.wasm +0 -0
- package/lib/analytic.d.ts +130 -0
- package/lib/analytic.js +252 -0
- package/lib/field-layout.d.ts +34 -0
- package/lib/field-layout.js +47 -0
- package/lib/field-task.d.ts +14 -0
- package/lib/field-task.js +54 -0
- package/lib/field.d.ts +57 -0
- package/lib/field.js +140 -0
- package/lib/grid.fallback.wgsl-effect-glsl-0-c640d63bfe7fd852.js +24 -0
- package/lib/grid.fallback.wgsl-effect-wgsl-0-8a5918d6897a07b9.js +24 -0
- package/lib/grid.fallback.wgsl.d.ts +18 -0
- package/lib/grid.fallback.wgsl.js +32 -0
- package/lib/grid.wgsl.d.ts +6 -0
- package/lib/grid.wgsl.js +24 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +8 -0
- package/lib/namespace.d.ts +6 -0
- package/lib/namespace.js +13 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +3 -0
- package/lib/wind.d.ts +139 -0
- package/lib/wind.js +361 -0
- package/package.json +57 -5
- package/shaders/field.wgsl +190 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ramesh Nair
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Wind for null3D
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@null3d/wind` makes the air in a null3D scene. One field moves every plant, flag and smoke card
|
|
4
|
+
that reads it, so a gust that crosses a field reaches all of them together. The air is solved: a
|
|
5
|
+
grid that follows the camera carries it from frame to frame. A gust therefore bends through the
|
|
6
|
+
scene, and a body leaves a wake that outlives it. A steady wind slows near the ground, and swirls
|
|
7
|
+
turn without piling up.
|
|
8
|
+
|
|
9
|
+
## Use
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineSketch } from '@null3d/engine';
|
|
13
|
+
import { createWind } from '@null3d/wind';
|
|
14
|
+
|
|
15
|
+
export default defineSketch((ctx) => {
|
|
16
|
+
const { scene } = ctx;
|
|
17
|
+
const camera = scene.createPerspectiveCamera({ position: [0, 6, 18], target: [0, 1, 0] });
|
|
18
|
+
scene.setActiveCamera(camera);
|
|
19
|
+
|
|
20
|
+
const wind = createWind(ctx, { camera, box: 128 });
|
|
21
|
+
wind.setBase(4, 0.4);
|
|
22
|
+
|
|
23
|
+
const leaf = ctx.materials.shader({
|
|
24
|
+
wgsl: leafShader,
|
|
25
|
+
textures: { wind: wind.field.texture },
|
|
26
|
+
uniforms: {
|
|
27
|
+
origin: wind.field.origin,
|
|
28
|
+
size: wind.field.size,
|
|
29
|
+
layer: wind.field.texture.layer,
|
|
30
|
+
base: wind.field.air.base,
|
|
31
|
+
gust: wind.field.air.gust,
|
|
32
|
+
swirl: wind.field.air.swirl,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
let nextGust = 0;
|
|
37
|
+
return {
|
|
38
|
+
onUpdate() {
|
|
39
|
+
// A gust every four seconds, sent where the air enters the scene.
|
|
40
|
+
if (ctx.time.now > nextGust) {
|
|
41
|
+
wind.gust([-40, 6], 6);
|
|
42
|
+
nextGust = ctx.time.now + 4;
|
|
43
|
+
}
|
|
44
|
+
wind.update();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Call `update` once in each frame. The add-on makes no object of its own; a sketch that pushes every frame keeps one two-number array for the place. Until the browser has optimized the add-on's functions, a fraction that crosses one of its calls becomes an object, as in the engine's own steps.
|
|
51
|
+
|
|
52
|
+
## The field
|
|
53
|
+
|
|
54
|
+
The field is one `rgba16float` texture over a box of ground that follows the camera. One pass keeps
|
|
55
|
+
two states of it: the air of the frame before, and the air it steps toward. The preset sets the
|
|
56
|
+
time between steps, the pressure iterations of a cycle and the grid's size. The frame-budget
|
|
57
|
+
governor lightens them when frames take too long. A wake therefore lasts after the body that made
|
|
58
|
+
it has gone.
|
|
59
|
+
|
|
60
|
+
A reader samples it with one texture read at each vertex. The shader build resolves only the
|
|
61
|
+
engine's library, so a reader's WGSL holds copies of two blocks: the steady field and the sampling
|
|
62
|
+
function. They are in `shaders/field.wgsl` and on the `api/wind` docs page. A test keeps every copy
|
|
63
|
+
equal to the one in the package.
|
|
64
|
+
|
|
65
|
+
`read(points, out)` gives the air at many places, three numbers a place, worked out by the add-on's
|
|
66
|
+
WebAssembly in a job worker. Use it in a frame, which is what moves a sketch's own objects with the
|
|
67
|
+
air. The answer lands before the next frame's update. A call that arrives while another waits for
|
|
68
|
+
its answer replaces that ask: the newest ask wins, and the replaced one's array keeps its numbers.
|
|
69
|
+
`sample(x, y, z, out)` gives the analytic air
|
|
70
|
+
on the CPU, which suits a test and a read outside a frame. The solved air is on the GPU.
|
|
71
|
+
|
|
72
|
+
## Costs and limits
|
|
73
|
+
|
|
74
|
+
- The pass fills one texture of `grid` by `grid` texels in each frame, and a reader spends one
|
|
75
|
+
texture slot on it. A page that gives `grid` keeps it; otherwise the preset's row sets it.
|
|
76
|
+
- The pass holds two states, so it costs twice the texture's memory, and one cycle takes the
|
|
77
|
+
preset's pressure steps and two more runs.
|
|
78
|
+
- A device without float render targets keeps no grid. There `field.size` is zero, so a reader
|
|
79
|
+
works the air out from the steady field and a plant still moves.
|
|
80
|
+
- A place outside the box reads the steady field at its own place, at the height that the texture
|
|
81
|
+
holds. So the air carries on past the box, instead of holding the box's edge. A page's pushes and
|
|
82
|
+
a gust that the page sends turn the air inside the box only.
|
|
83
|
+
|
|
84
|
+
`@null3d/wind` owns the wind. A scene makes its air with it, not with a hand-written field of its
|
|
85
|
+
own, so there is one wind for every reader.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Third-party code in @null3d/wind
|
|
2
|
+
|
|
3
|
+
The @null3d/wind package ships code from the projects below. Each section names the files
|
|
4
|
+
that hold the code, its licence, and the notices that the licence asks a copy to carry.
|
|
5
|
+
|
|
6
|
+
A build with the null3D Vite plugin writes this text into null3d-third-party-notices.txt beside
|
|
7
|
+
the page, after the engine's own notices. Keep that file with the build when you publish it, or
|
|
8
|
+
show its text in your game's credits.
|
|
9
|
+
|
|
10
|
+
==============================================================================
|
|
11
|
+
The Rust standard library in the wind field (dist/wind.wasm)
|
|
12
|
+
==============================================================================
|
|
13
|
+
|
|
14
|
+
The wind field is compiled from Rust with its standard library, which is offered under
|
|
15
|
+
the MIT License or the Apache License 2.0. null3D takes it under the MIT License.
|
|
16
|
+
|
|
17
|
+
- The Rust standard library: Copyright (c) The Rust Project Contributors
|
|
18
|
+
|
|
19
|
+
The MIT License
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in
|
|
29
|
+
all copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
37
|
+
THE SOFTWARE.
|
package/dist/wind.wasm
ADDED
|
Binary file
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first value of `null3d::noise`'s `pcg3d` hash, as a signed whole number. The library returns
|
|
3
|
+
* three, but value noise reads only the first, and this form makes no tuple and no closure.
|
|
4
|
+
*
|
|
5
|
+
* Each step keeps its number in the 32 bits that a whole number holds. The hash is the same 32 bits
|
|
6
|
+
* either way, and the top 24 come out the same. Read as unsigned, about half of them pass the
|
|
7
|
+
* largest number that the browser keeps in the value itself, and it makes an object of each such
|
|
8
|
+
* number it returns. So the steps wrap with `| 0` rather than `>>> 0`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function lattice(x: number, y: number, z: number): number;
|
|
11
|
+
/** `null3d::noise`'s value noise in 3D, from 0 to 1. */
|
|
12
|
+
export declare function value3(px: number, py: number, pz: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* One slot of the ring: a push or a gust, each of which turns the air about a center. A push turns
|
|
15
|
+
* about the place it names and fades over its life. A gust turns as a wave about a center that
|
|
16
|
+
* travels along the heading from that place, for as long as the wave's reach holds it. The slot's
|
|
17
|
+
* place in the ring tells the two apart: the gust keeps the last slot, after the pushes.
|
|
18
|
+
*/
|
|
19
|
+
export interface Push {
|
|
20
|
+
x: number;
|
|
21
|
+
z: number;
|
|
22
|
+
/** How hard the body shoved the air: a positive number turns it one way, a negative the other. */
|
|
23
|
+
strength: number;
|
|
24
|
+
/** The sketch time in seconds when the page sent the push or the gust. */
|
|
25
|
+
born: number;
|
|
26
|
+
}
|
|
27
|
+
/** The pushes that a page made, which the field reads in place. */
|
|
28
|
+
export interface PushRing {
|
|
29
|
+
/** The slots, which the field reads: the pushes first, then the newest gust. A slot that holds no
|
|
30
|
+
* strength turns nothing. */
|
|
31
|
+
readonly slots: readonly Push[];
|
|
32
|
+
/**
|
|
33
|
+
* Answers the slot that a push or a gust takes, without writing its numbers. The caller writes
|
|
34
|
+
* them in place, so a frame passes no freshly worked-out fraction into a call, where the browser
|
|
35
|
+
* would make a number object of it.
|
|
36
|
+
*/
|
|
37
|
+
take(gust: boolean): number;
|
|
38
|
+
/**
|
|
39
|
+
* Writes a push or a gust sent at the time `born`, and answers the slot that it wrote. A push
|
|
40
|
+
* takes the oldest push slot, so the newest three pushes turn the air. A gust takes the gust's
|
|
41
|
+
* own slot, so a page's pushes never push its gust out. A call replaces the slot's numbers, so a
|
|
42
|
+
* page may call it in every frame and the call allocates nothing.
|
|
43
|
+
*/
|
|
44
|
+
add(x: number, z: number, strength: number, born: number, gust: boolean): number;
|
|
45
|
+
}
|
|
46
|
+
/** Makes the empty ring that a page's pushes go into. The slots are made once, here. */
|
|
47
|
+
export declare function createPushRing(): PushRing;
|
|
48
|
+
/**
|
|
49
|
+
* The steady settings that a reader works out beyond the box, as the three vectors that its shader
|
|
50
|
+
* takes: the base wind, the gust and the swirl. A page gives them to a material once, and again
|
|
51
|
+
* when `setBase` or one of the air's settings changes; a frame changes nothing here.
|
|
52
|
+
*
|
|
53
|
+
* @category api/wind
|
|
54
|
+
*/
|
|
55
|
+
export interface WindReading {
|
|
56
|
+
/** The speed, the heading in radians, how much slower the air is at the ground, and the seed. */
|
|
57
|
+
readonly base: [number, number, number, number];
|
|
58
|
+
/** The gust's strength, its radius in meters, its wave number and how fast it travels. */
|
|
59
|
+
readonly gust: [number, number, number, number];
|
|
60
|
+
/** The swirl's strength, its size, how fast its pattern drifts, and a number it does not use. */
|
|
61
|
+
readonly swirl: [number, number, number, number];
|
|
62
|
+
/** The gust a page sent: its ground place in x and z, its strength, and the time it was sent. */
|
|
63
|
+
readonly sent: [number, number, number, number];
|
|
64
|
+
}
|
|
65
|
+
/** Makes the three vectors of a reading from the field's settings. */
|
|
66
|
+
export declare function createReading(state: FieldState): WindReading;
|
|
67
|
+
/**
|
|
68
|
+
* The time that a reading holds when no page has sent a gust: a born time that no frame reaches, so
|
|
69
|
+
* the sent gust's life is over at every frame time.
|
|
70
|
+
*/
|
|
71
|
+
export declare const SENT_NONE = -1000000000;
|
|
72
|
+
/** Writes the field's settings into a reading's vectors, in place, so a reader re-reads them. */
|
|
73
|
+
export declare function writeReading(state: FieldState, reading: WindReading): void;
|
|
74
|
+
/**
|
|
75
|
+
* The field's settings, which a page sets once or changes at any time.
|
|
76
|
+
*
|
|
77
|
+
* @category api/wind
|
|
78
|
+
*/
|
|
79
|
+
export interface FieldState {
|
|
80
|
+
/** The wind's speed in meters a second, at the top of the profile. */
|
|
81
|
+
speed: number;
|
|
82
|
+
/** The heading that the wind blows toward, in radians: 0 blows toward +x, pi/2 toward +z. */
|
|
83
|
+
heading: number;
|
|
84
|
+
/** How much slower the air is at the ground, from 0 to 1, over `GROUND_HEIGHT` meters. */
|
|
85
|
+
ground: number;
|
|
86
|
+
/** The strength of the gust's turn, in meters a second. */
|
|
87
|
+
gustStrength: number;
|
|
88
|
+
/** How wide the gust is, in meters. */
|
|
89
|
+
gustRadius: number;
|
|
90
|
+
/** How far apart the gust's turns sit, so the gust arrives as a wave rather than one eddy. */
|
|
91
|
+
gustWave: number;
|
|
92
|
+
/** How fast the gust travels, in meters a second. */
|
|
93
|
+
gustSpeed: number;
|
|
94
|
+
/** How wide a push turns the air, in meters. */
|
|
95
|
+
pushRadius: number;
|
|
96
|
+
/** The strength of the noise-built swirl, in meters a second. */
|
|
97
|
+
swirl: number;
|
|
98
|
+
/** The swirl's size: larger makes wider, slower eddies. */
|
|
99
|
+
swirlScale: number;
|
|
100
|
+
/** How fast the swirl's pattern drifts, in meters a second. */
|
|
101
|
+
swirlDrift: number;
|
|
102
|
+
/** The seed of the swirl's pattern, so two pages may look different. */
|
|
103
|
+
seed: number;
|
|
104
|
+
}
|
|
105
|
+
/** The height over which the air slows to the ground, in meters. */
|
|
106
|
+
export declare const GROUND_HEIGHT = 2;
|
|
107
|
+
/** How long a push lasts before it has faded away, in seconds. */
|
|
108
|
+
export declare const PUSH_LIFE = 3;
|
|
109
|
+
/** The pushes that the field holds: the newest replaces the oldest. */
|
|
110
|
+
export declare const PUSH_SLOTS = 3;
|
|
111
|
+
/** The slot that holds the newest gust, after the pushes, so a page's pushes never push it out. */
|
|
112
|
+
export declare const GUST_SLOT = 3;
|
|
113
|
+
/** The slots of the ring: the pushes, then the gust. */
|
|
114
|
+
export declare const RING_SLOTS: number;
|
|
115
|
+
/** The distance over which the noise's curl is measured, in noise cells. */
|
|
116
|
+
export declare const CURL_STEP = 0.02;
|
|
117
|
+
/** The settings that a page gets when it names none. */
|
|
118
|
+
export declare function defaultFieldState(): FieldState;
|
|
119
|
+
/**
|
|
120
|
+
* The height's factor of the wind, from 1 at the top to `1 - ground` at the ground, so a plant's
|
|
121
|
+
* crown moves more than its base.
|
|
122
|
+
*/
|
|
123
|
+
export declare function profile(state: FieldState, y: number): number;
|
|
124
|
+
/**
|
|
125
|
+
* The air's velocity at a world place and a sketch time, in meters a second, written into `out` as
|
|
126
|
+
* `[x, y, z]`. It allocates nothing and reads no state that a frame changes.
|
|
127
|
+
*/
|
|
128
|
+
export declare function analyticVelocity(state: FieldState, pushes: readonly (Push | undefined)[], x: number, y: number, z: number, t: number, out: [number, number, number]): [number, number, number];
|
|
129
|
+
/** The divergence of the field at a place and a time, in a second, measured over a short step. */
|
|
130
|
+
export declare function divergence(state: FieldState, pushes: readonly (Push | undefined)[], x: number, y: number, z: number, t: number, step?: number): number;
|