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

fixed material.

parent 70fac132
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
bl_info = { bl_info = {
"name": "Export Skeleletal Mesh/Animation Data", "name": "Export Skeleletal Mesh/Animation Data",
"author": "Darknet/Optimus_P-Fat/Active_Trash/Sinsoft/VendorX", "author": "Darknet/Optimus_P-Fat/Active_Trash/Sinsoft/VendorX",
"version": (2, 0), "version": (2, 2),
"blender": (2, 5, 6), "blender": (2, 5, 6),
"api": 31847, "api": 31847,
"location": "File > Export > Skeletal Mesh/Animation Data (.psk/.psa)", "location": "File > Export > Skeletal Mesh/Animation Data (.psk/.psa)",
...@@ -109,6 +109,7 @@ SIZE_VQUATANIMKEY = 32 ...@@ -109,6 +109,7 @@ SIZE_VQUATANIMKEY = 32
SIZE_VVERTEX = 16 SIZE_VVERTEX = 16
SIZE_VPOINT = 12 SIZE_VPOINT = 12
SIZE_VTRIANGLE = 12 SIZE_VTRIANGLE = 12
MaterialName = []
######################################################################## ########################################################################
# Generic Object->Integer mapping # Generic Object->Integer mapping
...@@ -452,7 +453,8 @@ class PSKFile: ...@@ -452,7 +453,8 @@ class PSKFile:
return self.Materials.Data[mat_index] return self.Materials.Data[mat_index]
else: else:
m = VMaterial() m = VMaterial()
m.MaterialName = "Mat%i" % mat_index # modified by VendorX
m.MaterialName = MaterialName[mat_index]
self.AddMaterial(m) self.AddMaterial(m)
return m return m
...@@ -680,10 +682,11 @@ def BoneIndexArmature(blender_armature): ...@@ -680,10 +682,11 @@ def BoneIndexArmature(blender_armature):
#BBCount += 1 #BBCount += 1
break break
bDeleteMergeMesh = False
# Actual object parsing functions # Actual object parsing functions
def parse_meshes(blender_meshes, psk_file): def parse_meshes(blender_meshes, psk_file):
#this is use to call the bone name and the index array for group index matches #this is use to call the bone name and the index array for group index matches
global bonedata global bonedata,bDeleteMergeMesh
#print("BONE DATA",len(bonedata)) #print("BONE DATA",len(bonedata))
print ("----- parsing meshes -----") print ("----- parsing meshes -----")
print("Number of Object Meshes:",len(blender_meshes)) print("Number of Object Meshes:",len(blender_meshes))
...@@ -694,7 +697,16 @@ def parse_meshes(blender_meshes, psk_file): ...@@ -694,7 +697,16 @@ def parse_meshes(blender_meshes, psk_file):
print("Mesh Name:",current_obj.name) print("Mesh Name:",current_obj.name)
current_mesh = current_obj.data current_mesh = current_obj.data
#if len(current_obj.materials) > 0: #collect a list of the material names
if len(current_obj.material_slots) > 0:
counter = 0
while counter < len(current_obj.material_slots):
MaterialName.append(current_obj.material_slots[counter].name)
print("Material Name:",current_obj.material_slots[counter].name)
#create the current material
psk_file.GetMatByIndex(counter)
#print("materials: ",MaterialName[counter])
counter += 1
# object_mat = current_obj.materials[0] # object_mat = current_obj.materials[0]
object_material_index = current_obj.active_material_index object_material_index = current_obj.active_material_index
...@@ -925,10 +937,16 @@ def parse_meshes(blender_meshes, psk_file): ...@@ -925,10 +937,16 @@ def parse_meshes(blender_meshes, psk_file):
psk_file.VertexGroups[bonegroup.bone] = vert_list psk_file.VertexGroups[bonegroup.bone] = vert_list
#unrealtriangulatebool #this will remove the mesh from the scene #unrealtriangulatebool #this will remove the mesh from the scene
if (bpy.context.scene.unrealtriangulatebool == True): if (bpy.context.scene.unrealtriangulatebool == True)or (bDeleteMergeMesh == True):
if bDeleteMergeMesh == True:
print("Removing merge mesh.")
print("Remove tmp Mesh [ " ,current_obj.name, " ] from scene >" ,(bpy.context.scene.unrealtriangulatebool )) print("Remove tmp Mesh [ " ,current_obj.name, " ] from scene >" ,(bpy.context.scene.unrealtriangulatebool ))
bpy.ops.object.mode_set(mode='OBJECT') # set it in object bpy.ops.object.mode_set(mode='OBJECT') # set it in object
bpy.context.scene.objects.unlink(current_obj) bpy.context.scene.objects.unlink(current_obj)
#if bDeleteMergeMesh == True:
#print("Remove merge Mesh [ " ,current_obj.name, " ] from scene")
#bpy.ops.object.mode_set(mode='OBJECT') # set it in object
#bpy.context.scene.objects.unlink(current_obj)
def make_fquat(bquat): def make_fquat(bquat):
quat = FQuat() quat = FQuat()
...@@ -1471,11 +1489,39 @@ def parse_animation(blender_scene, blender_armatures, psa_file): ...@@ -1471,11 +1489,39 @@ def parse_animation(blender_scene, blender_armatures, psa_file):
psa_file.AddAnimation(anim) psa_file.AddAnimation(anim)
print("==== Finish Action Build(s) ====") print("==== Finish Action Build(s) ====")
exportmessage = "Export Finish" exportmessage = "Export Finish"
def meshmerge(selectedobjects):
bpy.ops.object.mode_set(mode='OBJECT')
cloneobjects = []
if len(selectedobjects) > 1:
print("selectedobjects:",len(selectedobjects))
count = 0 #reset count
for count in range(len( selectedobjects)):
print("Index:",count)
if selectedobjects[count] != None:
me_da = selectedobjects[count].data.copy() #copy data
me_ob = selectedobjects[count].copy() #copy object
#note two copy two types else it will use the current data or mesh
me_ob.data = me_da
bpy.context.scene.objects.link(me_ob)#link the object to the scene #current object location
print("clone object",me_ob.name)
cloneobjects.append(me_ob)
#bpy.ops.object.mode_set(mode='OBJECT')
for i in bpy.data.objects: i.select = False #deselect all objects
count = 0 #reset count
#bpy.ops.object.mode_set(mode='OBJECT')
for count in range(len( cloneobjects)):
if count == 0:
bpy.context.scene.objects.active = cloneobjects[count]
print("Set Active Object:",cloneobjects[count].name)
cloneobjects[count].select = True
bpy.ops.object.join()
return cloneobjects[0]
def fs_callback(filename, context): def fs_callback(filename, context):
#this deal with repeat export and the reset settings #this deal with repeat export and the reset settings
global bonedata, BBCount, nbone, exportmessage global bonedata, BBCount, nbone, exportmessage,bDeleteMergeMesh
bonedata = []#clear array bonedata = []#clear array
BBCount = 0 BBCount = 0
nbone = 0 nbone = 0
...@@ -1524,16 +1570,47 @@ def fs_callback(filename, context): ...@@ -1524,16 +1570,47 @@ def fs_callback(filename, context):
print("Mesh Count:",len(blender_meshes)," Armature Count:",len(blender_armature)) print("Mesh Count:",len(blender_meshes)," Armature Count:",len(blender_armature))
print("====================================") print("====================================")
print("Checking Mesh Condtion(s):") print("Checking Mesh Condtion(s):")
#if there 1 mesh in scene add to the array
if len(blender_meshes) == 1: if len(blender_meshes) == 1:
print(" - One Mesh Scene") 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): elif (len(blender_meshes) > 1) and (len(selectmesh) == 1):
blender_meshes = [] blender_meshes = []
blender_meshes.append(selectmesh[0]) blender_meshes.append(selectmesh[0])
print(" - One Mesh [Select]") print(" - One Mesh [Select]")
elif (len(blender_meshes) > 1) and (len(selectmesh) >= 1):
#code build check for merge mesh before ops
print("More than one mesh is selected!")
centermesh = []
notcentermesh = []
countm = 0
for countm in range(len(selectmesh)):
#selectmesh[]
if selectmesh[countm].location.x == 0 and selectmesh[countm].location.y == 0 and selectmesh[countm].location.z == 0:
centermesh.append(selectmesh[countm])
else:
notcentermesh.append(selectmesh[countm])
if len(centermesh) > 0:
print("center object found")
blender_meshes = []
selectmesh = []
countm = 0
for countm in range(len(centermesh)):
selectmesh.append(centermesh[countm])
for countm in range(len(notcentermesh)):
selectmesh.append(notcentermesh[countm])
blender_meshes.append(meshmerge(selectmesh))
bDeleteMergeMesh = True
else:
bDeleteMergeMesh = False
bmesh = False
print("center object not found")
else: else:
print(" - Too Many Meshes!") print(" - Too Many Meshes!")
print(" - Select One Mesh Object!") print(" - Select One Mesh Object!")
bmesh = False bmesh = False
bDeleteMergeMesh = False
print("====================================") print("====================================")
print("Checking Armature Condtion(s):") print("Checking Armature Condtion(s):")
if len(blender_armature) == 1: if len(blender_armature) == 1:
...@@ -1546,7 +1623,7 @@ def fs_callback(filename, context): ...@@ -1546,7 +1623,7 @@ def fs_callback(filename, context):
barmature = False barmature = False
bMeshScale = True bMeshScale = True
bMeshCenter = True bMeshCenter = True
if blender_meshes[0] !=None: if len(blender_meshes) > 0:
if blender_meshes[0].scale.x == 1 and blender_meshes[0].scale.y == 1 and blender_meshes[0].scale.z == 1: if blender_meshes[0].scale.x == 1 and blender_meshes[0].scale.y == 1 and blender_meshes[0].scale.z == 1:
#print("Okay") #print("Okay")
bMeshScale = True bMeshScale = True
...@@ -1559,6 +1636,8 @@ def fs_callback(filename, context): ...@@ -1559,6 +1636,8 @@ def fs_callback(filename, context):
else: else:
print("Error, Mesh Object not center.",blender_meshes[0].location) print("Error, Mesh Object not center.",blender_meshes[0].location)
bMeshCenter = False bMeshCenter = False
else:
bmesh = False
bArmatureScale = True bArmatureScale = True
bArmatureCenter = True bArmatureCenter = True
if blender_armature[0] !=None: if blender_armature[0] !=None:
......
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