Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Show count of filtered animations in listing

Scott Petrovic31dd7d1aa76b
diff --git a/src/index.html b/src/index.html
index 10a1e82..a0b4f48 100644
--- a/src/index.html
+++ b/src/index.html
@@ -249,9 +249,9 @@
<div id="animations-listing">
- <!-- Filter textbox for animations -->
+ <!-- Filter textbox for animations -->
+ <div id="animation-listing-count">0</div>
<input type="text" id="animation-filter" placeholder="Filter animations...">
-
<!-- javascript will populate this item with animations
@@ -295,7 +295,7 @@
<button id="export-button" title="Export animations. Make sure to select the animations you want to export first.">
<span class="button-icon-group">
<span class="material-symbols-outlined">save_alt</span>
- <span>Download <span id="animation-selection-count">(0)</span></span>
+ <span>Download <span id="animation-selection-count">0</span></span>
</span>
</button>
<a id="download-hidden-link" href="#" style="display:none"></a>
diff --git a/src/lib/AnimationSearch.ts b/src/lib/AnimationSearch.ts
index 971b5ec..af6e8b0 100644
--- a/src/lib/AnimationSearch.ts
+++ b/src/lib/AnimationSearch.ts
@@ -11,11 +11,12 @@ export class AnimationSearch extends EventTarget {
private all_animations: AnimationWithState[] = []
private readonly filter_input: HTMLInputElement | null = null
private readonly animation_list_container: HTMLElement | null = null
+ private filtered_animations_list: AnimationWithState[] = []
private readonly theme_manager: ThemeManager
private readonly skeleton_type: SkeletonType
- private export_options_changed_event: CustomEvent | null = null
+ private custom_event: CustomEvent | null = null
constructor (filter_input_id: string, animation_list_container_id: string, theme_manager: ThemeManager, skeleton_type: SkeletonType) {
super()
@@ -60,6 +61,10 @@ export class AnimationSearch extends EventTarget {
this.filter_input.addEventListener('input', (event) => {
const filter_text = (event.target as HTMLInputElement).value.toLowerCase()
this.render_filtered_animations(filter_text)
+
+ // emit an event to notify that we have filtered our animation listing
+ this.custom_event = new CustomEvent('filtered-animations-listing', { detail: { selectedAnimations: this.get_selected_animation_indices() } })
+ this.dispatchEvent(this.custom_event)
})
}
@@ -76,8 +81,8 @@ export class AnimationSearch extends EventTarget {
}
// emit an event to notify other parts of the application that export options have changed
- this.export_options_changed_event = new CustomEvent('export-options-changed', { detail: { selectedAnimations: this.get_selected_animation_indices() } })
- this.dispatchEvent(this.export_options_changed_event)
+ this.custom_event = new CustomEvent('export-options-changed', { detail: { selectedAnimations: this.get_selected_animation_indices() } })
+ this.dispatchEvent(this.custom_event)
})
}
@@ -97,20 +102,26 @@ export class AnimationSearch extends EventTarget {
})
}
+ /* animations that are shown on UI after filtering */
+ public filtered_animations (): AnimationWithState[] {
+ return this.filtered_animations_list
+ }
+
private render_filtered_animations (filter_text: string): void {
if (this.animation_list_container === null) {
return
}
// Filter animations based on search text
- const filtered_animations = this.all_animations.filter((animation_clip) => {
- return animation_clip.name.toLowerCase().includes(filter_text)
+ this.filtered_animations_list = this.all_animations.filter(animation => {
+ return animation.name.toLowerCase().includes(filter_text)
})
+
// Clear and rebuild the animation list
this.animation_list_container.innerHTML = ''
- filtered_animations.forEach((animation_clip) => {
+ this.filtered_animations_list.forEach((animation_clip) => {
if (this.animation_list_container == null) {
return
}
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 8fa8a72..3da1fcf 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -59,6 +59,7 @@ export class UI {
dom_a_pose_correction_options: HTMLElement | null = null
dom_export_button_hidden_link: HTMLElement | null = null
dom_animation_count: HTMLElement | null = null
+ dom_animations_listing_count: HTMLElement | null = null
dom_build_version: HTMLElement | null = null
@@ -139,6 +140,7 @@ export class UI {
// UI for exporting the animation
this.dom_export_button_hidden_link = document.querySelector('#download-hidden-link')
this.dom_animation_count = document.querySelector('#animation-selection-count')
+ this.dom_animations_listing_count = document.querySelector('#animation-listing-count')
}
public hide_all_elements (): void {
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 2a0051d..196b05d 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -192,8 +192,6 @@ export class StepAnimationsListing extends EventTarget {
return 0
})
- console.log('all animations loaded:', this.animation_clips_loaded)
-
// create user interface with all available animation clips
this.build_animation_clip_ui(this.animation_clips_loaded, this.theme_manager, this.skeleton_type)
@@ -202,12 +200,21 @@ export class StepAnimationsListing extends EventTarget {
this.animation_search?.addEventListener('export-options-changed', () => {
// update the count for the download button
this.ui.dom_animation_count.innerHTML = this.animation_search?.get_selected_animation_indices().length.toString() ?? '0'
- this.ui.dom_animation_count.innerHTML = ' (' + this.ui.dom_animation_count.innerHTML + ')'
+ })
+
+ // add event listener to listen for filtered animations listing
+ this.update_filtered_animation_listing_ui()
+ this.animation_search?.addEventListener('filtered-animations-listing', () => {
+ this.update_filtered_animation_listing_ui()
})
this.play_animation(0) // play the first animation by default
}
+ private update_filtered_animation_listing_ui (): void {
+ const animation_length_string: string = this.animation_search?.filtered_animations().length.toString() ?? '0'
+ this.ui.dom_animations_listing_count.innerHTML = animation_length_string
+ }
private apply_hip_bone_offset (animation_clips: AnimationClip[]): void {
// update the position keyframes for the hips bone
diff --git a/src/styles.css b/src/styles.css
index 7a525aa..82b3974 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -93,6 +93,21 @@ h1, h2, h3, h4, h5, h6, input, button, select {
border-radius: 4px;
margin-bottom: 0.5rem;
}
+#animation-listing-count {
+ font-size: 90%;
+ position: absolute;
+ right: 3rem;
+ top: 5rem;
+}
+
+/* indicator on download buton with how many are selected */
+#animation-selection-count {
+ color: var(--text-primary);
+ padding: 0.1rem .5rem;
+ background-color: var(--bg-primary);
+ border-radius: 50%;
+ font-size: 80%;
+}
hr {
border:1px solid var(--bg-alternate);
@@ -355,6 +370,7 @@ option {
.anim-preview-label {
font-size: 75%;
cursor: pointer;
+ line-height: 110%;
}