3.2 KiB
3.2 KiB
Blender Integration Plan v2
Goal
Add an optional step to main.py to run blenderscripts/create_nodegroups.py and blenderscripts/create_materials.py on specified .blend files after asset processing is complete.
Proposed Plan
-
Update
config.py:- Add two new optional configuration variables:
DEFAULT_NODEGROUP_BLEND_PATHandDEFAULT_MATERIALS_BLEND_PATH. These will store the default paths to the Blender files.
- Add two new optional configuration variables:
-
Update
main.pyArgument Parser:- Add two new optional command-line arguments:
--nodegroup-blendand--materials-blend. - These arguments will accept file paths to the respective
.blendfiles. - If provided, these arguments will override the default paths specified in
config.py.
- Add two new optional command-line arguments:
-
Update
blenderscripts/create_nodegroups.pyandblenderscripts/create_materials.py:- Modify both scripts to accept the processed asset library root path (
PROCESSED_ASSET_LIBRARY_ROOT) as a command-line argument. This will be passed to the script when executed by Blender using the--separator. - Update the scripts to read this path from
sys.argvinstead of using the hardcoded variable.
- Modify both scripts to accept the processed asset library root path (
-
Update
main.pyExecution Flow:- After the main asset processing loop (
run_processing) completes and the summary is reported, check if the--nodegroup-blendor--materials-blendarguments (or their fallbacks fromconfig.py) were provided. - If a path for the nodegroup
.blendfile is available:- Construct a command to execute Blender in the background (
-b), load the specified nodegroup.blendfile, run thecreate_nodegroups.pyscript using--python, pass the processed asset root directory as an argument after--, and save the.blendfile (-S). - Execute this command using the
execute_commandtool.
- Construct a command to execute Blender in the background (
- If a path for the materials
.blendfile is available:- Construct a similar command to execute Blender in the background, load the specified materials
.blendfile, run thecreate_materials.pyscript using--python, pass the processed asset root directory as an argument after--, and save the.blendfile (-S). - Execute this command using the
execute_commandtool.
- Construct a similar command to execute Blender in the background, load the specified materials
- Include error handling for the execution of the Blender commands.
- After the main asset processing loop (
Execution Flow Diagram
graph TD
A[Asset Processing Complete] --> B[Report Summary];
B --> C{Nodegroup Blend Path Specified?};
C -- Yes --> D[Get Nodegroup Blend Path (Arg or Config)];
D --> E[Construct Blender Command for Nodegroups];
E --> F[Execute Command: blender -b nodegroup.blend --python create_nodegroups.py -- <asset_root> -S];
F --> G{Command Successful?};
G -- Yes --> H{Materials Blend Path Specified?};
G -- No --> I[Log Nodegroup Error];
I --> H;
H -- Yes --> J[Get Materials Blend Path (Arg or Config)];
J --> K[Construct Blender Command for Materials];
K --> L[Execute Command: blender -b materials.blend --python create_materials.py -- <asset_root> -S];
L --> M{Command Successful?};
M -- Yes --> N[End main.py];
M -- No --> O[Log Materials Error];
O --> N;
H -- No --> N;
C -- No --> H;