Skip to content

Commit

Permalink
Merge pull request #3028 from Onek8/main
Browse files Browse the repository at this point in the history
Upgrading and testing on Blender 4.3
  • Loading branch information
luboslenco authored Aug 7, 2024
2 parents fd9fe31 + 620ecdc commit 2c91e81
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 57 deletions.
5 changes: 4 additions & 1 deletion blender/arm/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,10 @@ def check_uv_precision(mesh: bpy.types.Mesh, uv_max_dim: float, max_dim_uvmap: b
)

def export_mesh_data(self, export_mesh: bpy.types.Mesh, bobject: bpy.types.Object, o, has_armature=False):
export_mesh.calc_normals_split()
if bpy.app.version < (4, 1, 0):
export_mesh.calc_normals_split()
else:
updated_normals = export_mesh.corner_normals
export_mesh.calc_loop_triangles()

loops = export_mesh.loops
Expand Down
2 changes: 1 addition & 1 deletion blender/arm/logicnode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def init_categories():
arm_nodes.add_category('Transform', icon='TRANSFORM_ORIGINS', section="motion")
arm_nodes.add_category('Physics', icon='PHYSICS', section="motion")

arm_nodes.add_category('Array', icon='LIGHTPROBE_GRID', section="values")
arm_nodes.add_category('Array', icon='MOD_ARRAY', section="values")
arm_nodes.add_category('Map', icon='SHORTDISPLAY', section="values")
arm_nodes.add_category('Math', icon='FORCE_HARMONIC', section="values")
arm_nodes.add_category('Random', icon='SEQ_HISTOGRAM', section="values")
Expand Down
64 changes: 44 additions & 20 deletions blender/arm/logicnode/arm_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,27 +595,51 @@ def draw_socket_layout_split(socket: bpy.types.NodeSocket, layout: bpy.types.UIL
layout.prop(socket, prop_name, text='')


def _make_socket_interface(interface_name: str, bl_idname: str) -> Type[bpy.types.NodeSocketInterface]:
"""Create a socket interface class that is used by Blender for node
groups. We currently don't use real node groups, but without these
classes Blender will (incorrectly) draw the socket borders in light grey.
"""
def draw(self, context, layout):
pass
if bpy.app.version < (4, 1, 0):
def _make_socket_interface(interface_name: str, bl_idname: str) -> Type[bpy.types.NodeSocketInterface]:
"""Create a socket interface class that is used by Blender for node
groups. We currently don't use real node groups, but without these
classes Blender will (incorrectly) draw the socket borders in light grey.
"""
def draw(self, context, layout):
pass

def draw_color(self, context):
# This would be used if we were using "real" node groups
return 0, 0, 0, 1

cls = type(
interface_name,
(bpy.types.NodeSocketInterface, ), {
'bl_socket_idname': bl_idname,
'draw': draw,
'draw_color': draw_color,
}
)
return cls
else:
def _make_socket_interface(interface_name: str, bl_idname: str) -> Type[bpy.types.NodeTreeInterfaceSocket]:
"""Create a socket interface class that is used by Blender for node
groups. We currently don't use real node groups, but without these
classes Blender will (incorrectly) draw the socket borders in light grey.
"""
def draw(self, context, layout):
pass

def draw_color(self, context):
# This would be used if we were using "real" node groups
return 0, 0, 0, 1

cls = type(
interface_name,
(bpy.types.NodeTreeInterfaceSocket, ), {
'bl_socket_idname': bl_idname,
'draw': draw,
'draw_color': draw_color,
}
)
return cls

def draw_color(self, context):
# This would be used if we were using "real" node groups
return 0, 0, 0, 1

cls = type(
interface_name,
(bpy.types.NodeSocketInterface, ), {
'bl_socket_idname': bl_idname,
'draw': draw,
'draw_color': draw_color,
}
)
return cls


ArmActionSocketInterface = _make_socket_interface('ArmActionSocketInterface', 'ArmNodeSocketAction')
Expand Down
5 changes: 4 additions & 1 deletion blender/arm/logicnode/logic/LN_select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from bpy.types import NodeSocketInterfaceInt
try:
from bpy.types import NodeSocketInterfaceInt
except:
from bpy.types import NodeTreeInterfaceSocketInt
from arm.logicnode.arm_nodes import *

class SelectNode(ArmLogicTreeNode):
Expand Down
38 changes: 22 additions & 16 deletions blender/arm/material/cycles_nodes/nodes_shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: N
# subsurface = c.parse_vector_input(node.inputs[1])
# subsurface_radius = c.parse_vector_input(node.inputs[2])
# subsurface_color = c.parse_vector_input(node.inputs[3])
state.out_metallic = c.parse_value_input(node.inputs[6])
if bpy.app.version < (4, 1, 0):
state.out_metallic = c.parse_value_input(node.inputs[6])
else:
state.out_metallic = c.parse_value_input(node.inputs[1])
state.out_specular = c.parse_value_input(node.inputs[7])
# specular_tint = c.parse_vector_input(node.inputs[6])
state.out_roughness = c.parse_value_input(node.inputs[9])
if bpy.app.version < (4, 1, 0):
state.out_roughness = c.parse_value_input(node.inputs[9])
else:
state.out_roughness = c.parse_value_input(node.inputs[2])
# aniso = c.parse_vector_input(node.inputs[8])
# aniso_rot = c.parse_vector_input(node.inputs[9])
# sheen = c.parse_vector_input(node.inputs[10])
Expand Down Expand Up @@ -117,14 +123,13 @@ def parse_bsdfdiffuse(node: bpy.types.ShaderNodeBsdfDiffuse, out_socket: NodeSoc
state.out_roughness = c.parse_value_input(node.inputs[1])
state.out_specular = '0.0'


def parse_bsdfglossy(node: bpy.types.ShaderNodeBsdfGlossy, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[2])
state.out_basecol = c.parse_vector_input(node.inputs[0])
state.out_roughness = c.parse_value_input(node.inputs[1])
state.out_metallic = '1.0'

if bpy.app.version < (4, 1, 0):
def parse_bsdfglossy(node: bpy.types.ShaderNodeBsdfGlossy, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[2])
state.out_basecol = c.parse_vector_input(node.inputs[0])
state.out_roughness = c.parse_value_input(node.inputs[1])
state.out_metallic = '1.0'

def parse_ambientocclusion(node: bpy.types.ShaderNodeAmbientOcclusion, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
Expand Down Expand Up @@ -204,9 +209,10 @@ def parse_bsdftransparent(node: bpy.types.ShaderNodeBsdfTransparent, out_socket:
state.out_opacity = '(1.0 - {0}.r)'.format(c.parse_vector_input(node.inputs[0]))


def parse_bsdfvelvet(node: bpy.types.ShaderNodeBsdfVelvet, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[2])
state.out_basecol = c.parse_vector_input(node.inputs[0])
state.out_roughness = '1.0'
state.out_metallic = '1.0'
if bpy.app.version < (4, 1, 0):
def parse_bsdfvelvet(node: bpy.types.ShaderNodeBsdfVelvet, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[2])
state.out_basecol = c.parse_vector_input(node.inputs[0])
state.out_roughness = '1.0'
state.out_metallic = '1.0'
23 changes: 12 additions & 11 deletions blender/arm/material/cycles_nodes/nodes_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,22 @@ def parse_tex_magic(node: bpy.types.ShaderNodeTexMagic, out_socket: bpy.types.No
return res


def parse_tex_musgrave(node: bpy.types.ShaderNodeTexMusgrave, out_socket: bpy.types.NodeSocket, state: ParserState) -> Union[floatstr, vec3str]:
state.curshader.add_function(c_functions.str_tex_musgrave)
if bpy.app.version < (4, 1, 0):
def parse_tex_musgrave(node: bpy.types.ShaderNodeTexMusgrave, out_socket: bpy.types.NodeSocket, state: ParserState) -> Union[floatstr, vec3str]:
state.curshader.add_function(c_functions.str_tex_musgrave)

if node.inputs[0].is_linked:
co = c.parse_vector_input(node.inputs[0])
else:
co = 'bposition'
if node.inputs[0].is_linked:
co = c.parse_vector_input(node.inputs[0])
else:
co = 'bposition'

scale = c.parse_value_input(node.inputs['Scale'])
# detail = c.parse_value_input(node.inputs[2])
# distortion = c.parse_value_input(node.inputs[3])
scale = c.parse_value_input(node.inputs['Scale'])
# detail = c.parse_value_input(node.inputs[2])
# distortion = c.parse_value_input(node.inputs[3])

res = f'tex_musgrave_f({co} * {scale} * 0.5)'
res = f'tex_musgrave_f({co} * {scale} * 0.5)'

return res
return res


def parse_tex_noise(node: bpy.types.ShaderNodeTexNoise, out_socket: bpy.types.NodeSocket, state: ParserState) -> Union[floatstr, vec3str]:
Expand Down
7 changes: 4 additions & 3 deletions blender/arm/material/node_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ class MaterialNodeMeta:
'BSDF_ANISOTROPIC': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfanisotropic),
'BSDF_DIFFUSE': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfdiffuse),
'BSDF_GLASS': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfglass),
'BSDF_GLOSSY': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfglossy),
'BSDF_PRINCIPLED': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfprincipled),
'BSDF_TRANSLUCENT': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdftranslucent),
'BSDF_TRANSPARENT': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdftransparent),
'BSDF_REFRACTION': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfrefraction),
'BSDF_VELVET': MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfvelvet),
'EMISSION': MaterialNodeMeta(parse_func=nodes_shader.parse_emission),
'HOLDOUT': MaterialNodeMeta(
parse_func=nodes_shader.parse_holdout,
Expand All @@ -177,7 +175,6 @@ class MaterialNodeMeta:
'TEX_GRADIENT': MaterialNodeMeta(parse_func=nodes_texture.parse_tex_gradient),
'TEX_IMAGE': MaterialNodeMeta(parse_func=nodes_texture.parse_tex_image),
'TEX_MAGIC': MaterialNodeMeta(parse_func=nodes_texture.parse_tex_magic),
'TEX_MUSGRAVE': MaterialNodeMeta(parse_func=nodes_texture.parse_tex_musgrave),
'TEX_NOISE': MaterialNodeMeta(parse_func=nodes_texture.parse_tex_noise),
'TEX_POINTDENSITY': MaterialNodeMeta(
parse_func=nodes_texture.parse_tex_pointdensity,
Expand All @@ -204,6 +201,10 @@ class MaterialNodeMeta:
)
}

