View difference between Paste ID: B2U0DAr8 and cXuEKCPG
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("\\", "\\\\")
85+
86
            bpy.ops.export_scene.fbx(filepath = path, use_selection = True)
87
            o.select = False
88
        
89
        endFile(file)
90
        
91
        return{'FINISHED'}
92
93
    def invoke(self, context, event):
94
        context.window_manager.fileselect_add(self)
95
        return{'RUNNING_MODAL'}
96
97
    def _mkdir(newdir):
98
        """works the way a good mkdir should :)
99
        - already exists, silently complete
100
        - regular file in the way, raise an exception
101
        - parent directory(ies) does not exist, make them as well
102
        """
103
        if os.path.isdir(newdir):
104
            pass
105
        elif os.path.isfile(newdir):
106
            raise OSError("a file with the same name as the desired " \
107
                          "dir, '%s', already exists." % newdir)
108
        else:
109
            head, tail = os.path.split(newdir)
110
            if head and not os.path.isdir(head):
111
                _mkdir(head)
112
            #print ("_mkdir %s" % repr(newdir))
113
            if tail:
114
                os.mkdir(newdir)
115
116
def register():
117
    bpy.utils.register_module(__name__)
118
119
def unregister():
120
    bpy.utils.unregister_module(__name__)