mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
fix(models): tracked and emergency tints mix into aircraft paint instead of multiplying it
Aircraft models multiplied their tint into the shaded paint (HIGHLIGHT). A saturated tint zeroes every channel it lacks: the tracked cyan (no red) drew a red helicopter solid black, day or night, and a white Cessna one flat cyan. Tinted models now mix the colour in at 30% (AIRCRAFT_MODEL_TINT_MIX), so the paint stays readable and the colour still marks them; untinted models still draw their own colours, and the IR boost stays flat white. Neither the multi-part models nor the part shader were involved: old and new GLBs, with and without the shader, render the same pixels, and an untinted model at night is lit by the default ambient term. The new conformance check draw.models.paint draws a model painted with COLOR_0 under a fixed sun and reads its colour by day, at night, and under a tint mixed in. The parts test model can now carry vertex paint.
This commit is contained in:
1 parent
953af60e1d
commit
e83c1672dd
9 files changed
+221
-12
No files matched your search
@@ -84,6 +84,7 @@ export const CESIUM_CHECKS = new Set([
|
||||
'draw.models.loadFailed',
|
||||
'draw.models.tint',
|
||||
'draw.models.blend',
|
||||
'draw.models.paint',
|
||||
'draw.models.update',
|
||||
'draw.models.parts',
|
||||
'draw.motion',
|
||||
|
||||
@@ -4049,6 +4049,93 @@ export function portChecks() {
|
||||
},
|
||||
{ capability: 'models', bareSky: true },
|
||||
),
|
||||
check(
|
||||
'draw.models.paint',
|
||||
'a lit model draws its vertex paint (`COLOR_0`) under the sun, stays readable with the sun below the horizon, and a tint mixed in keeps the paint',
|
||||
async (h, r) => {
|
||||
if (h.pixels === false)
|
||||
return { skip: 'this harness reads no drawn pixels' };
|
||||
// Austin at 13:00 local (sun about 80° up) and at 03:00 (about 32° below).
|
||||
const DAY = Date.parse('2026-06-21T18:00:00Z');
|
||||
const NIGHT = Date.parse('2026-06-21T08:00:00Z');
|
||||
r.frame.setTime(DAY);
|
||||
await overAustin(h, r, 200);
|
||||
const set = r.draw.models({ id: 'conf:models.paint' });
|
||||
const ready = [];
|
||||
set.on('ready', (id) => ready.push(id));
|
||||
const pos = h.toEcef({ ...AUSTIN, height: 0 });
|
||||
const model = (extra = {}) => ({
|
||||
id: 'm',
|
||||
pos,
|
||||
url: 'conformance:painted-model.glb',
|
||||
// Red paint, as a fleet model's livery: a white material, its
|
||||
// colour per vertex.
|
||||
gltf: partsModelGlb({ paint: [0.8, 0.05, 0.05] }),
|
||||
orientation: { heading: 0, pitch: 0, roll: 0 },
|
||||
environmentMap: false,
|
||||
tint: '#ffffff',
|
||||
colorBlend: { mode: 'highlight' },
|
||||
...extra,
|
||||
});
|
||||
try {
|
||||
set.set([model()]);
|
||||
for (let i = 0; i < 600 && !ready.length; i++) await drawn(h, r, 1);
|
||||
deepEqual(ready, ['m'], 'ready');
|
||||
const s = r.query.project(pos);
|
||||
ok(s, 'the model projects');
|
||||
// The mean colour of a patch on the model's top, seen from above.
|
||||
const mean = async (time) => {
|
||||
r.frame.setTime(time);
|
||||
await drawn(h, r, 3);
|
||||
await settled(r);
|
||||
r.frame.setTime(time);
|
||||
r.frame.renderNow();
|
||||
const image = r.readPixels({
|
||||
crop: {
|
||||
x: Math.round(s.x) - 4,
|
||||
y: Math.round(s.y) - 4,
|
||||
width: 9,
|
||||
height: 9,
|
||||
},
|
||||
});
|
||||
const sum = [0, 0, 0];
|
||||
for (let i = 0; i < image.data.length; i += 4)
|
||||
for (let c = 0; c < 3; c++) sum[c] += image.data[i + c];
|
||||
return sum.map((v) => Math.round(v / (image.data.length / 4)));
|
||||
};
|
||||
const day = await mean(DAY);
|
||||
ok(
|
||||
day[0] > 100 && day[0] > 2 * day[1] && day[0] > 2 * day[2],
|
||||
`in daylight, its red paint: ${day}`,
|
||||
);
|
||||
const night = await mean(NIGHT);
|
||||
ok(
|
||||
night[0] >= 30 && night[0] > 2 * night[1],
|
||||
`with the sun below the horizon, still its paint, not black: ${night}`,
|
||||
);
|
||||
ok(
|
||||
night[0] < day[0],
|
||||
`darker at night than by day: ${night}, ${day}`,
|
||||
);
|
||||
// A tint with no red, as a tracked cyan: mixed in, the paint shows.
|
||||
set.upsert([
|
||||
model({
|
||||
tint: '#00ffff',
|
||||
colorBlend: { mode: 'mix', amount: 0.3 },
|
||||
}),
|
||||
]);
|
||||
const tinted = await mean(DAY);
|
||||
ok(
|
||||
tinted[0] > 60 && tinted[1] > day[1] + 30,
|
||||
`a cyan tint mixed in at 0.3 keeps the red paint and adds its colour: ${tinted}`,
|
||||
);
|
||||
deepEqual(ready, ['m'], 'never loaded again');
|
||||
} finally {
|
||||
set.dispose();
|
||||
}
|
||||
},
|
||||
{ capability: 'models', bareSky: true },
|
||||
),
|
||||
check(
|
||||
'draw.models.bytes',
|
||||
'a model given its bytes is drawn from them, its url never fetched',
|
||||
|
||||
@@ -108,15 +108,19 @@ const CUBES = [
|
||||
* The model's GLB bytes. Its mesh node is scaled by `scale`, turned
|
||||
* `turnDeg` about its vertical and moved by `translation`; the mesh is
|
||||
* built in that node's own frame, so the model it draws is the same
|
||||
* whatever the node's transform.
|
||||
* whatever the node's transform. `paint` (RGB, 0..1) is every vertex's
|
||||
* colour (`COLOR_0`) over a white material, as the fleet models carry
|
||||
* their paint; without it the model has no vertex colours.
|
||||
* @param {{scale?: number, turnDeg?: number,
|
||||
* translation?: [number, number, number]}} [node]
|
||||
* translation?: [number, number, number],
|
||||
* paint?: [number, number, number]}} [node]
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
export function partsModelGlb({
|
||||
scale = 10,
|
||||
turnDeg = 0,
|
||||
translation = [0, 0, 0],
|
||||
paint,
|
||||
} = {}) {
|
||||
const a = (turnDeg * Math.PI) / 180;
|
||||
const c = Math.cos(a);
|
||||
@@ -139,7 +143,13 @@ export function partsModelGlb({
|
||||
const parts = new Uint8Array(count * 4);
|
||||
mesh.parts.forEach((part, i) => (parts[i * 4] = part));
|
||||
const indices = new Uint16Array(mesh.indices);
|
||||
// Normalised bytes, RGBA: four to a vertex, on its 4-byte boundary.
|
||||
const colors = paint ? new Uint8Array(count * 4) : null;
|
||||
if (colors)
|
||||
for (let i = 0; i < count; i++)
|
||||
colors.set([...paint.map((c) => Math.round(c * 255)), 255], i * 4);
|
||||
const chunks = [positions, normals, parts, indices];
|
||||
if (colors) chunks.push(colors);
|
||||
const offsets = [];
|
||||
let length = 0;
|
||||
for (const chunk of chunks) {
|
||||
@@ -177,7 +187,12 @@ export function partsModelGlb({
|
||||
{
|
||||
primitives: [
|
||||
{
|
||||
attributes: { POSITION: 0, NORMAL: 1, _PART: 2 },
|
||||
attributes: {
|
||||
POSITION: 0,
|
||||
NORMAL: 1,
|
||||
_PART: 2,
|
||||
...(colors ? { COLOR_0: 4 } : {}),
|
||||
},
|
||||
indices: 3,
|
||||
material: 0,
|
||||
},
|
||||
@@ -220,6 +235,17 @@ export function partsModelGlb({
|
||||
byteLength: indices.byteLength,
|
||||
target: 34963,
|
||||
},
|
||||
...(colors
|
||||
? [
|
||||
{
|
||||
buffer: 0,
|
||||
byteOffset: offsets[4],
|
||||
byteLength: colors.byteLength,
|
||||
byteStride: 4,
|
||||
target: 34962,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
accessors: [
|
||||
{
|
||||
@@ -238,6 +264,17 @@ export function partsModelGlb({
|
||||
count: indices.length,
|
||||
type: 'SCALAR',
|
||||
},
|
||||
...(colors
|
||||
? [
|
||||
{
|
||||
bufferView: 4,
|
||||
componentType: 5121,
|
||||
normalized: true,
|
||||
count,
|
||||
type: 'VEC4',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
let text = new TextEncoder().encode(JSON.stringify(json));
|
||||
|
||||
@@ -30,6 +30,7 @@ test('the stub passes the conformance suite', async () => {
|
||||
'draw.lines.split',
|
||||
'draw.lines.outlineDraped',
|
||||
'draw.models.blend',
|
||||
'draw.models.paint',
|
||||
'globe.imagery.video',
|
||||
'globe.weather.drawn',
|
||||
'globe.weather.sceneTime',
|
||||
|
||||
Reference in new issue
Block a user