Skip to content

Commit e589cdf

Browse files
committed
Revised Unreal FBX Publish
- Also set Published File Type on Unreal movie publish
1 parent 3d1b340 commit e589cdf

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

hooks/tk-multi-publish2/basic/publish_asset.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sgtk
66
import os
77
import unreal
8+
import datetime
89

910
HookBaseClass = sgtk.get_hook_baseclass()
1011

@@ -116,15 +117,6 @@ def accept(self, settings, item):
116117

117118
accepted = True
118119
publisher = self.parent
119-
120-
# ensure a work file template is available on the parent item
121-
work_template = item.parent.properties.get("work_template")
122-
if not work_template:
123-
self.logger.debug(
124-
"A work template is required for the asset item in order to "
125-
"publish it. Not accepting the item."
126-
)
127-
accepted = False
128120

129121
# ensure the publish template is defined
130122
publish_template_setting = settings.get("Publish Template")
@@ -139,7 +131,6 @@ def accept(self, settings, item):
139131
# we've validated the work and publish templates. add them to the item properties
140132
# for use in subsequent methods
141133
item.properties["publish_template"] = publish_template
142-
item.properties["work_template"] = work_template
143134

144135
return {
145136
"accepted": accepted,
@@ -186,36 +177,33 @@ def validate(self, settings, item):
186177
self.logger.debug("No publish template configured.")
187178
return False
188179

189-
# Get the work template which should have been retrieve by the collector and set on the item
190-
work_template = item.properties.get("work_template")
191-
if not work_template:
192-
self.logger.debug("No work template configured.")
193-
return False
194-
195-
# Get destination path for exported FBX from work template
196-
# which should be project root + work template
197-
work_path_fields = {"name" : asset_name}
198-
work_path = work_template.apply_fields(work_path_fields)
199-
work_path = os.path.normpath(work_path)
180+
# Add the Unreal asset name to the fields
181+
fields = {"name" : asset_name}
200182

201-
# Remove the filename from the work path
202-
destination_path = os.path.split(work_path)[0]
183+
# Add today's date to the fields
184+
date = datetime.date.today()
185+
fields["YYYY"] = date.year
186+
fields["MM"] = date.month
187+
fields["DD"] = date.day
203188

204-
# Ensure that the destination path exists before exporting since the FBX exporter doesn't check that
205-
publisher = self.parent
206-
publisher.ensure_folder_exists(destination_path)
189+
# Stash the Unrea asset path and name in properties
190+
item.properties["asset_path"] = asset_path
191+
item.properties["asset_name"] = asset_name
207192

208-
# Export the asset from Unreal
209-
result, item_path = _unreal_export_asset_to_fbx(destination_path, asset_path, asset_name)
193+
# Get destination path for exported FBX from publish template
194+
# which should be project root + publish template
195+
publish_path = publish_template.apply_fields(fields)
196+
publish_path = os.path.normpath(publish_path)
197+
item.properties["path"] = publish_path
210198

211-
if not result:
212-
self.logger.debug("Asset %s cannot be exported to FBX." % (asset_path))
213-
return False
199+
# Remove the filename from the work path
200+
destination_path = os.path.split(publish_path)[0]
201+
202+
# Stash the destination path in properties
203+
item.properties["destination_path"] = destination_path
214204

215-
# Set the path of the item
216-
# Path must match the pattern of the work template for the publish_file plugin to work
217-
item_path = item_path.replace("/", "\\")
218-
item.properties["path"] = item_path
205+
# Set the Published File Type
206+
item.properties["publish_type"] = "Unreal FBX"
219207

220208
# run the base class validation
221209
# return super(UnrealAssetPublishPlugin, self).validate(settings, item)
@@ -238,6 +226,19 @@ def publish(self, settings, item):
238226

239227
# get the path in a normalized state. no trailing separator, separators
240228
# are appropriate for current os, no double separators, etc.
229+
230+
# Ensure that the destination path exists before exporting since the
231+
# Unreal FBX exporter doesn't check that
232+
destination_path = item.properties["destination_path"]
233+
self.parent.ensure_folder_exists(destination_path)
234+
235+
# Export the asset from Unreal
236+
asset_path = item.properties["asset_path"]
237+
asset_name = item.properties["asset_name"]
238+
try:
239+
_unreal_export_asset_to_fbx(destination_path, asset_path, asset_name)
240+
except Exception:
241+
self.logger.debug("Asset %s cannot be exported to FBX." % (asset_path))
241242

242243
# let the base class register the publish
243244
# the publish_file will copy the file from the work path to the publish path

hooks/tk-multi-publish2/basic/publish_movie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def validate(self, settings, item):
237237

238238
item.properties["path"] = publish_template.apply_fields(fields)
239239
item.properties["publish_path"] = item.properties["path"]
240-
# item.properties["publish_name"] = movie_name
240+
item.properties["publish_type"] = "Unreal Render"
241241
item.properties["version_number"] = version_number
242242

243243
return True

0 commit comments

Comments
 (0)