Import a 3D Model and automatically assign and export animations
TypeScript
Start getting display change to work for weight painted mode. Issue with skeleton helper detached with transform
Scott Petrovic7ef298619b76
diff --git a/src/lib/EventListeners.ts b/src/lib/EventListeners.tsindex e8d3a0b..e503946 100644--- a/src/lib/EventListeners.ts+++ b/src/lib/EventListeners.ts@@ -36,7 +36,6 @@ export class EventListeners {})this.bootstrap.load_model_step.addEventListener('modelLoaded', () => {- this.bootstrap.scene.add(this.bootstrap.load_model_step.model_meshes())this.bootstrap.process_step = this.bootstrap.process_step_changed(ProcessStep.LoadSkeleton)})@@ -87,12 +86,7 @@ export class EventListeners {// going back to edit skeleton step after skinning// this will do a lot of resettingthis.bootstrap.ui.dom_back_to_edit_skeleton_button?.addEventListener('click', () => {- const existing_skinned_meshes = this.bootstrap.scene.children.filter((child: Object3D) => child.name === 'Skinned Mesh')- console.log(existing_skinned_meshes)- existing_skinned_meshes.forEach((existing_skinned_mesh: Object3D) => {- Utility.remove_object_with_children(existing_skinned_mesh)- })-+ this.bootstrap.remove_skinned_meshes_from_scene() // clear any existing skinned meshesthis.bootstrap.debugging_visual_object = Utility.regenerate_debugging_scene(this.bootstrap.scene)this.bootstrap.process_step = this.bootstrap.process_step_changed(ProcessStep.EditSkeleton)this.bootstrap.regenerate_skeleton_helper(this.bootstrap.edit_skeleton_step.skeleton())diff --git a/src/lib/processes/StepLoadModel.ts b/src/lib/processes/StepLoadModel.tsindex 220bc14..dfaa8d9 100644--- a/src/lib/processes/StepLoadModel.ts+++ b/src/lib/processes/StepLoadModel.ts@@ -188,7 +188,7 @@ export class StepLoadModel extends EventTarget {private strip_out_all_unecessary_model_data (model_data: Scene): Scene {// create a new scene object, and only include meshesconst new_scene = new Scene()- new_scene.name = 'New Scene'+ new_scene.name = 'Imported Model'model_data.traverse((child) => {let new_mesh: Mesh@@ -289,11 +289,11 @@ export class StepLoadModel extends EventTarget {return geometries_to_return}- public models_material_list(): Material[] {+ public models_material_list (): Material[] {return this.material_list}- public rotate_model_by_axis(axis: string, angle: number): void {+ public rotate_model_by_axis (axis: string, angle: number): void {this.final_mesh_data.traverse((obj) => {// if object is a mesh, rotate the geometry dataif (obj.type === 'Mesh') {diff --git a/src/lib/processes/StepWeightSkin.ts b/src/lib/processes/StepWeightSkin.tsindex 0c46144..55db7f0 100644--- a/src/lib/processes/StepWeightSkin.ts+++ b/src/lib/processes/StepWeightSkin.ts@@ -27,13 +27,18 @@ export class StepWeightSkin extends EventTarget {private all_mesh_materials: Material[] = []// weight painted mesh actually has multiple meshes that will go in a group- private readonly weight_painted_mesh_preview: Group | null = new Group()+ private readonly weight_painted_mesh_preview: Group = new Group()// debug options for bone skinning formulaprivate show_debug: boolean = falseprivate debug_scene_object: Object3D | undefinedprivate bone_index_to_test: number = -1+ constructor () {+ super()+ this.weight_painted_mesh_preview.name = 'Weight Painted Mesh Preview'+ }+public begin (): void {if (this.ui.dom_current_step_index !== null) {this.ui.dom_current_step_index.innerHTML = '3.5'@@ -113,13 +118,14 @@ export class StepWeightSkin extends EventTarget {}public create_binding_skeleton (): void {- if (this.skinning_armature !== undefined) {- // when we copy over the armature with the bind, we will lose the reference in the variable- this.binding_skeleton = Generators.create_skeleton(this.skinning_armature.children[0])- this.binding_skeleton.name = 'Mesh Binding Skeleton'- } else {- console.warn('Tried to create_binding_skeleton() but skinning_armature is undefined!')+ if (this.skinning_armature === undefined) {+ console.warn('Tried to create_binding_skeleton() but skinning_armature has no children!')+ return}++ // when we copy over the armature with the bind, we will lose the reference in the variable+ this.binding_skeleton = Generators.create_skeleton(this.skinning_armature.children[0])+ this.binding_skeleton.name = 'Mesh Binding Skeleton'}/**@@ -160,6 +166,10 @@ export class StepWeightSkin extends EventTarget {return this.skinned_meshes}+ public weight_painted_mesh_group (): Group | null {+ return this.weight_painted_mesh_preview+ }+public set_show_debug (value: boolean): void {this.show_debug = value}diff --git a/src/script.ts b/src/script.tsindex a9e5726..d36abf2 100644--- a/src/script.ts+++ b/src/script.ts@@ -48,6 +48,9 @@ export class Bootstrap {public skeleton_helper: CustomSkeletonHelper | undefined = undefinedpublic debugging_visual_object: Group = new Group()+ // when editing the skeleton, what type of mesh will we see+ public mesh_preview_display_type: ModelPreviewDisplay = ModelPreviewDisplay.Textured+private readonly clock = new THREE.Clock()private readonly environment_container: Group = new Group()@@ -165,6 +168,7 @@ export class Bootstrap {this.load_model_step.begin()breakcase ProcessStep.LoadSkeleton:+ this.scene.add(this.load_model_step.model_meshes())process_step = ProcessStep.LoadSkeletonthis.load_skeleton_step.begin()break@@ -179,7 +183,9 @@ export class Bootstrap {this.process_step = ProcessStep.BindPosethis.weight_skin_step.begin()this.transform_controls.enabled = false // shouldn't be editing bones- this.start_skin_weighting_step()+ this.calculate_skin_weighting_for_models()+ this.scene.add(...this.weight_skin_step.final_skinned_meshes()) // add final skinned mesh to scene+ this.process_step_changed(ProcessStep.AnimationsListing)breakcase ProcessStep.AnimationsListing:this.process_step = ProcessStep.AnimationsListing@@ -217,14 +223,18 @@ export class Bootstrap {}public changed_model_preview_display (mesh_textured_display_type: ModelPreviewDisplay): void {- // show/hide loaded textured model depending on view- this.load_model_step.model_meshes().visible = mesh_textured_display_type === ModelPreviewDisplay.Textured+ this.mesh_preview_display_type = mesh_textured_display_type- // weight paint preview model should probably be stored in the weight skin step+ // show/hide loaded textured model depending on view+ this.load_model_step.model_meshes().visible = this.mesh_preview_display_type === ModelPreviewDisplay.Textured- if (mesh_textured_display_type === ModelPreviewDisplay.WeightPainted) {+ if (this.mesh_preview_display_type === ModelPreviewDisplay.WeightPainted) {this.regenerate_weight_painted_preview_mesh()}++ // show/hide weight painted mesh depending on view+ this.weight_skin_step.weight_painted_mesh_group().visible =+ this.mesh_preview_display_type === ModelPreviewDisplay.WeightPainted}public handle_transform_controls_mouse_down (mouse_event: MouseEvent): void {@@ -272,18 +282,38 @@ export class Bootstrap {}}+ public remove_skinned_meshes_from_scene (): void {+ const existing_skinned_meshes = this.scene.children.filter((child: Object3D) => child.name === 'Skinned Mesh')+ existing_skinned_meshes.forEach((existing_skinned_mesh: Object3D) => {+ Utility.remove_object_with_children(existing_skinned_mesh)+ })+ }+private regenerate_weight_painted_preview_mesh (): void {- console.log('TODO: show the weight painted mesh logic here')+ // needed for skinning process+ this.calculate_skin_weighting_for_models()++ // if the weight painted mesh is not in scene, add it+ if (this.scene.getObjectByName('Weight Painted Mesh') === undefined) {+ this.scene.add(this.weight_skin_step.weight_painted_mesh_group())+ }++ // check to see how many weight painted meshes we hae+ console.log('Weight Painted Meshes in scene:', this.scene.children)}- private start_skin_weighting_step (): void {+ private calculate_skin_weighting_for_models (): void {// we only need one binding skeleton. All skinned meshes will use this.this.weight_skin_step.reset_all_skin_process_data() // clear out any existing skinned meshes in storage+ // needed for skinning process if we change modes+ this.weight_skin_step.create_bone_formula_object(this.edit_skeleton_step.armature(), this.edit_skeleton_step.algorithm(),+ this.load_skeleton_step.skeleton_type())+this.weight_skin_step.create_binding_skeleton()- // reset geometry data to skin- this.load_model_step.models_geometry_list().forEach((mesh_geometry, idx) => {+ // add geometry data needed for skinning+ this.load_model_step.models_geometry_list().forEach((mesh_geometry) => {this.weight_skin_step.add_to_geometry_data_to_skin(mesh_geometry)})@@ -297,7 +327,10 @@ export class Bootstrap {// TODO: Always regenerate the weight painted mesh preview for now. This will change later// when we have are in the "Weight Painted" display modethis.weight_skin_step.calculate_weights_for_all_mesh_data(true)- this.scene.add(...this.weight_skin_step.final_skinned_meshes())++ // TODO: maybe way to update references instead of removing and adding?+ // this.remove_skinned_meshes_from_scene() // clear any existing skinned meshes in the scene+ // this.scene.add(...this.weight_skin_step.final_skinned_meshes())// remember our skeleton position before we do the skinning process// that way if we revert to try again...we will have the original positions/rotations@@ -318,7 +351,7 @@ export class Bootstrap {return}- this.process_step_changed(ProcessStep.AnimationsListing)+ console.log('What does our scene look like after we are done skinning:', this.scene)}public test_bone_weighting_success (): boolean {