feat(preview): add low poly vehicle library
This commit is contained in:
@@ -7,6 +7,7 @@ const os = require("os");
|
||||
const path = require("path");
|
||||
const { cesiumPreviewHtml } = require("./lib/area-preview");
|
||||
const { makeVehicleGltf } = require("./lib/vehicle-model");
|
||||
const { VEHICLE_IDS, REVERSED_MODEL_IDS, writePreviewVehicleLibrary } = require("./lib/vehicle-library");
|
||||
const { allowedTurns, buildVehicleRoute, classifyConnection } = require("./lib/vehicle-route");
|
||||
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "preview-assets-"));
|
||||
@@ -85,17 +86,39 @@ assert.equal(
|
||||
vehicle.buffers[0].byteLength,
|
||||
);
|
||||
|
||||
const vehicleLibraryRoot = path.join(__dirname, "..", "assets", "models", "custom", "lowpoly_cars");
|
||||
if (fs.existsSync(vehicleLibraryRoot)) {
|
||||
const libraryDir = path.join(tempDir, "vehicle-library");
|
||||
const models = writePreviewVehicleLibrary(libraryDir, "fixture");
|
||||
assert.deepEqual(models, VEHICLE_IDS.map((id) => `fixture-vehicle-${id}.gltf`));
|
||||
assert.equal(models.length, 6);
|
||||
assert.ok(fs.existsSync(path.join(libraryDir, "fixture-vehicle-texture.jpg")));
|
||||
for (const model of models) {
|
||||
const gltf = JSON.parse(fs.readFileSync(path.join(libraryDir, model), "utf8"));
|
||||
assert.deepEqual(gltf.images.map((image) => image.uri), ["fixture-vehicle-texture.jpg"]);
|
||||
assert.equal(gltf.buffers[0].uri, model.replace(/\.gltf$/, ".bin"));
|
||||
assert.deepEqual(gltf.materials[0].pbrMetallicRoughness.baseColorFactor, [2.1, 2.1, 2.1, 1]);
|
||||
assert.deepEqual(gltf.materials[0].emissiveFactor, [0.25, 0.25, 0.25]);
|
||||
assert.equal(gltf.materials[0].emissiveTexture.index, gltf.materials[0].pbrMetallicRoughness.baseColorTexture.index);
|
||||
const reversed = model.includes("truck_a03_001");
|
||||
assert.equal(reversed, REVERSED_MODEL_IDS.has(model.match(/vehicle-(.+)\.gltf$/)[1]));
|
||||
assert.equal(gltf.nodes.every((node) => JSON.stringify(node.rotation || []) === JSON.stringify([0, 1, 0, 0])), reversed);
|
||||
}
|
||||
}
|
||||
|
||||
const html = cesiumPreviewHtml(
|
||||
"scene<&>.glb",
|
||||
"scene.json",
|
||||
"route.json",
|
||||
"vehicle.gltf",
|
||||
"north<&>\u2028valley",
|
||||
["car-a.gltf", "truck-a.gltf"],
|
||||
);
|
||||
assert.match(html, /<title>north<&>\u2028valley Cesium Preview<\/title>/);
|
||||
assert.match(html, /Loading scene<&>\.glb/);
|
||||
assert.match(html, /"areaId":"north\\u003c\\u0026\\u003e\\u2028valley"/);
|
||||
assert.match(html, /"glbName":"scene\\u003c\\u0026\\u003e\.glb"/);
|
||||
assert.match(html, /"vehicleModelNames":\["car-a\.gltf","truck-a\.gltf"\]/);
|
||||
assert.match(html, /id="viewMode"/);
|
||||
assert.match(html, /data-view-mode="inspect"/);
|
||||
assert.match(html, /id="semanticToggles" class="control-subgroup hidden"/);
|
||||
|
||||
Reference in New Issue
Block a user