From ceeb1301dccb3bcd76c7931ac1a698b768dcc66c Mon Sep 17 00:00:00 2001 From: Simarilius Date: Sat, 9 Mar 2024 23:45:02 +0000 Subject: [PATCH] allow repathing of the MaterialDepot --- i_scene_cp77_gltf/__init__.py | 33 +++++++++++++++---- .../importers/import_with_materials.py | 7 +++- i_scene_cp77_gltf/material_types/unknown.py | 17 +++++----- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/i_scene_cp77_gltf/__init__.py b/i_scene_cp77_gltf/__init__.py index 4f00a8d..3914d33 100644 --- a/i_scene_cp77_gltf/__init__.py +++ b/i_scene_cp77_gltf/__init__.py @@ -51,6 +51,14 @@ class CP77IOSuitePreferences(AddonPreferences): default=False, ) + # Define the depotfolder path property + depotfolder_path: bpy.props.StringProperty( + name="MaterialDepot Path", + description="Path to the material depot folder", + subtype='DIR_PATH', + default="//MaterialDepot" + ) + # toggle the mod tools tab and its sub panels - default True show_modtools: BoolProperty( @@ -94,6 +102,8 @@ def draw(self, context): layout = self.layout box = layout.box() + row = box.row() + row.prop(self, "depotfolder_path") row = box.row() row.prop(self, "show_modtools",toggle=1) row.prop(self, "experimental_features",toggle=1) @@ -764,7 +774,7 @@ def execute(self, context): selected_rig = rig_files[rig_names.index(selected_rig_name)] self.filepath = selected_rig CP77GLBimport(self, exclude_unused_mats=True, image_format='PNG', with_materials=False, - filepath=selected_rig, hide_armatures=False, import_garmentsupport=False, files=[], directory='', appearances="ALL") + 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) return {'FINISHED'} @@ -1222,7 +1232,7 @@ class CP77EntityImport(Operator,ImportHelper): include_collisions: BoolProperty(name="Include Collisions",default=False,description="Use this option to import collision bodies with this entity") include_phys: BoolProperty(name="Include .phys Collisions",default=False,description="Use this option if you want to import the .phys collision bodies. Useful for vehicle modding") include_entCollider: BoolProperty(name="Include Collision Components",default=False,description="Use this option to import entColliderComponent and entSimpleColliderComponent") - + remap_depot: BoolProperty(name="Remap Depot",default=False,description="replace the json depot path with the one in prefs") inColl: StringProperty(name= "Collector to put the imported entity in", description="Collector to put the imported entity in", default='', @@ -1242,6 +1252,8 @@ def draw(self, context): row = layout.row(align=True) row.prop(self, "with_materials") row = layout.row(align=True) + row.prop(self,"remap_depot") + row = layout.row(align=True) if not self.include_collisions: row.prop(self, "include_collisions") if self.include_collisions: @@ -1265,7 +1277,7 @@ def execute(self, context): bob=self.filepath inColl=self.inColl #print('Bob - ',bob) - importEnt( bob, apps, excluded,self.with_materials, self.include_collisions, self.include_phys, self.include_entCollider, inColl) + importEnt( bob, apps, excluded,self.with_materials, self.include_collisions, self.include_phys, self.include_entCollider, inColl, self.remap_depot) return {'FINISHED'} @@ -1286,6 +1298,8 @@ class CP77StreamingSectorImport(Operator,ImportHelper): want_collisions: BoolProperty(name="Import Collisions",default=False,description="Import Box and Capsule Collision objects (mesh not yet supported)") am_modding: BoolProperty(name="Generate New Collectors",default=False,description="Generate _new collectors for sectors to allow modifications to be saved back to game") with_materials: BoolProperty(name="With Materials",default=False,description="Import Wolvenkit-exported materials") + remap_depot: BoolProperty(name="Remap Depot",default=False,description="replace the json depot path with the one in prefs") + def draw(self, context): layout = self.layout @@ -1296,11 +1310,13 @@ def draw(self, context): row.prop(self, "am_modding") row = layout.row(align=True) row.prop(self, "with_materials") + row = layout.row(align=True) + row.prop(self, "remap_depot") def execute(self, context): bob=self.filepath print('Importing Sectors from project - ',bob) - importSectors( bob, self.want_collisions, self.am_modding, self.with_materials) + importSectors( bob, self.want_collisions, self.am_modding, self.with_materials , self.remap_depot) return {'FINISHED'} @@ -1331,6 +1347,8 @@ def draw(self, context): row.prop(operator, 'hide_armatures') row = layout.row(align=True) row.prop(operator, 'use_cycles') + row = layout.row(align=True) + row.prop(operator, 'remap_depot') if operator.use_cycles: row = layout.row(align=True) row.prop(operator, 'update_gi') @@ -1369,6 +1387,8 @@ class CP77Import(Operator,ImportHelper): import_garmentsupport: BoolProperty(name="Import Garment Support (Experimental)",default=True,description="Imports Garment Support mesh data as color attributes") + remap_depot: BoolProperty(name="Remap Depot",default=False,description="replace the json depot path with the one in prefs") + filepath: StringProperty(subtype = 'FILE_PATH') files: CollectionProperty(type=OperatorFileListElement) @@ -1376,8 +1396,7 @@ class CP77Import(Operator,ImportHelper): appearances: StringProperty(name= "Appearances", description="Appearances to extract with models", - default="ALL", - options={'HIDDEN'} + default="ALL" ) #kwekmaster: refactor UI layout from the operator. @@ -1386,7 +1405,7 @@ def draw(self, context): def execute(self, context): SetCyclesRenderer(self.use_cycles, self.update_gi) - CP77GLBimport(self, self.exclude_unused_mats, self.image_format, self.with_materials, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances) + CP77GLBimport(self, self.exclude_unused_mats, self.image_format, self.with_materials, self.filepath, self.hide_armatures, self.import_garmentsupport, self.files, self.directory, self.appearances,self.remap_depot) return {'FINISHED'} diff --git a/i_scene_cp77_gltf/importers/import_with_materials.py b/i_scene_cp77_gltf/importers/import_with_materials.py index 3c1b83e..82d4462 100644 --- a/i_scene_cp77_gltf/importers/import_with_materials.py +++ b/i_scene_cp77_gltf/importers/import_with_materials.py @@ -13,7 +13,7 @@ def objs_in_col(top_coll, objtype): return sum([len([o for o in col.objects if o.type==objtype]) for col in top_coll.children_recursive])+len([o for o in top_coll.objects if o.type==objtype]) -def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_materials=True, filepath='', hide_armatures=True, import_garmentsupport=False, files=[], directory='', appearances=[]): +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): context=bpy.context loadfiles=self.files @@ -86,6 +86,7 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater #Kwek: was tempted to do a try-catch, but that is just La-Z #Kwek: Added another gate for materials if with_materials and os.path.exists(BasePath + ".Material.json"): + file = open(BasePath + ".Material.json",mode='r') obj = json.loads(file.read()) file.close() @@ -94,6 +95,10 @@ def CP77GLBimport(self, exclude_unused_mats=True, image_format='png', with_mater self.report({'ERROR'}, "Incompatible material.json file detected. This add-on version requires materials generated WolvenKit 8.9.1 or higher.") break DepotPath = str(obj["MaterialRepo"]) + "\\" + context=bpy.context + if remap_depot and os.path.exists(context.preferences.addons[__name__.split('.')[0]].preferences.depotfolder_path): + DepotPath = context.preferences.addons[__name__.split('.')[0]].preferences.depotfolder_path + DepotPath= DepotPath.replace('\\', os.sep) json_apps=obj['Appearances'] # fix the app names as for some reason they have their index added on the end. appkeys=[k for k in json_apps.keys()] diff --git a/i_scene_cp77_gltf/material_types/unknown.py b/i_scene_cp77_gltf/material_types/unknown.py index 6e3a986..3d7c225 100644 --- a/i_scene_cp77_gltf/material_types/unknown.py +++ b/i_scene_cp77_gltf/material_types/unknown.py @@ -62,14 +62,15 @@ def create(self,Data,Mat): print("\t"+param+"Scale = CreateShaderNodeRGB(CurMat, Data['"+param+"'],"+str(x)+','+str(y)+",'"+param+"',True)") elif 'Scale' in param or 'scale' in param: vector=create_node(CurMat.nodes,'ShaderNodeMapping', (x,y), label=param) - vector.inputs[0][0]=Data[param]['X'] - vector.inputs[0][1]=Data[param]['Y'] - vector.inputs[0][2]=Data[param]['Z'] - if VERBOSE: - print("\tvector=create_node(CurMat.nodes,'ShaderNodeMapping', ("+str(x)+','+str(y)+"), label='"+param+"')") - print("\tvector.inputs[0][0]=Data['"+param+"']['X']") - print("\tvector.inputs[0][1]=Data['"+param+"']['Y']") - print("\tvector.inputs[0][2]=Data['"+param+"']['Z']") + if Data[param]: + vector.inputs[0][0]=Data[param]['X'] + vector.inputs[0][1]=Data[param]['Y'] + vector.inputs[0][2]=Data[param]['Z'] + if VERBOSE: + print("\tvector=create_node(CurMat.nodes,'ShaderNodeMapping', ("+str(x)+','+str(y)+"), label='"+param+"')") + print("\tvector.inputs[0][0]=Data['"+param+"']['X']") + print("\tvector.inputs[0][1]=Data['"+param+"']['Y']") + print("\tvector.inputs[0][2]=Data['"+param+"']['Z']") else: print('dict not captured ',param) y=y-ydelta