[Bf-extensions-cvs] [ac7d908] master: Heavy rework/cleanup of property area.

Bastien Montagne noreply at git.blender.org
Mon Mar 24 22:32:32 CET 2014


Commit: ac7d908b4059c316eb8b2265b58c1bcd08fd49b8
Author: Bastien Montagne
Date:   Mon Mar 24 22:28:45 2014 +0100
https://developer.blender.org/rBAac7d908b4059c316eb8b2265b58c1bcd08fd49b8

Heavy rework/cleanup of property area.

Finally understood a bit better Property format (name, type, kind_of_label?, flags, data, ...).
So needed to handle flags properly (currently, only aware of 'A'nimatable and 'U'ser-defined (aka custom),
no idea yet what means the '+' one found in some places).

Also changed templates definitions to use OrderedDict's, gives better output.

===================================================================

M	io_scene_fbx/export_fbx_bin.py

===================================================================

diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index cdc1428..1a990f6 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -334,74 +334,85 @@ def elem_data_vec_float64(elem, name, value):
 
 ##### Generators for standard FBXProperties70 properties. #####
 
-# Properties definitions, format: (b"type_1", b"type_2", b"type_3", "name_set_value_1", "name_set_value_2", ...)
+# Properties definitions, format: (b"type_1", b"label(???)", "name_set_value_1", "name_set_value_2", ...)
 # XXX Looks like there can be various variations of formats here... Will have to be checked ultimately!
-#     Among other things, what are those "A"/"A+"/"AU" codes?
+#     Also, those "custom" types like 'FieldOfView' or 'Lcl Translation' are pure nonsense,
+#     these are just Vector3D ultimately... *sigh* (again).
 FBX_PROPERTIES_DEFINITIONS = {
-    "p_bool": [b"bool", b"", b"", "add_int32"],  # Yes, int32 for a bool (and they do have a core bool type)!!!
-    "p_integer": [b"int", b"Integer", b"", "add_int32"],
-    "p_enum": [b"enum", b"", b"", "add_int32"],
-    "p_number": [b"double", b"Number", b"", "add_float64"],
-    "p_visibility": [b"Visibility", b"", b"A+", "add_float64"],
-    "p_fov": [b"FieldOfView", b"", b"A+", "add_float64"],
-    "p_fov_x": [b"FieldOfViewX", b"", b"A+", "add_float64"],
-    "p_fov_y": [b"FieldOfViewY", b"", b"A+", "add_float64"],
-    "p_vector_3d": [b"Vector3D", b"Vector", b"", "add_float64", "add_float64", "add_float64"],
-    "p_lcl_translation": [b"Lcl Translation", b"", b"A+", "add_float64", "add_float64", "add_float64"],
-    "p_lcl_rotation": [b"Lcl Rotation", b"", b"A+", "add_float64", "add_float64", "add_float64"],
-    "p_lcl_scaling": [b"Lcl Scaling", b"", b"A+", "add_float64", "add_float64", "add_float64"],
-    "p_color_rgb": [b"ColorRGB", b"Color", b"", "add_float64", "add_float64", "add_float64"],
-    "p_string": [b"KString", b"", b"", "add_string_unicode"],
-    "p_string_url": [b"KString", b"Url", b"", "add_string_unicode"],
-    "p_timestamp": [b"KTime", b"Time", b"", "add_int64"],
-    "p_datetime": [b"DateTime", b"", b"", "add_string_unicode"],
-    "p_object": [b"object", b"", b""],  # XXX Check this! No value for this prop???
-    "p_compound": [b"Compound", b"", b""],  # XXX Check this! No value for this prop???
+    "p_bool": (b"bool", b"", "add_int32"),  # Yes, int32 for a bool (and they do have a core bool type)!!!
+    "p_integer": (b"int", b"Integer", "add_int32"),
+    "p_enum": (b"enum", b"", "add_int32"),
+    "p_number": (b"double", b"Number", "add_float64"),
+    "p_visibility": (b"Visibility", b"", "add_float64"),
+    "p_fov": (b"FieldOfView", b"", "add_float64"),
+    "p_fov_x": (b"FieldOfViewX", b"", "add_float64"),
+    "p_fov_y": (b"FieldOfViewY", b"", "add_float64"),
+    "p_vector_3d": (b"Vector3D", b"Vector", "add_float64", "add_float64", "add_float64"),
+    "p_lcl_translation": (b"Lcl Translation", b"", "add_float64", "add_float64", "add_float64"),
+    "p_lcl_rotation": (b"Lcl Rotation", b"", "add_float64", "add_float64", "add_float64"),
+    "p_lcl_scaling": (b"Lcl Scaling", b"", "add_float64", "add_float64", "add_float64"),
+    "p_color_rgb": (b"ColorRGB", b"Color", "add_float64", "add_float64", "add_float64"),
+    "p_string": (b"KString", b"", "add_string_unicode"),
+    "p_string_url": (b"KString", b"Url", "add_string_unicode"),
+    "p_timestamp": (b"KTime", b"Time", "add_int64"),
+    "p_datetime": (b"DateTime", b"", "add_string_unicode"),
+    "p_object": (b"object", b""),  # XXX Check this! No value for this prop???
+    "p_compound": (b"Compound", b""),
 }
 
 
