From ad64ee015dd81f8a30f5510d15b7909e860578c7 Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:02:11 +0000 Subject: [PATCH 1/3] fix for empty workspots --- i_scene_cp77_gltf/importers/sector_import.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/i_scene_cp77_gltf/importers/sector_import.py b/i_scene_cp77_gltf/importers/sector_import.py index 1c6ee3c..c447940 100644 --- a/i_scene_cp77_gltf/importers/sector_import.py +++ b/i_scene_cp77_gltf/importers/sector_import.py @@ -465,7 +465,8 @@ def importSectors( filepath, with_mats, remap_depot, want_collisions, am_modding o['nodeIndex']=i o['debugName']=e['Data']['debugName']['$value'] o['sectorName']=sectorName - o['workspot']=e['Data']['spot']['Data']['resource']['DepotPath']['$value'] + if e['Data']['spot']: + o['workspot']=e['Data']['spot']['Data']['resource']['DepotPath']['$value'] if e['Data']['markings']: o['markings']=e['Data']['markings'][0]['$value'] o.empty_display_size = 0.2 From 044acda9793a0a7fc4dcd14fa34a0901ed286294 Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:02:43 +0000 Subject: [PATCH 2/3] give empty spots a value --- i_scene_cp77_gltf/importers/sector_import.py | 1 + 1 file changed, 1 insertion(+) diff --git a/i_scene_cp77_gltf/importers/sector_import.py b/i_scene_cp77_gltf/importers/sector_import.py index c447940..8799d37 100644 --- a/i_scene_cp77_gltf/importers/sector_import.py +++ b/i_scene_cp77_gltf/importers/sector_import.py @@ -467,6 +467,7 @@ def importSectors( filepath, with_mats, remap_depot, want_collisions, am_modding o['sectorName']=sectorName if e['Data']['spot']: o['workspot']=e['Data']['spot']['Data']['resource']['DepotPath']['$value'] + else o['workspot']='None' if e['Data']['markings']: o['markings']=e['Data']['markings'][0]['$value'] o.empty_display_size = 0.2 From 7bc9fe0e73f75230500fb87f6ebb5a9f5850da28 Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:02:31 +0000 Subject: [PATCH 3/3] extra checks for undefined stuff --- i_scene_cp77_gltf/importers/entity_import.py | 51 +++++++++++--------- i_scene_cp77_gltf/importers/sector_import.py | 3 +- i_scene_cp77_gltf/jsontool.py | 8 ++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/i_scene_cp77_gltf/importers/entity_import.py b/i_scene_cp77_gltf/importers/entity_import.py index 9f4a904..c69dc37 100644 --- a/i_scene_cp77_gltf/importers/entity_import.py +++ b/i_scene_cp77_gltf/importers/entity_import.py @@ -443,9 +443,9 @@ def importEnt(with_materials, filepath='', appearances=[], exclude_meshes=[], in print('interior_02') bindpt=[cmp for cmp in comps if cmp['name']['$value']==bindname] if bindpt and len(bindpt)==1: - if c['localTransform']['Position']['x']['Bits']==0 and c['localTransform']['Position']['y']['Bits']==0 and c['localTransform']['Position']['z']['Bits']==0: + if c['localTransform']['Position']['x']['Bits']==0 and c['localTransform']['Position']['y']['Bits']==0 and c['localTransform']['Position']['z']['Bits']==0 and 'localTransform' in bindpt[0]: c['localTransform']['Position']=bindpt[0]['localTransform']['Position'] - if c['localTransform']['Orientation']['i']==0 and c['localTransform']['Orientation']['j']==0 and c['localTransform']['Orientation']['k']==0 and c['localTransform']['Orientation']['r']==1: + if c['localTransform']['Orientation']['i']==0 and c['localTransform']['Orientation']['j']==0 and c['localTransform']['Orientation']['k']==0 and c['localTransform']['Orientation']['r']==1 and 'localTransform' in bindpt[0]: c['localTransform']['Orientation']=bindpt[0]['localTransform']['Orientation'] @@ -461,28 +461,31 @@ def importEnt(with_materials, filepath='', appearances=[], exclude_meshes=[], in for o in comps: if o['name']['$value']==bindname: pT=o['parentTransform'] - x=o['localTransform']['Position']['x']['Bits']/131072 - y=o['localTransform']['Position']['y']['Bits']/131072 - z=o['localTransform']['Position']['z']['Bits']/131072 - pT_HId=pT['HandleRefId'] - #print(bindname, 'pT_HId = ',pT_HId) - chunk_pt = 0 - for chunk in chunks: - if 'parentTransform' in chunk.keys() and isinstance( chunk['parentTransform'], dict): - if 'HandleId' in chunk['parentTransform'].keys(): - if chunk['parentTransform']['HandleId']==pT_HId: - chunk_pt=chunk['parentTransform'] - #print('HandleId found',chunk['parentTransform']['HandleId']) - if chunk_pt: - #print('in chunk pt processing') - bindname=chunk_pt['Data']['bindName']['$value'] - if bindname=='vehicle_slots': - if vehicle_slots: - slotname=chunk_pt['Data']['slotName']['$value'] - for slot in vehicle_slots: - if slot['slotName']['$value']==slotname: - bindname=slot['boneName']['$value'] - + if pT: + + x=o['localTransform']['Position']['x']['Bits']/131072 + y=o['localTransform']['Position']['y']['Bits']/131072 + z=o['localTransform']['Position']['z']['Bits']/131072 + + pT_HId=pT['HandleRefId'] + #print(bindname, 'pT_HId = ',pT_HId) + chunk_pt = 0 + for chunk in chunks: + if 'parentTransform' in chunk.keys() and isinstance( chunk['parentTransform'], dict): + if 'HandleId' in chunk['parentTransform'].keys(): + if chunk['parentTransform']['HandleId']==pT_HId: + chunk_pt=chunk['parentTransform'] + #print('HandleId found',chunk['parentTransform']['HandleId']) + if chunk_pt: + #print('in chunk pt processing') + bindname=chunk_pt['Data']['bindName']['$value'] + if bindname=='vehicle_slots': + if vehicle_slots: + slotname=chunk_pt['Data']['slotName']['$value'] + for slot in vehicle_slots: + if slot['slotName']['$value']==slotname: + bindname=slot['boneName']['$value'] + ###### if bindname in bones.keys(): #print('bindname in bones') diff --git a/i_scene_cp77_gltf/importers/sector_import.py b/i_scene_cp77_gltf/importers/sector_import.py index 8799d37..0f5d689 100644 --- a/i_scene_cp77_gltf/importers/sector_import.py +++ b/i_scene_cp77_gltf/importers/sector_import.py @@ -467,7 +467,8 @@ def importSectors( filepath, with_mats, remap_depot, want_collisions, am_modding o['sectorName']=sectorName if e['Data']['spot']: o['workspot']=e['Data']['spot']['Data']['resource']['DepotPath']['$value'] - else o['workspot']='None' + else: + o['workspot']='None' if e['Data']['markings']: o['markings']=e['Data']['markings'][0]['$value'] o.empty_display_size = 0.2 diff --git a/i_scene_cp77_gltf/jsontool.py b/i_scene_cp77_gltf/jsontool.py index fe6f9a4..94242b1 100644 --- a/i_scene_cp77_gltf/jsontool.py +++ b/i_scene_cp77_gltf/jsontool.py @@ -77,8 +77,12 @@ def jsonload(filepath): return 'CANCELLED' ent_apps= data['Data']['RootChunk']['appearances'] - ent_components= data['Data']['RootChunk']['components'] - ent_component_data= data['Data']['RootChunk']['compiledData']['Data']['Chunks'] + ent_components=[] + if data['Data']['RootChunk']['components']!=None: + ent_components= data['Data']['RootChunk']['components'] + ent_component_data=[] + if data['Data']['RootChunk']['compiledData']!=None: + ent_component_data= data['Data']['RootChunk']['compiledData']['Data']['Chunks'] res = data['Data']['RootChunk']['resolvedDependencies'] ent_default = data['Data']['RootChunk']['defaultAppearance']['$value'] # Do something for .ent.json