Skip to content

Commit ec81e7c

Browse files
committed
add a temporary material for baking when necessary
1 parent 2ff2202 commit ec81e7c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pdf.py

-2
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,3 @@ def encode(data):
237237
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"
238238
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"
239239
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"
240-
241-

unfolder.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,19 @@ def save_separate_images(self, scale, filepath, embed=None):
529529
bpy.data.images.remove(image)
530530

531531
def bake(self, faces, image):
532+
# FIXME: as of 3.5.0, this detection does not work properly
533+
# and one of existing 8 UVLayers would be overwritten
532534
if not self.looptex:
533535
raise UnfoldError("The mesh has no UV Map slots left. Either delete a UV Map or export the net without textures.")
534536
ob = bpy.context.active_object
535537
me = ob.data
536538
# in Cycles, the image for baking is defined by the active Image Node
537539
temp_nodes = dict()
538-
for mat in me.materials:
540+
temp_mat = None
541+
if not any(me.materials):
542+
temp_mat = bpy.data.materials.new("Unfolded")
543+
me.materials.append(temp_mat)
544+
for mat in filter(None, me.materials):
539545
mat.use_nodes = True
540546
img = mat.node_tree.nodes.new('ShaderNodeTexImage')
541547
img.image = image
@@ -556,6 +562,9 @@ def bake(self, faces, image):
556562
finally:
557563
for mat, node in temp_nodes.items():
558564
mat.node_tree.nodes.remove(node)
565+
if temp_mat:
566+
me.materials.pop()
567+
bpy.data.materials.remove(temp_mat)
559568
for uv in ignored_uvs:
560569
uv *= -1
561570

0 commit comments

Comments
 (0)