Welcome to mirror list, hosted at ThFree Co, Russian Federation.

__init__.py « io_scene_collada - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf9a15f81862335e780d5c836c3f6b2504b9e7d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

bl_info = {
    "name": "Collada",
    "author": "Gaia Clary",
    "version": (1, 0),
    "blender": (2, 7, 8),
    "location": "File > Import/Export > Blender Collada",
    "description": "Import/Export Collada (Blender default Implementation)",
    "warning": "",
    "wiki_url": "http://wiki.blender.org/index.php/Dev:2.5/Source/Architecture/COLLADA",
    "tracker_url": "http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse",
    "support": 'OFFICIAL',
    "category": "Import-Export",
}

import bpy
import os
import shutil

from bpy_extras.io_utils import (
        ImportHelper,
        ExportHelper
        )
from bpy.props import (
        StringProperty,
        BoolProperty,
        EnumProperty,
        IntProperty
        )

# Text strings

import_units_description = \
'''Specify the measurement units to be used in Blender:

- Disabled: match import to Blender's current Unit settings,
- Enabled: use the settings from the Imported scene'''
        
class ImportCollada(bpy.types.Operator, ImportHelper):
    '''Import as Collada-1.4.1'''
    bl_idname = "wm.collada_import"
    bl_label  = "Import Collada"
    bl_options = {'UNDO'}

    # ImportHelper mixin class uses this
    filename_ext = ".dae"

    filter_glob = StringProperty(
            default="*.dae",
            options={'HIDDEN'},
            )

    # Import data options

    import_units = BoolProperty(
            name        = "Import Units",
            description = import_units_description,
            default     = False
            )

    # Armature Options

    fix_orientation = BoolProperty(
            name        = "Fix Leaf Bones",
            description = "Fix Orientation of Leaf Bones (Collada does only support Joints)",
            default     = False
            )

    find_chains = BoolProperty(
            name        = "Find Bone Chains",
            description = "Find best matching Bone Chains and ensure bones in chain are connected",
            default     = False
            )

    auto_connect = BoolProperty(
            name        = "Auto Connect",
            description = "Set use_connect for parent bones which have exactly one child bone",
            default     = False
            )

    min_chain_length = IntProperty(
            name        = "Minimum Chain Length",
            description = "When searching Bone Chains disregard chains of length below this value",
            min         = 0,
            default     = 0
            )

    @classmethod
    def poll(cls, context):
        return True

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        box.label("Import Data Options", icon='MESH_DATA')
        col = box.column()
        col.prop(self, 'import_units')
        
        box = layout.box()
        box.label("Armature Options", icon='ARMATURE_DATA')
        col = box.column()
        col.prop(self, 'fix_orientation')
        col.prop(self, 'find_chains')
        col.prop(self, 'auto_connect')
        col.prop(self, 'min_chain_length')
        
        
    def execute(self, context):
        return bpy.ops.wm.collada_importo(
            filepath         = self.filepath,
            import_units     = self.import_units,
            fix_orientation  = self.fix_orientation,
            find_chains      = self.find_chains,
            auto_connect     = self.auto_connect,
            min_chain_length = self.min_chain_length
        )
        


