How to package my own CYCLES fork as an add-on for blender (as a .zip file)

I made a fork of the awesome CYCLES render engine. I wonder, can I package my fork as an add-on for blender?

I know that there are many alternative render engines for blender (e.g. LuxCoreRender). LuxCoreRender can be installed as an add-on. Can I do the same?

Not easily, the way Cycles is integrated requires access to Blender APIs that are not available to addons. In principle it is possible to do all the same things through the Python API, but that would require rewriting a lot of the Blender to Cycles conversion code.

1 Like

brecht, what do you think about the following idea.
Cycles “add-on”, I mean cycles RenderEngine implementation in python, imports the “_cycles” module. This module is generated by blender.exe on every blender start up.
Can I build _cycles as a .pyd dynamic library. And import it in my CustomCyclesRenderEngine?

Actually, I did it. Now I have CustomCycles.pyd, and I can import it in my add-on. But… I have problems with the RNA access. When I pass scene.as_pointer() to C++ it doesn’t have scene.cycles. And I do not know why.

Please, could you answer this question? And is the idea feasible?

No, that doesn’t work around the issues that I mentioned. _cycles is part of Blender itself and uses non-public Blender APIs, and separating it is where the difficulty is.

I know that _cycles is part of Blender and uses Blender API.
I have built _cycles as .pyd. More precisely, I slightly changed blender_python.cpp code and cmake lists, so this _cycles.pyd has all blender API inside and it is importable in python.

So, when I call

static PyObject *create_func(PyObject * /*self*/, PyObject *args)

I can access (RNA) everything in a scene except Scene.cycles and Scene.cycles_curves . I still think that I’m on the right way. Am I wrong?

I don’t think that works. Duplicating the Blender API inside _cycles.pyd may work for some things but in general it will not interact correctly with Blender.

Thank you Brecht.

Should I maybe use the xml as a connection between customized cycles and blender?
I found this repo https://github.com/zhutq/cycles-xml-exporter

But I tried and it seems to be very poor. I fed .xml to cycles standalone and output is

Unknown shader node "tex_sky".
Unknown shader node name "Sky_Texture".
Unknown shader node "volume_scatter".
Unknown shader node "vect_math".
Unknown shader node "tex_musgrave".
Unknown shader node "vect_transform".
Unknown shader node "vect_math".
Unknown shader node "sepxyz".
Unknown shader node "combxyz".
Unknown shader node name "Vector_Transform".

Lots of unknown shader nodes

I think these are just nodes that got renamed, they should all be there. Still for interactive viewport rendering going through XML is not really an option, you need to talk to the API directly.

One way or another, I think making this separation requires quite a lot of work. Either rewriting the Cycles export code to be more Python based like other external renderers that integrate into Blender, or supporting an official C++ Blender API that can be shared with official Cycles. Both would likely be months of work.