<commit_before>#ifndef __MeshLod_H__
#define __MeshLod_H__

#include "SdkSample.h"

#include "OgreLodConfig.h"
#include "OgreDistanceLodStrategy.h"
#include "OgrePixelCountLodStrategy.h"

#include "OgreProgressiveMesh.h"

//Should we generate Lods in a worker thread?
#define USE_QUEUED_PROGRESSIVE_MESH_GENERATOR

#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
#include "OgreQueuedProgressiveMeshGenerator.h"
typedef Ogre::QueuedProgressiveMeshGenerator PMGenType;
#else
#include "OgreProgressiveMeshGenerator.h"
typedef Ogre::ProgressiveMeshGenerator PMGenType;
#endif

using namespace Ogre;
using namespace OgreBites;

class _OgreSampleClassExport Sample_MeshLod :
	public SdkSample
{
public:

	Sample_MeshLod() : 
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		mWorker(0), mInjector(0),
#endif
		mHeadEntity(0), mUserReductionValue(0.5)
	{
		mInfo["Title"] = "MeshLod";
		mInfo["Description"] = "Shows how to add Lod levels to a mesh.";
		mInfo["Thumbnail"] = "thumb_meshlod.png";
		mInfo["Category"] = "Unsorted";
	}
protected:

	void setupContent()
	{

		mCameraMan->setStyle(CS_ORBIT);

        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));  // set ambient light

        // make the scene's main light come from above
        Light* l = mSceneMgr->createLight();
        l->setType(Light::LT_DIRECTIONAL);
        l->setDirection(Vector3::NEGATIVE_UNIT_Y);

		// create a node for the model
		mHeadNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		// setup gui
		setupControls();
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		mWorker = new PMWorker();
		mInjector = new PMInjector();
