align columns (for multi-drag)
[blender-addons.git] / io_scene_x3d / __init__.py
blob7bda64abde15d98ec10932cb2134cf77b14f4684
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8-80 compliant>
21 bl_info = {
22 "name": "Web3D X3D/VRML2 format",
23 "author": "Campbell Barton, Bart",
24 "blender": (2, 57, 0),
25 "location": "File > Import-Export",
26 "description": "Import-Export X3D, Import VRML2",
27 "warning": "",
28 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
29 "Scripts/Import-Export/Web3D",
30 "support": 'OFFICIAL',
31 "category": "Import-Export"}
33 if "bpy" in locals():
34 import imp
35 if "import_x3d" in locals():
36 imp.reload(import_x3d)
37 if "export_x3d" in locals():
38 imp.reload(export_x3d)
40 import bpy
41 from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty
42 from bpy_extras.io_utils import (ImportHelper,
43 ExportHelper,
44 axis_conversion,
45 path_reference_mode,
49 class ImportX3D(bpy.types.Operator, ImportHelper):
50 """Import an X3D or VRML2 file"""
51 bl_idname = "import_scene.x3d"
52 bl_label = "Import X3D/VRML2"
53 bl_options = {'PRESET', 'UNDO'}
55 filename_ext = ".x3d"
56 filter_glob = StringProperty(default="*.x3d;*.wrl", options={'HIDDEN'})
58 axis_forward = EnumProperty(
59 name="Forward",
60 items=(('X', "X Forward", ""),
61 ('Y', "Y Forward", ""),
62 ('Z', "Z Forward", ""),
63 ('-X', "-X Forward", ""),
64 ('-Y', "-Y Forward", ""),
65 ('-Z', "-Z Forward", ""),
67 default='Z',
70 axis_up = EnumProperty(
71 name="Up",
72 items=(('X', "X Up", ""),
73 ('Y', "Y Up", ""),
74 ('Z', "Z Up", ""),
75 ('-X', "-X Up", ""),
76 ('-Y', "-Y Up", ""),
77 ('-Z', "-Z Up", ""),
79 default='Y',
82 def execute(self, context):
83 from . import import_x3d
85 keywords = self.as_keywords(ignore=("axis_forward",
86 "axis_up",
87 "filter_glob",
89 global_matrix = axis_conversion(from_forward=self.axis_forward,
90 from_up=self.axis_up,
91 ).to_4x4()
92 keywords["global_matrix"] = global_matrix
94 return import_x3d.load(self, context, **keywords)
97 class ExportX3D(bpy.types.Operator, ExportHelper):
98 """Export selection to Extensible 3D file (.x3d)"""
99 bl_idname = "export_scene.x3d"
100 bl_label = 'Export X3D'
101 bl_options = {'PRESET'}
103 filename_ext = ".x3d"
104 filter_glob = StringProperty(default="*.x3d", options={'HIDDEN'})
106 use_selection = BoolProperty(
107 name="Selection Only",
108 description="Export selected objects only",
109 default=False,
111 use_mesh_modifiers = BoolProperty(
112 name="Apply Modifiers",
113 description="Use transformed mesh data from each object",
114 default=True,
116 use_triangulate = BoolProperty(
117 name="Triangulate",
118 description="Write quads into 'IndexedTriangleSet'",
119 default=False,
121 use_normals = BoolProperty(
122 name="Normals",
123 description="Write normals with geometry",
124 default=False,
126 use_compress = BoolProperty(
127 name="Compress",
128 description="Compress the exported file",
129 default=False,
131 use_hierarchy = BoolProperty(
132 name="Hierarchy",
133 description="Export parent child relationships",
134 default=True,
136 name_decorations = BoolProperty(
137 name="Name decorations",
138 description=("Add prefixes to the names of exported nodes to "
139 "indicate their type"),
140 default=True,
142 use_h3d = BoolProperty(
143 name="H3D Extensions",
144 description="Export shaders for H3D",
145 default=False,
148 axis_forward = EnumProperty(
149 name="Forward",
150 items=(('X', "X Forward", ""),
151 ('Y', "Y Forward", ""),
152 ('Z', "Z Forward", ""),
153 ('-X', "-X Forward", ""),
154 ('-Y', "-Y Forward", ""),
155 ('-Z', "-Z Forward", ""),
157 default='Z',
159 axis_up = EnumProperty(
160 name="Up",
161 items=(('X', "X Up", ""),
162 ('Y', "Y Up", ""),
163 ('Z', "Z Up", ""),
164 ('-X', "-X Up", ""),
165 ('-Y', "-Y Up", ""),
166 ('-Z', "-Z Up", ""),
168 default='Y',
170 global_scale = FloatProperty(
171 name="Scale",
172 min=0.01, max=1000.0,
173 default=1.0,
176 path_mode = path_reference_mode
178 def execute(self, context):
179 from . import export_x3d
181 from mathutils import Matrix
183 keywords = self.as_keywords(ignore=("axis_forward",
184 "axis_up",
185 "global_scale",
186 "check_existing",
187 "filter_glob",
189 global_matrix = axis_conversion(to_forward=self.axis_forward,
190 to_up=self.axis_up,
191 ).to_4x4() * Matrix.Scale(self.global_scale, 4)
192 keywords["global_matrix"] = global_matrix
194 return export_x3d.save(self, context, **keywords)
197 def menu_func_import(self, context):
198 self.layout.operator(ImportX3D.bl_idname,
199 text="X3D Extensible 3D (.x3d/.wrl)")
202 def menu_func_export(self, context):
203 self.layout.operator(ExportX3D.bl_idname,
204 text="X3D Extensible 3D (.x3d)")
207 def register():
208 bpy.utils.register_module(__name__)
210 bpy.types.INFO_MT_file_import.append(menu_func_import)
211 bpy.types.INFO_MT_file_export.append(menu_func_export)
214 def unregister():
215 bpy.utils.unregister_module(__name__)
217 bpy.types.INFO_MT_file_import.remove(menu_func_import)
218 bpy.types.INFO_MT_file_export.remove(menu_func_export)
220 # NOTES
221 # - blender version is hardcoded
223 if __name__ == "__main__":
224 register()