Skip to content

Commit

Permalink
Reuse materials and set default material name
Browse files Browse the repository at this point in the history
  • Loading branch information
sercero committed Mar 23, 2024
1 parent 5448b31 commit 30e77e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions io_ogre/ogre/ogre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
[[vertexNumber], [weight]], [[vertexNumber], [weight]], ..
['submeshes'][idx]
[material] - string (material name)
[materialOrg] - original material name - for searching the in shared materials file
[materialOrig] - original material name - for searching in the shared materials file
[faces] - vectors with faces [v1,v2,v3]
[geometry] - identical to 'sharedgeometry' data content
['materials']
Expand Down Expand Up @@ -287,12 +287,14 @@ def xCollectMeshData(meshData, xmldoc, meshname, dirname):
for submeshes in xmldoc.getElementsByTagName('submeshes'):
for submesh in submeshes.childNodes:
if submesh.localName == 'submesh':
materialOrg = str(submesh.getAttributeNode('material').value)
materialOrig = "Material"
if submesh.getAttributeNode('material') is not None:
materialOrig = str(submesh.getAttributeNode('material').value)
# To avoid Blender naming limit problems
material = GetValidBlenderName(materialOrg)
material = GetValidBlenderName(materialOrig)
sm = {}
sm['material'] = material
sm['materialOrg'] = materialOrg
sm['materialOrig'] = materialOrig
for subnodes in submesh.childNodes:
if subnodes.localName == 'faces':
facescount = int(subnodes.getAttributeNode('count').value)
Expand Down Expand Up @@ -1050,7 +1052,11 @@ def bCreateSubMeshes(meshData, meshName):
Report.materials.append(subMeshName)

# Create shadeless material and MTex
mat = bpy.data.materials.new(subMeshName)
mat = None
if subMeshName not in bpy.data.materials:
mat = bpy.data.materials.new(subMeshName)
else:
mat = bpy.data.materials.get(subMeshName)

mat.use_nodes = True

Expand Down

0 comments on commit 30e77e3

Please sign in to comment.