Skip to content

Commit

Permalink
Merge pull request #171 from DoctorPresto/main
Browse files Browse the repository at this point in the history
importers improvements, meshtools updates, ,other stuff too
  • Loading branch information
Simarilius-uk committed Aug 31, 2024
2 parents 83e8857 + 09ee7c2 commit a115299
Show file tree
Hide file tree
Showing 32 changed files with 570 additions and 214 deletions.
23 changes: 13 additions & 10 deletions i_scene_cp77_gltf/animtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..main.common import get_classes
from ..importers.import_with_materials import CP77GLBimport
from .animtools import *

from .generate_rigs import create_rigify_rig

def CP77AnimsList(self, context):
for action in bpy.data.actions:
Expand Down Expand Up @@ -51,15 +51,13 @@ def draw(self, context):
row.operator('cp77.rig_loader', text="Load Bundled Rig")
obj = context.active_object
if obj and obj.type == 'ARMATURE':
row = box.row(align=True)
col = box.column()
if 'deformBonesHidden' in obj:
row.operator('bone_unhider.cp77',text='Unhide Deform Bones')
col.operator('bone_unhider.cp77',text='Unhide Deform Bones')
else:
row.operator('bone_hider.cp77',text='Hide Deform Bones')
row = box.row()
row.operator('reset_armature.cp77')
row = box.row()
row.operator('cp77.anim_namer')
col.operator('bone_hider.cp77',text='Hide Deform Bones')
col.operator('reset_armature.cp77')
col.operator('cp77.anim_namer')
available_anims = list(CP77AnimsList(context,obj))
active_action = obj.animation_data.action if obj.animation_data else None
if not available_anims:
Expand Down Expand Up @@ -298,6 +296,7 @@ class CP77RigLoader(Operator):
appearances: StringProperty(name="Appearances", default="")
directory: StringProperty(name="Directory", default="")
filepath: StringProperty(name="Filepath", default="")
rigify_it: BoolProperty(name='Apply Rigify Rig', default=False)

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
Expand All @@ -315,16 +314,20 @@ def execute(self, context):
filepath=selected_rig, hide_armatures=False, import_garmentsupport=False, files=[], directory='', appearances="ALL", remap_depot=False)
if props.fbx_rot:
rotate_quat_180(self,context)
if self.rigify_it:
create_rigify_rig(self,context)
return {'FINISHED'}

def draw(self,context):
props = context.scene.cp77_panel_props
layout = self.layout
box = layout.box()
row = box.row(align=True)
row.label(text="Select rig to load: ")
row.prop(props, 'body_list', text="",)
row = box.row(align=True)
row.prop(props, 'fbx_rot', text="Load Rig in FBX Orientation")
col = box.column()
col.prop(self, 'rigify_it', text="Generate Rigify Control Rig")
col.prop(props, 'fbx_rot', text="Load Rig in FBX Orientation")


class CP77AnimNamer(Operator):
Expand Down
57 changes: 34 additions & 23 deletions i_scene_cp77_gltf/cyber_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,38 @@

def CP77RefitList(context):

target_addon_paths = [None]
target_addon_names = ['None']

SoloArmsAddon = os.path.join(refit_dir, "SoloArmsAddon.zip")
Adonis = os.path.join(refit_dir, "Adonis.zip")
VanillaFemToMasc = os.path.join(refit_dir, "f2m.zip")
VanillaFem_BigBoobs = os.path.join(refit_dir, "f_normal_to_big_boobs.zip")
VanillaFem_SmallBoobs = os.path.join(refit_dir, "f_normal_to_small_boobs.zip")
VanillaMascToFem = os.path.join(refit_dir, "m2f.zip")
Lush = os.path.join(refit_dir, "lush.zip")
Hyst_RB = os.path.join(refit_dir, "hyst_rb.zip")
Hyst_EBB = os.path.join(refit_dir, "hyst_ebb.zip")
Hyst_EBB_RB = os.path.join(refit_dir, "hyst_ebb_rb.zip")
Flat_Chest = os.path.join(refit_dir, "flat_chest.zip")
Solo_Ultimate = os.path.join(refit_dir, "solo_ultimate.zip")
Gymfiend = os.path.join(refit_dir, "gymfiend.zip")
Freyja = os.path.join(refit_dir, "freyja.zip")
# Hyst_EBBP_Addon = os.path.join(refit_dir, "hyst_ebbp_addon.zip")
Adonis = os.path.join(refit_dir, "Adonis.refitter.zip")
VanillaFemToMasc = os.path.join(refit_dir, "f2m.refitter.zip")
VanillaFem_BigBoobs = os.path.join(refit_dir, "f_normal_to_big_boobs.refitter.zip")
VanillaFem_SmallBoobs = os.path.join(refit_dir, "f_normal_to_small_boobs.refitter.zip")
VanillaMascToFem = os.path.join(refit_dir, "m2f.refitter.zip")
Lush = os.path.join(refit_dir, "lush.refitter.zip")
Hyst_RB = os.path.join(refit_dir, "hyst_rb.refitter.zip")
Hyst_EBB = os.path.join(refit_dir, "hyst_ebb.refitter.zip")
Hyst_EBB_RB = os.path.join(refit_dir, "hyst_ebb_rb.refitter.zip")
Flat_Chest = os.path.join(refit_dir, "flat_chest.refitter.zip")
Solo_Ultimate = os.path.join(refit_dir, "solo_ultimate.refitter.zip")
Gymfiend = os.path.join(refit_dir, "gymfiend.refitter.zip")
Freyja = os.path.join(refit_dir, "freyja.refitter.zip")

