<commit_before>#include "Application.hpp"

#include <lug/Graphics/Light/Directional.hpp>
#include <lug/Graphics/Scene/MeshInstance.hpp>

// TODO: Remove this when the ResourceManager is done
#include <lug/Graphics/Renderer.hpp>
#include <lug/Graphics/Vulkan/Renderer.hpp>

Application::Application() : lug::Core::Application::Application{{"triangle", {0, 1, 0}}} {
    getRenderWindowInfo().windowInitInfo.title = "Hello Triangle";
}

Application::~Application() {
    // TODO: Remove this when the ResourceManager is done
    lug::Graphics::Renderer* renderer = _graphics.getRenderer();
    lug::Graphics::Vulkan::Renderer* vkRender = static_cast<lug::Graphics::Vulkan::Renderer*>(renderer);
    for (auto& queue: vkRender->getQueues()) {
        queue.waitIdle();
    }
}

bool Application::init(int argc, char* argv[]) {
    if (!lug::Core::Application::init(argc, argv)) {
        return false;
    }

    _scene = _graphics.createScene();
    _triangle = _graphics.createMesh("Triangle");

    //1. pos
    //2. color
    //3. normal
    //4. texture uv
    _triangle->vertices = {
        {{-1.0f, -1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
        {{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
        {{-0.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
    };

    _triangle->indices = {
        2, 1, 0,
    };

    if (!_triangle->load()) {
        return false;
    }

    // Create the scene
    _scene = _graphics.createScene();

    // Add triangle to scene
    {
        std::unique_ptr<lug::Graphics::Scene::MeshInstance> triangleInstance = _scene->createMeshInstance("triangle instance", _triangle.get());
        _scene->getRoot()->createSceneNode("triangle instance node", std::move(triangleInstance));
    }

    // Add directional light to scene
    {
        std::unique_ptr<lug::Graphics::Light::Light> light = _scene->createLight("light", lug::Graphics::Light::Light::Type::Directional);

        // Set the diffuse to white color and the direction to the viewing direction of the camera
        light->setDiffuse({1.0f, 1.0f, 1.0f});
        static_cast<lug::Graphics::Light::Directional*>(light.get())->setDirection({0.0f, 0.0f, -1.0f});

        _scene->getRoot()->createSceneNode("light node", std::move(light));
    }

    // Create a camera
    std::unique_ptr<lug::Graphics::Render::Camera> camera = _graphics.createCamera("camera");
    camera->setScene(_scene.get());

    // Add camera to scene
    {
        std::unique_ptr<lug::Graphics::Scene::MovableCamera> movableCamera = _scene->createMovableCamera("movable camera", camera.get());
        _scene->getRoot()->createSceneNode("movable camera node", std::move(movableCamera));
    }

    // Attach camera to RenderView
    {
        auto& renderViews = _graphics.getRenderer()->getWindow()->getRenderViews();
        renderViews[0]->attachCamera(std::move(camera));
    }

    // Set the position of the camera
    {
        auto& renderViews = _graphics.getRenderer()->getWindow()->getRenderViews();
        renderViews[0]->getCamera()->setPosition({0.0f, 0.0f, 5.0f}, lug::Graphics::Node::TransformSpace::World);
    }

    return true;
}

void Application::onEvent(const lug::Window::Event& event) {
    if (event.type == lug::Window::EventType::CLOSE) {
        close();
    }
}

void Application::onFrame(const lug::System::Time&) {

}
<commit_msg>Fixed triangle sample<commit_after>#include "Application.hpp"

#include <lug/Graphics/Light/Directional.hpp>
#include <lug/Graphics/Scene/MeshInstance.hpp>

// TODO: Remove this when the ResourceManager is done
#include <lug/Graphics/Renderer.hpp>
#include <lug/Graphics/Vulkan/Renderer.hpp>

Application::Application() : lug::Core::Application::Application{{"triangle", {0, 1, 0}}} {
    getRenderWindowInfo().windowInitInfo.title = "Hello Triangle";
}

Application::~Application() {
    // TODO: Remove this when the ResourceManager is done
    lug::Graphics::Renderer* renderer = _graphics.getRenderer();
    lug::Graphics::Vulkan::Renderer* vkRender = static_cast<lug::Graphics::Vulkan::Renderer*>(renderer);
    for (auto& queue: vkRender->getQueues()) {
        queue.waitIdle();
    }
}

bool Application::init(int argc, char* argv[]) {
    if (!lug::Core::Application::init(argc, argv)) {
        return false;
    }

    _scene = _graphics.createScene();
    _triangle = _graphics.createMesh("Triangle");

    //1. pos
    //2. color
    //3. normal
    //4. texture uv
    _triangle->vertices = {
        {{-1.0f, -1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
        {{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
        {{-0.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
    };

    _triangle->indices = {
        2, 1, 0,
    };

    if (!_triangle->load()) {
        return false;
    }

    // Create the scene
    _scene = _graphics.createScene();

    // Add triangle to scene
    {
        std::unique_ptr<lug::Graphics::Scene::MeshInstance> triangleInstance = _scene->createMeshInstance("triangle instance", _triangle.get());
        _scene->getRoot()->createSceneNode("triangle instance node", std::move(triangleInstance));
    }

    // Add directional light to scene
    {
        std::unique_ptr<lug::Graphics::Light::Light> light = _scene->createLight("light", lug::Graphics::Light::Light::Type::Directional);

        // Set the diffuse to white color and the direction to the viewing direction of the camera
        light->setDiffuse({1.0f, 1.0f, 1.0f});
        static_cast<lug::Graphics::Light::Directional*>(light.get())->setDirection({0.0f, 0.0f, -1.0f});

        _scene->getRoot()->createSceneNode("light node", std::move(light));
    }

    // Create a camera
    std::unique_ptr<lug::Graphics::Render::Camera> camera = _graphics.createCamera("camera");
    camera->setScene(_scene.get());

    // Add camera to scene
    {
        std::unique_ptr<lug::Graphics::Scene::MovableCamera> movableCamera = _scene->createMovableCamera("movable camera", camera.get());
        _scene->getRoot()->createSceneNode("movable camera node", std::move(movableCamera));
    }

    // Attach camera to RenderView
    {
        auto& renderViews = _graphics.getRenderer()->getWindow()->getRenderViews();
        renderViews[0]->attachCamera(std::move(camera));
    }

    // Set the position of the camera
    {
        auto& renderViews = _graphics.getRenderer()->getWindow()->getRenderViews();
        renderViews[0]->getCamera()->setPosition({0.0f, 0.0f, 5.0f}, lug::Graphics::Node::TransformSpace::World);
    }

    return true;
}

void Application::onEvent(const lug::Window::Event& event) {
    if (event.type == lug::Window::Event::Type::Close) {
        close();
    }
}

void Application::onFrame(const lug::System::Time&) {

}

{'fraction_non_alphanumeric': 0.18051910177894429, 'fraction_numerical': 0.02799650043744532, 'mean_word_length': 3.4452365521710955, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2121031', 'n_tokens_mistral': 2375, 'n_tokens_neox': 2272, 'n_words': 436}