Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/rna_xml.py
| Show All 26 Lines | def build_property_typemap(skip_classes, skip_typemap): | ||||
| property_typemap = {} | property_typemap = {} | ||||
| for attr in dir(bpy.types): | for attr in dir(bpy.types): | ||||
| cls = getattr(bpy.types, attr) | cls = getattr(bpy.types, attr) | ||||
| if issubclass(cls, skip_classes): | if issubclass(cls, skip_classes): | ||||
| continue | continue | ||||
| # # to support skip-save we cant get all props | # # to support skip-save we can't get all props | ||||
| # properties = cls.bl_rna.properties.keys() | # properties = cls.bl_rna.properties.keys() | ||||
| properties = [] | properties = [] | ||||
| for prop_id, prop in cls.bl_rna.properties.items(): | for prop_id, prop in cls.bl_rna.properties.items(): | ||||
| if not prop.is_skip_save: | if not prop.is_skip_save: | ||||
| properties.append(prop_id) | properties.append(prop_id) | ||||
| properties.remove("rna_type") | properties.remove("rna_type") | ||||
| property_typemap[attr] = properties | property_typemap[attr] = properties | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def rna2xml_node(ident, value, parent): | ||||
| if subvalue_ls is None: | if subvalue_ls is None: | ||||
| nodes_items.append((prop, subvalue, subvalue_type)) | nodes_items.append((prop, subvalue, subvalue_type)) | ||||
| else: | else: | ||||
| # check if the list contains native types | # check if the list contains native types | ||||
| subvalue_rna = value.path_resolve(prop, False) | subvalue_rna = value.path_resolve(prop, False) | ||||
| if type(subvalue_rna).__name__ == "bpy_prop_array": | if type(subvalue_rna).__name__ == "bpy_prop_array": | ||||
| # check if this is a 0-1 color (rgb, rgba) | # check if this is a 0-1 color (rgb, rgba) | ||||
| # in that case write as a hexidecimal | # in that case write as a hexadecimal | ||||
| prop_rna = value.bl_rna.properties[prop] | prop_rna = value.bl_rna.properties[prop] | ||||
| if (prop_rna.subtype == 'COLOR_GAMMA' and | if (prop_rna.subtype == 'COLOR_GAMMA' and | ||||
| prop_rna.hard_min == 0.0 and | prop_rna.hard_min == 0.0 and | ||||
| prop_rna.hard_max == 1.0 and | prop_rna.hard_max == 1.0 and | ||||
| prop_rna.array_length in {3, 4}): | prop_rna.array_length in {3, 4}): | ||||
| # ----- | # ----- | ||||
| # color | # color | ||||
| array_value = "#" + "".join(("%.2x" % int(v * 255) for v in subvalue_rna)) | array_value = "#" + "".join(("%.2x" % int(v * 255) for v in subvalue_rna)) | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | def rna2xml_node(xml_node, value): | ||||
| elif subvalue_type == bool: | elif subvalue_type == bool: | ||||
| value_xml_coerce = {'TRUE': True, 'FALSE': False}[value_xml] | value_xml_coerce = {'TRUE': True, 'FALSE': False}[value_xml] | ||||
| tp_name = 'BOOL' | tp_name = 'BOOL' | ||||
| elif subvalue_type == str: | elif subvalue_type == str: | ||||
| value_xml_coerce = value_xml | value_xml_coerce = value_xml | ||||
| tp_name = 'STR' | tp_name = 'STR' | ||||
| elif hasattr(subvalue, "__len__"): | elif hasattr(subvalue, "__len__"): | ||||
| if value_xml.startswith("#"): | if value_xml.startswith("#"): | ||||
| # read hexidecimal value as float array | # read hexadecimal value as float array | ||||
| value_xml_split = value_xml[1:] | value_xml_split = value_xml[1:] | ||||
| value_xml_coerce = [int(value_xml_split[i:i + 2], 16) / | value_xml_coerce = [int(value_xml_split[i:i + 2], 16) / | ||||
| 255 for i in range(0, len(value_xml_split), 2)] | 255 for i in range(0, len(value_xml_split), 2)] | ||||
| del value_xml_split | del value_xml_split | ||||
| else: | else: | ||||
| value_xml_split = value_xml.split() | value_xml_split = value_xml.split() | ||||
| try: | try: | ||||
| value_xml_coerce = [int(v) for v in value_xml_split] | value_xml_coerce = [int(v) for v in value_xml_split] | ||||
| ▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines | |||||