Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

More conversion to typescript and linting fixes

Scott Petrovic5dfc53b1d8b7
diff --git a/src/lib/UI.js b/src/lib/UI.js
deleted file mode 100644
index ef1811a..0000000
--- a/src/lib/UI.js
+++ /dev/null
@@ -1,93 +0,0 @@
-export class UI {
- constructor()
- {
- this._initializeDOMElements()
- }
-
- _initializeDOMElements()
- {
- // grab all UI Elements from page that we need to interact with
- this.dom_current_step_index = document.querySelector('#current-step-index')
- this.dom_current_step_element = document.querySelector('#current-step-label')
- this.dom_transform_controls_switch = document.querySelector('#transform-controls')
-
- // UI controls for loading the model
- this.dom_load_model_tools = document.querySelector('#load-model-tools')
- this.dom_upload_model_button = document.querySelector('#model-upload')
- this.dom_load_model_button = document.querySelector('#load-model-button')
- this.dom_load_model_debug_checkbox = document.querySelector('#load-model-debug-checkbox')
-
- this.dom_rotate_model_x_button = document.querySelector('#rotate-model-x-button')
- this.dom_rotate_model_y_button = document.querySelector('#rotate-model-y-button')
- this.dom_rotate_model_z_button = document.querySelector('#rotate-model-z-button')
-
-
- // UI controls for loading/working with skeleton
- this.dom_load_skeleton_tools = document.querySelector('#load-skeleton-tools')
- this.dom_load_skeleton_button = document.querySelector('#load-skeleton-button')
- this.dom_skeleton_edit_tools = document.querySelector('#skeleton-step-actions')
- this.dom_skeleton_drop_type = document.querySelector('#skeleton-selection')
- this.dom_mirror_skeleton_checkbox = document.querySelector('#mirror-skeleton')
- this.dom_scale_skeleton_button = document.querySelector('#scale-skeleton-button')
-
- this.dom_bind_pose_button = document.querySelector('#action_bind_pose')
- this.dom_scale_skeleton_input_box = document.querySelector('#scale-input')
- this.dom_move_to_origin_button = document.querySelector('#action_move_to_origin')
- this.dom_skinning_algorithm_selection = document.querySelector('#skinning-algorithm-options')
-
-
- // UI controls for working with skinned mesh
- this.dom_skinned_mesh_tools = document.querySelector('#skinned-step-tools')
- this.dom_skinned_mesh_animation_tools = document.querySelector('#skinned-step-animation-export-options')
- this.dom_show_skeleton_checkbox = document.querySelector('#show-skeleton-checkbox')
- this.dom_back_to_edit_skeleton_button = document.querySelector('#action_back_to_edit_skeleton')
- this.dom_enable_skin_debugging = document.querySelector('#debug-skinning-checkbox')
-
- // UI Controls for working with animation list/selection and export
- this.dom_animation_clip_list = document.querySelector('#animations-items')
- this.dom_export_button = document.querySelector('#export-button')
- 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')
- }
-
- get_animated_selected_elements()
- {
- // this needs to be called ad-hoc as selections might change
- return document.querySelectorAll('#animations-items input[type="checkbox"]')
- }
-
- hideAllElements()
- {
- this.dom_transform_controls_switch.style.display = 'none';
- this.dom_load_model_tools.style.display = 'none';
- this.dom_load_skeleton_tools.style.display = 'none';
- this.dom_skeleton_edit_tools.style.display = 'none';
- this.dom_skinned_mesh_tools.style.display = 'none';
- this.dom_skinned_mesh_animation_tools.style.display = 'none';
- }
-
- build_animation_clip_ui(animation_clips_to_load)
- {
- /// take the animation_clips_loaded, loop through them, and build out the UI
- this.dom_animation_clip_list.innerHTML = '';
- animation_clips_to_load.forEach((animation_clip, index) => {
- this.dom_animation_clip_list.innerHTML +=
- `<div class="anim-item">
- <div>
- <button class="secondary-button play" data-index="${index}">&#9658;</button>
- <span style="align-self: center">${animation_clip.name}</span>
- </div>
- <div>
- <input type="checkbox" name="${animation_clip.name}" value="${index}">
- </div>
- </div>`
- });
- }
-}
\ No newline at end of file
diff --git a/src/lib/UI.ts b/src/lib/UI.ts
new file mode 100644
index 0000000..fbf7caf
--- /dev/null
+++ b/src/lib/UI.ts
@@ -0,0 +1,136 @@
+import { type AnimationClip } from 'three'
+
+export class UI {
+ dom_current_step_index: Element | null = null
+ dom_current_step_element: Element | null = null
+ dom_transform_controls_switch: Element | null = null
+ dom_load_model_tools: Element | null = null
+ dom_upload_model_button: Element | null = null
+ dom_load_model_button: Element | null = null
+ dom_load_model_debug_checkbox: Element | null = null
+ dom_rotate_model_x_button: Element | null = null
+ dom_rotate_model_y_button: Element | null = null
+ dom_rotate_model_z_button: Element | null = null
+ dom_load_skeleton_tools: Element | null = null
+ dom_load_skeleton_button: Element | null = null
+ dom_skeleton_edit_tools: Element | null = null
+ dom_skeleton_drop_type: Element | null = null
+ dom_mirror_skeleton_checkbox: Element | null = null
+ dom_scale_skeleton_button: Element | null = null
+ dom_bind_pose_button: Element | null = null
+ dom_scale_skeleton_input_box: Element | null = null
+ dom_move_to_origin_button: Element | null = null
+ dom_skinning_algorithm_selection: Element | null = null
+ dom_skinned_mesh_tools: Element | null = null
+ dom_skinned_mesh_animation_tools: Element | null = null
+ dom_show_skeleton_checkbox: Element | null = null
+ dom_back_to_edit_skeleton_button: Element | null = null
+ dom_enable_skin_debugging: Element | null = null
+ dom_animation_clip_list: Element | null = null
+ dom_export_button: Element | null = null
+ dom_info_panel: Element | null = null
+ dom_import_animations_button: Element | null = null
+ dom_extend_arm_input: Element | null = null
+ dom_extend_arm_button: Element | null = null
+ dom_export_button_hidden_link: Element | null = null
+
+ constructor () {
+ this.initialize_dom_elements()
+ }
+
+ private initialize_dom_elements (): void {
+ // grab all UI Elements from page that we need to interact with
+ this.dom_current_step_index = document.querySelector('#current-step-index')
+ this.dom_current_step_element = document.querySelector('#current-step-label')
+ this.dom_transform_controls_switch = document.querySelector('#transform-controls')
+
+ // UI controls for loading the model
+ this.dom_load_model_tools = document.querySelector('#load-model-tools')
+ this.dom_upload_model_button = document.querySelector('#model-upload')
+ this.dom_load_model_button = document.querySelector('#load-model-button')
+ this.dom_load_model_debug_checkbox = document.querySelector('#load-model-debug-checkbox')
+
+ this.dom_rotate_model_x_button = document.querySelector('#rotate-model-x-button')
+ this.dom_rotate_model_y_button = document.querySelector('#rotate-model-y-button')
+ this.dom_rotate_model_z_button = document.querySelector('#rotate-model-z-button')
+
+ // UI controls for loading/working with skeleton
+ this.dom_load_skeleton_tools = document.querySelector('#load-skeleton-tools')
+ this.dom_load_skeleton_button = document.querySelector('#load-skeleton-button')
+ this.dom_skeleton_edit_tools = document.querySelector('#skeleton-step-actions')
+ this.dom_skeleton_drop_type = document.querySelector('#skeleton-selection')
+ this.dom_mirror_skeleton_checkbox = document.querySelector('#mirror-skeleton')
+ this.dom_scale_skeleton_button = document.querySelector('#scale-skeleton-button')
+
+ this.dom_bind_pose_button = document.querySelector('#action_bind_pose')
+ this.dom_scale_skeleton_input_box = document.querySelector('#scale-input')
+ this.dom_move_to_origin_button = document.querySelector('#action_move_to_origin')
+ this.dom_skinning_algorithm_selection = document.querySelector('#skinning-algorithm-options')
+
+ // UI controls for working with skinned mesh
+ this.dom_skinned_mesh_tools = document.querySelector('#skinned-step-tools')
+ this.dom_skinned_mesh_animation_tools = document.querySelector('#skinned-step-animation-export-options')
+ this.dom_show_skeleton_checkbox = document.querySelector('#show-skeleton-checkbox')
+ this.dom_back_to_edit_skeleton_button = document.querySelector('#action_back_to_edit_skeleton')
+ this.dom_enable_skin_debugging = document.querySelector('#debug-skinning-checkbox')
+
+ // UI Controls for working with animation list/selection and export
+ this.dom_animation_clip_list = document.querySelector('#animations-items')
+ this.dom_export_button = document.querySelector('#export-button')
+ 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')
+ }
+
+ public get_animated_selected_elements (): NodeListOf<Element> {
+ // this needs to be called ad-hoc as selections might change
+ return document.querySelectorAll('#animations-items input[type="checkbox"]')
+ }
+
+ public hide_all_elements (): void {
+ if (this.dom_transform_controls_switch != null) {
+ this.dom_transform_controls_switch.style.display = 'none'
+ }
+ if (this.dom_load_model_tools != null) {
+ this.dom_load_model_tools.style.display = 'none'
+ }
+ if (this.dom_load_skeleton_tools != null) {
+ this.dom_load_skeleton_tools.style.display = 'none'
+ }
+ if (this.dom_skeleton_edit_tools != null) {
+ this.dom_skeleton_edit_tools.style.display = 'none'
+ }
+ if (this.dom_skinned_mesh_tools != null) {
+ this.dom_skinned_mesh_tools.style.display = 'none'
+ }
+ if (this.dom_skinned_mesh_animation_tools != null) {
+ this.dom_skinned_mesh_animation_tools.style.display = 'none'
+ }
+ }
+
+ public build_animation_clip_ui (animation_clips_to_load: AnimationClip[]): void {
+ if (this.dom_animation_clip_list === null) {
+ return
+ }
+
+ /// take the animation_clips_loaded, loop through them, and build out the UI
+ this.dom_animation_clip_list.innerHTML = ''
+ animation_clips_to_load.forEach((animation_clip, index) => {
+ this.dom_animation_clip_list.innerHTML +=
+ `<div class="anim-item">
+ <div>
+ <button class="secondary-button play" data-index="${index}">&#9658;</button>
+ <span style="align-self: center">${animation_clip.name}</span>
+ </div>
+ <div>
+ <input type="checkbox" name="${animation_clip.name}" value="${index}">
+ </div>
+ </div>`
+ })
+ }
+}
diff --git a/src/lib/processes/StepAnimationsListing.ts b/src/lib/processes/StepAnimationsListing.ts
index 98b7dab..41b51d1 100644
--- a/src/lib/processes/StepAnimationsListing.ts
+++ b/src/lib/processes/StepAnimationsListing.ts
@@ -1,4 +1,4 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
@@ -9,8 +9,7 @@ import { SkeletonType } from '../enums/SkeletonType.js'
import { MixamoToSimpleMapping } from '../mapping/MixamoToSimple.js'
// Note: EventTarget is a built-ininterface and do not need to import it
-export class StepAnimationsListing extends EventTarget
-{
+export class StepAnimationsListing extends EventTarget {
private readonly ui: UI
private animation_clips_loaded: AnimationClip[] = []
private gltf_animation_loader: GLTFLoader = new GLTFLoader()
@@ -28,20 +27,16 @@ export class StepAnimationsListing extends EventTarget
this.ui = new UI()
}
- public begin (): void
- {
- if (this.ui.dom_current_step_index != null)
- {
+ public begin (): void {
+ if (this.ui.dom_current_step_index != null) {
this.ui.dom_current_step_index.innerHTML = '4'
}
- if (this.ui.dom_current_step_element != null)
- {
+ if (this.ui.dom_current_step_element != null) {
this.ui.dom_current_step_element.innerHTML = 'Test animations'
}
- if (this.ui.dom_skinned_mesh_tools != null)
- {
+ if (this.ui.dom_skinned_mesh_tools != null) {
this.ui.dom_skinned_mesh_tools.style.display = 'flex'
}
@@ -52,8 +47,7 @@ export class StepAnimationsListing extends EventTarget
this.add_event_listeners()
}
- public instructions_text (): string
- {
+ public instructions_text (): string {
return `<div>Instructions</div>
<div>Test and export animations to GLB format</div>
<ol>
@@ -63,24 +57,20 @@ export class StepAnimationsListing extends EventTarget
</ol>`
}
- public mixer (): AnimationMixer
- {
+ public mixer (): AnimationMixer {
return this.animation_mixer
}
- public animation_clips(): AnimationClip[]
- {
+ public animation_clips(): AnimationClip[] {
return this.animation_clips_loaded
}
- public load_and_apply_default_animation_to_skinned_mesh(final_skinned_meshes: SkinnedMesh[], skeleton_type: string): void
- {
+ public load_and_apply_default_animation_to_skinned_mesh(final_skinned_meshes: SkinnedMesh[], skeleton_type: string): void {
this.skinned_meshes_to_animate = final_skinned_meshes
this.skeleton_type = skeleton_type
let animations_to_load_filepath: string = ''
- switch (skeleton_type)
- {
+ switch (skeleton_type) {
case SkeletonType.BipedalSimple:
animations_to_load_filepath = 'animations/character-simple-multiple.glb'
break
@@ -109,15 +99,13 @@ export class StepAnimationsListing extends EventTarget
})
}
- private extend_arm_animations_by_percentage(percentage: number): void
- {
+ private extend_arm_animations_by_percentage(percentage: number): void {
// loop through each animation clip to update the tracks
this.animation_clips_loaded.forEach((animation_clip: AnimationClip) => {
animation_clip.tracks.forEach((track: KeyframeTrack) => {
// if our name does not contain 'quaternion', we need to exit
// since we are only modifying the quaternion tracks (e.g. L_Arm.quaternion )
- if (track.name.indexOf('quaternion') < 0)
- {
+ if (track.name.indexOf('quaternion') < 0) {
return
}
@@ -125,13 +113,11 @@ export class StepAnimationsListing extends EventTarget
// if the track is an upper arm bone, then modify that
const track_name_to_match: string = '_Arm' // for simplified human skeleton
- if (quaterion_track.name.indexOf(track_name_to_match) > -1)
- {
+ if (quaterion_track.name.indexOf(track_name_to_match) > -1) {
const new_track_values: Float32Array = quaterion_track.values.slice() // clone array
const track_count: number = quaterion_track.times.length
- for (let i = 0; i < track_count; i++)
- {
+ for (let i = 0; i < track_count; i++) {
// get correct value since it is a quaternion
const units_in_quaternions: number = 4
const quaternion: Quaternion = new Quaternion()
@@ -161,8 +147,7 @@ export class StepAnimationsListing extends EventTarget
})
}
- private play_animation(index: number = 0): void
- {
+ private play_animation(index: number = 0): void {
this.current_playing_index = index
// animation mixer has internal cache with animations. doing this helps clear it
@@ -178,23 +163,19 @@ export class StepAnimationsListing extends EventTarget
})
}
- private load_animation_clips(animation_clips: AnimationClip[]): void
- {
+ private load_animation_clips(animation_clips: AnimationClip[]): void {
this.animation_clips_loaded = this.remove_position_and_scale_keyframes_from_animations(animation_clips)
}
- private add_event_listeners(): void
- {
- if (this.has_added_event_listeners)
- {
+ private add_event_listeners(): void {
+ if (this.has_added_event_listeners) {
return
}
// event listener for animation clip list with changing the current animation
if (this.ui.dom_animation_clip_list != null) {
this.ui.dom_animation_clip_list.addEventListener('click', (event) => {
- if ((event.target != null) && event.target.tagName === 'BUTTON')
- {
+ if ((event.target != null) && event.target.tagName === 'BUTTON') {
const animation_index: number = event.target.getAttribute('data-index')
this.play_animation(animation_index)
}
@@ -216,12 +197,9 @@ export class StepAnimationsListing extends EventTarget
// even the binary data comes in as string, so treat it all that way for now
const file_info: string = reader.result
- if (file_extension === 'fbx')
- {
+ if (file_extension === 'fbx') {
this.load_fbx_animation_clips(file_info, file_name)
- }
- else if (file_extension === 'glb' || file_extension === 'gltf')
- {
+ } else if (file_extension === 'glb' || file_extension === 'gltf') {
this.load_gltf_animation_clips(file_info)
}
@@ -240,8 +218,7 @@ export class StepAnimationsListing extends EventTarget
this.has_added_event_listeners = true
}
- private load_fbx_animation_clips(fbx_file: string, file_name: string): void
- {
+ private load_fbx_animation_clips(fbx_file: string, file_name: string): void {
this.fbx_animation_loader = new FBXLoader()
this.fbx_animation_loader.load(fbx_file, (fbx) => {
@@ -250,8 +227,7 @@ export class StepAnimationsListing extends EventTarget
// check to see if the animation is a mixamo skeleton. we will need this later for potential mapping
const is_mixamo_animation: boolean = animations_for_scene[0].name === 'mixamo.com'
- if (is_mixamo_animation)
- {
+ if (is_mixamo_animation) {
// mutates animations_for_scene contents
this.process_mixamo_animation_clips(animations_for_scene, file_name)
}
@@ -263,8 +239,7 @@ export class StepAnimationsListing extends EventTarget
})
}
- private process_mixamo_animation_clips(animation_clips: AnimationClip[], file_name: string): void
- {
+ private process_mixamo_animation_clips(animation_clips: AnimationClip[], file_name: string): void {
const using_simplified_skeleton: boolean = this.skeleton_type === SkeletonType.BipedalSimple
// loop through each animation clip to update the tracks
@@ -277,19 +252,16 @@ export class StepAnimationsListing extends EventTarget
const keyframe_type: string = track.name.split('.')[1]
// selected skeleton is a simplified mixamo skeleton. We need to map bone names
- if (using_simplified_skeleton)
- {
+ if (using_simplified_skeleton) {
const is_mappping_found: boolean = MixamoToSimpleMapping[mixamo_bone_name]
- if (is_mappping_found)
- {
+ if (is_mappping_found) {
track.name = MixamoToSimpleMapping[mixamo_bone_name] + '.' + keyframe_type
}
}
// Mixamo has 1 unit = 1cm. We need to scale position data to compensate for that
// the 200 value is arbitrary, but the results seem to look good, so I went with that.
- if (keyframe_type === 'position')
- {
+ if (keyframe_type === 'position') {
(track.values as Float32Array).forEach((value, index) => {
track.values[index] = value / 200
})
@@ -298,15 +270,13 @@ export class StepAnimationsListing extends EventTarget
// with the simple skeleton, there are many bones that are not used from the full mixamo animation
// remove unmapped bones since they won't be used
- if (using_simplified_skeleton)
- {
+ if (using_simplified_skeleton) {
animation_clip.tracks = animation_clip.tracks.filter(x => !x.name.includes('mixamorig'))
}
})
}
- private load_gltf_animation_clips(gltf_file: string): void
- {
+ private load_gltf_animation_clips(gltf_file: string): void {
this.gltf_animation_loader = new GLTFLoader()
this.gltf_animation_loader.load(gltf_file, (gltf) => {
@@ -319,8 +289,7 @@ export class StepAnimationsListing extends EventTarget
})
}
- private append_animation_clips(animation_clips: AnimationClip[]): void
- {
+ private append_animation_clips(animation_clips: AnimationClip[]): void {
// 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) => {
@@ -328,8 +297,7 @@ export class StepAnimationsListing extends EventTarget
return animation_clip_loaded.name === animation_clip.name
})
- if (is_name_found !== undefined)
- {
+ if (is_name_found !== undefined) {
animation_clip.name = animation_clip.name + ' Copy'
}
})
@@ -337,8 +305,7 @@ export class StepAnimationsListing extends EventTarget
this.animation_clips_loaded.push(...this.remove_position_and_scale_keyframes_from_animations(animation_clips))
}
- private remove_position_and_scale_keyframes_from_animations(animation_clip_list: AnimationClip[]): AnimationClip[]
- {
+ private remove_position_and_scale_keyframes_from_animations(animation_clip_list: AnimationClip[]): AnimationClip[] {
// Don't use this for now. Maybe delete this function later
const animation_clips = this.deep_clone_animation_clips(animation_clip_list)
@@ -352,8 +319,7 @@ export class StepAnimationsListing extends EventTarget
return animation_clips
}
- private deep_clone_animation_clips(animation_clips: AnimationClip[]): AnimationClip[]
- {
+ private deep_clone_animation_clips(animation_clips: AnimationClip[]): AnimationClip[] {
return animation_clips.map((clip: AnimationClip) => {
const tracks = clip.tracks.map(track => track.clone())
return new AnimationClip(clip.name, clip.duration, tracks)
diff --git a/src/lib/processes/StepEditSkeleton.js b/src/lib/processes/StepEditSkeleton.ts
similarity index 75%
rename from src/lib/processes/StepEditSkeleton.js
rename to src/lib/processes/StepEditSkeleton.ts
index e5df9e1..ff0d19d 100644
--- a/src/lib/processes/StepEditSkeleton.js
+++ b/src/lib/processes/StepEditSkeleton.ts
@@ -1,40 +1,50 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import { Generators } from '../Generators.ts'
import { Utility } from '../Utilities.ts'
import { Vector3, Euler } from 'three'
import { SkinningFormula } from '../enums/SkinningFormula.js'
export class StepEditSkeleton extends EventTarget {
- ui = null
- edited_armature = null
- edited_skeleton = null
- mirror_mode_enabled = true
- skinning_algorithm = SkinningFormula.Envelope
- show_debug = true
-
- constructor()
- {
+ private readonly ui: UI
+ private edited_armature = null
+ private edited_skeleton = null
+ private mirror_mode_enabled = true
+ private skinning_algorithm = SkinningFormula.Envelope
+ private show_debug = true
+
+ constructor () {
super()
this.ui = new UI()
}
- begin()
- {
+ public begin (): void {
// show UI elemnents for editing mesh
- this.ui.dom_current_step_index.innerHTML = '3'
- this.ui.dom_current_step_element.innerHTML = 'Edit Skeleton'
- this.ui.dom_transform_controls_switch.style.display = 'flex'
- this.ui.dom_skeleton_edit_tools.style.display = 'flex'
+ if (this.ui.dom_current_step_index != null) {
+ this.ui.dom_current_step_index.innerHTML = '3'
+ }
+
+ if (this.ui.dom_current_step_element != null) {
+ this.ui.dom_current_step_element.innerHTML = 'Edit Skeleton'
+ }
+
+ if (this.ui.dom_transform_controls_switch != null) {
+ this.ui.dom_transform_controls_switch.style.display = 'flex'
+ }
+
+ if (this.ui.dom_skeleton_edit_tools != null) {
+ this.ui.dom_skeleton_edit_tools.style.display = 'flex'
+ }
+
+ if (this.ui.dom_enable_skin_debugging != null) {
+ this.show_debug = this.ui.dom_enable_skin_debugging.checked
+ }
- // get initial state for the show_debug checkbox
- this.show_debug = this.ui.dom_enable_skin_debugging.checked
this._update_bind_button_text()
this.addEventListeners()
}
- instructions_text()
- {
+ instructions_text () {
return `<div>Instructions</div>
<div>Position skeleton into correct postion</div>
<ol>
@@ -46,10 +56,8 @@ export class StepEditSkeleton extends EventTarget {
</ol>`
}
- _update_bind_button_text()
- {
- if(this.show_debug)
- {
+ _update_bind_button_text () {
+ if(this.show_debug) {
this.ui.dom_bind_pose_button.innerHTML = 'Test Skinning'
return
}
@@ -57,37 +65,30 @@ export class StepEditSkeleton extends EventTarget {
this.ui.dom_bind_pose_button.innerHTML = 'Skin Model'
}
- show_debugging()
- {
+ show_debugging () {
return this.show_debug
}
- set_mirror_mode_enabled(value)
- {
+ set_mirror_mode_enabled (value) {
this.mirror_mode_enabled = value
}
- is_mirror_mode_enabled()
- {
+ is_mirror_mode_enabled () {
return this.mirror_mode_enabled
}
- algorithm()
- {
+ algorithm () {
return this.skinning_algorithm
}
- addEventListeners()
- {
- this.ui.dom_move_to_origin_button.addEventListener('click', () =>
- {
+ addEventListeners () {
+ this.ui.dom_move_to_origin_button.addEventListener('click', () => {
// the base bone itself is not at the origin, but the parent is the armature object
this.edited_skeleton.bones[0].position.set(0, 0, 0)
this.edited_skeleton.bones[0].updateWorldMatrix(true, true) // update on renderer
})
- this.ui.dom_scale_skeleton_button.addEventListener('click', () =>
- {
+ this.ui.dom_scale_skeleton_button.addEventListener('click', () => {
const modify_scale = 1.0 + (this.ui.dom_scale_skeleton_input_box.value/100.0)
Utility.scale_armature_by_scalar(this.edited_armature, modify_scale)
this.edited_armature.updateWorldMatrix(true, true)
@@ -101,16 +102,11 @@ export class StepEditSkeleton extends EventTarget {
this.ui.dom_skinning_algorithm_selection.addEventListener('change', (event) => {
const selection = event.target.value
- if(selection === 'bone-envelope')
- {
+ if(selection === 'bone-envelope') {
this.skinning_algorithm = SkinningFormula.Envelope
- }
- else if(selection === 'closest-bone')
- {
+ } else if(selection === 'closest-bone') {
this.skinning_algorithm = SkinningFormula.Distance
- }
- else if(selection === 'closest-bone-middle')
- {
+ } else if(selection === 'closest-bone-middle') {
this.skinning_algorithm = SkinningFormula.MedianDistance
}
})
@@ -121,8 +117,7 @@ export class StepEditSkeleton extends EventTarget {
})
}
- removeEventListeners()
- {
+ removeEventListeners () {
this.ui.dom_move_to_origin_button.removeEventListener('click', () => {})
this.ui.dom_scale_skeleton_button.removeEventListener('click', () => {})
this.ui.dom_mirror_skeleton_checkbox.removeEventListener('change', () => {})
@@ -130,10 +125,8 @@ export class StepEditSkeleton extends EventTarget {
this.ui.dom_enable_skin_debugging.removeEventListener('change', () => {})
}
- set_armature(armature)
- {
- if(this.edited_armature !== null)
- {
+ set_armature (armature) {
+ if(this.edited_armature !== null) {
return this.edited_armature
}
@@ -142,8 +135,7 @@ export class StepEditSkeleton extends EventTarget {
this._create_skeleton()
}
- _create_skeleton()
- {
+ _create_skeleton () {
// create skeleton and helper to visualize
this.edited_skeleton = Generators.create_skeleton(this.edited_armature.children[0])
this.edited_skeleton.name = 'Editing Skeleton'
@@ -155,18 +147,15 @@ export class StepEditSkeleton extends EventTarget {
return this.edited_skeleton
}
- armature()
- {
+ armature () {
return this.edited_armature
}
- skeleton()
- {
+ skeleton () {
return this.edited_skeleton
}
- apply_mirror_mode(selected_bone, transform_type)
- {
+ apply_mirror_mode (selected_bone, transform_type) {
// if we are on the positive side mirror mode is enabled
// we need to change the position of the bone on the other side of the mirror
@@ -179,22 +168,18 @@ export class StepEditSkeleton extends EventTarget {
// that should be the mirror
let mirror_bone = null
- this.edited_skeleton.bones.forEach((bone) =>
- {
+ this.edited_skeleton.bones.forEach((bone) => {
const bone_name_to_compare = Utility.calculate_bone_base_name(bone.name)
- if(bone_name_to_compare === base_bone_name && bone.name !== selected_bone.name)
- {
+ if(bone_name_to_compare === base_bone_name && bone.name !== selected_bone.name) {
mirror_bone = bone
}
})
- if(mirror_bone === null)
- {
+ if(mirror_bone === null) {
return // we probably something along the axis (head, neck, spine)
}
- if(transform_type === 'translate')
- {
+ if(transform_type === 'translate') {
// move the mirror bone in the -X value of the transform control
// this will mirror the movement of the bone
mirror_bone.position.copy(
diff --git a/src/lib/processes/StepExportToFile.js b/src/lib/processes/StepExportToFile.js
index 3ffcec6..f4e897c 100644
--- a/src/lib/processes/StepExportToFile.js
+++ b/src/lib/processes/StepExportToFile.js
@@ -1,4 +1,4 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js'
import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js'
diff --git a/src/lib/processes/StepLoadModel.js b/src/lib/processes/StepLoadModel.js
index a51bc02..9a898a6 100644
--- a/src/lib/processes/StepLoadModel.js
+++ b/src/lib/processes/StepLoadModel.js
@@ -1,4 +1,4 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import * as THREE from 'three'
import { Box3 } from 'three/src/math/Box3.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
diff --git a/src/lib/processes/StepLoadSkeleton.js b/src/lib/processes/StepLoadSkeleton.js
index 4a6150c..f6651b5 100644
--- a/src/lib/processes/StepLoadSkeleton.js
+++ b/src/lib/processes/StepLoadSkeleton.js
@@ -1,4 +1,4 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import { Generators } from '../Generators.ts'
import { BufferGeometry, Float32BufferAttribute, Mesh, Box3, MeshBasicMaterial } from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
diff --git a/src/lib/processes/StepWeightSkin.js b/src/lib/processes/StepWeightSkin.js
index 9aaa829..4668078 100644
--- a/src/lib/processes/StepWeightSkin.js
+++ b/src/lib/processes/StepWeightSkin.js
@@ -1,4 +1,4 @@
-import { UI } from '../UI.js'
+import { UI } from '../UI.ts'
import { BoneWeightsByEnvelope } from '../solvers/BoneWeightsByEnvelope.ts'
import BoneWeightsByDistance from '../solvers/BoneWeightsByDistance.ts'
diff --git a/src/script.js b/src/script.js
index 1fbbbed..2a90ea2 100644
--- a/src/script.js
+++ b/src/script.js
@@ -6,11 +6,11 @@ import { Generators } from './lib/Generators.ts'
import { TransformControls } from 'three/examples/jsm/controls/TransformControls.js'
-import { UI } from './lib/UI.js'
+import { UI } from './lib/UI.ts'
import { StepLoadModel } from './lib/processes/StepLoadModel.js'
import { StepLoadSkeleton } from './lib/processes/StepLoadSkeleton.js'
-import { StepEditSkeleton } from './lib/processes/StepEditSkeleton.js'
+import { StepEditSkeleton } from './lib/processes/StepEditSkeleton.ts'
import { StepAnimationsListing } from './lib/processes/StepAnimationsListing.ts'
import { StepExportToFile } from './lib/processes/StepExportToFile.js'
import { StepWeightSkin } from './lib/processes/StepWeightSkin.js'
@@ -177,7 +177,7 @@ function start_skin_weighting_step () {
function process_step_changed (process_step) {
// we will have the current step turn on the UI elements it needs
- ui.hideAllElements()
+ ui.hide_all_elements()
// clean up any event listeners from the previous steps
edit_skeleton_step.removeEventListeners()
diff --git a/tsconfig.json b/tsconfig.json
index 98e0761..260ccbe 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -35,7 +35,7 @@
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
+ "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */