@woosh/meep-engine 3.78.1 → 3.78.3
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/CHANGELOG.md +13 -0
- package/package.json +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/GroomAssetLoader.js +2 -1
- package/src/engine/graphics/hair/Groom.d.ts +30 -0
- package/src/engine/graphics/hair/Groom.d.ts.map +1 -1
- package/src/engine/graphics/hair/Groom.js +35 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +18 -2
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -1
- package/src/engine/graphics/hair/GroomSerializationAdapter.js +36 -6
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts +8 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.d.ts.map +1 -0
- package/src/engine/graphics/hair/GroomSerializationUpgrader_1_2.js +44 -0
- package/src/engine/graphics/hair/groom_bake_shelter.d.ts +33 -0
- package/src/engine/graphics/hair/groom_bake_shelter.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_bake_shelter.js +288 -0
- package/src/engine/graphics/hair/groom_build_group.d.ts +10 -2
- package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -1
- package/src/engine/graphics/hair/groom_build_group.js +8 -2
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts +119 -0
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.d.ts.map +1 -0
- package/src/generation/grid/generation/discrete/GridTaskWaveFunctionCollapse.js +563 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts +11 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.d.ts.map +1 -0
- package/src/generation/wfc/GRID_WFC_PIECE_SOCKET_PREFIX.js +10 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.d.ts +123 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCCompiledTileSet.js +355 -0
- package/src/generation/wfc/GridWFCEdge.d.ts +13 -0
- package/src/generation/wfc/GridWFCEdge.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCEdge.js +14 -0
- package/src/generation/wfc/GridWFCTileSet.d.ts +120 -0
- package/src/generation/wfc/GridWFCTileSet.d.ts.map +1 -0
- package/src/generation/wfc/GridWFCTileSet.js +275 -0
- package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
- package/src/shade/renderer/hair/GPUHairSystem.js +55 -11
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +4 -0
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts +77 -15
- package/src/shade/renderer/hair/HAIR_SIMULATION.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR_SIMULATION.js +104 -17
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts +9 -2
- package/src/shade/renderer/hair/chunk_hair_guide.d.ts.map +1 -1
- package/src/shade/renderer/hair/chunk_hair_guide.js +30 -2
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts +27 -18
- package/src/shade/renderer/hair/shader_hair_simulate.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_simulate.js +174 -83
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
### Generation: wave function collapse over a grid
|
|
6
|
+
|
|
7
|
+
- **Added:** `GridTaskWaveFunctionCollapse`, a grid task that lays the tiles of a `GridWFCTileSet` over the whole
|
|
8
|
+
grid with the `core/wfc` solver and runs each tile's `GridCellAction` on its cell, turned as the tile is. Cells a
|
|
9
|
+
`CellMatcher` names can be restricted to tiles carrying a tag, the edge of the grid likewise, and the tiles of one
|
|
10
|
+
tag can be required to form one region — by swapping in a tile with the same sockets that carries the tag where
|
|
11
|
+
one keeps two regions apart, and by drawing again where none can. A `fallback` tile covers the grid when every draw
|
|
12
|
+
failed.
|
|
13
|
+
- **Added:** `generation/wfc/GridWFCTileSet`: tiles described by a socket on each edge, expanded into their quarter
|
|
14
|
+
turns and compiled to a `WFCRuleTable`. `add_piece` makes a piece of several cells, joined edge to edge, that only
|
|
15
|
+
ever appears whole; `compile().lint()` names a tile showing a socket nothing answers and tiles that can never share
|
|
16
|
+
a result (`WFC_DESIGN.md` §13).
|
|
17
|
+
|
|
5
18
|
### Cloth: a cloth that slides is not pulled back to where it landed
|
|
6
19
|
|
|
7
20
|
- **Fixed:** cloth friction pulled a sliding particle towards the point where its contact began, for as long as
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroomAssetLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/GroomAssetLoader.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GroomAssetLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/GroomAssetLoader.js"],"names":[],"mappings":"AA0BA;;;;;;GAMG;AACH,qCAHW,KAAK,GACH,WAAW,CAcvB;AAED;;;;;GAKG;AACH,sCAHW,WAAW,GACT,KAAK,CAsBjB;AA5DD;;;GAGG;AACH,+BAFU,MAAM,CAE2B;AA0D3C;;;;GAIG;AACH;;IAaI,8FAmBC;CACJ;sBA9GqB,8BAA8B;4BAQxB,kBAAkB;sBAHxB,aAAa"}
|
|
@@ -4,6 +4,7 @@ import { load_groom_usd } from "../../../shade/renderer/loader/usd/usd_groom_ext
|
|
|
4
4
|
import { Groom } from "../../graphics/hair/Groom.js";
|
|
5
5
|
import { GroomSerializationAdapter } from "../../graphics/hair/GroomSerializationAdapter.js";
|
|
6
6
|
import { GroomSerializationUpgrader_0_1 } from "../../graphics/hair/GroomSerializationUpgrader_0_1.js";
|
|
7
|
+
import { GroomSerializationUpgrader_1_2 } from "../../graphics/hair/GroomSerializationUpgrader_1_2.js";
|
|
7
8
|
import { executeBinaryClassUpgraderChain } from "../../ecs/storage/binary/executeBinaryClassUpgraderChain.js";
|
|
8
9
|
import { Asset } from "../Asset.js";
|
|
9
10
|
import { GameAssetType } from "../GameAssetType.js";
|
|
@@ -21,7 +22,7 @@ export const GROOM_FILE_MAGIC = 0x4D52474D;
|
|
|
21
22
|
* `v` to `v + 1`.
|
|
22
23
|
* @type {import("../../ecs/storage/binary/BinaryClassUpgrader.js").BinaryClassUpgrader[]}
|
|
23
24
|
*/
|
|
24
|
-
const GROOM_UPGRADERS = [new GroomSerializationUpgrader_0_1()];
|
|
25
|
+
const GROOM_UPGRADERS = [new GroomSerializationUpgrader_0_1(), new GroomSerializationUpgrader_1_2()];
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* A {@link Groom} as a file: {@link GROOM_FILE_MAGIC}, the format's version (u32), then the groom
|
|
@@ -24,6 +24,17 @@ export const GROOM_POINT_COUNT_MAX: number;
|
|
|
24
24
|
* @type {number}
|
|
25
25
|
*/
|
|
26
26
|
export const GROOM_GUIDE_LIMIT: number;
|
|
27
|
+
/**
|
|
28
|
+
* Depths a guide's node has in {@link GroomGroup#guide_shelter}: toward +x, −x, +y, −y, +z and −z.
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
export const GROOM_SHELTER_WORDS: number;
|
|
32
|
+
/**
|
|
33
|
+
* The depth that stands for hair nothing passes, and for anything solid. A fibre's drag coefficient is never under
|
|
34
|
+
* one, so no more than `e^(−depth / 2)` of a wind crosses a depth: past this, less than a float32 tells from none.
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
37
|
+
export const GROOM_SHELTER_OPAQUE: number;
|
|
27
38
|
/**
|
|
28
39
|
* Strands of hair that share a point count, as they are at rest: a scalp, the brows, the lashes, a beard.
|
|
29
40
|
*
|
|
@@ -106,6 +117,25 @@ export class GroomGroup {
|
|
|
106
117
|
* @type {number}
|
|
107
118
|
*/
|
|
108
119
|
guide_reach: number;
|
|
120
|
+
/**
|
|
121
|
+
* How much hair stands between each guide's node and the open air along each of the group's axes
|
|
122
|
+
* (`groom_bake_shelter`): {@link GROOM_SHELTER_WORDS} depths a node, a guide's nodes in turn, guide after guide.
|
|
123
|
+
* A depth is the fibres' frontal area along the way out over the area crossed, a pure number, never past
|
|
124
|
+
* {@link GROOM_SHELTER_OPAQUE}.
|
|
125
|
+
* @type {Float32Array}
|
|
126
|
+
*/
|
|
127
|
+
guide_shelter: Float32Array;
|
|
128
|
+
/**
|
|
129
|
+
* The area the group's strands cover seen from a direction, averaged over every direction, square metres
|
|
130
|
+
* (`groom_bake_shelter`): what of a wind the group stands in the way of.
|
|
131
|
+
* @type {number}
|
|
132
|
+
*/
|
|
133
|
+
silhouette: number;
|
|
134
|
+
/**
|
|
135
|
+
* The length of every strand of the group, summed, metres.
|
|
136
|
+
* @type {number}
|
|
137
|
+
*/
|
|
138
|
+
fibre_length: number;
|
|
109
139
|
/**
|
|
110
140
|
* @returns {number} guides the group has
|
|
111
141
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Groom.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/Groom.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,gCAFU,MAAM,CAEmB;AAEnC;;;GAGG;AACH,2CAFU,MAAM,CAEmC;AAEnD;;;GAGG;AACH,sCAFU,MAAM,CAE4B;AAE5C;;;GAGG;AACH,oCAFU,MAAM,CAEyB;AAEzC;;;GAGG;AACH,gCAFU,MAAM,CAEyB;AAEzC;;;;;;;;;GASG;AACH;IACI;;OAEG;IACH,MAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;OAEG;IACH,cAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,QAFU,YAAY,CAEO;IAE7B;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;;OAIG;IACH,YAFU,MAAM,CAED;IAEf;;;;OAIG;IACH,cAFU,MAAM,CAEC;IAEjB;;;;OAIG;IACH,mBAFU,MAAM,CAEM;IAEtB;;;OAGG;IACH,cAFU,WAAW,CAEa;IAElC;;;OAGG;IACH,oBAFU,WAAW,CAEmB;IAExC;;;OAGG;IACH,gBAFU,YAAY,CAEe;IAErC;;;OAGG;IACH,cAFU,YAAY,CAEa;IAEnC;;;OAGG;IACH,cAFU,WAAW,CAEa;IAElC;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;OAEG;IACH,0BAEC;IAED;;;OAGG;IACH,QAFU,WAAW,CAEO;IAE5B;;;;OAIG;IACH,WAFU,UAAU,CAEU;IAE9B;;;;;OAKG;IACH,YAFU,YAAY,CAEW;IAEjC;;OAEG;IACH,0BAEC;IAED;;;;;;;OAOG;IACH,gBALW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,cAClC,MAAM,UACN,MAAM,SACN,MAAM,QAehB;IAED;;;;;;OAMG;IACH,mBAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAMlB;CACJ;AAED;;;GAGG;AACH;IACI;;OAEG;IACH,QAFU,UAAU,EAAE,CAEV;IAEZ;;OAEG;IACH,2BAQC;IAED;;OAEG;IACH,0BAUC;IAED;;OAEG;IACH,WAFW,UAAU,QAOpB;CACJ"}
|
|
1
|
+
{"version":3,"file":"Groom.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/Groom.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,gCAFU,MAAM,CAEmB;AAEnC;;;GAGG;AACH,2CAFU,MAAM,CAEmC;AAEnD;;;GAGG;AACH,sCAFU,MAAM,CAE4B;AAE5C;;;GAGG;AACH,oCAFU,MAAM,CAEyB;AAEzC;;;GAGG;AACH,gCAFU,MAAM,CAEyB;AAEzC;;;GAGG;AACH,kCAFU,MAAM,CAEqB;AAErC;;;;GAIG;AACH,mCAFU,MAAM,CAEuB;AAEvC;;;;;;;;;GASG;AACH;IACI;;OAEG;IACH,MAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;OAEG;IACH,cAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,QAFU,YAAY,CAEO;IAE7B;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;;OAIG;IACH,YAFU,MAAM,CAED;IAEf;;;;OAIG;IACH,cAFU,MAAM,CAEC;IAEjB;;;;OAIG;IACH,mBAFU,MAAM,CAEM;IAEtB;;;OAGG;IACH,cAFU,WAAW,CAEa;IAElC;;;OAGG;IACH,oBAFU,WAAW,CAEmB;IAExC;;;OAGG;IACH,gBAFU,YAAY,CAEe;IAErC;;;OAGG;IACH,cAFU,YAAY,CAEa;IAEnC;;;OAGG;IACH,cAFU,WAAW,CAEa;IAElC;;;OAGG;IACH,aAFU,MAAM,CAEA;IAEhB;;;;;;OAMG;IACH,eAFU,YAAY,CAEc;IAEpC;;;;OAIG;IACH,YAFU,MAAM,CAED;IAEf;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB;;OAEG;IACH,0BAEC;IAED;;;OAGG;IACH,QAFU,WAAW,CAEO;IAE5B;;;;OAIG;IACH,WAFU,UAAU,CAEU;IAE9B;;;;;OAKG;IACH,YAFU,YAAY,CAEW;IAEjC;;OAEG;IACH,0BAEC;IAED;;;;;;;OAOG;IACH,gBALW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,cAClC,MAAM,UACN,MAAM,SACN,MAAM,QAehB;IAED;;;;;;OAMG;IACH,mBAJW,MAAM,SACN,MAAM,GACJ,MAAM,CAMlB;CACJ;AAED;;;GAGG;AACH;IACI;;OAEG;IACH,QAFU,UAAU,EAAE,CAEV;IAEZ;;OAEG;IACH,2BAQC;IAED;;OAEG;IACH,0BAUC;IAED;;OAEG;IACH,WAFW,UAAU,QAOpB;CACJ"}
|
|
@@ -31,6 +31,19 @@ export const GROOM_POINT_COUNT_MAX = 129;
|
|
|
31
31
|
*/
|
|
32
32
|
export const GROOM_GUIDE_LIMIT = 0x10000;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Depths a guide's node has in {@link GroomGroup#guide_shelter}: toward +x, −x, +y, −y, +z and −z.
|
|
36
|
+
* @type {number}
|
|
37
|
+
*/
|
|
38
|
+
export const GROOM_SHELTER_WORDS = 6;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The depth that stands for hair nothing passes, and for anything solid. A fibre's drag coefficient is never under
|
|
42
|
+
* one, so no more than `e^(−depth / 2)` of a wind crosses a depth: past this, less than a float32 tells from none.
|
|
43
|
+
* @type {number}
|
|
44
|
+
*/
|
|
45
|
+
export const GROOM_SHELTER_OPAQUE = 32;
|
|
46
|
+
|
|
34
47
|
/**
|
|
35
48
|
* Strands of hair that share a point count, as they are at rest: a scalp, the brows, the lashes, a beard.
|
|
36
49
|
*
|
|
@@ -127,6 +140,28 @@ export class GroomGroup {
|
|
|
127
140
|
*/
|
|
128
141
|
guide_reach = 0;
|
|
129
142
|
|
|
143
|
+
/**
|
|
144
|
+
* How much hair stands between each guide's node and the open air along each of the group's axes
|
|
145
|
+
* (`groom_bake_shelter`): {@link GROOM_SHELTER_WORDS} depths a node, a guide's nodes in turn, guide after guide.
|
|
146
|
+
* A depth is the fibres' frontal area along the way out over the area crossed, a pure number, never past
|
|
147
|
+
* {@link GROOM_SHELTER_OPAQUE}.
|
|
148
|
+
* @type {Float32Array}
|
|
149
|
+
*/
|
|
150
|
+
guide_shelter = new Float32Array(0);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The area the group's strands cover seen from a direction, averaged over every direction, square metres
|
|
154
|
+
* (`groom_bake_shelter`): what of a wind the group stands in the way of.
|
|
155
|
+
* @type {number}
|
|
156
|
+
*/
|
|
157
|
+
silhouette = 0;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The length of every strand of the group, summed, metres.
|
|
161
|
+
* @type {number}
|
|
162
|
+
*/
|
|
163
|
+
fibre_length = 0;
|
|
164
|
+
|
|
130
165
|
/**
|
|
131
166
|
* @returns {number} guides the group has
|
|
132
167
|
*/
|
|
@@ -19,6 +19,20 @@ export function groom_write_group_v0(buffer: import("../../../core/binary/Binary
|
|
|
19
19
|
* @param {GroomGroup} group
|
|
20
20
|
*/
|
|
21
21
|
export function groom_write_guides(buffer: import("../../../core/binary/BinaryBuffer.js").BinaryBuffer, group: GroomGroup): void;
|
|
22
|
+
/**
|
|
23
|
+
* Write how a group shelters itself from the air, as version 2 follows its guides with it.
|
|
24
|
+
*
|
|
25
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
26
|
+
* @param {GroomGroup} group
|
|
27
|
+
*/
|
|
28
|
+
export function groom_write_shelter(buffer: import("../../../core/binary/BinaryBuffer.js").BinaryBuffer, group: GroomGroup): void;
|
|
29
|
+
/**
|
|
30
|
+
* Read a group's guides, as version 1 follows its version 0 fields with them.
|
|
31
|
+
*
|
|
32
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
33
|
+
* @param {GroomGroup} group
|
|
34
|
+
*/
|
|
35
|
+
export function groom_read_guides(buffer: import("../../../core/binary/BinaryBuffer.js").BinaryBuffer, group: GroomGroup): void;
|
|
22
36
|
/**
|
|
23
37
|
* A {@link Groom} as bytes: its groups, each as the renderer reads it, so a load is a copy and nothing is rebuilt.
|
|
24
38
|
*
|
|
@@ -26,9 +40,11 @@ export function groom_write_guides(buffer: import("../../../core/binary/BinaryBu
|
|
|
26
40
|
* the mean width (f32 each), the decimation table (a u8 count, then f32 each), the rest points (u32, `GROOM_POINT_WORDS`
|
|
27
41
|
* a point) and the strands' variation bytes; then its guides: the node count and the guide count (u32 each), each
|
|
28
42
|
* guide's strand and strand count (u32 each), wisp diameter and length (f32 each), each strand's guide (u16) and the
|
|
29
|
-
* reach (f32)
|
|
43
|
+
* reach (f32); then how it shelters itself from the air: its silhouette and its fibres' length (f32 each) and its
|
|
44
|
+
* guides' depths (f32, `GROOM_SHELTER_WORDS` a node). The group count (u32) leads.
|
|
30
45
|
*
|
|
31
|
-
* Version 0 had no guides; `GroomSerializationUpgrader_0_1` gives its groups theirs.
|
|
46
|
+
* Version 0 had no guides; `GroomSerializationUpgrader_0_1` gives its groups theirs. Version 1 had no shelter;
|
|
47
|
+
* `GroomSerializationUpgrader_1_2` works it out, with nothing solid about the hair.
|
|
32
48
|
*/
|
|
33
49
|
export class GroomSerializationAdapter extends BinaryClassSerializationAdapter<any> {
|
|
34
50
|
constructor();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroomSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/GroomSerializationAdapter.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,4CAHW,OAAO,sCAAsC,EAAE,YAAY,GACzD,UAAU,CAsBtB;AAED;;;;;GAKG;AACH,6CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAepB;AAED;;;;;GAKG;AACH,2CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAapB;
|
|
1
|
+
{"version":3,"file":"GroomSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/GroomSerializationAdapter.js"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,4CAHW,OAAO,sCAAsC,EAAE,YAAY,GACzD,UAAU,CAsBtB;AAED;;;;;GAKG;AACH,6CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAepB;AAED;;;;;GAKG;AACH,2CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAapB;AAED;;;;;GAKG;AACH,4CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAMpB;AAcD;;;;;GAKG;AACH,0CAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,UAAU,QAuBpB;AAED;;;;;;;;;;;;GAYG;AACH;;IACI,oBAAc;IAGd;;;OAGG;IACH,kBAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,KAAK,QAYf;IAED;;;OAGG;IACH,oBAHW,OAAO,sCAAsC,EAAE,YAAY,SAC3D,KAAK,QAkBf;CACJ;2BAlLyE,YAAY;gDADtC,6DAA6D;sBACnC,YAAY"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BinaryClassSerializationAdapter } from "../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
|
-
import { GROOM_POINT_WORDS, Groom, GroomGroup } from "./Groom.js";
|
|
2
|
+
import { GROOM_POINT_WORDS, GROOM_SHELTER_WORDS, Groom, GroomGroup } from "./Groom.js";
|
|
3
3
|
import { groom_root_spacing } from "./groom_root_spacing.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -71,10 +71,36 @@ export function groom_write_guides(buffer, group) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
+
* Write how a group shelters itself from the air, as version 2 follows its guides with it.
|
|
75
|
+
*
|
|
76
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
77
|
+
* @param {GroomGroup} group
|
|
78
|
+
*/
|
|
79
|
+
export function groom_write_shelter(buffer, group) {
|
|
80
|
+
buffer.writeFloat32(group.silhouette);
|
|
81
|
+
buffer.writeFloat32(group.fibre_length);
|
|
82
|
+
buffer.writeFloat32Array(group.guide_shelter, 0, group.guide_count * group.guide_point_count * GROOM_SHELTER_WORDS);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
87
|
+
* @param {GroomGroup} group with its guides
|
|
88
|
+
*/
|
|
89
|
+
function read_shelter(buffer, group) {
|
|
90
|
+
group.silhouette = buffer.readFloat32();
|
|
91
|
+
group.fibre_length = buffer.readFloat32();
|
|
92
|
+
|
|
93
|
+
group.guide_shelter = new Float32Array(group.guide_count * group.guide_point_count * GROOM_SHELTER_WORDS);
|
|
94
|
+
buffer.readFloat32Array(group.guide_shelter, 0, group.guide_shelter.length);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Read a group's guides, as version 1 follows its version 0 fields with them.
|
|
99
|
+
*
|
|
74
100
|
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
75
101
|
* @param {GroomGroup} group
|
|
76
102
|
*/
|
|
77
|
-
function
|
|
103
|
+
export function groom_read_guides(buffer, group) {
|
|
78
104
|
group.guide_point_count = buffer.readUint32();
|
|
79
105
|
|
|
80
106
|
const count = buffer.readUint32();
|
|
@@ -104,13 +130,15 @@ function read_guides(buffer, group) {
|
|
|
104
130
|
* the mean width (f32 each), the decimation table (a u8 count, then f32 each), the rest points (u32, `GROOM_POINT_WORDS`
|
|
105
131
|
* a point) and the strands' variation bytes; then its guides: the node count and the guide count (u32 each), each
|
|
106
132
|
* guide's strand and strand count (u32 each), wisp diameter and length (f32 each), each strand's guide (u16) and the
|
|
107
|
-
* reach (f32)
|
|
133
|
+
* reach (f32); then how it shelters itself from the air: its silhouette and its fibres' length (f32 each) and its
|
|
134
|
+
* guides' depths (f32, `GROOM_SHELTER_WORDS` a node). The group count (u32) leads.
|
|
108
135
|
*
|
|
109
|
-
* Version 0 had no guides; `GroomSerializationUpgrader_0_1` gives its groups theirs.
|
|
136
|
+
* Version 0 had no guides; `GroomSerializationUpgrader_0_1` gives its groups theirs. Version 1 had no shelter;
|
|
137
|
+
* `GroomSerializationUpgrader_1_2` works it out, with nothing solid about the hair.
|
|
110
138
|
*/
|
|
111
139
|
export class GroomSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
112
140
|
klass = Groom;
|
|
113
|
-
version =
|
|
141
|
+
version = 2;
|
|
114
142
|
|
|
115
143
|
/**
|
|
116
144
|
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} buffer
|
|
@@ -124,6 +152,7 @@ export class GroomSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
|
124
152
|
for (let g = 0; g < groups.length; g++) {
|
|
125
153
|
groom_write_group_v0(buffer, groups[g]);
|
|
126
154
|
groom_write_guides(buffer, groups[g]);
|
|
155
|
+
groom_write_shelter(buffer, groups[g]);
|
|
127
156
|
}
|
|
128
157
|
}
|
|
129
158
|
|
|
@@ -139,7 +168,8 @@ export class GroomSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
|
139
168
|
for (let g = 0; g < count; g++) {
|
|
140
169
|
const group = groom_read_group_v0(buffer);
|
|
141
170
|
|
|
142
|
-
|
|
171
|
+
groom_read_guides(buffer, group);
|
|
172
|
+
read_shelter(buffer, group);
|
|
143
173
|
|
|
144
174
|
// derived from the roots, so not written
|
|
145
175
|
group.root_spacing = groom_root_spacing(group);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A version 1 groom as version 2: each group and its guides as they were, followed by how it shelters itself from the
|
|
3
|
+
* air as `groom_bake_shelter` works it out with nothing solid about the hair.
|
|
4
|
+
*/
|
|
5
|
+
export class GroomSerializationUpgrader_1_2 extends BinaryClassUpgrader {
|
|
6
|
+
}
|
|
7
|
+
import { BinaryClassUpgrader } from "../../ecs/storage/binary/BinaryClassUpgrader.js";
|
|
8
|
+
//# sourceMappingURL=GroomSerializationUpgrader_1_2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GroomSerializationUpgrader_1_2.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/GroomSerializationUpgrader_1_2.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH;CA4BC;oCA3CmC,iDAAiD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BinaryClassUpgrader } from "../../ecs/storage/binary/BinaryClassUpgrader.js";
|
|
2
|
+
import { groom_bake_shelter } from "./groom_bake_shelter.js";
|
|
3
|
+
import { groom_root_spacing } from "./groom_root_spacing.js";
|
|
4
|
+
import {
|
|
5
|
+
groom_read_group_v0,
|
|
6
|
+
groom_read_guides,
|
|
7
|
+
groom_write_group_v0,
|
|
8
|
+
groom_write_guides,
|
|
9
|
+
groom_write_shelter
|
|
10
|
+
} from "./GroomSerializationAdapter.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A version 1 groom as version 2: each group and its guides as they were, followed by how it shelters itself from the
|
|
14
|
+
* air as `groom_bake_shelter` works it out with nothing solid about the hair.
|
|
15
|
+
*/
|
|
16
|
+
export class GroomSerializationUpgrader_1_2 extends BinaryClassUpgrader {
|
|
17
|
+
__startVersion = 1;
|
|
18
|
+
__targetVersion = 2;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} source
|
|
22
|
+
* @param {import("../../../core/binary/BinaryBuffer.js").BinaryBuffer} target
|
|
23
|
+
*/
|
|
24
|
+
upgrade(source, target) {
|
|
25
|
+
const count = source.readUint32();
|
|
26
|
+
|
|
27
|
+
target.writeUint32(count);
|
|
28
|
+
|
|
29
|
+
for (let g = 0; g < count; g++) {
|
|
30
|
+
const group = groom_read_group_v0(source);
|
|
31
|
+
|
|
32
|
+
groom_read_guides(source, group);
|
|
33
|
+
|
|
34
|
+
// not written, and what the bake takes its cells from
|
|
35
|
+
group.root_spacing = groom_root_spacing(group);
|
|
36
|
+
|
|
37
|
+
groom_bake_shelter(group, null);
|
|
38
|
+
|
|
39
|
+
groom_write_group_v0(target, group);
|
|
40
|
+
groom_write_guides(target, group);
|
|
41
|
+
groom_write_shelter(target, group);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work out how a group's hair shelters itself from the air, from its strands at rest: for every node of every guide,
|
|
3
|
+
* how much hair stands between it and the open air along each axis ({@link GroomGroup#guide_shelter}); and for the
|
|
4
|
+
* group, the area it stands in the wind's way with ({@link GroomGroup#silhouette}) and its fibres' length
|
|
5
|
+
* ({@link GroomGroup#fibre_length}). The guides are to be chosen already (`groom_build_guides`).
|
|
6
|
+
*
|
|
7
|
+
* **The hair as a density.** Every strand's frontal area, its length times the group's mean width, is laid into a
|
|
8
|
+
* grid a cell at a time, as frontal area a unit volume, and the grid is averaged with a 3 × 3 × 3 box so no one
|
|
9
|
+
* strand stands out of it. A cell is as wide as the wisp a guide stands for, the mean of the guides' diameters, or
|
|
10
|
+
* as the strands grow apart ({@link GroomGroup#root_spacing}) where that is wider, and wider still where the grid
|
|
11
|
+
* would pass {@link GROOM_SHELTER_CELL_LIMIT}.
|
|
12
|
+
*
|
|
13
|
+
* **A node's depths.** Air crossing hair is slowed by the fibres' drag: over a path whose frontal area a unit area
|
|
14
|
+
* crossed is `N`, a wind keeps `e^(−C_d N / 2)` of its speed, `C_d` a fibre's drag coefficient at that speed.
|
|
15
|
+
* A node keeps `N` along the way out toward each of +x, −x, +y, −y, +z and −z, from where it is to the grid's edge,
|
|
16
|
+
* and the wind's speed is applied by whoever reads them. A cell `solid` reaches into is one nothing passes
|
|
17
|
+
* (`shape3_voxelize_to_grid`), and a depth stops at {@link GROOM_SHELTER_OPAQUE}.
|
|
18
|
+
*
|
|
19
|
+
* **The silhouette.** The cells any strand passes through, seen along each axis, give three areas; the mean over
|
|
20
|
+
* every direction is taken of the ellipsoid with those three, whose area seen along a unit `n` is
|
|
21
|
+
* `√((A_x n_x)² + (A_y n_y)² + (A_z n_z)²)`.
|
|
22
|
+
*
|
|
23
|
+
* @param {import("./Groom.js").GroomGroup} group with its points and its guides
|
|
24
|
+
* @param {import("../../../core/geom/3d/shape/AbstractShape3D.js").AbstractShape3D|null} [solid] what the air does
|
|
25
|
+
* not pass, in the group's metres: the head the hair grows on
|
|
26
|
+
*/
|
|
27
|
+
export function groom_bake_shelter(group: import("./Groom.js").GroomGroup, solid?: import("../../../core/geom/3d/shape/AbstractShape3D.js").AbstractShape3D | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* The most cells the bake's grid has, a safety net: a group whose cells would be more takes larger ones.
|
|
30
|
+
* @type {number}
|
|
31
|
+
*/
|
|
32
|
+
export const GROOM_SHELTER_CELL_LIMIT: number;
|
|
33
|
+
//# sourceMappingURL=groom_bake_shelter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groom_bake_shelter.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/groom_bake_shelter.js"],"names":[],"mappings":"AA6CA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,0CAJW,OAAO,YAAY,EAAE,UAAU,UAC/B,OAAO,gDAAgD,EAAE,eAAe,GAAC,IAAI,QA2NvF;AA1RD;;;GAGG;AACH,uCAFU,MAAM,CAEgC"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { assert } from "../../../core/assert.js";
|
|
2
|
+
import { shape3_voxelize_to_grid } from "../../../core/geom/3d/shape/util/shape3_voxelize_to_grid.js";
|
|
3
|
+
import { sphere_fibonacci_point } from "../../../core/geom/3d/sphere/sphere_fibonacci_point.js";
|
|
4
|
+
import { GROOM_SHELTER_OPAQUE, GROOM_SHELTER_WORDS } from "./Groom.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The most cells the bake's grid has, a safety net: a group whose cells would be more takes larger ones.
|
|
8
|
+
* @type {number}
|
|
9
|
+
*/
|
|
10
|
+
export const GROOM_SHELTER_CELL_LIMIT = 1 << 24;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Directions the mean silhouette is taken over, evenly over the sphere.
|
|
14
|
+
*/
|
|
15
|
+
const SILHOUETTE_DIRECTIONS = 2048;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Average a grid with its two neighbours along one axis, `source` into `target`; past the grid there is nothing.
|
|
19
|
+
*
|
|
20
|
+
* @param {Float32Array} source
|
|
21
|
+
* @param {Float32Array} target
|
|
22
|
+
* @param {number} count cells
|
|
23
|
+
* @param {number} stride cells from a cell to its neighbour along the axis
|
|
24
|
+
* @param {number} size cells along the axis
|
|
25
|
+
*/
|
|
26
|
+
function blur_axis(source, target, count, stride, size) {
|
|
27
|
+
const span = stride * size;
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
const along = Math.floor((i % span) / stride);
|
|
31
|
+
|
|
32
|
+
let sum = source[i];
|
|
33
|
+
|
|
34
|
+
if (along > 0) {
|
|
35
|
+
sum += source[i - stride];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (along < size - 1) {
|
|
39
|
+
sum += source[i + stride];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
target[i] = sum / 3;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Work out how a group's hair shelters itself from the air, from its strands at rest: for every node of every guide,
|
|
48
|
+
* how much hair stands between it and the open air along each axis ({@link GroomGroup#guide_shelter}); and for the
|
|
49
|
+
* group, the area it stands in the wind's way with ({@link GroomGroup#silhouette}) and its fibres' length
|
|
50
|
+
* ({@link GroomGroup#fibre_length}). The guides are to be chosen already (`groom_build_guides`).
|
|
51
|
+
*
|
|
52
|
+
* **The hair as a density.** Every strand's frontal area, its length times the group's mean width, is laid into a
|
|
53
|
+
* grid a cell at a time, as frontal area a unit volume, and the grid is averaged with a 3 × 3 × 3 box so no one
|
|
54
|
+
* strand stands out of it. A cell is as wide as the wisp a guide stands for, the mean of the guides' diameters, or
|
|
55
|
+
* as the strands grow apart ({@link GroomGroup#root_spacing}) where that is wider, and wider still where the grid
|
|
56
|
+
* would pass {@link GROOM_SHELTER_CELL_LIMIT}.
|
|
57
|
+
*
|
|
58
|
+
* **A node's depths.** Air crossing hair is slowed by the fibres' drag: over a path whose frontal area a unit area
|
|
59
|
+
* crossed is `N`, a wind keeps `e^(−C_d N / 2)` of its speed, `C_d` a fibre's drag coefficient at that speed.
|
|
60
|
+
* A node keeps `N` along the way out toward each of +x, −x, +y, −y, +z and −z, from where it is to the grid's edge,
|
|
61
|
+
* and the wind's speed is applied by whoever reads them. A cell `solid` reaches into is one nothing passes
|
|
62
|
+
* (`shape3_voxelize_to_grid`), and a depth stops at {@link GROOM_SHELTER_OPAQUE}.
|
|
63
|
+
*
|
|
64
|
+
* **The silhouette.** The cells any strand passes through, seen along each axis, give three areas; the mean over
|
|
65
|
+
* every direction is taken of the ellipsoid with those three, whose area seen along a unit `n` is
|
|
66
|
+
* `√((A_x n_x)² + (A_y n_y)² + (A_z n_z)²)`.
|
|
67
|
+
*
|
|
68
|
+
* @param {import("./Groom.js").GroomGroup} group with its points and its guides
|
|
69
|
+
* @param {import("../../../core/geom/3d/shape/AbstractShape3D.js").AbstractShape3D|null} [solid] what the air does
|
|
70
|
+
* not pass, in the group's metres: the head the hair grows on
|
|
71
|
+
*/
|
|
72
|
+
export function groom_bake_shelter(group, solid = null) {
|
|
73
|
+
const strand_count = group.strand_count;
|
|
74
|
+
const point_count = group.point_count;
|
|
75
|
+
const guide_count = group.guide_count;
|
|
76
|
+
const node_count = group.guide_point_count;
|
|
77
|
+
|
|
78
|
+
assert.greaterThan(guide_count, 0, 'the group has guides');
|
|
79
|
+
|
|
80
|
+
const bounds = group.bounds;
|
|
81
|
+
|
|
82
|
+
let cell = 0;
|
|
83
|
+
|
|
84
|
+
for (let g = 0; g < guide_count; g++) {
|
|
85
|
+
cell += group.guide_diameter[g];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
cell = Math.max(cell / guide_count, group.root_spacing);
|
|
89
|
+
|
|
90
|
+
assert.greaterThan(cell, 0, 'cell');
|
|
91
|
+
|
|
92
|
+
const extent_x = bounds[3] - bounds[0];
|
|
93
|
+
const extent_y = bounds[4] - bounds[1];
|
|
94
|
+
const extent_z = bounds[5] - bounds[2];
|
|
95
|
+
|
|
96
|
+
// a cell of margin every side, which the averaging spills into
|
|
97
|
+
let nx = Math.ceil(extent_x / cell) + 3;
|
|
98
|
+
let ny = Math.ceil(extent_y / cell) + 3;
|
|
99
|
+
let nz = Math.ceil(extent_z / cell) + 3;
|
|
100
|
+
|
|
101
|
+
if (nx * ny * nz > GROOM_SHELTER_CELL_LIMIT) {
|
|
102
|
+
cell *= Math.cbrt(nx * ny * nz / GROOM_SHELTER_CELL_LIMIT);
|
|
103
|
+
|
|
104
|
+
nx = Math.ceil(extent_x / cell) + 3;
|
|
105
|
+
ny = Math.ceil(extent_y / cell) + 3;
|
|
106
|
+
nz = Math.ceil(extent_z / cell) + 3;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const origin_x = bounds[0] - cell;
|
|
110
|
+
const origin_y = bounds[1] - cell;
|
|
111
|
+
const origin_z = bounds[2] - cell;
|
|
112
|
+
|
|
113
|
+
const count = nx * ny * nz;
|
|
114
|
+
const stride_y = nx;
|
|
115
|
+
const stride_z = nx * ny;
|
|
116
|
+
|
|
117
|
+
let density = new Float32Array(count);
|
|
118
|
+
let scratch = new Float32Array(count);
|
|
119
|
+
|
|
120
|
+
// what the strands cover, seen along x, y and z
|
|
121
|
+
const cover_x = new Uint8Array(ny * nz);
|
|
122
|
+
const cover_y = new Uint8Array(nx * nz);
|
|
123
|
+
const cover_z = new Uint8Array(nx * ny);
|
|
124
|
+
|
|
125
|
+
const a = [0, 0, 0];
|
|
126
|
+
const b = [0, 0, 0];
|
|
127
|
+
|
|
128
|
+
const frontal = group.width_mean / (cell * cell * cell);
|
|
129
|
+
|
|
130
|
+
let fibre_length = 0;
|
|
131
|
+
|
|
132
|
+
for (let s = 0; s < strand_count; s++) {
|
|
133
|
+
group.read_point(a, 0, s, 0);
|
|
134
|
+
|
|
135
|
+
for (let i = 1; i < point_count; i++) {
|
|
136
|
+
group.read_point(b, 0, s, i);
|
|
137
|
+
|
|
138
|
+
const dx = b[0] - a[0];
|
|
139
|
+
const dy = b[1] - a[1];
|
|
140
|
+
const dz = b[2] - a[2];
|
|
141
|
+
|
|
142
|
+
const length = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
143
|
+
|
|
144
|
+
fibre_length += length;
|
|
145
|
+
|
|
146
|
+
// pieces no longer than half a cell, each laid where its middle is
|
|
147
|
+
const pieces = Math.max(1, Math.ceil(2 * length / cell));
|
|
148
|
+
const share = frontal * length / pieces;
|
|
149
|
+
|
|
150
|
+
for (let k = 0; k < pieces; k++) {
|
|
151
|
+
const t = (k + 0.5) / pieces;
|
|
152
|
+
|
|
153
|
+
const x = Math.floor((a[0] + dx * t - origin_x) / cell);
|
|
154
|
+
const y = Math.floor((a[1] + dy * t - origin_y) / cell);
|
|
155
|
+
const z = Math.floor((a[2] + dz * t - origin_z) / cell);
|
|
156
|
+
|
|
157
|
+
density[x + stride_y * y + stride_z * z] += share;
|
|
158
|
+
|
|
159
|
+
cover_x[y + ny * z] = 1;
|
|
160
|
+
cover_y[x + nx * z] = 1;
|
|
161
|
+
cover_z[x + nx * y] = 1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
a[0] = b[0];
|
|
165
|
+
a[1] = b[1];
|
|
166
|
+
a[2] = b[2];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
blur_axis(density, scratch, count, 1, nx);
|
|
171
|
+
blur_axis(scratch, density, count, stride_y, ny);
|
|
172
|
+
blur_axis(density, scratch, count, stride_z, nz);
|
|
173
|
+
|
|
174
|
+
const swap = density;
|
|
175
|
+
|
|
176
|
+
density = scratch;
|
|
177
|
+
scratch = swap;
|
|
178
|
+
|
|
179
|
+
if (solid !== null) {
|
|
180
|
+
// a cell's index to its middle, and back
|
|
181
|
+
const grid_to_world = new Float64Array(16);
|
|
182
|
+
const world_to_grid = new Float64Array(16);
|
|
183
|
+
|
|
184
|
+
grid_to_world[0] = grid_to_world[5] = grid_to_world[10] = cell;
|
|
185
|
+
grid_to_world[12] = origin_x + 0.5 * cell;
|
|
186
|
+
grid_to_world[13] = origin_y + 0.5 * cell;
|
|
187
|
+
grid_to_world[14] = origin_z + 0.5 * cell;
|
|
188
|
+
grid_to_world[15] = 1;
|
|
189
|
+
|
|
190
|
+
world_to_grid[0] = world_to_grid[5] = world_to_grid[10] = 1 / cell;
|
|
191
|
+
world_to_grid[12] = -grid_to_world[12] / cell;
|
|
192
|
+
world_to_grid[13] = -grid_to_world[13] / cell;
|
|
193
|
+
world_to_grid[14] = -grid_to_world[14] / cell;
|
|
194
|
+
world_to_grid[15] = 1;
|
|
195
|
+
|
|
196
|
+
const inside = new Uint8Array(count);
|
|
197
|
+
|
|
198
|
+
shape3_voxelize_to_grid(solid, world_to_grid, grid_to_world, inside, nx, ny, nz);
|
|
199
|
+
|
|
200
|
+
for (let i = 0; i < count; i++) {
|
|
201
|
+
if (inside[i] !== 0) {
|
|
202
|
+
density[i] = Infinity;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const shelter = new Float32Array(guide_count * node_count * GROOM_SHELTER_WORDS);
|
|
208
|
+
const stride = (point_count - 1) / (node_count - 1);
|
|
209
|
+
|
|
210
|
+
const sizes = [nx, ny, nz];
|
|
211
|
+
const strides = [1, stride_y, stride_z];
|
|
212
|
+
const place = [0, 0, 0];
|
|
213
|
+
const index = [0, 0, 0];
|
|
214
|
+
|
|
215
|
+
for (let g = 0; g < guide_count; g++) {
|
|
216
|
+
const strand = group.guide_strand[g];
|
|
217
|
+
|
|
218
|
+
for (let i = 0; i < node_count; i++) {
|
|
219
|
+
group.read_point(a, 0, strand, i * stride);
|
|
220
|
+
|
|
221
|
+
place[0] = (a[0] - origin_x) / cell;
|
|
222
|
+
place[1] = (a[1] - origin_y) / cell;
|
|
223
|
+
place[2] = (a[2] - origin_z) / cell;
|
|
224
|
+
|
|
225
|
+
index[0] = Math.floor(place[0]);
|
|
226
|
+
index[1] = Math.floor(place[1]);
|
|
227
|
+
index[2] = Math.floor(place[2]);
|
|
228
|
+
|
|
229
|
+
const home = index[0] + stride_y * index[1] + stride_z * index[2];
|
|
230
|
+
const at = (g * node_count + i) * GROOM_SHELTER_WORDS;
|
|
231
|
+
|
|
232
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
233
|
+
const within = place[axis] - index[axis];
|
|
234
|
+
|
|
235
|
+
for (let side = 0; side < 2; side++) {
|
|
236
|
+
const step = side === 0 ? strides[axis] : -strides[axis];
|
|
237
|
+
const cells = side === 0 ? sizes[axis] - 1 - index[axis] : index[axis];
|
|
238
|
+
|
|
239
|
+
// what is left of the node's own cell, then every cell to the edge
|
|
240
|
+
let depth = density[home] * cell * (side === 0 ? 1 - within : within);
|
|
241
|
+
|
|
242
|
+
for (let k = 1; k <= cells && depth < GROOM_SHELTER_OPAQUE; k++) {
|
|
243
|
+
depth += density[home + step * k] * cell;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// a node inside something solid is no depth of nothing: opaque as well
|
|
247
|
+
shelter[at + axis * 2 + side] = depth < GROOM_SHELTER_OPAQUE ? depth : GROOM_SHELTER_OPAQUE;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let area_x = 0;
|
|
254
|
+
let area_y = 0;
|
|
255
|
+
let area_z = 0;
|
|
256
|
+
|
|
257
|
+
for (let i = 0; i < cover_x.length; i++) {
|
|
258
|
+
area_x += cover_x[i];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (let i = 0; i < cover_y.length; i++) {
|
|
262
|
+
area_y += cover_y[i];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
for (let i = 0; i < cover_z.length; i++) {
|
|
266
|
+
area_z += cover_z[i];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
area_x *= cell * cell;
|
|
270
|
+
area_y *= cell * cell;
|
|
271
|
+
area_z *= cell * cell;
|
|
272
|
+
|
|
273
|
+
let silhouette = 0;
|
|
274
|
+
|
|
275
|
+
for (let i = 0; i < SILHOUETTE_DIRECTIONS; i++) {
|
|
276
|
+
sphere_fibonacci_point(a, 0, i, SILHOUETTE_DIRECTIONS);
|
|
277
|
+
|
|
278
|
+
const sx = area_x * a[0];
|
|
279
|
+
const sy = area_y * a[1];
|
|
280
|
+
const sz = area_z * a[2];
|
|
281
|
+
|
|
282
|
+
silhouette += Math.sqrt(sx * sx + sy * sy + sz * sz);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
group.guide_shelter = shelter;
|
|
286
|
+
group.silhouette = silhouette / SILHOUETTE_DIRECTIONS;
|
|
287
|
+
group.fibre_length = fibre_length;
|
|
288
|
+
}
|