mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 249 forks source link

Cannot set flag on a custom Python emitter #1249

Closed dvicini closed 3 months ago

dvicini commented 3 months ago

When creating a custom Python emitter, I seem to be unable to set its flags. This reproducer

import mitsuba as mi
mi.set_variant('llvm_ad_rgb')

class MyEmitter(mi.Emitter):

    def __init__(self, props):
        self.m_flags = mi.EmitterFlags.Surface

mi.register_emitter('myemitter', lambda props: MyEmitter(props))

emitter = mi.load_dict({'type': 'myemitter'})

fails with

TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (self, arg: int, /) -> None

Invoked with types: __main__.MyEmitter, mitsuba.EmitterFlags

I tried forcing an int conversion using self.m_flags = +mi.EmitterFlags.Surface, but got the error:

TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (self, arg: int, /) -> None

Invoked with types: __main__.MyEmitter, int

This is on MacOS with the latest master branch (as of posting this).

njroussel commented 3 months ago

@bathal1 litteraly just came to my office to show me a similar reproducer x)

I pushed a fix in https://github.com/mitsuba-renderer/mitsuba3/commit/113a9ff0037aea7de318ac9e50e8842f1c162ed3

From a quick grep we have a lot more these across all plugin types. I'm not sure why this changed/broke, I'll dig deeper as I look into the other ones. For now, Emitter is at least fixed.

dvicini commented 3 months ago

Amazing, thanks for the quick response!