diff --git a/.gitignore b/.gitignore index 87a2326..84c2670 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ exports/ # Ignore Krita and Blender backups *.*~ + +# Ignore development files +pipeline/blender_autocomplete/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..aefbd80 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "jacqueslucke.blender-development", + "blenderfreetimeprojects.blender-python-code-templates", + "ms-python.vscode-pylance", + "ms-python.python" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c540aca --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "python.autoComplete.extraPaths": [ + "pipeline/blender_autocomplete/3.6" + ], + "python.linting.pylintArgs": [ + "--init-hook", + "import sys; sys.path.append('pipeline/blender_autocomplete/3.6')" + ], + "python.analysis.extraPaths": [ + "pipeline/blender_autocomplete/3.6" + ], + "blender.addon.moduleName": "BoneJuice", + "blender.addon.loadDirectory": "pipeline", + "blender.addon.reloadOnSave": true, + "blender.addon.sourceDirectory": "pipeline", + "python.analysis.diagnosticSeverityOverrides": { + "reportInvalidTypeForm": "none" + } +} \ No newline at end of file diff --git a/README.md b/README.md index 13820c9..42fec2f 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,7 @@ If you need results from an automated process, see the `pipeline` directory. Eac For animations, please include the `pipeline/export_anims.py` script in your Blender file. This allows one-click exporting of FBX animations (may be fully automated with a script later). +See [automation docs](docs/automation.md) + ## Questions If there are any questions or feedback on these guidelines and conventions, please poke Alan with a sharp, pointy stick. diff --git a/animations/infantry/anims-alan.blend b/animations/infantry/anims-alan.blend index 4ad97d2..772b49a 100644 --- a/animations/infantry/anims-alan.blend +++ b/animations/infantry/anims-alan.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e2bfcbb68a409261c659b674e630f91f624708f997d10c6065a6c0d5e45ef34b -size 3414388 +oid sha256:0c2f61a1922d2dff5eda8c6515f549fbbcace13867b6a391a57163e9b838fe75 +size 3520104 diff --git a/docs/automation.md b/docs/automation.md new file mode 100644 index 0000000..6cea5b0 --- /dev/null +++ b/docs/automation.md @@ -0,0 +1,15 @@ +# Automation + +## Setup +- Add Blender 3.6 to your PATH so it can be run from command-line (putting `blender` in cmd should open Blender 3.6) +- Ensure Python is installed on your machine +- Install Blender as a Python module (you might have to do this as administrator): `pip install bpy==3.6.0` + +## Editing + +- Ensure you have Visual Studio Code installed +- Open this directory in VS Code and install the recommended plugins +- Open terminal, `cd` into `pipeline`, and run the following command: `$ git clone https://github.com/Korchy/blender_autocomplete.git` + +## Resources +- [Blender as a Python Module](https://pypi.org/project/bpy/) diff --git a/pipeline/batch.py b/pipeline/batch.py new file mode 100644 index 0000000..3bd6063 --- /dev/null +++ b/pipeline/batch.py @@ -0,0 +1,16 @@ +import bpy +from bpy.app.handlers import persistent +import shutil + +blender_bin = shutil.which("blender") +if blender_bin: + print("Found:", blender_bin) + bpy.app.binary_path = blender_bin +else: + print("Unable to find blender!") + +@persistent +def load_handler(dummy): + print("Load Handler", bpy.data.filepath) + +bpy.app.handlers.load_post(load_handler) diff --git a/pipeline/export_all_anims.cmd b/pipeline/export_all_anims.cmd new file mode 100644 index 0000000..27bea95 --- /dev/null +++ b/pipeline/export_all_anims.cmd @@ -0,0 +1 @@ +blender ..\animations\infantry\anims-alan.blend --background --python export_anims.py \ No newline at end of file diff --git a/pipeline/export_anims.py b/pipeline/export_anims.py index 48eba69..07488d0 100644 --- a/pipeline/export_anims.py +++ b/pipeline/export_anims.py @@ -1,4 +1,39 @@ import bpy +from bpy.types import Collection, LayerCollection, Object, Armature + +# Enter object mode +bpy.ops.object.mode_set(mode='OBJECT') + +# FIRST, toggle collections +collections_exportable = [ + "insurrectionist", "infantry", "rigging", "geometry", "grapple", "baton", "helmet", "gun", "jetpack" +] +def toggle_collection(coll: LayerCollection): + # Iterate over all child LayerCollections + for child in coll.children.values(): + c: LayerCollection = child + + # Force include/exclude character-related collections so they're included/excluded from export + c.exclude = not (c.name in collections_exportable) + if c.name == "insurrectionist" or c.name == "infantry": + bpy.context.view_layer.active_layer_collection = c +toggle_collection(bpy.context.view_layer.layer_collection) + +# Find rig to make it active +armatureObj: Object = None +for objBase in bpy.context.scene.objects: + # print(objBase) + obj: Object = objBase + # print(obj.data) + if obj.type == 'ARMATURE': + print("FOUND AN ARMATURE") + armatureObj = obj + obj.select_set(True) +bpy.context.active_object +print(bpy.context.active_object) +#bpy.context.active_object.animation_data.nla_tracks + +exit() # Get export directory path: str = bpy.data.filepath.replace('\\Shelby', '').replace('\\Tommy', '')