Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Phan <darkneter@gmail.com>2012-04-14 20:29:49 +0400
committerJohn Phan <darkneter@gmail.com>2012-04-14 20:29:49 +0400
commit44f8827118f18f38f929c5eac86333a5b9c0b977 (patch)
treef144217d013146f11b0cbd6c9e18c60f72aaf2da /io_export_unreal_psk_psa.py
parentc1984f79658b9d2497b70da49ea489a49dda3178 (diff)
Some clean up in coding. Fixed merge meshes. Fixed error and fail message that will display.
Diffstat (limited to 'io_export_unreal_psk_psa.py')
-rw-r--r--io_export_unreal_psk_psa.py108
1 files changed, 59 insertions, 49 deletions
diff --git a/io_export_unreal_psk_psa.py b/io_export_unreal_psk_psa.py
index dcc1847f..642038e3 100644
--- a/io_export_unreal_psk_psa.py
+++ b/io_export_unreal_psk_psa.py
@@ -114,7 +114,7 @@ MaterialName = []
# TODO: remove this 1am hack
nbone = 0
exportmessage = "Export Finish"
-
+exportfile = True
########################################################################
# Generic Object->Integer mapping
# the object must be usable as a dictionary key
@@ -631,36 +631,33 @@ def meshmerge(selectedobjects):
# http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#Triangulate_NMesh
#blender 2.63 format using the Operators/Commands to convert the mesh to tri mesh
def triangulateNMesh(object):
- print("Converting quad to tri mesh...")
+ print("Converting quad to tri mesh...",object.name)
scene = bpy.context.scene
bpy.ops.object.mode_set(mode='OBJECT')
for i in scene.objects: i.select = False #deselect all objects
object.select = True
scene.objects.active = object #set the mesh object to current
- bpy.ops.object.mode_set(mode='OBJECT')
- me_da = object.data.copy() #copy data
- me_ob = object.copy() #copy object
- #note two copy two types else it will use the current data or mesh
- me_ob.data = me_da
- scene = bpy.context.scene
- bpy.context.scene.objects.link(me_ob)#link the object to the scene #current object location
- for i in scene.objects: i.select = False #deselect all objects
- me_ob.select = True
- scene.objects.active = me_ob #set the mesh object to current
bpy.ops.object.mode_set(mode='EDIT') #Operators
bpy.ops.mesh.select_all(action='SELECT')#select all the face/vertex/edge
bpy.ops.mesh.quads_convert_to_tris() #Operators
bpy.context.scene.update()
bpy.ops.object.mode_set(mode='OBJECT') # set it in object
print("Triangulate Mesh Done!")
- return me_ob
+ return object
#Texture not working still find a way to get it work
# Actual object parsing functions
def parse_meshes(blender_meshes, psk_file):
- global exportmessage
+ global exportmessage, exportfile
print("Number of Object Meshes:",len(blender_meshes))
for current_obj in blender_meshes: #number of mesh that should be one mesh here
+ if current_obj.parent != None:
+ print("Armature Found!")
+ else:
+ exportmessage = "Mesh is not parent to Armature!"
+ bpy.context.scene.objects.unlink(current_obj)
+ exportfile = False
+ return
#material
if len(current_obj.material_slots) > 0:
counter = 0
@@ -681,8 +678,6 @@ def parse_meshes(blender_meshes, psk_file):
counter += 1
print("PSK INDEX:",matdata.TextureIndex)
-
-
points = ObjMap()
wedges = ObjMap()
discarded_face_count = 0
@@ -690,19 +685,13 @@ def parse_meshes(blender_meshes, psk_file):
faceUV = None
scene = bpy.context.scene #get current scene
EXPORT_APPLY_MODIFIERS = True
- currentmeshobject = current_obj;
-
- current_obj = triangulateNMesh(currentmeshobject) #convert tri incase
- bpy.context.scene.objects.unlink(currentmeshobject)
+ current_obj = triangulateNMesh(current_obj) #convert tri incase
me = current_obj.to_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW') #apply modified mesh and write mesh
-
- #print(dir(me))
-
faceuv = len(me.uv_textures) > 0 #check if has uv texture
if faceuv:
uv_layer = me.tessface_uv_textures.active.data[:]
else:
-
+ print("No UV Texture is added and will be ignore!")
has_UV = False
for face in me.tessfaces:
@@ -715,13 +704,13 @@ def parse_meshes(blender_meshes, psk_file):
if len(face.vertices) != 3:
#raise RuntimeError("Non-triangular face (%i)" % len(face.vertices))
exportmessage = "MESH IS NOT TRIANGLE (Alt + T)"
+ exportfile = False
return
if not is_1d_face(face,me):#face , Mesh
wedge_list = []
vect_list = []
-
for i in range(3): #UV TEXTURE, VERTICES
vert_index = face.vertices[i]
vert = me.vertices[vert_index]
@@ -807,25 +796,19 @@ def parse_meshes(blender_meshes, psk_file):
me.vertices[dindex0].select = True
me.vertices[dindex1].select = True
me.vertices[dindex2].select = True
-
- #raise RuntimeError("normal vector coplanar with face! points:", me.vertices[dindex0].co, current_mesh.vertices[dindex1].co, current_mesh.vertices[dindex2].co)
+ print("normal vector coplanar with face! points:", me.vertices[dindex0].co, current_mesh.vertices[dindex1].co, current_mesh.vertices[dindex2].co)
exportmessage = "One of the face is dot or period or line, coplanar with the face"
+ exportfile = False
+ bpy.context.scene.objects.unlink(current_obj)
return
#print(dir(current_face))
- face.select = True
- #print("smooth:",(current_face.use_smooth))
- #not sure if this right
- #tri.SmoothingGroups
- print(face.use_smooth)
+ #face.select = True
+
if face.use_smooth == True:
tri.SmoothingGroups = 0
else:
tri.SmoothingGroups = 1
- #tri.SmoothingGroups = face.use_smooth
- #tri.SmoothingGroups = hex(face.use_smooth)
- #print(hex(True))
- print(hex(face.use_smooth))
- #tri.SmoothingGroups = 1
+
tri.MatIndex = object_material_index
#print(tri)
psk_file.AddFace(tri)
@@ -835,8 +818,14 @@ def parse_meshes(blender_meshes, psk_file):
print (" -- Dumping Mesh Points -- LEN:",len(points.dict))
for point in points.items():
psk_file.AddPoint(point)
- #if len(points.dict) > 32767:
+ if len(points.dict) > 32767:
#raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict))
+ print("Vertex point reach max limited 32767 in pack data. Your",len(points.dict))
+ exportmessage = "You have went over the limit on your Vectices/Vertex points. Limit is 32767."
+ exportfile = False
+ bpy.context.scene.objects.unlink(current_obj)
+ return
+
print (" -- Dumping Mesh Wedge -- LEN:",len(wedges.dict))
for wedge in wedges.items():
@@ -989,6 +978,7 @@ def parse_bone(blender_bone, psk_file, psa_file, parent_id, is_root_bone, parent
parse_bone(current_child_bone, psk_file, psa_file, my_id, 0, mainparent, parent_root)
def parse_armature(blender_armature, psk_file, psa_file):
+ global exportmessage, exportfile
print ("----- parsing armature -----")
print ('blender_armature length: %i' % (len(blender_armature)))
@@ -1014,9 +1004,15 @@ def parse_armature(blender_armature, psk_file, psa_file):
#will ingore this part of the ocde
"""
if len(current_armature.bones) == 0:
- raise RuntimeError("Warning add two bones else it will crash the unreal editor.")
+ #raise RuntimeError("Warning add two bones else it will crash the unreal editor.")
+ exportmessage = "Warning add two bones else it will crash the unreal editor."
+ exportfile = False
+ return
if len(current_armature.bones) == 1:
- raise RuntimeError("Warning add one more bone else it will crash the unreal editor.")
+ #raise RuntimeError("Warning add one more bone else it will crash the unreal editor.")
+ exportmessage = "Warning add one more bone else it will crash the unreal editor."
+ exportfile = False
+ return
mainbonecount = 0;
for current_bone in current_armature.bones: #list the bone. #note this will list all the bones.
@@ -1024,8 +1020,11 @@ def parse_armature(blender_armature, psk_file, psa_file):
mainbonecount += 1
print("Main Bone",mainbonecount)
if mainbonecount > 1:
- #print("Warning there no main bone.")
- raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount)
+ print("Warning there no main bone.")
+ #raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount)
+ exportmessage = "There no Main Bone!"
+ exportfile = False
+ return
for current_bone in current_armature.bones: #list the bone. #note this will list all the bones.
if(current_bone.parent is None):
parse_bone(current_bone, psk_file, psa_file, 0, 0, current_obj.matrix_local, None)
@@ -1468,7 +1467,7 @@ def parse_animation(blender_scene, blender_armatures, psa_file):
def fs_callback(filename, context):
#this deal with repeat export and the reset settings
- global nbone, exportmessage
+ global nbone, exportmessage, exportfile
nbone = 0
start_time = time.clock()
@@ -1520,8 +1519,11 @@ def fs_callback(filename, context):
#if there 1 mesh in scene add to the array
if len(blender_meshes) == 1:
mesh = blender_meshes[0]
+ print("MESH NAME",blender_meshes[0].name)
blender_meshes = []
- blender_meshes.append(mesh.copy())
+ copymesh = mesh.copy()
+ bpy.context.scene.objects.link(copymesh)
+ blender_meshes.append(copymesh)
print(" - One Mesh Scene")
#if there more than one mesh and one mesh select add to array
elif (len(blender_meshes) > 1) and (len(selectmesh) == 1):
@@ -1529,6 +1531,7 @@ def fs_callback(filename, context):
exportmessage = "Error, Mesh Object not Center right should be (0,0,0)."
for mesh in selectmesh:#remove object
bpy.context.scene.objects.unlink(mesh)
+ exportfile = False
return
blender_meshes = []
copymesh = selectmesh[0]
@@ -1562,6 +1565,7 @@ def fs_callback(filename, context):
else:
print(" - Too Many Meshes!")
exportmessage = " - Select Mesh(s) For Export!"
+ exportfile = False
print(" - Select One Mesh Object!")
bmesh = False
return
@@ -1586,6 +1590,7 @@ def fs_callback(filename, context):
elif blender_meshes[0].scale.x != 1 and blender_meshes[0].scale.y != 1 and blender_meshes[0].scale.z != 1:
print("Error, Mesh Object not scale right should be (1,1,1).")
exportmessage = "Error, Mesh Object not scale right should be (1,1,1)."
+ exportfile = False
return
elif blender_meshes[0].location.x == 0 and blender_meshes[0].location.y == 0 and blender_meshes[0].location.z == 0:
#print("Okay")
@@ -1595,10 +1600,12 @@ def fs_callback(filename, context):
print("Error, Mesh Object not center.",blender_meshes[0].location)
#exportmessage = "Error, Mesh Object not center."
exportmessage = "Error, Mesh Object not center."
+ exportfile = False
bMeshCenter = False
return
else:
exportmessage = "Please Select your Meshes that matches that Armature for Export."
+ exportfile = False
return
else:
bmesh = False
@@ -1612,6 +1619,8 @@ def fs_callback(filename, context):
print("Error, Armature Object not scale right should be (1,1,1).")
exportmessage = "Error, Armature Object not scale right should be (1,1,1)."
bArmatureScale = False
+ exportfile = False
+ return
if blender_armature[0].location.x == 0 and blender_armature[0].location.y == 0 and blender_armature[0].location.z == 0:
#print("Okay")
bArmatureCenter = True
@@ -1619,6 +1628,8 @@ def fs_callback(filename, context):
print("Error, Armature Object not center.",blender_armature[0].location)
exportmessage = "Error, Armature Object not center."
bArmatureCenter = False
+ exportfile = False
+ return
@@ -1629,6 +1640,7 @@ def fs_callback(filename, context):
print("=================================")
print("= Export Fail! =")
print("=================================")
+ return
else:
exportmessage = "Export Finish!"
#print("blender_armature:",dir(blender_armature[0]))
@@ -1678,7 +1690,9 @@ def fs_callback(filename, context):
raise
# reset current frame
-
+ if exportfile == False:
+ print("EXPORT STOP!")
+ return
context.scene.frame_set(cur_frame) #set frame back to original frame
##########################
@@ -2008,10 +2022,6 @@ class OBJECT_OT_UnrealExport(bpy.types.Operator):
default_path = os.path.splitext(bpy.data.filepath)[0] + ".psk"
fs_callback(default_path, bpy.context)
- #self.report({'WARNING', 'INFO'}, exportmessage)
- #self.report({'INFO'}, exportmessage)
- #self.report({'DEBUG'}, exportmessage)
- #self.report({'WARNING'}, exportmessage)
self.report({'ERROR'}, exportmessage)
return{'FINISHED'}