Merge the PR branch (c737a354): the model items' nodes pose the stations' joints

Itallo's merge of main carried his own port of the ISS model onto the draw
port and gave the renderer contract a `nodes` member (the Cesium port writes
each named glTF node's matrix once the model is ready, changed ones only).
The satellites files keep this branch's versions, which cover both stations,
the STATION and LIVE sections and telemetry; the joint drivers' poses are now
the draw item's `nodes`, so the arrays, radiators, dishes and arms move again.
His duplicate point-range setters go; the changelog fragment takes #1690.
This commit is contained in:
Denis Groshev committed 2026-11-16 19:54:19 +01:00
commit 501a34ecaf
9 files changed
+159 -26

No files matched your search

+15 -14
View File
@@ -18,9 +18,9 @@ import { stationTrackedOn } from './policy.js';
* a second, which at model range would show as a jump).
*
* The moving parts (the joint driver, `createArticulation`) write node
* matrices into this part's node poses (`_nodePoses`), as they would into a
* model's nodes; the draw contract has no per-node posing yet, so the model
* draws rigid until it has, and the poses are kept for it.
* matrices into this part's node poses, as they would into a model's nodes;
* those poses are the draw item's `nodes`, which the renderer applies to the
* model's named glTF nodes.
*
* @typedef {object} StationModelSpec
* @property {string} key Short id ('iss', 'tiangong'): the STATION
@@ -147,12 +147,14 @@ export function stationModelOrientation(position, axes, localAxes) {
/**
* Node poses as a joint driver writes them: `getNode(name)` hands a node
* whose `matrix` it sets (a column-major 4×4, copied on write, as a model's
* node copies), and `poses` keeps every matrix written, by node name.
* node copies), and `poses` keeps every matrix written, by node name: the
* draw item's `nodes` (`ModelItem.nodes`), one object for the item's life.
* @returns {{ready: boolean, getNode: (name: string) => {matrix: Float64Array},
* poses: Map<string, Float64Array>, clear: () => void}}
* poses: Record<string, Float64Array>, clear: () => void}}
*/
export function createNodePoses() {
const poses = new Map();
/** @type {Record<string, Float64Array>} */
const poses = {};
const nodes = new Map();
return {
ready: true,
@@ -162,14 +164,10 @@ export function createNodePoses() {
if (!node) {
node = {
get matrix() {
return poses.get(name);
return poses[name];
},
set matrix(value) {
let kept = poses.get(name);
if (!kept) {
kept = new Float64Array(16);
poses.set(name, kept);
}
const kept = (poses[name] ??= new Float64Array(16));
for (let i = 0; i < 16; i++) kept[i] = value[i];
},
};
@@ -177,8 +175,9 @@ export function createNodePoses() {
}
return node;
},
/** Every node back to its authored pose (its name leaves the map). */
clear() {
poses.clear();
for (const name of Object.keys(poses)) delete poses[name];
},
};
}
@@ -318,6 +317,8 @@ export function createStationModel(
displayRange: nearRange,
// So a click on the model tracks the station, as a click on its dot does.
meta: { norad },
// The joint driver's poses, applied to the model's named nodes.
nodes: nodePoses.poses,
show: false,
};
set.upsert([item]);
@@ -763,7 +764,7 @@ export function createStationModel(
_telemetryStatus: () => telemetry?.status() ?? null,
/** The joint driver, for the STATION section. */
_articulation: articulation,
/** The node matrices the joint driver last wrote, by node name. */
/** The node matrices the joint driver last wrote, by node name (the item's `nodes`). */
_nodePoses: nodePoses.poses,
};
}
+17 -1
View File
@@ -248,7 +248,23 @@ test('posed, the model sits on the station with its flight axes as heading, pitc
const track = column(ISS_MODEL_LOCAL_AXES.indexOf('x'));
assert.ok(Math.abs(along(track)) < 1e-6, 'the along-track axis is level');
assert.equal(f.updates.length, 1, 'the joints are driven');
assert.equal(f.updates[0][0].ready, true, 'into node poses');
const nodes = f.updates[0][0];
assert.equal(nodes.ready, true, 'into node poses');
// What the driver writes to a node is the item's `nodes`, by name, as a
// column-major matrix the renderer applies to the model's glTF node.
const turned = new Float64Array(16);
turned[0] = turned[5] = turned[10] = turned[15] = 1;
turned[14] = 2.5;
nodes.getNode('SOLAR_JOINT').matrix = turned;
f.tick();
assert.equal(item.nodes, f.model._nodePoses, 'one object for the item');
assert.deepEqual(Array.from(item.nodes.SOLAR_JOINT), Array.from(turned));
f.model._destroyStationModel();
assert.equal(
Object.keys(f.model._nodePoses).length,
0,
'destroyed, every node goes back to its authored pose',
);
});
test('a station without views on its model hides it while the Cockpit rides the station, its own entry or a docked one', async (t) => {
+56
View File
@@ -7053,6 +7053,62 @@ test('models moved every frame keep their shader and pick ids: only a new look o
}
});
test('a model poses its named nodes once ready, writes only what changed, and gives a dropped one its own pose back', async () => {
const { loads, restore } = fakeModelLoads();
try {
const part = createCesiumDraw({
scene: fakeScene(),
report: (error) => assert.fail(error),
});
const set = part.port.models({ id: 'station' });
const turn = (x) => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, 0, 0, 1];
const item = (nodes) => ({
id: 'iss',
pos: { lon: 0, lat: 0, height: 400e3 },
url: 'iss.glb',
orientation: { heading: 0, pitch: 0, roll: 0 },
nodes,
});
set.upsert([item({ joint: turn(1), other: turn(2), missing: turn(3) })]);
loads[0].resolve();
await settle();
const model = loads[0].model;
const writes = [];
const nodes = {};
for (const name of ['joint', 'other'])
nodes[name] = {
originalMatrix: Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(9, 9, 9),
),
set matrix(m) {
writes.push(name);
this.current = m;
},
};
model.getNode = (name) => {
assert.equal(model.ready, true, 'nodes are asked for once ready');
return nodes[name];
};
loads[0].ready();
assert.deepEqual(writes.sort(), ['joint', 'other'], 'posed when ready');
assert.equal(nodes.joint.current[12], 1);
assert.equal(nodes.other.current[12], 2);
writes.length = 0;
set.upsert([item({ joint: turn(1), other: turn(5), missing: turn(3) })]);
assert.deepEqual(writes, ['other'], 'only the node that moved');
assert.equal(nodes.other.current[12], 5);
writes.length = 0;
set.upsert([item({ other: turn(5) })]);
assert.deepEqual(writes, ['joint'], 'the dropped node, back to its pose');
assert.equal(nodes.joint.current[12], 9);
set.dispose();
} finally {
restore();
}
});
test('a model set that recedes fades its models toward the limb with their focus; focus alone dims', async () => {
const { recedeFactors, recedeFrame, recedeParams, recededAlpha } =
await import('../recession.js');
+42 -1
View File
@@ -5,7 +5,7 @@
* item's `url` re-poses and restyles its model in place (position,
* orientation, scale, `axisScale` and pixel bounds, `shading`, `tint`,
* `colorBlend`, `maskColor`, `clip`, `environmentMap`, `displayRange`,
* `show`); only a new `url` loads again, and the old model keeps drawing
* `nodes`, `show`); only a new `url` loads again, and the old model keeps drawing
* until the new one is ready, so a swap never blinks. `ready` fires once per
* load, when the model has loaded and is posed. An item with its `gltf`
* bytes is built from them; its url is then not fetched.
@@ -55,6 +55,46 @@ export const MODEL_RETRY_MS = 5000;
*/
export const RECEDE_WRITE_EPSILON = 0.005;
/**
* Each model's posed nodes (`ModelItem.nodes`): name → the 16 numbers last
* written, so an update that keeps a node's matrix writes nothing.
*/
const posedNodes = new WeakMap();
/**
* Write the item's node transforms to `model` once it is ready: changed
* ones only, and a node whose name left the map back to its authored pose.
* Names the model lacks are skipped.
*/
function poseNodes(item, model) {
if (model.ready !== true) return;
const wanted = item.nodes;
let posed = posedNodes.get(model);
if (!wanted && !posed) return;
if (!posed) posedNodes.set(model, (posed = new Map()));
for (const [name, last] of posed) {
if (wanted && Object.hasOwn(wanted, name)) continue;
posed.delete(name);
const node = model.getNode(name);
if (node && last) node.matrix = Cesium.Matrix4.clone(node.originalMatrix);
}
if (!wanted) return;
for (const name of Object.keys(wanted)) {
const matrix = wanted[name];
if (!matrix || matrix.length < 16) continue;
const last = posed.get(name);
if (last && sameMatrix(last, matrix)) continue;
const node = model.getNode(name);
posed.set(name, node ? Array.from(matrix).slice(0, 16) : null);
if (node) node.matrix = Cesium.Matrix4.fromArray(matrix);
}
}
function sameMatrix(a, b) {
for (let i = 0; i < 16; i++) if (a[i] !== b[i]) return false;
return true;
}
/** Cesium's own blend amount, for a `mix` that names none. */
const DEFAULT_MIX = 0.5;
@@ -439,6 +479,7 @@ export function createModelSets({
const hidden = range && !(range[1] > range[0]);
if (entry.styled?.range !== rangeKey) entry.styled = { range: rangeKey };
entry.dynamic = needsFrame(item, record.spec);
poseNodes(item, model);
apply(entry, model, entry.frame ?? STILL, hidden);
}
+8
View File
@@ -444,6 +444,14 @@ export interface ModelItem extends Placed {
* would not hide what lies below it). Can change live.
*/
clip?: 'belowOrigin';
/**
* Transforms of the model's named glTF nodes (an articulated model's
* joints): each a column-major 4×4 matrix in the node's parent frame that
* replaces the node's own transform. A node whose name leaves the map goes
* back to its authored pose; names the model lacks are ignored. Applied
* once the model is ready. Can change live.
*/
nodes?: Readonly<Record<string, ArrayLike<number>>>;
/**
* Emphasis for a focused model, 0..1, 1 = none: the tint's alpha is
* multiplied by it (in a set that recedes, as `RecedeSpec` says). Can