-
Hello! I'm trying to assign some stencil value for every shape in my scene (similar to shape_index, but I could assign whatever value I want). I thought including it as a custom value for every shape would be a good idea, so I was wondering if there is a simple way to add custom attributes to a shape without creating a custom shape plugin. More precisely, I want to achieve something similar to this: class StencilIntegrator(mi.SamplingIntegrator):
def __init__(self, props):
mi.SamplingIntegrator.__init__(self, props)
def sample(self, scene: mi.Scene, sampler, ray: mi.RayDifferential3f, medium: mi.Medium = None,
active: bool = True) -> Tuple[mi.Color3f, bool, List[float]]:
si = scene.ray_intersect(ray=ray, active=active)
shape = si.shape
col_eval = shape.eval_attribute('stencil_id', si, active=active)
valid = si.is_valid()
color = dr.select(valid, col_eval, mi.Color3f(0.0, 0.0, 0.0))
return color, valid, [] Reading from a shape like this (or its python dict equivalent): <shape type="obj">
<string name="filename" value="meshes-custom/knight.obj"/>
<integer name="stencil_id" value="3"/>
<transform name="to_world">
<scale value="0.25, 0.25, 0.25"/>
<rotate angle="45" value="0, -1, 0"/>
<translate value="0.24, 0, 0.33"/>
</transform>
<bsdf type="diffuse">
<rgb name="reflectance" value="0.1 0.1 0.1"/>
</bsdf>
</shape> Avoiding creating a custom shape plugin if possible. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @Frollo24 Yes, this is a fairly new feature (introduced in #690). Take a look at the PR for an example. I've been meaning to write some documentation for a while now... This should work out of the box. The only slight difference with what you suggested, is that you need to pass your attribute value as a Texture or Spectra plugin. In your case, I guess you'd want to use the |
Beta Was this translation helpful? Give feedback.
Hi @Frollo24
Yes, this is a fairly new feature (introduced in #690). Take a look at the PR for an example. I've been meaning to write some documentation for a while now...
This should work out of the box. The only slight difference with what you suggested, is that you need to pass your attribute value as a Texture or Spectra plugin. In your case, I guess you'd want to use the
uniform
plugin.This feature was intended for color attributes, so the interfaces relfect that. You won't be able to pass an integer value. But if you use
Shape.eval_attribute_1()
you'll at least get a 1-dimensional value.