From 0bf452190757fe76b28660172c426bb39ae43e0d Mon Sep 17 00:00:00 2001 From: Christof Reimers Date: Wed, 10 Jul 2024 12:16:26 +0200 Subject: [PATCH 1/5] Add "apply transform" to export options Added an option to the export options. When disabled (enabled by default) the transform does not get applied during export. --- i_scene_cp77_gltf/exporters/__init__.py | 18 +++++++++++++----- i_scene_cp77_gltf/exporters/glb_export.py | 7 ++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/i_scene_cp77_gltf/exporters/__init__.py b/i_scene_cp77_gltf/exporters/__init__.py index d1f83f5..4afd336 100644 --- a/i_scene_cp77_gltf/exporters/__init__.py +++ b/i_scene_cp77_gltf/exporters/__init__.py @@ -31,16 +31,16 @@ def execute(self, context): class CP77GLBExport(Operator,ExportHelper): - ### cleaned this up and moved most code to exporters.py + ### cleaned this up and moved most code to exporters.py bl_idname = "export_scene.cp77_glb" bl_label = "Export for Cyberpunk" bl_options = {'REGISTER','UNDO'} bl_description = "Export to GLB with optimized settings for use with Wolvenkit for Cyberpunk 2077" filename_ext = ".glb" - ### adds a checkbox for anim export settings + ### adds a checkbox for anim export settings filter_glob: StringProperty(default="*.glb", options={'HIDDEN'}) - + filepath: StringProperty(subtype="FILE_PATH") limit_selected: BoolProperty( @@ -67,6 +67,12 @@ class CP77GLBExport(Operator,ExportHelper): description="Use this option to export all visible objects. Only use this if you know why you're using this" ) + apply_transform: BoolProperty( + name="Apply Transform", + default=True, + description="Applies the transform of the objects. Disable this if you don't care about the location/rotation/scale of the objects" + ) + def draw(self, context): layout = self.layout row = layout.row(align=True) @@ -80,9 +86,11 @@ def draw(self, context): else: row = layout.row(align=True) row.prop(self, "static_prop") - + row = layout.row(align=True) + row.prop(self, "apply_transform") + def execute(self, context): - export_cyberpunk_glb(context, self.filepath, self.export_poses, self.export_visible, self.limit_selected, self.static_prop) + export_cyberpunk_glb(context=context, filepath=self.filepath, export_poses=self.export_poses, export_visible=self.export_visible, limit_selected=self.limit_selected, static_prop=self.static_prop, apply_transform=self.apply_transform) return {'FINISHED'} diff --git a/i_scene_cp77_gltf/exporters/glb_export.py b/i_scene_cp77_gltf/exporters/glb_export.py index 8746deb..ae27103 100644 --- a/i_scene_cp77_gltf/exporters/glb_export.py +++ b/i_scene_cp77_gltf/exporters/glb_export.py @@ -96,7 +96,7 @@ def add_garment_cap(mesh): # setup the actual exporter - rewrote almost all of this, much quicker now # mana: by assigning default attributes, we make this update-safe (some older scripts broke). Just don't re-name them! -def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False): +def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False, apply_transform=True): groupless_bones = set() bone_names = [] @@ -168,7 +168,8 @@ def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=F for mesh in meshes: # apply transforms - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + if apply_transform: + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) if not mesh.data.uv_layers: bpy.ops.cp77.message_box('INVOKE_DEFAULT', message="Meshes must have UV layers in order to import in Wolvenkit. See https://tinyurl.com/uv-layers") return {'CANCELLED'} @@ -248,7 +249,7 @@ def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=F for group in obj.vertex_groups: if group.name in bone_names: group_has_bone[group.index] = True - # print(vertex_group.name) + # print(vertex_group.name) # Add groups with no weights to the set for group_index, has_bone in group_has_bone.items(): From d5dde0492fb86ff7a3f72347bcbdc8401f211909 Mon Sep 17 00:00:00 2001 From: Christof Reimers Date: Wed, 10 Jul 2024 13:32:14 +0200 Subject: [PATCH 2/5] Added additional control to apply transform export settings Yeah i did it anyway --- i_scene_cp77_gltf/exporters/__init__.py | 40 +++++++++++++++++++++-- i_scene_cp77_gltf/exporters/glb_export.py | 4 +-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/i_scene_cp77_gltf/exporters/__init__.py b/i_scene_cp77_gltf/exporters/__init__.py index 4afd336..debf681 100644 --- a/i_scene_cp77_gltf/exporters/__init__.py +++ b/i_scene_cp77_gltf/exporters/__init__.py @@ -73,6 +73,24 @@ class CP77GLBExport(Operator,ExportHelper): description="Applies the transform of the objects. Disable this if you don't care about the location/rotation/scale of the objects" ) + apply_transform_location: BoolProperty( + name="Apply Location", + default=True, + description="Applies the location of the objects." + ) + + apply_transform_rotation: BoolProperty( + name="Apply Rotation", + default=True, + description="Applies the rotation of the objects." + ) + + apply_transform_scale: BoolProperty( + name="Apply Scale", + default=True, + description="Applies the scale of the objects." + ) + def draw(self, context): layout = self.layout row = layout.row(align=True) @@ -86,11 +104,27 @@ def draw(self, context): else: row = layout.row(align=True) row.prop(self, "static_prop") - row = layout.row(align=True) - row.prop(self, "apply_transform") + (panel_header, panel_body) = layout.panel("apply_transform", default_closed=True) + panel_header.prop(self, "apply_transform") + panel_body.use_property_decorate = False + panel_body.enabled = self.apply_transform + panel_body.prop(self, "apply_transform_location") + panel_body.prop(self, "apply_transform_rotation") + panel_body.prop(self, "apply_transform_scale") def execute(self, context): - export_cyberpunk_glb(context=context, filepath=self.filepath, export_poses=self.export_poses, export_visible=self.export_visible, limit_selected=self.limit_selected, static_prop=self.static_prop, apply_transform=self.apply_transform) + export_cyberpunk_glb( + context=context, + filepath=self.filepath, + export_poses=self.export_poses, + export_visible=self.export_visible, + limit_selected=self.limit_selected, + static_prop=self.static_prop, + apply_transform=self.apply_transform, + apply_location=self.apply_transform_location, + apply_rotation=self.apply_transform_rotation, + apply_scale=self.apply_transform_scale, + ) return {'FINISHED'} diff --git a/i_scene_cp77_gltf/exporters/glb_export.py b/i_scene_cp77_gltf/exporters/glb_export.py index ae27103..21fec68 100644 --- a/i_scene_cp77_gltf/exporters/glb_export.py +++ b/i_scene_cp77_gltf/exporters/glb_export.py @@ -96,7 +96,7 @@ def add_garment_cap(mesh): # setup the actual exporter - rewrote almost all of this, much quicker now # mana: by assigning default attributes, we make this update-safe (some older scripts broke). Just don't re-name them! -def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False, apply_transform=True): +def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False, apply_transform=True, apply_location=True, apply_rotation=True, apply_scale=True): groupless_bones = set() bone_names = [] @@ -169,7 +169,7 @@ def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=F # apply transforms if apply_transform: - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) + bpy.ops.object.transform_apply(location=apply_location, rotation=apply_rotation, scale=apply_scale) if not mesh.data.uv_layers: bpy.ops.cp77.message_box('INVOKE_DEFAULT', message="Meshes must have UV layers in order to import in Wolvenkit. See https://tinyurl.com/uv-layers") return {'CANCELLED'} From 313370d4374aa192882bde4f3154b7bd4f5efcba Mon Sep 17 00:00:00 2001 From: Christof Reimers Date: Wed, 10 Jul 2024 13:34:34 +0200 Subject: [PATCH 3/5] Added my name to the authors :) --- i_scene_cp77_gltf/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i_scene_cp77_gltf/__init__.py b/i_scene_cp77_gltf/__init__.py index d92d809..9d26964 100644 --- a/i_scene_cp77_gltf/__init__.py +++ b/i_scene_cp77_gltf/__init__.py @@ -15,7 +15,7 @@ bl_info = { "name": "Cyberpunk 2077 IO Suite", - "author": "HitmanHimself, Turk, Jato, dragonzkiller, kwekmaster, glitchered, Simarilius, Doctor Presto, shotlastc, Rudolph2109, Holopointz", + "author": "HitmanHimself, Turk, Jato, dragonzkiller, kwekmaster, glitchered, Simarilius, Doctor Presto, shotlastc, Rudolph2109, Holopointz, Peatral", "version": (1, 5, 5, 3), "blender": (4, 0, 0), "location": "File > Import-Export", From c7ba286fc937fea65b37cbff64641985912f78b3 Mon Sep 17 00:00:00 2001 From: Christof Reimers Date: Wed, 10 Jul 2024 13:41:50 +0200 Subject: [PATCH 4/5] Fix identation in panel --- i_scene_cp77_gltf/exporters/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/i_scene_cp77_gltf/exporters/__init__.py b/i_scene_cp77_gltf/exporters/__init__.py index debf681..df2907a 100644 --- a/i_scene_cp77_gltf/exporters/__init__.py +++ b/i_scene_cp77_gltf/exporters/__init__.py @@ -106,11 +106,14 @@ def draw(self, context): row.prop(self, "static_prop") (panel_header, panel_body) = layout.panel("apply_transform", default_closed=True) panel_header.prop(self, "apply_transform") - panel_body.use_property_decorate = False - panel_body.enabled = self.apply_transform - panel_body.prop(self, "apply_transform_location") - panel_body.prop(self, "apply_transform_rotation") - panel_body.prop(self, "apply_transform_scale") + + if panel_body is not None: + panel_body.use_property_split = True + panel_body.use_property_decorate = False + panel_body.enabled = self.apply_transform + panel_body.prop(self, "apply_transform_location") + panel_body.prop(self, "apply_transform_rotation") + panel_body.prop(self, "apply_transform_scale") def execute(self, context): export_cyberpunk_glb( From 7507b7d844e3daad66507318f1b31a49e6764884 Mon Sep 17 00:00:00 2001 From: Christof Reimers Date: Thu, 11 Jul 2024 01:10:40 +0200 Subject: [PATCH 5/5] Remove individual controls --- i_scene_cp77_gltf/exporters/__init__.py | 33 ++--------------------- i_scene_cp77_gltf/exporters/glb_export.py | 4 +-- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/i_scene_cp77_gltf/exporters/__init__.py b/i_scene_cp77_gltf/exporters/__init__.py index df2907a..9a225e3 100644 --- a/i_scene_cp77_gltf/exporters/__init__.py +++ b/i_scene_cp77_gltf/exporters/__init__.py @@ -73,24 +73,6 @@ class CP77GLBExport(Operator,ExportHelper): description="Applies the transform of the objects. Disable this if you don't care about the location/rotation/scale of the objects" ) - apply_transform_location: BoolProperty( - name="Apply Location", - default=True, - description="Applies the location of the objects." - ) - - apply_transform_rotation: BoolProperty( - name="Apply Rotation", - default=True, - description="Applies the rotation of the objects." - ) - - apply_transform_scale: BoolProperty( - name="Apply Scale", - default=True, - description="Applies the scale of the objects." - ) - def draw(self, context): layout = self.layout row = layout.row(align=True) @@ -104,16 +86,8 @@ def draw(self, context): else: row = layout.row(align=True) row.prop(self, "static_prop") - (panel_header, panel_body) = layout.panel("apply_transform", default_closed=True) - panel_header.prop(self, "apply_transform") - - if panel_body is not None: - panel_body.use_property_split = True - panel_body.use_property_decorate = False - panel_body.enabled = self.apply_transform - panel_body.prop(self, "apply_transform_location") - panel_body.prop(self, "apply_transform_rotation") - panel_body.prop(self, "apply_transform_scale") + row = layout.row(align=True) + row.prop(self, "apply_transform") def execute(self, context): export_cyberpunk_glb( @@ -124,9 +98,6 @@ def execute(self, context): limit_selected=self.limit_selected, static_prop=self.static_prop, apply_transform=self.apply_transform, - apply_location=self.apply_transform_location, - apply_rotation=self.apply_transform_rotation, - apply_scale=self.apply_transform_scale, ) return {'FINISHED'} diff --git a/i_scene_cp77_gltf/exporters/glb_export.py b/i_scene_cp77_gltf/exporters/glb_export.py index 21fec68..ae27103 100644 --- a/i_scene_cp77_gltf/exporters/glb_export.py +++ b/i_scene_cp77_gltf/exporters/glb_export.py @@ -96,7 +96,7 @@ def add_garment_cap(mesh): # setup the actual exporter - rewrote almost all of this, much quicker now # mana: by assigning default attributes, we make this update-safe (some older scripts broke). Just don't re-name them! -def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False, apply_transform=True, apply_location=True, apply_rotation=True, apply_scale=True): +def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=False, limit_selected=True, static_prop=False, red_garment_col=False, apply_transform=True): groupless_bones = set() bone_names = [] @@ -169,7 +169,7 @@ def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=F # apply transforms if apply_transform: - bpy.ops.object.transform_apply(location=apply_location, rotation=apply_rotation, scale=apply_scale) + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) if not mesh.data.uv_layers: bpy.ops.cp77.message_box('INVOKE_DEFAULT', message="Meshes must have UV layers in order to import in Wolvenkit. See https://tinyurl.com/uv-layers") return {'CANCELLED'}