fix(渲染): 在渲染过程中隔离对象以避免干扰

在生成深度、法线和线稿贴图前,先保存所有对象的原始渲染可见状态,然后仅显示当前活动对象(或转换后的对象)进行渲染。渲染完成后恢复所有对象的原始渲染可见状态,防止其他对象在渲染过程中产生干扰。
This commit is contained in:
2026-02-25 10:04:38 +08:00
parent 05d8702373
commit 2288a47e4a

View File

@@ -491,8 +491,13 @@ 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
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
@@ -501,30 +506,30 @@ class Comfy_OT_Mvgen_B6229(bpy.types.Operator):
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', )
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"}
bpy.context.scene.sna_activeobject.modifiers['MV_Nodes'].node_group = node_group
active_obj.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
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 Map ---
_render_depth(self)
# --- Render Normal Map ---
_render_normal(self)
# --- Render Line Art ---
_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"}