Skip to content

Commit

Permalink
Merge branch 'dev' into 'main'
Browse files Browse the repository at this point in the history
Merge dev to main

See merge request renderman/projects/RenderManForBlender!24
  • Loading branch information
Ian Hsieh committed Apr 25, 2024
2 parents 8e95f1c + d2730ee commit 8027a96
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 24 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Expand Up @@ -30,7 +30,7 @@
bl_info = {
"name": "RenderMan For Blender",
"author": "Pixar",
"version": (26, 0, 0),
"version": (26, 1, 0),
"blender": (2, 93, 0),
"location": "Render Properties > Render Engine > RenderMan",
"description": "RenderMan 26 integration",
Expand Down
10 changes: 10 additions & 0 deletions changelog.txt
@@ -1,3 +1,13 @@
v26.1, April 24, 2024

Bug Fixes:
* Fixed bugs related to refreshing an OSL shader via the PxrOSL shading node
* Fixed a bug that caused the field of view to no be calculated correctly when
using an orthographic camera
* Fixed a bug that caused integrators to use the wrong settings during IPR
* Fixed a bug that caused instances created via geometry nodes to have the
wrong material attached

v26.0, April 02, 2024

New Features:
Expand Down
6 changes: 5 additions & 1 deletion rfb_unittests/test_geo.py
@@ -1,6 +1,7 @@
import unittest
import bpy
from ..rfb_utils import mesh_utils
from ..rman_constants import BLENDER_41


class GeoTest(unittest.TestCase):
Expand All @@ -20,7 +21,10 @@ def test_eq(a, b, msg=None):
nverts = [4, 4, 4, 4, 4, 4]
verts = [0, 1, 3, 2, 2, 3, 7, 6, 6, 7, 5, 4, 4, 5, 1, 0, 2, 6, 4, 0, 7, 3, 1, 5]
P = [[-1.0, -1.0, -1.0], [-1.0, -1.0, 1.0], [-1.0, 1.0, -1.0], [-1.0, 1.0, 1.0], [1.0, -1.0, -1.0], [1.0, -1.0, 1.0], [1.0, 1.0, -1.0], [1.0, 1.0, 1.0]]
N = [[-1.0, -0.0, 0.0], [0.0, 1.0, 0.0], [1.0, -0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0], [0.0, -0.0, 1.0]]
if BLENDER_41:
N = [[-1.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, -1.0, 0.0], [0.0, -1.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0], [0.0, 0.0, -1.0], [0.0, 0.0, -1.0], [0.0, 0.0, -1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]
else:
N = [[-1.0, -0.0, 0.0], [0.0, 1.0, 0.0], [1.0, -0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0], [0.0, -0.0, 1.0]]

mesh = mesh_utils.RmanMesh(nverts, verts, P, N)

Expand Down
6 changes: 5 additions & 1 deletion rfb_utils/camera_utils.py
Expand Up @@ -14,7 +14,11 @@ def render_get_aspect_(r, camera=None, x=-1, y=-1):
xratio = xres * r.pixel_aspect_x / 200.0
yratio = yres * r.pixel_aspect_y / 200.0

if camera is None or camera.type != 'PERSP':
if camera is None:
# If we don't have a camera, always use HORIZONTAL
# This is the viewport render case, but there's no camera in the scene
fit = 'HORIZONTAL'
elif camera.type != 'PERSP':
fit = 'AUTO'
else:
fit = camera.sensor_fit
Expand Down
6 changes: 3 additions & 3 deletions rfb_utils/shadergraph_utils.py
Expand Up @@ -793,7 +793,7 @@ def find_integrator_node(world):
(RendermanIntegratorNode) - the integrator ShadingNode
'''
rm = world.renderman
if not world.renderman.use_renderman_node:
if not world.use_nodes:
return None

output = find_node(world, 'RendermanIntegratorsOutputNode')
Expand All @@ -814,7 +814,7 @@ def find_displayfilter_nodes(world):
(list) - list of display filter nodes
'''
df_nodes = []
if not world.renderman.use_renderman_node:
if not world.use_nodes:
return df_nodes

output = find_node(world, 'RendermanDisplayfiltersOutputNode')
Expand All @@ -836,7 +836,7 @@ def find_samplefilter_nodes(world):
(list) - list of sample filter nodes
'''
sf_nodes = []
if not world.renderman.use_renderman_node:
if not world.use_nodes:
return sf_nodes

output = find_node(world, 'RendermanSamplefiltersOutputNode')
Expand Down
24 changes: 19 additions & 5 deletions rman_bl_nodes/rman_bl_nodes_shaders.py
Expand Up @@ -7,7 +7,7 @@
from ..rfb_utils.property_utils import BlPropInfo, __LOBES_ENABLE_PARAMS__
from ..rfb_utils import filepath_utils
from ..rman_config import __RFB_CONFIG_DICT__
from ..rman_constants import RFB_FLOAT3, RFB_SHADER_ALLOWED_CONNECTIONS
from ..rman_constants import RFB_FLOAT3, RFB_SHADER_ALLOWED_CONNECTIONS, __RMAN_SOCKET_MAP__
from .. import rman_bl_nodes
from .. import rfb_icons
from .. import rman_render
Expand Down Expand Up @@ -707,7 +707,14 @@ def setOslProps(self, prop_names, shader_meta):
if socket.is_linked:
links[input_name] = {"from_node": socket.links[0].from_node, "from_socket": socket.links[0].from_socket}
else:
values[input_name] = deepcopy(socket.default_value)
if isinstance(socket.default_value, bpy.types.bpy_prop_array):
# deecopy seems to fail on bpy_prop_array types, so manually copy
val = list()
for v in socket.default_value:
val.append(v)
values[input_name] = val
else:
values[input_name] = deepcopy(socket.default_value)
for input_name, socket in self.outputs.items():
if socket.is_linked:
links[input_name] = {"from_node": socket.links[0].to_node, "from_socket": socket.links[0].to_socket}
Expand All @@ -722,7 +729,7 @@ def setOslProps(self, prop_names, shader_meta):
prop_type = shader_meta[prop_name]["type"]
if shader_meta[prop_name]["IO"] == "out":
socket = self.outputs.new(
rman_socket_utils.__RMAN_SOCKET_MAP__[prop_type], prop_name)
__RMAN_SOCKET_MAP__[prop_type], prop_name)
if prop_name in links and socket.hide is False:
link = links[prop_name]
self.id_data.links.new(socket, link['from_socket'])
Expand All @@ -734,15 +741,22 @@ def setOslProps(self, prop_names, shader_meta):
prop_default = float(prop_default)
elif prop_type == "int":
prop_default = int(float(prop_default))
elif prop_type == "color":
# error checking on len(prop_default)
# we want len(prop_default) = 4
if len(prop_default) < 4:
prop_default += (4-len(prop_default)) * (1.0,)
elif len(prop_default) > 4:
prop_default = prop_default[:4]

if prop_type == "matrix":
self.inputs.new(rman_socket_utils.__RMAN_SOCKET_MAP__["struct"], prop_name, prop_name)
self.inputs.new(__RMAN_SOCKET_MAP__["struct"], prop_name, prop_name)
elif prop_type == "void":
pass
elif 'lockgeom' in shader_meta[prop_name] and shader_meta[prop_name]['lockgeom'] == 0:
pass
else:
input = self.inputs.new(rman_socket_utils.__RMAN_SOCKET_MAP__[shader_meta[prop_name]["type"]],
input = self.inputs.new(__RMAN_SOCKET_MAP__[shader_meta[prop_name]["type"]],
prop_name, identifier=prop_name)
if prop_default:
input.default_value = prop_default
Expand Down
2 changes: 1 addition & 1 deletion rman_bl_nodes/rman_bl_nodes_sockets.py
Expand Up @@ -436,7 +436,7 @@ class RendermanNodeSocketFloat(NodeSocketFloat, RendermanSocket):
renderman_type: StringProperty(default='float')
is_array: BoolProperty(default=False)
array_elem: IntProperty(default=-1)
default_value: IntProperty(update=update_func)
default_value: FloatProperty(update=update_func)

@classmethod
def draw_color_simple(cls):
Expand Down
4 changes: 4 additions & 0 deletions rman_render.py
Expand Up @@ -1246,6 +1246,8 @@ def start_export_rib_selected(self, context, rib_path, export_materials=True, ex

self.rman_running = True
bl_scene = context.scene
if self._do_prman_render_begin():
return False
if export_all_frames:
original_frame = bl_scene.frame_current
rfb_log().debug("Writing to RIB...")
Expand Down Expand Up @@ -1298,6 +1300,8 @@ def start_export_rib_selected(self, context, rib_path, export_materials=True, ex
self.rman_scene.reset()

self.rman_running = False
self.del_bl_engine()
self._do_prman_render_end()
return True

def stop_render(self, stop_draw_thread=True):
Expand Down
5 changes: 2 additions & 3 deletions rman_scene_sync.py
Expand Up @@ -86,9 +86,8 @@ def update_view(self, context, depsgraph):
translator = self.rman_scene.rman_translators['CAMERA']
with self.rman_scene.rman.SGManager.ScopedEdit(self.rman_scene.sg_scene):
if self.rman_scene.is_viewport_render:
ob = translator.update_viewport_resolution(rman_sg_camera)
if ob:
translator.update_viewport_cam(ob, rman_sg_camera, force_update=True)
if translator.update_viewport_resolution(rman_sg_camera):
translator.update_viewport_cam(None, rman_sg_camera, force_update=True)
translator.update_transform(None, rman_sg_camera)
else:
translator.update_transform(camera, rman_sg_camera)
Expand Down
16 changes: 11 additions & 5 deletions rman_translators/rman_camera_translator.py
Expand Up @@ -83,8 +83,8 @@ def _export_viewport_cam(self, db_name=""):
rman_sg_camera = RmanSgCamera(self.rman_scene, sg_group, db_name)
rman_sg_camera.sg_camera_node = self.rman_scene.sg_scene.CreateCamera('%s-CAMERA' % db_name)
sg_group.AddChild(rman_sg_camera.sg_camera_node)
ob = self.update_viewport_resolution(rman_sg_camera)
self.update_viewport_cam(ob, rman_sg_camera)
self.update_viewport_resolution(rman_sg_camera)
self.update_viewport_cam(None, rman_sg_camera)
self._set_orientation(rman_sg_camera)
self._update_viewport_transform(rman_sg_camera)
return rman_sg_camera
Expand Down Expand Up @@ -398,8 +398,8 @@ def update_viewport_resolution(self, rman_sg_camera):
options.SetFloatArray(self.rman_scene.rman.Tokens.Rix.k_Ri_CropWindow, crop_window, 4)
self.rman_scene.sg_scene.SetOptions(options)
rman_sg_camera.sg_camera_node.SetProperties(prop)
return ob
return None
return True
return False

def update_viewport_cam(self, ob, rman_sg_camera, force_update=False):
region = self.rman_scene.context.region
Expand All @@ -419,6 +419,10 @@ def update_viewport_cam(self, ob, rman_sg_camera, force_update=False):

bl_cam_props = deepcopy(rman_sg_camera.bl_cam_props)
if rman_sg_camera.bl_cam_props.view_perspective == 'CAMERA':
if ob is None:
ob = self.rman_scene.bl_scene.camera
if self.rman_scene.context.space_data.use_local_camera:
ob = self.rman_scene.context.space_data.camera
ob = ob.original
cam = ob.data
rman_sg_camera.bl_camera = ob
Expand Down Expand Up @@ -478,6 +482,8 @@ def update_viewport_cam(self, ob, rman_sg_camera, force_update=False):
rman_sg_camera.rman_focus_object = None

elif rman_sg_camera.bl_cam_props.view_perspective == 'PERSP':
if ob is None:
ob = self.rman_scene.context.space_data.camera
cam = None
if ob:
cam = ob.data
Expand All @@ -494,7 +500,7 @@ def update_viewport_cam(self, ob, rman_sg_camera, force_update=False):
region_data = self.rman_scene.context.region_data
vmat_inv = region_data.view_matrix.inverted()
pmat = region_data.perspective_matrix @ vmat_inv
fov = 360.0 * math.atan(1.0/pmat[1][1]) / math.pi
fov = 2.0 * math.atan(1.0/pmat[1][1]) * 180.0 / math.pi

bl_cam_props.rman_fov = fov

Expand Down
8 changes: 4 additions & 4 deletions rman_translators/rman_mesh_translator.py
Expand Up @@ -505,9 +505,9 @@ def update(self, ob, rman_sg_mesh, input_mesh=None, sg_node=None):
if rman_sg_mesh.is_multi_material:
material_ids = _get_material_ids(ob, mesh)
i = 1
for mat_id, faces in \
_get_mats_faces_(nverts, material_ids).items():

mat_faces_dict = _get_mats_faces_(nverts, material_ids)
min_idx = min(mat_faces_dict.keys()) # find the minimun material index
for mat_id, faces in mat_faces_dict.items():
# If the face has a mat index that is higher than the number of
# material slots, use the last material. This is what
# Eevee/Cycles does.
Expand All @@ -519,7 +519,7 @@ def update(self, ob, rman_sg_mesh, input_mesh=None, sg_node=None):
continue
sg_material = self.rman_scene.rman_materials.get(mat.original, None)

if mat_id == 0:
if mat_id == min_idx:
primvar.SetIntegerArray(self.rman_scene.rman.Tokens.Rix.k_shade_faceset, faces, len(faces))
scenegraph_utils.set_material(sg_node, sg_material.sg_node, sg_material, mat=mat, ob=ob)
else:
Expand Down

0 comments on commit 8027a96

Please sign in to comment.