NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
ModelRenderable.h
Go to the documentation of this file.
00001 
00007 #pragma once
00008 
00009 #include "../RenderableComponent.h"
00010 
00011 #include <d3d9.h>
00012 #include <d3dx9tex.h>
00013 #include <vector>
00014 #include <map>
00015 #include <string>
00016 #include <memory>
00017 
00018 #include "../../material/MaterialsSystemInterface.h"
00019 #include "../../texture/TexturesSystemInterface.h"
00020 #include "../../material/MaterialInterface.h"
00021 #include "../../texture/TextureInterface.h"
00022 #include "../../Types.h"
00023 
00024 namespace GraphicsCore {
00025   struct MeshData {
00026     MeshData(const LPD3DXMESH& mesh, const unsigned long& materialCount, const LPD3DXBUFFER& materialBuffer) :
00027       mesh(mesh),
00028       materialCount(materialCount),
00029       materialBuffer(materialBuffer)
00030       {
00031     }
00032     
00033     ~MeshData() {
00034       this->materialBuffer->Release(); // Don't need it any more, so get rid of it.
00035     }
00036     
00037     LPD3DXMESH mesh;
00038     unsigned long materialCount;
00039     LPD3DXBUFFER materialBuffer;
00040   };
00041   
00042   typedef std::map<std::string, std::shared_ptr<MeshData>> MeshCacheMap;
00043   typedef MeshCacheMap::value_type MeshCacheMapValue;
00044 }
00045 
00046 namespace GraphicsCore {
00047 
00048   class ModelComponent: public RenderableComponent, public MaterialsSystemInterface, public TexturesSystemInterface {
00049   public:
00050     ModelComponent(EntitySPTR, ModuleInterface*);
00051     virtual ~ModelComponent();
00052 
00053     bool LoadMeshFromFile(const std::string&);
00054 
00055   private: // Overridden/implemented methods of parent classes
00056     void Render(LPDIRECT3DDEVICE9);
00057 
00058     bool InsertMaterial(unsigned int, EnvelopeSPTR);
00059     bool RemoveMaterial(unsigned int);
00060 
00061     bool InsertTexture(unsigned int, EnvelopeSPTR);
00062     bool RemoveTexture(unsigned int);
00063 
00064   private:
00065     static MeshCacheMap MeshCache;
00066     
00067   private:
00068     void SetMaterials(LPD3DXBUFFER materialBuffer);
00069 
00070     LPD3DXMESH mesh;
00071     unsigned long materialCount;
00072     std::vector<MaterialInterface*> meshMaterials;
00073     std::vector<TextureInterface*> meshTextures;
00074 
00075   };
00076 }
00077