Skip to content

Commit

Permalink
Merge pull request #179 from specklesystems/jrm/4.0/material-support
Browse files Browse the repository at this point in the history
feat(4.X): Added support for Blender 4.X material nodes
  • Loading branch information
JR-Morgan authored Nov 11, 2023
2 parents 57ece17 + 6d8f4a4 commit e436949
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 196 deletions.
2 changes: 1 addition & 1 deletion bpy_speckle/convert/to_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def can_convert_to_native(speckle_object: Base) -> bool:
return True
return False

convert_instances_as: str #HACK: This is hacky, we need a better way to pass settings down to the converter
convert_instances_as: str = "" #HACK: This is hacky, we need a better way to pass settings down to the converter
def set_convert_instances_as(value: str):
global convert_instances_as
convert_instances_as = value
Expand Down
4 changes: 3 additions & 1 deletion bpy_speckle/convert/to_speckle.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ def material_to_speckle(blender_mat: bpy.types.Material) -> RenderMaterial:
if blender_mat.use_nodes:
if blender_mat.node_tree.nodes.get("Principled BSDF"):
inputs = blender_mat.node_tree.nodes["Principled BSDF"].inputs
emission_color = "Emission" if "Emission" in inputs else "Emission Color" # type: ignore

speckle_mat.diffuse = to_argb_int(inputs["Base Color"].default_value) # type: ignore
speckle_mat.emissive = to_argb_int(inputs["Emission"].default_value) # type: ignore
speckle_mat.emissive = to_argb_int(inputs[emission_color].default_value) # type: ignore
speckle_mat.roughness = inputs["Roughness"].default_value # type: ignore
speckle_mat.metalness = inputs["Metallic"].default_value # type: ignore
speckle_mat.opacity = inputs["Alpha"].default_value # type: ignore
Expand Down
7 changes: 5 additions & 2 deletions bpy_speckle/convert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from specklepy.objects.other import RenderMaterial
from bpy_speckle.convert.constants import IGNORED_PROPERTY_KEYS
from bpy_speckle.functions import _report
from bpy.types import Material, Object, Collection as BCollection, Node, ShaderNodeVertexColor
from bpy.types import Material, Object, Collection as BCollection, Node, ShaderNodeVertexColor, NodeInputs

from specklepy.objects.graph_traversal.traversal import TraversalContext

Expand Down Expand Up @@ -88,11 +88,14 @@ def render_material_to_native(speckle_mat: RenderMaterial) -> Material:
inputs = blender_mat.node_tree.nodes["Principled BSDF"].inputs

inputs["Base Color"].default_value = to_rgba(speckle_mat.diffuse) # type: ignore
inputs["Emission"].default_value = to_rgba(speckle_mat.emissive) # type: ignore
inputs["Roughness"].default_value = speckle_mat.roughness # type: ignore
inputs["Metallic"].default_value = speckle_mat.metalness # type: ignore
inputs["Alpha"].default_value = speckle_mat.opacity # type: ignore

# Blender >=4.0 use "Emission Color"
emission_color = "Emission" if "Emission" in inputs else "Emission Color" # type: ignore
inputs[emission_color].default_value = to_rgba(speckle_mat.emissive) # type: ignore

if speckle_mat.opacity < 1.0:
blender_mat.blend_method = "BLEND"

Expand Down
Loading

0 comments on commit e436949

Please sign in to comment.