Skip to content

Commit

Permalink
Merge branch 'Dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier150 committed Jun 19, 2021
2 parents e57550b + 7a358c6 commit b392455
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 93 deletions.
7 changes: 5 additions & 2 deletions Release log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
- 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
118 changes: 118 additions & 0 deletions blender-for-unrealengine/bfu_export_get_info.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
# 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

17 changes: 9 additions & 8 deletions blender-for-unrealengine/bfu_export_single_fbx_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(),
Expand All @@ -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()

Expand Down
8 changes: 5 additions & 3 deletions blender-for-unrealengine/bfu_export_single_fbx_nla_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions blender-for-unrealengine/bfu_export_single_skeletal_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions blender-for-unrealengine/bfu_export_single_static_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def ExportSingleStaticMesh(
GetAllCollisionAndSocketsObj(bpy.context.selected_objects)
)

SetVertexColorForUnrealExport(active)

bpy.ops.export_scene.fbx(
filepath=fullpath,
check_existing=False,
Expand Down
26 changes: 26 additions & 0 deletions blender-for-unrealengine/bfu_export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit b392455

Please sign in to comment.