Skip to content
Snippets Groups Projects
Commit 1ee940a6 authored by John Phan's avatar John Phan
Browse files

Fixed mesh rebuild for face id materials and vertex groups.

parent 40372e3a
No related branches found
No related tags found
No related merge requests found
...@@ -1823,7 +1823,7 @@ class ExportUDKAnimData(bpy.types.Operator): ...@@ -1823,7 +1823,7 @@ class ExportUDKAnimData(bpy.types.Operator):
'''Export Skeleton Mesh / Animation Data file(s)''' '''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_idname = "export_anim.udk" # this is important since its how bpy.ops.export.udk_anim_data is constructed
bl_label = "Export PSK/PSA" bl_label = "Export PSK/PSA"
__doc__ = "One mesh and one armature else select one mesh or armature to be exported." __doc__ = """One mesh and one armature else select one mesh or armature to be exported."""
# List of operator properties, the attributes will be assigned # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # to the class instance from the operator settings before calling.
...@@ -1954,7 +1954,7 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator): ...@@ -1954,7 +1954,7 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator):
global exportmessage global exportmessage
bl_idname = "export_mesh.udk" # XXX, name??? bl_idname = "export_mesh.udk" # XXX, name???
bl_label = "Unreal Export" bl_label = "Unreal Export"
__doc__ = "Select export setting for .psk/.psa or both." __doc__ = """Select export setting for .psk/.psa or both."""
def invoke(self, context, event): def invoke(self, context, event):
print("Init Export Script:") print("Init Export Script:")
...@@ -1972,8 +1972,7 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator): ...@@ -1972,8 +1972,7 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator):
print("Exporting ALL...") print("Exporting ALL...")
default_path = os.path.splitext(bpy.data.filepath)[0] + ".psk" default_path = os.path.splitext(bpy.data.filepath)[0] + ".psk"
fs_callback(default_path, bpy.context) fs_callback(default_path, bpy.context)
#self.report({'WARNING', 'INFO'}, exportmessage) #self.report({'WARNING', 'INFO'}, exportmessage)
self.report({'INFO'}, exportmessage) self.report({'INFO'}, exportmessage)
return{'FINISHED'} return{'FINISHED'}
...@@ -1981,29 +1980,24 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator): ...@@ -1981,29 +1980,24 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator):
class OBJECT_OT_UTSelectedFaceSmooth(bpy.types.Operator): class OBJECT_OT_UTSelectedFaceSmooth(bpy.types.Operator):
bl_idname = "object.utselectfacesmooth" # XXX, name??? bl_idname = "object.utselectfacesmooth" # XXX, name???
bl_label = "Select Smooth faces" bl_label = "Select Smooth faces"
__doc__ = "It will only select smooth faces that is select mesh." __doc__ = """It will only select smooth faces that is select mesh."""
def invoke(self, context, event): def invoke(self, context, event):
#print("Init Export Script:") print("----------------------------------------")
print("Init Select Face(s):")
bselected = False
for obj in bpy.data.objects: for obj in bpy.data.objects:
#print(dir(obj))
#print(dir(obj))
if obj.type == 'MESH' and obj.select == True: if obj.type == 'MESH' and obj.select == True:
smoothcount = 0 smoothcount = 0
flatcount = 0 flatcount = 0
bpy.ops.object.mode_set(mode='OBJECT')#it need to go into object mode to able to select the faces bpy.ops.object.mode_set(mode='OBJECT')#it need to go into object mode to able to select the faces
for i in bpy.context.scene.objects: i.select = False #deselect all objects for i in bpy.context.scene.objects: i.select = False #deselect all objects
obj.select = True obj.select = True #set current object select
bpy.context.scene.objects.active = obj bpy.context.scene.objects.active = obj #set active object
#print("Mesh found!",obj.name)
#bpy.ops.object.mode_set(mode='EDIT')
#print(len(obj.data.faces))
for face in obj.data.faces: for face in obj.data.faces:
#print(dir(face))
if face.use_smooth == True: if face.use_smooth == True:
face.select = True face.select = True
smoothcount += 1 smoothcount += 1
#print("selected:",face.select)
else: else:
flatcount += 1 flatcount += 1
face.select = False face.select = False
...@@ -2011,20 +2005,27 @@ class OBJECT_OT_UTSelectedFaceSmooth(bpy.types.Operator): ...@@ -2011,20 +2005,27 @@ class OBJECT_OT_UTSelectedFaceSmooth(bpy.types.Operator):
#print(("smooth:",face.use_smooth)) #print(("smooth:",face.use_smooth))
bpy.context.scene.update() bpy.context.scene.update()
bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='EDIT')
print("Select Smooth Count:",smoothcount," Flat Count:",flatcount) print("Select Smooth Count(s):",smoothcount," Flat Count(s):",flatcount)
bselected = True
break break
#objects = bpy.data.objects if bselected:
print("Selected faces exectue!") print("Selected Face(s) Exectue!")
self.report({'INFO'}, "Selected Face(s) Exectue!")
else:
print("Didn't select Mesh Object!")
self.report({'INFO'}, "Didn't Select Mesh Object!")
print("----------------------------------------")
return{'FINISHED'} return{'FINISHED'}
class OBJECT_OT_UTRebuildArmature(bpy.types.Operator): class OBJECT_OT_UTRebuildArmature(bpy.types.Operator):
bl_idname = "object.utrebuildarmature" # XXX, name??? bl_idname = "object.utrebuildarmature" # XXX, name???
bl_label = "Rebuild Armature" 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." __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): def invoke(self, context, event):
print("----------------------------------------")
print("Init Rebuild Armature...")
bselected = False
for obj in bpy.data.objects: for obj in bpy.data.objects:
if obj.type == 'ARMATURE' and obj.select == True: if obj.type == 'ARMATURE' and obj.select == True:
currentbone = [] #select armature for roll copy currentbone = [] #select armature for roll copy
...@@ -2067,8 +2068,14 @@ class OBJECT_OT_UTRebuildArmature(bpy.types.Operator): ...@@ -2067,8 +2068,14 @@ class OBJECT_OT_UTRebuildArmature(bpy.types.Operator):
print("New Bone Count",len(ob_new.data.edit_bones)) print("New Bone Count",len(ob_new.data.edit_bones))
print("Rebuild Armture Finish:",ob_new.name) print("Rebuild Armture Finish:",ob_new.name)
bpy.context.scene.update() bpy.context.scene.update()
bselected = True
break break
self.report({'INFO'}, "Rebuild Armature Finish!") 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'} return{'FINISHED'}
# rounded the vert locations to save a bit of blurb.. change the round value or remove for accuracy i suppose # rounded the vert locations to save a bit of blurb.. change the round value or remove for accuracy i suppose
...@@ -2084,10 +2091,12 @@ def unpack_list(list_of_tuples): ...@@ -2084,10 +2091,12 @@ def unpack_list(list_of_tuples):
class OBJECT_OT_UTRebuildMesh(bpy.types.Operator): class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
bl_idname = "object.utrebuildmesh" # XXX, name??? bl_idname = "object.utrebuildmesh" # XXX, name???
bl_label = "Rebuild Mesh" bl_label = "Rebuild Mesh"
__doc__ = "Work In Progress. It rebuild the mesh from scrape from the selected mesh." __doc__ = """It rebuild the mesh from scrape from the selected mesh object."""
def invoke(self, context, event): def invoke(self, context, event):
print("Init Scripting...") print("----------------------------------------")
print("Init Mesh Bebuild...")
bselected = False
for obj in bpy.data.objects: for obj in bpy.data.objects:
if obj.type == 'MESH' and obj.select == True: if obj.type == 'MESH' and obj.select == True:
for i in bpy.context.scene.objects: i.select = False #deselect all objects for i in bpy.context.scene.objects: i.select = False #deselect all objects
...@@ -2100,10 +2109,12 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator): ...@@ -2100,10 +2109,12 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
verts = [] verts = []
smoothings = [] smoothings = []
uvfaces = [] uvfaces = []
#print(dir(mesh))
print("creating array build mesh...")
uv_layer = mesh.uv_textures.active uv_layer = mesh.uv_textures.active
for face in mesh.faces: for face in mesh.faces:
v = [] v = []
smoothings.append(face.use_smooth) smoothings.append(face.use_smooth)#smooth or flat in boolean
if uv_layer != None:#check if there texture data exist if uv_layer != None:#check if there texture data exist
faceUV = uv_layer.data[face.index] faceUV = uv_layer.data[face.index]
#print(len(faceUV.uv)) #print(len(faceUV.uv))
...@@ -2117,11 +2128,23 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator): ...@@ -2117,11 +2128,23 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
for videx in face.vertices: for videx in face.vertices:
vert = mesh.vertices[videx] vert = mesh.vertices[videx]
v.append(videx) v.append(videx)
faces.append(v) faces.append(v)
#vertex positions
#print(dir(face))
for vertex in mesh.vertices: for vertex in mesh.vertices:
verts.append(vertex.co.to_tuple()) verts.append(vertex.co.to_tuple())
#vertices weight groups into array
vertGroups = {} #array in strings
for vgroup in obj.vertex_groups:
#print(dir(vgroup))
#print("name:",(vgroup.name),"index:",vgroup.index)
#vertex in index and weight
vlist = []
for v in mesh.vertices:
for vg in v.groups:
if vg.group == vgroup.index:
vlist.append((v.index,vg.weight))
#print((v.index,vg.weight))
vertGroups[vgroup.name] = vlist
''' '''
#Fail for this method #Fail for this method
#can't covert the tri face plogyon #can't covert the tri face plogyon
...@@ -2145,6 +2168,7 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator): ...@@ -2145,6 +2168,7 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
#for v in verts: #for v in verts:
#print("vertex",v) #print("vertex",v)
#me_ob = bpy.data.objects.new("ReBuildMesh",me_ob) #me_ob = bpy.data.objects.new("ReBuildMesh",me_ob)
print("creating mesh object...")
me_ob.from_pydata(verts, [], faces) me_ob.from_pydata(verts, [], faces)
me_ob.faces.foreach_set("use_smooth", smoothings)#smooth array from face me_ob.faces.foreach_set("use_smooth", smoothings)#smooth array from face
me_ob.update() me_ob.update()
...@@ -2164,15 +2188,45 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator): ...@@ -2164,15 +2188,45 @@ class OBJECT_OT_UTRebuildMesh(bpy.types.Operator):
blender_tface.uv3 = mfaceuv[2]; blender_tface.uv3 = mfaceuv[2];
blender_tface.uv4 = mfaceuv[3]; blender_tface.uv4 = mfaceuv[3];
obmesh = bpy.data.objects.new(("Re_"+obj.name),me_ob) 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.faces:
#print(dir(face))
me_ob.faces[face.index].material_index = face.material_index
#vertices weight groups
for vgroup in vertGroups:
#print("vgroup",vgroup)#name of group
#print(dir(vgroup))
#print(vertGroups[vgroup])
group = obmesh.vertex_groups.new(vgroup)
#print("group index",group.index)
for v in vertGroups[vgroup]:
group.add([v[0]], v[1], 'ADD')# group.add(array[vertex id],weight,add)
#print("[vertex id, weight]",v) #array (0,0)
#print("[vertex id, weight]",v[0],":",v[1]) #array (0,0)
bpy.context.scene.objects.link(obmesh) bpy.context.scene.objects.link(obmesh)
print("Mesh Material Count:",len(me_ob.materials))
for mat in me_ob.materials:
print("-Material:",mat.name)
print("Object Name:",obmesh.name) print("Object Name:",obmesh.name)
bpy.context.scene.update() bpy.context.scene.update()
#bpy.ops.wm.console_toggle() #bpy.ops.wm.console_toggle()
bselected = True
break break
if bselected:
print("Finish Mesh Build...") self.report({'INFO'}, "Rebuild Mesh Finish!")
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'} return{'FINISHED'}
def menu_func(self, context): def menu_func(self, context):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment