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 90 91 92 93 94 95 96 97 98 99
|
#pragma once
#include "imodelsurface.h"
#include "ishaders.h"
#include "math/AABB.h"
/* FORWARD DECLS */
class ModelSkin;
class RenderableCollector;
class SelectionTest;
class Selector;
class Shader;
class Ray;
namespace model
{
/**
* \brief
* A static surface contains a series of triangles textured with the same
* material. The number of vertices and indices of a surface never changes.
*
* StaticModelSurface objects are composited into a StaticModel object to
* create a renderable static mesh.
*/
class StaticModelSurface final :
public IIndexedModelSurface
{
private:
// Name of the material this surface is using by default (without any skins)
std::string _defaultMaterial;
// Name of the material with skin remaps applied
std::string _activeMaterial;
// Vector of MeshVertex structures, containing the coordinates,
// normals, tangents and texture coordinates of the component vertices
typedef std::vector<MeshVertex> VertexVector;
VertexVector _vertices;
// Vector of render indices, representing the groups of vertices to be
// used to create triangles
typedef std::vector<unsigned int> Indices;
Indices _indices;
// The AABB containing this surface, in local object space.
AABB _localAABB;
private:
// Calculate tangent and bitangent vectors for all vertices.
void calculateTangents();
public:
// Move-construct this static model surface from the given vertex- and index array
StaticModelSurface(std::vector<MeshVertex>&& vertices, std::vector<unsigned int>&& indices);
// Copy-constructor. All vertices and indices will be copied from 'other'.
StaticModelSurface(const StaticModelSurface& other);
/** Get the containing AABB for this surface.
*/
const AABB& getAABB() const {
return _localAABB;
}
/**
* Perform a selection test on this surface.
*/
void testSelect(Selector& selector, SelectionTest& test,
const Matrix4& localToWorld, bool twoSided) const;
// IModelSurface implementation
int getNumVertices() const override;
int getNumTriangles() const override;
const MeshVertex& getVertex(int vertexIndex) const override;
ModelPolygon getPolygon(int polygonIndex) const override;
const std::vector<MeshVertex>& getVertexArray() const override;
const std::vector<unsigned int>& getIndexArray() const override;
const std::string& getDefaultMaterial() const override;
void setDefaultMaterial(const std::string& defaultMaterial);
const std::string& getActiveMaterial() const override;
void setActiveMaterial(const std::string& activeMaterial);
const AABB& getSurfaceBounds() const override;
// Returns true if the given ray intersects this surface geometry and fills in
// the exact point in the given Vector3, returns false if no intersection was found.
bool getIntersection(const Ray& ray, Vector3& intersection, const Matrix4& localToWorld);
void applyScale(const Vector3& scale, const StaticModelSurface& originalSurface);
};
typedef std::shared_ptr<StaticModelSurface> StaticModelSurfacePtr;
}
|