Skip to content

Commit

Permalink
Unregister error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Spiderguy-F committed Mar 27, 2024
1 parent 5918602 commit 22cfd87
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 78 deletions.
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 @@ -11,7 +11,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 @@ -157,7 +157,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 is not 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
1 change: 1 addition & 0 deletions addons/io_hubs_addon/components/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def find_active_undo_step_index(undo_steps):

@persistent
def undo_stack_handler(dummy, depsgraph):
return #this fails on windows, sys.stdout.fileno() is not supported
global previous_undo_steps_dump
global previous_undo_step_index
global file_loading
Expand Down
1 change: 1 addition & 0 deletions addons/io_hubs_addon/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def c_fflush():

@contextmanager
def redirect_c_stdout(binary_stream):
#this causes an error on windows when the addon is enabled using: bpy.ops.preferences.addon_enable(module="io_hubs_addon")
stdout_file_descriptor = sys.stdout.fileno()
original_stdout_file_descriptor_copy = os.dup(stdout_file_descriptor)
try:
Expand Down
10 changes: 5 additions & 5 deletions addons/io_hubs_addon/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def gather_image(blender_image, export_settings):
else:
mime_type = "image/jpeg"
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 @@ -156,13 +156,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
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/nodes/lightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def register_blender_3():

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


def register():
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 28 additions & 27 deletions tests/export_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,35 @@
import os
import sys

bpy.ops.preferences.addon_enable(module="io_hubs_addon")

try:
argv = sys.argv
if "--" in argv:
argv = argv[argv.index("--") + 1:] # get all args after "--"
else:
argv = []
bpy.ops.preferences.addon_enable(module="io_hubs_addon") #it throws an error on windows and it's not necessary, since the commandline already enables the addon

extension = '.gltf'
if '--glb' in argv:
extension = '.glb'
#try:
argv = sys.argv
if "--" in argv:
argv = argv[argv.index("--") + 1:] # get all args after "--"
else:
argv = []

path = os.path.splitext(bpy.data.filepath)[0] + extension
path_parts = os.path.split(path)
output_dir = os.path.join(path_parts[0], argv[0])
if not os.path.exists(output_dir):
os.makedirs(output_dir)
args = {
# Settings from "Remember Export Settings"
**dict(bpy.context.scene.get('glTF2ExportSettings', {})),
extension = '.glb' if '--glb' in argv else '.gltf'

'export_format': ('GLB' if extension == '.glb' else 'GLTF_SEPARATE'),
'filepath': os.path.join(output_dir, path_parts[1]),
'export_cameras': True,
'export_extras': True
}
bpy.ops.export_scene.gltf(**args)
except Exception as err:
print(err, file=sys.stderr)
sys.exit(1)
path = os.path.splitext(bpy.data.filepath)[0] + extension
path_parts = os.path.split(path)
output_dir = os.path.join(path_parts[0], argv[0])
print("Saving to " + output_dir)
# if not os.path.exists(output_dir): #no need, Blender export always creates the dirs
# os.makedirs(output_dir)
args = {
# Settings from "Remember Export Settings"
**dict(bpy.context.scene.get('glTF2ExportSettings', {})),

'export_format': ('GLB' if extension == '.glb' else 'GLTF_SEPARATE'),
'filepath': output_dir,#, path_parts[1]),
'export_cameras': True,
'export_extras': True
}
print("Got args, exporting")
bpy.ops.export_scene.gltf(**args)
# except Exception as err:
# print(err, file=sys.stderr)
# sys.exit(1)
7 changes: 5 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "io-hubs-addon-tests",
"version": "1.0.0",
"description": "Test suite for io-hubs-addon",
"dependencies": {},
"dependencies": {
"g": "^2.0.1",
"yarn": "^1.22.22"
},
"devDependencies": {
"eslint": "^6.8.0",
"gltf-validator": "^2.0.0-dev.3.2",
Expand All @@ -19,4 +22,4 @@
"mocha": {
"timeout": 60000
}
}
}
62 changes: 31 additions & 31 deletions tests/roundtrip_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@
import os
import sys

try:
argv = sys.argv
if "--" in argv:
argv = argv[argv.index("--") + 1:] # get all args after "--"
else:
argv = []
#try:
argv = sys.argv
if "--" in argv:
argv = argv[argv.index("--") + 1:] # get all args after "--"
else:
argv = []

filepath = argv[0]
filepath = argv[0]
print("Filepath: " + filepath)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.import_scene.gltf(filepath=argv[0])
print("Importing: " + argv[0])
extension = '.gltf'
export_format = 'GLTF_SEPARATE'
if '--glb' in argv:
extension = '.glb'
export_format = 'GLB'

bpy.ops.import_scene.gltf(filepath=argv[0])

extension = '.gltf'
export_format = 'GLTF_SEPARATE'
if '--glb' in argv:
extension = '.glb'
export_format = 'GLB'

