I would like to ask for help with an issue I'm having regarding a Python script to enable or disable the camera
property (visible_camera) in the Ray Visibility
settings (found in the Object Properties tab), for the object in a specific Collection Info
node when it is connected to a Replace Material
node.
I have made several room templates (collections with planes for walls, the floor, etc and a door) due to having several templates the object collection that is assigned to the Collection Info
node is dynamic.
For extra clarity, the camera
Ray Visibility property of each room template's Door collection has to be toggled by the Python script for different View Layers
, because render cameras have to be able to look through the backside of the door in certain angles.
This is the code I currently have for toggling the camera
ray visibility property:
#Define room objects for visibility change
def visibility(Door: bool, Spotlight: bool):
for i in bpy.data.collections['Door_{}'.format(room)].objects:
i.visible_camera = Door
for i in bpy.data.collections['Spotlight_{}'.format(room)].objects:
i.visible_camera = Spotlight
This is the relative part of the code to determine for which View Layers the camera
ray visiblity property should be true or false:
#Define visibility for each template camera and view layer
visibility_map_Camera_1 = {
'Perspective': (False, True),
'Sideview': (True, True),
'Frontview': (False, True),
'Topview': (True, False), }
visibility_map_Camera_2 = {
'Perspective': (False, True),
'Sideview': (True, True),
'Frontview': (False, True),
'Topview': (True, False), }
#all other cameras.. in total there are 6#
# Iterate over each frame
for frame in range(start_frame, end_frame):
room = file.iloc[frame]['RoomTemplate']
bpy.context.scene.frame_set(frame)
# Determine which camera's view layer map to use
camera = file.iloc[frame]['Camera']
if camera == '1':
view_layer_camera_map = view_layer_camera_map_Camera_1
visibility_map = visibility_map_Camera_1
z_position_map = z_position_map_Camera_1
elif camera == '2':
view_layer_camera_map = view_layer_camera_map_Camera_2
visibility_map = visibility_map_Camera_2
z_position_map = z_position_map_Camera_2
#all other cameras.. in total there are 6#
# Iterate over each view layer
for view_layer_name in view_layer_camera_map:
# Get visibility settings from the map for the current view layer
visibility_settings = visibility_map.get(view_layer_name, (True, True)) # Default to (True, True) if not specified
z_position_settings = z_position_map.get(view_layer_name, (None, None)) # Default to (0.0, 0.0) if not specified
# Apply visibility settings based on the current view layer and camera
visibility(visibility_settings[0], visibility_settings[1])
When the Collection Info
node is not connected to a Replace Material
node everything is working perfectly as can be seen in the images below (the door is hidden in 2 of the 4 views).
The Spreadsheet
window also shows that the currently used room template's door collection assigned to the Collection Info
node is recognized by the Geometry Nodes:
But here the issue arises, if I connect the Door Collection Info
node to a Replace Material
node (to be able to change the color of the door handle), the door remains visible in every View Layer render because the Python script doesn't work anymore.
I also noticed that in the Spreadsheet
window, the name gets changed to simply Geometry as can be seen in the image below:
In the images below can be seen that the color of the door handle is changed to gold but also that the door remains visible in every image instead of only 2 out of 4 as shown previously.
My knowledge of Python is very limited, because of that I would like to ask if someone understands what the issue could be or knows how to fix this?
Edit: It is important that the geometry of the door and the handle remain visible in reflections, because of that I was trying to toggle the camera
property of the Ray Visibility
settings. The Replace Material
node is being used because the color (material assignment) of the door handle should be the same as the material that is assigned to eg. faucets in the room.
Thanks in advance!