#include "xsurfacecollisiontree.h"

XSurfaceCollisionTree::XSurfaceCollisionTree()
    : XAsset()
    , mTrans()
    , mScale()
    , mNodeCount(0)
    , mNodes()
    , mLeafCount(0)
    , mLeafs()
{
    SetName("Surface Collision Tree");
}

void XSurfaceCollisionTree::ParseData(XDataStream *aStream)
{
    quint32 rawTrans;
    *aStream >> rawTrans;
    memcpy(&mTrans[0], &rawTrans, sizeof(mTrans[0]));
    *aStream >> rawTrans;
    memcpy(&mTrans[1], &rawTrans, sizeof(mTrans[1]));
    *aStream >> rawTrans;
    memcpy(&mTrans[2], &rawTrans, sizeof(mTrans[2]));

    quint32 rawScale;
    *aStream >> rawScale;
    memcpy(&mScale[0], &rawScale, sizeof(mScale[0]));
    *aStream >> rawScale;
    memcpy(&mScale[1], &rawScale, sizeof(mScale[1]));
    *aStream >> rawScale;
    memcpy(&mScale[2], &rawScale, sizeof(mScale[2]));

    qint32 nodesPtr, leafsPtr;
    *aStream
        >> mNodeCount
        >> nodesPtr
        >> mLeafCount
        >> leafsPtr;

    if (nodesPtr)
    {
        for (quint32 i = 0; i < mNodeCount; i++)
        {
            XSurfaceCollisionNode newNode;
            newNode.ParseData(aStream);
            mNodes.append(newNode);
        }
    }
    if (leafsPtr)
    {
        for (quint32 i = 0; i < mLeafCount; i++)
        {
            XSurfaceCollisionLeaf newLeaf;
            newLeaf.ParseData(aStream);
            mLeafs.append(newLeaf);
        }
    }
}

void XSurfaceCollisionTree::Clear()
{
    
}
