#!/usr/bin/env python
"""Project texture mapping into one of the corners.

First argument is one of topleft bottomleft topright bottomright specifying
which quarter of the texture to project into, others are the meshes to modify.
"""

import sys

import vb

def opa(f, action):
	if action in ('topleft', 'bottomleft'):
		return f / 2
	if action in ('topright', 'bottomright'):
		return 0.5 + f / 2

def opb(f, action):
	if action in ('topleft', 'topright'):
		return f / 2
	if action in ('bottomleft', 'bottomright'):
		return 0.5 + f / 2

if __name__ == '__main__':
	action = sys.argv[1]
	for arg in sys.argv[2:]:
		m = vb.Mesh(arg)
		for v in m.vertices:
			x, y = v.tex()
			x = opa(x, action)
			y = opb(y, action)
			v.settex([x, y])
		m.write_vertices(arg)

