Przeglądaj źródła

Merge pull request #8246 from binki/dev

Blender exporter: optionally export Custom Properties as userData.
Mr.doob 9 lat temu
rodzic
commit
4150c98f2a

+ 17 - 0
utils/exporters/blender/addons/io_three/__init__.py

@@ -362,6 +362,10 @@ def restore_export_settings(properties, settings):
         constants.PRECISION,
         constants.EXPORT_OPTIONS[constants.PRECISION])
 
+    properties.option_custom_properties = settings.get(
+        constants.CUSTOM_PROPERTIES,
+        constants.EXPORT_OPTIONS[constants.CUSTOM_PROPERTIES])
+
     properties.option_logging = settings.get(
         constants.LOGGING,
         constants.EXPORT_OPTIONS[constants.LOGGING])
@@ -468,6 +472,7 @@ def set_settings(properties):
         constants.SCALE: properties.option_scale,
         constants.ENABLE_PRECISION: properties.option_round_off,
         constants.PRECISION: properties.option_round_value,
+        constants.CUSTOM_PROPERTIES: properties.option_custom_properties,
         constants.LOGGING: properties.option_logging,
         constants.COMPRESSION: properties.option_compression,
         constants.INDENT: properties.option_indent,
@@ -637,6 +642,11 @@ class ExportThree(bpy.types.Operator, ExportHelper):
         description="Floating point precision",
         default=constants.EXPORT_OPTIONS[constants.PRECISION])
 
+    option_custom_properties = BoolProperty(
+        name="Custom Props",
+        description="Export custom properties as userData",
+        default=False)
+
     logging_types = [
         (constants.DISABLED, constants.DISABLED, constants.DISABLED),
         (constants.DEBUG, constants.DEBUG, constants.DEBUG),
@@ -947,6 +957,13 @@ class ExportThree(bpy.types.Operator, ExportHelper):
         row = layout.row()
         row.prop(self.properties, 'option_round_value')
 
+        layout.row()
+        row = layout.row()
+        row.label(text="Custom Properties")
+
+        row = layout.row()
+        row.prop(self.properties, 'option_custom_properties')
+
         layout.row()
         row = layout.row()
         row.label(text="Logging verbosity:")

+ 2 - 0
utils/exporters/blender/addons/io_three/constants.py

@@ -99,6 +99,7 @@ TEXTURE_FOLDER = 'textureFolder'
 ENABLE_PRECISION = 'enablePrecision'
 PRECISION = 'precision'
 DEFAULT_PRECISION = 6
+CUSTOM_PROPERTIES = 'customProperties'
 EMBED_GEOMETRY = 'embedGeometry'
 EMBED_ANIMATION = 'embedAnimation'
 OFF = 'off'
@@ -160,6 +161,7 @@ EXPORT_OPTIONS = {
     LOGGING: DEBUG,
     ENABLE_PRECISION: True,
     PRECISION: DEFAULT_PRECISION,
+    CUSTOM_PROPERTIES: False,
     EMBED_GEOMETRY: True,
     EMBED_ANIMATION: True,
     GEOMETRY_TYPE: GEOMETRY,

+ 13 - 0
utils/exporters/blender/addons/io_three/exporter/api/object.py

@@ -235,6 +235,19 @@ def animated_xform(obj, options):
     # TODO: remove duplicated key frames
     return tracks
 
+@_object
+def custom_properties(obj):
+    """
+
+    :param obj:
+
+    """
+    logger.debug('object.custom_properties(%s)', obj)
+    # Grab any properties except those marked private (by underscore
+    # prefix) or those with types that would be rejected by the JSON
+    # serializer object model.
+    return {kvp[0]: kvp[1] for kvp in obj.data.items() if kvp[0][:1] != '_' and isinstance(kvp[1], constants.VALID_DATA_TYPES)}
+
 @_object
 def mesh(obj, options):
     """

+ 3 - 0
utils/exporters/blender/addons/io_three/exporter/object.py

@@ -142,6 +142,9 @@ class Object(base_classes.BaseNode):
                 else:
                     self[constants.CHILDREN].append(Object(child, parent=self))
 
+        if self.options.get(constants.CUSTOM_PROPERTIES, False):
+            self[constants.USER_DATA] = api.object.custom_properties(self.node)
+
     def _root_setup(self):
         """Applies to a root/scene object"""
         logger.debug("Object()._root_setup()")