View difference between Paste ID: cXuEKCPG and x9qtpjV7
SHOW: | | - or go back to the newest paste.
1
bl_info = {
2
    "name": "Aren World Exporter",
3
    "description": "Exports Aren World Information",
4
    "author": "James Rakos",
5
    "version": (1, 0),
6
    "blender": (2, 61, 0),
7
    "location": "Have to use the spacebar search thingy...",
8
    "warning": "",
9
    "wiki_url": "",
10
    "tracker_url": "",
11
    "category": "Import-Export"}
12
13
import bpy
14
import os
15
from bpy_extras.io_utils import ExportHelper
16
17
def setupFile(file):
18
    file.write("Exporter: v1.0\n")
19
    file.write("<worldtile> world1\n")
20
    return{'RUNNING_MODAL'}
21
22
def endFile(file):
23
    file.write("</worldtile>\n")
24
    file.write("<EOF>")
25
    return{'RUNNING_MODAL'}
26
27
def writeModel(file, object, index):
28
    writeSpaces(file, index)
29
    file.write("<model> " + str(object.name) + "\n")
30
    writeLocation(file, index + 1, object.location)
31
    writeTexture(file, object, index + 1)
32
    writeSpaces(file, index)
33
    file.write("</model>\n")
34
    return{'RUNNING_MODAL'}
35
36
def writeTexture(file, object, index):
37
    writeSpaces(file, index)
38
    file.write("<textures>\n")
39
    writeSpaces(file, index + 1)
40
    file.write("<diffuse> " + str(object.data.uv_textures[0].data[0].image.name) + "\n")
41
    writeSpaces(file, index)
42
    file.write("</textures>\n")
43
    return{'RUNNING_MODAL'}
44
45
def writeSpaces(file, index):
46
    for i in range(index):
47
        file.write(" ")
48
    return{'RUNNING_MODAL'}
49
50
def writeLocation(file, index, location):
51
    writeSpaces(file, index)
52
    file.write("<location>\n")
53
    writeSpaces(file, index + 1)
54
    file.write("<x,y,z> " + str(tuple(location)) + "\n")
55
    writeSpaces(file, index)
56
    file.write("</location>\n")
57
    return{'RUNNING_MODAL'}
58
59
class exportData(bpy.types.Operator, ExportHelper):
60
    bl_idname = "export.aren_export"
61
    bl_label = "Export To Aren"
62
63
    filename_ext = ".awf"
64
65
    index = 0;
66
67
    def execute(self, context):
68
        try:
69
            file = open(self.filepath, 'w')
70
        except:
71
            return{'CANCELED'}
72
        
73
        _mkdir(self.filepath[:-4] + "\\models\\")
74
        
75
        setupFile(file)
76
        
77
        file.write(" <models>\n")
78
        
79
        index = 2
80
        
81
        for o in bpy.context.scene.objects:
82
            writeModel(file, o, index)
83
            o.select = True
84
            path = os.path.join(self.filepath[:-4], "models", str(o.name)) + ".fbx"
85
            #path = path.replace("\\", "\\\\")
86
            file.write(path)
87
            bpy.ops.export_scene.fbx(filepath = path, use_selection = True)
88
            o.select = False
89
        
90
        endFile(file)
91
        
92
        return{'FINISHED'}
93
94
    def invoke(self, context, event):
95
        context.window_manager.fileselect_add(self)
96
        return{'RUNNING_MODAL'}
97
98
    def _mkdir(newdir):
99
        """works the way a good mkdir should :)
100
        - already exists, silently complete
101
        - regular file in the way, raise an exception
102
        - parent directory(ies) does not exist, make them as well
103
        """
104
        if os.path.isdir(newdir):
105
            pass
106
        elif os.path.isfile(newdir):
107
            raise OSError("a file with the same name as the desired " \
108
                          "dir, '%s', already exists." % newdir)
109
        else:
110
            head, tail = os.path.split(newdir)
111
            if head and not os.path.isdir(head):
112
                _mkdir(head)
113
            #print ("_mkdir %s" % repr(newdir))
114
            if tail:
115
                os.mkdir(newdir)
116
117
def register():
118
    bpy.utils.register_module(__name__)
119
120
def unregister():
121
    bpy.utils.unregister_module(__name__)