__init__.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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, tschw",
  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_apply_modifiers = settings.get(
  236. constants.APPLY_MODIFIERS,
  237. constants.EXPORT_OPTIONS[constants.APPLY_MODIFIERS])
  238. properties.option_geometry_type = settings.get(
  239. constants.GEOMETRY_TYPE,
  240. constants.EXPORT_OPTIONS[constants.GEOMETRY_TYPE])
  241. properties.option_index_type = settings.get(
  242. constants.INDEX_TYPE,
  243. constants.EXPORT_OPTIONS[constants.INDEX_TYPE])
  244. ## }
  245. ## Materials {
  246. properties.option_materials = settings.get(
  247. constants.MATERIALS,
  248. constants.EXPORT_OPTIONS[constants.MATERIALS])
  249. properties.option_uv_coords = settings.get(
  250. constants.UVS,
  251. constants.EXPORT_OPTIONS[constants.UVS])
  252. properties.option_face_materials = settings.get(
  253. constants.FACE_MATERIALS,
  254. constants.EXPORT_OPTIONS[constants.FACE_MATERIALS])
  255. properties.option_maps = settings.get(
  256. constants.MAPS,
  257. constants.EXPORT_OPTIONS[constants.MAPS])
  258. properties.option_colors = settings.get(
  259. constants.COLORS,
  260. constants.EXPORT_OPTIONS[constants.COLORS])
  261. properties.option_mix_colors = settings.get(
  262. constants.MIX_COLORS,
  263. constants.EXPORT_OPTIONS[constants.MIX_COLORS])
  264. ## }
  265. ## Settings {
  266. properties.option_scale = settings.get(
  267. constants.SCALE,
  268. constants.EXPORT_OPTIONS[constants.SCALE])
  269. properties.option_round_off = settings.get(
  270. constants.ENABLE_PRECISION,
  271. constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
  272. properties.option_round_value = settings.get(
  273. constants.PRECISION,
  274. constants.EXPORT_OPTIONS[constants.PRECISION])
  275. properties.option_logging = settings.get(
  276. constants.LOGGING,
  277. constants.EXPORT_OPTIONS[constants.LOGGING])
  278. properties.option_compression = settings.get(
  279. constants.COMPRESSION,
  280. constants.NONE)
  281. properties.option_indent = settings.get(
  282. constants.INDENT,
  283. constants.EXPORT_OPTIONS[constants.INDENT])
  284. properties.option_copy_textures = settings.get(
  285. constants.COPY_TEXTURES,
  286. constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
  287. properties.option_texture_folder = settings.get(
  288. constants.TEXTURE_FOLDER,
  289. constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
  290. properties.option_embed_animation = settings.get(
  291. constants.EMBED_ANIMATION,
  292. constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
  293. ## }
  294. ## Scene {
  295. properties.option_export_scene = settings.get(
  296. constants.SCENE,
  297. constants.EXPORT_OPTIONS[constants.SCENE])
  298. #properties.option_embed_geometry = settings.get(
  299. # constants.EMBED_GEOMETRY,
  300. # constants.EXPORT_OPTIONS[constants.EMBED_GEOMETRY])
  301. properties.option_lights = settings.get(
  302. constants.LIGHTS,
  303. constants.EXPORT_OPTIONS[constants.LIGHTS])
  304. properties.option_cameras = settings.get(
  305. constants.CAMERAS,
  306. constants.EXPORT_OPTIONS[constants.CAMERAS])
  307. properties.option_hierarchy = settings.get(
  308. constants.HIERARCHY,
  309. constants.EXPORT_OPTIONS[constants.HIERARCHY])
  310. ## }
  311. ## Animation {
  312. properties.option_animation_morph = settings.get(
  313. constants.MORPH_TARGETS,
  314. constants.EXPORT_OPTIONS[constants.MORPH_TARGETS])
  315. properties.option_animation_skeletal = settings.get(
  316. constants.ANIMATION,
  317. constants.EXPORT_OPTIONS[constants.ANIMATION])
  318. properties.option_frame_step = settings.get(
  319. constants.FRAME_STEP,
  320. constants.EXPORT_OPTIONS[constants.FRAME_STEP])
  321. properties.option_frame_index_as_time = settings.get(
  322. constants.FRAME_INDEX_AS_TIME,
  323. constants.EXPORT_OPTIONS[constants.FRAME_INDEX_AS_TIME])
  324. ## }
  325. def set_settings(properties):
  326. """Set the export settings to the correct keys.
  327. :param properties:
  328. :returns: settings
  329. :rtype: dict
  330. """
  331. settings = {
  332. constants.VERTICES: properties.option_vertices,
  333. constants.FACES: properties.option_faces,
  334. constants.NORMALS: properties.option_normals,
  335. constants.SKINNING: properties.option_skinning,
  336. constants.BONES: properties.option_bones,
  337. constants.APPLY_MODIFIERS: properties.option_apply_modifiers,
  338. constants.GEOMETRY_TYPE: properties.option_geometry_type,
  339. constants.INDEX_TYPE: properties.option_index_type,
  340. constants.MATERIALS: properties.option_materials,
  341. constants.UVS: properties.option_uv_coords,
  342. constants.FACE_MATERIALS: properties.option_face_materials,
  343. constants.MAPS: properties.option_maps,
  344. constants.COLORS: properties.option_colors,
  345. constants.MIX_COLORS: properties.option_mix_colors,
  346. constants.SCALE: properties.option_scale,
  347. constants.ENABLE_PRECISION: properties.option_round_off,
  348. constants.PRECISION: properties.option_round_value,
  349. constants.LOGGING: properties.option_logging,
  350. constants.COMPRESSION: properties.option_compression,
  351. constants.INDENT: properties.option_indent,
  352. constants.COPY_TEXTURES: properties.option_copy_textures,
  353. constants.TEXTURE_FOLDER: properties.option_texture_folder,
  354. constants.SCENE: properties.option_export_scene,
  355. #constants.EMBED_GEOMETRY: properties.option_embed_geometry,
  356. constants.EMBED_ANIMATION: properties.option_embed_animation,
  357. constants.LIGHTS: properties.option_lights,
  358. constants.CAMERAS: properties.option_cameras,
  359. constants.HIERARCHY: properties.option_hierarchy,
  360. constants.MORPH_TARGETS: properties.option_animation_morph,
  361. constants.ANIMATION: properties.option_animation_skeletal,
  362. constants.FRAME_STEP: properties.option_frame_step,
  363. constants.FRAME_INDEX_AS_TIME: properties.option_frame_index_as_time,
  364. constants.INFLUENCES_PER_VERTEX: properties.option_influences
  365. }
  366. return settings
  367. def compression_types():
  368. """Supported compression formats
  369. :rtype: tuple
  370. """
  371. types = [(constants.NONE, constants.NONE, constants.NONE)]
  372. try:
  373. import msgpack
  374. types.append((constants.MSGPACK, constants.MSGPACK,
  375. constants.MSGPACK))
  376. except ImportError:
  377. pass
  378. return types
  379. def animation_options():
  380. """The supported skeletal animation types
  381. :returns: list of tuples
  382. """
  383. anim = [
  384. (constants.OFF, constants.OFF.title(), constants.OFF),
  385. (constants.POSE, constants.POSE.title(), constants.POSE),
  386. (constants.REST, constants.REST.title(), constants.REST)
  387. ]
  388. return anim
  389. class ExportThree(bpy.types.Operator, ExportHelper):
  390. """Class that handles the export properties"""
  391. bl_idname = 'export.three'
  392. bl_label = 'Export THREE'
  393. bl_options = {'PRESET'}
  394. filename_ext = constants.EXTENSION
  395. option_vertices = BoolProperty(
  396. name="Vertices",
  397. description="Export vertices",
  398. default=constants.EXPORT_OPTIONS[constants.VERTICES])
  399. option_faces = BoolProperty(
  400. name="Faces",
  401. description="Export faces",
  402. default=constants.EXPORT_OPTIONS[constants.FACES])
  403. option_normals = BoolProperty(
  404. name="Normals",
  405. description="Export normals",
  406. default=constants.EXPORT_OPTIONS[constants.NORMALS])
  407. option_colors = BoolProperty(
  408. name="Vertex Colors",
  409. description="Export vertex colors",
  410. default=constants.EXPORT_OPTIONS[constants.COLORS])
  411. option_mix_colors = BoolProperty(
  412. name="Mix Colors",
  413. description="Mix material and vertex colors",
  414. default=constants.EXPORT_OPTIONS[constants.MIX_COLORS])
  415. option_uv_coords = BoolProperty(
  416. name="UVs",
  417. description="Export texture coordinates",
  418. default=constants.EXPORT_OPTIONS[constants.UVS])
  419. option_materials = BoolProperty(
  420. name="Materials",
  421. description="Export materials",
  422. default=constants.EXPORT_OPTIONS[constants.MATERIALS])
  423. option_face_materials = BoolProperty(
  424. name="Face Materials",
  425. description="Face mapping materials",
  426. default=constants.EXPORT_OPTIONS[constants.FACE_MATERIALS])
  427. option_maps = BoolProperty(
  428. name="Textures",
  429. description="Include texture maps",
  430. default=constants.EXPORT_OPTIONS[constants.MAPS])
  431. option_skinning = BoolProperty(
  432. name="Skinning",
  433. description="Export skin data",
  434. default=constants.EXPORT_OPTIONS[constants.SKINNING])
  435. option_bones = BoolProperty(
  436. name="Bones",
  437. description="Export bones",
  438. default=constants.EXPORT_OPTIONS[constants.BONES])
  439. option_apply_modifiers = BoolProperty(
  440. name="Apply Modifiers",
  441. description="Apply Modifiers to mesh objects",
  442. default=constants.EXPORT_OPTIONS[constants.APPLY_MODIFIERS]
  443. )
  444. index_buffer_types = [
  445. (constants.NONE,) * 3,
  446. (constants.UINT_16,) * 3,
  447. (constants.UINT_32,) * 3]
  448. option_index_type = EnumProperty(
  449. name="Index Buffer",
  450. description="Index buffer type that will be used for BufferGeometry objects.",
  451. items=index_buffer_types,
  452. default=constants.EXPORT_OPTIONS[constants.INDEX_TYPE])
  453. option_scale = FloatProperty(
  454. name="Scale",
  455. description="Scale vertices",
  456. min=0.01,
  457. max=1000.0,
  458. soft_min=0.01,
  459. soft_max=1000.0,
  460. default=constants.EXPORT_OPTIONS[constants.SCALE])
  461. option_round_off = BoolProperty(
  462. name="Enable Precision",
  463. description="Round off floating point values",
  464. default=constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
  465. option_round_value = IntProperty(
  466. name="Precision",
  467. min=0,
  468. max=16,
  469. description="Floating point precision",
  470. default=constants.EXPORT_OPTIONS[constants.PRECISION])
  471. logging_types = [
  472. (constants.DEBUG, constants.DEBUG, constants.DEBUG),
  473. (constants.INFO, constants.INFO, constants.INFO),
  474. (constants.WARNING, constants.WARNING, constants.WARNING),
  475. (constants.ERROR, constants.ERROR, constants.ERROR),
  476. (constants.CRITICAL, constants.CRITICAL, constants.CRITICAL)]
  477. option_logging = EnumProperty(
  478. name="",
  479. description="Logging verbosity level",
  480. items=logging_types,
  481. default=constants.DEBUG)
  482. option_geometry_type = EnumProperty(
  483. name="Type",
  484. description="Geometry type",
  485. items=_geometry_types()[1:],
  486. default=constants.EXPORT_OPTIONS[constants.GEOMETRY_TYPE])
  487. option_export_scene = BoolProperty(
  488. name="Scene",
  489. description="Export scene",
  490. default=constants.EXPORT_OPTIONS[constants.SCENE])
  491. #@TODO: removing this option since the ObjectLoader doesn't have
  492. # support for handling external geometry data
  493. #option_embed_geometry = BoolProperty(
  494. # name="Embed geometry",
  495. # description="Embed geometry",
  496. # default=constants.EXPORT_OPTIONS[constants.EMBED_GEOMETRY])
  497. option_embed_animation = BoolProperty(
  498. name="Embed animation",
  499. description="Embed animation data with the geometry data",
  500. default=constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
  501. option_copy_textures = BoolProperty(
  502. name="Copy textures",
  503. description="Copy textures",
  504. default=constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
  505. option_texture_folder = StringProperty(
  506. name="Texture folder",
  507. description="add this folder to textures path",
  508. default=constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
  509. option_lights = BoolProperty(
  510. name="Lights",
  511. description="Export default scene lights",
  512. default=False)
  513. option_cameras = BoolProperty(
  514. name="Cameras",
  515. description="Export default scene cameras",
  516. default=False)
  517. option_hierarchy = BoolProperty(
  518. name="Hierarchy",
  519. description="Export object hierarchy",
  520. default=False)
  521. option_animation_morph = BoolProperty(
  522. name="Morph animation",
  523. description="Export animation (morphs)",
  524. default=constants.EXPORT_OPTIONS[constants.MORPH_TARGETS])
  525. option_animation_skeletal = EnumProperty(
  526. name="",
  527. description="Export animation (skeletal)",
  528. items=animation_options(),
  529. default=constants.OFF)
  530. option_frame_index_as_time = BoolProperty(
  531. name="Frame index as time",
  532. description="Use (original) frame index as frame time",
  533. default=constants.EXPORT_OPTIONS[constants.FRAME_INDEX_AS_TIME])
  534. option_frame_step = IntProperty(
  535. name="Frame step",
  536. description="Animation frame step",
  537. min=1,
  538. max=1000,
  539. soft_min=1,
  540. soft_max=1000,
  541. default=1)
  542. option_indent = BoolProperty(
  543. name="Indent JSON",
  544. description="Disable this to reduce the file size",
  545. default=constants.EXPORT_OPTIONS[constants.INDENT])
  546. option_compression = EnumProperty(
  547. name="",
  548. description="Compression options",
  549. items=compression_types(),
  550. default=constants.NONE)
  551. option_influences = IntProperty(
  552. name="Influences",
  553. description="Maximum number of bone influences",
  554. min=1,
  555. max=4,
  556. default=2)
  557. def invoke(self, context, event):
  558. settings = context.scene.get(constants.EXPORT_SETTINGS_KEY)
  559. if settings:
  560. try:
  561. restore_export_settings(self.properties, settings)
  562. except AttributeError as e:
  563. logging.error("Loading export settings failed:")
  564. logging.exception(e)
  565. logging.debug("Removed corrupted settings")
  566. del context.scene[constants.EXPORT_SETTINGS_KEY]
  567. return ExportHelper.invoke(self, context, event)
  568. @classmethod
  569. def poll(cls, context):
  570. """
  571. :param context:
  572. """
  573. return context.active_object is not None
  574. def execute(self, context):
  575. """
  576. :param context:
  577. """
  578. if not self.properties.filepath:
  579. raise Exception("filename not set")
  580. settings = set_settings(self.properties)
  581. settings['addon_version'] = bl_info['version']
  582. filepath = self.filepath
  583. if settings[constants.COMPRESSION] == constants.MSGPACK:
  584. filepath = "%s%s" % (filepath[:-4], constants.PACK)
  585. from io_three import exporter
  586. if settings[constants.SCENE]:
  587. exporter.export_scene(filepath, settings)
  588. else:
  589. exporter.export_geometry(filepath, settings)
  590. return {'FINISHED'}
  591. def draw(self, context):
  592. """
  593. :param context:
  594. """
  595. layout = self.layout
  596. ## Geometry {
  597. row = layout.row()
  598. row.label(text="GEOMETRY:")
  599. row = layout.row()
  600. row.prop(self.properties, 'option_vertices')
  601. row.prop(self.properties, 'option_faces')
  602. row = layout.row()
  603. row.prop(self.properties, 'option_normals')
  604. row.prop(self.properties, 'option_uv_coords')
  605. row = layout.row()
  606. row.prop(self.properties, 'option_bones')
  607. row.prop(self.properties, 'option_skinning')
  608. row = layout.row()
  609. row.prop(self.properties, 'option_apply_modifiers')
  610. row = layout.row()
  611. row.prop(self.properties, 'option_geometry_type')
  612. row = layout.row()
  613. row.prop(self.properties, 'option_index_type')
  614. ## }
  615. layout.separator()
  616. ## Materials {
  617. row = layout.row()
  618. row.label(text="- Shading:")
  619. row = layout.row()
  620. row.prop(self.properties, 'option_face_materials')
  621. row = layout.row()
  622. row.prop(self.properties, 'option_colors')
  623. row = layout.row()
  624. row.prop(self.properties, 'option_mix_colors')
  625. ## }
  626. layout.separator()
  627. ## Animation {
  628. row = layout.row()
  629. row.label(text="- Animation:")
  630. row = layout.row()
  631. row.prop(self.properties, 'option_animation_morph')
  632. row = layout.row()
  633. row.label(text="Skeletal animations:")
  634. row = layout.row()
  635. row.prop(self.properties, 'option_animation_skeletal')
  636. layout.row()
  637. row = layout.row()
  638. row.prop(self.properties, 'option_influences')
  639. row = layout.row()
  640. row.prop(self.properties, 'option_frame_step')
  641. row = layout.row()
  642. row.prop(self.properties, 'option_frame_index_as_time')
  643. row = layout.row()
  644. row.prop(self.properties, 'option_embed_animation')
  645. ## }
  646. layout.separator()
  647. ## Scene {
  648. row = layout.row()
  649. row.label(text="SCENE:")
  650. row = layout.row()
  651. row.prop(self.properties, 'option_export_scene')
  652. row.prop(self.properties, 'option_materials')
  653. #row = layout.row()
  654. #row.prop(self.properties, 'option_embed_geometry')
  655. row = layout.row()
  656. row.prop(self.properties, 'option_lights')
  657. row.prop(self.properties, 'option_cameras')
  658. ## }
  659. row = layout.row()
  660. row.prop(self.properties, 'option_hierarchy')
  661. layout.separator()
  662. ## Settings {
  663. row = layout.row()
  664. row.label(text="SETTINGS:")
  665. row = layout.row()
  666. row.prop(self.properties, 'option_maps')
  667. row = layout.row()
  668. row.prop(self.properties, 'option_copy_textures')
  669. row = layout.row()
  670. row.prop(self.properties, 'option_texture_folder')
  671. row = layout.row()
  672. row.prop(self.properties, 'option_scale')
  673. layout.row()
  674. row = layout.row()
  675. row.prop(self.properties, 'option_round_off')
  676. row = layout.row()
  677. row.prop(self.properties, 'option_round_value')
  678. layout.row()
  679. row = layout.row()
  680. row.label(text="Logging verbosity:")
  681. row = layout.row()
  682. row.prop(self.properties, 'option_logging')
  683. row = layout.row()
  684. row.label(text="File compression format:")
  685. row = layout.row()
  686. row.prop(self.properties, 'option_compression')
  687. row = layout.row()
  688. row.prop(self.properties, 'option_indent')
  689. ## }
  690. ## Operators {
  691. has_settings = context.scene.get(constants.EXPORT_SETTINGS_KEY, False)
  692. row = layout.row()
  693. row.operator(
  694. ThreeExportSettings.bl_idname,
  695. ThreeExportSettings.bl_label,
  696. icon="%s" % "PINNED" if has_settings else "UNPINNED")
  697. ## }
  698. def menu_func_export(self, context):
  699. """
  700. :param self:
  701. :param context:
  702. """
  703. default_path = bpy.data.filepath.replace('.blend', constants.EXTENSION)
  704. text = "Three.js (%s)" % constants.EXTENSION
  705. operator = self.layout.operator(ExportThree.bl_idname, text=text)
  706. operator.filepath = default_path
  707. def register():
  708. """Registers the addon (Blender boilerplate)"""
  709. bpy.utils.register_module(__name__)
  710. bpy.types.INFO_MT_file_export.append(menu_func_export)
  711. def unregister():
  712. """Unregisters the addon (Blender boilerplate)"""
  713. bpy.utils.unregister_module(__name__)
  714. bpy.types.INFO_MT_file_export.remove(menu_func_export)
  715. if __name__ == '__main__':
  716. register()