Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Start with first option for bone algorithm instead of hard-coding it to bone envelope

Scott Petrovicacbecc115f48
diff --git a/src/index.html b/src/index.html
index a51d293..772c472 100644
--- a/src/index.html
+++ b/src/index.html
@@ -143,8 +143,8 @@
<!-- option to change out skinning algorithm -->
<label for="skinning-algorithm-options">Skinning algorithm:</label>
<select id="skinning-algorithm-options">
- <option value="bone-envelope">Bone Envelope</option>
<option value="closest-bone">Closest Bone</option>
+ <option value="bone-envelope">Bone Envelope</option>
<option value="closest-bone-middle">Closest Middle Bone</option>
</select>
diff --git a/src/lib/processes/StepEditSkeleton.ts b/src/lib/processes/StepEditSkeleton.ts
index 5622b5e..4143bd5 100644
--- a/src/lib/processes/StepEditSkeleton.ts
+++ b/src/lib/processes/StepEditSkeleton.ts
@@ -9,7 +9,7 @@ export class StepEditSkeleton extends EventTarget {
private edited_armature: Object3D = new Object3D()
private edited_skeleton: Skeleton = new Skeleton()
private mirror_mode_enabled: boolean = true
- private skinning_algorithm: string = SkinningFormula.Envelope
+ private skinning_algorithm: string | null = null
private show_debug: boolean = true
constructor () {
@@ -37,6 +37,12 @@ export class StepEditSkeleton extends EventTarget {
this.update_bind_button_text()
+ // set default skinning algorithm based on first option
+ if (this.ui.dom_skinning_algorithm_selection != null) {
+ const selection = this.ui.dom_skinning_algorithm_selection.value
+ this.skinning_algorithm = this.convert_skinning_algorithm_to_enum(selection)
+ }
+
this.add_event_listeners()
}
@@ -95,14 +101,7 @@ export class StepEditSkeleton extends EventTarget {
if (this.ui.dom_skinning_algorithm_selection !== null) {
this.ui.dom_skinning_algorithm_selection.addEventListener('change', (event) => {
const selection = event.target.value
-
- if (selection === 'bone-envelope') {
- this.skinning_algorithm = SkinningFormula.Envelope
- } else if (selection === 'closest-bone') {
- this.skinning_algorithm = SkinningFormula.Distance
- } else if (selection === 'closest-bone-middle') {
- this.skinning_algorithm = SkinningFormula.MedianDistance
- }
+ this.skinning_algorithm = this.convert_skinning_algorithm_to_enum(selection)
})
}
@@ -114,6 +113,17 @@ export class StepEditSkeleton extends EventTarget {
}
}
+ private convert_skinning_algorithm_to_enum (value: string): SkinningFormula {
+ switch (value) {
+ case 'bone-envelope':
+ return SkinningFormula.Envelope
+ case 'closest-bone-middle':
+ return SkinningFormula.MedianDistance
+ }
+
+ return SkinningFormula.Distance // default if other two don't match
+ }
+
public remove_event_listeners (): void {
if (this.ui.dom_move_to_origin_button !== null) {
this.ui.dom_move_to_origin_button.removeEventListener('click', () => {})