#include "AlphaMapCalculator.h" #include #include namespace CAlphaMapCalculator { struct Blend4 { Blend4(BlendShape4 shape,int alphamap) : m_Shape(shape), m_AlphaMap(alphamap) {} BlendShape4 m_Shape; int m_AlphaMap; }; struct Blend8 { Blend8(BlendShape8 shape,int alphamap) : m_Shape(shape), m_AlphaMap(alphamap) {} BlendShape8 m_Shape; int m_AlphaMap; }; Blend4 Blends1Neighbour[] = { Blend4(BlendShape4(1,0,0,0), 12) // u shape blend }; Blend4 Blends2Neighbour[] = { Blend4(BlendShape4(0,1,1,0), 7), // l shaped corner blend Blend4(BlendShape4(1,0,1,0), 10) // two edges blend }; Blend8 Blends2Neighbour8[] = { Blend8(BlendShape8(1,1,0,0,0,0,0,0), 12), // u shaped blend Blend8(BlendShape8(1,0,0,0,0,1,0,0), 12), // u shaped blend Blend8(BlendShape8(0,1,0,1,0,0,0,0), 0) , Blend8(BlendShape8(0,1,0,0,0,1,0,0), 0) }; Blend4 Blends3Neighbour[] = { Blend4(BlendShape4(1,1,1,0), 4) // l shaped corner blend }; Blend8 Blends3Neighbour8[] = { Blend8(BlendShape8(1,1,0,0,1,0,0,0), 10), Blend8(BlendShape8(1,1,0,0,0,0,0,1), 12), Blend8(BlendShape8(1,1,1,0,0,0,0,0), 1), Blend8(BlendShape8(0,1,1,0,1,0,0,0), 7), Blend8(BlendShape8(0,0,1,0,1,0,1,0), 4), Blend8(BlendShape8(1,1,0,0,0,1,0,0), 12), Blend8(BlendShape8(1,1,0,1,0,0,0,0), 12), Blend8(BlendShape8(0,0,1,0,1,0,0,1), 7), Blend8(BlendShape8(1,0,0,1,0,1,0,0), 12), Blend8(BlendShape8(0,1,0,1,0,1,0,0), 0) }; Blend8 Blends4Neighbour8[] = { Blend8(BlendShape8(1,1,0,0,1,0,0,1), 10), Blend8(BlendShape8(1,1,0,1,1,0,0,0), 10), Blend8(BlendShape8(1,1,0,0,1,1,0,0), 10), Blend8(BlendShape8(1,1,0,1,0,0,0,1), 12), Blend8(BlendShape8(0,1,1,0,1,1,0,0), 7), Blend8(BlendShape8(1,1,1,1,0,0,0,0), 1), Blend8(BlendShape8(1,1,1,0,1,0,0,0), 3), Blend8(BlendShape8(0,0,1,0,1,1,0,1), 7), Blend8(BlendShape8(1,0,1,0,1,1,0,0), 4), Blend8(BlendShape8(1,1,1,0,0,1,0,0), 1), Blend8(BlendShape8(1,1,0,1,0,1,0,0), 12), Blend8(BlendShape8(0,1,0,1,0,1,0,1), 0) }; Blend8 Blends5Neighbour8[] = { Blend8(BlendShape8(1,1,1,1,1,0,0,0), 2), Blend8(BlendShape8(1,1,1,1,0,0,0,1), 1), Blend8(BlendShape8(1,1,1,0,1,0,0,1), 3), Blend8(BlendShape8(1,1,1,0,1,0,1,0), 11), Blend8(BlendShape8(1,1,1,0,0,1,0,1), 1), Blend8(BlendShape8(1,1,0,1,1,1,0,0), 10), Blend8(BlendShape8(1,1,1,0,1,1,0,0), 3), Blend8(BlendShape8(1,0,1,0,1,1,0,1), 4), Blend8(BlendShape8(1,1,0,1,0,1,0,1), 12), Blend8(BlendShape8(0,1,1,0,1,1,0,1), 7) }; Blend8 Blends6Neighbour8[] = { Blend8(BlendShape8(1,1,1,1,1,1,0,0), 2), Blend8(BlendShape8(1,1,1,1,1,0,1,0), 8), Blend8(BlendShape8(1,1,1,1,0,1,0,1), 1), Blend8(BlendShape8(1,1,1,0,1,1,1,0), 6), Blend8(BlendShape8(1,1,1,0,1,1,0,1), 3), Blend8(BlendShape8(1,1,0,1,1,1,0,1), 10) }; Blend8 Blends7Neighbour8[] = { Blend8(BlendShape8(1,1,1,1,1,1,0,1), 2), Blend8(BlendShape8(1,1,1,1,1,1,1,0), 9) }; template bool MatchBlendShapeRotated(const T& templateshape,const T& shape,unsigned int& flipflags) { // try to match shapes by testing the template shape in normal, and flipped u and v configurations // test unrotated shape if (shape==templateshape) { return true; } T tstShape; templateshape.FlipU(tstShape); if (shape==tstShape) { flipflags|=0x02; return true; } templateshape.FlipV(tstShape); if (shape==tstShape) { flipflags|=0x01; return true; } return false; } template int MatchBlendShape(const T& templateshape,const T& shape,unsigned int& flipflags) { // try matching unrotated shape first if (MatchBlendShapeRotated(templateshape,shape,flipflags)) { return true; } // now try iterating through rotations of 90,180,270 degrees T tstShape; templateshape.Rotate90(tstShape); if (MatchBlendShapeRotated(tstShape,shape,flipflags)) { flipflags|=flipflags ? 0x10 : 0x04; return true; } templateshape.Rotate180(tstShape); if (MatchBlendShapeRotated(tstShape,shape,flipflags)) { flipflags|=0x08; return true; } templateshape.Rotate270(tstShape); if (MatchBlendShapeRotated(tstShape,shape,flipflags)) { flipflags|=flipflags ? 0x04 : 0x10; return true; } /* FlipBlendU(templateshape,tstShape); if (shape==tstShape) { flipflags|=0x01; return true; } FlipBlendV(templateshape,tstShape); if (shape==tstShape) { flipflags|=0x02; return true; } */ return false; } template int LookupBlend(int tableSize,const S* table,const T& shape,unsigned int& flipflags) { // iterate through known blend shapes for (int b=0;b