Skip to content

Commit

Permalink
Instanced and instancedDestructibles work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simarilius-uk committed Jan 13, 2024
1 parent 93154fe commit adef123
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 51 deletions.
85 changes: 34 additions & 51 deletions i_scene_cp77_gltf/exporters/sectors_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,14 @@ def exportSectors( filename):
if obj_col and inst_trans:
if len(obj_col.objects)>0:
obj=obj_col.objects[0]
set_pos(inst_trans,obj)
set_rot(inst_trans,obj)
set_scale(inst_trans,obj)
# 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)
new_ni=len(template_nodes)
template_nodes.append(copy.deepcopy(nodes[obj_col['nodeIndex']]))
# might need to convert instanced to static here, not sure what the best approach is.
createNodeData(template_nodeData, obj_col, new_ni, obj,ID)
ID+=1
else:
if obj_col:
deletions[sectorName].append(obj_col)
Expand All @@ -395,12 +400,16 @@ def exportSectors( filename):
for idx,inst in enumerate(instances):
obj=find_decal(i,idx,Sector_coll)
if obj:
set_pos(inst,obj)
set_rot(inst,obj)
set_scale(inst,obj)
# Check for Position and if changed delete the original and add to the new sector
if obj.matrix_world!=Matrix(obj['matrix']):
deletions['Decals'][sectorName].append(obj)
new_ni=len(template_nodes)
template_nodes.append(copy.deepcopy(nodes[obj['nodeIndex']]))
createNodeData(template_nodeData, Sector_coll, new_ni, obj,ID)
ID+=1
else:
if obj_col:
deletions[sectorName].append(obj_col)
deletions['Decals'][sectorName].append(obj_col)

case 'worldStaticMeshNode' | 'worldBuildingProxyMeshNode' | 'worldGenericProxyMeshNode'| 'worldTerrainProxyMeshNode':
if isinstance(e, dict) and 'mesh' in data.keys():
Expand All @@ -414,9 +423,7 @@ def exportSectors( filename):
if obj_col:
if len(obj_col.objects)>0:
obj=obj_col.objects[0]
# Needs a check for Position or this is completely wrong
if 'table' in obj_col.name:
print('boo')
# 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)
new_ni=len(template_nodes)
Expand All @@ -440,28 +447,15 @@ def exportSectors( filename):
# THIS IS WRONG, the entity meshes are in child collectors not objects
if obj_col and len(obj_col.children)>0:
if len(obj_col.children[0].objects)>0:
mat=Matrix(obj_col['matrix'])
mat_inv=mat.inverted()
obj=obj_col.children[0].objects[0]
inst_trans_m = obj.matrix_world @ mat_inv
obj_trans = obj.location
pos=inst_trans_m.translation
#pos=obj_trans-basic_pos
inst['Position']['X'] = float("{:.9g}".format(pos[0] ))
inst['Position']['Y'] = float("{:.9g}".format(pos[1] ))
inst['Position']['Z'] = float("{:.9g}".format(pos[2] ))
quat=inst_trans_m.to_quaternion()
inst['Orientation']['r'] = float("{:.9g}".format(quat[0] ))
inst['Orientation']['i'] = float("{:.9g}".format(quat[1] ))
inst['Orientation']['j'] = float("{:.9g}".format(quat[2] ))
inst['Orientation']['k'] = float("{:.9g}".format(quat[3] ))
scale=inst_trans_m.to_scale()
inst['Scale']['X']=float("{:.9g}".format(scale.x ))
inst['Scale']['Y']=float("{:.9g}".format(scale.y ))
inst['Scale']['Z']=float("{:.9g}".format(scale.z ))
#set_pos(inst,obj)
#set_rot(inst,obj)
#set_scale(inst,obj)
# 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)
new_ni=len(template_nodes)
template_nodes.append(copy.deepcopy(nodes[obj_col['nodeIndex']]))

createNodeData(template_nodeData, obj_col, new_ni, obj,ID)
ID+=1

else:
if obj_col:
deletions[sectorName].append(obj_col)
Expand Down Expand Up @@ -518,26 +512,15 @@ def exportSectors( filename):
if obj_col:
if len(obj_col.objects)>0:
obj=obj_col.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)
new_ni=len(template_nodes)
template_nodes.append(copy.deepcopy(nodes[obj_col['nodeIndex']]))

createNodeData(template_nodeData, obj_col, new_ni, obj,ID)
ID+=1

inst_trans_m = obj.matrix_world @ basic_matr_inv
obj_trans = obj.location
pos=inst_trans_m.translation
print(obj_trans, inst_pos)
deltapos=sum(obj_trans-inst_pos)
if abs(deltapos)>0.05:
print('deltapos ',abs(deltapos))
inst['Position']['X'] = float("{:.9g}".format(pos[0] ))
inst['Position']['Y'] = float("{:.9g}".format(pos[1] ))
inst['Position']['Z'] = float("{:.9g}".format(pos[2] ))
quat=inst_trans_m.to_quaternion()
inst['Orientation']['i'] = float("{:.12g}".format(quat[0] ))
inst['Orientation']['j'] = float("{:.12g}".format(quat[1] ))
inst['Orientation']['k'] = float("{:.12g}".format(quat[2] ))
inst['Orientation']['r'] = float("{:.12g}".format(quat[3] ))
scale=inst_trans_m.to_scale()
inst['Scale']['X']=float("{:.9g}".format(scale.x ))
inst['Scale']['Y']=float("{:.9g}".format(scale.y ))
inst['Scale']['Z']=float("{:.9g}".format(scale.z ))
else:
if obj_col:
deletions[sectorName].append(obj_col)
Expand Down
3 changes: 3 additions & 0 deletions i_scene_cp77_gltf/importers/sector_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,9 @@ def importSectors( filepath='', want_collisions=False, am_modding=False, with_ma
print('Finished with ',filepath)
# doing this earlier in the file was breaking the entity postitioning. NO idea how that works, but be warned.
Masters.hide_viewport=True
for obj in bpy.data.objects:
if 'Decal' in obj.name:
obj['matrix']=obj.matrix_world
print('Finished Importing Sectors')


Expand Down

0 comments on commit adef123

Please sign in to comment.