Import a 3D Model and automatically assign and export animations
TypeScript
potentially add an icon over the preview image to swap between mirroring option
Scott Petrovic02a0f04e4cc8
diff --git a/src/lib/processes/animations-listing/AnimationSearch.ts b/src/lib/processes/animations-listing/AnimationSearch.tsindex e5143be..5da59ca 100644--- a/src/lib/processes/animations-listing/AnimationSearch.ts+++ b/src/lib/processes/animations-listing/AnimationSearch.ts@@ -17,6 +17,14 @@ export class AnimationSearch extends EventTarget {private custom_event: CustomEvent | null = nullprivate show_selected_only: boolean = false+ private static readonly mirror_mode_cycle: AnimationMirrorExportMode[] = ['none', 'mirrored', 'both']++ private static readonly mirror_mode_icons: Record<AnimationMirrorExportMode, string> = {+ none: 'images/icons/mirror.svg',+ mirrored: 'images/icons/mirror.svg',+ both: 'images/icons/mirror-both.svg'+ }+constructor (filter_input_id: string, animation_list_container_id: string, theme_manager: ThemeManager, skeleton_type: SkeletonType) {super()this.filter_input = document.querySelector(`#${filter_input_id}`)@@ -91,14 +99,26 @@ export class AnimationSearch extends EventTarget {return}- // Add event listener to the container for checkbox/radio changes (event delegation)+ // Add event listener to the container for checkbox changes (event delegation)this.animation_list_container.addEventListener('change', (event) => {const target = event.target as HTMLInputElement- if (target?.type === 'checkbox' || this.is_mirror_mode_radio_input(target)) {- if (target?.type === 'checkbox') {- const row_element = target.closest('.anim-item, .anim-custom-item') as HTMLElement | null- if (row_element !== null) {- row_element.setAttribute('data-selected', target.checked ? 'true' : 'false')+ if (target?.type === 'checkbox') {+ const row_element = target.closest('.anim-item, .anim-custom-item') as HTMLElement | null+ if (row_element !== null) {+ row_element.setAttribute('data-selected', target.checked ? 'true' : 'false')++ // If a tile is deselected, reset its mirror mode so re-select starts from None.+ if (!target.checked) {+ const animation_index_str = row_element.getAttribute('data-animation-index')+ const animation_index = animation_index_str !== null ? parseInt(animation_index_str) : NaN+ if (!isNaN(animation_index) && animation_index >= 0 && animation_index < this.all_animations.length) {+ this.all_animations[animation_index].mirror_export_mode = 'none'+ }++ const mirror_toggle = row_element.querySelector('button[data-action="cycle-mirror-mode"]') as HTMLButtonElement | null+ if (mirror_toggle !== null) {+ this.sync_mirror_toggle_button_state(mirror_toggle, 'none')+ }}}@@ -120,10 +140,78 @@ export class AnimationSearch extends EventTarget {})this.dispatchEvent(this.custom_event)})++ // Add event listener for tri-state mirror toggle button clicks.+ this.animation_list_container.addEventListener('click', (event) => {+ const target = event.target as HTMLElement+ const toggle_button = target.closest('button[data-action="cycle-mirror-mode"]') as HTMLButtonElement | null+ if (toggle_button === null) {+ return+ }++ event.preventDefault()+ event.stopPropagation()++ const animation_index_str = toggle_button.getAttribute('data-animation-index')+ const animation_index = animation_index_str !== null ? parseInt(animation_index_str) : NaN+ if (isNaN(animation_index) || animation_index < 0 || animation_index >= this.all_animations.length) {+ return+ }++ const current_mode: AnimationMirrorExportMode = this.all_animations[animation_index].mirror_export_mode ?? 'none'+ const next_mode = this.get_next_mirror_export_mode(current_mode)+ this.all_animations[animation_index].mirror_export_mode = next_mode++ this.sync_mirror_toggle_button_state(toggle_button, next_mode)++ this.custom_event = new CustomEvent('export-options-changed', {+ detail: {+ selectedAnimations: this.get_selected_animation_indices(),+ exportAnimationCount: this.get_selected_export_animation_count()+ }+ })+ this.dispatchEvent(this.custom_event)+ })+ }++ private get_next_mirror_export_mode (current_mode: AnimationMirrorExportMode): AnimationMirrorExportMode {+ const current_index = AnimationSearch.mirror_mode_cycle.indexOf(current_mode)+ const next_index = current_index < 0+ ? 0+ : (current_index + 1) % AnimationSearch.mirror_mode_cycle.length++ return AnimationSearch.mirror_mode_cycle[next_index]}- private is_mirror_mode_radio_input (target: HTMLInputElement | null): boolean {- return target?.type === 'radio' && target.name.startsWith('mirror-export-mode-')+ private get_mirror_toggle_label (mode: AnimationMirrorExportMode): string {+ if (mode === 'none') {+ return 'Mirror mode: None'+ }++ if (mode === 'mirrored') {+ return 'Mirror mode: Mirrored'+ }++ return 'Mirror mode: Both'+ }++ private sync_mirror_toggle_button_state (toggle_button: HTMLButtonElement, mode: AnimationMirrorExportMode): void {+ const mirror_toggle_label = this.get_mirror_toggle_label(mode)++ toggle_button.setAttribute('data-mirror-mode', mode)+ toggle_button.setAttribute('aria-label', mirror_toggle_label)+ toggle_button.setAttribute('title', mirror_toggle_label)++ const row_element = toggle_button.closest('.anim-item, .anim-custom-item') as HTMLElement | null+ if (row_element !== null) {+ row_element.setAttribute('data-mirror-mode', mode)+ }++ const icon_element = toggle_button.querySelector('img')+ if (icon_element !== null) {+ icon_element.setAttribute('src', AnimationSearch.mirror_mode_icons[mode])+ icon_element.setAttribute('alt', mirror_toggle_label)+ }}private save_current_row_states (): void {@@ -141,22 +229,6 @@ export class AnimationSearch extends EventTarget {}})- const mirror_mode_radios = this.animation_list_container.querySelectorAll('input[type="radio"][name^="mirror-export-mode-"]')- mirror_mode_radios.forEach((radio) => {- const input = radio as HTMLInputElement- if (!input.checked) {- return- }-- const animation_index_str = input.getAttribute('data-animation-index')- const animation_index = animation_index_str !== null ? parseInt(animation_index_str) : NaN- if (isNaN(animation_index) || animation_index < 0 || animation_index >= this.all_animations.length) {- return- }-- const mode = input.value as AnimationMirrorExportMode- this.all_animations[animation_index].mirror_export_mode = mode- })}/* animations that are shown on UI after filtering */@@ -229,30 +301,30 @@ export class AnimationSearch extends EventTarget {: ''const mirror_export_mode = animation_clip.mirror_export_mode ?? 'none'+ const mirror_toggle_label = this.get_mirror_toggle_label(mirror_export_mode)const animation_entry_html = `- <div class="${is_custom_animation ? 'anim-custom-item' : 'anim-item'}" data-animation-index="${original_index}" data-selected="${was_checked ? 'true' : 'false'}">+ <div class="${is_custom_animation ? 'anim-custom-item' : 'anim-item'}" data-animation-index="${original_index}" data-selected="${was_checked ? 'true' : 'false'}" data-mirror-mode="${mirror_export_mode}"><button class="secondary-button play anim-play-button" data-action="play-animation" data-index="${original_index}" aria-label="Play ${this.animation_name_clean(animation_clip.name)}">${custom_animation_badge_html}<div class="anim-preview-placeholder"${preview_data_src_attribute}></div></button>- <div class="anim-row-content">- <label class="styled-checkbox anim-row-checkbox">- <input type="checkbox" name="${animation_clip.name}" value="${original_index}" ${checked_attribute}>- <span class="anim-preview-label">${this.animation_name_clean(animation_clip.name)}</span>- </label>-- <fieldset class="anim-mirror-segmented" aria-label="Mirror export mode for ${this.animation_name_clean(animation_clip.name)}">- <input type="radio" id="anim-${original_index}-mirror-none" name="mirror-export-mode-${original_index}" value="none" data-animation-index="${original_index}" ${mirror_export_mode === 'none' ? 'checked' : ''}>- <label for="anim-${original_index}-mirror-none">None</label>-- <input type="radio" id="anim-${original_index}-mirror-mirrored" name="mirror-export-mode-${original_index}" value="mirrored" data-animation-index="${original_index}" ${mirror_export_mode === 'mirrored' ? 'checked' : ''}>- <label for="anim-${original_index}-mirror-mirrored">Mirrored</label>-- <input type="radio" id="anim-${original_index}-mirror-both" name="mirror-export-mode-${original_index}" value="both" data-animation-index="${original_index}" ${mirror_export_mode === 'both' ? 'checked' : ''}>- <label for="anim-${original_index}-mirror-both">Both</label>- </fieldset>- </div>+ <label class="styled-checkbox anim-row-checkbox">+ <input type="checkbox" name="${animation_clip.name}" value="${original_index}" ${checked_attribute}>+ <span class="anim-preview-label">${this.animation_name_clean(animation_clip.name)}</span>+ </label>++ <button+ class="no-style-button anim-mirror-mode-toggle"+ type="button"+ data-action="cycle-mirror-mode"+ data-animation-index="${original_index}"+ data-mirror-mode="${mirror_export_mode}"+ aria-label="${mirror_toggle_label}"+ title="${mirror_toggle_label}"+ >+ <img src="${AnimationSearch.mirror_mode_icons[mirror_export_mode]}" alt="${mirror_toggle_label}" class="action-icon">+ </button></div>`// append the entire item HTML to the DOM element@@ -293,8 +365,8 @@ export class AnimationSearch extends EventTarget {video.className = 'anim-preview'const src = placeholder.getAttribute('data-src') ?? ''video.src = src- video.width = 76- video.height = 56+ video.width = 100+ video.height = 120video.loop = truevideo.muted = truevideo.playsInline = true // tells mobile browsers to play inline instead of going fullscreendiff --git a/src/styles.css b/src/styles.cssindex 65aa98c..fddccf6 100644--- a/src/styles.css+++ b/src/styles.css@@ -529,14 +529,16 @@ option {#animations-items{max-height: calc(100vh - 22rem);- display: flex;+ display: inline-flex;overflow: auto;;- flex-direction: column;+ flex-direction: row;margin-bottom: 1rem;background: var(--bg-alternate);border: 1px solid var(--bg-tertiary);- gap: 0.2rem;+ gap: 0.25rem;+ flex-wrap: wrap;overflow-x: hidden;+ width: 24rem;}#animations-items.create-page {@@ -557,16 +559,16 @@ option {.anim-item, .anim-custom-item {- display: flex;- flex-direction: row;- align-items: stretch;- justify-content: flex-start;+ display: inline-flex;+ flex-direction: column;+ justify-content: space-between;padding: 0;+ position: relative;transition: box-shadow 0.2s ease-in-out;- width: 100%;- min-height: 64px;+ width: 103px;+ height: 160px;}.anim-custom-item {@@ -583,40 +585,37 @@ option {}.anim-play-button {- margin: 0;+ margin-right: 0;+ padding: 0;+ display: inline-flex;+ flex-grow: 1;+ align-items: center;+ flex-direction: column;border-radius: 0;- width: 84px;- min-width: 84px;- height: 64px;- border-right: 1px solid var(--bg-tertiary);- position: relative;- overflow: hidden;+ border: none;+ box-shadow: none;+ width: 100%;+ height: 100%;+ transform: scale(1.0);}.anim-play-button .anim-preview-placeholder,.anim-play-button .anim-preview {- width: 76px;- height: 56px;- margin: auto;- border-radius: 2px;+ width: 100px;+ height: 120px;+ margin: 0;+ border-radius: 0;background: var(--bg-primary);object-fit: cover;-}--.anim-row-content {- display: flex;- flex: 1;- flex-direction: column;- align-items: flex-start;- justify-content: center;- gap: 0.2rem;- padding: 0.2rem 0.3rem;+ pointer-events: none;}.anim-row-checkbox {- margin: 0;- width: 100%;- min-width: 0;+ margin-top: 0.2rem;+ margin-bottom: 0.2rem;+ width: 100px;+ align-self: center;+ z-index: 2;}.anim-row-checkbox .anim-preview-label {@@ -626,48 +625,58 @@ option {}.anim-mirror-segmented {- display: inline-flex;- align-items: center;+ display: none;+}++.anim-mirror-mode-toggle {+ position: absolute;+ top: 0.25rem;+ right: 0.25rem;+ width: 35px;+ height: 35px;border: 1px solid var(--bg-tertiary);border-radius: 999px;- padding: 0.1rem;- margin: 0 0 0 1.75rem;- gap: 0.1rem;- white-space: nowrap;- flex-direction: row;+ background: color-mix(in srgb, var(--bg-primary) 80%, transparent);+ display: inline-flex;+ align-items: center;+ justify-content: center;+ padding: 0;+ margin: 0;+ cursor: pointer;+ z-index: 3;+ transition: transform 0.2s ease, border-color 0.2s ease;+ opacity: 1.0;}-.anim-item[data-selected="false"] .anim-mirror-segmented,-.anim-custom-item[data-selected="false"] .anim-mirror-segmented {- display: none;++.anim-mirror-mode-toggle .action-icon {+ width: 25px;+ height: 25px;}-.anim-mirror-segmented input[type="radio"] {- position: absolute;- opacity: 0;- width: 0;- height: 0;- pointer-events: none;+.anim-item[data-selected="false"] .anim-mirror-mode-toggle,+.anim-custom-item[data-selected="false"] .anim-mirror-mode-toggle {+ display: none;}-.anim-mirror-segmented label {- cursor: pointer;- border-radius: 999px;- padding: 0.2rem 0.45rem;- font-size: 0.74rem;- color: var(--text-alternate);- transition: background-color 0.2s ease, color 0.2s ease;+.anim-item[data-mirror-mode="none"] .anim-mirror-mode-toggle,+.anim-custom-item[data-mirror-mode="none"] .anim-mirror-mode-toggle {+ border-color: var(--bg-tertiary);+ opacity: 0.3;}-.anim-mirror-segmented input[type="radio"]:checked + label {- background: var(--button-primary-bg);- color: var(--text-primary);+.anim-item[data-mirror-mode="none"] .anim-mirror-mode-toggle .action-icon,+.anim-custom-item[data-mirror-mode="none"] .anim-mirror-mode-toggle .action-icon {+ filter: grayscale(1);}-.anim-mirror-segmented label:hover {- background: color-mix(in srgb, var(--bg-tertiary) 80%, transparent);+.anim-item[data-mirror-mode="mirrored"] .anim-mirror-mode-toggle,+.anim-custom-item[data-mirror-mode="mirrored"] .anim-mirror-mode-toggle {+ opacity: 1.0;}++@media (max-width: 980px) {#animations-items {width: 100%;diff --git a/static/images/icons/mirror-both.svg b/static/images/icons/mirror-both.svgnew file mode 100644index 0000000..bfefc08--- /dev/null+++ b/static/images/icons/mirror-both.svg@@ -0,0 +1,15 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<svg width="100%" height="100%" viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g transform="matrix(1,0,0,1,-0.509721,-293.945773)">+ <g id="MirrorBoth" transform="matrix(1,0,0,1,0.509721,293.945773)">+ <rect x="0" y="0" width="256" height="256" style="fill:none;"/>+ <g transform="matrix(1,0,0,1,4.517215,-286.544924)">+ <path d="M27.603,513.284L119.087,315.805L119.087,513.284L27.603,513.284Z" style="fill:rgb(255,255,255);"/>+ </g>+ <g transform="matrix(-0.993103,0,0,1,251.29242,-286.544924)">+ <path d="M27.603,513.284L119.087,315.805L119.087,513.284L27.603,513.284Z" style="fill:rgb(255,255,255);"/>+ </g>+ </g>+ </g>+</svg>diff --git a/static/images/icons/mirror-none.svg b/static/images/icons/mirror-none.svgnew file mode 100644index 0000000..2d8db42--- /dev/null+++ b/static/images/icons/mirror-none.svg@@ -0,0 +1,7 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <path d="M4 6h5v5"/>+ <path d="M20 6h-5v5"/>+ <path d="M9 11c0 3 1.6 5 3 7"/>+ <path d="M15 11c0 3-1.6 5-3 7"/>+ <path d="M4 20L20 4"/>+</svg>diff --git a/static/images/icons/mirror.svg b/static/images/icons/mirror.svgindex fa63c1c..6720e65 100644--- a/static/images/icons/mirror.svg+++ b/static/images/icons/mirror.svg@@ -5,11 +5,11 @@<g id="Mirror" transform="matrix(1,0,0,1,0.509721,293.945773)"><rect x="0" y="0" width="256" height="256" style="fill:none;"/><g transform="matrix(1,0,0,1,4.517215,-286.544924)">- <path d="M27.603,513.284L119.087,315.805L119.087,513.284L27.603,513.284ZM46.387,501.284L107.087,501.284L107.087,370.257L46.387,501.284Z" style="fill:rgb(216,216,216);"/>+ <path d="M27.603,513.284L119.087,315.805L119.087,513.284L27.603,513.284ZM46.387,501.284L107.087,501.284L107.087,370.257L46.387,501.284Z" style="fill:rgb(255,255,255);"/></g><g transform="matrix(-0.993103,0,0,1,251.29242,-286.544924)">- <path d="M27.603,513.284L119.087,513.284L119.087,315.805L27.603,513.284Z" style="fill:rgb(216,216,216);"/>- <path d="M27.603,513.284L119.087,513.284L119.087,315.805L27.603,513.284ZM46.463,501.284L107.003,370.6L107.003,501.284L46.463,501.284Z" style="fill:rgb(216,216,216);"/>+ <path d="M27.603,513.284L119.087,513.284L119.087,315.805L27.603,513.284Z" style="fill:rgb(255,255,255);"/>+ <path d="M27.603,513.284L119.087,513.284L119.087,315.805L27.603,513.284ZM46.463,501.284L107.003,370.6L107.003,501.284L46.463,501.284Z" style="fill:rgb(255,255,255);"/></g></g></g>