From 073b862f293c13a63446e5e80627627dd88a53a2 Mon Sep 17 00:00:00 2001 From: lpierabella <77288191+lpierabella@users.noreply.github.com> Date: Thu, 5 May 2022 15:51:12 +0200 Subject: [PATCH 1/3] added possibility to export uniqueID extension --- addons/io_scene_gltf2_msfs/__init__.py | 9 +++- addons/io_scene_gltf2_msfs/io/msfs_export.py | 5 +++ .../io/msfs_multi_export.py | 2 +- .../io_scene_gltf2_msfs/io/msfs_uniqueID.py | 44 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py diff --git a/addons/io_scene_gltf2_msfs/__init__.py b/addons/io_scene_gltf2_msfs/__init__.py index 8eaf2c1f..838ae959 100644 --- a/addons/io_scene_gltf2_msfs/__init__.py +++ b/addons/io_scene_gltf2_msfs/__init__.py @@ -47,6 +47,12 @@ class MSFS_ExporterProperties(bpy.types.PropertyGroup): description='Enable MSFS glTF export extensions', default=True ) + useUniqueID: bpy.props.BoolProperty( + name='Unique ID', + description='use UniqueID extension', + default=False + ) + class GLTF_PT_MSFSImporterExtensionPanel(bpy.types.Panel): bl_space_type = 'FILE_BROWSER' @@ -99,7 +105,8 @@ def draw(self, context): layout.use_property_decorate = False # No animation. layout.prop(props, 'enabled', text="Enabled") - + if props.enabled: + layout.prop(props, 'useUniqueID', text="Enable UniqueID extension") def recursive_module_search(path, root=""): for _, name, ispkg in pkgutil.iter_modules([str(path)]): diff --git a/addons/io_scene_gltf2_msfs/io/msfs_export.py b/addons/io_scene_gltf2_msfs/io/msfs_export.py index ff6bb264..8454e69f 100644 --- a/addons/io_scene_gltf2_msfs/io/msfs_export.py +++ b/addons/io_scene_gltf2_msfs/io/msfs_export.py @@ -23,6 +23,7 @@ from .msfs_light import MSFSLight from .msfs_gizmo import MSFSGizmo from .msfs_material import MSFSMaterial +from .msfs_uniqueID import MSFS_UniqueID class Export: @@ -49,6 +50,10 @@ def gather_node_hook(self, gltf2_object, blender_object, export_settings): if gltf2_object.extensions is None: gltf2_object.extensions = {} + exporter_props = bpy.context.scene.msfs_exporter_properties + if exporter_props.useUniqueID: + MSFS_UniqueID.export(gltf2_object, blender_object) + if blender_object.type == 'LIGHT': MSFSLight.export(gltf2_object, blender_object) diff --git a/addons/io_scene_gltf2_msfs/io/msfs_multi_export.py b/addons/io_scene_gltf2_msfs/io/msfs_multi_export.py index 2564779d..9469cdd6 100644 --- a/addons/io_scene_gltf2_msfs/io/msfs_multi_export.py +++ b/addons/io_scene_gltf2_msfs/io/msfs_multi_export.py @@ -215,7 +215,7 @@ class MSFS_PT_MultiExporter(bpy.types.Panel): @classmethod def poll(cls, context): - return context.scene.msfs_exporter_properties.enabled + return context.scene.msfs_exporter_properties def draw(self, context): layout = self.layout diff --git a/addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py b/addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py new file mode 100644 index 00000000..e6eae131 --- /dev/null +++ b/addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py @@ -0,0 +1,44 @@ +# glTF-Blender-IO-MSFS +# Copyright (C) 2021-2022 The glTF-Blender-IO-MSFS authors + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import math + +from io_scene_gltf2.io.com.gltf2_io_extensions import Extension +from mathutils import Matrix, Quaternion, Euler + +class MSFS_UniqueID: + bl_options = {"UNDO"} + + extension_name = "ASOBO_uniqueID" + + def __new__(cls, *args, **kwargs): + raise RuntimeError("%s should not be instantiated" % cls) + + @staticmethod + def create(gltf2_node, blender_node, import_settings): + pass + + @staticmethod + def export(gltf2_object, blender_object): + extension = {} + + extension["id"] = blender_object.name + + gltf2_object.extensions[MSFS_UniqueID.extension_name] = Extension( + name=MSFS_UniqueID.extension_name, + extension=extension, + required=False + ) \ No newline at end of file From 2539913063ef9a40a1eab330ed089726291db283 Mon Sep 17 00:00:00 2001 From: lpierabella <77288191+lpierabella@users.noreply.github.com> Date: Fri, 6 May 2022 10:00:33 +0200 Subject: [PATCH 2/3] fix type mistake, add bone support --- addons/io_scene_gltf2_msfs/__init__.py | 8 ++++---- addons/io_scene_gltf2_msfs/io/msfs_export.py | 16 ++++++++++++---- .../io/{msfs_uniqueID.py => msfs_unique_id.py} | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) rename addons/io_scene_gltf2_msfs/io/{msfs_uniqueID.py => msfs_unique_id.py} (87%) diff --git a/addons/io_scene_gltf2_msfs/__init__.py b/addons/io_scene_gltf2_msfs/__init__.py index 838ae959..cfe3e54e 100644 --- a/addons/io_scene_gltf2_msfs/__init__.py +++ b/addons/io_scene_gltf2_msfs/__init__.py @@ -47,9 +47,9 @@ class MSFS_ExporterProperties(bpy.types.PropertyGroup): description='Enable MSFS glTF export extensions', default=True ) - useUniqueID: bpy.props.BoolProperty( - name='Unique ID', - description='use UniqueID extension', + use_unique_id: bpy.props.BoolProperty( + name='use_unique_id', + description='use ASOBO_unique_id extension', default=False ) @@ -106,7 +106,7 @@ def draw(self, context): layout.prop(props, 'enabled', text="Enabled") if props.enabled: - layout.prop(props, 'useUniqueID', text="Enable UniqueID extension") + layout.prop(props, 'use_unique_id', text="Enable ASOBO_unique_id extension") def recursive_module_search(path, root=""): for _, name, ispkg in pkgutil.iter_modules([str(path)]): diff --git a/addons/io_scene_gltf2_msfs/io/msfs_export.py b/addons/io_scene_gltf2_msfs/io/msfs_export.py index 8454e69f..cd7dc0bd 100644 --- a/addons/io_scene_gltf2_msfs/io/msfs_export.py +++ b/addons/io_scene_gltf2_msfs/io/msfs_export.py @@ -23,7 +23,7 @@ from .msfs_light import MSFSLight from .msfs_gizmo import MSFSGizmo from .msfs_material import MSFSMaterial -from .msfs_uniqueID import MSFS_UniqueID +from .msfs_unique_id import MSFS_unique_id class Export: @@ -50,12 +50,20 @@ def gather_node_hook(self, gltf2_object, blender_object, export_settings): if gltf2_object.extensions is None: gltf2_object.extensions = {} - exporter_props = bpy.context.scene.msfs_exporter_properties - if exporter_props.useUniqueID: - MSFS_UniqueID.export(gltf2_object, blender_object) + if self.properties.use_unique_id: + MSFS_unique_id.export(gltf2_object, blender_object) if blender_object.type == 'LIGHT': MSFSLight.export(gltf2_object, blender_object) + + def gather_joint_hook(self, gltf2_node, blender_bone, export_settings): + if self.properties.enabled: + + if gltf2_node.extensions is None: + gltf2_node.extensions = {} + + if self.properties.use_unique_id: + MSFS_unique_id.export(gltf2_node, blender_bone) def gather_scene_hook(self, gltf2_scene, blender_scene, export_settings): if self.properties.enabled: diff --git a/addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py b/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py similarity index 87% rename from addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py rename to addons/io_scene_gltf2_msfs/io/msfs_unique_id.py index e6eae131..4394551e 100644 --- a/addons/io_scene_gltf2_msfs/io/msfs_uniqueID.py +++ b/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py @@ -19,10 +19,10 @@ from io_scene_gltf2.io.com.gltf2_io_extensions import Extension from mathutils import Matrix, Quaternion, Euler -class MSFS_UniqueID: +class MSFS_unique_id: bl_options = {"UNDO"} - extension_name = "ASOBO_uniqueID" + extension_name = "ASOBO_unique_id" def __new__(cls, *args, **kwargs): raise RuntimeError("%s should not be instantiated" % cls) @@ -37,8 +37,8 @@ def export(gltf2_object, blender_object): extension["id"] = blender_object.name - gltf2_object.extensions[MSFS_UniqueID.extension_name] = Extension( - name=MSFS_UniqueID.extension_name, + gltf2_object.extensions[MSFS_unique_id.extension_name] = Extension( + name=MSFS_unique_id.extension_name, extension=extension, required=False ) \ No newline at end of file From 6daafa1a7b640bdd3cee9f55e33f31cb99c014ab Mon Sep 17 00:00:00 2001 From: lpierabella <77288191+lpierabella@users.noreply.github.com> Date: Fri, 6 May 2022 16:21:46 +0200 Subject: [PATCH 3/3] added possibility to set uniqueID per object and per bone --- .../blender/li_properties.py | 5 +++++ .../blender/ui_properties.py | 20 +++++++++++++++++-- .../io_scene_gltf2_msfs/io/msfs_unique_id.py | 10 ++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/addons/io_scene_gltf2_msfs/blender/li_properties.py b/addons/io_scene_gltf2_msfs/blender/li_properties.py index 43add4bd..58b4598d 100644 --- a/addons/io_scene_gltf2_msfs/blender/li_properties.py +++ b/addons/io_scene_gltf2_msfs/blender/li_properties.py @@ -31,6 +31,11 @@ class MSFS_LI_object_properties(): bpy.types.Object.msfs_behavior = bpy.props.CollectionProperty(type = MSFS_attached_behavior) bpy.types.Object.msfs_active_behavior = bpy.props.IntProperty(name="Active behavior",min=0,default=0) + bpy.types.Object.msfs_override_unique_id = bpy.props.BoolProperty(name='Override Unique ID',default=False) + bpy.types.Object.msfs_unique_id = bpy.props.StringProperty(name='ID',default="") + bpy.types.Bone.msfs_override_unique_id = bpy.props.BoolProperty(name='Override Unique ID',default=False) + bpy.types.Bone.msfs_unique_id = bpy.props.StringProperty(name='ID',default="") + bpy.types.Object.msfs_light_has_symmetry = bpy.props.BoolProperty(name='Has symmetry',default=False) bpy.types.Object.msfs_light_flash_frequency = bpy.props.FloatProperty(name='Flash frequency',min=0.0,default=0.0) bpy.types.Object.msfs_light_flash_duration = bpy.props.FloatProperty(name='Flash duration',min=0.0,default=0.0) diff --git a/addons/io_scene_gltf2_msfs/blender/ui_properties.py b/addons/io_scene_gltf2_msfs/blender/ui_properties.py index 7c121430..27e7e968 100644 --- a/addons/io_scene_gltf2_msfs/blender/ui_properties.py +++ b/addons/io_scene_gltf2_msfs/blender/ui_properties.py @@ -35,7 +35,15 @@ class MSFS_PT_BoneProperties(bpy.types.Panel): def draw(self, context): layout = self.layout - box=layout.box() + + if context.mode != 'EDIT_ARMATURE': + active_bone = context.active_bone + box = layout.box() + box.prop(active_bone,"msfs_override_unique_id") + if active_bone.msfs_override_unique_id: + box.prop(active_bone, "msfs_unique_id") + + box.label(text = "Behavior list", icon = 'ANIM') box.template_list('MSFS_UL_object_behaviorListItem', "", context.object, 'msfs_behavior', context.object, 'msfs_active_behavior') @@ -60,13 +68,19 @@ class MSFS_PT_ObjectProperties(bpy.types.Panel): @classmethod def poll(cls, context): - return (context.object.type in ['LIGHT', 'EMPTY']) + return context.object.type def draw(self, context): layout = self.layout active_object = context.object + box = layout.box() + box.prop(active_object,"msfs_override_unique_id") + if active_object.msfs_override_unique_id: + box.prop(active_object, "msfs_unique_id") + + if active_object.type == 'LIGHT': box = layout.box() box.label(text = "MSFS Light Parameters", icon='LIGHT') @@ -83,6 +97,8 @@ def draw(self, context): box.prop(active_object, "msfs_gizmo_type") # TODO: change to msfs_msfs_gizmo_type if active_object.msfs_gizmo_type != "NONE": box.prop(active_object, "msfs_collision_is_road_collider") + + #if bpy.context.active_object.type == 'ARMATURE': diff --git a/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py b/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py index 4394551e..927c4673 100644 --- a/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py +++ b/addons/io_scene_gltf2_msfs/io/msfs_unique_id.py @@ -18,7 +18,7 @@ from io_scene_gltf2.io.com.gltf2_io_extensions import Extension from mathutils import Matrix, Quaternion, Euler - +import bpy class MSFS_unique_id: bl_options = {"UNDO"} @@ -35,7 +35,13 @@ def create(gltf2_node, blender_node, import_settings): def export(gltf2_object, blender_object): extension = {} - extension["id"] = blender_object.name + if type(blender_object) == bpy.types.PoseBone: + blender_object = blender_object.bone + + uniqueID = blender_object.name + if blender_object.msfs_override_unique_id: + uniqueID = blender_object.msfs_unique_id + extension["id"] = uniqueID gltf2_object.extensions[MSFS_unique_id.extension_name] = Extension( name=MSFS_unique_id.extension_name,