Skip to content

Commit

Permalink
Sector Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Simarilius-uk committed May 4, 2024
1 parent fc6f6a6 commit 65bdf8e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
10 changes: 6 additions & 4 deletions i_scene_cp77_gltf/exporters/sectors_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ def exportSectors( filename):
print('found ',collname)
crash= sector_Collisions_coll.objects[collname]
if Matrix(crash['matrix']).to_translation()!=crash.matrix_world.to_translation():
print('collision moved - cant process this yet')
# how the f do we deal with this???
# delete the actor with archivexl, then recreate it with the new position
# so we need a collisions node, then we need to add the actor
Expand All @@ -638,11 +637,13 @@ def exportSectors( filename):
impacts['Data']['compiledData']['Data']['Actors'].append(copy.deepcopy(Actors[idx]))
#update its position
ddyer=impacts['Data']['compiledData']['Data']['Actors'][len(impacts['Data']['compiledData']['Data']['Actors'])-1]
ddyer['Position']={'$type': 'WorldPosition',"x": { "$type": "FixedPoint", "Bits": int(crash.location[0]*131072) },"y": {"$type": "FixedPoint","Bits": int(crash.location[1]*131072) },
"z": { "$type": "FixedPoint", "Bits": int(crash.location[2]*131072) }}
actloc = ((crash.location[0]-ddyer['Shapes'][s]['Position']['X'])*131072,(crash.location[1]-ddyer['Shapes'][s]['Position']['Y'])*131072,(crash.location[2]-ddyer['Shapes'][s]['Position']['Z'])*131072)
ddyer['Shapes'][s]['Position']={"$type": "Vector3", "X": { "$type": "FixedPoint", "Bits": int(actloc[0]) },"y": {"$type": "FixedPoint","Bits": int(actloc[1]) },
"z": { "$type": "FixedPoint", "Bits": int(actloc[2]) }}
ddyer['Orientation']={'$type': 'Quaternion','r':float("{:.9g}".format(crash.rotation_quaternion[0])),'i':float("{:.9g}".format(crash.rotation_quaternion[1])),'j':float("{:.9g}".format(crash.rotation_quaternion[2])),'k':float("{:.9g}".format(crash.rotation_quaternion[3]))}
ddyer['Scale']= {'$type': 'Vector3', 'X': float("{:.9g}".format(crash.scale[0])), 'Y': float("{:.9g}".format(crash.scale[1])), 'Z': float("{:.9g}".format(crash.scale[2]))}
ddyer['Shapes'][s]['Size']= { "$type": "Vector3", "X": crash.dimensions[0]/2, "Y": crash.dimensions[1]/2, "Z": crash.dimensions[2]/2 }
if 'Size' in ddyer['Shapes'][s].keys():
ddyer['Shapes'][s]['Size']= { "$type": "Vector3", "X": crash.dimensions[0]/2, "Y": crash.dimensions[1]/2, "Z": crash.dimensions[2]/2 }
#update the numActors property
impacts['Data']['numActors']=len(impacts['Data']['compiledData']['Data']['Actors'])

Expand All @@ -663,6 +664,7 @@ def exportSectors( filename):




print(wIMNs)

# __ __ __ __ ___ ___ ___
Expand Down
4 changes: 2 additions & 2 deletions i_scene_cp77_gltf/importers/collision_mesh_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def CP77CollisionTriangleMeshJSONimport( jsonpath ):

if __name__ == "__main__":
import glob
test='HASHES'
test='filenames'
if test=='HASHES':
project_raw_path = 'C:\\cpmod\\hotel\\source\\raw'
sectorHashStrVal ='4490140329313192080' # from exterior_-15_-6_0_1
entryHashStrVals = ['16942165231745220599', '15592228418071567203','4736015122801775210','15495621493829931487'] # from a colllision node in that sector
for hash in entryHashStrVals:
CP77CollisionTriangleMeshJSONimport_by_hashes(sectorHashStr=sectorHashStrVal,entryHashStr=hash,project_raw_dir=project_raw_path)
else:
project_raw_path = 'C:\\cpmod\\LOD4\\source\\raw\\collision_meshes'
project_raw_path = 'C:\\cpmod\\notell\\source\\raw\\collision_meshes'
jsonpaths = glob.glob(os.path.join(project_raw_path, "**", "*.json"), recursive = True)
for jsonpath in jsonpaths:
print(jsonpath)
Expand Down
72 changes: 49 additions & 23 deletions i_scene_cp77_gltf/importers/sector_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,24 @@ def add_to_list(mesh, dict):
def get_pos(inst):
pos=[0,0,0]
if 'Position' in inst.keys():
if 'Properties' in inst['Position'].keys():
pos[0] = inst['Position']['Properties']['X'] /scale_factor
pos[1] = inst['Position']['Properties']['Y'] /scale_factor
pos[2] = inst['Position']['Properties']['Z'] /scale_factor
if '$type' in inst['Position'].keys() and inst['Position']['$type']=='WorldPosition':
pos[0]=inst['Position']['x']['Bits']/131072*scale_factor
pos[1]=inst['Position']['y']['Bits']/131072*scale_factor
pos[2]=inst['Position']['z']['Bits']/131072*scale_factor
else:
if 'X' in inst['Position'].keys():
pos[0] = inst['Position']['X'] /scale_factor
pos[1] = inst['Position']['Y'] /scale_factor
pos[2] = inst['Position']['Z'] /scale_factor
if 'Properties' in inst['Position'].keys():
pos[0] = inst['Position']['Properties']['X'] /scale_factor
pos[1] = inst['Position']['Properties']['Y'] /scale_factor
pos[2] = inst['Position']['Properties']['Z'] /scale_factor
else:
pos[0] = inst['Position']['x'] /scale_factor
pos[1] = inst['Position']['y'] /scale_factor
pos[2] = inst['Position']['z'] /scale_factor
if 'X' in inst['Position'].keys():
pos[0] = inst['Position']['X'] /scale_factor
pos[1] = inst['Position']['Y'] /scale_factor
pos[2] = inst['Position']['Z'] /scale_factor
else:
pos[0] = inst['Position']['x'] /scale_factor
pos[1] = inst['Position']['y'] /scale_factor
pos[2] = inst['Position']['z'] /scale_factor
elif 'position' in inst.keys():
if 'X' in inst['position'].keys():
pos[0] = inst['position']['X'] /scale_factor
Expand Down Expand Up @@ -796,7 +801,8 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
new['pivot']=inst['Pivot']

