Skip to content

Commit

Permalink
[#6] Code cleaning, veriable renames.
Browse files Browse the repository at this point in the history
  • Loading branch information
travnick committed Jul 20, 2013
1 parent 020ff35 commit d946fee
Showing 1 changed file with 31 additions and 46 deletions.
77 changes: 31 additions & 46 deletions io_export_cryblend/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def fixed_writexml(self, writer, indent="", addindent="", newl=""):

# end http://ronrothman.com/
# public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/
def write(config, doc, fname, exe):
def write_to_file(config, doc, fname, exe):
s = doc
s = doc.toprettyxml(indent=" ")
f = open(fname, "w")
Expand Down Expand Up @@ -343,15 +343,15 @@ def execute(self, config, context, exe):
bpy.data.objects[i.name].select = True
cbPrint("Bone Geometry found: " + i.name)

col = self.__doc.createElement('collada') # Top level element
root_node = self.__doc.createElement('collada') # Top level element
# asset
# Attributes are x=y values inside a tag
col.setAttribute("xmlns",
root_node.setAttribute("xmlns",
"http://www.collada.org/2005/11/COLLADASchema")
col.setAttribute("version", "1.4.1")
self.__doc.appendChild(col)
root_node.setAttribute("version", "1.4.1")
self.__doc.appendChild(root_node)
asset = self.__doc.createElement("asset")
col.appendChild(asset)
root_node.appendChild(asset)
contrib = self.__doc.createElement("contributor")
asset.appendChild(contrib)
auth = self.__doc.createElement("author")
Expand Down Expand Up @@ -380,9 +380,9 @@ def execute(self, config, context, exe):
# end asset
# just here for future use
libcam = self.__doc.createElement("library_cameras")
col.appendChild(libcam)
root_node.appendChild(libcam)
liblights = self.__doc.createElement("library_lights")
col.appendChild(liblights)
root_node.appendChild(liblights)
# just here for future use
# library images
libima = self.__doc.createElement("library_images")
Expand All @@ -398,7 +398,7 @@ def execute(self, config, context, exe):
infrom.appendChild(fpath)
imaid.appendChild(infrom)
libima.appendChild(imaid)
col.appendChild(libima)
root_node.appendChild(libima)
# end library images
# library effects
libeff = self.__doc.createElement("library_effects")
Expand Down Expand Up @@ -592,7 +592,7 @@ def execute(self, config, context, exe):
extra.appendChild(techn)
effid.appendChild(extra)
libeff.appendChild(effid)
col.appendChild(libeff)
root_node.appendChild(libeff)
# end library effects
# library materials
libmat = self.__doc.createElement("library_materials")
Expand All @@ -604,7 +604,7 @@ def execute(self, config, context, exe):
ie.setAttribute("url", "#%s_fx" % (mat.name))
matt.appendChild(ie)
libmat.appendChild(matt)
col.appendChild(libmat)
root_node.appendChild(libmat)
# end library materials
# library geometries
libgeo = self.__doc.createElement("library_geometries")
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def va(index, color):
geo.appendChild(me)
libgeo.appendChild(geo)
# bpy.data.meshes.remove(mesh)
col.appendChild(libgeo)
root_node.appendChild(libgeo)

# Duo Oratar
# Remove the boneGeometry from the selection so we can get on
Expand All @@ -1163,7 +1163,7 @@ def va(index, color):

self.__export_library_controllers(libcont)

col.appendChild(libcont)
root_node.appendChild(libcont)
# end library controllers aka skining info
# library_animations

Expand Down Expand Up @@ -1430,34 +1430,19 @@ def va(index, color):

if asw == 1:
libanmcl.appendChild(anicl)
col.appendChild(libanmcl)
col.appendChild(libanm)
asw = 0
ande2 = 0
root_node.appendChild(libanmcl)
root_node.appendChild(libanm)

# library_visual_scenes
libvs = self.__doc.createElement("library_visual_scenes")
# cprop = ""
# try group for cryexportnode?----Yes It Is Good :)
# for item in bpy.context.blend_data.groups:

# test

# test
vs = self.__doc.createElement("visual_scene")
libvs.appendChild(vs)
col.appendChild(libvs)
self.__export_library_visual_scenes(config, i, vs)
# end library_visual_scenes
# <scene> nothing really changes here or rather it doesnt need to.
self.__export_library_visual_scenes(config, root_node)

# <scene> nothing really changes here or rather it doesnt need to.
scene = self.__doc.createElement("scene")
ivs = self.__doc.createElement("instance_visual_scene")
ivs.setAttribute("url", "#scene")
scene.appendChild(ivs)
col.appendChild(scene)
# <scene>
# write to file
write(config, self.__doc, filepath, exe)
root_node.appendChild(scene)

write_to_file(config, self.__doc, filepath, exe)

def GetObjectChildren(self, Parent):
return [Object for Object in Parent.children
Expand Down Expand Up @@ -3322,22 +3307,23 @@ def __matrix_to_string(self, matrix):
result += "{!s} ".format(col)
return result.strip()

def __export_library_visual_scenes(self, config, i, vs):
def __export_library_visual_scenes(self, config, root_node):
libvs = self.__doc.createElement("library_visual_scenes")
visual_scenes_node = self.__doc.createElement("visual_scene")
libvs.appendChild(visual_scenes_node)
root_node.appendChild(libvs)

# doesnt matter what name we have here as long as it is
# the same for <scene>
vs.setAttribute("id", "scene")
vs.setAttribute("name", "scene")
# the same for <scene>
visual_scenes_node.setAttribute("id", "scene")
visual_scenes_node.setAttribute("name", "scene")
for item in bpy.context.blend_data.groups:
# TODO: remove - unused code.
# mesh = i.data
# if (i.type == "MESH"):
# mat = mesh.materials[:]
if item:
ename = str(item.id_data.name)
node1 = self.__doc.createElement("node")
node1.setAttribute("id", "%s" % (ename))
node1.setIdAttribute('id')
vs.appendChild(node1)
visual_scenes_node.appendChild(node1)
objectl = []
objectl = item.objects
node1 = self.vsp(config, objectl, node1)
Expand All @@ -3363,7 +3349,6 @@ def __export_library_visual_scenes(self, config, i, vs):
node1.appendChild(ext1)



def get_relative_path(filepath):
[is_relative, filepath] = strip_blender_path_prefix(filepath)

Expand Down

0 comments on commit d946fee

Please sign in to comment.