X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fmesh.py;h=8009191f080a045468c36908cee738a988e562e4;hb=160293feec7b0b976856685153cd24c7f1ce9492;hp=9741b8dd916f28495d3e25cde8fd64e767a7d118;hpb=86721a55699193e63c76e8a0a7b0ced0416c1cce;p=libs%2Fgl.git diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index 9741b8dd..8009191f 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -158,8 +158,8 @@ class Mesh: self.winding_test = mesh.winding_test self.smoothing = mesh.smoothing self.use_uv = mesh.use_uv - self.tangent_vecs = mesh.tangent_vecs self.tangent_uvtex = mesh.tangent_uvtex + self.use_strips = mesh.use_strips self.vertex_groups = mesh.vertex_groups # Clone basic data @@ -207,7 +207,7 @@ class Mesh: edge_map = {e.key: e for e in self.edges} for f in self.faces: if len(f.vertices)>4: - raise ValueError("Ngons are not supported") + raise ValueError("Unsupported face on mesh {}: N-gon".format(self.name)) f.vertices = [self.vertices[i] for i in f.vertices] for v in f.vertices: @@ -229,6 +229,21 @@ class Mesh: else: self.lines = [] + # Check if tangent vectors are needed + if mesh.tangent_vecs=='NO': + self.tangent_vecs = False + elif mesh.tangent_vecs=='YES': + self.tangent_vecs = True + elif mesh.tangent_vecs=='AUTO': + from .material import Material + self.tangent_vecs = False + for m in self.materials: + mat = Material(m) + if mat.type=="pbr": + normal_prop = next((p for p in mat.properties if p.tex_keyword=="normal_map"), None) + if normal_prop and normal_prop.texture: + self.tangent_vecs = True + self.vertex_sequence = [] def transform(self, matrix): @@ -237,10 +252,10 @@ class Mesh: def splice(self, other): if len(self.uv_layers)!=len(other.uv_layers): - raise ValueError("Meshes have incompatible UV layers") + raise ValueError("Meshes {} and {} have incompatible UV layers".format(self.name, other.name)) for i, u in enumerate(self.uv_layers): if u.name!=other.uv_layers[i].name: - raise ValueError("Meshes have incompatible UV layers") + raise ValueError("Meshes {} and {} have incompatible UV layers".format(self.name, other.name)) # Merge materials and form a lookup from source material indices to the # merged material list @@ -403,7 +418,7 @@ class Mesh: def apply_material_atlas(self, material_atlas): for m in self.materials: if m.name not in material_atlas.material_names: - raise Exception("Material atlas is not compatible with Mesh") + raise Exception("Material atlas {} is not compatible with Mesh {}".format(material_atlas.name, self.name)) if self.use_uv=='NONE': return @@ -465,7 +480,7 @@ class Mesh: progress.pop_task() prog_step = 2 else: - raise Exception("Tangent UV layer not found") + raise Exception("Invalid configuration on mesh {}: No tangent UV layer".format(self.name)) # Split by the remaining UV layers for i, u in enumerate(self.uv_layers): @@ -780,9 +795,9 @@ class Mesh: e.key = make_edge_key(e.vertices[0].index, e.vertices[1].index) -def create_mesh_from_object(context, obj, progress, *, material_atlas=None): +def create_mesh_from_object(context, obj, material_atlas, progress): if obj.type!="MESH": - raise Exception("Object is not a mesh") + raise Exception("Object {} is not a mesh".format(obj.name)) progress.push_task("Preparing mesh", 0.0, 0.2)