Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse materials and set default material name #216

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading