Skip to content

Commit

Permalink
add a temporary material for baking when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
addam committed May 1, 2023
1 parent 2ff2202 commit ec81e7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 0 additions & 2 deletions pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


11 changes: 10 additions & 1 deletion unfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit ec81e7c

Please sign in to comment.