
#ifndef TTREE_H_INCLUDED
#define TTREE_H_INCLUDED

/*
OBJET       classe d'un bouquet d'arbre (par instanciation > model)

DATE        08/2025

AUTEUR      philippe Thebaud

COMMENTAIRE utilisez TWood pour une forêt (plus d'une centaine d'arbres)
*/

#include <GL/glew.h>
#include <string>
#include <fstream>
#include <vector>
//#include <deque>

#include "../ECO/OUtils.h"
#include "../ECO/OMesh_obj.h"
#include "../ECO/defered/ODshader.h"

#include "common.h"


// code flux load save
#define FLUX_TREE1      "tree1"
#define FLUX_TREE1_M    "tree1m"

class Ttree_shader : public ODshader
{
public:

    Ttree_shader();

    bool        create();

    void        setVP(const OMat4& vp);
    void        setTextures(uint32_t texture, uint32_t normal, uint32_t specular);
    void        setTime(float value);

private:

    uint32_t    m_vp;
	uint32_t    m_colorMap, m_normalMap, m_specularMap;
	uint32_t    m_time;

};


class Ttree
{
public:
	Ttree();
	~Ttree();

    void        addModel(std::string flux);

    void        create(std::string flux);
    void        create(std::fstream& flux);

	void        draw(OMat4& vp);

	OVec3_f     getBound_min(size_t instance);
	OVec3_f     getBound_max(size_t instance);
	size_t      getInstance_nbr();
	OMat4&      getModel(size_t instance);

	void        save(std::ofstream& flux);

private:

    void        _composition();

	void		_setModel(size_t idx);

private:

    std::string m_code, m_path, m_file;
	bool        m_cull_face;
	OMesh_obj   mesh;
	float       m_time;

    std::vector<OMat4>      m_model;
	std::vector<OMat4>      m_model_multi;
    std::vector<OVec3_f>    m_pos;
    std::vector<OVec3_f>    m_rot;
    std::vector<float>      m_scale;

public:

    Ttree_shader    dshTree;
};

#endif
