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

Port to blender4 Merged with blender4-image-export #296

Merged
merged 14 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def migrate(self, migration_type, panel_type, instance_version, host, migration_
self.coneOuterAngle = radians(
self.coneOuterAngle)

if migration_type != MigrationType.GLOBAL or is_linked(ob) or type(ob) == bpy.types.Armature:
if migration_type != MigrationType.GLOBAL or is_linked(ob) or type(ob) is bpy.types.Armature:
host_reference = get_host_reference_message(panel_type, host, ob=ob)
migration_report.append(
f"Warning: The Media Cone angles may not have migrated correctly for the Audio Params component on the {panel_type.value} {host_reference}")
Expand Down
4 changes: 2 additions & 2 deletions addons/io_hubs_addon/components/definitions/media_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def is_bone(ob):
return type(ob) == EditBone or type(ob) == Bone
return type(ob) is EditBone or type(ob) is Bone


class MediaFrameGizmo(Gizmo):
Expand Down Expand Up @@ -158,7 +158,7 @@ def migrate(self, migration_type, panel_type, instance_version, host, migration_
bounds = Vector((bounds.x, bounds.z, bounds.y))
self.bounds = bounds

if migration_type != MigrationType.GLOBAL or is_linked(ob) or type(ob) == bpy.types.Armature:
if migration_type != MigrationType.GLOBAL or is_linked(ob) or type(ob) is bpy.types.Armature:
host_reference = get_host_reference_message(panel_type, host, ob=ob)
migration_report.append(
f"Warning: The Media Frame component's Y and Z bounds on the {panel_type.value} {host_reference} may not have migrated correctly")
Expand Down
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/definitions/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def gather_import(cls, gltf, blender_host, component_name, component_value, impo
continue

if property_name in SPOKE_PROPS_TO_FIX:
if type(property_value) == int or type(property_value) == float:
if type(property_value) is int or type(property_value) is float:
property_value = str(property_value)

assign_property(gltf.vnodes, blender_component,
Expand Down
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def migrate(component, migration_type, panel_type, host, migration_report, ob=No
was_migrated = component.migrate(
migration_type, panel_type, instance_version, host, migration_report, ob=ob)

if type(was_migrated) != bool:
if type(was_migrated) is not bool:
print(f"Warning: the {component.get_display_name()} component didn't return whether a migration occurred.")
# Fall back to assuming there was a migration since the version increased.
was_migrated = True
Expand Down
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def display_wrapped_text(layout, wrapped_text, *, heading_icon='NONE'):
def get_host_reference_message(panel_type, host, ob=None):
'''The ob argument is used for bone hosts and is the armature object, but will fall back to the armature if the armature object isn't available.'''
if panel_type == PanelType.BONE:
ob_type = "armature" if type(ob) == bpy.types.Armature else "object"
ob_type = "armature" if type(ob) is bpy.types.Armature else "object"
host_reference = f"\"{host.name}\" in {ob_type} \"{ob.name_full}\""
else:
host_reference = f"\"{host.name_full}\""
Expand Down
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
28 changes: 16 additions & 12 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, 1, 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, 1, 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 @@ -87,7 +92,7 @@ def gather_image(blender_image, export_settings):

data = HubsExportImage.from_blender_image(blender_image).encode(mime_type, export_settings)

if type(data) == tuple:
if type(data) is tuple:
data = data[0]

if export_settings['gltf_format'] == 'GLTF_SEPARATE':
Expand Down Expand Up @@ -168,13 +173,13 @@ def gather_property(export_settings, blender_object, target, property_name):
return gather_vec_property(export_settings, blender_object, target, property_name)

elif (property_definition.bl_rna.identifier == 'PointerProperty'):
if type(property_value) == bpy.types.Object:
if type(property_value) is bpy.types.Object:
return gather_node_property(export_settings, blender_object, target, property_name)
elif type(property_value) == bpy.types.Material:
elif type(property_value) is bpy.types.Material:
return gather_material_property(export_settings, blender_object, target, property_name)
elif type(property_value) == bpy.types.Image:
elif type(property_value) is bpy.types.Image:
return gather_image_property(export_settings, blender_object, target, property_name)
elif type(property_value) == bpy.types.Texture:
elif type(property_value) is bpy.types.Texture:
return gather_texture_property(export_settings, blender_object, target, property_name)

return gltf2_blender_extras.__to_json_compatible(property_value)
Expand Down Expand Up @@ -363,12 +368,11 @@ def gather_lightmap_texture_info(blender_material, export_settings):
# TODO this assumes a single image directly connected to the socket
blender_image = texture_socket.links[0].from_node.image
texture = gather_texture(blender_image, 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)
else:
tex_transform, tex_coord, _ = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
texture_socket, export_settings)
socket = lightmap_node.inputs.get("Lightmap") if bpy.app.version < (4, 1, 0) \
else gltf2_blender_search_node_tree.NodeSocket(texture_socket, blender_material)
tex_attributes = gltf2_blender_gather_texture_info.__gather_texture_transform_and_tex_coord(
socket, export_settings)
tex_transform, tex_coord = tex_attributes[:2]
texture_info = gltf2_io.TextureInfo(
extensions=gltf2_blender_gather_texture_info.__gather_extensions(
tex_transform, export_settings),
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"


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