From 8603399f19ce73ff7e219137028d2d38faa5edd8 Mon Sep 17 00:00:00 2001 From: TigerKat Date: Tue, 13 Apr 2021 00:59:46 +0930 Subject: [PATCH] bugfix: Wasn't creating materials for a mesh, and the material indexes it was already generating were wrong. --- __init__.py | 2 +- geo.py | 1 + geomesh.py | 4 ++++ import_geo.py | 9 +++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 8214d1d..c8bcfdc 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ bl_info = { "name": "City of Heroes (.geo)", "author": "TigerKat", - "version": (0, 2, 8), + "version": (0, 2, 9), "blender": (2, 80, 0), "location": "File > Import/Export,", "description": "City of Heroes (.geo)", diff --git a/geo.py b/geo.py index 21d9b67..7ec24b9 100755 --- a/geo.py +++ b/geo.py @@ -947,6 +947,7 @@ class Model: v = GeoVertex(coord, normal, uv, weights) geomesh.getGeoVertexIndexNew(v) texture_indexes = [] + #print("Geo.tex_idx: %s Geo.geo.header_texnames: %s" % (self.tex_idx, self.geo.header_texnames)) for t in self.tex_idx: texture_indexes += [geomesh.getTextureIndex(self.geo.header_texnames[t[0]])] * t[1] #print("len(self.verts): %s" % (len(self.verts), )) diff --git a/geomesh.py b/geomesh.py index 2348725..cbdea24 100644 --- a/geomesh.py +++ b/geomesh.py @@ -73,7 +73,11 @@ class GeoMesh: self.geovertex.append(gv) return index def getTextureIndex(self, name): + if isinstance(name, int): + #Convenience, assume ints are from a previous look up. + return name index = self.textures_map.get(name, len(self.textures)) + #print("GeoMesh.getTextureIndex(%s): %s" % (name, index)) if index == len(self.textures): self.textures_map[name] = index self.textures.append(name) diff --git a/import_geo.py b/import_geo.py index 84183c2..e0fdd67 100644 --- a/import_geo.py +++ b/import_geo.py @@ -44,6 +44,15 @@ def convert_model(geo_model, mesh_data, obj, scale): indices = [i for face in geomesh.face for i in import_fix_winding(face.vert_indexes)] texture_indices = [face.texture_index for face in geomesh.face] + #Create materials for textures. + mesh_data.materials.clear() + #print("geomesh.textures: %s" % (geomesh.textures,)) + for i, tex_name in enumerate(geomesh.textures): + #if isinstance(tex_name, int): + # continue + #print("tex_name: %s" % tex_name) + mesh_data.materials.append(bpy.data.materials.new(tex_name.decode("utf-8"))) + mesh_data.vertices.add(len(geomesh.geovertex)) mesh_data.loops.add(len(indices)) mesh_data.polygons.add(len(geomesh.face))