#!/usr/bin/env python
"""Given a submesh, and the same submesh with some vertices and faces 
removed, create a submesh with all of the original vertices, but only 
the faces which were not deleted. This allows 4D meshes to be 
partially removed:

1) Delete things from, say, 2_transformed.vb, save result.
2) Run this script. first argument 2_transformed.vb, second argument 
   what you just made, saved to the third argument.
3) Copy just the .ib file from the result into both "$2".ib and 
   "$2"_transformed.ib

Maybe there's a better way of doing this, but this does at least work.
"""

import sys

import vb

if __name__ == '__main__':
	modifying = vb.Mesh(sys.argv[1])
	face_source = vb.Mesh(sys.argv[2])
	matchers = face_source.matchers()
	new_faces = []
	for f in modifying.faces:
		done = False
		for i, m in enumerate(matchers):
			if m.matches(modifying, f):
				new_faces.append(f)
				done = True
				break
		if done:
			del matchers[i]
	modifying.faces = new_faces
	modifying.write(sys.argv[3])