#endif
		// load mesh
		changeSelectedMesh("sinbad.mesh");
	}

	void setupControls()
	{
		
		SelectMenu* objectType = mTrayMgr->createThickSelectMenu(TL_TOPLEFT, "ObjectType", "Object : ", 200, 4);
		objectType->addItem("sinbad.mesh");
		objectType->addItem("ogrehead.mesh");
		objectType->addItem("knot.mesh");
		objectType->addItem("fish.mesh");
		objectType->addItem("penguin.mesh");
		objectType->addItem("ninja.mesh");
		objectType->addItem("dragon.mesh");
		objectType->addItem("athene.mesh");
		objectType->addItem("sibenik.mesh");

		/*
		// Add all meshes from popular:
		Ogre::StringVectorPtr meshes = Ogre::ResourceGroupManager::getSingleton().findResourceNames("Popular", "*.mesh");
		for(auto& meshName : *meshes){
			objectType->addItem(meshName);
		}
		*/

		mWireframe = mTrayMgr->createCheckBox(TL_TOPLEFT, "wireframe", "Show wireframe");
		mAutoconfig = mTrayMgr->createCheckBox(TL_TOPLEFT, "autoconfig", "Autoconfigure");
		mNewAlgorithm = mTrayMgr->createCheckBox(TL_TOPLEFT, "newalgorithm", "New algorithm");
		OgreBites::Slider* slider = mTrayMgr->createThickSlider(TL_TOPLEFT, "ReductionSlider", "Reduction value", 200, 50, 0, 1000, 101);
		slider->setValue(500, false); // 50%
		mUserReductionValue = 0.5; // 50%

		mTrayMgr->showCursor();
	}

	void changeSelectedMesh(const Ogre::String& name)
	{	
		if(mHeadEntity){
			mSceneMgr->destroyEntity(mHeadEntity);
			mHeadEntity = 0;
		}
		mHeadMesh = Ogre::MeshManager::getSingleton().load(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		mHeadEntity = mSceneMgr->createEntity(name, mHeadMesh);
		mHeadNode->attachObject(mHeadEntity);
		mCamera->setPosition(Ogre::Vector3(0, 0, 0));
		mCamera->moveRelative(Ogre::Vector3(0, 0, mHeadMesh->getBoundingSphereRadius() * 2));
		mCamera->setNearClipDistance(mHeadMesh->getBoundingSphereRadius() / 32);
		mCamera->setFarClipDistance(mHeadMesh->getBoundingSphereRadius() * 128);

		updateLod();
	}
	void cleanupContent()
	{
		if(mHeadEntity){
			mSceneMgr->destroyEntity(mHeadEntity);
			mHeadEntity = 0;
		}
		
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		delete mWorker;
		mWorker = 0;
		delete mInjector;
		mInjector = 0;
#endif
	}
	
	void sliderMoved(Slider* slider)
	{
		if (slider->getName() == "ReductionSlider") {
			mUserReductionValue = slider->getValue() / 1000.0f;
			mAutoconfig->setChecked(false, false);
			updateLod();
		}
	}

	void itemSelected(SelectMenu* menu)
	{
		if (menu->getName() == "ObjectType") {
			changeSelectedMesh(menu->getSelectedItem());<commit_msg>Fix GUI for MeshLod sample<commit_after>#ifndef __MeshLod_H__
#define __MeshLod_H__

#include "SdkSample.h"

#include "OgreLodConfig.h"
#include "OgreDistanceLodStrategy.h"
#include "OgrePixelCountLodStrategy.h"

#include "OgreProgressiveMesh.h"

//Should we generate Lods in a worker thread?
#define USE_QUEUED_PROGRESSIVE_MESH_GENERATOR

#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
#include "OgreQueuedProgressiveMeshGenerator.h"
typedef Ogre::QueuedProgressiveMeshGenerator PMGenType;
#else
#include "OgreProgressiveMeshGenerator.h"
typedef Ogre::ProgressiveMeshGenerator PMGenType;
#endif

using namespace Ogre;
using namespace OgreBites;

class _OgreSampleClassExport Sample_MeshLod :
	public SdkSample
{
public:

	Sample_MeshLod() : 
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		mWorker(0), mInjector(0),
#endif
		mHeadEntity(0), mUserReductionValue(0.5)
	{
		mInfo["Title"] = "MeshLod";
		mInfo["Description"] = "Shows how to add Lod levels to a mesh.";
		mInfo["Thumbnail"] = "thumb_meshlod.png";
		mInfo["Category"] = "Unsorted";
	}
protected:

	void setupContent()
	{

		mCameraMan->setStyle(CS_ORBIT);

        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));  // set ambient light

        // make the scene's main light come from above
        Light* l = mSceneMgr->createLight();
        l->setType(Light::LT_DIRECTIONAL);
        l->setDirection(Vector3::NEGATIVE_UNIT_Y);

		// create a node for the model
		mHeadNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		// setup gui
		setupControls();
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		mWorker = new PMWorker();
		mInjector = new PMInjector();
#endif
		// load mesh
		changeSelectedMesh("sinbad.mesh");
	}

	void setupControls()
	{
		
		SelectMenu* objectType = mTrayMgr->createThickSelectMenu(TL_TOPLEFT, "ObjectType", "Object:", 200, 4);
		objectType->addItem("sinbad.mesh");
		objectType->addItem("ogrehead.mesh");
		objectType->addItem("knot.mesh");
		objectType->addItem("fish.mesh");
		objectType->addItem("penguin.mesh");
		objectType->addItem("ninja.mesh");
		objectType->addItem("dragon.mesh");
		objectType->addItem("athene.mesh");
		objectType->addItem("sibenik.mesh");

		/*
		// Add all meshes from popular:
		Ogre::StringVectorPtr meshes = Ogre::ResourceGroupManager::getSingleton().findResourceNames("Popular", "*.mesh");
		for(auto& meshName : *meshes){
			objectType->addItem(meshName);
		}
		*/

		mWireframe = mTrayMgr->createCheckBox(TL_TOPLEFT, "wireframe", "Show wireframe");
		mAutoconfig = mTrayMgr->createCheckBox(TL_TOPLEFT, "autoconfig", "Autoconfigure");
		mNewAlgorithm = mTrayMgr->createCheckBox(TL_TOPLEFT, "newalgorithm", "New algorithm");
		OgreBites::Slider* slider = mTrayMgr->createThickSlider(TL_TOPLEFT, "ReductionSlider", "Percentage", 200, 50, 0, 100, 11);
		slider->setValue(50, false); // 50%
		mUserReductionValue = 0.5; // 50%

		mTrayMgr->showCursor();
	}

	void changeSelectedMesh(const Ogre::String& name)
	{	
		if(mHeadEntity){
			mSceneMgr->destroyEntity(mHeadEntity);
			mHeadEntity = 0;
		}
		mHeadMesh = Ogre::MeshManager::getSingleton().load(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		mHeadEntity = mSceneMgr->createEntity(name, mHeadMesh);
		mHeadNode->attachObject(mHeadEntity);
		mCamera->setPosition(Ogre::Vector3(0, 0, 0));
		mCamera->moveRelative(Ogre::Vector3(0, 0, mHeadMesh->getBoundingSphereRadius() * 2));
		mCamera->setNearClipDistance(mHeadMesh->getBoundingSphereRadius() / 32);
		mCamera->setFarClipDistance(mHeadMesh->getBoundingSphereRadius() * 128);

		updateLod();
	}
	void cleanupContent()
	{
		if(mHeadEntity){
			mSceneMgr->destroyEntity(mHeadEntity);
			mHeadEntity = 0;
		}
		
#ifdef USE_QUEUED_PROGRESSIVE_MESH_GENERATOR
		delete mWorker;
		mWorker = 0;
		delete mInjector;
		mInjector = 0;
#endif
	}
	
	void sliderMoved(Slider* slider)
	{
		if (slider->getName() == "ReductionSlider") {
			mUserReductionValue = slider->getValue() / 100.0f;
			mAutoconfig->setChecked(false, false);
			updateLod();
		}
	}

	void itemSelected(SelectMenu* menu)
	{
		if (menu->getName() == "ObjectType") {
			changeSelectedMesh(menu->getSelectedItem());
{'fraction_non_alphanumeric': 0.13742123121667474, 'fraction_numerical': 0.014057198254968492, 'mean_word_length': 5.518957345971564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 83, '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': '4019325', 'n_tokens_mistral': 3213, 'n_tokens_neox': 2943, 'n_words': 494}