Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting to blender 4.x #289

Closed
Closed
3 changes: 2 additions & 1 deletion addons/io_hubs_addon/io/gltf_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def patched_gather_gltf(exporter, export_settings):

def get_version_string():
from .. import (bl_info)
return str(bl_info['version'][0]) + '.' + str(bl_info['version'][1]) + '.' + str(bl_info['version'][2])
info = bl_info['version']
return f"{info[0]}.{info[1]}.{info[2]}"


def export_callback(callback_method, export_settings):
Expand Down
14 changes: 12 additions & 2 deletions addons/io_hubs_addon/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture_info, gltf2_blender_export_keys
from io_scene_gltf2.blender.exp import gltf2_blender_image
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
if bpy.app.version >= (4, 0, 0):
from io_scene_gltf2.blender.exp.material import gltf2_blender_search_node_tree
from io_scene_gltf2.io.com import gltf2_io_extensions
from io_scene_gltf2.io.com import gltf2_io
from io_scene_gltf2.io.exp import gltf2_io_binary_data
Expand Down Expand Up @@ -47,7 +49,10 @@ def from_blender_image(image: bpy.types.Image):

def encode(self, mime_type: Optional[str], export_settings) -> Union[Tuple[bytes, bool], bytes]:
if mime_type == "image/vnd.radiance":
return self.encode_from_image_hdr(self.blender_image())
if bpy.app.version < (4, 0, 0):
return self.encode_from_image_hdr(self.blender_image())
else:
return self.encode_from_image_hdr(self.blender_image(export_settings))
if bpy.app.version < (3, 5, 0):
return super().encode(mime_type)
else:
Expand Down Expand Up @@ -366,8 +371,13 @@ def gather_lightmap_texture_info(blender_material, export_settings):
if bpy.app.version < (3, 2, 0):
tex_transform, tex_coord = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
texture_socket, export_settings)
elif bpy.app.version >= (4, 0, 0):
socket = gltf2_blender_search_node_tree.NodeSocket(texture_socket, blender_material)
tex_transform, tex_coord = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
socket, export_settings)
else:
tex_transform, tex_coord, _ = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
print("processing __gather_texture_transform_and_tex_coord")
tex_transform, tex_coord = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
texture_socket, export_settings)
texture_info = gltf2_io.TextureInfo(
extensions=gltf2_blender_gather_texture_info.__gather_extensions(
Expand Down
44 changes: 42 additions & 2 deletions addons/io_hubs_addon/nodes/lightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def poll(cls, context):
]


def add_node_menu_blender4(self, context):
self.layout.menu("NODE_MT_mozilla_hubs_nodes")


class NODE_MT_mozilla_hubs_nodes(bpy.types.Menu):
"""Add node menu for Blender 4.x"""
bl_label = "Hubs"
bl_idname = "NODE_MT_mozilla_hubs_nodes"

def draw(self, context):
layout = self.layout
layout.operator("node.add_node", text="MOZ_lightmap settings").type = "moz_lightmap.node"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the node.add_node operator should use the use_transform option set to True so that it maintains the same behavior as in Blender 3.6



class MozLightmapNode(Node):
"""MOZ_lightmap settings node"""
bl_idname = 'moz_lightmap.node'
Expand Down Expand Up @@ -46,11 +60,37 @@ def draw_label(self):
return "MOZ_lightmap"


def register():
def register_blender_4():
bpy.utils.register_class(NODE_MT_mozilla_hubs_nodes)
bpy.types.NODE_MT_shader_node_add_all.append(add_node_menu_blender4)
bpy.utils.register_class(MozLightmapNode)


def unregister_blender_4():
bpy.types.NODE_MT_shader_node_add_all.remove(add_node_menu_blender4)
bpy.utils.unregister_class(NODE_MT_mozilla_hubs_nodes)
bpy.utils.unregister_class(MozLightmapNode)


def register_blender_3():
bpy.utils.register_class(MozLightmapNode)
nodeitems_utils.register_node_categories("MOZ_NODES", node_categories)


def unregister():
def unregister_blender_3():
bpy.utils.unregister_class(MozLightmapNode)
nodeitems_utils.unregister_node_categories("MOZ_NODES")


def register():
if bpy.app.version < (4, 0, 0):
register_blender_3()
else:
register_blender_4()


def unregister():
if bpy.app.version < (4, 0, 0):
unregister_blender_3()
else:
unregister_blender_4()
2 changes: 1 addition & 1 deletion tests/test/test_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ describe('Importer / Exporter (Roundtrip)', function () {
});
});
});
});
});
Loading