# Return the list of variable names
target_body_paths = [ Gymfiend, Freyja, SoloArmsAddon, Solo_Ultimate, Adonis, Flat_Chest, Hyst_EBB_RB, Hyst_EBB, Hyst_RB, Lush, VanillaFemToMasc, VanillaMascToFem, VanillaFem_BigBoobs, VanillaFem_SmallBoobs ]
target_body_names = [ 'Gymfiend', 'Freyja', 'SoloArmsAddon', 'Solo_Ultimate', 'Adonis', 'Flat_Chest', 'Hyst_EBB_RB', 'Hyst_EBB', 'Hyst_RB', 'Lush', 'VanillaFemToMasc', 'VanillaMascToFem', 'VanillaFem_BigBoobs', 'VanillaFem_SmallBoobs' ]
target_body_paths = [ Gymfiend, Freyja, Solo_Ultimate, Adonis, Flat_Chest, Hyst_EBB_RB, Hyst_EBB, Hyst_RB, Lush, VanillaFemToMasc, VanillaMascToFem, VanillaFem_BigBoobs, VanillaFem_SmallBoobs ]
target_body_names = [ 'Gymfiend', 'Freyja', 'Solo_Ultimate', 'Adonis', 'Flat_Chest', 'Hyst_EBB_RB', 'Hyst_EBB', 'Hyst_RB', 'Lush', 'VanillaFemToMasc', 'VanillaMascToFem', 'VanillaFem_BigBoobs', 'VanillaFem_SmallBoobs' ]

# Return the list of tuples
return target_body_paths, target_body_names

#def VertColourPresetList
def CP77RefitAddonList(context):

SoloArmsAddon = os.path.join(refit_dir, "SoloArmsAddon.refitter.zip")
Hyst_EBBP_Addon = os.path.join(refit_dir, "hyst_ebbp_addon.refitter.zip")

# Return the list of variable names
addon_target_body_paths = [SoloArmsAddon, Hyst_EBBP_Addon]
addon_target_body_names = ['SoloArmsAddon','Hyst_EBBP_Addon']

# Return the list of tuples
return addon_target_body_paths, addon_target_body_names


def SetCyclesRenderer(use_cycles=True, set_gi_params=False):
Expand Down Expand Up @@ -84,15 +89,16 @@ def cp77riglist(self, context):
man_big = os.path.join(rig_dir, "man_big_full.glb")
man_fat = os.path.join(rig_dir, "man_fat_full.glb")
Judy = os.path.join(rig_dir, "judy_full.glb")
Songbird = os.path.join(rig_dir, "songbird_full.glb")
Panam = os.path.join(rig_dir, "panam_full.glb")
Jackie = os.path.join(rig_dir, "jackie_full.glb")
Rhino = os.path.join(rig_dir, "rhino_full.glb")
Dex = os.path.join(rig_dir, "dex_full.glb")
Smasher = os.path.join(rig_dir, "smasher_full.glb")

# Store the variable names in a list
cp77rigs = [man_base, woman_base, man_big, man_fat, Judy, Panam, Jackie, Rhino, Dex, Smasher]
cp77rig_names = ['man_base', 'woman_base', 'man_big', 'man_fat', 'Judy', 'Panam', 'Jackie', 'Rhino', 'Dex', 'Adam Smasher']
cp77rigs = [man_base, woman_base, man_big, man_fat, Judy, Songbird, Panam, Jackie, Rhino, Dex, Smasher]
cp77rig_names = ['man_base', 'woman_base', 'man_big', 'man_fat', 'Judy', 'Songbird', 'Panam', 'Jackie', 'Rhino', 'Dex', 'Adam Smasher']

# Return the list of variable names
return cp77rigs, cp77rig_names
Expand Down Expand Up @@ -208,6 +214,11 @@ class CP77_PT_PanelProps(PropertyGroup):
name="Body Shape"
)

refit_addon_json: EnumProperty(
items=[(addon_target_body_names, addon_target_body_names, '') for addon_target_body_names in CP77RefitAddonList(None)[1]],
name="Refitter Addon"
)

