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

meshtools UI update, QOL improvements, with_materials fix for all importers #169

Merged
merged 2 commits into from
Jul 28, 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
66 changes: 21 additions & 45 deletions i_scene_cp77_gltf/importers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def execute(self, context):
bob=self.filepath
inColl=self.inColl
#print('Bob - ',bob)
importEnt( bob, apps, excluded, props.with_materials, self.include_collisions, self.include_phys, self.include_entCollider, inColl, props.remap_depot)
importEnt(props.with_materials, bob, apps, excluded, self.include_collisions, self.include_phys, self.include_entCollider, inColl, props.remap_depot)

return {'FINISHED'}

Expand Down Expand Up @@ -152,7 +152,7 @@ def execute(self, context):
bob=self.filepath
props = context.scene.cp77_panel_props
print('Importing Sectors from project - ',bob)
importSectors( bob, self.want_collisions, self.am_modding, props.with_materials , props.remap_depot)
importSectors( bob, props.with_materials, props.remap_depot, self.want_collisions, self.am_modding)
return {'FINISHED'}


Expand Down Expand Up @@ -191,57 +191,33 @@ class CP77Import(Operator, ImportHelper):
default="ALL"
)

#kwekmaster: refactor UI layout from the operator.
# switch back to operator draw function to align with other UI features
def draw(self, context):
pass
cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences
props = context.scene.cp77_panel_props
layout = self.layout
col = layout.column()
col.prop(props, 'with_materials')
if props.with_materials:
col.prop(self, 'image_format')
col.prop(self, 'exclude_unused_mats')
col.prop(props, 'use_cycles')
if props.use_cycles:
col.prop(props, 'update_gi')
col.prop(self, 'hide_armatures')
col.prop(self, 'import_garmentsupport')
if cp77_addon_prefs.experimental_features:
col.prop(props,"remap_depot")


def execute(self, context):
props = context.scene.cp77_panel_props
SetCyclesRenderer(props.use_cycles, props.update_gi)
CP77GLBimport(self, self.exclude_unused_mats, self.image_format, props.with_materials, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances, props.remap_depot)
CP77GLBimport(self, props.with_materials, props.remap_depot, self.exclude_unused_mats, self.image_format, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances)

return {'FINISHED'}


# Material Sub-panel
class CP77_PT_ImportWithMaterial(Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "With Materials"

@classmethod
def poll(cls, context):
operator = context.space_data.active_operator
return operator.bl_idname == "IO_SCENE_GLTF_OT_cp77"

def draw_header(self, context):
props = context.scene.cp77_panel_props
self.layout.prop(props, "with_materials", text="")

def draw(self, context):
cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences
props = context.scene.cp77_panel_props
operator = context.space_data.active_operator
layout = self.layout
row = layout.row(align=True)
layout.enabled = props.with_materials
row.prop(operator, 'exclude_unused_mats')
row = layout.row(align=True)
row.prop(operator, 'image_format')
row = layout.row(align=True)
row.prop(operator, 'hide_armatures')
row = layout.row(align=True)
row.prop(props, 'use_cycles')
if cp77_addon_prefs.experimental_features:
row = layout.row(align=True)
row.prop(props,"remap_depot")
if props.use_cycles:
row = layout.row(align=True)
row.prop(props, 'update_gi')
row = layout.row(align=True)
row.prop(operator, 'import_garmentsupport')



def menu_func_import(self, context):
self.layout.operator(CP77Import.bl_idname, text="Cyberpunk GLTF (.gltf/.glb)", icon_value=get_icon('WKIT'))
self.layout.operator(CP77EntityImport.bl_idname, text="Cyberpunk Entity (.json)", icon_value=get_icon('WKIT'))
Expand Down
7 changes: 4 additions & 3 deletions i_scene_cp77_gltf/importers/entity_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def create_axes(ent_coll,name):
# if you've already imported the body/head and set the rig up you can exclude them by putting them in the exclude_meshes list
#presto_stash=[]

def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=True, include_collisions=False, include_phys=False, include_entCollider=False, inColl='', remapdepot=False):
def importEnt(with_materials, filepath='', appearances=[], exclude_meshes=[], include_collisions=False, include_phys=False, include_entCollider=False, inColl='', remapdepot=False):
cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences
with_materials = with_materials
if not cp77_addon_prefs.non_verbose:
print('')
print('-------------------- Importing Cyberpunk 2077 Entity --------------------')
Expand Down Expand Up @@ -137,7 +138,7 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr
# presto_stash.append(animsinres)

if len(animsinres)>0:
bpy.ops.io_scene_gltf.cp77(filepath=animsinres[0])
bpy.ops.io_scene_gltf.cp77(with_materials, filepath=animsinres[0])
#find what we just loaded
arms=[x for x in bpy.data.objects if 'Armature' in x.name and x not in oldarms]
rig=arms[0]
Expand Down Expand Up @@ -328,7 +329,7 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr
meshApp=c['meshAppearance']['$value']
#print(meshApp)
try:
bpy.ops.io_scene_gltf.cp77(filepath=meshpath, appearances=meshApp)
bpy.ops.io_scene_gltf.cp77(with_materials, filepath=meshpath, appearances=meshApp)
for obj in C.selected_objects:
obj['componentName'] = c['name']['$value']
obj['sourcePath'] = meshpath
Expand Down
14 changes: 8 additions & 6 deletions i_scene_cp77_gltf/importers/import_with_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def objs_in_col(top_coll, objtype):
appearances = None
collection = None

