Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bl_info = {
- "name": "Aren World Exporter",
- "description": "Exports Aren World Information",
- "author": "James Rakos",
- "version": (1, 0),
- "blender": (2, 61, 0),
- "location": "Have to use the spacebar search thingy...",
- "warning": "",
- "wiki_url": "",
- "tracker_url": "",
- "category": "Import-Export"}
- import bpy
- import os
- from bpy_extras.io_utils import ExportHelper
- def setupFile(file):
- file.write("Exporter: v1.0\n")
- file.write("<worldtile> world1\n")
- return{'RUNNING_MODAL'}
- def endFile(file):
- file.write("</worldtile>\n")
- file.write("<EOF>")
- return{'RUNNING_MODAL'}
- def writeModel(file, object, index):
- writeSpaces(file, index)
- file.write("<model> " + str(object.name) + "\n")
- writeLocation(file, index + 1, object.location)
- writeTexture(file, object, index + 1)
- writeSpaces(file, index)
- file.write("</model>\n")
- return{'RUNNING_MODAL'}
- def writeTexture(file, object, index):
- writeSpaces(file, index)
- file.write("<textures>\n")
- writeSpaces(file, index + 1)
- file.write("<diffuse> " + str(object.data.uv_textures[0].data[0].image.name) + "\n")
- writeSpaces(file, index)
- file.write("</textures>\n")
- return{'RUNNING_MODAL'}
- def writeSpaces(file, index):
- for i in range(index):
- file.write(" ")
- return{'RUNNING_MODAL'}
- def writeLocation(file, index, location):
- writeSpaces(file, index)
- file.write("<location>\n")
- writeSpaces(file, index + 1)
- file.write("<x,y,z> " + str(tuple(location)) + "\n")
- writeSpaces(file, index)
- file.write("</location>\n")
- return{'RUNNING_MODAL'}
- class exportData(bpy.types.Operator, ExportHelper):
- bl_idname = "export.aren_export"
- bl_label = "Export To Aren"
- filename_ext = ".awf"
- index = 0;
- def execute(self, context):
- try:
- file = open(self.filepath, 'w')
- except:
- return{'CANCELED'}
- _mkdir(self.filepath[:-4] + "\\models\\")
- setupFile(file)
- file.write(" <models>\n")
- index = 2
- for o in bpy.context.scene.objects:
- writeModel(file, o, index)
- o.select = True
- path = os.path.join(self.filepath[:-4], "models", str(o.name)) + ".fbx"
- file.write(path)
- bpy.ops.export_scene.fbx(filepath = path, use_selection = True)
- o.select = False
- endFile(file)
- return{'FINISHED'}
- def invoke(self, context, event):
- context.window_manager.fileselect_add(self)
- return{'RUNNING_MODAL'}
- def _mkdir(newdir):
- """works the way a good mkdir should :)
- - already exists, silently complete
- - regular file in the way, raise an exception
- - parent directory(ies) does not exist, make them as well
- """
- if os.path.isdir(newdir):
- pass
- elif os.path.isfile(newdir):
- raise OSError("a file with the same name as the desired " \
- "dir, '%s', already exists." % newdir)
- else:
- head, tail = os.path.split(newdir)
- if head and not os.path.isdir(head):
- _mkdir(head)
- #print ("_mkdir %s" % repr(newdir))
- if tail:
- os.mkdir(newdir)
- def register():
- bpy.utils.register_module(__name__)
- def unregister():
- bpy.utils.unregister_module(__name__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement