-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blender: Start implementing node support in add-on
Not really 100% sure how I'll approach it in the end, but I'm just sketching out the ctypes boilerplate for now.
- Loading branch information
Showing
5 changed files
with
389 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import ctypes as ct | ||
from vector import _vector | ||
from value import _value | ||
|
||
class _color_type(IntEnum): | ||
unknown = 0 | ||
constant = 1 | ||
image = 2 | ||
checkerboard = 3 | ||
blackbody = 4 | ||
split = 5 | ||
rgb = 6 | ||
hsl = 7 | ||
vec_to_color = 8 | ||
gradient = 9 | ||
|
||
class _color(ct.Structure): | ||
_fields_ = [ | ||
("type", _color_type) | ||
("arg", _color_arg) | ||
] | ||
|
||
class cr_color(ct.Structure): | ||
_fields_ = [ | ||
("r", ct.c_float), | ||
("g", ct.c_float), | ||
("b", ct.c_float), | ||
("a", ct.c_float), | ||
] | ||
|
||
class _color_arg(ct.Union): | ||
_fields_ = [ | ||
("constant", cr_color), | ||
("image", _color_arg_image), | ||
("checkerboard", _color_arg_checkerboard), | ||
("blackbody", _color_arg_blackbody), | ||
("split", _color_arg_split), | ||
("rgb", _color_arg_rgb), | ||
("hsl", _color_arg_hsl), | ||
("vec_to_color", _color_arg_vec_to_color), | ||
("gradient", _color_arg_gradient), | ||
] | ||
|
||
class _color_arg_image(ct.Structure): | ||
_fields_ = [ | ||
("full_path", ct.c_char_p), | ||
("options", ct.c_uint8) | ||
] | ||
|
||
class _color_arg_checkerboard(ct.Structure): | ||
_fields_ = [ | ||
("a", ct.POINTER(_color)), | ||
("b", ct.POINTER(_color)), | ||
("scale", ct.POINTER(_value)) | ||
] | ||
|
||
class _color_arg_blackbody(ct.Structure): | ||
_fields_ = [ | ||
("degrees", ct.POINTER(_value)) | ||
] | ||
|
||
class _color_arg_split(ct.Structure): | ||
_fields_ = [ | ||
("value", ct.POINTER(_value)) | ||
] | ||
|
||
class _color_arg_rgb(ct.Structure): | ||
_fields_ = [ | ||
("red", ct.POINTER(_value)), | ||
("green", ct.POINTER(_value)), | ||
("blue", ct.POINTER(_value)), | ||
] | ||
|
||
class _color_arg_hsl(ct.Structure): | ||
_fields_ = [ | ||
("H", ct.POINTER(_value)), | ||
("S", ct.POINTER(_value)), | ||
("L", ct.POINTER(_value)), | ||
] | ||
|
||
class _color_arg_vec_to_color(ct.Structure): | ||
_fields_ = [ | ||
("vec", ct.POINTER(_vector)) | ||
] | ||
|
||
class _color_arg_gradient(ct.Structure): | ||
_fields_ = [ | ||
("a", ct.POINTER(_color)), | ||
("b", ct.POINTER(_color)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import ctypes as ct | ||
from color import _color | ||
from value import _value | ||
from vector import _vector | ||
|
||
class _shader_type(IntEnum): | ||
unknown = 0 | ||
diffuse = 1 | ||
metal = 2 | ||
glass = 3 | ||
plastic = 4 | ||
mix = 5 | ||
add = 6 | ||
transparent = 7 | ||
emissive = 8 | ||
translucent = 9 | ||
background = 10 | ||
|
||
class _shader(ct.Structure): | ||
_fields_ = [ | ||
("type", _shader_type), | ||
("arg", _shader_arg) | ||
] | ||
|
||
class _shader_arg(ct.Union): | ||
_fields_ = [ | ||
("diffuse", _shader_arg_diffuse) | ||
] | ||
|
||
class _shader_arg_diffuse(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] | ||
|
||
class _shader_arg_metal(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)), | ||
("roughness", ct.POINTER(_value)), | ||
] | ||
|
||
class _shader_arg_plastic(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)), | ||
("roughness", ct.POINTER(_value)), | ||
("IOR", ct.POINTER(_value)), | ||
] | ||
|
||
class _shader_arg_mix(ct.Structure): | ||
_fields_ = [ | ||
("A", ct.POINTER(_shader)), | ||
("B", ct.POINTER(_shader)), | ||
("factor", ct.POINTER(_value)) | ||
] | ||
|
||
class _shader_arg_add(ct.Structure): | ||
_fields_ = [ | ||
("A", ct.POINTER(_shader)), | ||
("B", ct.POINTER(_shader)), | ||
] | ||
|
||
class _shader_arg_transparent(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] | ||
|
||
class _shader_arg_emissive(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)), | ||
("strength", ct.POINTER(_value)) | ||
] | ||
|
||
class _shader_arg_translucent(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] | ||
|
||
class _shader_arg_background(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)), | ||
("pose", ct.POINTER(_vector)), | ||
("strength", ct.POINTER(_value)) | ||
] | ||
|
||
class _shader_arg_diffuse(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import ctypes as ct | ||
from vector import _vector | ||
from color import _color | ||
|
||
class _value_type(IntEnum): | ||
unknown = 1 | ||
constant = 2 | ||
fresnel = 3 | ||
map_range = 4 | ||
raylength = 5 | ||
alpha = 6 | ||
vec_to_value = 7 | ||
math = 8 | ||
grayscale = 9 | ||
|
||
class _value(ct.Structure): | ||
_fields_ = [ | ||
("type", _value_type) | ||
("arg", _value_arg) | ||
] | ||
|
||
class _value_arg(ct.Union): | ||
_fields_ = [ | ||
("constant", ct.c_double), | ||
("fresnel", _value_arg_fresnel), | ||
("map_range", _value_arg_map_range) | ||
] | ||
|
||
class _value_arg_fresnel(ct.Structure): | ||
_fields_ = [ | ||
("IOR", ct.POINTER(_value)), | ||
("normal", ct.POINTER(_vector)) | ||
] | ||
|
||
class _value_arg_map_range(ct.Structure): | ||
_fields_ = [ | ||
("input_value", ct.POINTER(_value)), | ||
("from_min", ct.POINTER(_value)), | ||
("from_max", ct.POINTER(_value)), | ||
("to_min", ct.POINTER(_value)), | ||
("to_max", ct.POINTER(_value)), | ||
] | ||
|
||
class _value_arg_alpha(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] | ||
|
||
class _component(IntEnum): | ||
X = 0 | ||
Y = 1 | ||
Z = 3 | ||
U = 4 | ||
V = 5 | ||
F = 6 | ||
|
||
class _value_arg_vec_to_value(ct.Structure): | ||
_fields_ = [ | ||
("comp", _component), | ||
("vec", ct.POINTER(_vector)) | ||
] | ||
|
||
# These are ripped off here: | ||
# https:#docs.blender.org/manual/en/latest/render/shader_nodes/converter/math.html | ||
# TODO: Commented ones need to be implemented to reach parity with Cycles. Feel free to do so! :^) | ||
class _math_op(IntEnum): | ||
Add = 0 | ||
Subtract = 1 | ||
Multiply = 2 | ||
Divide = 3 | ||
#MultiplyAdd = | ||
Power = 4 | ||
Log = 5 | ||
SquareRoot = 6 | ||
InvSquareRoot = 7 | ||
Absolute = 8 | ||
#Exponent = | ||
Min = 9 | ||
Max = 10 | ||
LessThan = 11 | ||
GreaterThan = 12 | ||
Sign = 13 | ||
Compare = 14 | ||
#SmoothMin = | ||
#SmoothMax = | ||
Round = 15 | ||
Floor = 16 | ||
Ceil = 17 | ||
Truncate = 18 | ||
Fraction = 19 | ||
Modulo = 20 | ||
#Wrap = | ||
#Snap = | ||
#PingPong = | ||
Sine = 21 | ||
Cosine = 22 | ||
Tangent = 23 | ||
#ArcSine = | ||
#ArcCosine = | ||
#ArcTangent = | ||
#ArcTan2 = | ||
#HyperbolicSine = | ||
#HyperbolicCosine = | ||
#HyperbolicTangent = | ||
ToRadians = 24 | ||
ToDegrees = 25 | ||
|
||
class _value_arg_math(ct.Structure): | ||
_fields_ = [ | ||
("A", ct.POINTER(_value)), | ||
("B", ct.POINTER(_value)), | ||
("op", _math_op) | ||
] | ||
|
||
class _value_arg_grayscale(ct.Structure): | ||
_fields_ = [ | ||
("color", ct.POINTER(_color)) | ||
] |
Oops, something went wrong.