2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2018-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
from mathutils import Color, Vector
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
"PrincipledBSDFWrapper",
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _set_check(func):
|
|
|
|
from functools import wraps
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@wraps(func)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
if self.is_readonly:
|
2022-09-14 16:18:59 +10:00
|
|
|
assert not "Trying to set value to read-only shader!"
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
return
|
|
|
|
return func(self, *args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
def rgb_to_rgba(rgb):
|
|
|
|
return list(rgb) + [1.0]
|
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
def rgba_to_rgb(rgba):
|
|
|
|
return Color((rgba[0], rgba[1], rgba[2]))
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2019-07-30 11:17:01 +02:00
|
|
|
# All clamping value shall follow Blender's defined min/max (check relevant node definition .c file).
|
|
|
|
def values_clamp(val, minv, maxv):
|
|
|
|
if hasattr(val, "__iter__"):
|
|
|
|
return tuple(max(minv, min(maxv, v)) for v in val)
|
|
|
|
else:
|
|
|
|
return max(minv, min(maxv, val))
|
|
|
|
|
2024-03-13 05:22:43 +01:00
|
|
|
# TODO: Consider moving node_input_value_set/node_input_value_get into a common utility module if
|
|
|
|
# more usage merits doing so. If that is done, abstract out the validity check and make it usable
|
|
|
|
# for node outputs as well. See PR #119354 for details.
|
2024-03-13 10:39:22 +01:00
|
|
|
|
|
|
|
|
2024-03-13 05:22:43 +01:00
|
|
|
def node_input_value_set(node, input, value):
|
|
|
|
if node is None or input not in node.inputs:
|
|
|
|
return
|
|
|
|
|
|
|
|
node.inputs[input].default_value = value
|
|
|
|
|
|
|
|
|
|
|
|
def node_input_value_get(node, input, default_value=None):
|
|
|
|
if node is None or input not in node.inputs:
|
|
|
|
return default_value
|
|
|
|
|
|
|
|
return node.inputs[input].default_value
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
|
2025-02-04 14:51:17 +11:00
|
|
|
class ShaderWrapper:
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
"""
|
|
|
|
Base class with minimal common ground for all types of shader interfaces we may want/need to implement.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# The two mandatory nodes any children class should support.
|
|
|
|
NODES_LIST = (
|
|
|
|
"node_out",
|
|
|
|
|
|
|
|
"_node_texcoords",
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
__slots__ = (
|
|
|
|
"is_readonly",
|
|
|
|
"material",
|
|
|
|
"_textures",
|
|
|
|
"_grid_locations",
|
2018-10-01 08:45:46 +10:00
|
|
|
*NODES_LIST,
|
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
_col_size = 300
|
|
|
|
_row_size = 300
|
|
|
|
|
|
|
|
def _grid_to_location(self, x, y, dst_node=None, ref_node=None):
|
|
|
|
if ref_node is not None: # x and y are relative to this node location.
|
|
|
|
nx = round(ref_node.location.x / self._col_size)
|
|
|
|
ny = round(ref_node.location.y / self._row_size)
|
|
|
|
x += nx
|
|
|
|
y += ny
|
|
|
|
loc = None
|
|
|
|
while True:
|
|
|
|
loc = (x * self._col_size, y * self._row_size)
|
|
|
|
if loc not in self._grid_locations:
|
|
|
|
break
|
|
|
|
loc = (x * self._col_size, (y - 1) * self._row_size)
|
|
|
|
if loc not in self._grid_locations:
|
|
|
|
break
|
|
|
|
loc = (x * self._col_size, (y - 2) * self._row_size)
|
|
|
|
if loc not in self._grid_locations:
|
|
|
|
break
|
|
|
|
x -= 1
|
|
|
|
self._grid_locations.add(loc)
|
|
|
|
if dst_node is not None:
|
|
|
|
dst_node.location = loc
|
|
|
|
dst_node.width = min(dst_node.width, self._col_size - 20)
|
|
|
|
return loc
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
def __init__(self, material, is_readonly=True, use_nodes=True):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.is_readonly = is_readonly
|
|
|
|
self.material = material
|
2018-10-16 16:32:43 +02:00
|
|
|
if not is_readonly:
|
|
|
|
self.use_nodes = use_nodes
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self): # Should be re-implemented by children classes...
|
|
|
|
for node in self.NODES_LIST:
|
|
|
|
setattr(self, node, None)
|
|
|
|
self._textures = {}
|
|
|
|
self._grid_locations = set()
|
|
|
|
|
|
|
|
def use_nodes_get(self):
|
|
|
|
return self.material.use_nodes
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def use_nodes_set(self, val):
|
|
|
|
self.material.use_nodes = val
|
|
|
|
self.update()
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
use_nodes = property(use_nodes_get, use_nodes_set)
|
|
|
|
|
|
|
|
def node_texcoords_get(self):
|
|
|
|
if not self.use_nodes:
|
|
|
|
return None
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_texcoords is ...:
|
|
|
|
# Running only once, trying to find a valid texcoords node.
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
for n in self.material.node_tree.nodes:
|
|
|
|
if n.bl_idname == 'ShaderNodeTexCoord':
|
|
|
|
self._node_texcoords = n
|
|
|
|
self._grid_to_location(0, 0, ref_node=n)
|
|
|
|
break
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_texcoords is ...:
|
|
|
|
self._node_texcoords = None
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self._node_texcoords is None and not self.is_readonly:
|
|
|
|
tree = self.material.node_tree
|
|
|
|
nodes = tree.nodes
|
2019-03-17 21:13:25 +11:00
|
|
|
# links = tree.links
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
node_texcoords = nodes.new(type='ShaderNodeTexCoord')
|
|
|
|
node_texcoords.label = "Texture Coords"
|
|
|
|
self._grid_to_location(-5, 1, dst_node=node_texcoords)
|
|
|
|
self._node_texcoords = node_texcoords
|
|
|
|
return self._node_texcoords
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
node_texcoords = property(node_texcoords_get)
|
|
|
|
|
|
|
|
|
|
|
|
class PrincipledBSDFWrapper(ShaderWrapper):
|
|
|
|
"""
|
|
|
|
Hard coded shader setup, based in Principled BSDF.
|
|
|
|
Should cover most common cases on import, and gives a basic nodal shaders support for export.
|
|
|
|
Supports basic: diffuse/spec/reflect/transparency/normal, with texturing.
|
|
|
|
"""
|
|
|
|
NODES_LIST = (
|
|
|
|
"node_out",
|
|
|
|
"node_principled_bsdf",
|
|
|
|
|
|
|
|
"_node_normalmap",
|
|
|
|
"_node_texcoords",
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
__slots__ = (
|
|
|
|
"is_readonly",
|
|
|
|
"material",
|
2018-10-01 08:45:46 +10:00
|
|
|
*NODES_LIST,
|
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
NODES_LIST = ShaderWrapper.NODES_LIST + NODES_LIST
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
def __init__(self, material, is_readonly=True, use_nodes=True):
|
|
|
|
super(PrincipledBSDFWrapper, self).__init__(material, is_readonly, use_nodes)
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
def update(self):
|
|
|
|
super(PrincipledBSDFWrapper, self).update()
|
|
|
|
|
|
|
|
if not self.use_nodes:
|
|
|
|
return
|
|
|
|
|
|
|
|
tree = self.material.node_tree
|
|
|
|
|
|
|
|
nodes = tree.nodes
|
|
|
|
links = tree.links
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Main output and shader.
|
|
|
|
node_out = None
|
|
|
|
node_principled = None
|
|
|
|
for n in nodes:
|
|
|
|
if n.bl_idname == 'ShaderNodeOutputMaterial' and n.inputs[0].is_linked:
|
|
|
|
node_out = n
|
|
|
|
node_principled = n.inputs[0].links[0].from_node
|
|
|
|
elif n.bl_idname == 'ShaderNodeBsdfPrincipled' and n.outputs[0].is_linked:
|
|
|
|
node_principled = n
|
|
|
|
for lnk in n.outputs[0].links:
|
|
|
|
node_out = lnk.to_node
|
|
|
|
if node_out.bl_idname == 'ShaderNodeOutputMaterial':
|
|
|
|
break
|
2018-10-01 08:42:58 +10:00
|
|
|
if (
|
|
|
|
node_out is not None and node_principled is not None and
|
|
|
|
node_out.bl_idname == 'ShaderNodeOutputMaterial' and
|
|
|
|
node_principled.bl_idname == 'ShaderNodeBsdfPrincipled'
|
|
|
|
):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
break
|
|
|
|
node_out = node_principled = None # Could not find a valid pair, let's try again
|
|
|
|
|
|
|
|
if node_out is not None:
|
|
|
|
self._grid_to_location(0, 0, ref_node=node_out)
|
|
|
|
elif not self.is_readonly:
|
|
|
|
node_out = nodes.new(type='ShaderNodeOutputMaterial')
|
|
|
|
node_out.label = "Material Out"
|
|
|
|
node_out.target = 'ALL'
|
|
|
|
self._grid_to_location(1, 1, dst_node=node_out)
|
|
|
|
self.node_out = node_out
|
|
|
|
|
|
|
|
if node_principled is not None:
|
|
|
|
self._grid_to_location(0, 0, ref_node=node_principled)
|
|
|
|
elif not self.is_readonly:
|
|
|
|
node_principled = nodes.new(type='ShaderNodeBsdfPrincipled')
|
|
|
|
node_principled.label = "Principled BSDF"
|
|
|
|
self._grid_to_location(0, 1, dst_node=node_principled)
|
|
|
|
# Link
|
|
|
|
links.new(node_principled.outputs["BSDF"], self.node_out.inputs["Surface"])
|
|
|
|
self.node_principled_bsdf = node_principled
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Normal Map, lazy initialization...
|
2018-10-13 19:27:12 +02:00
|
|
|
self._node_normalmap = ...
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Tex Coords, lazy initialization...
|
2018-10-13 19:27:12 +02:00
|
|
|
self._node_texcoords = ...
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
def node_normalmap_get(self):
|
2018-10-17 20:18:40 +02:00
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
return None
|
2018-10-17 20:18:40 +02:00
|
|
|
node_principled = self.node_principled_bsdf
|
|
|
|
if self._node_normalmap is ...:
|
|
|
|
# Running only once, trying to find a valid normalmap node.
|
|
|
|
if node_principled.inputs["Normal"].is_linked:
|
|
|
|
node_normalmap = node_principled.inputs["Normal"].links[0].from_node
|
|
|
|
if node_normalmap.bl_idname == 'ShaderNodeNormalMap':
|
|
|
|
self._node_normalmap = node_normalmap
|
|
|
|
self._grid_to_location(0, 0, ref_node=node_normalmap)
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_normalmap is ...:
|
2018-10-17 20:18:40 +02:00
|
|
|
self._node_normalmap = None
|
|
|
|
if self._node_normalmap is None and not self.is_readonly:
|
|
|
|
tree = self.material.node_tree
|
|
|
|
nodes = tree.nodes
|
|
|
|
links = tree.links
|
|
|
|
|
|
|
|
node_normalmap = nodes.new(type='ShaderNodeNormalMap')
|
|
|
|
node_normalmap.label = "Normal/Map"
|
|
|
|
self._grid_to_location(-1, -2, dst_node=node_normalmap, ref_node=node_principled)
|
|
|
|
# Link
|
|
|
|
links.new(node_normalmap.outputs["Normal"], node_principled.inputs["Normal"])
|
2018-11-16 14:58:37 +01:00
|
|
|
self._node_normalmap = node_normalmap
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
return self._node_normalmap
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
node_normalmap = property(node_normalmap_get)
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
2018-10-12 15:39:56 +02:00
|
|
|
# Base Color.
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
def base_color_get(self):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return self.material.diffuse_color
|
2018-10-12 15:39:56 +02:00
|
|
|
return rgba_to_rgb(self.node_principled_bsdf.inputs["Base Color"].default_value)
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
2018-10-12 15:39:56 +02:00
|
|
|
def base_color_set(self, color):
|
2019-07-30 11:17:01 +02:00
|
|
|
color = values_clamp(color, 0.0, 1.0)
|
2019-01-30 14:37:09 +01:00
|
|
|
color = rgb_to_rgba(color)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.material.diffuse_color = color
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
2019-01-30 14:37:09 +01:00
|
|
|
self.node_principled_bsdf.inputs["Base Color"].default_value = color
|
2018-10-13 19:27:12 +02:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
base_color = property(base_color_get, base_color_set)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
def base_color_texture_get(self):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Base Color"],
|
|
|
|
grid_row_diff=1,
|
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
2018-10-12 15:39:56 +02:00
|
|
|
base_color_texture = property(base_color_texture_get)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Specular.
|
|
|
|
|
|
|
|
def specular_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return self.material.specular_intensity
|
2023-09-25 12:52:13 +02:00
|
|
|
return self.node_principled_bsdf.inputs["Specular IOR Level"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def specular_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.material.specular_intensity = value
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
2023-09-25 12:52:13 +02:00
|
|
|
self.node_principled_bsdf.inputs["Specular IOR Level"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
specular = property(specular_get, specular_set)
|
|
|
|
|
2023-09-26 19:22:26 +02:00
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def specular_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Specular IOR Level"],
|
|
|
|
grid_row_diff=0,
|
|
|
|
colorspace_name='Non-Color',
|
|
|
|
)
|
|
|
|
|
|
|
|
specular_texture = property(specular_texture_get)
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Specular Tint.
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
def specular_tint_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
2023-09-22 16:56:44 +02:00
|
|
|
return Color((0.0, 0.0, 0.0))
|
|
|
|
return rgba_to_rgb(self.node_principled_bsdf.inputs["Specular Tint"].default_value)
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
2023-09-22 16:56:44 +02:00
|
|
|
def specular_tint_set(self, color):
|
|
|
|
color = values_clamp(color, 0.0, 1.0)
|
|
|
|
color = rgb_to_rgba(color)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
2023-09-22 16:56:44 +02:00
|
|
|
self.node_principled_bsdf.inputs["Specular Tint"].default_value = color
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
specular_tint = property(specular_tint_get, specular_tint_set)
|
|
|
|
|
2023-09-26 19:22:26 +02:00
|
|
|
def specular_tint_texture_get(self):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
2023-09-26 19:22:26 +02:00
|
|
|
self.node_principled_bsdf.inputs["Specular Tint"],
|
2018-10-01 08:42:58 +10:00
|
|
|
grid_row_diff=0,
|
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
2023-09-26 19:22:26 +02:00
|
|
|
specular_tint_texture = property(specular_tint_texture_get)
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Roughness (also sort of inverse of specular hardness...).
|
|
|
|
|
|
|
|
def roughness_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return self.material.roughness
|
|
|
|
return self.node_principled_bsdf.inputs["Roughness"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def roughness_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.material.roughness = value
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
|
|
|
self.node_principled_bsdf.inputs["Roughness"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
roughness = property(roughness_get, roughness_set)
|
|
|
|
|
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def roughness_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Roughness"],
|
|
|
|
grid_row_diff=0,
|
2019-10-17 11:35:38 +02:00
|
|
|
colorspace_name='Non-Color',
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
roughness_texture = property(roughness_texture_get)
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Metallic (a.k.a reflection, mirror).
|
|
|
|
|
|
|
|
def metallic_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return self.material.metallic
|
|
|
|
return self.node_principled_bsdf.inputs["Metallic"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def metallic_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.material.metallic = value
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
|
|
|
self.node_principled_bsdf.inputs["Metallic"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
metallic = property(metallic_get, metallic_set)
|
|
|
|
|
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def metallic_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Metallic"],
|
|
|
|
grid_row_diff=0,
|
2023-04-18 10:42:00 +10:00
|
|
|
colorspace_name="Non-Color",
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
metallic_texture = property(metallic_texture_get)
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Transparency settings.
|
|
|
|
|
|
|
|
def ior_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return 1.0
|
|
|
|
return self.node_principled_bsdf.inputs["IOR"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def ior_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1000.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
|
|
|
self.node_principled_bsdf.inputs["IOR"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
ior = property(ior_get, ior_set)
|
|
|
|
|
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def ior_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["IOR"],
|
|
|
|
grid_row_diff=-1,
|
2019-10-17 11:35:38 +02:00
|
|
|
colorspace_name='Non-Color',
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
ior_texture = property(ior_texture_get)
|
|
|
|
|
|
|
|
def transmission_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return 0.0
|
2023-09-25 14:43:12 +02:00
|
|
|
return self.node_principled_bsdf.inputs["Transmission Weight"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def transmission_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
2023-09-25 14:43:12 +02:00
|
|
|
self.node_principled_bsdf.inputs["Transmission Weight"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
transmission = property(transmission_get, transmission_set)
|
|
|
|
|
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def transmission_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
2023-09-25 14:43:12 +02:00
|
|
|
self.node_principled_bsdf.inputs["Transmission Weight"],
|
2018-10-01 08:42:58 +10:00
|
|
|
grid_row_diff=-1,
|
2019-10-17 11:35:38 +02:00
|
|
|
colorspace_name='Non-Color',
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
transmission_texture = property(transmission_texture_get)
|
|
|
|
|
2019-05-15 20:58:18 +02:00
|
|
|
def alpha_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return 1.0
|
|
|
|
return self.node_principled_bsdf.inputs["Alpha"].default_value
|
|
|
|
|
|
|
|
@_set_check
|
|
|
|
def alpha_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 1.0)
|
2019-05-15 20:58:18 +02:00
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
|
|
|
self.node_principled_bsdf.inputs["Alpha"].default_value = value
|
|
|
|
|
|
|
|
alpha = property(alpha_get, alpha_set)
|
|
|
|
|
|
|
|
# Will only be used as gray-scale one...
|
|
|
|
def alpha_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Alpha"],
|
2020-09-16 16:36:33 +02:00
|
|
|
use_alpha=True,
|
2019-05-15 20:58:18 +02:00
|
|
|
grid_row_diff=-1,
|
2019-10-17 11:35:38 +02:00
|
|
|
colorspace_name='Non-Color',
|
2019-05-15 20:58:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
alpha_texture = property(alpha_texture_get)
|
|
|
|
|
2019-10-10 17:17:04 +02:00
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Emission color.
|
|
|
|
|
|
|
|
def emission_color_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return Color((0.0, 0.0, 0.0))
|
2023-09-22 17:05:47 +02:00
|
|
|
return rgba_to_rgb(self.node_principled_bsdf.inputs["Emission Color"].default_value)
|
2019-10-10 17:17:04 +02:00
|
|
|
|
|
|
|
@_set_check
|
|
|
|
def emission_color_set(self, color):
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
2020-09-09 11:36:57 +02:00
|
|
|
color = values_clamp(color, 0.0, 1000000.0)
|
2019-10-10 17:17:04 +02:00
|
|
|
color = rgb_to_rgba(color)
|
2023-09-22 17:05:47 +02:00
|
|
|
self.node_principled_bsdf.inputs["Emission Color"].default_value = color
|
2019-10-10 17:17:04 +02:00
|
|
|
|
|
|
|
emission_color = property(emission_color_get, emission_color_set)
|
|
|
|
|
|
|
|
def emission_color_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
2023-09-22 17:05:47 +02:00
|
|
|
self.node_principled_bsdf.inputs["Emission Color"],
|
2019-10-10 17:17:04 +02:00
|
|
|
grid_row_diff=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
emission_color_texture = property(emission_color_texture_get)
|
|
|
|
|
2020-09-09 11:36:57 +02:00
|
|
|
def emission_strength_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return 1.0
|
|
|
|
return self.node_principled_bsdf.inputs["Emission Strength"].default_value
|
|
|
|
|
|
|
|
@_set_check
|
|
|
|
def emission_strength_set(self, value):
|
|
|
|
value = values_clamp(value, 0.0, 1000000.0)
|
|
|
|
if self.use_nodes and self.node_principled_bsdf is not None:
|
|
|
|
self.node_principled_bsdf.inputs["Emission Strength"].default_value = value
|
|
|
|
|
|
|
|
emission_strength = property(emission_strength_get, emission_strength_set)
|
|
|
|
|
|
|
|
def emission_strength_texture_get(self):
|
|
|
|
if not self.use_nodes or self.node_principled_bsdf is None:
|
|
|
|
return None
|
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_principled_bsdf,
|
|
|
|
self.node_principled_bsdf.inputs["Emission Strength"],
|
|
|
|
grid_row_diff=-1,
|
|
|
|
colorspace_name='Non-Color',
|
|
|
|
)
|
|
|
|
|
|
|
|
emission_strength_texture = property(emission_strength_texture_get)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Normal map.
|
|
|
|
|
|
|
|
def normalmap_strength_get(self):
|
|
|
|
if not self.use_nodes or self.node_normalmap is None:
|
|
|
|
return 0.0
|
|
|
|
return self.node_normalmap.inputs["Strength"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def normalmap_strength_set(self, value):
|
2019-07-30 11:17:01 +02:00
|
|
|
value = values_clamp(value, 0.0, 10.0)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.use_nodes and self.node_normalmap is not None:
|
|
|
|
self.node_normalmap.inputs["Strength"].default_value = value
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
normalmap_strength = property(normalmap_strength_get, normalmap_strength_set)
|
|
|
|
|
|
|
|
def normalmap_texture_get(self):
|
2018-10-17 20:17:02 +02:00
|
|
|
if not self.use_nodes or self.node_normalmap is None:
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
return None
|
2018-10-01 08:42:58 +10:00
|
|
|
return ShaderImageTextureWrapper(
|
|
|
|
self, self.node_normalmap,
|
|
|
|
self.node_normalmap.inputs["Color"],
|
|
|
|
grid_row_diff=-2,
|
2019-07-03 18:35:06 +02:00
|
|
|
colorspace_is_data=True,
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
normalmap_texture = property(normalmap_texture_get)
|
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
2025-02-04 14:51:17 +11:00
|
|
|
class ShaderImageTextureWrapper:
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
"""
|
|
|
|
Generic 'image texture'-like wrapper, handling image node, some mapping (texture coordinates transformations),
|
|
|
|
and texture coordinates source.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Note: this class assumes we are using nodes, otherwise it should never be used...
|
|
|
|
|
|
|
|
NODES_LIST = (
|
|
|
|
"node_dst",
|
|
|
|
"socket_dst",
|
|
|
|
|
|
|
|
"_node_image",
|
|
|
|
"_node_mapping",
|
2018-10-01 08:42:58 +10:00
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
__slots__ = (
|
|
|
|
"owner_shader",
|
|
|
|
"is_readonly",
|
|
|
|
"grid_row_diff",
|
|
|
|
"use_alpha",
|
2019-07-03 18:35:06 +02:00
|
|
|
"colorspace_is_data",
|
2019-10-17 11:35:38 +02:00
|
|
|
"colorspace_name",
|
2018-10-01 08:45:46 +10:00
|
|
|
*NODES_LIST,
|
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2019-05-09 13:11:36 +10:00
|
|
|
def __new__(cls, owner_shader: ShaderWrapper, node_dst, socket_dst, *_args, **_kwargs):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
instance = owner_shader._textures.get((node_dst, socket_dst), None)
|
|
|
|
if instance is not None:
|
|
|
|
return instance
|
|
|
|
instance = super(ShaderImageTextureWrapper, cls).__new__(cls)
|
|
|
|
owner_shader._textures[(node_dst, socket_dst)] = instance
|
|
|
|
return instance
|
|
|
|
|
2019-07-03 18:35:06 +02:00
|
|
|
def __init__(self, owner_shader: ShaderWrapper, node_dst, socket_dst, grid_row_diff=0,
|
2019-10-17 11:35:38 +02:00
|
|
|
use_alpha=False, colorspace_is_data=..., colorspace_name=...):
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.owner_shader = owner_shader
|
|
|
|
self.is_readonly = owner_shader.is_readonly
|
|
|
|
self.node_dst = node_dst
|
|
|
|
self.socket_dst = socket_dst
|
|
|
|
self.grid_row_diff = grid_row_diff
|
|
|
|
self.use_alpha = use_alpha
|
2019-07-03 18:35:06 +02:00
|
|
|
self.colorspace_is_data = colorspace_is_data
|
2019-10-17 11:35:38 +02:00
|
|
|
self.colorspace_name = colorspace_name
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
self._node_image = ...
|
|
|
|
self._node_mapping = ...
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
2019-05-09 13:11:36 +10:00
|
|
|
# tree = node_dst.id_data
|
2019-03-17 21:13:25 +11:00
|
|
|
# nodes = tree.nodes
|
|
|
|
# links = tree.links
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
if socket_dst.is_linked:
|
2018-10-13 19:27:12 +02:00
|
|
|
from_node = socket_dst.links[0].from_node
|
|
|
|
if from_node.bl_idname == 'ShaderNodeTexImage':
|
|
|
|
self._node_image = from_node
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
if self.node_image is not None:
|
|
|
|
socket_dst = self.node_image.inputs["Vector"]
|
|
|
|
if socket_dst.is_linked:
|
|
|
|
from_node = socket_dst.links[0].from_node
|
|
|
|
if from_node.bl_idname == 'ShaderNodeMapping':
|
|
|
|
self._node_mapping = from_node
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
def copy_from(self, tex):
|
|
|
|
# Avoid generating any node in source texture.
|
|
|
|
is_readonly_back = tex.is_readonly
|
|
|
|
tex.is_readonly = True
|
|
|
|
|
|
|
|
if tex.node_image is not None:
|
|
|
|
self.image = tex.image
|
|
|
|
self.projection = tex.projection
|
|
|
|
self.texcoords = tex.texcoords
|
|
|
|
self.copy_mapping_from(tex)
|
|
|
|
|
|
|
|
tex.is_readonly = is_readonly_back
|
|
|
|
|
|
|
|
def copy_mapping_from(self, tex):
|
|
|
|
# Avoid generating any node in source texture.
|
|
|
|
is_readonly_back = tex.is_readonly
|
|
|
|
tex.is_readonly = True
|
|
|
|
|
|
|
|
if tex.node_mapping is None: # Used to actually remove mapping node.
|
|
|
|
if self.has_mapping_node():
|
|
|
|
# We assume node_image can never be None in that case...
|
|
|
|
# Find potential existing link into image's Vector input.
|
|
|
|
socket_dst = socket_src = None
|
|
|
|
if self.node_mapping.inputs["Vector"].is_linked:
|
|
|
|
socket_dst = self.node_image.inputs["Vector"]
|
|
|
|
socket_src = self.node_mapping.inputs["Vector"].links[0].from_socket
|
|
|
|
|
|
|
|
tree = self.owner_shader.material.node_tree
|
|
|
|
tree.nodes.remove(self.node_mapping)
|
|
|
|
self._node_mapping = None
|
|
|
|
|
|
|
|
# If previously existing, re-link texcoords -> image
|
|
|
|
if socket_src is not None:
|
|
|
|
tree.links.new(socket_src, socket_dst)
|
|
|
|
elif self.node_mapping is not None:
|
|
|
|
self.translation = tex.translation
|
|
|
|
self.rotation = tex.rotation
|
|
|
|
self.scale = tex.scale
|
|
|
|
|
|
|
|
tex.is_readonly = is_readonly_back
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Image.
|
|
|
|
|
|
|
|
def node_image_get(self):
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_image is ...:
|
|
|
|
# Running only once, trying to find a valid image node.
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.socket_dst.is_linked:
|
|
|
|
node_image = self.socket_dst.links[0].from_node
|
|
|
|
if node_image.bl_idname == 'ShaderNodeTexImage':
|
|
|
|
self._node_image = node_image
|
|
|
|
self.owner_shader._grid_to_location(0, 0, ref_node=node_image)
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_image is ...:
|
|
|
|
self._node_image = None
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self._node_image is None and not self.is_readonly:
|
|
|
|
tree = self.owner_shader.material.node_tree
|
|
|
|
|
|
|
|
node_image = tree.nodes.new(type='ShaderNodeTexImage')
|
2021-07-06 12:05:27 +10:00
|
|
|
self.owner_shader._grid_to_location(
|
|
|
|
-1, 0 + self.grid_row_diff,
|
|
|
|
dst_node=node_image, ref_node=self.node_dst,
|
|
|
|
)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
tree.links.new(node_image.outputs["Alpha" if self.use_alpha else "Color"], self.socket_dst)
|
2020-12-29 16:38:40 +01:00
|
|
|
if self.use_alpha:
|
2024-11-25 10:51:45 +01:00
|
|
|
self.owner_shader.material.surface_render_method = 'DITHERED'
|
2024-06-04 14:48:40 +02:00
|
|
|
self.owner_shader.material.use_transparency_overlap = False
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
self._node_image = node_image
|
|
|
|
return self._node_image
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
node_image = property(node_image_get)
|
|
|
|
|
|
|
|
def image_get(self):
|
|
|
|
return self.node_image.image if self.node_image is not None else None
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def image_set(self, image):
|
2019-07-03 18:35:06 +02:00
|
|
|
if self.colorspace_is_data is not ...:
|
2019-10-17 11:35:38 +02:00
|
|
|
if image.colorspace_settings.is_data != self.colorspace_is_data and image.users >= 1:
|
|
|
|
image = image.copy()
|
2019-07-03 18:35:06 +02:00
|
|
|
image.colorspace_settings.is_data = self.colorspace_is_data
|
2019-10-17 11:35:38 +02:00
|
|
|
if self.colorspace_name is not ...:
|
2021-01-27 18:16:02 +11:00
|
|
|
if image.colorspace_settings.name != self.colorspace_name and image.users >= 1:
|
2019-10-17 11:35:38 +02:00
|
|
|
image = image.copy()
|
|
|
|
image.colorspace_settings.name = self.colorspace_name
|
2020-12-29 16:38:40 +01:00
|
|
|
if self.use_alpha:
|
|
|
|
# Try to be smart, and only use image's alpha output if image actually has alpha data.
|
|
|
|
tree = self.owner_shader.material.node_tree
|
|
|
|
if image.channels < 4 or image.depth in {24, 8}:
|
|
|
|
tree.links.new(self.node_image.outputs["Color"], self.socket_dst)
|
|
|
|
else:
|
|
|
|
tree.links.new(self.node_image.outputs["Alpha"], self.socket_dst)
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
self.node_image.image = image
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
image = property(image_get, image_set)
|
|
|
|
|
|
|
|
def projection_get(self):
|
|
|
|
return self.node_image.projection if self.node_image is not None else 'FLAT'
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def projection_set(self, projection):
|
|
|
|
self.node_image.projection = projection
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
projection = property(projection_get, projection_set)
|
|
|
|
|
|
|
|
def texcoords_get(self):
|
|
|
|
if self.node_image is not None:
|
2018-10-13 19:27:12 +02:00
|
|
|
socket = (self.node_mapping if self.has_mapping_node() else self.node_image).inputs["Vector"]
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if socket.is_linked:
|
|
|
|
return socket.links[0].from_socket.name
|
|
|
|
return 'UV'
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def texcoords_set(self, texcoords):
|
2018-10-12 15:39:56 +02:00
|
|
|
# Image texture node already defaults to UVs, no extra node needed.
|
2018-10-13 19:27:12 +02:00
|
|
|
# ONLY in case we do not have any texcoords mapping!!!
|
|
|
|
if texcoords == 'UV' and not self.has_mapping_node():
|
2018-10-12 15:39:56 +02:00
|
|
|
return
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
tree = self.node_image.id_data
|
|
|
|
links = tree.links
|
2018-10-13 19:27:12 +02:00
|
|
|
node_dst = self.node_mapping if self.has_mapping_node() else self.node_image
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
socket_src = self.owner_shader.node_texcoords.outputs[texcoords]
|
|
|
|
links.new(socket_src, node_dst.inputs["Vector"])
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
texcoords = property(texcoords_get, texcoords_set)
|
|
|
|
|
2018-10-16 16:32:43 +02:00
|
|
|
def extension_get(self):
|
|
|
|
return self.node_image.extension if self.node_image is not None else 'REPEAT'
|
|
|
|
|
|
|
|
@_set_check
|
|
|
|
def extension_set(self, extension):
|
|
|
|
self.node_image.extension = extension
|
|
|
|
|
|
|
|
extension = property(extension_get, extension_set)
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# Mapping.
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
def has_mapping_node(self):
|
|
|
|
return self._node_mapping not in {None, ...}
|
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
def node_mapping_get(self):
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_mapping is ...:
|
|
|
|
# Running only once, trying to find a valid mapping node.
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self.node_image is None:
|
|
|
|
return None
|
|
|
|
if self.node_image.inputs["Vector"].is_linked:
|
|
|
|
node_mapping = self.node_image.inputs["Vector"].links[0].from_node
|
|
|
|
if node_mapping.bl_idname == 'ShaderNodeMapping':
|
|
|
|
self._node_mapping = node_mapping
|
|
|
|
self.owner_shader._grid_to_location(0, 0 + self.grid_row_diff, ref_node=node_mapping)
|
2018-10-13 19:27:12 +02:00
|
|
|
if self._node_mapping is ...:
|
|
|
|
self._node_mapping = None
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
if self._node_mapping is None and not self.is_readonly:
|
|
|
|
# Find potential existing link into image's Vector input.
|
|
|
|
socket_dst = self.node_image.inputs["Vector"]
|
2018-10-13 19:27:12 +02:00
|
|
|
# If not already existing, we need to create texcoords -> mapping link (from UV).
|
|
|
|
socket_src = (socket_dst.links[0].from_socket if socket_dst.is_linked
|
2021-07-06 12:05:27 +10:00
|
|
|
else self.owner_shader.node_texcoords.outputs['UV'])
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
tree = self.owner_shader.material.node_tree
|
|
|
|
node_mapping = tree.nodes.new(type='ShaderNodeMapping')
|
|
|
|
node_mapping.vector_type = 'TEXTURE'
|
|
|
|
self.owner_shader._grid_to_location(-1, 0, dst_node=node_mapping, ref_node=self.node_image)
|
|
|
|
|
2018-10-13 19:27:12 +02:00
|
|
|
# Link mapping -> image node.
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
tree.links.new(node_mapping.outputs["Vector"], socket_dst)
|
2018-10-13 19:27:12 +02:00
|
|
|
# Link texcoords -> mapping.
|
|
|
|
tree.links.new(socket_src, node_mapping.inputs["Vector"])
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
|
|
|
|
self._node_mapping = node_mapping
|
|
|
|
return self._node_mapping
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
node_mapping = property(node_mapping_get)
|
|
|
|
|
|
|
|
def translation_get(self):
|
2024-03-13 05:22:43 +01:00
|
|
|
return node_input_value_get(self.node_mapping, "Location", Vector((0.0, 0.0, 0.0)))
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def translation_set(self, translation):
|
2024-03-13 05:22:43 +01:00
|
|
|
node_input_value_set(self.node_mapping, "Location", translation)
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
translation = property(translation_get, translation_set)
|
|
|
|
|
|
|
|
def rotation_get(self):
|
2019-09-06 22:06:25 +02:00
|
|
|
if self.node_mapping is None:
|
|
|
|
return Vector((0.0, 0.0, 0.0))
|
2023-04-18 10:42:00 +10:00
|
|
|
return self.node_mapping.inputs["Rotation"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def rotation_set(self, rotation):
|
2023-04-18 10:42:00 +10:00
|
|
|
self.node_mapping.inputs["Rotation"].default_value = rotation
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
rotation = property(rotation_get, rotation_set)
|
|
|
|
|
|
|
|
def scale_get(self):
|
2019-09-06 22:06:25 +02:00
|
|
|
if self.node_mapping is None:
|
2019-10-09 20:31:54 +02:00
|
|
|
return Vector((1.0, 1.0, 1.0))
|
2023-04-18 10:42:00 +10:00
|
|
|
return self.node_mapping.inputs["Scale"].default_value
|
2018-10-01 08:42:58 +10:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
@_set_check
|
|
|
|
def scale_set(self, scale):
|
2023-04-18 10:42:00 +10:00
|
|
|
self.node_mapping.inputs["Scale"].default_value = scale
|
2018-10-13 19:27:12 +02:00
|
|
|
|
Python IO: Initial nodal shader support for import AND export.
That new bpy_extras' node_shader_utils module is remotely based on
existing addons' cycles_shader_compat module. It has some key
differences though:
- It is based on Principled shader, instead of the noodle combination
of half a dozen simpler shaders.
- It does not do any value conversion (like e.g. clamping, which was
only suited for FBX). Any conversion/adaptation is to be done
by each IO add-on.
- It extensively uses accessors to offer:
- Easy read/write of values, hiding all the hairy noodly nodes
(principled shader helps a lot here).
- lazy creation of most nodes on accessing (when generating a
material), which avoids getting unused nodes in final shader.
- We only use Principled BSDF so far though, which means some features
supported by previous system are not yet implemented in new one.
Note that, even though we support 'exporting' side of things, this will
only work for a very specific (and basic) kind of shader. This will have
to be clearly explained in end-user documentation.
Also, that code has had some basic testing, but most certainly needs a
lot more refinement.
As proof-of-concept, OBJ IO script will be updated to use that new
system after that commit.
2018-09-27 22:03:30 +02:00
|
|
|
scale = property(scale_get, scale_set)
|