Resources Numerical accuracy Calculation policy

Library 3D preview

The 3D view of an item on its Library page and on the configure page.

How the precision is kept

The item's body is copied into 32-bit vertex buffers for the graphics processor and drawn with the three.js library the page loads. Nothing computed here is shown as a number, saved or exported.

Calculations under this policy

3 calculations in 2 source files. 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.

library-3d.js Shared shell, every app 32-bit, display only 2 calculations Reviewed

Tests None found by the review

Mesh buffers

32-bit, display only

The item's box or mesh as geometry for drawing, turned from z up to y up.

Positions are copied into a Float32Array with the y and z axes exchanged and one sign changed. The buffer only feeds the graphics processor.

  • library-3d.js
  • lines 37 to 58
// Body (x, y, z up) → three.js (x, Y up = z, Z = -y): the plan's front (-Y) faces the viewer.
function geometry(THREE) {
  if (data.type === 'box') {
    const g = new THREE.BoxGeometry(data.w, data.h, data.d);
    g.translate(data.x + data.w / 2, data.z + data.h / 2, -(data.y + data.d / 2));
    return g;
  }
  if (data.type === 'mesh') {
    const g = new THREE.BufferGeometry();
    const p = new Float32Array((data.positions.length / 3) * 3);
    for (let i = 0; i < data.positions.length; i += 3) {
      p[i] = data.positions[i];
      p[i + 1] = data.positions[i + 2];
      p[i + 2] = -data.positions[i + 1];
    }
    g.setAttribute('position', new THREE.BufferAttribute(p, 3));
    g.setIndex(data.indices);
    g.computeVertexNormals();
    return g;
  }
  return null;
}

Camera position

32-bit, display only

Where the camera sits as the view is turned and zoomed.

position = target + dist × (sin φ sin θ, cos φ, sin φ cos θ)

Spherical coordinates in 64-bit, handed to three.js for drawing only.

  • library-3d.js
  • lines 90 to 95
const place = () => {
  const sp = Math.sin(phi);
  camera.position.set(target.x + dist * sp * Math.sin(theta), target.y + dist * Math.cos(phi), target.z + dist * sp * Math.cos(theta));
  camera.lookAt(target);
  renderer.render(scene, camera);
};
library-configurator.js Shared shell, every app 32-bit, display only 1 calculation Reviewed

Tests None found by the review

Variant body buffers

32-bit, display only

The chosen variant's box or mesh as geometry for drawing.

A box becomes a three.js box moved to its corner position; a mesh goes into a 32-bit buffer attribute. Used for drawing only.

  • library-configurator.js
  • lines 145 to 156
function geometryOf(body) {
  const g = new THREE.BufferGeometry();
  if (body.type === 'box') {
    const { x, y, z, w, d, h } = body;
    const bg = new THREE.BoxGeometry(w, d, h); bg.translate(x + w / 2, y + d / 2, z + h / 2);
    return bg;
  }
  g.setAttribute('position', new THREE.Float32BufferAttribute(body.positions, 3));
  g.setIndex(body.indices);
  g.computeVertexNormals();
  return g;
}

In detail

Method
A box or a triangle mesh from the item data, vertex normals from three.js, an orbiting camera.
Number types
Float32Array vertex buffers; 64-bit camera angles and distance.

Approach: Display only

Computed to draw the screen, often in 32-bit on the graphics processor. No number a person reads, saves or exports comes from it.

Every policy that takes this approach