blob: fd4ac287d006562e09d393b0e36ab4c56e3f574d [file] [edit]
<!DOCTYPE html> <!-- webkit-test-runner [ SpatialPortalEnabled=true ModelElementEnabled=true ModelProcessEnabled=true allowTestOnlyIPC=true ] -->
<html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/ui-helper.js"></script>
<script src="../model-element/resources/model-utils.js"></script>
<script src="resources/spatial-portal-utils.js"></script>
<style>
.portal { spatial: portal; width: 40cm; height: 20cm; }
</style>
<body>
<script>
'use strict';
internals.disableModelLoadDelaysForTesting();
// Deliberately spread out, so the merged bounds move as each one loads.
const spreadAssets = ["2x2x2-center.usdz", "2x2x2-at-100x50x200.usdz", "2x2x2-positive.usdz"];
const loadPortalInOrder = async (test, assets, options) => {
const portal = createPortal(test, options);
const loaded = [];
let previous = null;
for (const asset of assets) {
const model = appendModel(portal, asset);
loaded.push({ model, asset });
await model.ready;
await UIHelper.ensureStablePresentationUpdate();
loaded.forEach(each => {
assert_equals(internals.modelElementState(each.model), "Loaded", `${each.asset} is loaded (${loaded.length}/${assets.length} appended)`);
});
const transform = await waitForPortalTransform(portal, portalTransformIsResolved, `fit after loading ${asset}`);
if (previous)
assert_less_than_equal(transform.m11, previous.m11, `the scale does not grow when ${asset} joins the merged bounds`);
previous = transform;
}
return portal;
};
for (const portalAction of ["none", "orbit"]) {
promise_test(async t => {
const forward = await loadPortalInOrder(t, spreadAssets, { portalAction });
const reversed = await loadPortalInOrder(t, [...spreadAssets].reverse(), { portalAction });
assert_3d_matrix_approx_equals(resolvedPortalTransform(reversed), resolvedPortalTransform(forward));
}, `portal-action: ${portalAction} fits the merged bounds independently of model load order`);
}
promise_test(async t => {
const incremental = await loadPortalInOrder(t, spreadAssets, { portalAction: "orbit" });
const batched = createPortal(t, { portalAction: "orbit" });
await Promise.all(spreadAssets.map(asset => appendModel(batched, asset).ready));
await waitForPortalTransform(batched, portalTransformIsResolved, "batched portal");
assert_3d_matrix_approx_equals(resolvedPortalTransform(batched), resolvedPortalTransform(incremental));
}, `portal-action: orbit fits the merged bounds the same whether models load one by one or together`);
</script>
</body>
</html>