path = os.path.splitext(filepath)[0] + extension
path_parts = os.path.split(path)
output_dir = os.path.join(path_parts[0], argv[1])
if not os.path.exists(output_dir):
os.makedirs(output_dir)
if '--no-sample-anim' in argv:
bpy.ops.export_scene.gltf(export_format=export_format, filepath=os.path.join(
output_dir, path_parts[1]), export_force_sampling=False)
else:
bpy.ops.export_scene.gltf(
export_format=export_format, filepath=os.path.join(output_dir, path_parts[1]))
except Exception as err:
print(err, file=sys.stderr)
sys.exit(1)
path = os.path.splitext(filepath)[0] + extension
path_parts = os.path.split(path)
output_dir = os.path.join(path_parts[0], argv[1])
if not os.path.exists(output_dir):
os.makedirs(output_dir)
if '--no-sample-anim' in argv:
bpy.ops.export_scene.gltf(export_format=export_format, filepath=os.path.join(
output_dir, path_parts[1]), export_force_sampling=False)
else:
bpy.ops.export_scene.gltf(
export_format=export_format, filepath=os.path.join(output_dir, path_parts[1]))
# except Exception as err:
# print(err, file=sys.stderr)
# sys.exit(1)
18 changes: 12 additions & 6 deletions tests/test/test_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const blenderVersions = (() => {
"blender"
];
}
else if (process.platform == 'win32') {
return [
"C:\\Program Files\\Blender Foundation\\Blender 3.6\\blender.exe",
];
}
})();

var utils = require('./utils.js').utils;
Expand All @@ -32,15 +37,16 @@ describe('Exporter', function () {

variants.forEach(function (variant) {
const args = variant[1];
describe(blenderVersion + '_export' + variant[0], function () {
describe(blenderVersion + ', exporting:' + variant[0], function () {
blenderSampleScenes.forEach((scene) => {
it(scene, function (done) {
let outDirName = 'out' + blenderVersion + variant[0];
let blenderPath = `scenes/${scene}.blend`;
let ext = args.indexOf('--glb') === -1 ? '.gltf' : '.glb';
let outDirPath = path.resolve(OUT_PREFIX, 'scenes', outDirName);
let outDirPath = path.resolve(OUT_PREFIX, 'scenes');
let dstPath = path.resolve(outDirPath, `${scene}${ext}`);
utils.blenderFileToGltf(blenderVersion, blenderPath, outDirPath, (error) => {
//utils.blenderFileToGltf(blenderVersion, blenderPath, outDirPath, (error) => {
utils.blenderFileToGltf(blenderVersion, blenderPath, dstPath, (error) => {
if (error)
return done(error);

Expand All @@ -51,9 +57,9 @@ describe('Exporter', function () {
});
});

describe(blenderVersion + '_export_results', function () {
let outDirName = 'out' + blenderVersion;
let outDirPath = path.resolve(OUT_PREFIX, 'scenes', outDirName);
describe(blenderVersion + ' export_results', function () {
let outDirName = 'out';// + blenderVersion;
let outDirPath = path.resolve(OUT_PREFIX, 'scenes');//, outDirName);

it('can export link', function () {
let gltfPath = path.resolve(outDirPath, 'link.gltf');
Expand Down
10 changes: 6 additions & 4 deletions tests/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12

function blenderFileToGltf(blenderVersion, blenderPath, outDirName, done, options = '') {
const { exec } = require('child_process');
const cmd = `${blenderVersion} -b --factory-startup --addons io_hubs_addon -noaudio ${blenderPath} --python export_gltf.py -- ${outDirName} ${options}`;
//const cmd = `"${blenderVersion}" "${blenderPath}" -b --factory-startup --addons io_hubs_addon -noaudio --python export_gltf.py -- ${outDirName} ${options}`;
//const cmd = `"${blenderVersion}" "${blenderPath}" -b --factory-startup --addons io_hubs_addon -noaudio --python export_gltf.py -- ${outDirName}`;
const cmd = `"${blenderVersion}" "${blenderPath}" -b --factory-startup -noaudio --python export_gltf.py -- ${outDirName.replace(/\\/g, '//')} `;
var prc = exec(cmd, (error, stdout, stderr) => {
//if (stderr) process.stderr.write(stderr);

console.log("Exporter resulsts\n" + stdout);
if (error) {
console.log(stdout);

done(error);
return;
}
Expand All @@ -24,7 +26,7 @@ function blenderRoundtripGltf(blenderVersion, gltfPath, outDirName, done, option
const cmd = `${blenderVersion} -b --factory-startup --addons io_hubs_addon -noaudio --python roundtrip_gltf.py -- ${gltfPath} ${outDirName} ${options}`;
var prc = exec(cmd, (error, stdout, stderr) => {
//if (stderr) process.stderr.write(stderr);

console.log("Roundtrip resulsts\n" + stdout);
if (error) {
done(error);
return;
Expand Down
10 changes: 10 additions & 0 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=

g@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/g/-/g-2.0.1.tgz#0b5963ebd0ca70e3bc8c6766934a021821c8b857"
integrity sha512-Fi6Ng5fZ/ANLQ15H11hCe+09sgUoNvDEBevVgx3KoYOhsH5iLNPn54hx0jPZ+3oSWr+xajnp2Qau9VmPsc7hTA==

get-caller-file@^2.0.1:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
Expand Down Expand Up @@ -1687,3 +1692,8 @@ yargs@13.3.2, yargs@^13.2.2, yargs@^13.3.0:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.2"

yarn@^1.22.22:
version "1.22.22"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz#ac34549e6aa8e7ead463a7407e1c7390f61a6610"
integrity sha512-prL3kGtyG7o9Z9Sv8IPfBNrWTDmXB4Qbes8A9rEzt6wkJV8mUvoirjU0Mp3GGAU06Y0XQyA3/2/RQFVuK7MTfg==

0 comments on commit 22cfd87

Please sign in to comment.