Skip to content

Commit

Permalink
Small fix for exporting objects, and small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Oct 20, 2024
1 parent c7e488d commit 7442a00
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion ModelExporter/addon_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ def parse_object(self, ob, parent: Object):

# let's first sort out any entity data that is specified:
if ob.NMSMesh_props.has_entity or ob.NMSLocator_props.has_entity:
print('this has an entity:', ob)
# we need to pull information from two places:
# ob.NMSEntity_props
# check to see if the mesh's entity will get the action trigger
Expand Down
6 changes: 2 additions & 4 deletions ModelExporter/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def serialize_data(self):
i_len = len(i_data)
index_sizes.append(i_len)
md = TkMeshData(
name,
name.upper(),
v_data + i_data,
self.mesh_metadata[name]["hash"],
i_len,
Expand Down Expand Up @@ -338,7 +338,6 @@ def serialize_data(self):
f.seek(0x10, 1)
curr_pos = f.tell()
offset = struct.unpack("<Q", f.read(8))[0]
# print(offset, )
abs_pos = curr_pos + offset
f.seek(0x10, 1)
_, vert_size = struct.unpack("<II", f.read(8))
Expand All @@ -350,7 +349,7 @@ def serialize_data(self):
StreamMetaDataArray = []
for i, md in enumerate(mesh_datas):
StreamMetaDataArray.append(TkMeshMetaData(
md.IdString,
md.IdString.upper(),
md.Hash,
offsets[i][1],
index_sizes[i],
Expand Down Expand Up @@ -778,7 +777,6 @@ def write(self):
)
hdr.write(f)
gd = self.GeometryData
print(gd["StreamMetaDataArray"])
thing = TkGeometryData_new(
SmallVertexLayout=gd["SmallVertexLayout"], # good
VertexLayout=gd["VertexLayout"], # good
Expand Down
5 changes: 3 additions & 2 deletions ModelExporter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ def movetoindex(lst, i, index):
def nmsHash(data):
"""
Lazy hash function for mesh data
This is simply the last 16 hexadecimal digits of a sha256 hash
This is simply the last 16 hexadecimal digits of a sha256 hash.
Also just take the first 16 verts to save time...
"""
if isinstance(data, list):
d = array('f')
for verts in data:
for verts in data[:16]:
d.extend(verts)
else:
d = data
Expand Down
19 changes: 7 additions & 12 deletions ModelImporter/import_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def __init__(self, fpath, parent_obj=None, ref_scenes=dict(),
'.MBIN')
exml_fpath = fpath
elif ftype.lower() == '.mbin':
exml_fpath = (op.join(self.local_directory, self.scene_basename) +
'.EXML')
mbin_fpath = fpath
else:
raise TypeError('Selected file is of the wrong format.')
Expand Down Expand Up @@ -150,17 +148,15 @@ def __init__(self, fpath, parent_obj=None, ref_scenes=dict(),
# change to render with cycles
self.scn.render.engine = RENDER_ENGINE

if not op.exists(exml_fpath):
if not op.exists(mbin_fpath):
retcode = subprocess.call(
[self.scn.nmsdk_default_settings.MBINCompiler_path, "-q", "-Q",
fpath])
[self.scn.nmsdk_default_settings.MBINCompiler_path, "-q", "-Q", fpath]
)
if retcode != 0:
print('MBINCompiler failed to run. Please ensure it is '
'registered on the path.')
print('MBINCompiler failed to run. Please ensure it is registered on the path.')
print('Import failed')
self.requires_render = False
raise OSError("MBINCompiler failed to run. See System Console "
"for more details. "
raise OSError("MBINCompiler failed to run. See System Console for more details. "
"(Window > Toggle System Console)")

self.scene_node_data = SceneNodeData(self._scene_node_data)
Expand Down Expand Up @@ -235,7 +231,7 @@ def __init__(self, fpath, parent_obj=None, ref_scenes=dict(),

# load all the mesh metadata
self.mesh_metadata = {
x.IdString: gstream_info(
x.IdString.upper(): gstream_info(
x.VertexDataSize,
x.VertexDataOffset,
x.IndexDataSize,
Expand Down Expand Up @@ -613,8 +609,7 @@ def _add_empty_to_scene(self, scene_node: SceneNodeData,
' registered on the path.')
print('Import failed')
return
self.descriptor_data = read_descriptor(
descriptor_path + '.EXML')
self.descriptor_data = read_descriptor(descriptor_path + '.EXML')
else:
print("No descriptor found... Scene is not proc-gen")
self.local_objects[self.scene_basename] = empty_obj
Expand Down
2 changes: 1 addition & 1 deletion ModelImporter/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def read_anim(fname): # TODO: FIX!
""" Reads an anim file. """
# anim_data = dict()
anim_data = dict()

with open(fname, "rb") as f:
header = MBINHeader.read(f)
Expand Down

0 comments on commit 7442a00

Please sign in to comment.