Skip to content

Commit

Permalink
add new front/back opacity node
Browse files Browse the repository at this point in the history
  • Loading branch information
Theverat committed Mar 24, 2019
1 parent cfa276f commit 5d45c07
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 4 additions & 2 deletions nodes/materials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from .. import LuxCoreNodeTree

# Import all material nodes just so they get registered
from .emission import LuxCoreNodeMatEmission
from .carpaint import LuxCoreNodeMatCarpaint
from .cloth import LuxCoreNodeMatCloth
from .emission import LuxCoreNodeMatEmission
from .frontbackopacity import LuxCoreNodeMatFrontBackOpacity
from .glass import LuxCoreNodeMatGlass
from .glossytranslucent import LuxCoreNodeMatGlossyTranslucent
from .glossy2 import LuxCoreNodeMatGlossy2
from .glossycoating import LuxCoreNodeMatGlossyCoating
from .carpaint import LuxCoreNodeMatCarpaint
from .matte import LuxCoreNodeMatMatte
from .mattetranslucent import LuxCoreNodeMatMatteTranslucent
from .metal import LuxCoreNodeMatMetal
Expand Down Expand Up @@ -82,6 +83,7 @@ def poll(cls, context):
NodeItem("LuxCoreNodeMatCarpaint", label="Carpaint"),
NodeItem("LuxCoreNodeMatCloth", label="Cloth"),
NodeItem("LuxCoreNodeMatVelvet", label="Velvet"),
NodeItem("LuxCoreNodeMatFrontBackOpacity", label="Front/Back Opacity"),
]),

LuxCoreNodeCategoryMaterial("LUXCORE_MATERIAL_TEXTURE", "Texture", items=[
Expand Down
27 changes: 27 additions & 0 deletions nodes/materials/frontbackopacity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .. import LuxCoreNodeMaterial
from ...utils import node as utils_node


class LuxCoreNodeMatFrontBackOpacity(LuxCoreNodeMaterial):
"""
Not a standalone material, but a node that offers
optional extra properties for all materials, to
avoid cluttering all other material nodes.
"""
bl_label = "Front/Back Opacity"
bl_width_default = 160

def init(self, context):
self.add_input("LuxCoreSocketMaterial", "Material")
self.add_input("LuxCoreSocketFloat0to1", "Front Opacity", 1)
self.add_input("LuxCoreSocketFloat0to1", "Back Opacity", 1)

self.outputs.new("LuxCoreSocketMaterial", "Material")

def sub_export(self, exporter, props, luxcore_name=None, output_socket=None):
input_mat_name = utils_node.export_material_input(self.inputs["Material"], exporter, props, luxcore_name)
definitions = {
"transparency.front": self.inputs["Front Opacity"].export(exporter, props),
"transparency.back": self.inputs["Back Opacity"].export(exporter, props),
}
return self.create_props(props, definitions, input_mat_name)
7 changes: 4 additions & 3 deletions utils/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ def draw_transmission_info(node, layout):
layout.label("Transmitted: %.2f" % transmitted, icon=icons.INFO)


def export_material_input(input, exporter, props):
material_name = input.export(exporter, props)
def export_material_input(input, exporter, props, luxcore_name=None):
material_name = input.export(exporter, props, luxcore_name)

if material_name:
return material_name
else:
print("WARNING: No material linked on input", input.name, "of node", input.node.name)
luxcore_name = "__BLACK__"
if luxcore_name is None:
luxcore_name = "__BLACK__"
props.Set(pyluxcore.Property("scene.materials.%s.type" % luxcore_name, "matte"))
props.Set(pyluxcore.Property("scene.materials.%s.kd" % luxcore_name, [0, 0, 0]))
return luxcore_name
Expand Down

0 comments on commit 5d45c07

Please sign in to comment.