Turns tessellated curves and surfaces into the buffers the 3D view draws, with zebra stripes and curvature colors.
How the precision is kept
Positions, normals, parameters and colors are copied into Float32Arrays for the graphics card after scaling to the host's units. These 32-bit copies are only drawn; the numbers behind them stay in the NURBS library's 64-bit arrays.
Calculations under this policy
2 calculations 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.
The positions of a polyline in the host's units, for drawing.
Each coordinate is multiplied by the host scale and stored in a Float32Array handed to the graphics library. Nothing reads it back as a measurement.
nurbs-ui/display.js
lines 36 to 41
ModelCraft 0.8.1
line(points, color) {
const T = this.T, s = this.scale, a = new Float32Array(points.length * 3);
points.forEach((p, i) => { a[i * 3] = p[0] * s; a[i * 3 + 1] = p[1] * s; a[i * 3 + 2] = (p[2] || 0) * s; });
const g = new T.BufferGeometry(); g.setAttribute('position', new T.BufferAttribute(a, 3));
return new T.Line(g, this.mat('line', color));
}
Surface mesh buffers
32-bit, display only
The positions, normals, parameters and colors of a surface's triangles, for drawing.
Positions are scaled and copied to a Float32Array, normals and parameters likewise; the 64-bit normals and curvature values are kept beside the mesh for the zebra and curvature colors.
nurbs-ui/display.js
lines 42 to 65
ModelCraft 0.8.1
surfaceMesh(it, mode, tol) {
const T = this.T, s = this.scale, N = this.N;
const tess = it.trim ? N.trim.tessellate(it.surface, it.trim, { tol, curvature: mode === 'curvature' }) // 0.8 DC.54 S2: cut along the trim loops
: mode === 'curvature' ? N.analysis.maps(it.surface, { tol }) : N.surface.tessellate(it.surface, { tol });
const n = tess.positions.length / 3, pos = new Float32Array(n * 3), nor = new Float32Array(n * 3);
for (let i = 0; i < n * 3; i++) { pos[i] = tess.positions[i] * s; nor[i] = tess.normals[i]; }
const g = new T.BufferGeometry();
g.setAttribute('position', new T.BufferAttribute(pos, 3));
g.setAttribute('normal', new T.BufferAttribute(nor, 3)); // the surface's own normals: kept
g.setAttribute('uv', new T.BufferAttribute(Float32Array.from(tess.uvs), 2));
g.setIndex(new T.BufferAttribute(tess.indices, 1));
let material;
if (mode === 'shaded') material = this.mat('mesh', COL.surface);
else {
const col = new Float32Array(n * 3);
g.setAttribute('color', new T.BufferAttribute(col, 3));
material = this.mat('mesh', 0xffffff, { vertexColors: true, roughness: 1, metalness: 0 });
if (mode === 'curvature') g.userData.K = tess.K;
}
const m = new T.Mesh(g, material);
m.userData.nurbs = { id: it.id, kind: 'surface' };
m.userData.normals = tess.normals;
return m;
}
In detail
Method
Lines from curve.tessellate, meshes from surface.tessellate or trim.tessellate with the surface's own normals, colors from the curvature values or the zebra phase.
Number types
Float32Array buffers for the GPU; the curvature legend's range is read from the library's Float64Array (recorded under the NURBS evaluation policy).
Limits
What is drawn follows the surface within the drawing tolerance (0.05 by default) and 32-bit positions.
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.