提交 46171252 编写于 作者: N Nathan Phillip Brink

Blender exporter: optionally export Custom Properties as userData.

Adds a new option to the blender export plugin to support
Custom Props. Enabling that allows one to set Custom Properties
under the Object data tab in blender and access those on the
userData property of imported objects.

The ObjectLoader already supports importing JSON with userData.
上级 13892cfd
......@@ -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:")
......
......@@ -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,
......
......@@ -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):
"""
......
......@@ -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()")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册