Add configurable area asset budgets
This commit is contained in:
@@ -10,7 +10,14 @@ const {
|
||||
layerFile,
|
||||
} = require("./scene-layers");
|
||||
const { digest: glbDigest } = require("../glb-digest");
|
||||
const { BUDGETS, fileRecord, readStageManifest, stageManifestPath } = require("./stage-manifest");
|
||||
const {
|
||||
BUDGETS,
|
||||
evaluateGlbBudget,
|
||||
fileRecord,
|
||||
glbBudgetWarnings,
|
||||
readStageManifest,
|
||||
stageManifestPath,
|
||||
} = require("./stage-manifest");
|
||||
|
||||
function defaultConfigPath(repoRoot) {
|
||||
return path.join(repoRoot, "config", "areas", "nantaizi-lake-innovation-valley.json");
|
||||
@@ -604,15 +611,7 @@ function collectWarnings(area, osm, artifacts, manifests, glb, metadata) {
|
||||
}
|
||||
}
|
||||
if (glb) {
|
||||
if (glb.fileBytes > BUDGETS.glbBytes) {
|
||||
warnings.push(`GLB size ${mb(glb.fileBytes)} MB exceeds budget ${mb(BUDGETS.glbBytes)} MB.`);
|
||||
}
|
||||
if (glb.counts.nodes > BUDGETS.glbNodes) {
|
||||
warnings.push(`GLB nodes ${glb.counts.nodes} exceed budget ${BUDGETS.glbNodes}.`);
|
||||
}
|
||||
if (glb.counts.images > BUDGETS.glbImages) {
|
||||
warnings.push(`GLB images ${glb.counts.images} exceed budget ${BUDGETS.glbImages}.`);
|
||||
}
|
||||
warnings.push(...glbBudgetWarnings("GLB", glb, area.budget).map((warning) => `${warning}.`));
|
||||
}
|
||||
if (metadata && metadata.assets < 1) {
|
||||
warnings.push("Cesium metadata has no assets entries.");
|
||||
@@ -707,6 +706,9 @@ function printDiagnosticsReport(result) {
|
||||
`${glb.counts.materials} materials, ${glb.counts.images} images, ${glb.counts.accessors} accessors`,
|
||||
);
|
||||
console.log(` Extensions: ${glb.extensionsUsed.length ? glb.extensionsUsed.join(", ") : "none"}`);
|
||||
printGlbBudget(glb, area.budget);
|
||||
printGlbSources(glb);
|
||||
printGlbImages(glb);
|
||||
}
|
||||
console.log("");
|
||||
|
||||
@@ -789,15 +791,7 @@ function classifyAreaQuality(result) {
|
||||
}
|
||||
|
||||
if (glb) {
|
||||
if (glb.fileBytes > BUDGETS.glbBytes) {
|
||||
failures.push(`GLB size ${mb(glb.fileBytes)} MB exceeds budget ${mb(BUDGETS.glbBytes)} MB.`);
|
||||
}
|
||||
if (glb.counts.nodes > BUDGETS.glbNodes) {
|
||||
failures.push(`GLB nodes ${glb.counts.nodes} exceed budget ${BUDGETS.glbNodes}.`);
|
||||
}
|
||||
if (glb.counts.images > BUDGETS.glbImages) {
|
||||
failures.push(`GLB images ${glb.counts.images} exceed budget ${BUDGETS.glbImages}.`);
|
||||
}
|
||||
failures.push(...glbBudgetWarnings("GLB", glb, result.area.budget).map((warning) => `${warning}.`));
|
||||
}
|
||||
|
||||
if (!result.area.blender.treeStyle) {
|
||||
@@ -832,6 +826,35 @@ function formatBytes(bytes) {
|
||||
return `${bytes} B`;
|
||||
}
|
||||
|
||||
function printGlbBudget(glb, budget) {
|
||||
const result = evaluateGlbBudget(glb, budget);
|
||||
console.log(" Budget:");
|
||||
console.log(` Size: ${formatBytes(result.usage.glbBytes)} / ${formatBytes(result.limits.glbBytes)}`);
|
||||
console.log(` Nodes: ${result.usage.glbNodes} / ${result.limits.glbNodes}`);
|
||||
console.log(` Images: ${result.usage.glbImages} / ${result.limits.glbImages}`);
|
||||
console.log(` Render triangles: ${result.usage.glbTriangles} / ${result.limits.glbTriangles}`);
|
||||
console.log(` Embedded images: ${formatBytes(result.usage.glbImageBytes)} / ${formatBytes(result.limits.glbImageBytes)}`);
|
||||
if (budget.reason) console.log(` Exception: ${budget.reason}`);
|
||||
}
|
||||
|
||||
function printGlbSources(glb) {
|
||||
const sources = (glb.sourceSummary || []).slice(0, 5);
|
||||
if (!sources.length) return;
|
||||
console.log(" Top sources:");
|
||||
for (const source of sources) {
|
||||
console.log(` ${source.source}: ${source.nodes} nodes, ${source.triangles} triangles`);
|
||||
}
|
||||
}
|
||||
|
||||
function printGlbImages(glb) {
|
||||
const images = (glb.images || []).filter((image) => image.bytes > 0).slice(0, 5);
|
||||
if (!images.length) return;
|
||||
console.log(" Top embedded images:");
|
||||
for (const image of images) {
|
||||
console.log(` ${image.name || "unnamed"}: ${formatBytes(image.bytes)}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
BUDGETS,
|
||||
analyzeOsmPreflight,
|
||||
|
||||
Reference in New Issue
Block a user