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

added possibility to export uniqueID extension #145

Merged
3 commits merged into from
May 9, 2022
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
9 changes: 8 additions & 1 deletion addons/io_scene_gltf2_msfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class MSFS_ExporterProperties(bpy.types.PropertyGroup):
description='Enable MSFS glTF export extensions',
default=True
)
use_unique_id: bpy.props.BoolProperty(
name='use_unique_id',
description='use ASOBO_unique_id extension',
default=False
)


class GLTF_PT_MSFSImporterExtensionPanel(bpy.types.Panel):
bl_space_type = 'FILE_BROWSER'
Expand Down Expand Up @@ -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, 'use_unique_id', text="Enable ASOBO_unique_id extension")

def recursive_module_search(path, root=""):
for _, name, ispkg in pkgutil.iter_modules([str(path)]):
Expand Down
5 changes: 5 additions & 0 deletions addons/io_scene_gltf2_msfs/blender/li_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions addons/io_scene_gltf2_msfs/blender/ui_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand All @@ -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':
Expand Down
13 changes: 13 additions & 0 deletions addons/io_scene_gltf2_msfs/io/msfs_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .msfs_light import MSFSLight
from .msfs_gizmo import MSFSGizmo
from .msfs_material import MSFSMaterial
from .msfs_unique_id import MSFS_unique_id

class Export:

Expand All @@ -49,8 +50,20 @@ def gather_node_hook(self, gltf2_object, blender_object, export_settings):
if gltf2_object.extensions is None:
gltf2_object.extensions = {}

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:
Expand Down
2 changes: 1 addition & 1 deletion addons/io_scene_gltf2_msfs/io/msfs_multi_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions addons/io_scene_gltf2_msfs/io/msfs_unique_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 <https://www.gnu.org/licenses/>.

import math

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"}

extension_name = "ASOBO_unique_id"

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 = {}

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,
extension=extension,
required=False
)