From 2288a47e4ae8508cec651cedd0dd6c24fe779b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=85=9C?= <2082529121@qq.com> Date: Wed, 25 Feb 2026 10:04:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B8=B2=E6=9F=93):=20=E5=9C=A8=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=BF=87=E7=A8=8B=E4=B8=AD=E9=9A=94=E7=A6=BB=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E4=BB=A5=E9=81=BF=E5=85=8D=E5=B9=B2=E6=89=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在生成深度、法线和线稿贴图前,先保存所有对象的原始渲染可见状态,然后仅显示当前活动对象(或转换后的对象)进行渲染。渲染完成后恢复所有对象的原始渲染可见状态,防止其他对象在渲染过程中产生干扰。 --- utils.py | 73 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/utils.py b/utils.py index be6ee4e..3bb2983 100644 --- a/utils.py +++ b/utils.py @@ -491,40 +491,45 @@ class Comfy_OT_Mvgen_B6229(bpy.types.Operator): else: if (None is not bpy.context.view_layer.objects.active): if bpy.context.view_layer.objects.active.type == 'MESH': - bpy.context.scene.sna_activeobject = bpy.context.view_layer.objects.active - bpy.context.scene.sna_activeobject_name = bpy.context.scene.sna_activeobject.name - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) - if property_exists("bpy.data.node_groups['UV_New']", globals(), locals()): - pass - else: - before_data = list(bpy.data.node_groups) - bpy.ops.wm.append(directory=os.path.join(os.path.dirname(__file__), 'assets', 'geonodesuvpack.blend') + r'\NodeTree', filename='UV_New', link=False) - new_data = list(filter(lambda d: d not in before_data, list(bpy.data.node_groups))) - appended_4ED0B = None if not new_data else new_data[0] - bpy.context.view_layer.objects.active = bpy.context.scene.sna_activeobject - bpy.context.scene.sna_activeobject.select_set(state=True, ) - modifier_5D814 = bpy.context.scene.sna_activeobject.modifiers.new(name='MV_Nodes', type='NODES', ) - node_group = bpy.data.node_groups.get('UV_New') - if node_group is None: - self.report({'ERROR'}, message='Missing node group: UV_New') - return {"CANCELLED"} - bpy.context.scene.sna_activeobject.modifiers['MV_Nodes'].node_group = node_group - bpy.ops.object.convert(target='MESH', keep_original=True) - # Save the converted copy name immediately (active object after convert) - bpy.context.scene['_comfy_converted_name'] = bpy.context.active_object.name - bpy.data.objects[bpy.context.scene.sna_activeobject_name].hide_render = True - bpy.ops.comfyui.aovbake_ad980('INVOKE_DEFAULT', ) - bpy.data.objects[bpy.context.scene.sna_activeobject_name].modifiers.clear() - bpy.context.view_layer.objects[bpy.context.scene.sna_activeobject_name].hide_set(state=True, ) - - # --- Render Depth Map --- - _render_depth(self) - - # --- Render Normal Map --- - _render_normal(self) - - # --- Render Line Art --- - _render_lineart(self) + original_hide_render = {obj.name: obj.hide_render for obj in bpy.data.objects} + try: + active_obj = bpy.context.view_layer.objects.active + for obj in bpy.data.objects: + obj.hide_render = obj != active_obj + bpy.context.scene.sna_activeobject = active_obj + bpy.context.scene.sna_activeobject_name = active_obj.name + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + if property_exists("bpy.data.node_groups['UV_New']", globals(), locals()): + pass + else: + before_data = list(bpy.data.node_groups) + bpy.ops.wm.append(directory=os.path.join(os.path.dirname(__file__), 'assets', 'geonodesuvpack.blend') + r'\NodeTree', filename='UV_New', link=False) + new_data = list(filter(lambda d: d not in before_data, list(bpy.data.node_groups))) + appended_4ED0B = None if not new_data else new_data[0] + bpy.context.view_layer.objects.active = active_obj + active_obj.select_set(state=True, ) + modifier_5D814 = active_obj.modifiers.new(name='MV_Nodes', type='NODES', ) + node_group = bpy.data.node_groups.get('UV_New') + if node_group is None: + self.report({'ERROR'}, message='Missing node group: UV_New') + return {"CANCELLED"} + active_obj.modifiers['MV_Nodes'].node_group = node_group + bpy.ops.object.convert(target='MESH', keep_original=True) + converted_obj = bpy.context.active_object + bpy.context.scene['_comfy_converted_name'] = converted_obj.name + for obj in bpy.data.objects: + obj.hide_render = obj != converted_obj + bpy.data.objects[bpy.context.scene.sna_activeobject_name].hide_render = True + bpy.ops.comfyui.aovbake_ad980('INVOKE_DEFAULT', ) + bpy.data.objects[bpy.context.scene.sna_activeobject_name].modifiers.clear() + bpy.context.view_layer.objects[bpy.context.scene.sna_activeobject_name].hide_set(state=True, ) + _render_depth(self) + _render_normal(self) + _render_lineart(self) + finally: + for name, state in original_hide_render.items(): + if name in bpy.data.objects: + bpy.data.objects[name].hide_render = state return {"FINISHED"}