__init__.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  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.
  7. #
  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.
  12. #
  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.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. import os
  19. import json
  20. import logging
  21. import bpy
  22. from bpy_extras.io_utils import ExportHelper
  23. from bpy.props import (
  24. EnumProperty,
  25. BoolProperty,
  26. FloatProperty,
  27. IntProperty,
  28. StringProperty
  29. )
  30. from . import constants
  31. logging.basicConfig(
  32. format='%(levelname)s:THREE:%(message)s',
  33. level=logging.DEBUG)
  34. bl_info = {
  35. 'name': "Three.js Format",
  36. 'author': "repsac, mrdoob, yomotsu, mpk, jpweeks, rkusa",
  37. 'version': (1, 4, 0),
  38. 'blender': (2, 7, 3),
  39. 'location': "File > Export",
  40. 'description': "Export Three.js formatted JSON files.",
  41. 'warning': "Importer not included.",
  42. 'wiki_url': "https://github.com/mrdoob/three.js/tree/"\
  43. "master/utils/exporters/blender",
  44. 'tracker_url': "https://github.com/mrdoob/three.js/issues",
  45. 'category': 'Import-Export'
  46. }
  47. def _geometry_types():
  48. """The valid geometry types that are supported by Three.js
  49. :return: list of tuples
  50. """
  51. keys = (constants.GLOBAL,
  52. constants.GEOMETRY,
  53. constants.BUFFER_GEOMETRY)
  54. types = []
  55. for key in keys:
  56. types.append((key, key.title(), key))
  57. return types
  58. bpy.types.Mesh.THREE_geometry_type = EnumProperty(
  59. name="Geometry type",
  60. description="Geometry type",
  61. items=_geometry_types(),
  62. default=constants.GLOBAL)
  63. class ThreeMesh(bpy.types.Panel):
  64. """Creates custom properties on a mesh node"""
  65. bl_label = 'THREE'
  66. bl_space_type = 'PROPERTIES'
  67. bl_region_type = 'WINDOW'
  68. bl_context = 'data'
  69. def draw(self, context):
  70. """
  71. :param context:
  72. """
  73. row = self.layout.row()
  74. if context.mesh:
  75. row.prop(context.mesh,
  76. 'THREE_geometry_type',
  77. text="Type")
  78. def _blending_types(index):
  79. """Supported blending types for Three.js
  80. :param index:
  81. :type index: int
  82. :returns: tuple if types (str, str, str)
  83. """
  84. types = (constants.BLENDING_TYPES.NONE,
  85. constants.BLENDING_TYPES.NORMAL,
  86. constants.BLENDING_TYPES.ADDITIVE,
  87. constants.BLENDING_TYPES.SUBTRACTIVE,
  88. constants.BLENDING_TYPES.MULTIPLY,
  89. constants.BLENDING_TYPES.CUSTOM)
  90. return (types[index], types[index], types[index])
  91. bpy.types.Material.THREE_blending_type = EnumProperty(
  92. name="Blending type",
  93. description="Blending type",
  94. items=[_blending_types(x) for x in range(5)],
  95. default=constants.BLENDING_TYPES.NORMAL)
  96. bpy.types.Material.THREE_depth_write = BoolProperty(default=True)
  97. bpy.types.Material.THREE_depth_test = BoolProperty(default=True)
  98. class ThreeMaterial(bpy.types.Panel):
  99. """Adds custom properties to the Materials of an object"""
  100. bl_label = 'THREE'
  101. bl_space_type = 'PROPERTIES'
  102. bl_region_type = 'WINDOW'
  103. bl_context = 'material'
  104. def draw(self, context):
  105. """
  106. :param context:
  107. """
  108. layout = self.layout
  109. mat = context.material
  110. if mat is not None:
  111. row = layout.row()
  112. row.label(text="Selected material: %s" % mat.name)
  113. row = layout.row()
  114. row.prop(mat, 'THREE_blending_type',
  115. text="Blending type")
  116. row = layout.row()
  117. row.prop(mat, 'THREE_depth_write',
  118. text="Enable depth writing")
  119. row = layout.row()
  120. row.prop(mat, 'THREE_depth_test',
  121. text="Enable depth testing")
  122. def _mag_filters(index):
  123. """Three.js mag filters
  124. :param index:
  125. :type index: int
  126. :returns: tuple with the filter values
  127. """
  128. types = (constants.LINEAR_FILTERS.LINEAR,
  129. constants.NEAREST_FILTERS.NEAREST)
  130. return (types[index], types[index], types[index])
  131. bpy.types.Texture.THREE_mag_filter = EnumProperty(
  132. name="Mag Filter",
  133. items=[_mag_filters(x) for x in range(2)],
  134. default=constants.LINEAR_FILTERS.LINEAR)
  135. def _min_filters(index):
  136. """Three.js min filters
  137. :param index:
  138. :type index: int
  139. :returns: tuple with the filter values
  140. """
  141. types = (constants.LINEAR_FILTERS.LINEAR,
  142. constants.LINEAR_FILTERS.MIP_MAP_NEAREST,
  143. constants.LINEAR_FILTERS.MIP_MAP_LINEAR,
  144. constants.NEAREST_FILTERS.NEAREST,
  145. constants.NEAREST_FILTERS.MIP_MAP_NEAREST,
  146. constants.NEAREST_FILTERS.MIP_MAP_LINEAR)
  147. return (types[index], types[index], types[index])
  148. bpy.types.Texture.THREE_min_filter = EnumProperty(
  149. name="Min Filter",
  150. items=[_min_filters(x) for x in range(6)],
  151. default=constants.LINEAR_FILTERS.MIP_MAP_LINEAR)
  152. def _mapping(index):
  153. """Three.js texture mappings types
  154. :param index:
  155. :type index: int
  156. :returns: tuple with the mapping values
  157. """
  158. types = (constants.MAPPING_TYPES.UV,
  159. constants.MAPPING_TYPES.CUBE_REFLECTION,
  160. constants.MAPPING_TYPES.CUBE_REFRACTION,
  161. constants.MAPPING_TYPES.SPHERICAL_REFLECTION)
  162. return (types[index], types[index], types[index])
  163. bpy.types.Texture.THREE_mapping = EnumProperty(
  164. name="Mapping",
  165. items=[_mapping(x) for x in range(4)],
  166. default=constants.MAPPING_TYPES.UV)
  167. class ThreeTexture(bpy.types.Panel):
  168. """Adds custom properties to a texture"""
  169. bl_label = 'THREE'
  170. bl_space_type = 'PROPERTIES'
  171. bl_region_type = 'WINDOW'
  172. bl_context = 'texture'
  173. #@TODO: possible to make cycles compatible?
  174. def draw(self, context):
  175. """
  176. :param context:
  177. """
  178. layout = self.layout
  179. tex = context.texture
  180. if tex is not None:
  181. row = layout.row()
  182. row.prop(tex, 'THREE_mapping', text="Mapping")
  183. row = layout.row()
  184. row.prop(tex, 'THREE_mag_filter', text="Mag Filter")
  185. row = layout.row()
  186. row.prop(tex, 'THREE_min_filter', text="Min Filter")
  187. bpy.types.Object.THREE_export = bpy.props.BoolProperty(default=True)
  188. class ThreeObject(bpy.types.Panel):
  189. """Adds custom properties to an object"""
  190. bl_label = 'THREE'
  191. bl_space_type = 'PROPERTIES'
  192. bl_region_type = 'WINDOW'
  193. bl_context = 'object'
  194. def draw(self, context):
  195. """
  196. :param context:
  197. """
  198. layout = self.layout
  199. obj = context.object
  200. row = layout.row()
  201. row.prop(obj, 'THREE_export', text='Export')
  202. class ThreeExportSettings(bpy.types.Operator):
  203. """Save the current export settings (gets saved in .blend)"""
  204. bl_label = "Save Settings"
  205. bl_idname = "scene.three_export_settings_set"
  206. def execute(self, context):
  207. cycles = context.scene.cycles
  208. cycles.use_samples_final = True
  209. context.scene[constants.EXPORT_SETTINGS_KEY] = set_settings(context.active_operator.properties)
  210. self.report({"INFO"}, "Three Export Settings Saved")
  211. return {"FINISHED"}
  212. def restore_export_settings(properties, settings):
  213. """Restore the settings
  214. :param properties:
  215. """
  216. ## Geometry {
  217. properties.option_vertices = settings.get(
  218. constants.VERTICES,
  219. constants.EXPORT_OPTIONS[constants.VERTICES])
  220. properties.option_faces = settings.get(
  221. constants.FACES,
  222. constants.EXPORT_OPTIONS[constants.FACES])
  223. properties.option_normals = settings.get(
  224. constants.NORMALS,
  225. constants.EXPORT_OPTIONS[constants.NORMALS])
  226. properties.option_skinning = settings.get(
  227. constants.SKINNING,
  228. constants.EXPORT_OPTIONS[constants.SKINNING])
  229. properties.option_bones = settings.get(
  230. constants.BONES,
  231. constants.EXPORT_OPTIONS[constants.BONES])
  232. properties.option_influences = settings.get(
  233. constants.INFLUENCES_PER_VERTEX,
  234. constants.EXPORT_OPTIONS[constants.INFLUENCES_PER_VERTEX])
  235. properties.option_geometry_type = settings.get(
  236. constants.GEOMETRY_TYPE,
  237. constants.EXPORT_OPTIONS[constants.GEOMETRY_TYPE])
  238. ## }
  239. ## Materials {
  240. properties.option_materials = settings.get(
  241. constants.MATERIALS,
  242. constants.EXPORT_OPTIONS[constants.MATERIALS])
  243. properties.option_uv_coords = settings.get(
  244. constants.UVS,
  245. constants.EXPORT_OPTIONS[constants.UVS])
  246. properties.option_face_materials = settings.get(
  247. constants.FACE_MATERIALS,
  248. constants.EXPORT_OPTIONS[constants.FACE_MATERIALS])
  249. properties.option_maps = settings.get(
  250. constants.MAPS,
  251. constants.EXPORT_OPTIONS[constants.MAPS])
  252. properties.option_colors = settings.get(
  253. constants.COLORS,
  254. constants.EXPORT_OPTIONS[constants.COLORS])
  255. properties.option_mix_colors = settings.get(
  256. constants.MIX_COLORS,
  257. constants.EXPORT_OPTIONS[constants.MIX_COLORS])
  258. ## }
  259. ## Settings {
  260. properties.option_scale = settings.get(
  261. constants.SCALE,
  262. constants.EXPORT_OPTIONS[constants.SCALE])
  263. properties.option_round_off = settings.get(
  264. constants.ENABLE_PRECISION,
  265. constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
  266. properties.option_round_value = settings.get(
  267. constants.PRECISION,
  268. constants.EXPORT_OPTIONS[constants.PRECISION])
  269. properties.option_logging = settings.get(
  270. constants.LOGGING,
  271. constants.EXPORT_OPTIONS[constants.LOGGING])
  272. properties.option_compression = settings.get(
  273. constants.COMPRESSION,
  274. constants.NONE)
  275. properties.option_indent = settings.get(
  276. constants.INDENT,
  277. constants.EXPORT_OPTIONS[constants.INDENT])
  278. properties.option_copy_textures = settings.get(
  279. constants.COPY_TEXTURES,
  280. constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
  281. properties.option_texture_folder = settings.get(
  282. constants.TEXTURE_FOLDER,
  283. constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
  284. properties.option_embed_animation = settings.get(
  285. constants.EMBED_ANIMATION,
  286. constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
  287. ## }
  288. ## Scene {
  289. properties.option_export_scene = settings.get(
  290. constants.SCENE,
  291. constants.EXPORT_OPTIONS[constants.SCENE])
  292. #properties.option_embed_geometry = settings.get(
  293. # constants.EMBED_GEOMETRY,
  294. # constants.EXPORT_OPTIONS[constants.EMBED_GEOMETRY])
  295. properties.option_lights = settings.get(
  296. constants.LIGHTS,
  297. constants.EXPORT_OPTIONS[constants.LIGHTS])
  298. properties.option_cameras = settings.get(
  299. constants.CAMERAS,
  300. constants.EXPORT_OPTIONS[constants.CAMERAS])
  301. properties.option_hierarchy = settings.get(
  302. constants.HIERARCHY,
  303. constants.EXPORT_OPTIONS[constants.HIERARCHY])
  304. ## }
  305. ## Animation {
  306. properties.option_animation_morph = settings.get(
  307. constants.MORPH_TARGETS,
  308. constants.EXPORT_OPTIONS[constants.MORPH_TARGETS])
  309. properties.option_animation_skeletal = settings.get(
  310. constants.ANIMATION,
  311. constants.EXPORT_OPTIONS[constants.ANIMATION])
  312. properties.option_frame_step = settings.get(
  313. constants.FRAME_STEP,
  314. constants.EXPORT_OPTIONS[constants.FRAME_STEP])
  315. properties.option_frame_index_as_time = settings.get(
  316. constants.FRAME_INDEX_AS_TIME,
  317. constants.EXPORT_OPTIONS[constants.FRAME_INDEX_AS_TIME])
  318. ## }
  319. def set_settings(properties):
  320. """Set the export settings to the correct keys.
  321. :param properties:
  322. :returns: settings
  323. :rtype: dict
  324. """
  325. settings = {
  326. constants.VERTICES: properties.option_vertices,
  327. constants.FACES: properties.option_faces,
  328. constants.NORMALS: properties.option_normals,
  329. constants.SKINNING: properties.option_skinning,
  330. constants.BONES: properties.option_bones,
  331. constants.GEOMETRY_TYPE: properties.option_geometry_type,
  332. constants.MATERIALS: properties.option_materials,
  333. constants.UVS: properties.option_uv_coords,
  334. constants.FACE_MATERIALS: properties.option_face_materials,
  335. constants.MAPS: properties.option_maps,
  336. constants.COLORS: properties.option_colors,
  337. constants.MIX_COLORS: properties.option_mix_colors,
  338. constants.SCALE: properties.option_scale,
  339. constants.ENABLE_PRECISION: properties.option_round_off,
  340. constants.PRECISION: properties.option_round_value,
  341. constants.LOGGING: properties.option_logging,
  342. constants.COMPRESSION: properties.option_compression,
  343. constants.INDENT: properties.option_indent,
  344. constants.COPY_TEXTURES: properties.option_copy_textures,
  345. constants.TEXTURE_FOLDER: properties.option_texture_folder,
  346. constants.SCENE: properties.option_export_scene,
  347. #constants.EMBED_GEOMETRY: properties.option_embed_geometry,
  348. constants.EMBED_ANIMATION: properties.option_embed_animation,
  349. constants.LIGHTS: properties.option_lights,
  350. constants.CAMERAS: properties.option_cameras,
  351. constants.HIERARCHY: properties.option_hierarchy,
  352. constants.MORPH_TARGETS: properties.option_animation_morph,
  353. constants.ANIMATION: properties.option_animation_skeletal,
  354. constants.FRAME_STEP: properties.option_frame_step,
  355. constants.FRAME_INDEX_AS_TIME: properties.option_frame_index_as_time,
  356. constants.INFLUENCES_PER_VERTEX: properties.option_influences
  357. }
  358. return settings
  359. def compression_types():
  360. """Supported compression formats
  361. :rtype: tuple
  362. """
  363. types = [(constants.NONE, constants.NONE, constants.NONE)]
  364. try:
  365. import msgpack
  366. types.append((constants.MSGPACK, constants.MSGPACK,
  367. constants.MSGPACK))
  368. except ImportError:
  369. pass
  370. return types
  371. def animation_options():
  372. """The supported skeletal animation types
  373. :returns: list of tuples
  374. """
  375. anim = [
  376. (constants.OFF, constants.OFF.title(), constants.OFF),
  377. (constants.POSE, constants.POSE.title(), constants.POSE),
  378. (constants.REST, constants.REST.title(), constants.REST)
  379. ]
  380. return anim
  381. class ExportThree(bpy.types.Operator, ExportHelper):
  382. """Class that handles the export properties"""
  383. bl_idname = 'export.three'
  384. bl_label = 'Export THREE'
  385. bl_options = {'PRESET'}
  386. filename_ext = constants.EXTENSION
  387. option_vertices = BoolProperty(
  388. name="Vertices",
  389. description="Export vertices",
  390. default=constants.EXPORT_OPTIONS[constants.VERTICES])
  391. option_faces = BoolProperty(
  392. name="Faces",
  393. description="Export faces",
  394. default=constants.EXPORT_OPTIONS[constants.FACES])
  395. option_normals = BoolProperty(
  396. name="Normals",
  397. description="Export normals",
  398. default=constants.EXPORT_OPTIONS[constants.NORMALS])
  399. option_colors = BoolProperty(
  400. name="Vertex Colors",
  401. description="Export vertex colors",
  402. default=constants.EXPORT_OPTIONS[constants.COLORS])
  403. option_mix_colors = BoolProperty(
  404. name="Mix Colors",
  405. description="Mix material and vertex colors",
  406. default=constants.EXPORT_OPTIONS[constants.MIX_COLORS])
  407. option_uv_coords = BoolProperty(
  408. name="UVs",
  409. description="Export texture coordinates",
  410. default=constants.EXPORT_OPTIONS[constants.UVS])
  411. option_materials = BoolProperty(
  412. name="Materials",
  413. description="Export materials",
  414. default=constants.EXPORT_OPTIONS[constants.MATERIALS])
  415. option_face_materials = BoolProperty(
  416. name="Face Materials",
  417. description="Face mapping materials",
  418. default=constants.EXPORT_OPTIONS[constants.FACE_MATERIALS])
  419. option_maps = BoolProperty(
  420. name="Textures",
  421. description="Include texture maps",
  422. default=constants.EXPORT_OPTIONS[constants.MAPS])
  423. option_skinning = BoolProperty(
  424. name="Skinning",
  425. description="Export skin data",
  426. default=constants.EXPORT_OPTIONS[constants.SKINNING])
  427. option_bones = BoolProperty(
  428. name="Bones",
  429. description="Export bones",
  430. default=constants.EXPORT_OPTIONS[constants.BONES])
  431. option_scale = FloatProperty(
  432. name="Scale",
  433. description="Scale vertices",
  434. min=0.01,
  435. max=1000.0,
  436. soft_min=0.01,
  437. soft_max=1000.0,
  438. default=constants.EXPORT_OPTIONS[constants.SCALE])
  439. option_round_off = BoolProperty(
  440. name="Enable Precision",
  441. description="Round off floating point values",
  442. default=constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
  443. option_round_value = IntProperty(
  444. name="Precision",
  445. min=0,
  446. max=16,
  447. description="Floating point precision",
  448. default=constants.EXPORT_OPTIONS[constants.PRECISION])
  449. logging_types = [
  450. (constants.DEBUG, constants.DEBUG, constants.DEBUG),
  451. (constants.INFO, constants.INFO, constants.INFO),
  452. (constants.WARNING, constants.WARNING, constants.WARNING),
  453. (constants.ERROR, constants.ERROR, constants.ERROR),
  454. (constants.CRITICAL, constants.CRITICAL, constants.CRITICAL)]
  455. option_logging = EnumProperty(
  456. name="",
  457. description="Logging verbosity level",
  458. items=logging_types,
  459. default=constants.DEBUG)
  460. option_geometry_type = EnumProperty(
  461. name="Type",
  462. description="Geometry type",
  463. items=_geometry_types()[1:],
  464. default=constants.GEOMETRY)
  465. option_export_scene = BoolProperty(
  466. name="Scene",
  467. description="Export scene",
  468. default=constants.EXPORT_OPTIONS[constants.SCENE])
  469. #@TODO: removing this option since the ObjectLoader doesn't have
  470. # support for handling external geometry data
  471. #option_embed_geometry = BoolProperty(
  472. # name="Embed geometry",
  473. # description="Embed geometry",
  474. # default=constants.EXPORT_OPTIONS[constants.EMBED_GEOMETRY])
  475. option_embed_animation = BoolProperty(
  476. name="Embed animation",
  477. description="Embed animation data with the geometry data",
  478. default=constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
  479. option_copy_textures = BoolProperty(
  480. name="Copy textures",
  481. description="Copy textures",
  482. default=constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
  483. option_texture_folder = StringProperty(
  484. name="Texture folder",
  485. description="add this folder to textures path",
  486. default=constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
  487. option_lights = BoolProperty(
  488. name="Lights",
  489. description="Export default scene lights",
  490. default=False)
  491. option_cameras = BoolProperty(
  492. name="Cameras",
  493. description="Export default scene cameras",
  494. default=False)
  495. option_hierarchy = BoolProperty(
  496. name="Hierarchy",
  497. description="Export object hierarchy",
  498. default=False)
  499. option_animation_morph = BoolProperty(
  500. name="Morph animation",
  501. description="Export animation (morphs)",
  502. default=constants.EXPORT_OPTIONS[constants.MORPH_TARGETS])
  503. option_animation_skeletal = EnumProperty(
  504. name="",
  505. description="Export animation (skeletal)",
  506. items=animation_options(),
  507. default=constants.OFF)
  508. option_frame_index_as_time = BoolProperty(
  509. name="Frame index as time",
  510. description="Use (original) frame index as frame time",
  511. default=constants.EXPORT_OPTIONS[constants.FRAME_INDEX_AS_TIME])
  512. option_frame_step = IntProperty(
  513. name="Frame step",
  514. description="Animation frame step",
  515. min=1,
  516. max=1000,
  517. soft_min=1,
  518. soft_max=1000,
  519. default=1)
  520. option_indent = BoolProperty(
  521. name="Indent JSON",
  522. description="Disable this to reduce the file size",
  523. default=constants.EXPORT_OPTIONS[constants.INDENT])
  524. option_compression = EnumProperty(
  525. name="",
  526. description="Compression options",
  527. items=compression_types(),
  528. default=constants.NONE)
  529. option_influences = IntProperty(
  530. name="Influences",
  531. description="Maximum number of bone influences",
  532. min=1,
  533. max=4,
  534. default=2)
  535. def invoke(self, context, event):
  536. settings = context.scene.get(constants.EXPORT_SETTINGS_KEY)
  537. if settings:
  538. try:
  539. restore_export_settings(self.properties, settings)
  540. except AttributeError as e:
  541. logging.error("Loading export settings failed:")
  542. logging.exception(e)
  543. logging.debug("Removed corrupted settings")
  544. del context.scene[constants.EXPORT_SETTINGS_KEY]
  545. return ExportHelper.invoke(self, context, event)
  546. @classmethod
  547. def poll(cls, context):
  548. """
  549. :param context:
  550. """
  551. return context.active_object is not None
  552. def execute(self, context):
  553. """
  554. :param context:
  555. """
  556. if not self.properties.filepath:
  557. raise Exception("filename not set")
  558. settings = set_settings(self.properties)
  559. settings['addon_version'] = bl_info['version']
  560. filepath = self.filepath
  561. if settings[constants.COMPRESSION] == constants.MSGPACK:
  562. filepath = "%s%s" % (filepath[:-4], constants.PACK)
  563. from io_three import exporter
  564. if settings[constants.SCENE]:
  565. exporter.export_scene(filepath, settings)
  566. else:
  567. exporter.export_geometry(filepath, settings)
  568. return {'FINISHED'}
  569. def draw(self, context):
  570. """
  571. :param context:
  572. """
  573. layout = self.layout
  574. ## Geometry {
  575. row = layout.row()
  576. row.label(text="GEOMETRY:")
  577. row = layout.row()
  578. row.prop(self.properties, 'option_vertices')
  579. row.prop(self.properties, 'option_faces')
  580. row = layout.row()
  581. row.prop(self.properties, 'option_normals')
  582. row.prop(self.properties, 'option_uv_coords')
  583. row = layout.row()
  584. row.prop(self.properties, 'option_bones')
  585. row.prop(self.properties, 'option_skinning')
  586. row = layout.row()
  587. row.prop(self.properties, 'option_geometry_type')
  588. ## }
  589. layout.separator()
  590. ## Materials {
  591. row = layout.row()
  592. row.label(text="- Shading:")
  593. row = layout.row()
  594. row.prop(self.properties, 'option_face_materials')
  595. row = layout.row()
  596. row.prop(self.properties, 'option_colors')
  597. row = layout.row()
  598. row.prop(self.properties, 'option_mix_colors')
  599. ## }
  600. layout.separator()
  601. ## Animation {
  602. row = layout.row()
  603. row.label(text="- Animation:")
  604. row = layout.row()
  605. row.prop(self.properties, 'option_animation_morph')
  606. row = layout.row()
  607. row.label(text="Skeletal animations:")
  608. row = layout.row()
  609. row.prop(self.properties, 'option_animation_skeletal')
  610. layout.row()
  611. row = layout.row()
  612. row.prop(self.properties, 'option_influences')
  613. row = layout.row()
  614. row.prop(self.properties, 'option_frame_step')
  615. row = layout.row()
  616. row.prop(self.properties, 'option_frame_index_as_time')
  617. row = layout.row()
  618. row.prop(self.properties, 'option_embed_animation')
  619. ## }
  620. layout.separator()
  621. ## Scene {
  622. row = layout.row()
  623. row.label(text="SCENE:")
  624. row = layout.row()
  625. row.prop(self.properties, 'option_export_scene')
  626. row.prop(self.properties, 'option_materials')
  627. #row = layout.row()
  628. #row.prop(self.properties, 'option_embed_geometry')
  629. row = layout.row()
  630. row.prop(self.properties, 'option_lights')
  631. row.prop(self.properties, 'option_cameras')
  632. ## }
  633. row = layout.row()
  634. row.prop(self.properties, 'option_hierarchy')
  635. layout.separator()
  636. ## Settings {
  637. row = layout.row()
  638. row.label(text="SETTINGS:")
  639. row = layout.row()
  640. row.prop(self.properties, 'option_maps')
  641. row = layout.row()
  642. row.prop(self.properties, 'option_copy_textures')
  643. row = layout.row()
  644. row.prop(self.properties, 'option_texture_folder')
  645. row = layout.row()
  646. row.prop(self.properties, 'option_scale')
  647. layout.row()
  648. row = layout.row()
  649. row.prop(self.properties, 'option_round_off')
  650. row = layout.row()
  651. row.prop(self.properties, 'option_round_value')
  652. layout.row()
  653. row = layout.row()
  654. row.label(text="Logging verbosity:")
  655. row = layout.row()
  656. row.prop(self.properties, 'option_logging')
  657. row = layout.row()
  658. row.label(text="File compression format:")
  659. row = layout.row()
  660. row.prop(self.properties, 'option_compression')
  661. row = layout.row()
  662. row.prop(self.properties, 'option_indent')
  663. ## }
  664. ## Operators {
  665. has_settings = context.scene.get(constants.EXPORT_SETTINGS_KEY, False)
  666. row = layout.row()
  667. row.operator(
  668. ThreeExportSettings.bl_idname,
  669. ThreeExportSettings.bl_label,
  670. icon="%s" % "PINNED" if has_settings else "UNPINNED")
  671. ## }
  672. def menu_func_export(self, context):
  673. """
  674. :param self:
  675. :param context:
  676. """
  677. default_path = bpy.data.filepath.replace('.blend', constants.EXTENSION)
  678. text = "Three.js (%s)" % constants.EXTENSION
  679. operator = self.layout.operator(ExportThree.bl_idname, text=text)
  680. operator.filepath = default_path
  681. def register():
  682. """Registers the addon (Blender boilerplate)"""
  683. bpy.utils.register_module(__name__)
  684. bpy.types.INFO_MT_file_export.append(menu_func_export)
  685. def unregister():
  686. """Unregisters the addon (Blender boilerplate)"""
  687. bpy.utils.unregister_module(__name__)
  688. bpy.types.INFO_MT_file_export.remove(menu_func_export)
  689. if __name__ == '__main__':
  690. register()