if bpy.app.version < (4, 1, 0):
ALL_NODES['BSDF_GLOSSY'] = MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfglossy)
ALL_NODES['BSDF_VELVET'] = MaterialNodeMeta(parse_func=nodes_shader.parse_bsdfvelvet)
ALL_NODES['TEX_MUSGRAVE'] = MaterialNodeMeta(parse_func=nodes_texture.parse_tex_musgrave)

def get_node_meta(node: bpy.types.Node) -> MaterialNodeMeta:
type_identifier = node.type if node.type != 'CUSTOM' else node.bl_idname
Expand Down
5 changes: 4 additions & 1 deletion blender/arm/nodes_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ def draw(cls, context):
path_data = [path.node_tree.name for path in context.space_data.path]
str = cls.convert_array_to_string(path_data)
blf.position(0, 20, height-60, 0)
blf.size(0, 15, 72)
if bpy.app.version < (4, 1, 0):
blf.size(0, 15, 72)
else:
blf.size(15, 72)
blf.draw(0, str)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion blender/arm/write_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def write_indexhtml(w, h, is_publish):
""")
if rpdat.rp_stereo or wrd.arm_winmode == 'Fullscreen':
f.write("""
<canvas style="width: 100vw; height: 100vh; display: block;" id='khanvas' tabindex='-1'""" + str(popupmenu_in_browser) + """></canvas>
<canvas style="object-fit: contain; min-width: 100%; max-width: 100%; max-height: 100vh; min-height: 100vh; display: block;" id='khanvas' tabindex='-1'""" + str(popupmenu_in_browser) + """></canvas>
""")
else:
f.write("""
Expand Down
10 changes: 8 additions & 2 deletions blender/arm/write_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def setup_envmap_render():
scene.render.image_settings.color_depth = '32'

# Export in linear space and with default color management settings
scene.display_settings.display_device = "None"
if bpy.app.version < (4, 1, 0):
scene.display_settings.display_device = "None"
else:
scene.display_settings.display_device = "sRGB"
scene.view_settings.view_transform = "Standard"
scene.view_settings.look = "None"
scene.view_settings.exposure = 0
Expand Down Expand Up @@ -93,7 +96,10 @@ def setup_envmap_render():

cam_obj.location = [0.0, 0.0, 0.0]
cam.type = "PANO"
cam.cycles.panorama_type = "EQUIRECTANGULAR"
if bpy.app.version < (4, 1, 0):
cam.cycles.panorama_type = "EQUIRECTANGULAR"
else:
cam.panorama_type = "EQUIRECTANGULAR"
cam_obj.rotation_euler = [math.radians(90), 0, math.radians(-90)]

try:
Expand Down

0 comments on commit 2c91e81

Please sign in to comment.