From ec81e7c5b5fe8a23df637b531b770b8fc5500eea Mon Sep 17 00:00:00 2001 From: Adam Dominec Date: Mon, 1 May 2023 10:01:25 +0200 Subject: [PATCH] add a temporary material for baking when necessary --- pdf.py | 2 -- unfolder.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pdf.py b/pdf.py index b15da86..e907933 100644 --- a/pdf.py +++ b/pdf.py @@ -237,5 +237,3 @@ def encode(data): command_sticker = "q /F1 {size:.6f} Tf {mat[0][0]:.6f} {mat[1][0]:.6f} {mat[0][1]:.6f} {mat[1][1]:.6f} {pos.x:.6f} {pos.y:.6f} cm BT {align:.6f} 0 Td ({label}) Tj ET Q" command_arrow = "q /F1 {size:.6f} Tf BT {pos.x:.6f} {pos.y:.6f} Td ({index}) Tj ET {mat[0][0]:.6f} {mat[1][0]:.6f} {mat[0][1]:.6f} {mat[1][1]:.6f} {arrow_pos.x:.6f} {arrow_pos.y:.6f} cm 0 0 m 1 -1 l 0 -0.25 l -1 -1 l f Q" command_number = "q /F1 {size:.6f} Tf {mat[0][0]:.6f} {mat[1][0]:.6f} {mat[0][1]:.6f} {mat[1][1]:.6f} {pos.x:.6f} {pos.y:.6f} cm BT ({label}) Tj ET Q" - - diff --git a/unfolder.py b/unfolder.py index 4e0389b..f46fbc8 100644 --- a/unfolder.py +++ b/unfolder.py @@ -529,13 +529,19 @@ def save_separate_images(self, scale, filepath, embed=None): bpy.data.images.remove(image) def bake(self, faces, image): + # FIXME: as of 3.5.0, this detection does not work properly + # and one of existing 8 UVLayers would be overwritten if not self.looptex: raise UnfoldError("The mesh has no UV Map slots left. Either delete a UV Map or export the net without textures.") ob = bpy.context.active_object me = ob.data # in Cycles, the image for baking is defined by the active Image Node temp_nodes = dict() - for mat in me.materials: + temp_mat = None + if not any(me.materials): + temp_mat = bpy.data.materials.new("Unfolded") + me.materials.append(temp_mat) + for mat in filter(None, me.materials): mat.use_nodes = True img = mat.node_tree.nodes.new('ShaderNodeTexImage') img.image = image @@ -556,6 +562,9 @@ def bake(self, faces, image): finally: for mat, node in temp_nodes.items(): mat.node_tree.nodes.remove(node) + if temp_mat: + me.materials.pop() + bpy.data.materials.remove(temp_mat) for uv in ignored_uvs: uv *= -1