Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Change import animation button to a drop-down to selection animation type

Scott Petrovicf19137935743
diff --git a/src/index.html b/src/index.html
index a9e005a..518050e 100644
--- a/src/index.html
+++ b/src/index.html
@@ -170,13 +170,41 @@
<div style="display: flex; column-gap: 10px; justify-content: center;">
- <label for="import-animations-button" class="button" >
+
+ <!-- can import a different types of animations depending on skeleton it is associated with-->
+ <div class="animation-import-section">
+ <button id="import-animations-button" class="button dropbtn">
+ <span class="button-icon-group" style="pointer-events: none">
+ <span>Import</span>
+ <span class="material-symbols-outlined">arrow_drop_down</span>
+ </span>
+ </button>
+ <div id="animation-import-options" class="dropdown-content">
+ <a href="#" data-value="mixamo-animation">Mixamo Animation</a>
+ <a href="#" data-value="carnegie-animation">Carnegie Mellon Animation</a>
+ </div>
+ </div>
+
+
+ <!-- <div class="dropdown button">
+ <span class="button-icon-group">
+ <span>Import</span>
+ <span class="material-symbols-outlined">arrow_drop_down</span>
+ </span>
+ <div class="animation-import-dropdown-content">
+ <div id="mixamo-animation-import-option">Mixamo Animation</div>
+ <div id="carnegie-mellon-animation-import-option">Carnegie Mellon Animation</div>
+ </div>
+ </div> -->
+
+
+ <!-- <label for="import-animations-button" class="button" >
<span class="button-icon-group">
<span class="material-symbols-outlined">add</span>
<span>Import</span>
</span>
</label>
- <input id="import-animations-button" type="file" name="animation-upload" accept=".glb, .gltf, .fbx, .bvh" />
+ <input id="import-animations-button" type="file" name="animation-upload" accept=".glb, .gltf, .fbx, .bvh" /> -->
<button id="export-button">
<span class="button-icon-group">
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
index 1290b22..1162222 100644
--- a/src/lib/UI.ts
+++ b/src/lib/UI.ts
@@ -34,6 +34,8 @@ export class UI {
dom_extend_arm_button: Element | null = null
dom_export_button_hidden_link: Element | null = null
dom_build_version: Element | null = null
+ dom_animation_import_options: Element | null = null
+ dom_import_animations_buton: Element | null = null
constructor () {
this.initialize_dom_elements()
@@ -86,6 +88,9 @@ export class UI {
this.dom_build_version = document.querySelector('#build-version')
+ this.dom_import_animations_buton = document.querySelector('#import-animations-button')
+ this.dom_animation_import_options = document.querySelector('#animation-import-options')
+
// UI for exporting the animation
this.dom_export_button_hidden_link = document.querySelector('#download-hidden-link')
}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 28e9576..ca7ddd5 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -218,6 +218,19 @@ export class StepAnimationsListing extends EventTarget {
this.play_animation(this.current_playing_index)
})
+ if (this.ui.dom_import_animations_buton !== null && this.ui.dom_animation_import_options !== null) {
+ // toggle the Import button being shown/hidden
+ this.ui.dom_import_animations_buton.addEventListener('click', (event) => {
+ this.ui.dom_animation_import_options.classList.toggle('show')
+ })
+
+ // handle clicking an animation type to import
+ this.ui.dom_animation_import_options.addEventListener('click', (event) => {
+ const animation_type = event.target.getAttribute('data-value')
+ console.log('clicked on an import animation option', animation_type)
+ })
+ }
+
// helps ensure we don't add event listeners multiple times
this.has_added_event_listeners = true
}
diff --git a/src/script.ts b/src/script.ts
index cd2b005..140ff05 100644
--- a/src/script.ts
+++ b/src/script.ts
@@ -336,8 +336,34 @@ export class Bootstrap {
this.transform_controls.setMode('rotate')
}
})
+
+ window.addEventListener('click', (event: MouseEvent) => {
+ this.handle_closing_drop_down_ui(event)
+ }, false)
} // end event listeners
+ private handle_closing_drop_down_ui (event: MouseEvent): void {
+ if (event?.target === null) {
+ return
+ }
+
+ const target_element = event.target as Element
+
+ const target_has_dropdown = target_element.matches('.dropbtn') // button object
+ const parent_class_has_dropdown = target_element.parentElement?.matches('.dropbtn') // text inside button
+
+ if (!target_has_dropdown && parent_class_has_dropdown === false) {
+ const drop_downs = document.getElementsByClassName('dropdown-content')
+ let i = 0
+ for (i = 0; i < drop_downs.length; i++) {
+ const open_drop_downs = drop_downs[i]
+ if (open_drop_downs.classList.contains('show')) {
+ open_drop_downs.classList.remove('show')
+ }
+ }
+ }
+ }
+
private start_skin_weighting_step (): void {
// we only need one binding skeleton. All skinned meshes will use this.
this.weight_skin_step.create_binding_skeleton()
diff --git a/src/styles.css b/src/styles.css
index 84e7a7e..17c30b4 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -288,4 +288,40 @@ input[type="file"] {
#github-logo img {
width: 50px;
height: auto;
-}
\ No newline at end of file
+}
+
+
+
+
+/* drop-down button */
+/* Dropdown Button */
+
+ /* The container <div> - needed to position the dropdown content */
+ .dropdown {
+ position: relative;
+ display: inline-block;
+ }
+
+ /* Dropdown Content (Hidden by Default) */
+ .dropdown-content {
+ display: none;
+ position: absolute;
+ background-color: #b6cde0;
+ min-width: 160px;
+ box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
+ z-index: 1;
+ }
+
+ /* Links inside the dropdown */
+ .dropdown-content a {
+ color: black;
+ padding: 12px 16px;
+ text-decoration: none;
+ display: block;
+ }
+
+ /* Change color of dropdown links on hover */
+ .dropdown-content a:hover {background-color: #ddd;}
+
+ /* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
+ .show {display:block;}
\ No newline at end of file