diff --git a/src/document/scene-document-validation.ts b/src/document/scene-document-validation.ts index d5ff8e03..81f7c7b9 100644 --- a/src/document/scene-document-validation.ts +++ b/src/document/scene-document-validation.ts @@ -3736,6 +3736,7 @@ function validateProjectScheduler( interface ProjectSchedulerValidationContext { actorIds: Set; + actorUsagesById: Map; entityCounts: Map; entityKindsById: Map>; modelInstanceCounts: Map; @@ -3743,6 +3744,15 @@ interface ProjectSchedulerValidationContext { soundEmitterHasAudioById: Map; } +interface ProjectSchedulerActorValidationUsage { + sceneId: string; + entityId: string; + modelAssetId: string | null; + animationNames: string[]; + pathIds: Set; + enabledPathIds: Set; +} + function incrementSchedulerValidationCount( counts: Map, id: string @@ -3763,6 +3773,7 @@ function addSchedulerValidationKind( function createEmptyProjectSchedulerValidationContext(): ProjectSchedulerValidationContext { return { actorIds: new Set(), + actorUsagesById: new Map(), entityCounts: new Map(), entityKindsById: new Map>(), modelInstanceCounts: new Map(), @@ -3773,14 +3784,37 @@ function createEmptyProjectSchedulerValidationContext(): ProjectSchedulerValidat function recordProjectSchedulerSceneTargets( context: ProjectSchedulerValidationContext, - scene: Pick + scene: Pick, + sceneId: string ) { + const pathIds = new Set(Object.keys(scene.paths)); + const enabledPathIds = new Set( + Object.values(scene.paths) + .filter((path) => path.enabled) + .map((path) => path.id) + ); + for (const entity of Object.values(scene.entities)) { incrementSchedulerValidationCount(context.entityCounts, entity.id); addSchedulerValidationKind(context.entityKindsById, entity.id, entity.kind); if (entity.kind === "npc") { context.actorIds.add(entity.actorId); + const usages = context.actorUsagesById.get(entity.actorId) ?? []; + const targetAsset = + entity.modelAssetId === null ? undefined : scene.assets[entity.modelAssetId]; + usages.push({ + sceneId, + entityId: entity.id, + modelAssetId: entity.modelAssetId, + animationNames: + targetAsset !== undefined && targetAsset.kind === "model" + ? [...targetAsset.metadata.animationNames] + : [], + pathIds: new Set(pathIds), + enabledPathIds: new Set(enabledPathIds) + }); + context.actorUsagesById.set(entity.actorId, usages); } if (entity.kind === "soundEmitter") { @@ -3808,7 +3842,7 @@ function createProjectSchedulerValidationContextFromSceneDocument( document: SceneDocument ): ProjectSchedulerValidationContext { const context = createEmptyProjectSchedulerValidationContext(); - recordProjectSchedulerSceneTargets(context, document); + recordProjectSchedulerSceneTargets(context, document, "activeScene"); return context; } @@ -3821,8 +3855,9 @@ function createProjectSchedulerValidationContextFromProjectDocument( recordProjectSchedulerSceneTargets(context, { entities: scene.entities, modelInstances: scene.modelInstances, - assets: document.assets - }); + assets: document.assets, + paths: scene.paths + }, scene.id); } return context;