Skip to content

Commit

Permalink
Updates to Sector import/export to get it working again
Browse files Browse the repository at this point in the history
should generate valid axl for deletions.
  • Loading branch information
Simarilius-uk committed Apr 19, 2024
1 parent dd8ad20 commit 95f67eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
26 changes: 24 additions & 2 deletions i_scene_cp77_gltf/exporters/sectors_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
#
# Ask in world-editing on the discord (https://discord.gg/redmodding) if you have any trouble

# TODO

# - Fix the entities
# - Add collisions
# - sort out instanced bits












import json
import glob
import os
Expand Down Expand Up @@ -347,6 +364,10 @@ def exportSectors( filename):
j=json.load(f)
nodes = j["Data"]["RootChunk"]["nodes"]
t=j['Data']['RootChunk']['nodeData']['Data']
# add nodeDataIndex props to all the nodes in t
for index, obj in enumerate(t):
obj['nodeDataIndex']=index

sectorName=os.path.basename(filepath)[:-5]
deletions[sectorName]=[]
deletions['Decals'][sectorName]=[]
Expand Down Expand Up @@ -452,16 +473,17 @@ def exportSectors( filename):

case 'worldEntityNode':
if isinstance(e, dict) and 'entityTemplate' in data.keys():
entname = data['entityTemplate']['DepotPath']
entname = data['entityTemplate']['DepotPath']['$value'].replace('\\', os.sep)

if(entname != 0):
instances = [x for x in t if x['NodeIndex'] == i]
for idx,inst in enumerate(instances):
obj_col=find_col(i,idx,Sector_coll)
#print(obj_col)
# THIS IS WRONG, the entity meshes are in child collectors not objects
# THIS WAS WRONG, the entity meshes are in child collectors not objects so children>0 and children.objects>0
if obj_col and len(obj_col.children)>0:
if len(obj_col.children[0].objects)>0:
obj=obj_col.children[0].objects[0]
# Check for Position and if changed delete the original and add to the new sector
if obj.matrix_world!=Matrix(obj_col['matrix']):
deletions[sectorName].append(obj_col)
Expand Down
9 changes: 5 additions & 4 deletions i_scene_cp77_gltf/importers/sector_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
new['appearanceName']=data['appearanceName']
new['pivot']=inst['Pivot']

if len(group.all_objects)>0:
new['matrix']=group.all_objects[0].matrix_local

pos = Vector(get_pos(inst))
rot=[0,0,0,0]
scale =Vector((1/scale_factor,1/scale_factor,1/scale_factor))
Expand All @@ -444,6 +443,8 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
obj.matrix_local= inst_trans_mat @ obj.matrix_local
if 'Armature' in obj.name:
obj.hide_set(True)
if len(group.all_objects)>0:
new['matrix']=group.all_objects[0].matrix_world

case 'worldBendedMeshNode' | 'worldCableMeshNode' :
#print(type)
Expand Down Expand Up @@ -997,8 +998,8 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
# Have to do a view_layer update or the matrices are all blank
bpy.context.view_layer.update()
for col in Sector_coll.children:
if len(col.objects)>0:
col['matrix']= col.objects[0].matrix_world
if len(col.all_objects)>0:
col['matrix']= col.all_objects[0].matrix_world



Expand Down

0 comments on commit 95f67eb

Please sign in to comment.