Skip to content

Commit

Permalink
allow repathing of the MaterialDepot
Browse files Browse the repository at this point in the history
  • Loading branch information
Simarilius-uk committed Mar 9, 2024
1 parent 4cc3180 commit ceeb130
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
33 changes: 26 additions & 7 deletions i_scene_cp77_gltf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'}
Expand Down Expand Up @@ -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='',
Expand All @@ -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:
Expand All @@ -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'}

Expand All @@ -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
Expand All @@ -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'}


Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -1369,15 +1387,16 @@ 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)
directory: StringProperty()

appearances: StringProperty(name= "Appearances",
description="Appearances to extract with models",
default="ALL",
options={'HIDDEN'}
default="ALL"
)

#kwekmaster: refactor UI layout from the operator.
Expand All @@ -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'}

Expand Down
7 changes: 6 additions & 1 deletion i_scene_cp77_gltf/importers/import_with_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()]
Expand Down
17 changes: 9 additions & 8 deletions i_scene_cp77_gltf/material_types/unknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ceeb130

Please sign in to comment.