Merge branch 'sameh/renderer-transit' into sameh/renderer-seam

# Conflicts:
#	src/render/cesium/draw.test.mjs
This commit is contained in:
Sameh Khamis committed 2026-11-09 01:00:43 -08:00
commit 9d4e438e63
27 files changed
+2016 -465

No files matched your search

+157
View File
@@ -949,6 +949,113 @@ export function createCesiumDraw({
return look;
}
/**
* What a billboard draws of an icon item but its position, image, `meta`
* and `lodGroup`, as plain values: the course rotation follows the
* position, so it is written with it.
*/
function iconStyleOf(record, item) {
const color = item.color;
const curve = (c) =>
c ? [c.near, c.nearValue, c.far, c.farValue] : undefined;
return {
width: item.size[0],
height: item.size[1],
scale: item.scale,
color:
Array.isArray(color) || ArrayBuffer.isView(color) ? [...color] : color,
alpha: item.alpha,
focus: item.focus,
anchor: item.anchor,
disableDepthTest: item.disableDepthTest,
heightMode: item.height,
clampTo: record.spec.clampTo,
show: item.show,
displayRange: item.displayRange ? [...item.displayRange] : undefined,
scaleByDistance: curve(item.scaleByDistance),
fadeByDistance: curve(item.fadeByDistance),
rotationMode: item.rotationMode,
rotation: item.rotation,
course: item.course,
};
}
/** Two lists, or two missing ones, alike element by element. */
function sameList(a, b) {
if (!a || !b) return a === b;
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
return true;
}
/** A curve as `iconStyleOf` keeps it, and one as an item gives it. */
function sameCurve(a, c) {
return !a || !c
? !a && !c
: a[0] === c.near &&
a[1] === c.nearValue &&
a[2] === c.far &&
a[3] === c.farValue;
}
/**
* Whether `item` draws as `style` (`iconStyleOf`) says, but its position
* and, turned on screen, its rotation (`moveIcon` writes both).
*/
function sameIconStyle(style, record, item) {
const color = item.color;
return (
style.width === item.size[0] &&
style.height === item.size[1] &&
style.scale === item.scale &&
(Array.isArray(color) || ArrayBuffer.isView(color)
? Array.isArray(style.color) && sameList(style.color, color)
: style.color === color) &&
style.alpha === item.alpha &&
style.focus === item.focus &&
style.anchor === item.anchor &&
style.disableDepthTest === item.disableDepthTest &&
style.heightMode === item.height &&
style.clampTo === record.spec.clampTo &&
style.show === item.show &&
sameList(style.displayRange, item.displayRange) &&
sameCurve(style.scaleByDistance, item.scaleByDistance) &&
sameCurve(style.fadeByDistance, item.fadeByDistance) &&
style.rotationMode === item.rotationMode &&
(item.rotationMode === 'screen' || style.rotation === item.rotation) &&
style.course === item.course
);
}
const movedEnu = new Cesium.Matrix4();
const movedAxis = new Cesium.Cartesian3();
/**
* Move a drawn icon whose look is unchanged (`sameIconStyle`): its
* position, the course rotation that follows it or the screen rotation
* it is given, and its pick record.
*/
function moveIcon(record, entry, item) {
const { billboard, placed } = entry;
const position = toCartesianInto(item.pos, placed.position);
billboard.position = position;
if (item.rotationMode === 'course') {
Cesium.Transforms.eastNorthUpToFixedFrame(position, undefined, movedEnu);
// The billboard copies the axis it is given.
billboard.alignedAxis = Cesium.Matrix4.multiplyByPointAsVector(
movedEnu,
Cesium.Cartesian3.UNIT_Y,
movedAxis,
);
}
if (item.rotationMode === 'screen') {
billboard.rotation = item.rotation ?? 0;
entry.style.rotation = item.rotation;
}
billboard.id.meta = item.meta;
billboard.id.lodGroup = item.lodGroup;
billboard.show = shownNow(record, placed);
}
/** Give a billboard its image: a generated one under its key. */
function setIconImage(record, billboard, image) {
if (isKeyed(image)) billboard.setImage(image.key, image.canvas);
@@ -971,6 +1078,8 @@ export function createCesiumDraw({
placed,
image: imageKeyOf(image),
canvas: image?.canvas,
// What it is drawn as, for `patchIcon`'s quick path.
style: iconStyleOf(record, item),
});
}
@@ -982,6 +1091,17 @@ export function createCesiumDraw({
*/
function patchIcon(record, entry, item, image) {
const { billboard, placed } = entry;
// Drawn as it was but for where it is: only that is written, so a set
// whose icons move every frame costs little more than the moves.
if (
entry.style &&
imageKeyOf(image) === entry.image &&
sameIconStyle(entry.style, record, item)
) {
moveIcon(record, entry, item);
return;
}
entry.style = iconStyleOf(record, item);
const position = toCartesian(item.pos);
const look = iconLook(record, item, position);
// Sized first: a new SVG image rasterises at the billboard's size.
@@ -1000,6 +1120,42 @@ export function createCesiumDraw({
billboard.show = shownNow(record, placed);
}
/**
* `syncIcons`' quick case: every item is drawn, every touched one keeps
* the image it is drawn with, and nothing drawn has gone, so each touched
* one is changed where it is and nothing is added, removed or reordered.
* False, changing nothing, otherwise.
* @param {object} record
* @param {readonly string[]} touched
*/
function patchDrawnIcons(record, touched) {
const drawn = record.billboards;
// Nothing to remove: every item drawn, and nothing drawn but items.
if (
!Array.isArray(touched) ||
touched.length === 0 ||
drawn.size !== record.items.size
)
return false;
for (const id of touched) {
const entry = drawn.get(id);
const item = record.items.get(id);
if (!entry || !item) return false;
const image = iconImage(record, item.image);
if (
image === undefined ||
imageKeyOf(image) !== entry.image ||
(isKeyed(image) && image.canvas !== entry.canvas)
)
return false;
}
for (const id of touched) {
const item = record.items.get(id);
patchIcon(record, drawn.get(id), item, iconImage(record, item.image));
}
return true;
}
/**
* Bring an icon set's billboards in line with its items without a
* rebuild: those of items gone (or whose image is gone) are removed, the
@@ -1029,6 +1185,7 @@ export function createCesiumDraw({
host.isDestroyed()
)
return false;
if (!reordered && patchDrawnIcons(record, touched)) return ICONS_KEPT;
const images = new Map();
for (const id of touched) {
const item = record.items.get(id);