Merge branch 'master' into blender2.8
[blender-addons.git] / io_scene_x3d / __init__.py
blobd5c555a106da2c126fa0cb17349755eab461fd3d
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, Bastien Montagne, Seva Alekseyev",
24 "version": (1, 2, 0),
25 "blender": (2, 76, 0),
26 "location": "File > Import-Export",
27 "description": "Import-Export X3D, Import VRML2",
28 "warning": "",
29 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Web3D",
30 "support": 'OFFICIAL',
31 "category": "Import-Export",
34 if "bpy" in locals():
35 import importlib
36 if "import_x3d" in locals():
37 importlib.reload(import_x3d)
38 if "export_x3d" in locals():
39 importlib.reload(export_x3d)
41 import bpy
42 from bpy.props import (
43 BoolProperty,
44 EnumProperty,
45 FloatProperty,
46 StringProperty,
48 from bpy_extras.io_utils import (
49 ImportHelper,
50 ExportHelper,
51 orientation_helper_factory,
52 axis_conversion,
53 path_reference_mode,
57 IOX3DOrientationHelper = orientation_helper_factory("IOX3DOrientationHelper", axis_forward='Z', axis_up='Y')
60 class ImportX3D(bpy.types.Operator, ImportHelper, IOX3DOrientationHelper):
61 """Import an X3D or VRML2 file"""
62 bl_idname = "import_scene.x3d"
63 bl_label = "Import X3D/VRML2"
64 bl_options = {'PRESET', 'UNDO'}
66 filename_ext = ".x3d"
67 filter_glob = StringProperty(default="*.x3d;*.wrl", options={'HIDDEN'})
69 def execute(self, context):
70 from . import import_x3d
72 keywords = self.as_keywords(ignore=("axis_forward",
73 "axis_up",
74 "filter_glob",
76 global_matrix = axis_conversion(from_forward=self.axis_forward,
77 from_up=self.axis_up,
78 ).to_4x4()
79 keywords["global_matrix"] = global_matrix
81 return import_x3d.load(context, **keywords)
84 class ExportX3D(bpy.types.Operator, ExportHelper, IOX3DOrientationHelper):
85 """Export selection to Extensible 3D file (.x3d)"""
86 bl_idname = "export_scene.x3d"
87 bl_label = 'Export X3D'
88 bl_options = {'PRESET'}
90 filename_ext = ".x3d"
91 filter_glob = StringProperty(default="*.x3d", options={'HIDDEN'})
93 use_selection = BoolProperty(
94 name="Selection Only",
95 description="Export selected objects only",
96 default=False,
98 use_mesh_modifiers = BoolProperty(
99 name="Apply Modifiers",
100 description="Use transformed mesh data from each object",
101 default=True,
103 use_triangulate = BoolProperty(
104 name="Triangulate",
105 description="Write quads into 'IndexedTriangleSet'",
106 default=False,
108 use_normals = BoolProperty(
109 name="Normals",
110 description="Write normals with geometry",
111 default=False,
113 use_compress = BoolProperty(
114 name="Compress",
115 description="Compress the exported file",
116 default=False,
118 use_hierarchy = BoolProperty(
119 name="Hierarchy",
120 description="Export parent child relationships",
121 default=True,
123 name_decorations = BoolProperty(
124 name="Name decorations",
125 description=("Add prefixes to the names of exported nodes to "
126 "indicate their type"),
127 default=True,
129 use_h3d = BoolProperty(
130 name="H3D Extensions",
131 description="Export shaders for H3D",
132 default=False,
135 global_scale = FloatProperty(
136 name="Scale",
137 min=0.01, max=1000.0,
138 default=1.0,
141 path_mode = path_reference_mode
143 def execute(self, context):
144 from . import export_x3d
146 from mathutils import Matrix
148 keywords = self.as_keywords(ignore=("axis_forward",
149 "axis_up",
150 "global_scale",
151 "check_existing",
152 "filter_glob",
154 global_matrix = axis_conversion(to_forward=self.axis_forward,
155 to_up=self.axis_up,
156 ).to_4x4() * Matrix.Scale(self.global_scale, 4)
157 keywords["global_matrix"] = global_matrix
159 return export_x3d.save(context, **keywords)
162 def menu_func_import(self, context):
163 self.layout.operator(ImportX3D.bl_idname,
164 text="X3D Extensible 3D (.x3d/.wrl)")
167 def menu_func_export(self, context):
168 self.layout.operator(ExportX3D.bl_idname,
169 text="X3D Extensible 3D (.x3d)")
172 def register():
173 bpy.utils.register_module(__name__)
175 bpy.types.INFO_MT_file_import.append(menu_func_import)
176 bpy.types.INFO_MT_file_export.append(menu_func_export)
179 def unregister():
180 bpy.utils.unregister_module(__name__)
182 bpy.types.INFO_MT_file_import.remove(menu_func_import)
183 bpy.types.INFO_MT_file_export.remove(menu_func_export)
185 # NOTES
186 # - blender version is hardcoded
188 if __name__ == "__main__":
189 register()