diff --git a/Release log.txt b/Release log.txt index d79b5999..835fa753 100644 --- a/Release log.txt +++ b/Release log.txt @@ -356,7 +356,7 @@ It is now possible to force the duration of an animation according to the scene == Rev 0.2.9 == - +- New: you can now choose a specific Vertex Paint to use when you Export. - Change: The skeletal mesh are exported with scale at 1.0. - Change: You can use "Show Asset(s)" and "Show Action(s)" buttons for force to update the action cache. - Fixed: Do a new preset do a script error. @@ -365,4 +365,7 @@ It is now possible to force the duration of an animation according to the scene - Fixed: In camera sequencer with some frame rates the frame keys can be shifted. - Fixed: Export SkeletalMesh without animation_data make script fail. - Fixed: Button "Show Asset(s)" make script fail when the selected actor is not a SkeletalMesh. -- Fixed: Animation file with space can do error durring import \ No newline at end of file +- Fixed: Animation file with space can do error durring import +- Fixed: Vertex color updated only in import option when reimport. +- Fixed: With Unit Scale not at 0.01 SkeletalMesh have a wrong scale. +- Fixed: Import NLA animation with script don't work \ No newline at end of file diff --git a/blender-for-unrealengine/bfu_export_get_info.py b/blender-for-unrealengine/bfu_export_get_info.py new file mode 100644 index 00000000..124a2827 --- /dev/null +++ b/blender-for-unrealengine/bfu_export_get_info.py @@ -0,0 +1,118 @@ +# ====================== BEGIN GPL LICENSE BLOCK ============================ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# All rights reserved. +# +# ======================= END GPL LICENSE BLOCK ============================= + + +import bpy +import time +import math + +if "bpy" in locals(): + import importlib + if "bfu_write_text" in locals(): + importlib.reload(bfu_write_text) + if "bfu_basics" in locals(): + importlib.reload(bfu_basics) + if "bfu_utils" in locals(): + importlib.reload(bfu_utils) + +from . import bfu_write_text +from . import bfu_basics +from .bfu_basics import * +from . import bfu_utils +from .bfu_utils import * +from enum import Enum + +class VertexColorExportData: + def __init__(self, obj, parent = None): + self.obj = obj + self.parent = parent + self.export_type = "IGNORE" + self.name = "" + self.color = (1.0, 1.0, 1.0) + self.index = -1 + + + if self.GetPropertyOwner(): + if self.GetPropertyOwner().VertexColorImportOption == "IGNORE": + self.export_type = "IGNORE" + + elif self.GetPropertyOwner().VertexColorImportOption == "OVERRIDE": + self.color = self.GetPropertyOwner().VertexOverrideColor + self.export_type = "OVERRIDE" + + elif self.GetPropertyOwner().VertexColorImportOption == "REPLACE": + index = self.GetChosenVertexIndex() + if index != -1: + self.index = index + self.name = self.GetChosenVertexName() + self.export_type = "REPLACE" + + def GetPropertyOwner(self): + #Return the object to use for the property or return self if none + if self.parent: + return self.parent + return self.obj + + + def GetChosenVertexIndex(self): + obj = self.obj + if obj.type != "MESH": + return -1 + + VertexColorToUse = self.GetPropertyOwner().VertexColorToUse + VertexColorIndexToUse = self.GetPropertyOwner().VertexColorIndexToUse + + if obj: + if obj.data: + if len(obj.data.vertex_colors) > 0: + + if VertexColorToUse == "FirstIndex": + return 0 + + if VertexColorToUse == "LastIndex": + return len(obj.data.vertex_colors)-1 + + if VertexColorToUse == "ActiveIndex": + for index, vertex_color in enumerate(obj.data.vertex_colors): + if vertex_color.active_render == True: + return index + + if VertexColorToUse == "CustomIndex": + if VertexColorIndexToUse < len(obj.data.vertex_colors): + return VertexColorIndexToUse + return -1 + + def GetChosenVertexName(self): + + index = self.GetChosenVertexIndex() + if index == -1: + return "None" + + + obj = self.obj + if obj: + if obj.type == "MESH": + if obj.data: + if obj.VertexColorIndexToUse < len(obj.data.vertex_colors): + return obj.data.vertex_colors[index].name + + return "None" + + def GetVertexByIndex(self, index): + self.obj + diff --git a/blender-for-unrealengine/bfu_export_single_fbx_action.py b/blender-for-unrealengine/bfu_export_single_fbx_action.py index 353b5149..a5bd68c4 100644 --- a/blender-for-unrealengine/bfu_export_single_fbx_action.py +++ b/blender-for-unrealengine/bfu_export_single_fbx_action.py @@ -129,7 +129,7 @@ def ExportSingleFbxAction( ResetArmaturePose(active) RescaleRigConsraints(active, rrf) - ApplyExportTransform(active) + ApplyExportTransform(active) # Apply export transform after rescale # animation_data.action is ReadOnly with tweakmode in 2.8 if (scene.is_nla_tweakmode): @@ -171,12 +171,13 @@ def ExportSingleFbxAction( bake_space_transform=False ) - # Rename Action name for export - TempName = "ActionAutoRigProTempExportNameForUnreal" - OriginalActionName = active.animation_data.action.name - active.animation_data.action.name = TempName + elif (export_procedure == "auto-rig-pro"): + + # Rename Action name for export + TempName = "ActionAutoRigProTempExportNameForUnreal" + OriginalActionName = active.animation_data.action.name + active.animation_data.action.name = TempName - if (export_procedure == "auto-rig-pro"): ExportAutoProRig( filepath=fullpath, # export_rig_name=GetDesiredExportArmatureName(), @@ -186,8 +187,8 @@ def ExportSingleFbxAction( arp_simplify_fac=active.SimplifyAnimForExport ) - # Reset Action name - active.animation_data.action.name = OriginalActionName + # Reset Action name + active.animation_data.action.name = OriginalActionName asset_name.ResetNames() diff --git a/blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py b/blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py index 55f4bc9b..eebe4f0d 100644 --- a/blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py +++ b/blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py @@ -54,6 +54,7 @@ def ProcessNLAAnimExport(obj): MyAsset = scene.UnrealExportedAssetsList.add() MyAsset.StartAssetExport(obj) MyAsset.asset_type = "NlAnim" + MyAsset.asset_name = GetNLAExportFileName(obj) ExportSingleFbxNLAAnim(dirpath, GetNLAExportFileName(obj), obj) file = MyAsset.files.add() @@ -95,7 +96,7 @@ def ExportSingleFbxNLAAnim( animation_data = AnimationManagment() animation_data.SaveAnimationData(obj) - animation_data.SetAnimationData(active) + animation_data.SetAnimationData(active, True) if active.ExportAsProxy: ApplyProxyData(active) @@ -111,7 +112,8 @@ def ExportSingleFbxNLAAnim( savedUnitLength = bpy.context.scene.unit_settings.scale_length bpy.context.scene.unit_settings.scale_length *= 1/rrf oldScale = active.scale.z - ApplySkeletalExportScale(active, rrf) + + ApplySkeletalExportScale(active, rrf, animation_data) RescaleAllActionCurve(rrf*oldScale) for selected in bpy.context.selected_objects: if selected.type == "MESH": @@ -120,7 +122,7 @@ def ExportSingleFbxNLAAnim( ResetArmaturePose(active) RescaleRigConsraints(active, rrf) - ApplyExportTransform(active) + ApplyExportTransform(active) # Apply export transform after rescale # scene.frame_start += active.StartFramesOffset # scene.frame_end += active.EndFramesOffset diff --git a/blender-for-unrealengine/bfu_export_single_skeletal_mesh.py b/blender-for-unrealengine/bfu_export_single_skeletal_mesh.py index 9e9a8649..58a695bf 100644 --- a/blender-for-unrealengine/bfu_export_single_skeletal_mesh.py +++ b/blender-for-unrealengine/bfu_export_single_skeletal_mesh.py @@ -106,8 +106,6 @@ def ExportSingleSkeletalMesh( if active.ExportAsProxy: ApplyProxyData(active) - ApplyExportTransform(active) - # This will rescale the rig and unit scale to get a root bone egal to 1 ShouldRescaleRig = GetShouldRescaleRig(active) if ShouldRescaleRig: @@ -117,6 +115,8 @@ def ExportSingleSkeletalMesh( bpy.context.scene.unit_settings.scale_length *= 1/rrf ApplySkeletalExportScale(active, rrf) + ApplyExportTransform(active) # Apply export transform after rescale + absdirpath = bpy.path.abspath(dirpath) VerifiDirs(absdirpath) fullpath = os.path.join(absdirpath, filename) @@ -136,6 +136,8 @@ def ExportSingleSkeletalMesh( RemoveAllConsraints(active) bpy.context.object.data.pose_position = 'REST' + SetVertexColorForUnrealExport(active) + if (export_procedure == "normal"): pass bpy.ops.export_scene.fbx( diff --git a/blender-for-unrealengine/bfu_export_single_static_mesh.py b/blender-for-unrealengine/bfu_export_single_static_mesh.py index a154b77b..5e7ec8fd 100644 --- a/blender-for-unrealengine/bfu_export_single_static_mesh.py +++ b/blender-for-unrealengine/bfu_export_single_static_mesh.py @@ -118,6 +118,8 @@ def ExportSingleStaticMesh( GetAllCollisionAndSocketsObj(bpy.context.selected_objects) ) + SetVertexColorForUnrealExport(active) + bpy.ops.export_scene.fbx( filepath=fullpath, check_existing=False, diff --git a/blender-for-unrealengine/bfu_export_utils.py b/blender-for-unrealengine/bfu_export_utils.py index 70b1457a..39612436 100644 --- a/blender-for-unrealengine/bfu_export_utils.py +++ b/blender-for-unrealengine/bfu_export_utils.py @@ -29,12 +29,16 @@ importlib.reload(bfu_basics) if "bfu_utils" in locals(): importlib.reload(bfu_utils) + if "bfu_export_get_info" in locals(): + importlib.reload(bfu_export_get_info) from . import bfu_write_text from . import bfu_basics from .bfu_basics import * from . import bfu_utils from .bfu_utils import * +from . import bfu_export_get_info +from .bfu_export_get_info import * def ApplyProxyData(obj): @@ -311,6 +315,28 @@ def CorrectExtremUVAtExport(): return True return False +# Vertex Color + + +def SetVertexColorForUnrealExport(parent): + + + objs = GetExportDesiredChilds(parent) + objs.append(parent) + + for obj in objs: + if obj.type == "MESH": + vced = VertexColorExportData(obj, parent) + if vced.export_type == "REPLACE": + + obj.data.vertex_colors.active_index = vced.index + new_vertex_color = obj.data.vertex_colors.new() + new_vertex_color.name = "BFU_VertexColorExportName" + + number = len(obj.data.vertex_colors) -1 + for i in range(number): + obj.data.vertex_colors.remove(obj.data.vertex_colors[0]) + def GetShouldRescaleRig(obj): # This will return if the rig should be rescale. diff --git a/blender-for-unrealengine/bfu_ui.py b/blender-for-unrealengine/bfu_ui.py index 99c1aac0..df49ca2a 100644 --- a/blender-for-unrealengine/bfu_ui.py +++ b/blender-for-unrealengine/bfu_ui.py @@ -26,8 +26,10 @@ from . import bfu_basics from .bfu_basics import * from . import bfu_utils -from . import bfu_check_potential_error from .bfu_utils import * +from . import bfu_export_get_info +from .bfu_export_get_info import * +from . import bfu_check_potential_error from . import bfu_ui_utils from . import languages from .languages import * @@ -43,6 +45,8 @@ importlib.reload(bfu_basics) if "bfu_utils" in locals(): importlib.reload(bfu_utils) + if "bfu_export_get_info" in locals(): + importlib.reload(bfu_export_get_info) if "bfu_check_potential_error" in locals(): importlib.reload(bfu_check_potential_error) if "bfu_ui_utils" in locals(): @@ -509,6 +513,28 @@ class BFU_PT_BlenderForUnrealObject(bpy.types.Panel): # https://docs.unrealengine.com/en-US/PythonAPI/class/FbxSkeletalMeshImportData.html ) + bpy.types.Object.VertexColorToUse = EnumProperty( + name="Vertex Color to use", + description="Specify which vertex colors should be imported", + items=[ + ("FirstIndex", "First Index", + "Use the the first index in Object Data -> Vertex Color.", 0), + ("LastIndex", "Last Index", + "Use the the last index in Object Data -> Vertex Color.", 1), + ("ActiveIndex", "Active Render", + "Use the the active index in Object Data -> Vertex Color.", 2), + ("CustomIndex", "CustomIndex", + "Use a specific Vertex Color in Object Data -> Vertex Color.", 3) + ], + default="ActiveIndex" + ) + + bpy.types.Object.VertexColorIndexToUse = IntProperty( + name="Vertex color index", + description="Vertex Color index to use.", + default=0 + ) + bpy.types.Object.exportActionEnum = EnumProperty( name="Action to export", description="Export procedure for actions (Animations and poses)", @@ -1001,7 +1027,9 @@ class BFU_OT_AddObjectGlobalPropertiesPreset(AddPresetBase, Operator): 'obj.MaterialSearchLocation', 'obj.CollisionTraceFlag', 'obj.VertexColorImportOption', - 'obj.VertexOverrideColor ', + 'obj.VertexOverrideColor', + 'obj.VertexColorToUse', + 'obj.VertexColorIndexToUse', 'obj.exportActionEnum', 'obj.PrefixNameToExport', 'obj.AnimStartEndTimeEnum', @@ -1301,12 +1329,29 @@ def draw(self, contex): # Vertex color StaticMeshVertexColorImportOption = layout.column() StaticMeshVertexColorImportOption.prop(obj, 'VertexColorImportOption') - StaticMeshVertexColorImportOptionColor = StaticMeshVertexColorImportOption.row() - StaticMeshVertexColorImportOptionColor.prop(obj, 'VertexOverrideColor') if obj.VertexColorImportOption == "OVERRIDE": - StaticMeshVertexColorImportOptionColor.enabled = True - else: - StaticMeshVertexColorImportOptionColor.enabled = False + StaticMeshVertexColorImportOptionColor = StaticMeshVertexColorImportOption.row() + StaticMeshVertexColorImportOptionColor.prop(obj, 'VertexOverrideColor') + if obj.VertexColorImportOption == "REPLACE": + StaticMeshVertexColorImportOptionIndex = StaticMeshVertexColorImportOption.row() + StaticMeshVertexColorImportOptionIndex.prop(obj, 'VertexColorToUse') + if obj.VertexColorToUse == "CustomIndex": + StaticMeshVertexColorImportOptionIndexCustom = StaticMeshVertexColorImportOption.row() + StaticMeshVertexColorImportOptionIndexCustom.prop(obj, 'VertexColorIndexToUse') + + StaticMeshVertexColorFeedback = StaticMeshVertexColorImportOption.row() + if obj.type == "MESH": + vced = VertexColorExportData(obj) + if vced.export_type == "REPLACE": + StaticMeshVertexColorFeedback.label(text='Vertex color nammed "' + vced.name + '" will be used.', icon='INFO') + else: + StaticMeshVertexColorFeedback.label(text='No vertex color found at this index.', icon='ERROR') + else: + StaticMeshVertexColorFeedback.label(text='Vertex color property will be apply on the childrens.', icon='INFO') + + + + bfu_ui_utils.LayoutSection(layout, "bfu_object_light_map_properties_expanded", "Light map") if scene.bfu_object_light_map_properties_expanded: @@ -1823,14 +1868,16 @@ def SetObjData(self, obj): def StartAssetExport(self, obj=None, action=None, collection=None): if obj: self.SetObjData(obj) - - if obj: self.asset_type = GetAssetType(obj) + if obj.type == "ARMATURE": + self.skeleton_name = obj.name + if action: self.asset_type = GetActionType(action) # Override + if obj and action: self.asset_name = GetActionExportFileName(obj, action, "") - self.skeleton_name = obj.name + if collection: self.asset_type = GetCollectionType(collection) # Override diff --git a/blender-for-unrealengine/bfu_utils.py b/blender-for-unrealengine/bfu_utils.py index 0000e840..2b863d21 100644 --- a/blender-for-unrealengine/bfu_utils.py +++ b/blender-for-unrealengine/bfu_utils.py @@ -239,11 +239,16 @@ def SaveAnimationData(self, obj): self.action_extrapolation = obj.animation_data.action_extrapolation self.action_blend_type = obj.animation_data.action_blend_type self.action_influence = obj.animation_data.action_influence + self.nla_tracks_ref = obj.animation_data.nla_tracks + self.use_animation_data = True + else: + self.use_animation_data = False def ClearAnimationData(self, obj): obj.animation_data_clear() - def SetAnimationData(self, obj): + def SetAnimationData(self, obj, copy_nla=False): + print(obj.name) if self.use_animation_data: obj.animation_data_create() @@ -253,6 +258,44 @@ def SetAnimationData(self, obj): obj.animation_data.action_blend_type = self.action_blend_type obj.animation_data.action_influence = self.action_influence + if copy_nla: + #Clear nla_tracks + nla_tracks_len = len(obj.animation_data.nla_tracks) + for x in range(nla_tracks_len): + obj.animation_data.nla_tracks.remove(obj.animation_data.nla_tracks[0]) + + #Add Current nla_tracks + for nla_track in self.nla_tracks_ref: + new_nla_track = obj.animation_data.nla_tracks.new() + #new_nla_track.active = nla_track.active + new_nla_track.is_solo = nla_track.is_solo + new_nla_track.lock = nla_track.lock + new_nla_track.mute = nla_track.mute + new_nla_track.name = nla_track.name + new_nla_track.select = nla_track.select + for strip in nla_track.strips: + new_strip = new_nla_track.strips.new(strip.name, strip.frame_start, strip.action) + #new_strip.action = strip.action + new_strip.action_frame_end = strip.action_frame_end + new_strip.action_frame_start = strip.action_frame_start + #new_strip.active = strip.active + new_strip.blend_in = strip.blend_in + new_strip.blend_out = strip.blend_out + new_strip.blend_type = strip.blend_type + new_strip.extrapolation = strip.extrapolation + #new_strip.fcurves = strip.fcurves #TO DO + new_strip.frame_end = strip.frame_end + #new_strip.frame_start = strip.frame_start + new_strip.influence = strip.influence + #new_strip.modifiers = strip.modifiers #TO DO + new_strip.mute = strip.mute + #new_strip.name = strip.name + new_strip.repeat = strip.repeat + new_strip.scale = strip.scale + new_strip.select = strip.select + new_strip.strip_time = strip.strip_time + #new_strip.strips = strip.strips #TO DO + def SafeModeSet(target_mode='OBJECT', obj=None): if bpy.ops.object.mode_set.poll(): @@ -940,14 +983,19 @@ def ApplyExportTransform(obj): obj.scale = saveScale -def ApplySkeletalExportScale(armature, rescale): +def ApplySkeletalExportScale(armature, rescale, target_animation_data = None): + # This function will rescale the armature and applys the new scale - animation_data = AnimationManagment() - animation_data.SaveAnimationData(armature) - animation_data.ClearAnimationData(armature) - + if target_animation_data is None: + animation_data = AnimationManagment() + animation_data.SaveAnimationData(armature) + animation_data.ClearAnimationData(armature) + else: + animation_data = target_animation_data + armature.scale = armature.scale*rescale + bpy.ops.object.transform_apply( location=True, scale=True, diff --git a/blender-for-unrealengine/bfu_write_import_asset_script.py b/blender-for-unrealengine/bfu_write_import_asset_script.py index 0f3a45ed..1cf7d694 100644 --- a/blender-for-unrealengine/bfu_write_import_asset_script.py +++ b/blender-for-unrealengine/bfu_write_import_asset_script.py @@ -34,6 +34,8 @@ importlib.reload(bfu_write_utils) if "languages" in locals(): importlib.reload(languages) + if "bfu_export_get_info" in locals(): + importlib.reload(bfu_export_get_info) from . import bfu_basics from .bfu_basics import * @@ -41,6 +43,8 @@ from .bfu_utils import * from . import bfu_write_utils from .bfu_write_utils import * +from . import bfu_export_get_info +from .bfu_export_get_info import * def WriteImportAssetScript(): @@ -132,13 +136,7 @@ def WriteImportAssetScript(): asset_data["custom_light_map_resolution"] = ExportCompuntedLightMapValue(asset.object) asset_data["light_map_resolution"] = GetCompuntedLightMap(asset.object) asset_data["collision_trace_flag"] = asset.object.CollisionTraceFlag - asset_data["vertex_color_import_option"] = asset.object.VertexColorImportOption - vertex_override_color = ( - asset.object.VertexOverrideColor[0], # R - asset.object.VertexOverrideColor[1], # G - asset.object.VertexOverrideColor[2] # B - ) # Color to Json - asset_data["vertex_override_color"] = vertex_override_color + data['assets'].append(asset_data) return data diff --git a/blender-for-unrealengine/bfu_write_text.py b/blender-for-unrealengine/bfu_write_text.py index d70d9632..5d580088 100644 --- a/blender-for-unrealengine/bfu_write_text.py +++ b/blender-for-unrealengine/bfu_write_text.py @@ -40,6 +40,8 @@ importlib.reload(bfu_write_import_sequencer_script) if "languages" in locals(): importlib.reload(languages) + if "bfu_export_get_info" in locals(): + importlib.reload(bfu_export_get_info) from . import bfu_basics from .bfu_basics import * @@ -47,6 +49,8 @@ from .bfu_utils import * from . import bfu_write_import_asset_script from . import bfu_write_import_sequencer_script +from . import bfu_export_get_info +from .bfu_export_get_info import * def ExportSingleText(text, dirpath, filename): @@ -426,6 +430,7 @@ def WriteSingleMeshAdditionalParameter(obj): # Defaultsettings data['DefaultSettings'] = {} # config.set('Defaultsettings', 'SocketNumber', str(len(sockets))) + # Level of detail data['LevelOfDetail'] = {} @@ -480,6 +485,24 @@ def WriteSingleMeshAdditionalParameter(obj): MySocket = [SocketName, b.name.replace('.', '_'), array_location, array_rotation, array_scale] data['Sockets']['socket_'+str(i)] = MySocket + # Vertex Color + if GetAssetType(obj) == "SkeletalMesh" or GetAssetType(obj) == "StaticMesh": + vced = VertexColorExportData(obj) + data["vertex_color_import_option"] = vced.export_type + vertex_override_color = ( + vced.color[0], # R + vced.color[1], # G + vced.color[2] # B + ) # Color to Json + data["vertex_override_color"] = vertex_override_color + + # preview_import_path + #SkeletonName = customName+"."+customName + #SkeletonLoc = os.path.join(asset.folder_name, SkeletonName) + #asset_data["animation_skeleton_path"] = os.path.join("/Game/", scene.unreal_import_location, SkeletonLoc).replace('\\', '/') + + data["preview_import_path"] = GetObjExportFileName(obj, "") + return data diff --git a/blender-for-unrealengine/import/asset_import_script.py b/blender-for-unrealengine/import/asset_import_script.py index 1dfe21ab..c86091e7 100644 --- a/blender-for-unrealengine/import/asset_import_script.py +++ b/blender-for-unrealengine/import/asset_import_script.py @@ -78,6 +78,7 @@ def GetAssetByType(type): return target_assets def ImportAsset(asset_data): + counter = str(len(ImportedList)+1) + "/" + str(len(import_assets_data["assets"])) print("Import asset " + counter + ": ", asset_data["name"]) @@ -95,9 +96,20 @@ def ImportAsset(asset_data): asset_data["fbx_path"] # fbx_file_path asset_data["additional_tracks_path"] # additional_track_file_path + def GetAdditionalData(): + if "additional_tracks_path" in asset_data: + if asset_data["additional_tracks_path"] is not None: + with open(asset_data["additional_tracks_path"], "r") as json_file: + additional_data = json.load(json_file) + return additional_data + return None + + additional_data = GetAdditionalData() + def ImportTask(): # New import task # Property + if asset_data["type"] == "Animation": find_asset = unreal.find_asset(asset_data["animation_skeleton_path"]) if isinstance(find_asset, unreal.Skeleton): @@ -109,6 +121,25 @@ def ImportTask(): task = unreal.AssetImportTask() + + def GetStaticMeshImportData(): + if asset_data["type"] == "StaticMesh": + return task.get_editor_property('options').static_mesh_import_data + return None + + def GetSkeletalMeshImportData(): + if asset_data["type"] == "SkeletalMesh": + return task.get_editor_property('options').skeletal_mesh_import_data + return None + + def GetMeshImportData(): + if asset_data["type"] == "StaticMesh": + return GetStaticMeshImportData() + if asset_data["type"] == "SkeletalMesh": + return GetSkeletalMeshImportData() + + return None + if asset_data["type"] == "Alembic": task.filename = asset_data["abc_path"] else: @@ -123,10 +154,39 @@ def ImportTask(): else: task.set_editor_property('options', unreal.FbxImportUI()) + # Vertex color + vertex_override_color = None + vertex_color_import_option = None + if additional_data: + + if "vertex_color_import_option" in additional_data: + if additional_data["vertex_color_import_option"] == "IGNORE": + vertex_color_import_option = unreal.VertexColorImportOption.IGNORE + elif additional_data["vertex_color_import_option"] == "OVERRIDE": + vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE + elif additional_data["vertex_color_import_option"] == "REPLACE": + vertex_color_import_option = unreal.VertexColorImportOption.REPLACE + + vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default + if "vertex_override_color" in additional_data: + vertex_override_color = unreal.LinearColor( + additional_data["vertex_override_color"][0], + additional_data["vertex_override_color"][1], + additional_data["vertex_override_color"][2] + ) + # #################################[Change] # unreal.FbxImportUI # https://docs.unrealengine.com/en-US/PythonAPI/class/FbxImportUI.html?highlight=fbximportui#unreal.FbxImportUI + + # Vertex color + if vertex_color_import_option and GetMeshImportData(): + GetMeshImportData().set_editor_property('vertex_color_import_option', vertex_color_import_option) + + if vertex_override_color and GetMeshImportData(): + GetMeshImportData().set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) + if asset_data["type"] == "Alembic": task.get_editor_property('options').set_editor_property('import_type', unreal.AlembicImportType.SKELETAL) @@ -188,44 +248,32 @@ def ImportTask(): if "generate_lightmap_u_vs" in asset_data: task.get_editor_property('options').static_mesh_import_data.set_editor_property('generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) - if asset_data["type"] == "StaticMesh" or asset_data["type"] == "SkeletalMesh": - - vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default - if "vertex_override_color" in asset_data: - vertex_override_color = unreal.LinearColor( - asset_data["vertex_override_color"][0], - asset_data["vertex_override_color"][1], - asset_data["vertex_override_color"][2] - ) - - if "vertex_color_import_option" in asset_data: - if asset_data["vertex_color_import_option"] == "IGNORE": - vertex_color_import_option = unreal.VertexColorImportOption.IGNORE - elif asset_data["vertex_color_import_option"] == "OVERRIDE": - vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE - elif asset_data["vertex_color_import_option"] == "REPLACE": - vertex_color_import_option = unreal.VertexColorImportOption.REPLACE - - if asset_data["type"] == "StaticMesh": - # unreal.FbxSkeletalMeshImportData - if "vertex_color_import_option" in asset_data: - task.get_editor_property('options').static_mesh_import_data.set_editor_property('vertex_color_import_option', vertex_color_import_option) - if "vertex_override_color" in asset_data: - task.get_editor_property('options').static_mesh_import_data.set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) - - if asset_data["type"] == "SkeletalMesh": - # unreal.FbxSkeletalMeshImportData - if "vertex_color_import_option" in asset_data: - task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('vertex_color_import_option', vertex_color_import_option) - if "vertex_override_color" in asset_data: - task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) - if asset_data["type"] == "SkeletalMesh" or asset_data["type"] == "Animation": # unreal.FbxSkeletalMeshImportData task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('import_morph_targets', True) task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('convert_scene', True) task.get_editor_property('options').skeletal_mesh_import_data.set_editor_property('normal_import_method', unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS) + + # ###############[ pre import ]################ + + # Check is the file alredy exit + if additional_data: + if "preview_import_path" in additional_data: + task_asset_full_path = task.destination_path+"/"+additional_data["preview_import_path"]+"."+additional_data["preview_import_path"] + find_asset = unreal.find_asset(task_asset_full_path) + if find_asset: + + # Vertex color + + asset_import_data = find_asset.get_editor_property('asset_import_data') + if vertex_color_import_option: + asset_import_data.set_editor_property('vertex_color_import_option', vertex_color_import_option) + + if vertex_override_color: + asset_import_data.set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) + + # ###############[ import asset ]################ print("Import task") @@ -271,6 +319,7 @@ def ImportTask(): # ###############[ Post treatment ]################ + asset_import_data = asset.get_editor_property('asset_import_data') if asset_data["type"] == "StaticMesh": if "static_mesh_lod_group" in asset_data: if asset_data["static_mesh_lod_group"]: @@ -288,34 +337,13 @@ def ImportTask(): elif asset_data["collision_trace_flag"] == "CTF_UseComplexAsSimple": asset.get_editor_property('body_setup').set_editor_property('collision_trace_flag', unreal.CollisionTraceFlag.CTF_USE_COMPLEX_AS_SIMPLE) - if asset_data["type"] == "StaticMesh" or asset_data["type"] == "SkeletalMesh": - vertex_color_import_option = unreal.VertexColorImportOption.REPLACE # Default - if "vertex_override_color" in asset_data: - vertex_override_color = unreal.LinearColor( - asset_data["vertex_override_color"][0], - asset_data["vertex_override_color"][1], - asset_data["vertex_override_color"][2] - ) - - if "vertex_color_import_option" in asset_data: - if asset_data["vertex_color_import_option"] == "IGNORE": - vertex_color_import_option = unreal.VertexColorImportOption.IGNORE - elif asset_data["vertex_color_import_option"] == "OVERRIDE": - vertex_color_import_option = unreal.VertexColorImportOption.OVERRIDE - elif asset_data["vertex_color_import_option"] == "REPLACE": - vertex_color_import_option = unreal.VertexColorImportOption.REPLACE - - if "vertex_color_import_option" in asset_data: - asset.get_editor_property('asset_import_data').set_editor_property('vertex_color_import_option', vertex_color_import_option) - if "vertex_override_color" in asset_data: - asset.get_editor_property('asset_import_data').set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) if asset_data["type"] == "StaticMesh": if "generate_lightmap_u_vs" in asset_data: - asset.get_editor_property('asset_import_data').set_editor_property('generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) # Import data + asset_import_data.set_editor_property('generate_lightmap_u_vs', asset_data["generate_lightmap_u_vs"]) # Import data unreal.EditorStaticMeshLibrary.set_generate_lightmap_uv(asset, asset_data["generate_lightmap_u_vs"]) # Build settings at lod if asset_data["type"] == "SkeletalMesh": - asset.get_editor_property('asset_import_data').set_editor_property('normal_import_method', unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS) + asset_import_data.set_editor_property('normal_import_method', unreal.FBXNormalImportMethod.FBXNIM_IMPORT_NORMALS_AND_TANGENTS) # with open(asset_data["additional_tracks_path"], "r") as json_file: # asset_tracks = json.load(json_file) @@ -353,6 +381,15 @@ def ImportTask(): elif asset_data["type"] == "SkeletalMesh": pass unreal.FbxMeshUtils.ImportSkeletalMeshLOD(asset, lod, x+1) # Vania unreal python dont have unreal.FbxMeshUtils. + + + # Vertex color + if vertex_override_color: + asset_import_data.set_editor_property('vertex_override_color', vertex_override_color.to_rgbe()) + + if vertex_color_import_option: + asset_import_data.set_editor_property('vertex_color_import_option', vertex_color_import_option) + # #################################[EndChange] if asset_data["type"] == "StaticMesh" or asset_data["type"] == "SkeletalMesh": diff --git a/docs/Examples/AssetsExample_VertexColor.blend b/docs/Examples/AssetsExample_VertexColor.blend index 8372e449..30103b0c 100644 Binary files a/docs/Examples/AssetsExample_VertexColor.blend and b/docs/Examples/AssetsExample_VertexColor.blend differ