Newer
Older
for face in obj.data.faces:
#print(dir(face))
if face.use_smooth == True:
face.select = True
John Phan
committed
smoothcount += 1
#print("selected:",face.select)
else:
John Phan
committed
flatcount += 1
face.select = False
#print("selected:",face.select)
#print(("smooth:",face.use_smooth))
John Phan
committed
bpy.context.scene.update()
John Phan
committed
print("Select Smooth Count:",smoothcount," Flat Count:",flatcount)
John Phan
committed
print("Selected faces exectue!")
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."
def invoke(self, context, event):
John Phan
committed
for obj in bpy.data.objects:
if obj.type == 'ARMATURE' and obj.select == True:
John Phan
committed
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)
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
John Phan
committed
print("Bone Count:",len(obj.data.bones))
print("Hold Bone Count",len(currentbone))
print("New Bone Count",len(ob_new.data.edit_bones))
bpy.context.scene.update()
break
return{'FINISHED'}
John Phan
committed
# rounded the vert locations to save a bit of blurb.. change the round value or remove for accuracy i suppose
def rounded_tuple(tup):
return tuple(round(value,4) for value in tup)
def unpack_list(list_of_tuples):
l = []
for t in list_of_tuples:
l.extend(t)
return l
class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
bl_idname = "object.utrebuildmesh" # XXX, name???
bl_label = "Rebuild Mesh"
__doc__ = "Work In Progress. It rebuild the mesh from scrape from the selected mesh."
John Phan
committed
def invoke(self, context, event):
print("Init Scripting...")
John Phan
committed
for obj in bpy.data.objects:
if obj.type == 'MESH' and obj.select == True:
for i in bpy.context.scene.objects: i.select = False #deselect all objects
obj.select = True
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='OBJECT')
me_ob = bpy.data.meshes.new(("Re_"+obj.name))
John Phan
committed
mesh = obj.data
faces = []
verts = []
smoothings = []
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
uvfaces = []
uv_layer = mesh.uv_textures.active
for face in mesh.faces:
v = []
smoothings.append(face.use_smooth)
if uv_layer != None:#check if there texture data exist
faceUV = uv_layer.data[face.index]
#print(len(faceUV.uv))
uvs = []
for uv in faceUV.uv:
#vert = mesh.vertices[videx]
#print("UV:",uv[0],":",uv[1])
uvs.append((uv[0],uv[1]))
#print(uvs)
uvfaces.append(uvs)
for videx in face.vertices:
vert = mesh.vertices[videx]
v.append(videx)
faces.append(v)
#print(dir(face))
for vertex in mesh.vertices:
verts.append(vertex.co.to_tuple())
'''
#Fail for this method
#can't covert the tri face plogyon
John Phan
committed
for face in mesh.faces:
x = [f for f in face.vertices]
faces.extend(x)
smoothings.append(face.use_smooth)
for vertex in mesh.vertices:
verts.append(vertex.co.to_tuple())
me_ob.vertices.add(len(verts))
me_ob.faces.add(len(faces)//4)
me_ob.vertices.foreach_set("co", unpack_list(verts))
me_ob.faces.foreach_set("vertices_raw", faces)
me_ob.faces.foreach_set("use_smooth", smoothings)
'''
#test dummy mesh
#verts = [(-1,1,0),(1,1,0),(1,-1,0),(-1,-1,0),(0,1,1),(0,-1,1)]
#faces = [(0,1,2,3),(1,2,5,4),(0,3,5,4),(0,1,4),(2,3,5)]
#for f in faces:
#print("face",f)
#for v in verts:
#print("vertex",v)
#me_ob = bpy.data.objects.new("ReBuildMesh",me_ob)
me_ob.from_pydata(verts, [], faces)
me_ob.faces.foreach_set("use_smooth", smoothings)#smooth array from face
John Phan
committed
me_ob.update()
#check if there is uv faces
if len(uvfaces) > 0:
uvtex = me_ob.uv_textures.new(name="retex")
for i, face in enumerate(me_ob.faces):
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];
obmesh = bpy.data.objects.new(("Re_"+obj.name),me_ob)
John Phan
committed
bpy.context.scene.objects.link(obmesh)
print("Object Name:",obmesh.name)
bpy.context.scene.update()
#bpy.ops.wm.console_toggle()
John Phan
committed
break
John Phan
committed
print("Finish Mesh Build...")
self.report({'INFO'}, "Rebuild Mesh Finish!")
return{'FINISHED'}
def menu_func(self, context):
#bpy.context.scene.unrealexportpsk = True
#bpy.context.scene.unrealexportpsa = True
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
Brendon Murphy
committed
def register():
Campbell Barton
committed
bpy.utils.register_module(__name__)
Brendon Murphy
committed
def unregister():
Campbell Barton
committed
bpy.utils.unregister_module(__name__)
Brendon Murphy
committed
if __name__ == "__main__":