Skip to content

Commit

Permalink
Merge pull request #3030 from 1k8/main
Browse files Browse the repository at this point in the history
Blender version support
  • Loading branch information
luboslenco authored Aug 13, 2024
2 parents 9a54071 + 97feaf2 commit 3b8f6ea
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Sources/armory/network/WebSocket.hx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WebSocket {
_onmessage = value;
_ws.onmessage = function(message: Dynamic) {
if (_onmessage != null) {
if (Std.isOfType(message.data, JsBuffer)) {
if (message.data is JsBuffer) {
var buffer = new Buffer();
buffer.writeBytes(Bytes.ofData(message.data));
_onmessage(BytesMessage(buffer));
Expand Down Expand Up @@ -141,10 +141,10 @@ class WebSocket {
}

public function send(msg:Any) {
if (Std.isOfType(msg, Bytes)) {
if (msg is Bytes) {
var bytes = cast(msg, Bytes);
_ws.send(bytes.getData());
} else if (Std.isOfType(msg, Buffer)) {
} else if (msg is Buffer) {
var buffer = cast(msg, Buffer);
_ws.send(buffer.readAllAvailableBytes().getData());
} else {
Expand Down
13 changes: 9 additions & 4 deletions blender/arm/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,15 @@ def export_object(self, bobject: bpy.types.Object, out_parent: Dict = None) -> N
if bobject.hide_render or not bobject.arm_visible:
out_object['visible'] = False

if not bobject.visible_camera:
out_object['visible_mesh'] = False
if not bobject.visible_shadow:
out_object['visible_shadow'] = False
if bpy.app.version < (3, 0, 0):
if not bobject.cycles_visibility:
out_object['visible_mesh'] = False
out_object['visible_shadow'] = False
else:
if not bobject.visible_camera:
out_object['visible_mesh'] = False
if not bobject.visible_shadow:
out_object['visible_shadow'] = False

if not bobject.arm_spawn:
out_object['spawn'] = False
Expand Down
36 changes: 18 additions & 18 deletions blender/arm/material/cycles_nodes/nodes_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def parse_valtorgb(node: bpy.types.ShaderNodeValToRGB, out_socket: bpy.types.Nod
rel_pos = f'({fac_var} - {prev_stop_fac}) * (1.0 / ({next_stop_fac} - {prev_stop_fac}))'
return f'mix({prev_stop_col}, {next_stop_col}, max({rel_pos}, 0.0))'


def parse_combine_color(node: bpy.types.ShaderNodeCombineColor, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
if node.mode == 'RGB':
return parse_combrgb(node, out_socket, state)
elif node.mode == 'HSV':
return parse_combhsv(node, out_socket, state)
elif node.mode == 'HSL':
log.warn('Combine Color node: HSL mode is not supported, using default value')
return c.to_vec3((0.0, 0.0, 0.0))
if bpy.app.version > (3, 2, 0):
def parse_combine_color(node: bpy.types.ShaderNodeCombineColor, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
if node.mode == 'RGB':
return parse_combrgb(node, out_socket, state)
elif node.mode == 'HSV':
return parse_combhsv(node, out_socket, state)
elif node.mode == 'HSL':
log.warn('Combine Color node: HSL mode is not supported, using default value')
return c.to_vec3((0.0, 0.0, 0.0))


def parse_combhsv(node: bpy.types.ShaderNodeCombineHSV, out_socket: bpy.types.NodeSocket, state: ParserState) -> vec3str:
Expand Down Expand Up @@ -356,15 +356,15 @@ def parse_math(node: bpy.types.ShaderNodeMath, out_socket: bpy.types.NodeSocket,
def parse_rgbtobw(node: bpy.types.ShaderNodeRGBToBW, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
return c.rgb_to_bw(c.parse_vector_input(node.inputs[0]))


def parse_separate_color(node: bpy.types.ShaderNodeSeparateColor, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
if node.mode == 'RGB':
return parse_seprgb(node, out_socket, state)
elif node.mode == 'HSV':
return parse_sephsv(node, out_socket, state)
elif node.mode == 'HSL':
log.warn('Separate Color node: HSL mode is not supported, using default value')
return '0.0'
if bpy.app.version > (3, 2, 0):
def parse_separate_color(node: bpy.types.ShaderNodeSeparateColor, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
if node.mode == 'RGB':
return parse_seprgb(node, out_socket, state)
elif node.mode == 'HSV':
return parse_sephsv(node, out_socket, state)
elif node.mode == 'HSL':
log.warn('Separate Color node: HSL mode is not supported, using default value')
return '0.0'


def parse_sephsv(node: bpy.types.ShaderNodeSeparateHSV, out_socket: bpy.types.NodeSocket, state: ParserState) -> floatstr:
Expand Down
100 changes: 66 additions & 34 deletions blender/arm/material/cycles_nodes/nodes_shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,47 @@ def parse_addshader(node: bpy.types.ShaderNodeAddShader, out_socket: NodeSocket,
state.out_opacity = '({0} * 0.5 + {1} * 0.5)'.format(opac1, opac2)
state.out_ior = '({0} * 0.5 + {1} * 0.5)'.format(ior1, ior2)

def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[22])
state.out_basecol = c.parse_vector_input(node.inputs[0])
# 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])
if bpy.app.version < (4, 1, 0):

if bpy.app.version < (3, 0, 0):
def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[20])
state.out_basecol = c.parse_vector_input(node.inputs[0])
state.out_metallic = c.parse_value_input(node.inputs[4])
state.out_specular = c.parse_value_input(node.inputs[5])
state.out_roughness = c.parse_value_input(node.inputs[7])
if (node.inputs['Emission Strength'].is_linked or node.inputs['Emission Strength'].default_value != 0.0)\
and (node.inputs['Emission'].is_linked or not mat_utils.equals_color_socket(node.inputs['Emission'], (0.0, 0.0, 0.0), comp_alpha=False)):
emission_col = c.parse_vector_input(node.inputs[17])
emission_strength = c.parse_value_input(node.inputs[18])
state.out_emission_col = '({0} * {1})'.format(emission_col, emission_strength)
mat_state.emission_type = mat_state.EmissionType.SHADED
else:
mat_state.emission_type = mat_state.EmissionType.NO_EMISSION
if state.parse_opacity:
state.out_ior = c.parse_value_input(node.inputs[14])
state.out_opacity = c.parse_value_input(node.inputs[19])
if bpy.app.version >= (3, 0, 0) and bpy.app.version <= (4, 1, 0):
def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[22])
state.out_basecol = c.parse_vector_input(node.inputs[0])
# 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])
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])
if bpy.app.version < (4, 1, 0):
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])
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])
# sheen_tint = c.parse_vector_input(node.inputs[11])
# clearcoat = c.parse_vector_input(node.inputs[12])
# clearcoat_rough = c.parse_vector_input(node.inputs[13])
# ior = c.parse_vector_input(node.inputs[14])
# transmission = c.parse_vector_input(node.inputs[15])
# transmission_roughness = c.parse_vector_input(node.inputs[16])
if bpy.app.version < (4, 1, 0):
# 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])
# sheen_tint = c.parse_vector_input(node.inputs[11])
# clearcoat = c.parse_vector_input(node.inputs[12])
# clearcoat_rough = c.parse_vector_input(node.inputs[13])
# ior = c.parse_vector_input(node.inputs[14])
# transmission = c.parse_vector_input(node.inputs[15])
# transmission_roughness = c.parse_vector_input(node.inputs[16])
if (node.inputs['Emission Strength'].is_linked or node.inputs['Emission Strength'].default_value != 0.0)\
and (node.inputs['Emission'].is_linked or not mat_utils.equals_color_socket(node.inputs['Emission'], (0.0, 0.0, 0.0), comp_alpha=False)):
emission_col = c.parse_vector_input(node.inputs[19])
Expand All @@ -110,21 +124,34 @@ def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: N
mat_state.emission_type = mat_state.EmissionType.SHADED
else:
mat_state.emission_type = mat_state.EmissionType.NO_EMISSION
else:
# clearcoar_normal = c.parse_vector_input(node.inputs[21])
# tangent = c.parse_vector_input(node.inputs[22])
if state.parse_opacity:
state.out_ior = c.parse_value_input(node.inputs[16])
if len(node.inputs) >= 21:
state.out_opacity = c.parse_value_input(node.inputs[21])
if bpy.app.version > (4, 1, 0):
def parse_bsdfprincipled(node: bpy.types.ShaderNodeBsdfPrincipled, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[5])
state.out_basecol = c.parse_vector_input(node.inputs[0])
subsurface = c.parse_value_input(node.inputs[8])
subsurface_radius = c.parse_vector_input(node.inputs[9])
subsurface_color = c.parse_vector_input(node.inputs[0])
state.out_metallic = c.parse_value_input(node.inputs[1])
state.out_specular = c.parse_value_input(node.inputs[7])
state.out_roughness = c.parse_value_input(node.inputs[2])
if (node.inputs['Emission Strength'].is_linked or node.inputs['Emission Strength'].default_value != 0.0)\
and (node.inputs['Emission Color'].is_linked or not mat_utils.equals_color_socket(node.inputs['Emission Color'], (0.0, 0.0, 0.0), comp_alpha=False)):
emission_col = c.parse_vector_input(node.inputs[27])
emission_strength = c.parse_value_input(node.inputs[28])
state.out_emission_col = '({0} * {1})'.format(emission_col, emission_strength)
mat_state.emission_type = mat_state.EmissionType.SHADED
else:
mat_state.emission_type = mat_state.EmissionType.NO_EMISSION
# clearcoar_normal = c.parse_vector_input(node.inputs[21])
# tangent = c.parse_vector_input(node.inputs[22])
if state.parse_opacity:
state.out_ior = c.parse_value_input(node.inputs[16])
if len(node.inputs) >= 21:
state.out_opacity = c.parse_value_input(node.inputs[21])
mat_state.emission_type = mat_state.EmissionType.NO_EMISSION
if state.parse_opacity:
state.out_ior = c.parse_value_input(node.inputs[3])
state.out_opacity = c.parse_value_input(node.inputs[4])

def parse_bsdfdiffuse(node: bpy.types.ShaderNodeBsdfDiffuse, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
Expand All @@ -133,6 +160,7 @@ 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'


if bpy.app.version < (4, 1, 0):
def parse_bsdfglossy(node: bpy.types.ShaderNodeBsdfGlossy, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
Expand All @@ -141,6 +169,7 @@ def parse_bsdfglossy(node: bpy.types.ShaderNodeBsdfGlossy, out_socket: NodeSocke
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:
# Single channel
Expand Down Expand Up @@ -198,7 +227,10 @@ def parse_bsdfrefraction(node: bpy.types.ShaderNodeBsdfRefraction, out_socket: N

def parse_subsurfacescattering(node: bpy.types.ShaderNodeSubsurfaceScattering, out_socket: NodeSocket, state: ParserState) -> None:
if state.parse_surface:
c.write_normal(node.inputs[4])
if bpy.app.version < (4, 1, 0):
c.write_normal(node.inputs[4])
else:
c.write_normal(node.inputs[6])
state.out_basecol = c.parse_vector_input(node.inputs[0])


Expand Down
7 changes: 3 additions & 4 deletions blender/arm/material/cycles_nodes/nodes_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ def parse_tex_magic(node: bpy.types.ShaderNodeTexMagic, out_socket: bpy.types.No

return res


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)
Expand All @@ -253,13 +252,13 @@ def parse_tex_musgrave(node: bpy.types.ShaderNodeTexMusgrave, out_socket: bpy.ty
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])

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

return res


Expand Down
5 changes: 3 additions & 2 deletions blender/arm/material/node_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ class MaterialNodeMeta:
'BLACKBODY': MaterialNodeMeta(parse_func=nodes_converter.parse_blackbody),
'CLAMP': MaterialNodeMeta(parse_func=nodes_converter.parse_clamp),
'COMBHSV': MaterialNodeMeta(parse_func=nodes_converter.parse_combhsv),
'COMBINE_COLOR': MaterialNodeMeta(parse_func=nodes_converter.parse_combine_color),
'COMBRGB': MaterialNodeMeta(parse_func=nodes_converter.parse_combrgb),
'COMBXYZ': MaterialNodeMeta(parse_func=nodes_converter.parse_combxyz),
'MAP_RANGE': MaterialNodeMeta(parse_func=nodes_converter.parse_maprange),
'MATH': MaterialNodeMeta(parse_func=nodes_converter.parse_math),
'RGBTOBW': MaterialNodeMeta(parse_func=nodes_converter.parse_rgbtobw),
'SEPARATE_COLOR': MaterialNodeMeta(parse_func=nodes_converter.parse_separate_color),
'SEPHSV': MaterialNodeMeta(parse_func=nodes_converter.parse_sephsv),
'SEPRGB': MaterialNodeMeta(parse_func=nodes_converter.parse_seprgb),
'SEPXYZ': MaterialNodeMeta(parse_func=nodes_converter.parse_sepxyz),
Expand Down Expand Up @@ -201,6 +199,9 @@ class MaterialNodeMeta:
)
}

if bpy.app.version > (3, 2, 0):
ALL_NODES['SEPARATE_COLOR'] = MaterialNodeMeta(parse_func=nodes_converter.parse_separate_color)
ALL_NODES['COMBINE_COLOR'] = MaterialNodeMeta(parse_func=nodes_converter.parse_combine_color)
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)
Expand Down
5 changes: 4 additions & 1 deletion blender/arm/props_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,10 @@ def draw(self, context):
if state.proc_play is None and state.proc_build is None:
row.operator("arm.play", icon="PLAY")
else:
row.operator("arm.stop", icon="MESH_PLANE")
if bpy.app.version < (3, 0, 0):
row.operator("arm.stop", icon="CANCEL", text="")
else:
row.operator("arm.stop", icon="SEQUENCE_COLOR_01", text="")
row.operator("arm.clean_menu", icon="BRUSH_DATA")

col = layout.box().column()
Expand Down
2 changes: 1 addition & 1 deletion blender/arm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def get_render_resolution(scene):
return int(render.resolution_x * scale), int(render.resolution_y * scale)

def get_texture_quality_percentage() -> int:
return int(bpy.data.worlds["Arm"].arm_texture_quality * 100)
return int(bpy.data.worlds['Arm'].arm_texture_quality * 100)

def get_project_scene_name():
return get_active_scene().name
Expand Down

0 comments on commit 3b8f6ea

Please sign in to comment.