Namespace sceneModel

SceneModel Inspector

Runs inspections on a SceneModel and returns a structured InspectionReport.

applyFixes applies registered fixes for supported issue codes. The module also exports registries, async variants, and optimizeSceneModel.

%%{init:{"theme":"dark"}}%% classDiagram direction TB class inspectSceneModel { +(params) InspectionReport } class applyFixes { +(params) SDKResult~ApplyFixesResult~ } class InspectionReport { +issues : Issue[] +errors / warnings / info : Issue[] +byCode : Map~code, Issue[]~ } class Issue { +code : string +severity : error | warning | info +message : string +resourceId? / context? } class ApplyFixesResult { +fixed : Issue[] +skipped : Issue[] +errors : Issue[] } class Inspection { +codes : string[] +run(sceneModel, push) } class Fix { +codes : string[] +apply(issue, sceneModel) } class InspectionRegistry { +register(inspection) } class FixRegistry { +register(fix) +unregister(code) } inspectSceneModel ..> InspectionRegistry : walks inspectSceneModel ..> InspectionReport : produces InspectionRegistry "1" *-- "*" Inspection InspectionReport "1" *-- "*" Issue applyFixes ..> InspectionReport : consumes applyFixes ..> FixRegistry : dispatches applyFixes ..> ApplyFixesResult : returns FixRegistry "1" *-- "*" Fix
%%{init:{"theme":"default"}}%% classDiagram direction TB class inspectSceneModel { +(params) InspectionReport } class applyFixes { +(params) SDKResult~ApplyFixesResult~ } class InspectionReport { +issues : Issue[] +errors / warnings / info : Issue[] +byCode : Map~code, Issue[]~ } class Issue { +code : string +severity : error | warning | info +message : string +resourceId? / context? } class ApplyFixesResult { +fixed : Issue[] +skipped : Issue[] +errors : Issue[] } class Inspection { +codes : string[] +run(sceneModel, push) } class Fix { +codes : string[] +apply(issue, sceneModel) } class InspectionRegistry { +register(inspection) } class FixRegistry { +register(fix) +unregister(code) } inspectSceneModel ..> InspectionRegistry : walks inspectSceneModel ..> InspectionReport : produces InspectionRegistry "1" *-- "*" Inspection InspectionReport "1" *-- "*" Issue applyFixes ..> InspectionReport : consumes applyFixes ..> FixRegistry : dispatches applyFixes ..> ApplyFixesResult : returns FixRegistry "1" *-- "*" Fix
classDiagram
    direction TB
    class inspectSceneModel {
      +(params) InspectionReport
    }
    class applyFixes {
      +(params) SDKResult~ApplyFixesResult~
    }
    class InspectionReport {
      +issues   : Issue[]
      +errors / warnings / info : Issue[]
      +byCode   : Map~code, Issue[]~
    }
    class Issue {
      +code      : string
      +severity  : error | warning | info
      +message   : string
      +resourceId? / context?
    }
    class ApplyFixesResult {
      +fixed    : Issue[]
      +skipped  : Issue[]
      +errors   : Issue[]
    }
    class Inspection {
      +codes    : string[]
      +run(sceneModel, push)
    }
    class Fix {
      +codes    : string[]
      +apply(issue, sceneModel)
    }
    class InspectionRegistry {
      +register(inspection)
    }
    class FixRegistry {
      +register(fix)
      +unregister(code)
    }
    inspectSceneModel ..> InspectionRegistry : walks
    inspectSceneModel ..> InspectionReport : produces
    InspectionRegistry "1" *-- "*" Inspection
    InspectionReport "1" *-- "*" Issue
    applyFixes ..> InspectionReport : consumes
    applyFixes ..> FixRegistry : dispatches
    applyFixes ..> ApplyFixesResult : returns
    FixRegistry "1" *-- "*" Fix
%%{init:{"theme":"dark"}}%% flowchart LR A[SceneModel] --> B[inspectSceneModel] B --> C[InspectionReport] C --> D[applyFixes] D --> E[ApplyFixesResult] E -- re-inspect --> B
%%{init:{"theme":"default"}}%% flowchart LR A[SceneModel] --> B[inspectSceneModel] B --> C[InspectionReport] C --> D[applyFixes] D --> E[ApplyFixesResult] E -- re-inspect --> B
flowchart LR
    A[SceneModel] --> B[inspectSceneModel]
    B --> C[InspectionReport]
    C --> D[applyFixes]
    D --> E[ApplyFixesResult]
    E -- re-inspect --> B
npm install @xeokit/sdk
  • Issue: one finding with severity, code, message, optional resource id, and optional context.
  • InspectionReport: issue list plus severity and code groupings.
  • Inspection: {codes[], description, run}. Walks a SceneModel and returns issues.
  • Fix: {codes[], description, apply}. Handles one or more issue codes.

