<commit_before>#include <iostream>

#include "LoaderDae.h"
#include "ChimeraUtils.h"
#include "ExceptionChimera.h"
#include "Camera.h"
#include "CameraSpherical.h"
#include "Light.h"
#include "Object.h"
#include "DrawTriMesh.h"
#include "Material.h"
#include "Effect.h"
#include "Texture.h"
#include "SkyBox.h"
#include "Singleton.h"

namespace ChimeraLoader {

LoaderDae::LoaderDae ( const std::string &textureDir, const std::string &modelDir ) {

    doc = nullptr;
    root = nullptr;
    this->textureDir = textureDir;
    this->modelDir = modelDir;

    pPhysicsControl = Chimera::Infra::Singleton<Chimera::PhysicsControl>::getRefSingleton();

}

LoaderDae::~LoaderDae() {

    if ( doc != nullptr ) {
        delete doc;
        doc = nullptr;
    }

    Chimera::Infra::Singleton<Chimera::PhysicsControl>::releaseRefSingleton();
}

Chimera::Graph::Node* LoaderDae::loadFile ( const std::string &file ) {

    Chimera::Graph::Node *pRootScene = nullptr;
#ifdef WIN32
    std::string dir_arquivo = modelDir + "\\" + file;
#else
    std::string dir_arquivo = modelDir + "/" + file;
#endif

    doc = new tinyxml2::XMLDocument();

    if ( doc->LoadFile ( dir_arquivo.c_str() ) != 0 ) {
        throw Chimera::ExceptionChimera ( Chimera::ExceptionCode::OPEN, "Falha ao ler arquivo" );
    }

    root = doc->FirstChildElement ( "COLLADA" );
    if ( root == nullptr ) {
        throw Chimera::ExceptionChimera ( Chimera::ExceptionCode::OPEN, "Nao  um arquivo colada" );
    }

    pRootScene = getNodeSceneInFile();

    getPhysicSceneInfile();

    return pRootScene;
}

void LoaderDae::getPhysicSceneInfile() {

//     tinyxml2::XMLElement* l_nPhysicScene = findSceneLib (root, ( const char* ) "Physic Scene", ( const char* ) "instance_physics_scene", ( const char* ) "library_physics_scenes" );
//     if ( l_nPhysicScene != nullptr ) {
// 
//         const char *l_nome = l_nPhysicScene->Attribute ( "name" );
//         const char *l_id = l_nPhysicScene->Attribute ( "id" );
// 
//         pPhysicsControl->loadCollada ( l_nPhysicScene );
// 
//         getDadosInstancePhysicModel ( l_nPhysicScene );
// <commit_msg>carga de efeito e lista de imagens<commit_after>#include <iostream>

#include "LoaderDae.h"
#include "ChimeraUtils.h"
#include "ExceptionChimera.h"
#include "Camera.h"
#include "CameraSpherical.h"
#include "Light.h"
#include "Object.h"
#include "DrawTriMesh.h"
#include "Material.h"
#include "Effect.h"
#include "Texture.h"
#include "SkyBox.h"
#include "Singleton.h"

namespace ChimeraLoader {

LoaderDae::LoaderDae ( const std::string &textureDir, const std::string &modelDir ) {

    doc = nullptr;
    root = nullptr;
    this->textureDir = textureDir;
    this->modelDir = modelDir;

    pPhysicsControl = Chimera::Infra::Singleton<Chimera::PhysicsControl>::getRefSingleton();

}

LoaderDae::~LoaderDae() {

    if ( doc != nullptr ) {
        delete doc;
        doc = nullptr;
    }

    Chimera::Infra::Singleton<Chimera::PhysicsControl>::releaseRefSingleton();
}

int libImageMap(tinyxml2::XMLElement* root, std::map<std::string, std::string> &mapaImagens) {
    
    tinyxml2::XMLElement* l_nNode = root->FirstChildElement ( "library_images" );
    if ( l_nNode != nullptr ) {
        l_nNode = l_nNode->FirstChildElement ( "image" );
        while ( l_nNode != nullptr ) {
            
            std::string l_id = Chimera::retornaAtributo ( "id", l_nNode );
            std::string l_val = l_nNode->FirstChildElement ( "init_from" )->GetText();
            mapaImagens[l_id] = l_val;
            
            l_nNode = l_nNode->NextSiblingElement ( "image" );
        }
    }
    
    return mapaImagens.size();
}

int libEffectMap ( tinyxml2::XMLElement* root, std::map<std::string, Chimera::Graph::Effect*> &mapaEfeito) {

    tinyxml2::XMLElement* l_nNode = root->FirstChildElement ( "library_effects" );
    if ( l_nNode != nullptr ) {
        l_nNode = l_nNode->FirstChildElement ( "effect" );
        while ( l_nNode != nullptr ) {

            std::string l_id = Chimera::retornaAtributo ( "id", l_nNode );
            std::string l_name = Chimera::retornaAtributo ( "name", l_nNode );
            
            Chimera::Graph::Effect *pEffect = new Chimera::Graph::Effect ( l_id, l_name  );
            mapaEfeito[ l_id ] = pEffect;
            
            pEffect->loadCollada ( l_nNode );

            l_nNode = l_nNode->NextSiblingElement ( "effect" );
        }

    }
    
    return mapaEfeito.size();
}

Chimera::Graph::Node* LoaderDae::loadFile ( const std::string &file ) {

    Chimera::Graph::Node *pRootScene = nullptr;
#ifdef WIN32
    std::string dir_arquivo = modelDir + "\\" + file;
#else
    std::string dir_arquivo = modelDir + "/" + file;
#endif

    doc = new tinyxml2::XMLDocument();

    if ( doc->LoadFile ( dir_arquivo.c_str() ) != 0 ) {
        throw Chimera::ExceptionChimera ( Chimera::ExceptionCode::OPEN, "Falha ao ler arquivo" );
    }

    root = doc->FirstChildElement ( "COLLADA" );
    if ( root == nullptr ) {
        throw Chimera::ExceptionChimera ( Chimera::ExceptionCode::OPEN, "Nao  um arquivo colada" );
    }

    std::map<std::string, Chimera::Graph::Effect*> mapaEfeito; 
    std::map<std::string, std::string> mapaImagens; 
    
    int totalEffect = libEffectMap(root, mapaEfeito);
    int totalImagens = libImageMap(root, mapaImagens);
    
    
    pRootScene = getNodeSceneInFile();

    getPhysicSceneInfile();

    return pRootScene;
}

void LoaderDae::getPhysicSceneInfile() {

//     tinyxml2::XMLElement* l_nPhysicScene = findSceneLib (root, ( const char* ) "Physic Scene", ( const char* ) "instance_physics_scene", ( const char* ) "library_physics_scenes" );
//     if ( l_nPhysicScene != nullptr ) {
// 
//         const char *l_nome = l_nPhysicScene->Attribute ( "name" );
//         const char *l_id = l_nPhysicScene->Attribute ( "id" );
// 
//         pPhysicsControl->loadCollada ( l_nPhysicScene );
// 
//         getDadosInstancePhysicModel ( l_nPhysicScene );
// 
{'fraction_non_alphanumeric': 0.144675150703282, 'fraction_numerical': 0.002344273275284662, 'mean_word_length': 3.344, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4407425', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2080, 'n_words': 384}