Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
print("creating mesh object...")
#me_ob.from_pydata(verts, [], faces)
me_ob.vertices.add(len(verts))
me_ob.tessfaces.add(len(faces))
me_ob.vertices.foreach_set("co", unpack_list(verts))
me_ob.tessfaces.foreach_set("vertices_raw",unpack_list( faces))
me_ob.tessfaces.foreach_set("use_smooth", smoothings)#smooth array from face
#check if there is uv faces
if len(uvfaces) > 0:
uvtex = me_ob.tessface_uv_textures.new(name="retex")
for i, face in enumerate(me_ob.tessfaces):
blender_tface = uvtex.data[i] #face
mfaceuv = uvfaces[i]
if len(mfaceuv) == 3:
blender_tface.uv1 = mfaceuv[0];
blender_tface.uv2 = mfaceuv[1];
blender_tface.uv3 = mfaceuv[2];
if len(mfaceuv) == 4:
blender_tface.uv1 = mfaceuv[0];
blender_tface.uv2 = mfaceuv[1];
blender_tface.uv3 = mfaceuv[2];
blender_tface.uv4 = mfaceuv[3];
me_ob.update()#need to update the information to able to see into the secne
obmesh = bpy.data.objects.new(("Re_"+obj.name),me_ob)
bpy.context.scene.update()
#Build tmp materials
materialname = "ReMaterial"
for matcount in mesh.materials:
matdata = bpy.data.materials.new(materialname)
me_ob.materials.append(matdata)
#assign face to material id
for face in mesh.tessfaces:
me_ob.faces[face.index].material_index = face.material_index
#vertices weight groups
for vgroup in vertGroups:
group = obmesh.vertex_groups.new(vgroup)
for v in vertGroups[vgroup]:
group.add([v[0]], v[1], 'ADD')# group.add(array[vertex id],weight,add)
bpy.context.scene.objects.link(obmesh)
print("Mesh Material Count:",len(me_ob.materials))
matcount = 0
print("MATERIAL ID OREDER:")
for mat in me_ob.materials:
print("-Material:",mat.name,"INDEX:",matcount)
matcount += 1
print("Object Name:",obmesh.name)
bpy.context.scene.update()
bselected = True
break
if bselected:
self.report({'INFO'}, "Rebuild Mesh Finish!")
print("Finish Mesh Build...")
else:
self.report({'INFO'}, "Didn't Select Mesh Object!")
print("Didn't Select Mesh Object!")
print("----------------------------------------")
return{'FINISHED'}
class OBJECT_OT_UTRebuildArmature(bpy.types.Operator):
bl_idname = "object.utrebuildarmature" # XXX, name???
bl_label = "Rebuild Armature"
__doc__ = """If mesh is deform when importing to unreal engine try this. It rebuild the bones one at the time by select one armature object scrape to raw setup build. Note the scale will be 1:1 for object mode. To keep from deforming"""
def invoke(self, context, event):
print("----------------------------------------")
print("Init Rebuild Armature...")
bselected = False
for obj in bpy.data.objects:
if obj.type == 'ARMATURE' and obj.select == True:
currentbone = [] #select armature for roll copy
print("Armature Name:",obj.name)
objectname = "ArmatureDataPSK"
meshname ="ArmatureObjectPSK"
armdata = bpy.data.armatures.new(objectname)
ob_new = bpy.data.objects.new(meshname, armdata)
bpy.context.scene.objects.link(ob_new)
bpy.ops.object.mode_set(mode='OBJECT')
for i in bpy.context.scene.objects: i.select = False #deselect all objects
ob_new.select = True
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
for bone in obj.data.edit_bones:
if bone.parent != None:
currentbone.append([bone.name,bone.roll])
else:
currentbone.append([bone.name,bone.roll])
bpy.ops.object.mode_set(mode='OBJECT')
for i in bpy.context.scene.objects: i.select = False #deselect all objects
bpy.context.scene.objects.active = ob_new
bpy.ops.object.mode_set(mode='EDIT')
for bone in obj.data.bones:
bpy.ops.object.mode_set(mode='EDIT')
newbone = ob_new.data.edit_bones.new(bone.name)
newbone.head = bone.head_local
newbone.tail = bone.tail_local
for bonelist in currentbone:
if bone.name == bonelist[0]:
newbone.roll = bonelist[1]
break
if bone.parent != None:
parentbone = ob_new.data.edit_bones[bone.parent.name]
newbone.parent = parentbone
print("Bone Count:",len(obj.data.bones))
print("Hold Bone Count",len(currentbone))
print("New Bone Count",len(ob_new.data.edit_bones))
print("Rebuild Armture Finish:",ob_new.name)
bpy.context.scene.update()
bselected = True
break
if bselected:
self.report({'INFO'}, "Rebuild Armature Finish!")
else:
self.report({'INFO'}, "Didn't Select Armature Object!")
print("End of Rebuild Armature.")
print("----------------------------------------")
return{'FINISHED'}
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
class Panel_UDKExport( bpy.types.Panel ):
bl_label = "UDK Export"
bl_idname = "OBJECT_PT_udk_tools"
#bl_space_type = "PROPERTIES"
#bl_region_type = "WINDOW"
#bl_context = "object"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
#def draw_header(self, context):
# layout = self.layout
#obj = context.object
#layout.prop(obj, "select", text="")
#@classmethod
#def poll(cls, context):
# return context.active_object
def draw(self, context):
layout = self.layout
path = get_dst_path()
object_name = ""
#if context.object:
# object_name = context.object.name
if context.active_object:
object_name = context.active_object.name
layout.prop(context.scene, "udk_option_smoothing_groups")
layout.prop(context.scene, "udk_option_clamp_uv")
layout.prop(context.scene, "udk_option_verbose")
row = layout.row()
row.label(text="Active object: " + object_name)
layout.prop(context.scene, "udk_option_filename_src")
row = layout.row()
row.label(text=path)
layout.prop(context.scene, "udk_option_export")
layout.operator("object.udk_export")
layout.operator("object.toggle_console")
layout.operator(OBJECT_OT_UTRebuildArmature.bl_idname)
layout.operator(OBJECT_OT_MeshClearWeights.bl_idname)
layout.operator(OBJECT_OT_UTSelectedFaceSmooth.bl_idname)
layout.operator(OBJECT_OT_UTRebuildMesh.bl_idname)
class ExportUDKAnimData(bpy.types.Operator):
"""Export Skeleton Mesh / Animation Data file(s)"""
bl_idname = "export_anim.udk" # this is important since its how bpy.ops.export.udk_anim_data is constructed
bl_label = "Export PSK/PSA"
__doc__ = """One mesh and one armature else select one mesh or armature to be exported"""
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
filepath = StringProperty(
subtype='FILE_PATH',
)
filter_glob = StringProperty(
default="*.psk;*.psa",
options={'HIDDEN'},
)
udk_option_smoothing_groups = bpy.types.Scene.udk_option_smoothing_groups
udk_option_clamp_uv = bpy.types.Scene.udk_option_clamp_uv
udk_option_verbose = bpy.types.Scene.udk_option_verbose
udk_option_filename_src = bpy.types.Scene.udk_option_filename_src
udk_option_export = bpy.types.Scene.udk_option_export
John Phan
committed
@classmethod
def poll(cls, context):
return context.active_object != None
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
def execute(self, context):
scene = bpy.context.scene
scene.udk_option_export_psk = (scene.udk_option_export == '0' or scene.udk_option_export == '2')
scene.udk_option_export_psa = (scene.udk_option_export == '1' or scene.udk_option_export == '2')
filepath = get_dst_path()
# cache settings
restore_frame = scene.frame_current
message = "Finish Export!"
try:
export(filepath)
except Error as err:
print(err.message)
message = err.message
# restore settings
scene.frame_set(restore_frame)
self.report({'WARNING', 'INFO'}, message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def menu_func(self, context):
default_path = os.path.splitext(bpy.data.filepath)[0] + ".psk"
self.layout.operator(ExportUDKAnimData.bl_idname, text="Skeleton Mesh / Animation Data (.psk/.psa)").filepath = default_path
#===========================================================================
# Entry
#===========================================================================
Brendon Murphy
committed
def register():
#print("REGISTER")
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_export.append(menu_func)
Brendon Murphy
committed
def unregister():
#print("UNREGISTER")
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_export.remove(menu_func)
Brendon Murphy
committed
if __name__ == "__main__":
#print("\n"*4)
print(header("UDK Export PSK/PSA Alpha 0.1", 'CENTER'))
register()
#loader
#filename = "D:/Projects/BlenderScripts/io_export_udk_psa_psk_alpha.py"
#exec(compile(open(filename).read(), filename, 'exec'))