1 #include "mof/private/Mesh.hpp"
2 #include "mof/GraphicsDevice.hpp"
3 #include "mof/private/MeshDisposer.hpp"
4 #include "mof/stream/Constant.hpp"
5 #include "mof/ConsoleIO.hpp"
7 struct mof::Mesh::Impl{
9 std::shared_ptr<mof::MeshDisposer> pMeshDisposer;
10 unsigned long nMaterials;
11 std::shared_ptr<Material>* materials;
12 std::shared_ptr<Texture>* textures;
13 mof::Manipulator<mof::Matrix3D>::Handler worldMatrix;
14 mof::FrameNumber m_frame;
18 std::shared_ptr<mof::MeshDisposer> pMeshDisposer_ ,
19 unsigned long nMaterials_
21 pMeshDisposer(pMeshDisposer_) ,
22 nMaterials(nMaterials_) , materials(NULL) , textures(NULL) ,
23 worldMatrix(mof::makeConstantHandler(mof::Matrix3D::createIdentity()))
33 std::shared_ptr<mof::MeshDisposer> pMeshDisposer ,
34 unsigned long nMaterials ,
35 const std::shared_ptr<Material>* materials ,
36 const std::shared_ptr<Texture>* textures
37 ) : m_pImpl(new Impl(pMeshDisposer , nMaterials )){
39 m_pImpl->materials = new std::shared_ptr<mof::Material>[nMaterials];
40 m_pImpl->textures = new std::shared_ptr<mof::Texture>[nMaterials];
42 for(unsigned long i = 0 ; i < nMaterials ; i++ ){
43 m_pImpl->materials[i] = materials[i];
44 m_pImpl->textures[i] = textures[i];
53 void mof::Mesh::setWorldMatrix(const mof::Manipulator<mof::Matrix3D>::Handler& handler){
54 m_pImpl->worldMatrix = handler;
61 void mof::Mesh::setTexture(
63 const std::shared_ptr<mof::Texture>& pTexture){
65 if(num < m_pImpl->nMaterials)m_pImpl->textures[num] = pTexture;
70 bool mof::Mesh::isVisible() const{
75 void mof::Mesh::update(){
79 void mof::Mesh::draw() const{
82 for( DWORD i = 0; i < m_pImpl->nMaterials ; i++ )
84 mof::GraphicsDevice::setMaterial(*m_pImpl->materials[i].get());
85 mof::GraphicsDevice::setTexture(m_pImpl->textures[i].get());
86 mof::GraphicsDevice::setWorldTransform(m_pImpl->worldMatrix->value(m_pImpl->m_frame));
88 HRESULT hr = m_pImpl->pMeshDisposer->pMesh->DrawSubset( i );
89 if(FAILED(hr))throw std::runtime_error("Failed --- DrawSubset");