#ifndef MODELCREATORDATA_H
#define MODELCREATORDATA_H
#include "m3dm.h"
#include "m3dt.h"
#include "m3ds.h"
#include "m3dme.h"
#include "m3dml.h"
#define FREE(var) if(!var)delete[] var;
#define ALLOC(var, type) if(!var)delete var; var = new type;
#define ALLOC_N(var, type, count) if(!var)delete[] var; var = new type[count];

class ModelCreatorData
{
public:

    M3D::M3DME mesh;
    M3D::M3DM model;
    M3D::M3DS shader;
    M3D::M3DT texture[8];
    M3D::M3DML material;

    M3D::M3DME_Header mesh_header;
    M3D::M3DT_Header texture_header;

    M3D::M3DML_Header material_header;
    M3D::M3DML_Layer material_data[8];
    char *material_shader_path;

    M3D::M3DM_Header model_header;
    M3D::M3DM_Data model_data;

    M3D::M3DS_Header shader_header;
    M3D::M3DS_Data shader_data;

    ModelCreatorData();
    ~ModelCreatorData();
};

extern ModelCreatorData *MCD;


#define SET_VALUE(value_object, value_name, value) \
{ \
    MCD->value_object##_header.value_name##_length = value.toUtf8().size()+1; \
    if(MCD->value_object##_data.value_name)delete[] MCD->value_object##_data.value_name; \
    MCD->value_object##_data.value_name = new char[value.toUtf8().size() + 1]; \
    strncpy(MCD->value_object##_data.value_name, value.toUtf8().data(), value.toUtf8().size()+1); \
}

#define SET_VALUE_SIZE(value_object, value_name, value) \
{ \
    MCD->value_object##_header.value_name##_size = value.toUtf8().size()+1; \
    if(MCD->value_object##_data.value_name)delete[] MCD->value_object##_data.value_name; \
    MCD->value_object##_data.value_name = new char[value.toUtf8().size() + 1]; \
    strncpy(MCD->value_object##_data.value_name, value.toUtf8().data(), value.toUtf8().size()+1); \
}


#endif // MODELCREATORDATA_H
