fix(渲染): 在渲染过程中隔离对象以避免干扰
在生成深度、法线和线稿贴图前,先保存所有对象的原始渲染可见状态,然后仅显示当前活动对象(或转换后的对象)进行渲染。渲染完成后恢复所有对象的原始渲染可见状态,防止其他对象在渲染过程中产生干扰。
This commit is contained in:
73
utils.py
73
utils.py
@@ -491,40 +491,45 @@ class Comfy_OT_Mvgen_B6229(bpy.types.Operator):
|
|||||||
else:
|
else:
|
||||||
if (None is not bpy.context.view_layer.objects.active):
|
if (None is not bpy.context.view_layer.objects.active):
|
||||||
if bpy.context.view_layer.objects.active.type == 'MESH':
|
if bpy.context.view_layer.objects.active.type == 'MESH':
|
||||||
bpy.context.scene.sna_activeobject = bpy.context.view_layer.objects.active
|
original_hide_render = {obj.name: obj.hide_render for obj in bpy.data.objects}
|
||||||
bpy.context.scene.sna_activeobject_name = bpy.context.scene.sna_activeobject.name
|
try:
|
||||||
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
active_obj = bpy.context.view_layer.objects.active
|
||||||
if property_exists("bpy.data.node_groups['UV_New']", globals(), locals()):
|
for obj in bpy.data.objects:
|
||||||
pass
|
obj.hide_render = obj != active_obj
|
||||||
else:
|
bpy.context.scene.sna_activeobject = active_obj
|
||||||
before_data = list(bpy.data.node_groups)
|
bpy.context.scene.sna_activeobject_name = active_obj.name
|
||||||
bpy.ops.wm.append(directory=os.path.join(os.path.dirname(__file__), 'assets', 'geonodesuvpack.blend') + r'\NodeTree', filename='UV_New', link=False)
|
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
||||||
new_data = list(filter(lambda d: d not in before_data, list(bpy.data.node_groups)))
|
if property_exists("bpy.data.node_groups['UV_New']", globals(), locals()):
|
||||||
appended_4ED0B = None if not new_data else new_data[0]
|
pass
|
||||||
bpy.context.view_layer.objects.active = bpy.context.scene.sna_activeobject
|
else:
|
||||||
bpy.context.scene.sna_activeobject.select_set(state=True, )
|
before_data = list(bpy.data.node_groups)
|
||||||
modifier_5D814 = bpy.context.scene.sna_activeobject.modifiers.new(name='MV_Nodes', type='NODES', )
|
bpy.ops.wm.append(directory=os.path.join(os.path.dirname(__file__), 'assets', 'geonodesuvpack.blend') + r'\NodeTree', filename='UV_New', link=False)
|
||||||
node_group = bpy.data.node_groups.get('UV_New')
|
new_data = list(filter(lambda d: d not in before_data, list(bpy.data.node_groups)))
|
||||||
if node_group is None:
|
appended_4ED0B = None if not new_data else new_data[0]
|
||||||
self.report({'ERROR'}, message='Missing node group: UV_New')
|
bpy.context.view_layer.objects.active = active_obj
|
||||||
return {"CANCELLED"}
|
active_obj.select_set(state=True, )
|
||||||
bpy.context.scene.sna_activeobject.modifiers['MV_Nodes'].node_group = node_group
|
modifier_5D814 = active_obj.modifiers.new(name='MV_Nodes', type='NODES', )
|
||||||
bpy.ops.object.convert(target='MESH', keep_original=True)
|
node_group = bpy.data.node_groups.get('UV_New')
|
||||||
# Save the converted copy name immediately (active object after convert)
|
if node_group is None:
|
||||||
bpy.context.scene['_comfy_converted_name'] = bpy.context.active_object.name
|
self.report({'ERROR'}, message='Missing node group: UV_New')
|
||||||
bpy.data.objects[bpy.context.scene.sna_activeobject_name].hide_render = True
|
return {"CANCELLED"}
|
||||||
bpy.ops.comfyui.aovbake_ad980('INVOKE_DEFAULT', )
|
active_obj.modifiers['MV_Nodes'].node_group = node_group
|
||||||
bpy.data.objects[bpy.context.scene.sna_activeobject_name].modifiers.clear()
|
bpy.ops.object.convert(target='MESH', keep_original=True)
|
||||||
bpy.context.view_layer.objects[bpy.context.scene.sna_activeobject_name].hide_set(state=True, )
|
converted_obj = bpy.context.active_object
|
||||||
|
bpy.context.scene['_comfy_converted_name'] = converted_obj.name
|
||||||
# --- Render Depth Map ---
|
for obj in bpy.data.objects:
|
||||||
_render_depth(self)
|
obj.hide_render = obj != converted_obj
|
||||||
|
bpy.data.objects[bpy.context.scene.sna_activeobject_name].hide_render = True
|
||||||
# --- Render Normal Map ---
|
bpy.ops.comfyui.aovbake_ad980('INVOKE_DEFAULT', )
|
||||||
_render_normal(self)
|
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 Line Art ---
|
_render_depth(self)
|
||||||
_render_lineart(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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user