@@ -54,7 +54,7 @@ def disable_collection_by_name(collection_name):
5454appearances = None
5555collection = None
5656
57- def CP77GLBimport (self , with_materials , remap_depot , exclude_unused_mats = True , image_format = 'png' , filepath = '' , hide_armatures = True , import_garmentsupport = False , files = [], directory = '' , appearances = [], scripting = False ):
57+ def CP77GLBimport ( with_materials = False , remap_depot = False , exclude_unused_mats = True , image_format = 'png' , filepath = '' , hide_armatures = True , import_garmentsupport = False , files = [], directory = '' , appearances = [], scripting = False ):
5858 cp77_addon_prefs = bpy .context .preferences .addons ['i_scene_cp77_gltf' ].preferences
5959 context = bpy .context
6060
@@ -65,31 +65,29 @@ def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, i
6565 # obj = None
6666 start_time = time .time ()
6767 if not scripting :
68- loadfiles = self . files
68+ loadfiles = files
6969 else :
7070 f = {}
71- f ['name' ]= os .path .basename (self . filepath )
71+ f ['name' ]= os .path .basename (filepath )
7272 loadfiles = (f ,)
73-
73+ glbname = os . path . basename ( filepath )
7474 DepotPath = cp77_addon_prefs
75- appearances = self . appearances . split ( "," )
75+
7676 if not cp77_addon_prefs .non_verbose :
77- if ".anims.glb" in self . filepath :
77+ if ".anims.glb" in filepath :
7878 print ('\n -------------------- Beginning Cyberpunk Animation Import --------------------' )
79- print (f"Importing Animations From: { os . path . basename ( self . filepath ) } " )
79+ print (f"Importing Animations From: { glbname } " )
8080
8181 else :
8282 print ('\n -------------------- Beginning Cyberpunk Model Import --------------------' )
8383 if with_materials == True :
84- print (f"Importing: { os . path . basename ( self . filepath ) } with materials" )
85- print (f"Appearances to Import: { ( ', ' . join ( appearances )) } " )
84+ print (f"Importing: { glbname } with materials" )
85+ print (f"Appearances to Import: " , appearances )
8686 else :
87- print (f"Importing: { os . path . basename ( self . filepath ) } " )
87+ print (f"Importing: { glbname } " )
8888 # prevent crash if no directory supplied when using filepath
89- if len (self .directory )> 0 and not scripting :
90- directory = self .directory
91- else :
92- directory = os .path .dirname (self .filepath )
89+ if len (directory )== 0 or scripting :
90+ directory = os .path .dirname (filepath )
9391
9492
9593 file_names = []
@@ -115,7 +113,7 @@ def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, i
115113 #Kwek: was tempted to do a try-catch, but that is just La-Z
116114 #Kwek: Added another gate for materials
117115 for f in loadfiles :
118- filename = os .path .splitext (f ['name' ])[0 ]
116+ filename = os .path .splitext (os . path . splitext ( f ['name' ])[ 0 ])[0 ]
119117 filepath = os .path .join (directory , f ['name' ])
120118 vers = bpy .app .version
121119 if vers [0 ] == 4 and vers [1 ] >= 2 and vers [1 ] < 4 :
@@ -125,12 +123,12 @@ def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, i
125123 elif vers [0 ] == 4 and vers [1 ] >= 5 :
126124 gltf_importer = glTFImporter (filepath , { "files" : None , "loglevel" : 0 , "import_pack_images" :True , 'import_unused_materials' :False , "merge_vertices" :False , "import_shading" : 'NORMALS' , "bone_heuristic" :heuristic , "guess_original_bind_pose" : False , "import_user_extensions" : "" ,'disable_bone_shape' :octos , 'bone_shape_scale_factor' :1.0 , 'import_scene_as_collection' :True , 'import_scene_extras' :True , 'import_select_created_objects' :True , 'import_merge_material_slots' :False })
127125 else :
128- gltf_importer = glTFImporter (filepath , { "files" : None , "loglevel" : 0 , "import_pack_images" :True , "merge_vertices" :False , "import_shading" : 'NORMALS' , "bone_heuristic" :heuristic , "guess_original_bind_pose" : False , "import_user_extensions" : "" ,'disable_bone_shape' :octos ,})
126+ gltf_importer = glTFImporter (filepath , { "files" : None , "loglevel" : 0 , "import_pack_images" :True , "merge_vertices" :False , "import_shading" : 'NORMALS' , "bone_heuristic" :heuristic , "guess_original_bind_pose" : False , "import_user_extensions" : "" ,'disable_bone_shape' :octos , 'import_select_created_objects' : True , })
129127 gltf_importer .read ()
130128 gltf_importer .checks ()
131129 existingMeshes = bpy .data .meshes .keys ()
132130
133- current_file_base_path = os .path .splitext ( filepath )[ 0 ]
131+ current_file_base_path = os .path .join ( os . path . dirname ( filepath ), filename )
134132 has_material_json = os .path .exists (current_file_base_path + ".Material.json" )
135133
136134 existingMaterials = bpy .data .materials .keys ()
@@ -229,9 +227,14 @@ def CP77GLBimport(self, with_materials, remap_depot, exclude_unused_mats=True, i
229227 validmats = {}
230228 # fix the app names as for some reason they have their index added on the end.
231229 if len (json_apps ) > 0 :
230+
232231 appkeys = [k for k in json_apps .keys ()]
233232 for i ,k in enumerate (appkeys ):
234233 json_apps [k [:- 1 * len (str (i ))]]= json_apps .pop (k )
234+
235+ # save the json_apps to the collection so that we can use it later
236+ collection ['json_apps' ]= json .dumps (json_apps )
237+
235238 #appearances = ({'name':'short_hair'},{'name':'02_ca_limestone'},{'name':'ml_plastic_doll'},{'name':'03_ca_senna'})
236239 #if appearances defined populate valid mats with the mats for them, otherwise populate with everything used.
237240 if len (appearances )> 0 and 'ALL' not in appearances :
@@ -354,6 +357,7 @@ def import_mats(BasePath, DepotPath, exclude_unused_mats, existingMeshes, gltf_i
354357 for name in names :
355358
356359 bpy .data .meshes [name ].materials .clear ()
360+ # we're not getting the materials from the json, but from the glTF importer data
357361 extras = gltf_importer .data .meshes [counter ].extras
358362
359363 # morphtargets don't have material names. Just use all of them.
@@ -368,6 +372,7 @@ def import_mats(BasePath, DepotPath, exclude_unused_mats, existingMeshes, gltf_i
368372 materialNames = extras ["materialNames" ]
369373
370374 # remove duplicate material names (why does "extras" end up with 10k "decals" entries when I import the maimai?)
375+ # Sim - because of a bug in wkit I'd assume mana
371376 materialNames = list (dict .fromkeys (materialNames ))
372377
373378 # Kwek: I also found that other material hiccups will cause the Collection to fail
0 commit comments