-
Hello all, I'm trying to find the correct workflow for using a custom data-driven BSDF, written in Python, within an XML scene file. Specifically, my goal is to use my own measured BRDF data, which I have in .h5 or .npy file formats, to drive a custom BSDF plugin. The documentation is very clear on how to instantiate plugins within Python using mi.load_dict() and hard-coded parameters, like this example: my_bsdf = mi.load_dict({ 'type' : 'mybsdf', 'tint' : [0.2, 0.9, 0.2] }) However, the documentation doesn't seem to explicitly cover the workflow for two related use cases: A Python class that is designed to accept a filename from the props object and load the data using NumPy or h5py. class MyMeasuredBSDF(mi.BSDF):
def __init__(self, props):
mi.BSDF.__init__(self, props)
filename = props['my_data_file']
self.data = np.load(filename) A main Python script that registers the class before loading the XML scene. import mitsuba as mi
from my_plugin import MyMeasuredBSDF
mi.set_variant('scalar_rgb')
mi.register_bsdf("my_material", MyMeasuredBSDF)
scene = mi.load_file("scene.xml") # <-- Load XML after registration The XML uses the registered name as the type and passes the file path using a tag. <scene version="3.0.0">
<shape type="sphere">
<bsdf type="my_material">
<string name="my_data_file" value="path/to/data.npy"/>
</bsdf>
</shape>
</scene> My main question is: Is this three-step process the correct way to link a custom, data-driven Python plugin (using formats like .npy or .h5) to an XML scene? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @Daavid739, Yes, the process you describe sounds right:
|
Beta Was this translation helpful? Give feedback.
Hello @Daavid739,
Yes, the process you describe sounds right:
props
load_file/load_dict
type=""
to your plugin name and nest astring
property with the correctname
to pass your filename.