Stored size, roughness and bump
64-bitThe numbers saved with a photo material.
x = round(clamp(x) × 100) ÷ 100
Each is clamped, then multiplied by 100, rounded with Math.round and divided by 100, so the saved value has at most two decimals. A value that is not finite is replaced by the default (size 1, roughness 0.65, bump 1).
/** One photo (raw pixels, photo-material.js decodePhoto) → the record for the file, plus the three maps for showing it. */
export function makeFromPhoto(photo, { name = '', size = 1, id = null, ...opts } = {}) {
const tile = Math.min(100, Math.max(0.01, Number.isFinite(size) ? size : 1));
const r = fromPhoto(photo, opts);
const title = String(name || 'Photo material').trim().slice(0, 80) || 'Photo material';
const rough = Math.round((Number.isFinite(opts.roughness) ? Math.min(1, Math.max(0, opts.roughness)) : 0.65) * 100) / 100;
const bump = Math.round((Number.isFinite(opts.bump) ? Math.min(4, Math.max(0, opts.bump)) : 1) * 100) / 100;
const record = { id: id || newId(), name: title, size: tile, rough, bump, color: r.stats.meanColor, png: toBase64(pngBytes(r.color.w, r.color.h, rgbOf(r.color))) };
return { record, maps: { color: r.color, roughness: r.roughness, normal: r.normal }, stats: r.stats, notes: r.notes };
}