Inspections and fixes are stored in separate registries:

Tests and one-off pipelines can create fresh registries and pass them through the matching registry field on the params object.

// Register a fix in the default registry.
import * as sceneModelInspector from "@xeokit/sdk/inspect/sceneModel";

sceneModelInspector.DEFAULT_FIX_REGISTRY.register({
codes: ["MyApp/STALE_PROPERTY_SET"],
description: "Prune deprecated property sets",
apply(issue, sceneModel) {
return {ok: true, value: {fixed: true}};
},
});
// Build a one-off registry.
import {
FixRegistry,
mergeDuplicateGeometries,
applyFixes,
} from "@xeokit/sdk/inspect/sceneModel";

const registry = new FixRegistry([
mergeDuplicateGeometries,
myFix,
]);
applyFixes({sceneModel, report, registry});

Use unregister(code) to remove a fix mapping.

Built-in inspections are registered in DEFAULT_INSPECTION_REGISTRY.

Inspection Codes
geometryDataIntegrity GEOMETRY_NO_POSITIONS, GEOMETRY_POSITIONS_LENGTH, GEOMETRY_PRIMITIVE_UNSUPPORTED, GEOMETRY_NORMALS_LENGTH, GEOMETRY_UVS_LENGTH, GEOMETRY_COLORS_LENGTH, GEOMETRY_AABB_LENGTH, GEOMETRY_AABB_NONFINITE, GEOMETRY_AABB_INVERTED, GEOMETRY_NO_INDICES, GEOMETRY_INDICES_LENGTH, GEOMETRY_INDEX_OUT_OF_RANGE, GEOMETRY_EDGE_INDICES_LENGTH, GEOMETRY_EDGE_INDEX_OUT_OF_RANGE, GEOMETRY_SPLAT_SCALES_LENGTH, GEOMETRY_SPLAT_ROTATIONS_LENGTH (errors)
meshReferences MESH_DANGLING_GEOMETRY, MESH_DANGLING_MATERIAL, MESH_DANGLING_TRANSFORM, MESH_NONFINITE_MATRIX (errors)
objectMeshReferences OBJECT_DANGLING_MESH (error)
transformParentCycles TRANSFORM_CYCLE (error)
unusedResources MATERIAL_UNUSED, TEXTURE_UNUSED, TRANSFORM_UNUSED (warnings)
identityTransforms TRANSFORM_IDENTITY (warning)
duplicateGeometries GEOMETRY_DUPLICATE (warning, opt-in via checkDuplicateGeometries)
similarGeometries GEOMETRY_SIMILAR (warning, opt-in via checkSimilarGeometries)
denseGeometries GEOMETRY_OVER_BUDGET (warning, opt-in via checkDenseGeometries)
largeGeometries GEOMETRY_OVER_EXTENT (warning, opt-in via checkLargeGeometries)
geometryQuality GEOMETRY_ZERO_VOLUME_AABB, GEOMETRY_DEGENERATE_TRIANGLES, GEOMETRY_UNUSED_VERTICES, GEOMETRY_DUPLICATE_VERTICES, GEOMETRY_NON_WATERTIGHT, GEOMETRY_INCONSISTENT_WINDING, GEOMETRY_AABB_NOT_TIGHT, GEOMETRY_DUPLICATE_INDICES (warnings, opt-in via checkGeometryQuality)
objectPlacement OBJECT_FAR_FROM_ORIGIN, OBJECT_DUPLICATE_AABB (warnings, opt-in via checkObjectStructure)
textureDimensions TEXTURE_NPOT, TEXTURE_OVERSIZED (warnings, opt-in via checkTextureSanity)
farFromOriginGeometries GEOMETRY_FAR_FROM_ORIGIN (warning, opt-in via checkGeometryFarFromOrigin)

Built-in fixes are registered in DEFAULT_FIX_REGISTRY.