-def _elem_props_set(elem, ptype, name, value):
+def _elem_props_set(elem, ptype, name, value, flags):
     p = elem_data_single_string(elem, b"P", name)
-    for t in ptype[:3]:
+    for t in ptype[:2]:
         p.add_string(t)
-    if len(ptype) == 4:
-        getattr(p, ptype[3])(value)
-    elif len(ptype) > 4:
+    p.add_string(flags)
+    if len(ptype) == 3:
+        getattr(p, ptype[2])(value)
+    elif len(ptype) > 3:
         # We assume value is iterable, else it's a bug!
-        for callback, val in zip(ptype[3:], value):
+        for callback, val in zip(ptype[2:], value):
             getattr(p, callback)(val)
 
 
-def elem_props_set(elem, ptype, name, value=None, custom=False):
+def _elem_props_flags(animatable, custom):
+    if animatable and custom:
+        return b"AU"
+    elif animatable:
+        return b"A"
+    elif custom:
+        return b"U"
+    return b""
+
+
+def elem_props_set(elem, ptype, name, value=None, animatable=False, custom=False):
     ptype = FBX_PROPERTIES_DEFINITIONS[ptype]
-    if custom:
-        ptype[2] = b"U"
-    _elem_props_set(elem, ptype, name, value)
+    _elem_props_set(elem, ptype, name, value, _elem_props_flags(animatable, custom))
 
 
-def elem_props_compound(elem, cmpd_name):
-    def _setter(ptype, name, value):
+def elem_props_compound(elem, cmpd_name, custom=False):
+    def _setter(ptype, name, value, animatable=False, custom=False):
         name = cmpd_name + b"|" + name
-        elem_props_set(elem, ptype, name, value)
+        elem_props_set(elem, ptype, name, value, animatable=animatable, custom=custom)
 
-    elem_props_set(elem, "p_compound", cmpd_name)
+    elem_props_set(elem, "p_compound", cmpd_name, custom=custom)
     return _setter
 
 
-def elem_props_template_set(template, elem, ptype_name, name, value, custom=False):
+def elem_props_template_set(template, elem, ptype_name, name, value, animatable=False):
     """
     Only add a prop if the same value is not already defined in given template.
     Note it is important to not give iterators as value, here!
     """
     ptype = FBX_PROPERTIES_DEFINITIONS[ptype_name]
-    if custom:
-        ptype[2] = b"U"
-    tmpl_val, tmpl_ptype = template.properties.get(name, (None, None))
+    tmpl_val, tmpl_ptype, tmpl_animatable = template.properties.get(name, (None, None, False))
+    # Note animatable flag from template takes precedence over given one, if applicable.
     if tmpl_ptype is not None:
