Import a 3D Model and automatically assign and export animations
TypeScript
Do a better job explaining errors when animation import fails
Scott Petrovic75bdc28d85c5
diff --git a/src/lib/processes/animations-listing/CustomAnimationValidation.ts b/src/lib/processes/animations-listing/CustomAnimationValidation.tsindex aedcf02..735dabb 100644--- a/src/lib/processes/animations-listing/CustomAnimationValidation.ts+++ b/src/lib/processes/animations-listing/CustomAnimationValidation.ts@@ -24,23 +24,24 @@ export default class CustomAnimationValidation {})})- const animation_bone_names = CustomAnimationValidation.get_animation_bone_names(animation_clips)+ const animation_bone_map = CustomAnimationValidation.get_animation_bones_by_clip(animation_clips)+ const animation_bone_names = new Set(animation_bone_map.keys())if (animation_bone_names.size === 0) {throw new NoAnimationsError('We couldn\'t find any animation tracks in this file.')}- // Check bone count mismatch- if (animation_bone_names.size !== target_bone_names.size) {- throw new IncompatibleSkeletonError('The Mesh2Motion skeleton has ' + target_bone_names.size +- ' bones, but your imported animation rig has ' + animation_bone_names.size + ' bones.')- }+ // Check bone name mismatch+ const missing_from_animation = Array.from(target_bone_names).filter(bone => !animation_bone_names.has(bone)).sort()+ const extra_in_animation = Array.from(animation_bone_names).filter(bone => !target_bone_names.has(bone)).sort()- // Check bone name mismatch (animation has bones not in target skeleton)- const missing_bones = Array.from(animation_bone_names).filter(bone => !target_bone_names.has(bone))- if (missing_bones.length > 0) {- throw new IncompatibleSkeletonError('The bone names dont match the Mesh2Motion rig exactly. ' +- 'The following bones were found in the animation but not in the Mesh2Motion skeleton: ' + missing_bones.join(', '))+ if (missing_from_animation.length > 0 || extra_in_animation.length > 0) {+ const details = CustomAnimationValidation.format_bone_mismatch_details(+ missing_from_animation,+ extra_in_animation,+ animation_bone_map+ )+ throw new IncompatibleSkeletonError('Bone names don\'t match the Mesh2Motion rig:\n' + details)}}@@ -60,6 +61,25 @@ export default class CustomAnimationValidation {return bone_names}+ /**+ * Gets bone names mapped to the animation clips they appear in+ */+ static get_animation_bones_by_clip (animation_clips: AnimationClip[]): Map<string, Set<string>> {+ const bone_to_clips = new Map<string, Set<string>>()+ animation_clips.forEach((clip) => {+ clip.tracks.forEach((track) => {+ const bone_name = CustomAnimationValidation.extract_bone_name_from_track(track.name)+ if (bone_name !== null) {+ if (!bone_to_clips.has(bone_name)) {+ bone_to_clips.set(bone_name, new Set())+ }+ bone_to_clips.get(bone_name)!.add(clip.name)+ }+ })+ })+ return bone_to_clips+ }+/*** Extracts bone name from animation track name*/@@ -77,6 +97,34 @@ export default class CustomAnimationValidation {return null}+ /**+ * Formats bone mismatch details in a side-by-side comparison+ */+ static format_bone_mismatch_details (+ missing_from_animation: string[],+ extra_in_animation: string[],+ animation_bone_map: Map<string, Set<string>>+ ): string {+ let details = ''++ if (missing_from_animation.length > 0) {+ details += 'Missing from animation (in Mesh2Motion but not animation):\n'+ details += missing_from_animation.join(', ')+ }++ if (extra_in_animation.length > 0) {+ if (details.length > 0) details += '\n\n'+ details += 'Extra in animation (in animation but not in Mesh2Motion):\n'+ extra_in_animation.forEach((bone) => {+ const clips = animation_bone_map.get(bone)+ const clip_names = clips ? Array.from(clips).join(', ') : 'unknown'+ details += '\n • ' + bone + ' (in: ' + clip_names + ')'+ })+ }++ return details+ }+/**** Shows different error messages when importing custom animations based on the type of error encountered*/