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

Add "apply transform" to export options #161

Merged
merged 5 commits into from
Jul 12, 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
2 changes: 1 addition & 1 deletion i_scene_cp77_gltf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 21 additions & 5 deletions i_scene_cp77_gltf/exporters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -80,9 +86,19 @@ 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'}


Expand Down
7 changes: 4 additions & 3 deletions i_scene_cp77_gltf/exporters/glb_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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'}
Expand Down Expand Up @@ -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():
Expand Down