Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-02-04 17:18:13 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-02-04 17:18:13 +0300
commit6a090568c38e4fe6d6d096681de59ca940a054ba (patch)
tree97cae310bec97a05d245e45c9c619eb6bcb76ea5 /io_scene_fbx/import_fbx.py
parent80e4d25bfb79b07f38f32818885d6c5886e5e7dd (diff)
FBX import: tweak a bit image/texture loading (e.g. try to use relpath first), add support for embeded images.
Diffstat (limited to 'io_scene_fbx/import_fbx.py')
-rw-r--r--io_scene_fbx/import_fbx.py45
1 files changed, 35 insertions, 10 deletions
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 93e8fdeb..67dfd845 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -113,6 +113,13 @@ def elem_name_ensure_class(elem, clss=...):
return elem_name.decode('utf-8')
+def elem_name_ensure_classes(elem, clss=...):
+ elem_name, elem_class = elem_split_name_class(elem)
+ if clss is not ...:
+ assert(elem_class in clss)
+ return elem_name.decode('utf-8')
+
+
def elem_split_name_class_nodeattr(elem):
assert(elem.props_type[-2] == data_types.STRING)
elem_name, elem_class = elem.props[-2].split(b'\x00\x01')
@@ -1195,21 +1202,22 @@ def blen_read_material(fbx_tmpl, fbx_obj, settings):
# -------
-# Texture
+# Image & Texture
-def blen_read_texture(fbx_tmpl, fbx_obj, basedir, settings):
+def blen_read_texture_image(fbx_tmpl, fbx_obj, basedir, settings):
import os
from bpy_extras import image_utils
- elem_name_utf8 = elem_name_ensure_class(fbx_obj, b'Texture')
+ elem_name_utf8 = elem_name_ensure_classes(fbx_obj, {b'Texture', b'Video'})
image_cache = settings.image_cache
- filepath = elem_find_first_string(fbx_obj, b'FileName')
- if os.sep == '/':
- filepath = filepath.replace('\\', '/')
+ filepath = elem_find_first_string(fbx_obj, b'RelativeFileName')
+ if filepath:
+ filepath = os.path.join(basedir, filepath)
else:
- filepath = filepath.replace('/', '\\')
+ filepath = elem_find_first_string(fbx_obj, b'FileName')
+ filepath = filepath.replace('\\', '/') if (os.sep == '/') else filepath.replace('/', '\\')
image = image_cache.get(filepath)
if image is not None:
@@ -1222,6 +1230,14 @@ def blen_read_texture(fbx_tmpl, fbx_obj, basedir, settings):
recursive=settings.use_image_search,
)
+ # Try to use embedded data, if available!
+ data = elem_find_first_bytes(fbx_obj, b'Content')
+ if (data):
+ data_len = len(data)
+ print(data_len)
+ if (data_len):
+ image.pack(data=data, data_len=data_len)
+
image_cache[filepath] = image
# name can be ../a/b/c
image.name = os.path.basename(elem_name_utf8)
@@ -2145,15 +2161,24 @@ def load(operator, context, filepath="",
_(); del _
# ----
- # Load image data
+ # Load image & textures data
def _():
- fbx_tmpl = fbx_template_get((b'Texture', b'KFbxFileTexture'))
+ fbx_tmpl_tex = fbx_template_get((b'Texture', b'KFbxFileTexture'))
+ fbx_tmpl_img = fbx_template_get((b'Video', b'KFbxVideo'))
+ # Important to run all 'Video' ones first, embedded images are stored in those nodes.
+ # XXX Note we simplify things here, assuming both matching Video and Texture will use same file path,
+ # this may be a bit weak, if issue arise we'll fallback to plain connection stuff...
+ for fbx_uuid, fbx_item in fbx_table_nodes.items():
+ fbx_obj, blen_data = fbx_item
+ if fbx_obj.id != b'Video':
+ continue
+ fbx_item[1] = blen_read_texture_image(fbx_tmpl_img, fbx_obj, basedir, settings)
for fbx_uuid, fbx_item in fbx_table_nodes.items():
fbx_obj, blen_data = fbx_item
if fbx_obj.id != b'Texture':
continue
- fbx_item[1] = blen_read_texture(fbx_tmpl, fbx_obj, basedir, settings)
+ fbx_item[1] = blen_read_texture_image(fbx_tmpl_tex, fbx_obj, basedir, settings)
_(); del _
# ----