Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Start trying to figure out extending arms positions with control

Scott Petrovic45e7d7529f86
diff --git a/src/index.html b/src/index.html
index 6b10567..5ddac24 100644
--- a/src/index.html
+++ b/src/index.html
@@ -157,14 +157,18 @@
that we get from the animations file(s) -->
<div id="animations-items"> </div>
- <div style="display: flex; column-gap: 10px; justify-content: center;">
- <!-- <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> -->
+ <!-- slider to control arm extension -->
+ <div style="display: flex; flex-direction: row; justify-content: space-evenly; align-items: center;">
+ <input type="number" id="extend-arm-input" name="arm-extend-input" value="1" min="-25" max="25" step="0.1">
+ <span class="suffix-unit">%</span>
+ <button id="extend-arm-button" class="secondary-button" >Extend</button>
+ </div>
+
+ <hr />
+
+
+ <div style="display: flex; column-gap: 10px; justify-content: center;">
<label for="import-animations-button" class="button" >
<span class="button-icon-group">
@@ -174,9 +178,6 @@
</label>
<input id="import-animations-button" type="file" name="animation-upload" accept=".glb, .gltf" />
-
-
-
<button id="export-button">
<span class="button-icon-group">
<span class="material-symbols-outlined">save_alt</span>
diff --git a/src/lib/UI.js b/src/lib/UI.js
index 66d40d0..ef1811a 100644
--- a/src/lib/UI.js
+++ b/src/lib/UI.js
@@ -49,6 +49,10 @@ export class UI {
this.dom_info_panel = document.querySelector('#info-messaging')
this.dom_import_animations_button = document.querySelector('#import-animations-button')
+ this.dom_extend_arm_input = document.querySelector('#extend-arm-input')
+ this.dom_extend_arm_button = document.querySelector('#extend-arm-button')
+
+
// UI for exporting the animation
this.dom_export_button_hidden_link = document.querySelector('#download-hidden-link')
}
diff --git a/src/lib/processes/StepAnimationsListing.js b/src/lib/processes/StepAnimationsListing.js
index c4c07ec..9d1bd69 100644
--- a/src/lib/processes/StepAnimationsListing.js
+++ b/src/lib/processes/StepAnimationsListing.js
@@ -2,7 +2,7 @@ import { UI } from '../UI.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
-import { AnimationClip, AnimationMixer } from 'three';
+import { AnimationClip, AnimationMixer, Quaternion, Vector3 } from 'three';
import { SkeletonType } from '../enums/SkeletonType.js';
// Note: EventTarget is a built-ininterface and do not need to import it
@@ -13,6 +13,7 @@ export class StepAnimationsListing extends EventTarget
animation_loader = null
animation_mixer = null
skinned_meshes_to_animate = []
+ current_playing_index = 0
constructor()
{
@@ -86,14 +87,64 @@ export class StepAnimationsListing extends EventTarget
});
+ this.ui.dom_extend_arm_button.addEventListener('click', (event) => {
+ let extend_arm_value = this.ui.dom_extend_arm_input.value
+ this._extend_arm_animations_by_percentage(extend_arm_value)
+ this._play_animation(this.current_playing_index)
+ })
+
+ }
+
+ _extend_arm_animations_by_percentage(percentage)
+ {
+ // loop through each animation clip to update the tracks
+ this.animation_clips_loaded.forEach((animation_clip) => {
+
+ animation_clip.tracks.forEach((track) => {
+
+ // if the track is an upper arm bone, then modify that
+ const track_name_to_match = '_Arm.quaternion' // for simplified human skeleton
+ if(track.name.indexOf(track_name_to_match) > -1)
+ {
+ const new_track_values = track.values.slice(); // clone array
+ const track_count = track.times.length
+ for(let i = 0; i < track_count; i++)
+ {
+ // get correct value since it is a quaternion
+ const units_in_quaternions = 4
+
+
+ const quaternion = new Quaternion();
+ quaternion.setFromAxisAngle( new Vector3( 0, percentage, 0 ), Math.PI / 2 );
+
+
+
+ // this should change the first quaternion component of the track
+ new_track_values[i * units_in_quaternions + 0] = quaternion.x
+ new_track_values[i * units_in_quaternions + 1] = quaternion.y
+ new_track_values[i * units_in_quaternions + 2] = quaternion.z
+ new_track_values[i * units_in_quaternions + 3] = quaternion.w
+ }
+
+ track.values = new_track_values
+ console.log(new_track_values)
+ }
+
+
+ })
+
+ })
+
}
_play_animation(index = 0)
{
+ this.current_playing_index = index
+
this.animation_mixer.stopAllAction();
this.skinned_meshes_to_animate.forEach((skinned_mesh) => {
- let anim_clip = this.animation_mixer.clipAction(this.animation_clips_loaded[index], skinned_mesh);
+ let anim_clip = this.animation_mixer.clipAction(this.animation_clips_loaded[this.current_playing_index], skinned_mesh);
anim_clip.play();
});
}
diff --git a/src/lib/processes/StepLoadModel.js b/src/lib/processes/StepLoadModel.js
index ff0cbf7..917d016 100644
--- a/src/lib/processes/StepLoadModel.js
+++ b/src/lib/processes/StepLoadModel.js
@@ -296,7 +296,6 @@ export class StepLoadModel extends EventTarget
break;
}
- //obj.geometry.rotateX(THREE.MathUtils.degToRad(angle))
}
})