Skip to content

Commit

Permalink
Revive parts of the metadata picking specs
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Sep 10, 2024
1 parent d813dba commit 0ad2bc5
Showing 1 changed file with 152 additions and 20 deletions.
172 changes: 152 additions & 20 deletions packages/engine/Specs/Scene/Model/pickMetadataSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Math as CesiumMath,
Model,
ResourceCache,
Cartesian4,
} from "../../../index.js";
import createScene from "../../../../../Specs/createScene.js";
import createCanvas from "../../../../../Specs/createCanvas.js";
Expand Down Expand Up @@ -381,6 +382,37 @@ function createPropertyTextureGltfVec3() {
return createPropertyTextureGltf(schema, properties);
}

/**
* Creates the glTF for the 'vec4' test case
*
* @returns The glTF
*/
function createPropertyTextureGltfVec4() {
const schema = {
id: "ExampleSchema",
classes: {
exampleClass: {
name: "Example class",
properties: {
example_UINT8_VEC4: {
name: "Example VEC4 property with UINT8 components",
type: "VEC4",
componentType: "UINT8",
},
},
},
},
};
const properties = {
example_UINT8_VEC4: {
index: 0,
texCoord: 0,
channels: [0, 1, 2, 3],
},
};
return createPropertyTextureGltf(schema, properties);
}

/**
* Create a model from the given glTF, add it as a primitive
* to the given scene, and wait until it is fully loaded.
Expand Down Expand Up @@ -649,23 +681,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
3
0,
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
3
0,
2
);
const expectedMetadataValue0 = 0;
const expectedMetadataValue1 = 127;
Expand Down Expand Up @@ -709,23 +741,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
3,
3
0
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
6,
3
0
);
const expectedMetadataValue0 = 0.0;
const expectedMetadataValue1 = 0.5;
Expand Down Expand Up @@ -769,23 +801,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
4
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
5
2
);
const expectedMetadataValue0 = [0, 0, 0];
const expectedMetadataValue1 = [127, 0, 127];
Expand Down Expand Up @@ -829,23 +861,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
4
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
5
2
);
const expectedMetadataValue0 = new Cartesian2(0, 0);
const expectedMetadataValue1 = new Cartesian2(127, 0);
Expand Down Expand Up @@ -889,23 +921,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
4
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
5
2
);

const expectedMetadataValue0 = new Cartesian2(0.0, 0.0);
Expand Down Expand Up @@ -950,23 +982,23 @@ describe(
className,
propertyName,
0,
3
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
4
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
5
2
);
const expectedMetadataValue0 = new Cartesian3(0, 0, 0);
const expectedMetadataValue1 = new Cartesian3(127, 0, 127);
Expand All @@ -985,6 +1017,106 @@ describe(
propertyValueEpsilon
);
});

it("picks UINT8 VEC4 from a property texture", async function () {
const schemaId = undefined;
const className = "exampleClass";
const propertyName = "example_UINT8_VEC4";
const gltf = createPropertyTextureGltfVec4();

const canvasSizeX = textureSizeX * canvasScaling;
const canvasSizeY = textureSizeY * canvasScaling;
scene = createScene({
canvas: createCanvas(canvasSizeX, canvasSizeY),
});

await loadAsModel(scene, gltf);
fitCameraToUnitSquare(scene.camera);

scene.initializeFrame();
scene.render(defaultDate);

const actualMetadataValue0 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
0,
0
);
const actualMetadataValue1 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
1,
1
);
const actualMetadataValue2 = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
2,
2
);

const expectedMetadataValue0 = new Cartesian4(0, 0, 0, 0);
const expectedMetadataValue1 = new Cartesian4(127, 0, 127, 0);
const expectedMetadataValue2 = new Cartesian4(255, 0, 255, 0);

expect(actualMetadataValue0).toEqualEpsilon(
expectedMetadataValue0,
propertyValueEpsilon
);
expect(actualMetadataValue1).toEqualEpsilon(
expectedMetadataValue1,
propertyValueEpsilon
);
expect(actualMetadataValue2).toEqualEpsilon(
expectedMetadataValue2,
propertyValueEpsilon
);
});

// XXX For debugging:
it("picks metadata from a property texture quarry - TO BE REMOVED", async function () {
const schemaId = undefined;
const className = "exampleClass";
const propertyName = "example_UINT8_SCALAR";
const gltf = createPropertyTextureGltfScalar();

const canvasSizeX = textureSizeX * canvasScaling;
const canvasSizeY = textureSizeY * canvasScaling;
scene = createScene({
canvas: createCanvas(canvasSizeX, canvasSizeY),
});

await loadAsModel(scene, gltf);
fitCameraToUnitSquare(scene.camera);

scene.initializeFrame();
scene.render(defaultDate);

for (let x = 0; x < 16; x++) {
for (let y = 0; y < 16; y++) {
const actualMetadataValue = pickMetadataAt(
scene,
schemaId,
className,
propertyName,
x,
y
);

console.log(
`actualMetadataValue at ${x} ${y} is `,
actualMetadataValue
);
}
}
console.log("done");
});
},
"WebGL"
);

0 comments on commit 0ad2bc5

Please sign in to comment.