Resources Numerical accuracy Calculation policy

Photo material settings

Keeps the tile size, roughness and bump strength of a material made from a photo, as they are saved in the file.

How the precision is kept

Roughness and bump are limited to their ranges and rounded to two decimals before they are stored. The tile size is limited to 0.01 to 100 meters and stored as typed.

Calculations under this policy

1 calculation in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.

photo-materials.js BimCraft 0.8.1 64-bit 1 calculation Reviewed

Tests tools/bimcraft-test/photo-material-test.mjs

Stored size, roughness and bump

64-bit

The 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).

  • photo-materials.js
  • lines 58 to 67
  • BimCraft 0.8.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 };
}

In detail

Method
rough = round(clamp(x, 0, 1) × 100) ÷ 100; bump = round(clamp(x, 0, 4) × 100) ÷ 100; size = clamp(x, 0.01, 100) m.
Number types
64-bit numbers; the picture itself is 8-bit.
Tolerances
Ranges: roughness 0 to 1, bump 0 to 4, size 0.01 to 100 m.
Limits
A roughness of 0.655 is stored as 0.66 or 0.65 depending on how the product with 100 rounds in binary. The mean color is 8-bit per channel.

Approach: 64-bit, direct

Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.

Every policy that takes this approach