__init__.py 28 KB

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