[Bf-extensions-cvs] [b3fdb7d] fbx_io_development: - import custom properties - introduce settings object to store conversion parameters - export 3 item list properties as vector

Jens Ch. Restemeier noreply at git.blender.org
Wed Jul 30 10:03:41 CEST 2014


Commit: b3fdb7d6cc4196e906a33ae77e978ed541d4842d
Author: Jens Ch. Restemeier
Date:   Tue Jul 29 09:49:25 2014 +0100
Branches: fbx_io_development
https://developer.blender.org/rBAb3fdb7d6cc4196e906a33ae77e978ed541d4842d

- import custom properties
- introduce settings object to store conversion parameters
- export 3 item list properties as vector

- renamed export-specific settings into FBXExport*
- renamed FBXSettingsImport into FBXImportSettings
- added ColorRGB and ColorRGBA types
- removed debug print
- grouped import settings by use

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

M	io_scene_fbx/__init__.py
M	io_scene_fbx/export_fbx_bin.py
M	io_scene_fbx/fbx_utils.py
M	io_scene_fbx/import_fbx.py

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

diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index 6e0c105..b359f11 100644
--- a/io_scene_fbx/__init__.py
+++ b/io_scene_fbx/__init__.py
@@ -121,6 +121,20 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
         options={'HIDDEN'}
     )
 
+    use_custom_properties = BoolProperty(
+        name="Import user properties",
+        description="Import user properties as custom properties",
+        default=True,
+        options={'HIDDEN'}
+    )
+    
+    import_enum_properties_as_string = BoolProperty(
+        name="Import enum properties as string",
+        description="Store enumeration values as string",
+        default=True,
+        options={'HIDDEN'}
+    )
+    
     def draw(self, context):
         layout = self.layout
 
@@ -135,6 +149,11 @@ class ImportFBX(bpy.types.Operator, ImportHelper):
         #layout.prop(self, "use_alpha_decals")
         layout.prop(self, "decal_offset")
 
+        layout.prop(self, "use_custom_properties")
+        sub = layout.row()
+        sub.enabled = self.use_custom_properties
+        sub.prop(self, "import_enum_properties_as_string")
+        
     def execute(self, context):
         keywords = self.as_keywords(ignore=("filter_glob", "directory"))
         keywords["use_cycles"] = (context.scene.render.engine == 'CYCLES')
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index de38f0a..b9daf34 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -89,7 +89,7 @@ from .fbx_utils import (
     # Objects.
     ObjectWrapper, fbx_name_class,
     # Top level.
-    FBXSettingsMedia, FBXSettings, FBXData,
+    FBXExportSettingsMedia, FBXExportSettings, FBXExportData,
 )
 
 # Units convertors!
@@ -530,13 +530,19 @@ def fbx_data_element_custom_properties(props, bid):
     Store custom properties of blender ID bid (any mapping-like object, in fact) into FBX properties props.
     """
     for k, v in bid.items():
+        to_list = getattr(v, "to_list", None)
+        list_val = None
+        if to_list:
+            list_val = to_list()
+    
         if isinstance(v, str):
             elem_props_set(props, "p_string", k.encode(), v, custom=True)
         elif isinstance(v, int):
             elem_props_set(props, "p_integer", k.encode(), v, custom=True)
-        if isinstance(v, float):
+        elif isinstance(v, float):
             elem_props_set(props, "p_double", k.encode(), v, custom=True)
-
+        elif list_val and len(list_val) == 3:
+            elem_props_set(props, "p_vector", k.encode(), list_val, custom=True)
 
 def fbx_data_empty_elements(root, empty, scene_data):
     """
@@ -2090,7 +2096,7 @@ def fbx_data_from_scene(scene, settings):
     frame_end = scene.frame_end
     if settings.bake_anim:
         # From objects & bones only for a start.
