Resources Numerical accuracy Calculation policy

Focus distance picked in the view

The focus distance set by clicking a point in the live rendered view.

How the precision is kept

The ray through the clicked pixel is built from the packed scene's header, read as a Float32Array, and is cast against the packed triangles, which pt-pack.js stores in Float32Array records. The distance along the view direction is rounded to 0.01 m, saved in the render settings and shown in the status line.

Open item. Cast the focus ray against the scene's 64-bit geometry, or state in the dialog that the picked distance is a 0.01 m value taken from 32-bit render data.

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.

render/ipr.js BimCraft 0.8.1 32-bit in part 1 calculation Reviewed

Tests None found by the review

Picked focus distance

32-bit in part

The distance from the camera to the clicked surface, measured along the view direction.

focus = round(−(d · view axis ÷ |view axis|) × t × 100) ÷ 100

The camera matrices are read from a Float32Array view of the header, and the triangles the ray is cast against are stored in a Float32Array by the scene packer, so the hit distance carries 32-bit inputs. The value saved and shown is rounded to 0.01 m.

  • render/ipr.js
  • lines 129 to 143
  • BimCraft 0.8.1
function pickFocus(x, y) {
  // the ray through that pixel (the pack's own camera) → the distance it travels to the first surface
  const hu = new Uint32Array(pk.header), hf = new Float32Array(pk.header), ro = [0, 0, 0], rd = [0, 0, 0], hit = {};
  const lens = hf[87]; hf[87] = 0;   // a pinhole ray from the middle of the lens
  cameraRay(hf, hu, x, y, canvas.width, canvas.height, 0, 0, 0, 0, 0, ro, rd);
  hf[87] = lens;
  const sc = sceneFromV2({ records: new Uint32Array(pk.nodes.buffer, pk.nodes.byteOffset, pk.nodes.length), tris: pk.tris, header: { 3: hu[3], 62: hu[62], 63: hu[63] } });
  if (!sceneHit(sc, ro, rd, 1e30, hit) || !(hit.t > 0)) { status(o.t('render.ipr.focus.none')); return; }
  // the distance along the view direction (the focus plane is square to it)
  const fl = Math.hypot(hf[24], hf[25], hf[26]) || 1, along = -(rd[0] * hf[24] + rd[1] * hf[25] + rd[2] * hf[26]) / fl * hit.t;
  const s = { ...o.settings(), dof: true, focus: Math.round(along * 100) / 100 };
  o.save?.(cleanSettings(s));
  status(o.t('render.ipr.focus.set', { m: (Math.round(along * 100) / 100).toString() }));
  api.mode = 'view';
}

In detail

Method
A camera ray through the pixel, the nearest triangle hit through the packed scene's hierarchy, then the hit distance projected onto the view direction.
Number types
Camera matrices and triangles read from 32-bit arrays; the arithmetic on them is 64-bit.
Tolerances
The result is rounded to 0.01 m.
Limits
The distance carries the 32-bit camera and triangle coordinates before it is rounded.

Approach: 32-bit step, flagged

One step stores or exchanges 32-bit values that reach a number a person reads. It is listed here with its open item, and the step is either moved to 64-bit or the app will warn where the number is read.

Every policy that takes this approach