






#include "xgfxworldvertex.h"

XGfxWorldVertex::XGfxWorldVertex()
    : XAsset() {
}

void XGfxWorldVertex::ParseData(QDataStream *aStream) {
    if (GetPtr() == -1) {
        aStream->read((char*)mXYZ, 3 * sizeof(float));
        aStream->read((char*)&mBinormalSign, sizeof(float));

        // Read color components
        quint8 r, g, b, a;
        aStream->read((char*)&r, sizeof(quint8));
        aStream->read((char*)&g, sizeof(quint8));
        aStream->read((char*)&b, sizeof(quint8));
        aStream->read((char*)&a, sizeof(quint8));
        mColor.r = r;
        mColor.g = g;
        mColor.b = b;
        mColor.a = a;

        // Read texture coordinates
        aStream->read((char*)mTexCoord, 2 * sizeof(float));
        aStream->read((char*)mLmapCoord, 2 * sizeof(float));

        // Read normal and tangent (assuming they're PackedUnitVec)
        mNormal.ParseData(aStream);
        mTangent.ParseData(aStream);
    }
}

const float* XGfxWorldVertex::GetXYZ() const {
    return mXYZ;
}

void XGfxWorldVertex::SetXYZ(const float* xyz, size_t count) {
    if (count <= 3) {
        memcpy(mXYZ, xyz, count * sizeof(float));
    }
}

float XGfxWorldVertex::GetBinormalSign() const {
    return mBinormalSign;
}

void XGfxWorldVertex::SetBinormalSign(float sign) {
    mBinormalSign = sign;
}

const GfxColor& XGfxWorldVertex::GetColor() const {
    return mColor;
}

void XGfxWorldVertex::SetColor(const GfxColor& color) {
    mColor = color;
}

const float* XGfxWorldVertex::GetTexCoord() const {
    return mTexCoord;
}

void XGfxWorldVertex::SetTexCoord(const float* texCoord, size_t count) {
    if (count <= 2) {
        memcpy(mTexCoord, texCoord, count * sizeof(float));
    }
}

const float* XGfxWorldVertex::GetLmapCoord() const {
    return mLmapCoord;
}

void XGfxWorldVertex::SetLmapCoord(const float* lmapCoord, size_t count) {
    if (count <= 2) {
        memcpy(mLmapCoord, lmapCoord, count * sizeof(float));
    }
}

const PackedUnitVec& XGfxWorldVertex::GetNormal() const {
    return mNormal;
}

void XGfxWorldVertex::SetNormal(const PackedUnitVec& normal) {
    mNormal = normal;
}

const PackedUnitVec& XGfxWorldVertex::GetTangent() const {
    return mTangent;
}

void XGfxWorldVertex::SetTangent(const PackedUnitVec& tangent) {
    mTangent = tangent;
}




