Skip to content

Commit

Permalink
Merge pull request #355 from howetuft/caustics
Browse files Browse the repository at this point in the history
Cycles - Caustics
  • Loading branch information
howetuft authored Jan 18, 2024
2 parents 8686e5b + 1b7dd00 commit 6ffb759
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 16 deletions.
30 changes: 23 additions & 7 deletions Render/rdrhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,34 @@ def get_template_file_filter(self):

def _get_renderer_specifics(self, view):
"""Get specific parameters of the renderer for a given view."""
rdrname = self.renderer_name

# Source properties
src = view.Source
try:
properties = src.PropertiesList
except AttributeError:
return {}
res = {}
else:
res = {
p[len(rdrname) :]: src.getPropertyByName(p)
for p in properties
if p.startswith(rdrname)
}

rdrname = self.renderer_name
res = {
p[len(rdrname) :]: src.getPropertyByName(p)
for p in properties
if p.startswith(rdrname)
}
# View properties
try:
properties = view.PropertiesList
except AttributeError:
pass
else:
res.update(
{
p[len(rdrname) :]: view.getPropertyByName(p)
for p in properties
if p.startswith(rdrname)
}
)
return res

def _get_general_data(self):
Expand Down
31 changes: 22 additions & 9 deletions Render/renderers/Cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
def write_mesh(name, mesh, material, **kwargs):
"""Compute a string in renderer SDL to represent a FreeCAD mesh."""
# Get specific parameters
cast_caustics = kwargs.get("CastCaustics", False)
receive_caustics = kwargs.get("ReceiveCaustics", False)
cast_caustics = kwargs.get("ObjectCastCaustics", False)
receive_caustics = kwargs.get("ObjectReceiveCaustics", False)

# Compute material values
matval = material.get_material_values(
Expand All @@ -105,15 +105,27 @@ def write_mesh(name, mesh, material, **kwargs):

interpolation = "smooth" if mesh.has_vnormals() else "flat"

# Caustics
if cast_caustics or receive_caustics:
snippet_state = f"""
<object
name="{name}"
is_caustics_caster="{cast_caustics}"
is_caustics_receiver="{receive_caustics}"
/>
<state interpolation="{interpolation}" shader="{name}" object="{name}">"""
else:
snippet_state = f"""
<state interpolation="{interpolation}" shader="{name}">"""

snippet_obj = f"""
<transform matrix="{trans}">
<state interpolation="{interpolation}" shader="{name}">
<transform matrix="{trans}">
<include src="{cyclesfile}" />
</state>
</transform>
</transform>
</state>
"""

snippet = snippet_mat + snippet_obj
snippet = snippet_mat + snippet_state + snippet_obj

return snippet

Expand Down Expand Up @@ -145,8 +157,8 @@ def write_camera(name, pos, updir, target, fov, resolution, **kwargs):

def write_pointlight(name, pos, color, power, **kwargs):
"""Compute a string in renderer SDL to represent a point light."""
# This is where you write the renderer-specific code
# to export a point light in the renderer format
# Get specific parameters
use_caustics = kwargs.get("LightUseCaustics", False)

snippet = f"""
<!-- Generated by FreeCAD - Pointlight '{name}' -->
Expand All @@ -164,6 +176,7 @@ def write_pointlight(name, pos, color, power, **kwargs):
light_type="point"
strength="1 1 1"
tfm="1 0 0 {pos[0]} 0 1 0 {pos[1]} 0 0 1 {pos[2]}"
use_caustics="{use_caustics}"
/>
</state>
"""
Expand Down
42 changes: 42 additions & 0 deletions Render/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,48 @@ class View(FeatureBase):
30,
0,
),
"CyclesObjectCastCaustics": Prop(
"App::PropertyBool",
chr(127) + "Specifics",
QT_TRANSLATE_NOOP(
"App::Property",
(
"Cycles only - Enable object to cast shadow caustics.\n"
"WARNING: require Cycles version >= 4.0.3 "
"(otherwise may crash)."
),
),
False,
0,
),
"CyclesObjectReceiveCaustics": Prop(
"App::PropertyBool",
chr(127) + "Specifics",
QT_TRANSLATE_NOOP(
"App::Property",
(
"Cycles only - Enable object to receive shadow caustics.\n"
"WARNING: require Cycles version >= 4.0.3 "
"(otherwise may crash)."
),
),
False,
0,
),
"CyclesLightUseCaustics": Prop(
"App::PropertyBool",
chr(127) + "Specifics",
QT_TRANSLATE_NOOP(
"App::Property",
(
"Cycles only - Enable light to generate caustics\n"
"WARNING: require Cycles version >= 4.0.3 "
"(otherwise may crash)."
),
),
False,
0,
),
}

@classmethod
Expand Down

0 comments on commit 6ffb759

Please sign in to comment.