#include "CurveCreator.h"
#include <QtCore/QVector>
CurveCreator::CurveCreator() :
m_iCurrentCurve( -1 ),
m_iDoState( 0 ), m_fSTimes(this, "Smooth", 0, 100, 1, 0)
{
m_fSTimes.SetValue(20);
m_fSTimes.SetVisible(true);
iLastFaceIndex = -1;
iFirstPointIndex = -1;
};
void CurveCreator::BeginStroke( Mesh *,
Modifier, TriggerType )
{
m_iDoState = 0;
m_iCurrentCurve = gLines.
size() - 1;
};
void CurveCreator::EndStroke( void )
{
if( gLines.
back()->ItemCount() == 0 )
{
m_iCurrentCurve = -1;
}
else if (iFirstPointIndex >= 0 && iLastFaceIndex >= 0)
{
int iEndPointIndex = gLines.
back()->ItemCount() - 1;
if (iEndPointIndex - iFirstPointIndex + 1 >= 3 && m_fSTimes)
{
const int iPCount = iEndPointIndex - iFirstPointIndex + 1;
for (int iS = 0; iS < m_fSTimes; ++iS)
{
for (int i = iFirstPointIndex + 1; i < iEndPointIndex; ++i)
aP[i - iFirstPointIndex] = (gLines.
back()->operator[](i-1) + gLines.
back()->operator[](i)
+ gLines.
back()->operator[](i) + gLines.
back()->operator[](i+1)) * 0.25f;
for (int i = iFirstPointIndex + 1; i < iEndPointIndex; ++i)
gLines.
back()->operator[](i) = aP[i - iFirstPointIndex];
}
}
}
iLastFaceIndex = -1;
iFirstPointIndex = -1;
Kernel()->DoOperation(
this );
};
void CurveCreator::AddPatch( const SurfacePoint *, const Vector &, float, float, float, AxisAlignedBoundingBox & )
{
};
void CurveCreator::MouseMove(
float fX,
float fY,
float ,
float , AxisAlignedBoundingBox &
a,
float )
{
SurfacePoint pp;
ViewPort *pVPp =
Kernel()->ViewPort();
if(
Kernel()->Scene()->ActiveCamera()->Pick( fX*pVPp->Width(), fY*pVPp->Height(), pp ) )
{
gLines.
back()->Add( pp.WorldPosition() );
if (iLastFaceIndex == -1 || iFirstPointIndex == -1)
{
iLastFaceIndex = pp.m_iFaceIndex;
iFirstPointIndex = 0;
}
if (iFirstPointIndex >= 0 && iLastFaceIndex >= 0 &&
pp.m_iFaceIndex != iLastFaceIndex)
{
int iEndPointIndex = gLines.
back()->ItemCount() - 2;
if (iEndPointIndex - iFirstPointIndex + 1 >= 3 && m_fSTimes)
{
const int iPCount = iEndPointIndex - iFirstPointIndex + 1;
for (int iS = 0; iS < m_fSTimes; ++iS)
{
for (int i = iFirstPointIndex + 1; i < iEndPointIndex; ++i)
aP[i - iFirstPointIndex] = (gLines.
back()->operator[](i-1) + gLines.
back()->operator[](i)
+ gLines.
back()->operator[](i) + gLines.
back()->operator[](i+1)) * 0.25f;
for (int i = iFirstPointIndex + 1; i < iEndPointIndex; ++i)
gLines.
back()->operator[](i) = aP[i - iFirstPointIndex];
}
}
iFirstPointIndex = gLines.
back()->ItemCount() - 1;
iLastFaceIndex = pp.m_iFaceIndex;
}
};
for(
int i = 0; i < gLines.
size(); ++i )
{
for( unsigned int j = 0; j < gLines[i]->ItemCount(); ++j )
a.Extend( gLines[i]->operator[](j) );
};
};
bool CurveCreator::ExecuteAndInvert( void )
{
if( m_iDoState == 0 )
{
m_iLine.Clear();
m_iDoState = 1;
}
else if( m_iDoState == 1 )
{
if( m_iCurrentCurve != -1 )
{
Store<Vector>* pLine = gLines.
back();
m_iLine = *pLine;
delete pLine;
pLine = 0;
};
m_iDoState = 2;
}
else if( m_iDoState == 2 )
{
if( m_iCurrentCurve != -1 )
{
Store<Vector>* pNewLine = new Store<Vector>;
*pNewLine = m_iLine;
};
m_iDoState = 1;
};
return true;
};
void CurveCreator::Serialize( Stream &
s )
{
s == m_iCurrentCurve == m_iLine == m_iDoState;
};