Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Added new dragon rig with better controls and more bones in wings. Updated combine script to make sure Y+ is used.

Scott Petrovicbb14562dafb8
diff --git a/static/animations/dragon-animations.glb b/static/animations/dragon-animations.glb
index 809e201..47cc51c 100644
Binary files a/static/animations/dragon-animations.glb and b/static/animations/dragon-animations.glb differ
diff --git a/static/blender/rigs/bird/combine-and-export.py b/static/blender/rigs/bird/combine-and-export.py
deleted file mode 100644
index b29f04d..0000000
--- a/static/blender/rigs/bird/combine-and-export.py
+++ /dev/null
@@ -1,55 +0,0 @@
-import bpy
-import os
-
-## WHAT IS THIS SCRIPT FOR?
-# Each BLEND file only has one animation action. This script consolidates all these actions and
-# creates one GLB file that the Mesh2Motion tool can load.
-# This will make loading faster since it will be one HTTP request
-# if there gets to be a ton of animations, we can revisit this to split things apart.
-
-## INSTRUCTIONS ON HOW TO RUN
-# 1. Open the rig-bird.blend file in Blender. This process should work for all the rig files
-# 2. Open a "Text Editor" view and click New to create a new text area
-# 3. Copy and paste this script into the text area
-# 4. Update the path below to point to the rig you want to create a GLB for
-# 5. Click the "Run Script" (play) button
-# 6. You can put the GLB file in the static > animations folder overwriting the old rig one
-
-
-# Define the directory containing the Blender RIG files
-base_dir = r"C:\git\ModelMotionizer\static\blender\rigs"
-
-# Define the rig type/folder
-rig_type = "bird"
-
-
-# DO NOT NEED TO CHANGE BELOW THIS LINE
-#----------------------------------------------------
-
-# Define the output file path. It will be saved in the same directory as the input files
-blend_dir = os.path.join(base_dir, rig_type)
-output_file = os.path.join(blend_dir, f"{rig_type}-animations.glb")
-
-
-# Iterate over each Blender file
-for file in os.listdir(blend_dir):
- if file.endswith(".blend") and "animation" in file.lower():
- # Append actions from the file
- filepath = os.path.join(blend_dir, file)
- with bpy.data.libraries.load(filepath) as (data_from, data_to):
- data_to.actions = data_from.actions
-
-# Export the combined actions to a GLB file
-# select just the armature and mesh objects we want to export
-export_objects = [obj for obj in bpy.context.scene.objects if obj.type in ['ARMATURE', 'MESH']]
-for obj in export_objects:
- obj.select_set(True)
-
-
-bpy.ops.export_scene.gltf(
- filepath=output_file,
- export_format="GLB",
- export_animations=True,
- export_nla_strips=False, # Export actions instead of NLA strips
- use_selection=True
-)
\ No newline at end of file
diff --git a/static/blender/rigs/fox/combine-and-export.py b/static/blender/rigs/combine-and-export.py
similarity index 91%
rename from static/blender/rigs/fox/combine-and-export.py
rename to static/blender/rigs/combine-and-export.py
index 11feecc..7bf6fc0 100644
--- a/static/blender/rigs/fox/combine-and-export.py
+++ b/static/blender/rigs/combine-and-export.py
@@ -20,7 +20,7 @@ import os
base_dir = r"C:\git\ModelMotionizer\static\blender\rigs"
# Define the rig type/folder
-rig_type = "fox"
+rig_type = "dragon"
# DO NOT NEED TO CHANGE BELOW THIS LINE
@@ -52,5 +52,7 @@ bpy.ops.export_scene.gltf(
export_animations=True,
export_nla_strips=False, # Export actions instead of NLA strips
use_selection=True,
- use_visible=True # hides bone shape collection objects
+ export_yup=True, # Blender uses Z-up, three.js uses Y-up
+ export_def_bones=True, # only export deformation bones
+ use_visible=True, # hides bone shape collection objects
)
\ No newline at end of file
diff --git a/static/blender/rigs/dragon/animation-dragon-flap-v2.blend b/static/blender/rigs/dragon/animation-dragon-flap-v2.blend
new file mode 100644
index 0000000..aabd0e6
Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-flap-v2.blend differ
diff --git a/static/blender/rigs/dragon/animation-dragon-flap.blend b/static/blender/rigs/dragon/animation-dragon-flap.blend
deleted file mode 100644
index 32023a3..0000000
Binary files a/static/blender/rigs/dragon/animation-dragon-flap.blend and /dev/null differ
diff --git a/static/blender/rigs/dragon/animation-dragon-idle-v2.blend b/static/blender/rigs/dragon/animation-dragon-idle-v2.blend
new file mode 100644
index 0000000..e9bd633
Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-idle-v2.blend differ
diff --git a/static/blender/rigs/dragon/animation-dragon-idle.blend b/static/blender/rigs/dragon/animation-dragon-idle.blend
deleted file mode 100644
index 528ad72..0000000
Binary files a/static/blender/rigs/dragon/animation-dragon-idle.blend and /dev/null differ
diff --git a/static/blender/rigs/dragon/animation-dragon-walk-v2.blend b/static/blender/rigs/dragon/animation-dragon-walk-v2.blend
new file mode 100644
index 0000000..c602658
Binary files /dev/null and b/static/blender/rigs/dragon/animation-dragon-walk-v2.blend differ
diff --git a/static/blender/rigs/dragon/animation-dragon-walk.blend b/static/blender/rigs/dragon/animation-dragon-walk.blend
deleted file mode 100644
index b67c905..0000000
Binary files a/static/blender/rigs/dragon/animation-dragon-walk.blend and /dev/null differ
diff --git a/static/blender/rigs/dragon/rig-dragon.blend b/static/blender/rigs/dragon/rig-dragon-v2.blend
similarity index 52%
rename from static/blender/rigs/dragon/rig-dragon.blend
rename to static/blender/rigs/dragon/rig-dragon-v2.blend
index 0afe806..a312b4d 100644
Binary files a/static/blender/rigs/dragon/rig-dragon.blend and b/static/blender/rigs/dragon/rig-dragon-v2.blend differ
diff --git a/static/blender/rigs/fox/animation-fox-idle-v2.blend b/static/blender/rigs/fox/animation-fox-idle-v2.blend
index 510b104..24721c6 100644
Binary files a/static/blender/rigs/fox/animation-fox-idle-v2.blend and b/static/blender/rigs/fox/animation-fox-idle-v2.blend differ
diff --git a/static/blender/rigs/fox/rig-fox-v2.blend b/static/blender/rigs/fox/rig-fox-v2.blend
index 505d909..f252c10 100644
Binary files a/static/blender/rigs/fox/rig-fox-v2.blend and b/static/blender/rigs/fox/rig-fox-v2.blend differ
diff --git a/static/rigs/rig-dragon.glb b/static/rigs/rig-dragon.glb
index 26705cb..81803d2 100644
Binary files a/static/rigs/rig-dragon.glb and b/static/rigs/rig-dragon.glb differ