Fix Codes handled
addMissingUVs MATERIAL_TEXTURED_GEOMETRY_NO_UVS — synthesises planar UVs
addMissingNormals MATERIAL_PBR_GEOMETRY_NO_NORMALS — synthesises smooth normals
pruneDanglingMeshRefs OBJECT_DANGLING_MESH
dropUnusedMaterial MATERIAL_UNUSED — destroys the orphan SceneMaterial
dropUnusedTexture TEXTURE_UNUSED — destroys the orphan SceneTexture
dropUnusedTransform TRANSFORM_UNUSED — destroys the orphan SceneTransform
dropIdentityTransform TRANSFORM_IDENTITY — re-parents referencers and destroys the identity transform
mergeDuplicateGeometries GEOMETRY_DUPLICATE
mergeSimilarGeometries GEOMETRY_SIMILAR — fits a rigid transform via Kabsch (Horn's quaternion method) and instances each similar geometry through its referencing meshes' matrices
splitDenseGeometry GEOMETRY_OVER_BUDGET — splits dense / over-budget geometries (one split per apply)
splitLargeGeometry GEOMETRY_OVER_EXTENT — splits large / over-extent geometries (one split per apply)
dropDegenerateTriangles GEOMETRY_DEGENERATE_TRIANGLES — drops zero-area triangles from geom.indices
compactUnusedVertices GEOMETRY_UNUSED_VERTICES — compacts unused vertex slots, remaps indices
mergeDuplicateVertices GEOMETRY_DUPLICATE_VERTICES — coalesces byte-identical vertex slots, remaps indices
downgradeNonWatertight GEOMETRY_NON_WATERTIGHT — flips SolidPrimitiveSurfacePrimitive
dropDuplicateObject OBJECT_DUPLICATE_AABB — destroys duplicate SceneObjects (detach + destroy meshes, then destroy object)
recenterGeometry GEOMETRY_FAR_FROM_ORIGIN — shifts the AABB to origin and composes the inverse offset into each referencing mesh's matrix
unifyTriangleWinding GEOMETRY_INCONSISTENT_WINDING — flood-fill flip wrongly-wound triangles to match the seed
tightenAabb GEOMETRY_AABB_NOT_TIGHT — re-quantises positions into a tight AABB to recover precision
dropDuplicateTriangles GEOMETRY_DUPLICATE_INDICES — drops duplicate triangles (same vertex set, any rotation / winding) from indices

Codes without a built-in fix include MESH_DANGLING_*, MESH_NONFINITE_MATRIX, malformed GEOMETRY_* issues, and TRANSFORM_CYCLE.

Typical pipeline: load -> inspect -> applyFixes -> re-inspect -> render.

import * as sceneModelInspector from "@xeokit/sdk/inspect/sceneModel";

const report = sceneModelInspector.inspectSceneModel({
sceneModel,
checkDuplicateGeometries: true, // opt-in: byte-identical detection
checkSimilarGeometries: true, // opt-in: pose-invariant shape match
});

if (report.errors.length > 0) {
for (const e of report.errors) {
console.error(`[${e.code}] ${e.message}`);
}
return;
}

const fixResult = sceneModelInspector.applyFixes({sceneModel, report});
if (!fixResult.ok) throw new Error(fixResult.error);

const {fixed, skipped, errors} = fixResult.value;
console.log(
`fixed ${fixed.length}, skipped ${skipped.length}, ` +
`errors ${errors.length}`,
);

// Re-inspect after applying fixes.
const after = sceneModelInspector.inspectSceneModel({sceneModel});

optimizeSceneModel runs inspection first, stops on errors, splits oversized geometries, and prunes orphan resources. Use inspectSceneModel and applyFixes directly when you need per-rule control.

Classes

FixRegistry
InspectionRegistry

Interfaces

ApplyFixesIssueOutcome
ApplyFixesIssueOutcomeJson
ApplyFixesParams
ApplyFixesProgress
ApplyFixesResult
ApplyFixesResultJson
CodeAggregateJson
ConfigSchema
Fix
Inspection
InspectionReport
InspectionReportJson
InspectionReportToJsonParams
InspectProgress
InspectSceneModelParams
Issue
IssueHighlight
IssueJson
OptimizeSceneModelParams
ResolvedConfig
ResourceLabel
SceneModelInspectionIndex
VertexCanonicalSlots

Type Aliases

ConfigField
FixApplyResult
FixSkipReason
IssueSeverity
ResourceKind

Variables

compactUnusedVertices
DEFAULT_FIX_REGISTRY
DEFAULT_INSPECTION_REGISTRY
denseGeometries
downgradeNonWatertight
dropDegenerateTriangles
dropDuplicateObject
dropDuplicateTriangles
dropIdentityTransform
dropUnusedMaterial
dropUnusedTexture
dropUnusedTransform
duplicateGeometries
farFromOriginGeometries
geometryArrayLengths
geometryDataIntegrity
geometryQuality
identityTransforms
largeGeometries
mergeDuplicateGeometries
mergeDuplicateVertices
mergeSimilarGeometries
meshReferences
objectMeshReferences
objectPlacement
pruneDanglingMeshRefs
recenterGeometry
similarGeometries
splitDenseGeometry
splitLargeGeometry
splitOversizedGeometry
textureDimensions
tightenAabb
transformParentCycles
unifyTriangleWinding
unusedResources

Functions

applyFixes
applyFixesAsync
applyFixesResultToJson
createSceneModelInspectionIndex
descriptionForCode
findResourceLabel
findSceneObjectsForGeometry
getInspectionIndex
inspectionReportToJson
inspectSceneModel
inspectSceneModelAsync
issueToJson
labelForCode
optimizeSceneModel
outcomeToJson
resolveConfig
splitGeometryAndRebuildMeshes