Skip to content

Commit

Permalink
Support multiple camera export
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier150 committed May 17, 2022
1 parent 2e50764 commit 94e017c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 46 deletions.
1 change: 1 addition & 0 deletions blender-for-unrealengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def register():
bpy.types.Scene.bfu_collection_properties_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_object_advanced_properties_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_export_type_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_camera_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_collision_socket_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_lightmap_expanded = bpy.props.BoolProperty()
bpy.types.Scene.bfu_nomenclature_properties_expanded = bpy.props.BoolProperty()
Expand Down
99 changes: 67 additions & 32 deletions blender-for-unrealengine/bfu_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,22 +900,19 @@ def execute(self, context):
)
return {'FINISHED'}



class BFU_OT_CopyRegularCameraButton(Operator):
bl_label = "Copy Regular Camera for Unreal"
bl_idname = "object.copy_regular_camera_command"
bl_description = "Copy Regular Camera Script command"

def execute(self, context):
scene = context.scene
obj = context.object
if obj:
if obj.type == "CAMERA":
setWindowsClipboard(GetImportCameraScriptCommand(obj, False))
self.report(
{'INFO'},
"Camera copied. Paste in Unreal Engine scene for import the camera. (Ctrl+V)")
result = GetImportCameraScriptCommand([obj], False)
if result[0]:
setWindowsClipboard(result[1])
self.report({'INFO'}, result[2])
else:
self.report({'WARNING'}, result[2])
return {'FINISHED'}

class BFU_OT_CopyCineCameraButton(Operator):
Expand All @@ -924,14 +921,13 @@ class BFU_OT_CopyCineCameraButton(Operator):
bl_description = "Copy Cine Camera Script command"

def execute(self, context):
scene = context.scene
obj = context.object
if obj:
if obj.type == "CAMERA":
setWindowsClipboard(GetImportCameraScriptCommand(obj, True))
self.report(
{'INFO'},
"Camera copied. Paste in Unreal Engine scene for import the camera. (Ctrl+V)")
result = GetImportCameraScriptCommand([obj], False)
if result[0]:
setWindowsClipboard(result[1])
self.report({'INFO'}, result[2])
else:
self.report({'WARNING'}, result[2])
return {'FINISHED'}

class BFU_OT_ComputLightMap(Operator):
Expand All @@ -948,21 +944,6 @@ def execute(self, context):
"Compunted Light map: " + str(GetCompuntedLightMap(obj)))
return {'FINISHED'}

class BFU_OT_ComputAllLightMap(Operator):
bl_label = "Calculate all surface area"
bl_idname = "object.computalllightmap"
bl_description = (
"Click to calculate the surface of the all object in the scene"
)

def execute(self, context):
updated = UpdateAreaLightMapList()
self.report(
{'INFO'},
"The light maps of " + str(updated) +
" object(s) have been updated."
)
return {'FINISHED'}

# Animation :

Expand Down Expand Up @@ -1744,6 +1725,36 @@ class BFU_PT_BlenderForUnrealTool(bpy.types.Panel):
default="MySocket"
)

class BFU_OT_CopyRegularCamerasButton(Operator):
bl_label = "Copy Regular Cameras for Unreal"
bl_idname = "object.copy_regular_cameras_command"
bl_description = "Copy Regular Cameras Script command"

def execute(self, context):
objs = context.selected_objects
result = GetImportCameraScriptCommand(objs, False)
if result[0]:
setWindowsClipboard(result[1])
self.report({'INFO'}, result[2])
else:
self.report({'WARNING'}, result[2])
return {'FINISHED'}

class BFU_OT_CopyCineCamerasButton(Operator):
bl_label = "Copy Cine Cameras for Unreal"
bl_idname = "object.copy_cine_cameras_command"
bl_description = "Copy Cine Cameras Script command"

def execute(self, context):
objs = context.selected_objects
result = GetImportCameraScriptCommand(objs, False)
if result[0]:
setWindowsClipboard(result[1])
self.report({'INFO'}, result[2])
else:
self.report({'WARNING'}, result[2])
return {'FINISHED'}

class BFU_OT_ConvertToCollisionButtonBox(Operator):
bl_label = "Convert to box (UBX)"
bl_idname = "object.converttoboxcollision"
Expand Down Expand Up @@ -1892,6 +1903,22 @@ def execute(self, context):
"Skeletal sockets copied. Paste in Unreal Engine Skeletal Mesh assets for import sockets. (Ctrl+V)")
return {'FINISHED'}

class BFU_OT_ComputAllLightMap(Operator):
bl_label = "Calculate all surface area"
bl_idname = "object.computalllightmap"
bl_description = (
"Click to calculate the surface of the all object in the scene"
)

def execute(self, context):
updated = UpdateAreaLightMapList()
self.report(
{'INFO'},
"The light maps of " + str(updated) +
" object(s) have been updated."
)
return {'FINISHED'}