-        if ((len(ptype) == 4 and (tmpl_val, tmpl_ptype) == (value, ptype_name)) or
-                (len(ptype) > 4 and (tuple(tmpl_val), tmpl_ptype) == (tuple(value), ptype_name))):
+        if ((len(ptype) == 3 and (tmpl_val, tmpl_ptype) == (value, ptype_name)) or
+                (len(ptype) > 3 and (tuple(tmpl_val), tmpl_ptype) == (tuple(value), ptype_name))):
             return  # Already in template and same value.
-    _elem_props_set(elem, ptype, name, value)
+        _elem_props_set(elem, ptype, name, value, _elem_props_flags(tmpl_animatable, False))
+    else:
+        _elem_props_set(elem, ptype, name, value, _elem_props_flags(animatable, False))
 
 
 ##### Generators for connection elements. #####
@@ -439,12 +450,12 @@ def fbx_templates_generate(root, fbx_templates):
             if prop_type_name and properties:
                 elem = elem_data_single_string(template, b"PropertyTemplate", prop_type_name)
                 props = elem_properties(elem)
-                for name, (value, ptype) in properties.items():
-                    elem_props_set(props, ptype, name, value)
+                for name, (value, ptype, animatable) in properties.items():
+                    elem_props_set(props, ptype, name, value, animatable=animatable)
 
 
 def fbx_template_def_globalsettings(scene, settings, override_defaults=None, nbr_users=0):
-    props = {}
+    props = OrderedDict()
     if override_defaults is not None:
         props.update(override_defaults)
     return FBXTemplate(b"GlobalSettings", b"", props, nbr_users)
@@ -452,78 +463,79 @@ def fbx_template_def_globalsettings(scene, settings, override_defaults=None, nbr
 
 def fbx_template_def_model(scene, settings, override_defaults=None, nbr_users=0):
     gscale = settings.global_scale
-    props = {
-        b"QuaternionInterpolate": (False, "p_bool"),
-        b"RotationOffset": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"RotationPivot": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"ScalingOffset": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"ScalingPivot": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"TranslationActive": (False, "p_bool"),
-        b"TranslationMin": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"TranslationMax": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"TranslationMinX": (False, "p_bool"),
-        b"TranslationMinY": (False, "p_bool"),
-        b"TranslationMinZ": (False, "p_bool"),
-        b"TranslationMaxX": (False, "p_bool"),
-        b"TranslationMaxY": (False, "p_bool"),
-        b"TranslationMaxZ": (False, "p_bool"),
-        b"RotationOrder": (0, "p_enum"),  # we always use 'XYZ' order.
-        b"RotationSpaceForLimitOnly": (False, "p_bool"),
-        b"RotationStiffnessX": (0.0, "p_number"),
-        b"RotationStiffnessY": (0.0, "p_number"),
-        b"RotationStiffnessZ": (0.0, "p_number"),
-        b"AxisLen": (10.0, "p_number"),
-        b"PreRotation": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"PostRotation": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"RotationActive": (False, "p_bool"),
-        b"RotationMin": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"RotationMax": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"RotationMinX": (False, "p_bool"),
-        b"RotationMinY": (False, "p_bool"),
-        b"RotationMinZ": (False, "p_bool"),
-        b"RotationMaxX": (False, "p_bool"),
-        b"RotationMaxY": (False, "p_bool"),
-        b"RotationMaxZ": (False, "p_bool"),
-        b"InheritType": (1, "p_enum"),  # RSrs
-        b"ScalingActive": (False, "p_bool"),
-        b"ScalingMin": (Vector((1.0, 1.0, 1.0)) * gscale, "p_vector_3d"),
-        b"ScalingMax": (Vector((1.0, 1.0, 1.0)) * gscale, "p_vector_3d"),
-        b"ScalingMinX": (False, "p_bool"),
-        b"ScalingMinY": (False, "p_bool"),
-        b"ScalingMinZ": (False, "p_bool"),
-        b"ScalingMaxX": (False, "p_bool"),
-        b"ScalingMaxY": (False, "p_bool"),
-        b"ScalingMaxZ": (False, "p_bool"),
-        b"GeometricTranslation": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"GeometricRotation": ((0.0, 0.0, 0.0), "p_vector_3d"),
-        b"GeometricScaling": (Vector((1.0, 1.0, 1.0))

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list