@null3d/wind 0.0.0 → 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.
@@ -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 CHANGED
Binary file
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.0.0";
1
+ export declare const VERSION = "0.1.0";
package/lib/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // The package's version, which the release keeps equal to the engine's. The package checks it
2
2
  // against the engine's VERSION as it loads, because an add-on and the engine ship in step.
3
- export const VERSION = '0.0.0';
3
+ export const VERSION = '0.1.0';
package/lib/wind.d.ts CHANGED
@@ -28,9 +28,9 @@ export interface WindOptions {
28
28
  */
29
29
  export interface WindField {
30
30
  /**
31
- * The texture. A reader declares it as `var wind: texture_2d<f32>;` and samples it through the
32
- * sampling function, which gives the air back: the wind across the ground, the wind's rise,
33
- * which is zero while the field is flat, and how fast the air moves. The grid keeps its state
31
+ * The texture. A reader declares it as `var wind: texture_2d_array<f32>;` and samples it
32
+ * through the sampling function, which gives the air back: the wind across the ground, the
33
+ * wind's rise, which is zero while the field is flat, and how fast the air moves. The grid keeps its state
34
34
  * in the texture's own numbers, so a reader does not decode them itself. A preset change that
35
35
  * changes the grid makes a new texture, so read this again after one.
36
36
  */
@@ -44,8 +44,9 @@ export interface WindField {
44
44
  */
45
45
  readonly size: number;
46
46
  /**
47
- * The steady settings that a reader works out beyond the box. Give them to a material with the
48
- * sampling function's three vectors, and give them again when `setBase` or the air changes.
47
+ * The steady settings that a reader works out beyond the box. Give them to a material in the
48
+ * first three of the sampling function's four vectors, and give them again when `setBase` or
49
+ * the air changes. The fourth holds the gust that the page sent last.
49
50
  */
50
51
  readonly air: WindReading;
51
52
  }
package/lib/wind.js CHANGED
@@ -16,7 +16,7 @@ const STEP_MS = [0, 33, 33, 16];
16
16
  const STEP_MS_WEBGL2 = [0, 66, 66, 66];
17
17
  /** The pressure iterations of one cycle at each preset. */
18
18
  const PRESSURE_ROW = [0, 16, 24, 40];
19
- /** The trees that keep branch springs at each preset. The vegetation add-on reads it. */
19
+ /** The trees that keep branch springs at each preset. */
20
20
  const SPRING_ROW = [0, 8, 32, 64];
21
21
  /**
22
22
  * The grid's texels across each way at each preset. Low keeps no grid and reads the steady field,
@@ -41,10 +41,11 @@ export const CYCLE_STEPS = PRESSURE_STEPS + 2;
41
41
  /** The fixed time that one cycle steps the air by, in seconds, before a preset applies. */
42
42
  export const STEP_SECONDS = 1 / 60;
43
43
  /**
44
- * The most cycles that one frame runs, which is ten seconds of air. A longer stall in a page skips
45
- * the air that it missed rather than spends one frame solving it.
44
+ * The most air that one frame runs, in seconds. A frame runs at most the cycles that fit in it at
45
+ * the field's step. A longer stall in a page skips the air that it missed rather than spends one
46
+ * frame solving it.
46
47
  */
47
- const MAX_CYCLES = 600;
48
+ const MAX_AIR_SECONDS = 10;
48
49
  /** How strong a gust is when the page names no strength. */
49
50
  const GUST = 7;
50
51
  /** How strong a push is when the page names no strength. */
@@ -85,10 +86,13 @@ export function createWind(ctx, options) {
85
86
  // time owes, so the air keeps the same pace whatever the frame rate.
86
87
  //
87
88
  // The air starts when a page makes the wind. A held page's first drawn frame runs the air from
88
- // then to the held time, so a held picture carries the air that the hold built. Each frame reads
89
+ // then to the held time, up to ten seconds of it, so a held picture carries the air that the
90
+ // hold built. Each frame reads
89
91
  // the sketch time from the engine's field, because a helper that answered it would box its
90
- // fraction on a call that the browser does not inline.
91
- let solved = ctx.time.now;
92
+ // fraction on a call that the browser does not inline. The time that the air has run to sits in
93
+ // a typed array, because a fraction written to a closure's variable makes a number object at each
94
+ // write.
95
+ const solved = new Float64Array([ctx.time.now]);
92
96
  // The preset names no field at Low. A page that keeps its own grid there still gets a field, at
93
97
  // the add-on's own step and pressure count, because air that never steps never moves.
94
98
  const presetField = () => stepSeconds > 0;
@@ -103,13 +107,14 @@ export function createWind(ctx, options) {
103
107
  const step = presetField() ? stepSeconds : STEP_SECONDS;
104
108
  // The sketch time is a sum of frame times, so a frame that owes exactly one step can read a
105
109
  // hair under it.
106
- const owed = Math.floor((ctx.time.now - solved) / step + 1e-6);
110
+ const owed = Math.floor((ctx.time.now - solved[0]) / step + 1e-6);
107
111
  if (owed <= 0)
108
112
  return 0;
109
- const cycles = Math.min(owed, MAX_CYCLES);
113
+ const most = Math.max(1, Math.floor(MAX_AIR_SECONDS / step + 1e-6));
114
+ const cycles = Math.min(owed, most);
110
115
  // A stall that owes more than one frame runs skips the air that it missed. Crediting only
111
116
  // the cycles that ran would leave a debt, and every later frame would pay it.
112
- solved = owed > MAX_CYCLES ? ctx.time.now : solved + cycles * step;
117
+ solved[0] = owed > most ? ctx.time.now : solved[0] + cycles * step;
113
118
  return cycles * cycleSteps();
114
119
  };
115
120
  const values = new Array(32).fill(0);
@@ -251,7 +256,7 @@ export function createWind(ctx, options) {
251
256
  if (old)
252
257
  ctx.render.removePass(old);
253
258
  pass = makePass();
254
- solved = ctx.time.now;
259
+ solved[0] = ctx.time.now;
255
260
  host.remove('wind');
256
261
  feature = host.add(describe());
257
262
  feature.refresh();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@null3d/wind",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "Wind for null3D sketches: one field of air that plants, flags, smoke and water read, from an analytic wind of place and time with traveling gusts and pushes, solved on a grid that follows the camera, built on the engine's public API.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "author": "Ramesh Nair (https://hiddentao.com)",
@@ -37,7 +37,8 @@
37
37
  "dist",
38
38
  "shaders",
39
39
  "LICENSE-MIT",
40
- "LICENSE-APACHE"
40
+ "LICENSE-APACHE",
41
+ "THIRD-PARTY-NOTICES.txt"
41
42
  ],
42
43
  "publishConfig": {
43
44
  "access": "public",