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:
authorCampbell Barton <ideasman42@gmail.com>2011-04-18 13:18:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-04-18 13:18:24 +0400
commita5453436ebc34e338a12041f9cfaad1f07fb2404 (patch)
tree877d6c4287d13d414562d706c5d8c9fff4c42bb2 /io_scene_3ds
parent8ff6c903b5cd1a37a1106ba703d8aa4b5fd160f6 (diff)
fix for error with file reported over IRC, some files dont define material names referenced.
Diffstat (limited to 'io_scene_3ds')
-rw-r--r--io_scene_3ds/import_3ds.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py
index 856698a7..1aea6384 100644
--- a/io_scene_3ds/import_3ds.py
+++ b/io_scene_3ds/import_3ds.py
@@ -248,7 +248,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
#contextMatrix_tx = None # Blender.mathutils.Matrix(); contextMatrix.identity()
contextMesh_vertls = None # flat array: (verts * 3)
contextMesh_facels = None
- contextMeshMaterials = {} # matname:[face_idxs]
+ contextMeshMaterials = [] # (matname, [face_idxs])
contextMeshUV = None # flat array (verts * 2)
TEXTURE_DICT = {}
@@ -294,12 +294,18 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
else:
uv_faces = None
- for mat_idx, (matName, faces) in enumerate(myContextMeshMaterials.items()):
+ for mat_idx, (matName, faces) in enumerate(myContextMeshMaterials):
if matName is None:
bmat = None
else:
- bmat = MATDICT[matName][1]
- img = TEXTURE_DICT.get(bmat.name)
+ bmat = MATDICT.get(matName)
+ # in rare cases no materials defined.
+ if bmat:
+ img = TEXTURE_DICT.get(bmat.name)
+ else:
+ print(" warning: material %r not defined!" % matName)
+ bmat = MATDICT[matName] = bpy.data.materials.new(matName)
+ img = None
bmesh.materials.append(bmat) # can be None
@@ -423,7 +429,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
contextMesh_facels = []
## preparando para receber o proximo objeto
- contextMeshMaterials = {} # matname:[face_idxs]
+ contextMeshMaterials = [] # matname:[face_idxs]
contextMeshUV = None
#contextMesh.vertexUV = 1 # Make sticky coords.
# Reset matrix
@@ -452,7 +458,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
new_chunk.bytes_read += read_str_len
contextMaterial.name = material_name.rstrip() # remove trailing whitespace
- MATDICT[material_name] = (contextMaterial.name, contextMaterial)
+ MATDICT[material_name] = contextMaterial
elif (new_chunk.ID == MAT_AMBIENT):
#print 'elif (new_chunk.ID == MAT_AMBIENT):'
@@ -597,7 +603,9 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
temp_data = file.read(STRUCT_SIZE_UNSIGNED_SHORT * num_faces_using_mat)
new_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT * num_faces_using_mat
- contextMeshMaterials[material_name] = struct.unpack("<%dH" % (num_faces_using_mat), temp_data)
+ temp_data = struct.unpack("<%dH" % (num_faces_using_mat), temp_data)
+
+ contextMeshMaterials.append((material_name, temp_data))
#look up the material in all the materials