From 07747bcf64963eefaff8aaa9cee24ed652fda5b9 Mon Sep 17 00:00:00 2001
From: Bastien Montagne <montagne29@wanadoo.fr>
Date: Mon, 11 Aug 2014 13:03:43 +0200
Subject: [PATCH] Fix T41396: FBX export fails with some very simple material
 setups.

---
 io_scene_fbx/export_fbx_bin.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index 228d993f7..16ff3ba7b 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1101,7 +1101,8 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
                 me.polygons.foreach_get("material_index", t_pm)
 
                 # We have to validate mat indices, and map them to FBX indices.
-                blmats_to_fbxmats_idxs = [me_fbxmats_idx[m] for m in me_blmats]
+                # Note a mat might not be in me_fbxmats_idx (e.g. node mats are ignored).
+                blmats_to_fbxmats_idxs = [me_fbxmats_idx[m] for m in me_blmats if m in me_fbxmats_idx]
                 mat_idx_limit = len(blmats_to_fbxmats_idxs)
                 def_mat = blmats_to_fbxmats_idxs[0]
                 _gen = (blmats_to_fbxmats_idxs[m] if m < mat_idx_limit else def_mat for m in t_pm)
-- 
GitLab