Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('XVIZLoader#encode-and-parse', t => {
for (const tcName in TEST_CASES) {
const TEST_JSON = TEST_CASES[tcName];
const glbFileBuffer = encodeBinaryXVIZ(TEST_JSON, {flattenArrays: true});
const json = parseBinaryXVIZ(glbFileBuffer);
t.ok(
!Array.isArray(json.buffers),
`${tcName} Encoded and parsed XVIZ - has no JSON buffers field`
);
t.ok(
!Array.isArray(json.bufferViews),
`${tcName} Encoded and parsed XVIZ - has no JSON bufferViews field`
);
t.ok(
!Array.isArray(json.accessors),
`${tcName} Encoded and parsed XVIZ - has no JSON accessors field`
);
// const reference = toLowPrecision(packJsonArrays(TEST_JSON));
const extensionArrayBuffer = encodeSync(
{json: extensionGlbJsonObject, binary: BINARY_GLB_CHUNK},
GLBWriter,
{}
);
const extensionJson = parseBinaryXVIZ(extensionArrayBuffer);
delete extensionJson.data.updates[0].primitives['/object/points'].points[0].colors.accessor;
t.deepEqual(extensionJson, EXPECTED_STATE_UPDATE, 'Parse extension GLB correctly');
// Now make sure we are using the XVIZ extension
const options = {useAVSXVIZExtension: true};
const encodedArrayBuffer = encodeBinaryXVIZ(EXPECTED_STATE_UPDATE, options);
const resultStr = buffer2String(encodedArrayBuffer);
t.notEqual(-1, resultStr.indexOf(XVIZ_GLTF_EXTENSION), 'AVS extension encoding check');
t.end();
});
type: 'points3d',
color: [255, 0, 0, 255],
vertices: new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9]),
reflectance: new Float32Array([9, 8, 7])
};
const frame = {
state_updates: [
{
timestamps: 1317042272459,
primitives: {}
}
]
};
const xvizBinary = encodeBinaryXVIZ(sample_lidar, options);
const xvizBinaryDecoded = parseBinaryXVIZ(xvizBinary);
validateLidarData(t, xvizBinaryDecoded);
frame.state_updates[0].primitives.lidarPoints = xvizBinaryDecoded;
const frameBinary = encodeBinaryXVIZ(frame, options);
t.equal(frameBinary.byteLength, 584);
const xvizBinaryDecoded2 = parseBinaryXVIZ(frameBinary);
const lidar = xvizBinaryDecoded2.state_updates[0].primitives.lidarPoints;
validateLidarData(t, xvizBinaryDecoded);
t.end();
});
state_updates: [
{
timestamps: 1317042272459,
primitives: {}
}
]
};
const xvizBinary = encodeBinaryXVIZ(sample_lidar, options);
const xvizBinaryDecoded = parseBinaryXVIZ(xvizBinary);
validateLidarData(t, xvizBinaryDecoded);
frame.state_updates[0].primitives.lidarPoints = xvizBinaryDecoded;
const frameBinary = encodeBinaryXVIZ(frame, options);
t.equal(frameBinary.byteLength, 584);
const xvizBinaryDecoded2 = parseBinaryXVIZ(frameBinary);
const lidar = xvizBinaryDecoded2.state_updates[0].primitives.lidarPoints;
validateLidarData(t, xvizBinaryDecoded);
t.end();
});