selected_armature: EnumProperty(
name="Armatures",
items=CP77ArmatureList
Expand Down
25 changes: 13 additions & 12 deletions i_scene_cp77_gltf/exporters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class CP77StreamingSectorExport(Operator,ExportHelper):
bl_idname = "export_scene.cp77_sector"
bl_label = "Export Sector Updates for Cyberpunk"
bl_options = {'REGISTER','UNDO'}
bl_description = "Export changes to Sectors back to project"
bl_description = "Export changes to Sectors back to project"
filename_ext = ".cpmodproj"
filter_glob: StringProperty(default="*.cpmodproj", options={'HIDDEN'})

def draw(self, context):
props = context.scene.cp77_panel_props
layout = self.layout
Expand All @@ -44,7 +44,7 @@ class CP77GLBExport(Operator,ExportHelper):
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

filter_glob: StringProperty(default="*.glb", options={'HIDDEN'})

filepath: StringProperty(subtype="FILE_PATH")
Expand All @@ -54,7 +54,7 @@ class CP77GLBExport(Operator,ExportHelper):
default=True,
description="Only Export the Selected Meshes. This is probably the setting you want to use"
)

static_prop: BoolProperty(
name="Export as Static Prop",
default=False,
Expand Down Expand Up @@ -94,15 +94,16 @@ def draw(self, context):
row.prop(self, "static_prop")
row = layout.row(align=True)
row.prop(self, "apply_transform")



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,
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 All @@ -128,7 +129,7 @@ class CP77MlSetupExport(Operator):
bl_description = "EXPERIMENTAL: Export material changes to mlsetup files"

filepath: StringProperty(subtype="FILE_PATH")

def execute(self, context):
cp77_mlsetup_export(self, context)
return {"FINISHED"}
Expand Down
32 changes: 23 additions & 9 deletions i_scene_cp77_gltf/exporters/glb_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,44 @@ def default_cp77_options():
"export_shared_accessors": True,
"export_try_omit_sparse_sk": False,
})

return options

#make sure meshes are exported with tangents, morphs and vertex colors
def cp77_mesh_options():
vers=bpy.app.version
options = {
'export_animations': False,
'export_tangents': True,
'export_normals': True,
'export_morph_tangent': True,
'export_morph_normal': True,
'export_morph': True,
'export_colors': True,
'export_attributes': True,
}

if vers[0] < 4:
options.update({
'export_colors': True,

})

if vers[1] >= 2:
options.update({
"export_all_vertex_colors ": True,
"export_active_vertex_color_when_no_material": True,
})
return options

#the options for anims
def pose_export_options():
vers=bpy.app.version
options = {
'export_animations': True,
'export_anim_slide_to_zero': True,
'export_animation_mode': 'ACTIONS',
'export_anim_single_armature': True,
"export_bake_animation": True
"export_bake_animation": False
}
return options

Expand Down Expand Up @@ -101,14 +115,14 @@ def export_cyberpunk_glb(context, filepath, export_poses=False, export_visible=F

objects = context.selected_objects
options = default_cp77_options()

#if for photomode, make sure there's an armature selected, if not use the message box to show an error
if export_poses:
armatures = [obj for obj in objects if obj.type == 'ARMATURE']
if not armatures:
show_message("No armature objects are selected, please select an armature")
return {'CANCELLED'}

export_anims(context, filepath, options, armatures)
return{'FINISHED'}

Expand Down Expand Up @@ -148,7 +162,7 @@ def export_anims(context, filepath, options, armatures):
action["fallbackFrameIndices"] = []
if "optimizationHints" not in action:
action["optimizationHints"] = { "preferSIMD": False, "maxRotationCompression": 1}

options.update(pose_export_options())
for armature in armatures:
reset_armature(armature, context)
Expand Down Expand Up @@ -190,7 +204,7 @@ def export_meshes(context, filepath, export_visible, limit_selected, static_prop
bpy.ops.mesh.select_face_by_sides(number=3, type='NOTEQUAL', extend=False)
show_message("All faces must be triangulated before exporting. Untriangulated faces have been selected for you. See https://tinyurl.com/triangulate-faces")
return {'CANCELLED'}

if red_garment_col:
add_garment_cap(mesh)

Expand All @@ -217,7 +231,7 @@ def export_meshes(context, filepath, export_visible, limit_selected, static_prop
if not armature_modifier:
show_message((f"Armature missing from: {mesh.name} Armatures are required for movement. If this is intentional, try 'export as static prop'. See https://tinyurl.com/armature-missing"))
return {'CANCELLED'}

armature = armature_modifier.object

# Make necessary to armature visibility and selection state for export
Expand All @@ -237,7 +251,7 @@ def export_meshes(context, filepath, export_visible, limit_selected, static_prop
group_has_bone[group.index] = True
# print(vertex_group.name)

# Add groups with no weights to the set
# Add groups with no weights to the set
for group_index, has_bone in group_has_bone.items():
if not has_bone:
groupless_bones.add(mesh.vertex_groups[group_index].name)
Expand Down Expand Up @@ -276,7 +290,7 @@ def export_meshes(context, filepath, export_visible, limit_selected, static_prop
armature.hide_set(True)
except Exception as e:
print(e)

# def ExportAll(self, context):
# #Iterate through all objects in the scene
def ExportAll(self, context):
Expand Down
Loading

0 comments on commit a115299

Please sign in to comment.