3D engine that AI agents drive
Keep agent-scene within 8 bytes: one table for the liquid optics defaults and ranges
Nguyen Xuan Anf6b39c9777ca
diff --git a/src/liquid-optics.js b/src/liquid-optics.jsindex 68d51a31..a2063826 100644--- a/src/liquid-optics.js+++ b/src/liquid-optics.js@@ -1,9 +1,22 @@// The liquid and foam optics a frame may set. Kept apart from the liquid pass so the recipe look can check them without the pass.-const DEFAULT_LIQUID = Object.freeze({ thickness: 0.5, ior: 1.33, refraction: 1, scattering: 1, foamOpacity: 0.55, foamSoftness: 1 });+// Each entry is [default, minimum, maximum].+const LIQUID_OPTICS = {+ thickness: [0.5, 0, 100],+ ior: [1.33, 1, 3],+ refraction: [1, 0, 4],+ scattering: [1, 0, 10],+ foamOpacity: [0.55, 0, 1],+ foamSoftness: [1, 0, 1],+};export function resolveLiquidOptics(options = {}) {- const optics = { ...DEFAULT_LIQUID, ...options };- for (const [name, minimum, maximum] of [['thickness', 0, 100], ['ior', 1, 3], ['refraction', 0, 4], ['scattering', 0, 10], ['foamOpacity', 0, 1], ['foamSoftness', 0, 1]]) {+ const optics = {};+ for (const name in LIQUID_OPTICS) {+ optics[name] = LIQUID_OPTICS[name][0];+ }+ Object.assign(optics, options);+ for (const name in LIQUID_OPTICS) {+ const [, minimum, maximum] = LIQUID_OPTICS[name];const value = optics[name];if (typeof value !== 'number' || !Number.isFinite(value) || value < minimum || value > maximum) throw new RangeError(`liquid.${name} must be between ${minimum} and ${maximum}.`);}