-        tmp_scdata = FBXData(  # Kind of hack, we need a temp scene_data for object's space handling to bake animations...
+        tmp_scdata = FBXExportData(  # Kind of hack, we need a temp scene_data for object's space handling to bake animations...
             None, None, None,
             settings, scene, objects, None, 0.0, 0.0,
             data_empties, data_lamps, data_cameras, data_meshes, None,
@@ -2297,7 +2303,7 @@ def fbx_data_from_scene(scene, settings):
 
     ##### And pack all this!
 
-    return FBXData(
+    return FBXExportData(
         templates, templates_users, connections,
         settings, scene, objects, animations, frame_start, frame_end,
         data_empties, data_lamps, data_cameras, data_meshes, mesh_mat_indices,
@@ -2602,7 +2608,7 @@ def save_single(operator, scene, filepath="",
     if embed_textures and path_mode != 'COPY':
         embed_textures = False
 
-    media_settings = FBXSettingsMedia(
+    media_settings = FBXExportSettingsMedia(
         path_mode,
         os.path.dirname(bpy.data.filepath),  # base_src
         os.path.dirname(filepath),  # base_dst
@@ -2612,7 +2618,7 @@ def save_single(operator, scene, filepath="",
         set(),  # copy_set
     )
 
-    settings = FBXSettings(
+    settings = FBXExportSettings(
         operator.report, (axis_up, axis_forward), global_matrix, global_scale,
         bake_space_transform, global_matrix_inv, global_matrix_inv_transposed,
         context_objects, object_types, use_mesh_modifiers,
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index 0db26c5..2d2805c 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -1059,13 +1059,13 @@ def fbx_name_class(name, cls):
 ##### Top-level FBX data container. #####
 
 # Helper sub-container gathering all exporter settings related to media (texture files).
-FBXSettingsMedia = namedtuple("FBXSettingsMedia", (
+FBXExportSettingsMedia = namedtuple("FBXExportSettingsMedia", (
     "path_mode", "base_src", "base_dst", "subdir",
     "embed_textures", "copy_set",
 ))
 
 # Helper container gathering all exporter settings.
-FBXSettings = namedtuple("FBXSettings", (
+FBXExportSettings = namedtuple("FBXExportSettings", (
     "report", "to_axes", "global_matrix", "global_scale",
     "bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed",
     "context_objects", "object_types", "use_mesh_modifiers",
@@ -1081,10 +1081,18 @@ FBXSettings = namedtuple("FBXSettings", (
 #     * object data.
 #     * skinning data (binding armature/mesh).
 #     * animations.
-FBXData = namedtuple("FBXData", (
+FBXExportData = namedtuple("FBXExportData", (
     "templates", "templates_users", "connections",
     "settings", "scene", "objects", "animations", "frame_start", "frame_end",
     "data_empties", "data_lamps", "data_cameras", "data_meshes", "mesh_mat_indices",
     "data_bones", "data_deformers_skin", "data_deformers_shape",
     "data_world", "data_materials", "data_textures", "data_videos",
 ))
+
+# Helper container gathering all importer settings.
+FBXImportSettings = namedtuple("FBXImportSettings", (
+    "report", "to_axes", "global_matrix", "global_scale",
+    "use_cycles", "use_image_search", 
+    "use_alpha_decals", "decal_offset", 
+    "use_custom_properties", "import_enum_properties_as_string"
+))
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index c12739b..6dfc062 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -44,6 +44,7 @@ from .fbx_utils import (
     array_to_matrix4,
     similar_values,
     similar_values_iter,
+    FBXImportSettings
 )
 
 # global singleton, assign on execution
@@ -276,6 +277,60 @@ FBXTransformData = namedtuple("FBXTransformData", (
 
 object_tdata_cache = {}
 
+def blen_read_custom_properties(fbx_obj, blen_obj, settings):
+    # There doesn't seem to be a way to put user properties into templates, so this only get the object properties:
+    fbx_obj_props = elem_find_first(fbx_obj, b'Properties70')
+    if fbx_obj_props:
+        for fbx_prop in fbx_obj_props.elems:
+            assert(fbx_prop.id == b'P')
+
+            if b'U' in fbx_prop.props[3]:
+                if fbx_prop.props[0] == b'UDP3DSMAX':
+                    # Special case for 3DS Max user properties:
+                    assert(fbx_prop.props[1] == b'KString')
+                    assert(fbx_prop.props_type[4] == data_types.STRING)
+                    items = fbx_prop.props[4].decode('utf-8')
+                    keyvaluelist = [(key.strip(), value.strip()) for key, value in [tuple(item.split('=', 1)) for item in items.split('\r\n') if len(item) > 0]]
+                    for prop_name, prop_value in keyvaluelist:
+                        blen_obj[prop_name] = prop_value
+                else:
+                    prop_name = fbx_prop.props[0].decode('utf-8')
+                    prop_type = fbx_prop.props[1]
+                    if prop_type in [b'Vector', b'Vector3D', b'Color', b'ColorRGB']:
+                        assert(fbx_prop.props_type[4:7] == bytes((data_types.FLOAT64,)) * 3)
+                        blen_obj[prop_name] = fbx_prop.props[4:7]
+                    elif prop_type in [b'Vector4', b'ColorRGBA']:
+                        assert(fbx_prop.props_type[4:8] == bytes((data_types.FLOAT64,)) * 4)
+                        blen_obj[prop_name] = fbx_prop.props[4:8]
+                    elif prop_type == b'Vector2D':
+                        assert(fbx_prop.props_type[4:6] == bytes((data_types.FLOAT64,)) * 2)
+                        blen_obj[prop_name] = fbx_prop.props[4:6]
+                    elif prop_type in [b'Integer', b'int']:
+                        assert(fbx_prop.props_type[4] == data_types.INT32)
+                        blen_obj[prop_name] = fbx_prop.props[4]
+                    elif prop_type == b'KString':
+                        assert(fbx_prop.props_type[4] == data_types.STRING)
+                        blen_obj[prop_name] = fbx_prop.props[4].decode('utf-8')
+                    elif prop_type == b'Number':
+                        assert(fbx_prop.props_type[4] == data_types.FLOAT64)
+                        blen_obj[prop_name] = fbx_prop.props[4]
+                    elif prop_type in [b'Float', b'float']:
+                        assert(fbx_prop.props_type[4] == data_types.FLOAT32)
+                        blen_obj[prop_name] = fbx_prop.props[4]
+                    elif prop_type in [b'Bool', b'bool']:
+                        assert(fbx_prop.props_type[4] == data_types.INT32)
+                        blen_obj[prop_name] = fbx_prop.props[4] != 0
+                    elif prop_type in [b'Enum', b'enum']:
+                        assert(fbx_prop.props_type[4:6] == bytes((data_types.INT32, data_types.STRING)))
+                        val = fbx_prop.props[4]
+                        if settings.import_enum_properties_as_string:
+                            enum_items = fbx_prop.props[5].decode('utf-8').split('~')
+                            assert(val >= 0 and val < len(enum_items))
+                            blen_obj[prop_name] = enum_items[val]
+                        else:
+                            blen_obj[prop_name] = val
+                    else:
+                        print ("WARNING: User property type '%s' is not supported" % prop_type.decode('utf-8'))
 
 def blen_read_object_transform_do(t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list