Asset Pipeline v2 #145
@ -6,11 +6,9 @@ from .merge.publish import (
|
||||
get_next_published_file,
|
||||
)
|
||||
|
||||
from .merge.transfer_data.transfer_ui import draw_transfer_data
|
||||
from .images import save_images
|
||||
from . import constants
|
||||
from .sync import (
|
||||
sync_poll,
|
||||
sync_invoke,
|
||||
sync_draw,
|
||||
sync_execute_update_ownership,
|
||||
@ -29,6 +27,10 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
_dir = None
|
||||
_prefix = None
|
||||
|
||||
create_files: bpy.props.BoolProperty(
|
||||
name="Create Files for Unselected Task Layers", default=True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: bpy.types.Context) -> bool:
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
@ -38,35 +40,59 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
if os.path.exists(os.path.join(asset_pipe.dir, asset_pipe.name)):
|
||||
cls.poll_message_set("Asset Folder already exists")
|
||||
return False
|
||||
if bpy.data.filepath == "":
|
||||
cls.poll_message_set("Please Save File before creating asset")
|
||||
return False
|
||||
# TODO Add warning if file is unsaved like a general startup file
|
||||
return True
|
||||
|
||||
def invoke(self, context: bpy.types.Context, event):
|
||||
# Dynamically Create Task Layer Bools
|
||||
task_layer_settings = context.scene.asset_pipeline.task_layer_settings
|
||||
task_layer_settings.clear()
|
||||
for task_layer_key in constants.TASK_LAYER_TYPES.keys():
|
||||
if task_layer_key == "NONE":
|
||||
continue
|
||||
transfer_data_item = task_layer_settings.add()
|
||||
transfer_data_item.name = constants.TASK_LAYER_TYPES[task_layer_key]
|
||||
transfer_data_item.key = task_layer_key
|
||||
return context.window_manager.invoke_props_dialog(self, width=400)
|
||||
|
||||
def draw(self, context: bpy.types.Context):
|
||||
box = self.layout.box()
|
||||
task_layer_settings = context.scene.asset_pipeline.task_layer_settings
|
||||
|
||||
box.label(text="Choose Which Task Layers will be local the current file")
|
||||
for task_layer_bool in task_layer_settings:
|
||||
box.prop(task_layer_bool, "is_local", text=task_layer_bool.name)
|
||||
self.layout.prop(self, "create_files")
|
||||
|
||||
def execute(self, context: bpy.types.Context):
|
||||
# New File is Createed so Props need to be saved
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
self._name = asset_pipe.name
|
||||
self._dir = asset_pipe.dir
|
||||
self._dir = bpy.path.abspath(asset_pipe.dir)
|
||||
self._prefix = asset_pipe.prefix
|
||||
|
||||
task_layer_settings = context.scene.asset_pipeline.task_layer_settings
|
||||
local_tls = []
|
||||
for task_layer_bool in task_layer_settings:
|
||||
if task_layer_bool.is_local:
|
||||
local_tls.append(task_layer_bool.key)
|
||||
|
||||
if not any(task_layer_bool.is_local for task_layer_bool in task_layer_settings):
|
||||
self.report(
|
||||
{'ERROR'},
|
||||
"Please select at least one task layer to be local to the current file",
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Create Asset Folder at Directory
|
||||
asset_path = os.path.join(self._dir, self._name)
|
||||
os.mkdir(asset_path)
|
||||
|
||||
for publish_type in constants.PUBLISH_KEYS:
|
||||
os.mkdir(os.path.join(asset_path, publish_type))
|
||||
|
||||
# Prepare New File
|
||||
bpy.ops.wm.read_homefile(app_template="")
|
||||
|
||||
# Remove All Data
|
||||
for col in bpy.data.collections:
|
||||
bpy.data.collections.remove(col)
|
||||
for obj in bpy.data.objects:
|
||||
bpy.data.objects.remove(obj)
|
||||
|
||||
bpy.ops.outliner.orphans_purge(
|
||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||
)
|
||||
|
||||
# Setup New File
|
||||
asset_pipe = context.scene.asset_pipeline
|
||||
asset_pipe.is_asset_pipeline_file = True
|
||||
@ -77,28 +103,39 @@ class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
|
||||
asset_pipe.name = self._name
|
||||
asset_pipe.prefix = self._prefix
|
||||
|
||||
# Create the collections for each task layer.
|
||||
# for task_layer_key in constants.TASK_LAYER_TYPES.keys():
|
||||
# if task_layer_key == "NONE":
|
||||
# continue
|
||||
# col_name = get_task_layer_col_name(task_layer_key)
|
||||
# bpy.data.collections.new(col_name)
|
||||
# new_col = bpy.data.collections.get(col_name)
|
||||
# asset_col.children.link(new_col)
|
||||
# new_col.asset_id_owner = task_layer_key
|
||||
|
||||
starting_file = ""
|
||||
local_tls_string = ""
|
||||
for task_layer in local_tls:
|
||||
local_tls_string += task_layer + ","
|
||||
asset_pipe.local_task_layers = local_tls_string
|
||||
first_file = os.path.join(asset_path, Path(bpy.data.filepath).name)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=first_file, copy=True)
|
||||
starting_file = first_file
|
||||
|
||||
# TODO Support mulitple task layers in same file
|
||||
# Create the file for each task layer.
|
||||
for task_layer_key in constants.TASK_LAYER_TYPES.keys():
|
||||
if task_layer_key == "NONE":
|
||||
if task_layer_key == "NONE" or task_layer_key in local_tls:
|
||||
continue
|
||||
name = (
|
||||
self._name + "." + constants.TASK_LAYER_TYPES[task_layer_key] + ".blend"
|
||||
)
|
||||
|
||||
asset_pipe.local_task_layers = task_layer_key + ","
|
||||
|
||||
# Remove Data From Newly Created Files that aren't the user's main file
|
||||
for col in bpy.data.collections:
|
||||
if not col == asset_col:
|
||||
bpy.data.collections.remove(col)
|
||||
for obj in bpy.data.objects:
|
||||
bpy.data.objects.remove(obj)
|
||||
|
||||
bpy.ops.outliner.orphans_purge(
|
||||
do_local_ids=True, do_linked_ids=False, do_recursive=True
|
||||
)
|
||||
|
||||
task_layer_file = os.path.join(asset_path, name)
|
||||
asset_pipe.task_layer_name = task_layer_key
|
||||
if task_layer_key == constants.STARTING_FILE:
|
||||
starting_file = task_layer_file
|
||||
asset_pipe.local_task_layers = task_layer_key + ","
|
||||
bpy.ops.wm.save_as_mainfile(filepath=task_layer_file, copy=True)
|
||||
|
||||
# Create intial publish based on task layers.
|
||||
|
@ -34,6 +34,11 @@ class AssetTransferDataTemp(bpy.types.PropertyGroup):
|
||||
obj: bpy.props.PointerProperty(type=bpy.types.Object)
|
||||
|
||||
|
||||
class TaskLayerSettings(bpy.types.PropertyGroup):
|
||||
is_local: bpy.props.BoolProperty(name="Task Layer is Local", default=False)
|
||||
key: bpy.props.StringProperty(name="Key for Task Layer", default="")
|
||||
|
||||
|
||||
class AssetPipeline(bpy.types.PropertyGroup):
|
||||
"""Properties to manage the status of asset pipeline files"""
|
||||
|
||||
@ -74,10 +79,13 @@ class AssetPipeline(bpy.types.PropertyGroup):
|
||||
name="Prefix", description="Prefix for new Asset", default=""
|
||||
)
|
||||
|
||||
task_layer_settings: bpy.props.CollectionProperty(type=TaskLayerSettings)
|
||||
|
||||
|
||||
classes = (
|
||||
AssetTransferData,
|
||||
AssetTransferDataTemp,
|
||||
TaskLayerSettings,
|
||||
AssetPipeline,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user