1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#pragma once
#include "imodelsurface.h"
#include "render/RenderableSurface.h"
namespace model
{
// Wraps an IIndexedModelSurface to implement the IRenderableSurface interface
// required to draw a composite mesh in the scene.
class RenderableModelSurface :
public render::RenderableSurface
{
private:
const IIndexedModelSurface& _surface;
const IRenderEntity* _entity;
const Matrix4& _localToWorld;
ShaderPtr _wireShader;
ShaderPtr _fillShader;
public:
using Ptr = std::shared_ptr<RenderableModelSurface>;
// Construct this renderable around the existing surface.
// The reference to the orientation matrix is stored and needs to remain valid
RenderableModelSurface(const IIndexedModelSurface& surface, const IRenderEntity* entity, const Matrix4& localToWorld) :
_surface(surface),
_entity(entity),
_localToWorld(localToWorld)
{}
RenderableModelSurface(const RenderableModelSurface& other) = delete;
RenderableModelSurface& operator=(const RenderableModelSurface& other) = delete;
// By default the Model surface will return the render entity's wire shader
virtual ShaderPtr captureWireShader(RenderSystem& renderSystem)
{
return _entity->getWireShader();
}
// By default the Model surface will use the active material as defined by the surface
virtual ShaderPtr captureFillShader(RenderSystem& renderSystem)
{
return renderSystem.capture(getSurface().getActiveMaterial());
}
const IIndexedModelSurface& getSurface() const
{
return _surface;
}
bool isVisible() override
{
return !_surface.getIndexArray().empty();
}
const std::vector<MeshVertex>& getVertices() override
{
return _surface.getVertexArray();
}
const std::vector<unsigned int>& getIndices() override
{
return _surface.getIndexArray();
}
bool isOriented() override
{
return true;
}
const Matrix4& getObjectTransform() override
{
return _localToWorld;
}
const AABB& getObjectBounds() override
{
return _surface.getSurfaceBounds();
}
bool isShadowCasting() override
{
return _entity != nullptr && _entity->isShadowCasting();
}
};
}
|