Import a 3D Model and automatically assign and export animations
TypeScript
Hook up actually adding animations
Scott Petrovicc40c5ae628b0
diff --git a/src/index.html b/src/index.htmlindex b1c851c..1acd9f6 100644--- a/src/index.html+++ b/src/index.html@@ -34,7 +34,7 @@<label for="model-upload" class="button" ><span class="button-icon-group"><span class="material-symbols-outlined" >upload</span>- Upload GLTF+ <span>Upload GLTF</span></span></label><input id="model-upload" type="file" name="file-upload" accept=".glb, .gltf" />@@ -145,12 +145,22 @@<div style="display: flex; column-gap: 10px; justify-content: center;">- <button id="import-animations-button" class="secondary-button" style="margin: 0;">+ <!-- <button id="import-animations-button" class="secondary-button" style="margin: 0;"><span class="button-icon-group"><span class="material-symbols-outlined">add</span><span>Import</span></span>- </button>+ </button> -->++ <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" />++<button id="export-button">diff --git a/src/lib/processes/StepAnimationsListing.js b/src/lib/processes/StepAnimationsListing.jsindex 80fc26d..b91aa55 100644--- a/src/lib/processes/StepAnimationsListing.js+++ b/src/lib/processes/StepAnimationsListing.js@@ -53,17 +53,37 @@ export class StepAnimationsListing extends EventTarget});- this.ui.dom_import_animations_button.addEventListener('click', () => {- console.log('Nbring up file dialog to import animations')- // bring up file dialog to import animattions file (just support GLB for now)+ this.ui.dom_import_animations_button.addEventListener('change', (event) => {+ const file = event.target.files[0];+ const reader = new FileReader();+ reader.readAsDataURL(file);- // parse through the file and extract the animations+ console.log('loading more files')- // make sure the animations are compatible with the skeleton+ reader.onload = () => {+ var animations_import = reader.result- // add the animations to the animation_clips_loaded+ this.loader = new GLTFLoader();+ this.loader.load(animations_import, (gltf) => {+ const animations_for_scene = gltf.animations; // we only need the animations++ // make sure the animations are compatible with the skeleton+ // TODO: figure out what type of validation I could do with this++ // add the animations to the animation_clips_loaded+ // update the UI with the new animation clips+ this._append_animation_clips(animations_for_scene)+ this.ui.build_animation_clip_ui(this.animation_clips_loaded);++ // clear out the file input field in case we want to test by loading same file again+ this.ui.dom_import_animations_button.value = '';++ });++ };+});}@@ -99,6 +119,38 @@ export class StepAnimationsListing extends EventTargetthis.animation_clips_loaded = this._remove_position_keyframes_from_animations(animation_clips)}+ _append_animation_clips(animation_clips)+ {+ // loop through each animation_clip and change name if the animaton name already exists+ // see if the aniation name is already taken.. if so, add a number to the end of the name+ animation_clips.forEach((animation_clip) => {++ let animation_clip_name_found = false+ let name_counter = 0++ while(!animation_clip_name_found)+ {+ let is_name_found = this.animation_clips_loaded.find((animation_clip_loaded) => {+ return animation_clip_loaded.name === animation_clip.name+ })++ if(is_name_found === undefined)+ {+ animation_clip_name_found = true+ }+ else+ {+ console.log('duplicate found, adding number to end of name', animation_clip.name)+ name_counter+++ animation_clip.name = `${animation_clip.name}-${name_counter}`+ }+ }+ });++ this.animation_clips_loaded.push(...this._remove_position_keyframes_from_animations(animation_clips))++ }+_remove_position_keyframes_from_animations(animation_clip_list){let animation_clips = this._deep_clone_animation_clips(animation_clip_list)diff --git a/src/styles.css b/src/styles.cssindex 9687163..84e7a7e 100644--- a/src/styles.css+++ b/src/styles.css@@ -105,6 +105,10 @@ button:active, .button:active {justify-content: center;column-gap: 6px;}+.button-icon-group span{+ align-self: center;+}+.transform-icons {width: 25px;