#include "xcollisionaabbtree.h"

XCollisionAabbTree::XCollisionAabbTree()
    : XAsset()
    , mOrigin()
    , mHalfSize()
    , mMaterialIndex(0)
    , mChildCount(0)
    , mTreeIndex()
{
    SetName("Collision AABB Tree");
}

XCollisionAabbTree::~XCollisionAabbTree()
{
}

void XCollisionAabbTree::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mOrigin.setX(aStream->ParseSingle(QString("%1 origin x").arg(GetName())));
        mOrigin.setY(aStream->ParseSingle(QString("%1 origin y").arg(GetName())));
        mOrigin.setZ(aStream->ParseSingle(QString("%1 origin z").arg(GetName())));

        mHalfSize.setX(aStream->ParseSingle(QString("%1 half size x").arg(GetName())));
        mHalfSize.setY(aStream->ParseSingle(QString("%1 half size y").arg(GetName())));
        mHalfSize.setZ(aStream->ParseSingle(QString("%1 half size z").arg(GetName())));

        mMaterialIndex = aStream->ParseUInt32(QString("%1 material index").arg(GetName()));
        mChildCount = aStream->ParseUInt32(QString("%1 child count").arg(GetName()));

        mTreeIndex.ParseData(aStream);
    }
}

void XCollisionAabbTree::Clear()
{
    mOrigin = QVector3D();
    mHalfSize = QVector3D();
    mMaterialIndex = 0;
    mChildCount = 0;
    mTreeIndex.Clear();
}

QVector3D XCollisionAabbTree::GetOrigin() const {
    return mOrigin;
}

void XCollisionAabbTree::SetOrigin(QVector3D aOrigin) {
    mOrigin = aOrigin;
}

QVector3D XCollisionAabbTree::GetHalfSize() const {
    return mHalfSize;
}

void XCollisionAabbTree::SetHalfSize(QVector3D aHalfSize) {
    mHalfSize = aHalfSize;
}

quint32 XCollisionAabbTree::GetMaterialIndex() const {
    return mMaterialIndex;
}

void XCollisionAabbTree::SetMaterialIndex(quint32 aIndex) {
    mMaterialIndex = aIndex;
}

quint32 XCollisionAabbTree::GetChildCount() const {
    return mChildCount;
}

void XCollisionAabbTree::SetChildCount(quint32 count) {
    mChildCount = count;
}

XCollisionAabbTreeIndex& XCollisionAabbTree::GetTreeIndex() {
    return mTreeIndex;
}

void XCollisionAabbTree::SetTreeIndex(const XCollisionAabbTreeIndex& aTreeIndex) {
    mTreeIndex = aTreeIndex;
}