def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_materials=True, filepath='', hide_armatures=True, import_garmentsupport=False, files=[], directory='', appearances=[], remap_depot=False):
def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, image_format='png', filepath='', hide_armatures=True, import_garmentsupport=False, files=[], directory='', appearances=[]):
cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences
context=bpy.context
obj = None
Expand All @@ -56,9 +56,11 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater
else:
print('-------------------- Beginning Cyberpunk Model Import --------------------')
print('')
print(f"Importing: {os.path.basename(self.filepath)}")
if with_materials==True:
print(f"Importing: {os.path.basename(self.filepath)} with materials")
print(f"Appearances to Import: {(', '.join(appearances))}")
else:
print(f"Importing: {os.path.basename(self.filepath)}")
print('')
# prevent crash if no directory supplied when using filepath
if len(self.directory)>0:
Expand Down Expand Up @@ -143,7 +145,7 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater
if ".anims.glb" in filepath:
break
else:
if has_material_json:
if with_materials==True and has_material_json:
matjsonpath = current_file_base_path + ".Material.json"
obj = jsonload(matjsonpath)
if obj == None:
Expand Down Expand Up @@ -173,9 +175,9 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater
for key in json_apps.keys():
for m in json_apps[key]:
validmats[m]=True

import_mats(current_file_base_path, DepotPath, exclude_unused_mats, existingMeshes, gltf_importer, image_format, obj,
validmats)
if with_materials:
import_mats(current_file_base_path, DepotPath, exclude_unused_mats, existingMeshes, gltf_importer, image_format, obj, validmats)

if not cp77_addon_prefs.non_verbose:
print(f"GLB Import Time: {(time.time() - start_time)} Seconds")
print('')
Expand Down
14 changes: 7 additions & 7 deletions i_scene_cp77_gltf/importers/sector_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def get_tan_pos(inst):
pos[1][2] = inst['Elements'][1]['Z']
return pos

def importSectors( filepath='', want_collisions=False, am_modding=False, with_materials=True, remap_depot=False, with_lights=True ):
def importSectors( filepath, with_mats, remap_depot, want_collisions=False, am_modding=False,with_lights=True ):
cp77_addon_prefs = bpy.context.preferences.addons['i_scene_cp77_gltf'].preferences
if not cp77_addon_prefs.non_verbose:
print('')
Expand Down Expand Up @@ -368,7 +368,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
groupname = groupname[:-1]
if groupname not in Masters.children.keys() and os.path.exists(meshpath):
try:
bpy.ops.io_scene_gltf.cp77(filepath=meshpath, appearances=impapps)
bpy.ops.io_scene_gltf.cp77(with_mats, filepath=meshpath, appearances=impapps)
objs = C.selected_objects
move_coll= coll_scene.children.get( objs[0].users_collection[0].name )
coll_target.children.link(move_coll)
Expand Down Expand Up @@ -450,7 +450,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
try:
#print('Importing ',entpath, ' using app ',app)
incoll='MasterInstances'
bpy.ops.io_scene_gltf.cp77entity(filepath=entpath, appearances=app, inColl=incoll)
bpy.ops.io_scene_gltf.cp77entity(with_mats, filepath=entpath, appearances=app, inColl=incoll)
move_coll=Masters.children.get(ent_groupname)
imported=True
except:
Expand Down Expand Up @@ -790,7 +790,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma

#o.empty_display_size = 0.002
#o.empty_display_type = 'IMAGE'
if with_materials:
if with_mats:
mipath = o['decal']
jsonpath = os.path.join(path,mipath)+".json"
#print(jsonpath)
Expand Down Expand Up @@ -864,7 +864,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
# Roads all have stupid prx0 names so instancing by name wont work.
imported=False
try:
bpy.ops.io_scene_gltf.cp77(filepath=meshpath, with_materials=True)
bpy.ops.io_scene_gltf.cp77(with_mats, filepath=meshpath)
objs = C.selected_objects
groupname = objs[0].users_collection[0].name
group= coll_scene.children.get( groupname )
Expand Down Expand Up @@ -955,7 +955,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
new['pivot']=inst['Pivot']
new['meshAppearance']=meshAppearance

print(new['nodeDataIndex'])
#print(new['nodeDataIndex'])
# Should do something with the Advertisements lightData bits here

for old_obj in group.all_objects:
Expand Down Expand Up @@ -1263,4 +1263,4 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma

filepath = 'F:\\CPMod\\judysApt\\judysApt.cpmodproj'

importSectors( filepath, want_collisions=False, am_modding=False, with_materials=True )
importSectors( filepath, with_mats=True, want_collisions=False, am_modding=False )
Loading
Loading