From 09d7c7a966383d84e441025793bed3c990bd4099 Mon Sep 17 00:00:00 2001 From: Marco Hutter Date: Sat, 17 Aug 2024 14:25:26 +0200 Subject: [PATCH] Handle missing batch ID attributes --- src/tools/migration/TileFormatsMigrationB3dm.ts | 2 +- src/tools/migration/TileTableDataToMeshFeatures.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tools/migration/TileFormatsMigrationB3dm.ts b/src/tools/migration/TileFormatsMigrationB3dm.ts index f7e60cd..2126b68 100644 --- a/src/tools/migration/TileFormatsMigrationB3dm.ts +++ b/src/tools/migration/TileFormatsMigrationB3dm.ts @@ -90,7 +90,7 @@ export class TileFormatsMigrationB3dm { primitive, batchIdToFeatureIdAccessor ); - if (propertyTable) { + if (featureId && propertyTable) { featureId.setPropertyTable(propertyTable); } } diff --git a/src/tools/migration/TileTableDataToMeshFeatures.ts b/src/tools/migration/TileTableDataToMeshFeatures.ts index b9de9ee..efbb840 100644 --- a/src/tools/migration/TileTableDataToMeshFeatures.ts +++ b/src/tools/migration/TileTableDataToMeshFeatures.ts @@ -23,11 +23,15 @@ export class TileTableDataToMeshFeatures { * extension that is associated with this primitive, storing * the former batch ID attribute as a new `_FEATURE_ID_0` attribute. * - * Note that this will remove the former batch ID attributes + * Note that this will set the former batch ID attributes * in the given primitive to `null`, but it will not dispose * the corresponding accessors. These have to be disposed * after all primitives have been processed. * + * If the given primitive does not contain a batch ID attribute, + * then a warning will be printed, and `undefined` will be + * returned. + * * @param document - The glTF-Transform document * @param primitive - The glTF-Transform primitive * @param batchIdToFeatureIdAccessor - A mapping from former @@ -42,7 +46,7 @@ export class TileTableDataToMeshFeatures { document: Document, primitive: Primitive, batchIdToFeatureIdAccessor: Map - ): FeatureId { + ): FeatureId | undefined { let batchIdAttribute = primitive.getAttribute("_BATCHID"); if (!batchIdAttribute) { batchIdAttribute = primitive.getAttribute("BATCHID"); @@ -52,9 +56,10 @@ export class TileTableDataToMeshFeatures { "should be _BATCHID, starting with an underscore" ); } else { - throw new TileFormatError( - "The primitive did not contain a _BATCHID attribute" + logger.warn( + "The primitive did not contain a _BATCHID or BATCHID attribute" ); + return undefined; } }