Adding & Modifying Nodes via Python?

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Post Reply
kintuX
Posts: 809
Joined: Wed Jan 10, 2018 2:37 am

Adding & Modifying Nodes via Python?

Post by kintuX »

First, i'm ignorant in python :oops:
but for years i have this constant urge to dive in... and i know it will take a looong time.
So i decided to at least do few small steps.

For starters i'd like to modify HSV node inputs. Specifically, I want to lift max. Saturation & Value from 2 to X.
But as expected, simply changing those values in hsv.py does nothing. :lol:
So what do i need to do? Where can i get the relevant information?

There's lot of other stuff i'd like to tackle (add more nodes) and am also wondering, if Blender's nodes can be used in some way?
Sorry for the lack of understanding, just a few pointers in the direction i wish to go would be nice... as for now, i'm lost :|

TIA
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Adding & Modifying Nodes via Python?

Post by B.Y.O.B. »

Great that you're interested :D

I think you should start by forking the BlendLuxCore repository.
However if you don't know git, you can also just edit the Python source files in your BlendLuxCore installation. This is easier if you don't have prior programming/version control knowledge.
kintuX wrote: Wed Sep 12, 2018 6:49 pm For starters i'd like to modify HSV node inputs. Specifically, I want to lift max. Saturation & Value from 2 to X.
But as expected, simply changing those values in hsv.py does nothing.
So what do i need to do? Where can i get the relevant information?
You should first look into the LuxCore code that reads the properties and creates the texture: https://github.com/LuxCoreRender/LuxCor ... s.cpp#L491
Some non-textured values are clamped there, but since all inputs of the HSV texture are texturable, this code allows arbitrary inputs.

Next, you should look at the LuxCore code that computes the texture output at a given hitpoint: https://github.com/LuxCoreRender/LuxCor ... sv.cpp#L33
In case of the HSV texture this is a bit complicated, you might want to look at some other textures to get what is essentially going on.
Anyway, what I did just now is check if there is any clamping happening here.
In the HSV texture, only the color input is clamped (in line 46).
So it is possible to pass any saturation or value!

This means that the only clamping that is going on is inside the Python addon.
In nodes/textures/hsv.py we see that the saturation socket is of type "LuxCoreSocketFloat0to2".
Socket classes are declared in nodes/sockets.py.
You can copy and paste the name of most socket classes here into the string in hsv.py.
For example, you could change it to "LuxCoreSocketFloatUnbounded" to get a float input without bounds.

And with this, you get the following:
2018-09-12_22-08-59.png
However, there's also another trick you can use without any coding:
Because we saw that on the LuxCore side, no clamping happens, we can use a "Constant Value" node to plug any value into the saturation socket.
2018-09-12_22-21-31.png
Anyway, this might be interesting for you:
https://github.com/LuxCoreRender/BlendL ... master/doc (Blender addon documentation, not as much as I'd like to have)
https://wiki.luxcorerender.org/LuxCore_ ... anual_v2.1 (manual for the property definitions)
https://github.com/LuxCoreRender/LuxCor ... uxcore.cpp (LuxCore Python API)
https://wiki.luxcorerender.org/Writing_ ... ine_Plugin
https://wiki.luxcorerender.org/Compiling_LuxCore

Hope I didn't overwhelm you :)
kintuX
Posts: 809
Joined: Wed Jan 10, 2018 2:37 am

Re: Adding & Modifying Nodes via Python?

Post by kintuX »

Yes, overwhelming, but anyways -THANK YOU! I know, it will take time, patience and perseverance...

Am also realizing, a good way to learn is by simply observing issues and fixes on repos. Since my brain then tries to find or construct a pattern from the observed process... oh, wow... got so many things (code foundations & adv. math) to brush up...

"On with the snail race!" :mrgreen:
Post Reply