5
5
import sgtk
6
6
import os
7
7
import unreal
8
+ import datetime
8
9
9
10
HookBaseClass = sgtk .get_hook_baseclass ()
10
11
@@ -116,15 +117,6 @@ def accept(self, settings, item):
116
117
117
118
accepted = True
118
119
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
128
120
129
121
# ensure the publish template is defined
130
122
publish_template_setting = settings .get ("Publish Template" )
@@ -139,7 +131,6 @@ def accept(self, settings, item):
139
131
# we've validated the work and publish templates. add them to the item properties
140
132
# for use in subsequent methods
141
133
item .properties ["publish_template" ] = publish_template
142
- item .properties ["work_template" ] = work_template
143
134
144
135
return {
145
136
"accepted" : accepted ,
@@ -186,36 +177,33 @@ def validate(self, settings, item):
186
177
self .logger .debug ("No publish template configured." )
187
178
return False
188
179
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 }
200
182
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
203
188
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
207
192
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
210
198
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
214
204
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"
219
207
220
208
# run the base class validation
221
209
# return super(UnrealAssetPublishPlugin, self).validate(settings, item)
@@ -238,6 +226,19 @@ def publish(self, settings, item):
238
226
239
227
# get the path in a normalized state. no trailing separator, separators
240
228
# 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 ))
241
242
242
243
# let the base class register the publish
243
244
# the publish_file will copy the file from the work path to the publish path
0 commit comments