Posted: Mon May 14, 2012 10:06 am
Joined: 14 May 2012
Posts: 4
Hi, I'm working on updating my .blend file reader to the be able to read BMesh data. At this point, I have everything working except for the material index - The value in MPoly.mat_nr doesn't seem to correspond to the material index as I previously understood it. For example, I have a mesh with 3 materials saved as a .blend file. When I look at the Mesh.mat array, I see that there are in fact 3 materials in the list. But when I look at the Mesh.mpoly list, all of the values for mat_nr are zero.
(If you are wondering why I am reading .blend files, this is to do offline bulk conversions.)
Posted: Tue May 15, 2012 11:27 pm
Joined: 05 Apr 2009
Posts: 680
material_index of 0 means the first material of object is assigned to that polygon. If there wasn't a material assigned, it would be -1
This is python, but i believe the relationships equal in C code:
| Code: |
mat_index = bpy.data.objects['Mesh'].data.polygons[0].material_index
mat = bpy.data.objects['Mesh'].data.materials[mat_index]
# mat is bpy.data.materials['Material'] |
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Wed May 16, 2012 8:03 am
Joined: 14 May 2012
Posts: 4
| CoDEmanX wrote: |
material_index of 0 means the first material of object is assigned to that polygon. If there wasn't a material assigned, it would be -1
This is python, but i believe the relationships equal in C code:
| Code: | mat_index = bpy.data.objects['Mesh'].data.polygons[0].material_index
mat = bpy.data.objects['Mesh'].data.materials[mat_index]
# mat is bpy.data.materials['Material'] |
|
I've inspected the data using the methods you suggested. What I am seeing is that every polygon has a material index of 0, even though the mesh uses three different materials. So I'm still confused.
And before you ask:
* It's a single object, not several different objects.
* The object has multiple materials each having a different texture.
* I can see all three materials in the 3d modeling window.
However, this does clear up one point - since I'm seeing the same thing in memory as I am seeing in the .blend file, that means that it's not a problem with my .blend file reader.
But I don't understand how I can be seeing multiple materials in the editor, and yet every polygon has a material_index of 0.
Posted: Wed May 16, 2012 8:06 am
Joined: 14 May 2012
Posts: 4
Here's an example of what I am seeing:
| Code: |
>>> [poly.material_index for poly in bpy.data.objects['Wall'].data.polygons]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
Posted: Wed May 16, 2012 8:24 am
Joined: 14 May 2012
Posts: 4
I figured it out - they were all using the same material, but different textures because the UV maps were different. The relationship between the UV map texture and the material texture is something that I frequently find confusing.