From e4cf8b202b99538a53f49fe4f576cbd7c1d7e9d4 Mon Sep 17 00:00:00 2001 From: Jack Yao <151671689+jack-yao91@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:34:03 -0600 Subject: [PATCH] Send2UE - Added `object_collection_override` list to properties (#104) * Added object_collection_override list to properties * Prevent displaying the pipeline menu based on environment variable --- docs/send2ue/customize/python-api.md | 15 +++++++++++++++ src/addons/send2ue/__init__.py | 2 +- src/addons/send2ue/blender_manifest.toml | 2 +- src/addons/send2ue/core/export.py | 6 ++++-- src/addons/send2ue/core/utilities.py | 12 +++++++++--- src/addons/send2ue/properties.py | 3 +++ src/addons/send2ue/release_notes.md | 12 ++++++++---- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/docs/send2ue/customize/python-api.md b/docs/send2ue/customize/python-api.md index c3e7ea75..2ad8611e 100644 --- a/docs/send2ue/customize/python-api.md +++ b/docs/send2ue/customize/python-api.md @@ -111,5 +111,20 @@ bpy.ops.send2ue.start_rpc_servers() bpy.ops.wm.send2ue() ``` +!!! tip + + Here is how you could use Python to override what objects are collected. + ```python + import bpy + + # override what objects are collected + bpy.context.window_manager.send2ue.object_collection_override.extend([ + bpy.data.objects['Cube'] + ]) + + # run send to unreal + bpy.ops.wm.send2ue() + ``` + The same process can be used to dynamically set any property on the Send to Unreal tool. diff --git a/src/addons/send2ue/__init__.py b/src/addons/send2ue/__init__.py index 043e2e41..21c38c6f 100644 --- a/src/addons/send2ue/__init__.py +++ b/src/addons/send2ue/__init__.py @@ -11,7 +11,7 @@ bl_info = { "name": "Send to Unreal", "author": "Epic Games Inc (now a community fork)", - "version": (2, 5, 0), + "version": (2, 6, 0), "blender": (3, 6, 0), "location": "Header > Pipeline > Send to Unreal", "description": "Sends an asset to the first open Unreal Editor instance on your machine.", diff --git a/src/addons/send2ue/blender_manifest.toml b/src/addons/send2ue/blender_manifest.toml index f8ffb92d..a0f86a5f 100644 --- a/src/addons/send2ue/blender_manifest.toml +++ b/src/addons/send2ue/blender_manifest.toml @@ -2,7 +2,7 @@ schema_version = "1.0.0" id = "send2ue" name = "Send to Unreal" tagline = "Send assets directly to an open Unreal Editor on your machine" -version = "2.5.0" +version = "2.6.0" type = "add-on" tags = [ "Pipeline" ] blender_version_min = "4.2.0" diff --git a/src/addons/send2ue/core/export.py b/src/addons/send2ue/core/export.py index 499d8a1f..ae8f1b47 100644 --- a/src/addons/send2ue/core/export.py +++ b/src/addons/send2ue/core/export.py @@ -542,8 +542,8 @@ def send2ue(properties): utilities.escape_local_view() # clear the asset_data and current id - bpy.context.window_manager.send2ue.asset_id = '' - bpy.context.window_manager.send2ue.asset_data.clear() + bpy.context.window_manager.send2ue.asset_id = '' # type: ignore + bpy.context.window_manager.send2ue.asset_data.clear() # type: ignore # if there are no failed validations continue validation_manager = validations.ValidationManager(properties) @@ -551,3 +551,5 @@ def send2ue(properties): # create the asset data create_asset_data(properties) ingest.assets(properties) + + bpy.context.window_manager.send2ue.object_collection_override.clear() # type: ignore \ No newline at end of file diff --git a/src/addons/send2ue/core/utilities.py b/src/addons/send2ue/core/utilities.py index db7141d1..7db3c4d6 100644 --- a/src/addons/send2ue/core/utilities.py +++ b/src/addons/send2ue/core/utilities.py @@ -367,11 +367,17 @@ def get_from_collection(object_type): """ collection_objects = [] + # first check if the collection_objects is overridden + for collection_object in bpy.context.window_manager.send2ue.object_collection_override: # type: ignore + if collection_object.type == object_type: + collection_objects.append(collection_object) + # get the collection with the given name export_collection = bpy.data.collections.get(ToolInfo.EXPORT_COLLECTION.value) - if export_collection: + # if the collection exists and the collection_objects is not overridden + if export_collection and not collection_objects: # get all the objects in the collection - for collection_object in export_collection.all_objects: + for collection_object in export_collection.all_objects: # type: ignore # if the object is the correct type if collection_object.type == object_type: # if the object is visible @@ -1107,7 +1113,7 @@ def setup_project(*args): create_collections() # create the header menu - if importlib.util.find_spec('unpipe') is None: + if not os.environ.get('SEND2UE_HIDE_PIPELINE_MENU'): header_menu.add_pipeline_menu() diff --git a/src/addons/send2ue/properties.py b/src/addons/send2ue/properties.py index e747a26c..3ea0ac4a 100644 --- a/src/addons/send2ue/properties.py +++ b/src/addons/send2ue/properties.py @@ -68,6 +68,9 @@ class Send2UeWindowMangerProperties(bpy.types.PropertyGroup): """ This class holds the properties for a window. """ + # This can be set programmatically to override the default collection behavior. + # This is cleared back to an empty list after the send2ue operation has completed. + object_collection_override = [] # ------------- current asset info ------------------ asset_data = {} asset_id: bpy.props.StringProperty( diff --git a/src/addons/send2ue/release_notes.md b/src/addons/send2ue/release_notes.md index dfbf69fc..b121b422 100644 --- a/src/addons/send2ue/release_notes.md +++ b/src/addons/send2ue/release_notes.md @@ -1,10 +1,14 @@ -## Patch Changes -* Fixed Texture filepaths post operation - * [99](https://github.com/poly-hammer/BlenderTools/pull/99) +## Features +* Enhanced Python API by allowing other scripts to set `object_collection_override` to a list of objects to override collection behavior. Check out example in [docs](https://poly-hammer.github.io/BlenderTools/send2ue/customize/python-api/#examples) + * [101](https://github.com/poly-hammer/BlenderTools/issues/101) + * [104](https://github.com/poly-hammer/BlenderTools/issues/104) +* Made the extensions repo path a list view in addons preferences. + * [102](https://github.com/poly-hammer/BlenderTools/issues/102) + * [103](https://github.com/poly-hammer/BlenderTools/pull/103) ## Special Thanks - +@jack-yao91 ## Tests Passing On * Blender `3.6`, `4.2` (installed from blender.org)