initial import
fix half-way crash

There was an off-by-one in the material-assignment, causing a
crash due to an out-of-bounds access on some machines. Fix this,
and swap around the material indices to match.