class ExportCollada(bpy.types.Operator, ExportHelper):
    '''Export as Collada-1.4.1'''
    bl_idname = "wm.collada_export"  # this is important since its how bpy.ops.export.some_data is constructed
    bl_label  = "Export Collada"
    bl_options = {'UNDO', 'PRESET'}

    # ExportHelper mixin class uses this
    filename_ext = ".dae"

    filter_glob = StringProperty(
            default="*.dae",
            options={'HIDDEN'},
            )

    # Export Data Options
    export_mesh_type = 0   #not used, only here to keep old presets compatible
    apply_modifiers = BoolProperty(
            name="Apply Modifiers",
            description="Apply modifiers to exported mesh (non destructive)",
            default=True
            )
    
    export_mesh_type_selection = EnumProperty(
            name="Apply Modifiers",
            items=(
                   ('view', "View",     "Apply modifier's View settings"),
                   ('render', "Render", "Apply modifier's Render settings"),
                   ),
            default = 'view'
            )

    selected = BoolProperty(
            name        = "Selection Only",
            description = "Export only selected elements",
            default     = True
            )

    include_children = BoolProperty(
            name        = "Include Children",
            description = "Export all children of selected objects (even if not selected)",
            default     = False
            )

    include_armatures = BoolProperty(
            name        = "Include Armatures",
            description = "Export related armatures (even if not selected)",
            default     = False
            )

    include_shapekeys = BoolProperty(
            name        = "Include Shape Keys",
            description = "Export all Shape Keys from Mesh Objects",
            default     = True
            )

    # Texture Options

    active_uv_only = BoolProperty(
            name        = "Only Selected UV Map",
            description = "Export only the selected UV Map",
            default     = False
            )

    include_uv_textures = BoolProperty(
            name        = "Include UV Textures",
            description = "Export textures assigned to the object UV Maps",
            default     = False
            )

    include_material_textures = BoolProperty(
            name        = "Include Material Textures",
            description = "Export textures assigned to the object Materials",
            default     = False
            )

    use_texture_copies = BoolProperty(
            name        = "Copy",
            description = "Copy textures to same folder where the .dae file is exported",
            default     = True
            )

    #Armature Options

    deform_bones_only = BoolProperty(
            name        = "Deform Bones only",
            description = "Only export deforming bones with armatures",
            default     = False
            )

    open_sim = BoolProperty(
            name        = "Export to SL/OpenSim",
            description = "Compatibility mode for SL, OpenSim and other compatible online worlds",
            default     = False
            )

    # Collada Options

    triangulate = BoolProperty(
            name        = "Triangulate",
            description = "Export Polygons (Quads & NGons) as Triangles",
            default     = False
            )

    use_object_instantiation = BoolProperty(
            name        = "Use Object Instances",
            description = "Instantiate multiple Objects from same Data",
            default     = False
            )

    use_blender_profile = BoolProperty(
            name        = "Use Blender Profile",
            description = "Export additional Blender specific information (for material, shaders, bones, etc.)",
            default     = False
            )

    export_transformation_type_selection = EnumProperty(
            name        = "Transformation Type",
            items=(
                   ('transrotloc', "View",   "use <translate>, <rotate>, <scale> to write transformations"),
                   ('matrix',      "Matrix", "use <matrix> to write transformations"),
                   ),
            default = 'matrix',
            description="Transformation type for translation, scale and rotation"
            )

    sort_by_name = BoolProperty(
            name        = "Sort by Object name",
            description = "Sort exported data by Object name",
            default     = False
            )

    @classmethod
    def poll(cls, context):
        return True

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        box.label("Export Data Options", icon='MESH_DATA')

        col    = box.column()
        split  = col.split(percentage=0.6)
        split.prop(self, 'apply_modifiers')
        col=split.column()
        col.prop(self, 'export_mesh_type_selection', text='')
        col.enabled = self.apply_modifiers

        box.separator()

        col=box.column()
        col.prop(self, 'selected')
        col.prop(self, 'include_children')
        col.prop(self, 'include_armatures')
        col.prop(self, 'include_shapekeys')

        box = layout.box()
        box.label("Texture Options", icon='TEXTURE_DATA')

        col    = box.column()
        col.prop(self, 'active_uv_only')
        col.prop(self, 'include_uv_textures')
        col.prop(self, 'include_material_textures')
        col    = box.column()
        col.prop(self, 'use_texture_copies')
        
        box = layout.box()
        box.label("Armature Options", icon='ARMATURE_DATA')
        
        col    = box.column()
        col.prop(self, 'deform_bones_only')
        col.prop(self, 'open_sim')
        
        box = layout.box()
        box.label("Collada Options", icon='MODIFIER')
        
        col    = box.column()
        col.prop(self, 'triangulate')
        col.prop(self, 'use_object_instantiation')
        col.prop(self, 'use_blender_profile')
        split  = col.split(percentage=0.6)
        split.label('Transformation Type')
        split.prop(self, 'export_transformation_type_selection', text='')
        col.prop(self, 'sort_by_name')

    def execute(self, context):
        return bpy.ops.wm.collada_exporto(
            filepath                             = self.filepath,
            selected                             = self.selected,
            apply_modifiers                      = self.apply_modifiers,
            open_sim                             = self.open_sim,
            export_mesh_type_selection           = self.export_mesh_type_selection,
            include_children                     = self.include_children,
            include_armatures                    = self.include_armatures,
            include_shapekeys                    = self.include_shapekeys,
            active_uv_only                       = self.active_uv_only,
            include_uv_textures                  = self.include_uv_textures,
            include_material_textures            = self.include_material_textures,
            use_texture_copies                   = self.use_texture_copies,
            deform_bones_only                    = self.deform_bones_only,
            triangulate                          = self.triangulate,
            use_object_instantiation             = self.use_object_instantiation,
            use_blender_profile                  = self.use_blender_profile,
            export_transformation_type_selection = self.export_transformation_type_selection,
            sort_by_name                         = self.sort_by_name
        )

def menu_func_import(self, context):
    self.layout.operator(ImportCollada.bl_idname, text="Collada (.dae)")

    
def menu_func_export(self, context):
    self.layout.operator(ExportCollada.bl_idname, text="Collada (.dae)")

def copydir(src, dst):
    for root, dirs, files in os.walk(src):
        srcdir=root
        folder=srcdir[len(src):]
        dstdir=dst+folder
        if not os.path.exists(dstdir):
            os.makedirs(dstdir)
            
        for file in files:
            dstfile = os.path.join(dstdir,file)
            srcfile = os.path.join(srcdir,file)
            shutil.copyfile(srcfile, dstfile)

def register():
    bpy.utils.register_module(__name__)

    bpy.types.INFO_MT_file_export.prepend(menu_func_export)
    bpy.types.INFO_MT_file_import.prepend(menu_func_import)

    addon_home       = os.path.dirname(__file__)
    addon_presets    = os.path.join(addon_home, "presets")
    blender_scripts  = bpy.utils.user_resource('SCRIPTS', "presets")
    destdir          = os.path.join(blender_scripts, __name__)
    copydir(addon_presets, destdir)


def unregister():
    bpy.utils.unregister_module(__name__)

    bpy.types.INFO_MT_file_import.remove(menu_func_import)
    bpy.types.INFO_MT_file_export.remove(menu_func_export)

if __name__ == "__main__":
    register()