2021-06-08 01:03:44 -04:00
|
|
|
from io import UnsupportedOperation
|
|
|
|
import pyffi
|
|
|
|
import pickle
|
|
|
|
from pyffi.formats.nif import NifFormat
|
|
|
|
import sys
|
|
|
|
|
2021-06-13 06:14:54 -04:00
|
|
|
def validate_nif(mesh_data, nif_stream):
|
|
|
|
mesh_data.inspect_version_only(nif_stream)
|
|
|
|
if mesh_data.version >= 0:
|
|
|
|
mesh_data.read(nif_stream)
|
|
|
|
elif mesh_data.version == -1:
|
|
|
|
raise UnsupportedOperation("Unsupported NIF version")
|
|
|
|
else:
|
|
|
|
raise UnsupportedOperation("Not a NIF")
|
|
|
|
|
2021-06-08 01:03:44 -04:00
|
|
|
argv = sys.argv
|
|
|
|
try:
|
|
|
|
index = argv.index("--") + 1
|
|
|
|
except ValueError:
|
|
|
|
index = len(argv)
|
|
|
|
argv = argv[index:]
|
|
|
|
|
2021-06-13 06:14:54 -04:00
|
|
|
print(argv[0] + ' --> ' + argv[1] + ' TEMPLATE: ' + argv[2])
|
2021-06-13 01:50:25 -04:00
|
|
|
|
2021-06-13 06:14:54 -04:00
|
|
|
mesh_data = NifFormat.Data()
|
|
|
|
with open(argv[0], 'rb') as mesh_file:
|
|
|
|
validate_nif(mesh_data, mesh_file)
|
|
|
|
|
|
|
|
alpha_index = len(mesh_data.header.block_types)
|
|
|
|
|
|
|
|
for child in mesh_data.get_global_iterator():
|
|
|
|
# Replace the generic collision data with data from the template,
|
|
|
|
# but preserve the collision vertices
|
|
|
|
if isinstance(child, NifFormat.bhkCollisionObject):
|
|
|
|
template_data = NifFormat.Data()
|
|
|
|
with open(argv[2], 'rb') as template_file:
|
|
|
|
validate_nif(template_data, template_file)
|
2021-06-08 01:03:44 -04:00
|
|
|
|
2021-06-13 06:14:54 -04:00
|
|
|
new_collision = template_data.roots[0].collision_object
|
|
|
|
new_collision.body.shape = child.body.shape
|
2021-06-13 01:50:25 -04:00
|
|
|
|
2021-06-13 06:14:54 -04:00
|
|
|
child.target.collision_object = new_collision
|
|
|
|
# Fix the alpha value
|
2021-06-08 01:03:44 -04:00
|
|
|
if isinstance(child, NifFormat.NiTriShape):
|
2021-06-13 01:50:25 -04:00
|
|
|
alpha = NifFormat.NiAlphaProperty(parent=child)
|
2021-06-08 01:03:44 -04:00
|
|
|
alpha.flags = 4845
|
2021-06-13 01:50:25 -04:00
|
|
|
child.bs_properties[-1] = alpha
|
2021-06-13 06:14:54 -04:00
|
|
|
mesh_data.blocks.append(alpha)
|
2021-06-08 01:03:44 -04:00
|
|
|
|
2021-06-13 01:50:25 -04:00
|
|
|
with open(argv[1], 'wb') as nif_out:
|
2021-06-13 06:14:54 -04:00
|
|
|
mesh_data.write(nif_out)
|