#include "xcbrush.h"

XCBrush::XCBrush()
    : XAsset()
    , mMins()
    , mContents(0)
    , mMaxs()
    , mNumsides()
    , mSides()
    , mAxialMaterialNum()
    , mBaseAdjacentSide()
    , mFirstAdjacentSideOffsets()
    , mEdgeCount()
{
    
}

XCBrush::~XCBrush()
{
    
}

void XCBrush::ParseData(QDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        qint32 sidesPtr, baseAdjacentSidePtr;
        *aStream
            >> mMins[0]
            >> mMins[1]
            >> mMins[2]
            >> mContents
            >> mMaxs[0]
            >> mMaxs[1]
            >> mMaxs[2]
            >> mNumsides
            >> sidesPtr;

        for (int i = 0; i < 3; i++)
        {
            *aStream
                >> mAxialMaterialNum[i][0]
                >> mAxialMaterialNum[i][1]
                >> mAxialMaterialNum[i][2];
        }

        *aStream >> baseAdjacentSidePtr;

        for (int i = 0; i < 3; i++)
        {
            *aStream
                >> mFirstAdjacentSideOffsets[i][0]
                >> mFirstAdjacentSideOffsets[i][1]
                >> mFirstAdjacentSideOffsets[i][2];
        }
        for (int i = 0; i < 3; i++)
        {
            *aStream
                >> mEdgeCount[i][0]
                >> mEdgeCount[i][1]
                >> mEdgeCount[i][2];
        }

        aStream->skipRawData(10);

        if (sidesPtr == -1)
        {
            XCBrushSide newSize;
            newSize.ParseData(aStream);
        }

        if (baseAdjacentSidePtr == -1)
        {
            XCBrushSide newSize;
            newSize.ParseData(aStream);
        }
    }
}

void XCBrush::Clear()
{
    mMins = QVector3D();
    mContents = 0;
    mMaxs = QVector3D();
    mNumsides = 0;
    mSides = QVector<XCBrushSide>();
    mAxialMaterialNum = QVector<QVector3D>();
    mBaseAdjacentSide = 0;
    mFirstAdjacentSideOffsets = QVector<QVector3D>();
    mEdgeCount = QVector<QVector3D>();
}
