@selvajs/visualization 1.7.0-beta.0 → 1.7.1-beta.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/dist/parse.cjs +60 -15
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.d.cts +3 -2
- package/dist/parse.d.ts +3 -2
- package/dist/parse.js +60 -15
- package/dist/parse.js.map +1 -1
- package/package.json +1 -1
package/dist/parse.cjs
CHANGED
|
@@ -75,10 +75,24 @@ function cloneSceneObjects(meshes) {
|
|
|
75
75
|
function releaseSceneObjects(meshes) {
|
|
76
76
|
meshes.forEach((root) => require_gpu_dispose.disposeObjectTree(root, { materials: false }));
|
|
77
77
|
}
|
|
78
|
+
/** Geometry bytes only: the memo's copies share materials and textures with the live scene. */
|
|
79
|
+
function sceneObjectsByteSize(meshes) {
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
const seen = /* @__PURE__ */ new Set();
|
|
82
|
+
for (const root of meshes) root.traverse((child) => {
|
|
83
|
+
const geometry = child.geometry;
|
|
84
|
+
if (!geometry || seen.has(geometry)) return;
|
|
85
|
+
seen.add(geometry);
|
|
86
|
+
for (const attribute of Object.values(geometry.attributes)) bytes += attribute.array.byteLength;
|
|
87
|
+
if (geometry.index) bytes += geometry.index.array.byteLength;
|
|
88
|
+
});
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
78
91
|
/** Structurally, not nominally, typed as `@selvajs/solve/client`'s `MeshPolicy<THREE.Object3D>` — avoids a dependency on solve. */
|
|
79
92
|
const meshPolicy = {
|
|
80
93
|
clone: cloneSceneObjects,
|
|
81
|
-
release: releaseSceneObjects
|
|
94
|
+
release: releaseSceneObjects,
|
|
95
|
+
byteSize: sceneObjectsByteSize
|
|
82
96
|
};
|
|
83
97
|
/** Opacity < 1 flips `transparent` on. */
|
|
84
98
|
function materialParams(color, opacity) {
|
|
@@ -1684,29 +1698,58 @@ function applyTexture(material, url, slot, mapSize) {
|
|
|
1684
1698
|
const f$1 = (n) => n.toFixed(4);
|
|
1685
1699
|
const PITH = 120;
|
|
1686
1700
|
const PITH_SPREAD = 120;
|
|
1687
|
-
const PLANK =
|
|
1701
|
+
const PLANK = 160;
|
|
1702
|
+
const SEAM_JITTER = .7;
|
|
1688
1703
|
const LEAN = .0105;
|
|
1704
|
+
const BOARD_SHADE = .14;
|
|
1705
|
+
const PORE_ROW = .35;
|
|
1706
|
+
const PORE_FILL = .3;
|
|
1707
|
+
const PORE_DARK = .4;
|
|
1708
|
+
const PORE_MEAN = PORE_FILL * .7 * .42;
|
|
1709
|
+
const seam = (k) => `( ( ${k} ) + ( selvaHash( vec2( ${k}, 6.0 ) ) - 0.5 ) * ${f$1(SEAM_JITTER)} ) * ${f$1(PLANK)}`;
|
|
1689
1710
|
const wood = ({ ring, latewood, band, pores, streaks }) => `
|
|
1690
|
-
float
|
|
1691
|
-
float
|
|
1711
|
+
float cell = floor( uv.y / ${f$1(PLANK)} );
|
|
1712
|
+
float plank = cell + ( uv.y < ${seam("cell")} ? -1.0 : ( uv.y >= ${seam("cell + 1.0")} ? 1.0 : 0.0 ) );
|
|
1713
|
+
float lo = ${seam("plank")};
|
|
1714
|
+
float hi = ${seam("plank + 1.0")};
|
|
1715
|
+
// Each plank starts somewhere else along its log.
|
|
1716
|
+
float along = uv.x + selvaHash( vec2( plank, 9.0 ) ) * 5000.0;
|
|
1717
|
+
// The pith lies anywhere under the plank, sometimes past its edge, which leaves straight
|
|
1718
|
+
// rift grain on that side.
|
|
1719
|
+
float heart = mix( lo, hi, selvaHash( vec2( plank, 3.0 ) ) * 1.6 - 0.3 );
|
|
1720
|
+
heart += ( selvaNoise( vec2( along * 0.0006, plank * 7.0 ) ) - 0.5 ) * 50.0;
|
|
1721
|
+
float s = uv.y - heart;
|
|
1692
1722
|
float pith = ${f$1(PITH)} + selvaHash( vec2( plank, 2.0 ) ) * ${f$1(PITH_SPREAD)};
|
|
1723
|
+
pith += ( selvaFbm( vec2( along * 0.0004, plank * 5.0 + 1.0 ) ) - 0.5 ) * ${f$1(50)};
|
|
1724
|
+
float lean = ${f$1(LEAN)} * ( 0.5 + selvaHash( vec2( plank, 8.0 ) ) );
|
|
1693
1725
|
// Rings wander a few mm and vary in spacing, as growth does from year to year.
|
|
1694
|
-
float wander = ( selvaFbm(
|
|
1695
|
-
float r = sqrt( pith * pith + s * s ) +
|
|
1726
|
+
float wander = ( selvaFbm( vec2( along * 0.003, uv.y * 0.008 ) ) - 0.5 ) * ${f$1(ring * 2)};
|
|
1727
|
+
float r = sqrt( pith * pith + s * s ) + along * lean + wander;
|
|
1696
1728
|
r += selvaFbm( vec2( r * 0.02, plank ) ) * ${f$1(ring * 3)} + selvaHash( vec2( plank, 1.0 ) ) * ${f$1(ring * 20)};
|
|
1697
1729
|
float year = fract( r / ${f$1(ring)} );
|
|
1698
1730
|
float late = smoothstep( ${f$1(1 - band)}, ${f$1(1 - band * .4)}, year ) * ( 1.0 - smoothstep( 0.95, 1.0, year ) );
|
|
1699
1731
|
// Open-pored wood shows its rings as a broken band of pores, not a clean line.
|
|
1700
|
-
|
|
1732
|
+
float broken = 1.0 - smoothstep( 0.3, 0.7, selvaNoise( uv * vec2( 0.25, 2.0 ) ) );
|
|
1733
|
+
late *= 1.0 - ${f$1(pores * .45)} * mix( 0.5, broken, selvaDetail( 0.5 ) );
|
|
1701
1734
|
late *= selvaDetail( ${f$1(ring)} );
|
|
1702
1735
|
float fibre = ( selvaNoise( uv * vec2( 0.04, 1.6 ) ) - 0.5 ) * selvaDetail( 1.0 );
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
float
|
|
1706
|
-
float
|
|
1707
|
-
|
|
1736
|
+
// Pores: thin dashes along the grain, most of each row empty. Smaller than a pixel they
|
|
1737
|
+
// show as their average shade, or they would be static.
|
|
1738
|
+
float poreRow = floor( uv.y / ${f$1(PORE_ROW)} );
|
|
1739
|
+
float poreAlong = uv.x / mix( 1.5, 5.0, selvaHash( vec2( poreRow, 11.0 ) ) ) + selvaHash( vec2( poreRow, 12.0 ) );
|
|
1740
|
+
float poreT = fract( poreAlong );
|
|
1741
|
+
float pore = step( ${f$1(.7)}, selvaHash( vec2( poreRow, 13.0 + 1.618 * floor( poreAlong ) ) ) );
|
|
1742
|
+
pore *= smoothstep( 0.0, 0.3, poreT ) * smoothstep( 1.0, 0.7, poreT );
|
|
1743
|
+
pore *= 1.0 - smoothstep( 0.12, 0.3, abs( fract( uv.y / ${f$1(PORE_ROW)} ) - 0.5 ) );
|
|
1744
|
+
pore = mix( ${f$1(PORE_MEAN)}, pore, selvaDetail( ${f$1(PORE_ROW)} ) ) * ${f$1(pores)} * ( 1.0 - 0.6 * late );
|
|
1745
|
+
float streak = ( selvaFbm( vec2( along * 0.0015, uv.y * 0.012 ) ) - 0.5 ) * ${f$1(streaks)};
|
|
1746
|
+
float shade = 1.0 + ${f$1(latewood * band)} - late * ${f$1(latewood)} + fibre * 0.1 - pore * ${f$1(PORE_DARK)} + streak * 0.6;
|
|
1747
|
+
float board = ( selvaHash( vec2( plank, 4.0 ) ) - 0.5 ) * selvaDetail( ${f$1(PLANK * .5)} );
|
|
1748
|
+
float warmth = ( selvaHash( vec2( plank, 5.0 ) ) - 0.5 ) * selvaDetail( ${f$1(PLANK * .5)} );
|
|
1749
|
+
tone = vec3( shade ) * ( 1.0 + board * ${f$1(BOARD_SHADE)} ) * vec3( 1.0 + warmth * 0.06, 1.0, 1.0 - warmth * 0.06 );
|
|
1708
1750
|
gloss = 1.0 + late * 0.08 + pore * 0.4 - fibre * 0.2;
|
|
1709
|
-
|
|
1751
|
+
// No relief from pores: a bump from screen derivatives beads any dash under a few pixels wide.
|
|
1752
|
+
height = fibre * 0.00008 * selvaDetail( 0.6 );`;
|
|
1710
1753
|
/**
|
|
1711
1754
|
* Procedural surfaces, so a preset looks like its material with no texture files to ship or upload.
|
|
1712
1755
|
* UVs are millimetres, so a brick is brick-sized at any model scale. Each recipe sets `tone` (albedo
|
|
@@ -2016,6 +2059,7 @@ const RECIPES = {
|
|
|
2016
2059
|
};
|
|
2017
2060
|
const TILT = .6;
|
|
2018
2061
|
const FIBRE_FADE = .35;
|
|
2062
|
+
const FIBRE_ASPECT = 16;
|
|
2019
2063
|
const f = (n) => n.toFixed(4);
|
|
2020
2064
|
/** The shader patch for a finish, or null when it would draw nothing. `key` extends the program cache key. */
|
|
2021
2065
|
function finishPatch(finish, strength) {
|
|
@@ -2047,7 +2091,8 @@ function finishPatch(finish, strength) {
|
|
|
2047
2091
|
// of the part. depth * |depth| keeps most fibres faint and a few deep.
|
|
2048
2092
|
float selvaFibreRow( vec2 uv, float pitch, vec2 len, float seed ) {
|
|
2049
2093
|
float row = floor( uv.y / pitch );
|
|
2050
|
-
|
|
2094
|
+
// A coarse cell stays a streak: as wide as it is long it reads as speckle, not grain.
|
|
2095
|
+
float l = max( mix( len.x, len.y, selvaHash( vec2( row, seed + 1.0 ) ) ), pitch * ${f(FIBRE_ASPECT)} );
|
|
2051
2096
|
float along = uv.x / l + selvaHash( vec2( row, seed + 2.0 ) );
|
|
2052
2097
|
float seg = floor( along );
|
|
2053
2098
|
float depth = selvaHash( vec2( row, seed + 3.0 + 1.618 * seg ) ) * 2.0 - 1.0;
|
|
@@ -2159,7 +2204,7 @@ function createMaterial(matData, options) {
|
|
|
2159
2204
|
}
|
|
2160
2205
|
if (matData.anisotropy != null && matData.anisotropy > 0 && options?.hasUvs) {
|
|
2161
2206
|
material.anisotropy = matData.anisotropy;
|
|
2162
|
-
material.anisotropyRotation = matData.anisotropyRotation ?? 0;
|
|
2207
|
+
material.anisotropyRotation = (matData.anisotropyRotation ?? 0) + Math.PI / 2;
|
|
2163
2208
|
}
|
|
2164
2209
|
if (matData.ior != null) material.ior = matData.ior;
|
|
2165
2210
|
if (matData.transmission != null && matData.transmission > 0) applyGlass(material, matData);
|