<commit_before>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"
#include "Foundation.h"
#include "OgreRenderingModule.h"
#include "Renderer.h"
#include "EC_OgrePlaceable.h"
#include "EC_OgreMesh.h"

#include <Ogre.h>

namespace OgreRenderer
{
    EC_OgreMesh::EC_OgreMesh(Foundation::ModuleInterface* module) :
        Foundation::ComponentInterface(module->GetFramework()),
        renderer_(checked_static_cast<OgreRenderingModule*>(module)->GetRenderer()),
        entity_(NULL),
        adjustment_node_(NULL),
        attached_(false),
        scale_to_unity_(false)
    {
        Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();
        adjustment_node_ = scene_mgr->createSceneNode();        
    }
    
    EC_OgreMesh::~EC_OgreMesh()
    {
        RemoveMesh();
        
        if (adjustment_node_)
        {            
            Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();
            scene_mgr->destroySceneNode(adjustment_node_);
            adjustment_node_ = NULL;
        }        
    }
    
    void EC_OgreMesh::SetPlaceable(Foundation::ComponentPtr placeable)
    {
        DetachEntity();
        placeable_ = placeable;
        AttachEntity();
    }
    
    void EC_OgreMesh::SetScaleToUnity(bool enable)
    {
        scale_to_unity_ = enable;
        ScaleEntity();
    }
    
    void EC_OgreMesh::SetAdjustPosition(const Core::Vector3df& position)
    {
        adjustment_node_->setPosition(Ogre::Vector3(position.x, position.y, position.z));
    }

    void EC_OgreMesh::SetAdjustOrientation(const Core::Quaternion& orientation)
    {
        adjustment_node_->setOrientation(Ogre::Quaternion(orientation.w, orientation.x, orientation.y, orientation.z));
    }   
    
    Core::Vector3df EC_OgreMesh::GetAdjustPosition() const
    {
        const Ogre::Vector3& pos = adjustment_node_->getPosition();
        return Core::Vector3df(pos.x, pos.y, pos.z);
    }
    
    Core::Quaternion EC_OgreMesh::GetAdjustOrientation() const
    {
        const Ogre::Quaternion& orientation = adjustment_node_->getOrientation();
        return Core::Quaternion(orientation.x, orientation.y, orientation.z, orientation.w);
    }     
    
    bool EC_OgreMesh::SetMesh(const std::string& mesh_name)
    {
        RemoveMesh();
        
        Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();

        Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().getByName(mesh_name);
        if (mesh->hasSkeleton())
        {
            Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().getByName(mesh->getSkeletonName());
            if (skeleton.isNull() || skeleton->getNumBones() == 0)
            {
                mesh->setSkeletonName("");
            }
        }
        
        try
        {
            entity_ = scene_mgr->createEntity(renderer_->GetUniqueObjectName(), mesh_name);
        }
        catch (Ogre::Exception& e)
        {
            OgreRenderingModule::LogError("Could not set mesh " + mesh_name + ": " + std::string(e.what()));
            return false;
        }
        
        AttachEntity();
        ScaleEntity();
        return true;
    }
    
    void EC_OgreMesh::RemoveMesh()<commit_msg>Emit a warning when a skeleton for a mesh was not loaded properly.<commit_after>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"
#include "Foundation.h"
#include "OgreRenderingModule.h"
#include "Renderer.h"
#include "EC_OgrePlaceable.h"
#include "EC_OgreMesh.h"

#include <Ogre.h>

namespace OgreRenderer
{
    EC_OgreMesh::EC_OgreMesh(Foundation::ModuleInterface* module) :
        Foundation::ComponentInterface(module->GetFramework()),
        renderer_(checked_static_cast<OgreRenderingModule*>(module)->GetRenderer()),
        entity_(NULL),
        adjustment_node_(NULL),
        attached_(false),
        scale_to_unity_(false)
    {
        Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();
        adjustment_node_ = scene_mgr->createSceneNode();        
    }
    
    EC_OgreMesh::~EC_OgreMesh()
    {
        RemoveMesh();
        
        if (adjustment_node_)
        {            
            Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();
            scene_mgr->destroySceneNode(adjustment_node_);
            adjustment_node_ = NULL;
        }        
    }
    
    void EC_OgreMesh::SetPlaceable(Foundation::ComponentPtr placeable)
    {
        DetachEntity();
        placeable_ = placeable;
        AttachEntity();
    }
    
    void EC_OgreMesh::SetScaleToUnity(bool enable)
    {
        scale_to_unity_ = enable;
        ScaleEntity();
    }
    
    void EC_OgreMesh::SetAdjustPosition(const Core::Vector3df& position)
    {
        adjustment_node_->setPosition(Ogre::Vector3(position.x, position.y, position.z));
    }

    void EC_OgreMesh::SetAdjustOrientation(const Core::Quaternion& orientation)
    {
        adjustment_node_->setOrientation(Ogre::Quaternion(orientation.w, orientation.x, orientation.y, orientation.z));
    }   
    
    Core::Vector3df EC_OgreMesh::GetAdjustPosition() const
    {
        const Ogre::Vector3& pos = adjustment_node_->getPosition();
        return Core::Vector3df(pos.x, pos.y, pos.z);
    }
    
    Core::Quaternion EC_OgreMesh::GetAdjustOrientation() const
    {
        const Ogre::Quaternion& orientation = adjustment_node_->getOrientation();
        return Core::Quaternion(orientation.x, orientation.y, orientation.z, orientation.w);
    }     
    
    bool EC_OgreMesh::SetMesh(const std::string& mesh_name)
    {
        RemoveMesh();
        
        Ogre::SceneManager* scene_mgr = renderer_->GetSceneManager();

        Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().getByName(mesh_name);
        if (mesh->hasSkeleton())
        {
            Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().getByName(mesh->getSkeletonName());
            if (skeleton.isNull() || skeleton->getNumBones() == 0)
            {
                OgreRenderingModule::LogWarning("Mesh " + mesh_name + " has a skeleton with 0 bones. Disabling the skeleton.");
                mesh->setSkeletonName("");
            }
        }
        
        try
        {
            entity_ = scene_mgr->createEntity(renderer_->GetUniqueObjectName(), mesh_name);
        }
        catch (Ogre::Exception& e)
        {
            OgreRenderingModule::LogError("Could not set mesh " + mesh_name + ": " + std::string(e.what()));
            return false;
        }
        
        AttachEntity();
        ScaleEntity();
        return true;
    }
    
    void EC_OgreMesh::RemoveMesh()
{'fraction_non_alphanumeric': 0.11745416604561038, 'fraction_numerical': 0.0019376956327321509, 'mean_word_length': 2.6055883933369155, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 41, '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': '802030', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1976, 'n_words': 310}