print(new['nodeDataIndex'])

# Should do something with the Advertisements lightData bits here

for old_obj in group.all_objects:
obj=old_obj.copy()
new.objects.link(obj)
Expand Down Expand Up @@ -971,21 +977,26 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
Actors=e['Data']['compiledData']['Data']['Actors']
for idx,act in enumerate(Actors):
#print(len(act['Shapes']))
x=act['Position']['x']['Bits']/131072*scale_factor
y=act['Position']['y']['Bits']/131072*scale_factor
z=act['Position']['z']['Bits']/131072*scale_factor
[x,y,z] =get_pos(act)
#x=act['Position']['x']['Bits']/131072*scale_factor
#y=act['Position']['y']['Bits']/131072*scale_factor
#z=act['Position']['z']['Bits']/131072*scale_factor
arot=get_rot(act)
for s,shape in enumerate(act['Shapes']):
if 'Size' in shape.keys():
ssize=(2*shape['Size']['X']*act['Scale']['X'],2*shape['Size']['Y']*act['Scale']['Y'],2*shape['Size']['Z']*act['Scale']['Z'])
else:
ssize=None
spos=get_pos(shape)
srot=get_rot(shape)
arot_q = Quaternion((arot[0],arot[1],arot[2],arot[3]))
srot_q = Quaternion((srot[0],srot[1],srot[2],srot[3]))
rot= arot_q @ srot_q
loc=(spos[0]+x,spos[1]+y,spos[2]+z)
if shape['ShapeType']=='Box' or shape['ShapeType']=='Capsule':
#print('Box Collision Node')
#pprint(act['Shapes'])
ssize=(2*shape['Size']['X']*act['Scale']['X'],2*shape['Size']['Y']*act['Scale']['Y'],2*shape['Size']['Z']*act['Scale']['Z'])
spos=get_pos(shape)
srot=get_rot(shape)
arot_q = Quaternion((arot[0],arot[1],arot[2],arot[3]))
srot_q = Quaternion((srot[0],srot[1],srot[2],srot[3]))
rot= arot_q @ srot_q
loc=(spos[0]+x,spos[1]+y,spos[2]+z)

if shape['ShapeType']=='Box':
bpy.ops.mesh.primitive_cube_add(size=1/scale_factor, scale=(ssize[0],ssize[1],ssize[2]),location=(loc[0],loc[1],loc[2]))
elif shape['ShapeType']=='Capsule':
Expand All @@ -1007,7 +1018,22 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
set_collider_props(crash, shape['ShapeType'], shape['Materials'][0]['$value'], 'WORLD')

else:
print(f"skipping unsupported shape {shape['ShapeType']}")
print(f"unsupported shape {shape['ShapeType']}")
o = bpy.data.objects.new('NDI_'+str(inst['nodeDataIndex'])+'_Actor_'+str(idx)+'_Shape_'+str(s), None)
o['nodeType']='worldCollisionNode'
o['nodeIndex']=i
o['nodeDataIndex']=inst['nodeDataIndex']
o['ShapeType']=shape['ShapeType']
o['ShapeNo']=s
o['ActorIdx']=idx
o['sectorName']=sectorName
sector_Collisions_coll.objects.link(o)
o.location = (loc[0],loc[1],loc[2])
o.rotation_mode = "QUATERNION"
o.rotation_quaternion = rot
if ssize:
o.scale = (ssize[0],ssize[1],ssize[2])



case _:
Expand Down

0 comments on commit 65bdf8e

Please sign in to comment.