def draw(self, context):

addon_prefs = GetAddonPrefs()
Expand Down Expand Up @@ -1943,6 +1970,12 @@ def FoundTypeInSelect(targetType, include_active=True):
export_type_cameras.operator("object.converttoboxcollision", icon='MESH_CUBE')
'''

bfu_ui_utils.LayoutSection(layout, "bfu_camera_expanded", "Camera")
if scene.bfu_camera_expanded:
copy_camera_buttons = layout.column()
copy_camera_buttons.operator("object.copy_regular_cameras_command", icon="COPYDOWN")
copy_camera_buttons.operator("object.copy_cine_cameras_command", icon="COPYDOWN")

bfu_ui_utils.LayoutSection(layout, "bfu_collision_socket_expanded", "Collision and Socket")
if scene.bfu_collision_socket_expanded:
if not ActiveModeIs("OBJECT"):
Expand Down Expand Up @@ -2902,14 +2935,16 @@ def execute(self, context):
BFU_PT_BlenderForUnrealObject.BFU_OT_ShowCollectionToExport,

BFU_PT_BlenderForUnrealTool,
BFU_PT_BlenderForUnrealTool.BFU_OT_CopyRegularCamerasButton,
BFU_PT_BlenderForUnrealTool.BFU_OT_CopyCineCamerasButton,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToCollisionButtonBox,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToCollisionButtonCapsule,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToCollisionButtonSphere,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToCollisionButtonConvex,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToStaticSocketButton,
BFU_PT_BlenderForUnrealTool.BFU_OT_ConvertToSkeletalSocketButton,
BFU_PT_BlenderForUnrealTool.BFU_OT_CopySkeletalSocketButton,
BFU_PT_BlenderForUnrealObject.BFU_OT_ComputAllLightMap,
BFU_PT_BlenderForUnrealTool.BFU_OT_ComputAllLightMap,

# BFU_PT_BlenderForUnrealDebug, # Unhide for dev

Expand Down
56 changes: 42 additions & 14 deletions blender-for-unrealengine/bfu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,16 +1760,24 @@ def GetImportAssetScriptCommand():
return 'py "'+fullpath+'"'


def GetImportCameraScriptCommand(obj, CineCamera=True):
if obj:
if obj.type == "CAMERA":
def GetImportCameraScriptCommand(objs, CineCamera=True):
# Return (success, command)

success = False
command = ""
report = ""
add_camera_num = 0

def AddCameraToCommand(camera):
if camera.type == "CAMERA":
t = ""
# Get Camera Data
scene = bpy.context.scene
frame_current = scene.frame_current

# First I get the camera data.
# This is a very bad way to do this. I need do a new python file specific to camera with class to get data.
data = bfu_write_text.WriteCameraAnimationTracks(obj, frame_current, frame_current)
data = bfu_write_text.WriteCameraAnimationTracks(camera, frame_current, frame_current)
transform_track = data["Camera transform"][frame_current]
location_x = transform_track["location_x"]
location_y = transform_track["location_y"]
Expand All @@ -1787,11 +1795,7 @@ def GetImportCameraScriptCommand(obj, CineCamera=True):
FocusDistance = data["Camera FocusDistance"][frame_current]
Aperture = data["Camera Aperture"][frame_current]
AspectRatio = data["desired_screen_ratio"]
CameraName = obj.name

# And I apply the camrta data to the copy paste text.
t = "Begin Map" + "\n"
t += " " + "Begin Level" + "\n"
CameraName = camera.name

# Actor
if CineCamera:
Expand Down Expand Up @@ -1841,13 +1845,37 @@ def GetImportCameraScriptCommand(obj, CineCamera=True):

# Close
t += " " + "End Actor" + "\n"
t += " " + "End Level" + "\n"
t += "Begin Surface" + "\n"
t += "End Surface" + "\n"
t += "End Object" + "\n"
return t
return None

return "Please select a Camera."
cameras = []
for obj in objs:
if obj.type == "CAMERA":
cameras.append(obj)

if len(cameras) == 0:
report = "Please select at least one camera."
return (success, command, report)

# And I apply the camrta data to the copy paste text.
t = "Begin Map" + "\n"
t += " " + "Begin Level" + "\n"
for camera in cameras:
add_command = AddCameraToCommand(camera)
if add_command:
t += add_command
add_camera_num += 1

t += " " + "End Level" + "\n"
t += "Begin Surface" + "\n"
t += "End Surface" + "\n"
t += "End Object" + "\n"

success = True
command = t
report = str(add_camera_num)+" camera(s) copied. Paste in Unreal Engine scene for import the camera. (Ctrl+V)"

return (success, command, report)


def GetImportSkeletalMeshSocketScriptCommand(obj):
Expand Down

0 comments on commit 94e017c

Please sign in to comment.