Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6009: Re-implement NullModelNode on top of ModelNodeBase
- Loading branch information
1 parent
af383b9
commit 3eec85b
Showing
11 changed files
with
183 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#pragma once | ||
|
||
#include "RenderableModelSurface.h" | ||
#include "render/RenderableBox.h" | ||
|
||
namespace model | ||
{ | ||
|
||
class IndexedBoxSurface final : | ||
public IIndexedModelSurface | ||
{ | ||
private: | ||
const AABB& _bounds; | ||
const Matrix4& _orientation; | ||
|
||
std::vector<MeshVertex> _vertices; | ||
std::vector<unsigned int> _indices; | ||
|
||
public: | ||
IndexedBoxSurface(const AABB& bounds, const Matrix4& orientation) : | ||
_bounds(bounds), | ||
_orientation(orientation) | ||
{ | ||
static Vector3 Origin(0, 0, 0); | ||
|
||
// Calculate the corner vertices of this bounding box | ||
Vector3 max(Origin + _bounds.extents); | ||
Vector3 min(Origin - _bounds.extents); | ||
|
||
auto vertices = render::detail::getFillBoxVertices(min, max, { 1, 1, 1, 1 }); | ||
|
||
for (const auto& vertex : vertices) | ||
{ | ||
_vertices.push_back(MeshVertex( | ||
toVector3(vertex.vertex), | ||
toVector3(vertex.normal), | ||
Vector2(vertex.texcoord.x(), vertex.texcoord.y()), | ||
Vector4(vertex.colour.x(), vertex.colour.y(), vertex.colour.z(), vertex.colour.w()), | ||
toVector3(vertex.tangent), | ||
toVector3(vertex.bitangent) | ||
)); | ||
} | ||
|
||
_indices = render::detail::generateTriangleBoxIndices(); | ||
} | ||
|
||
int getNumVertices() const override | ||
{ | ||
return static_cast<int>(_vertices.size()); | ||
} | ||
|
||
int getNumTriangles() const override | ||
{ | ||
return static_cast<int>(_indices.size() / 3); // 3 indices per triangle | ||
} | ||
|
||
const MeshVertex& getVertex(int vertexNum) const override | ||
{ | ||
return _vertices.at(vertexNum); | ||
} | ||
|
||
ModelPolygon getPolygon(int polygonIndex) const override | ||
{ | ||
assert(polygonIndex >= 0 && polygonIndex * 3 < static_cast<int>(_indices.size())); | ||
|
||
ModelPolygon poly; | ||
|
||
poly.a = _vertices[_indices[polygonIndex * 3]]; | ||
poly.b = _vertices[_indices[polygonIndex * 3 + 1]]; | ||
poly.c = _vertices[_indices[polygonIndex * 3 + 2]]; | ||
|
||
return poly; | ||
} | ||
|
||
const std::string& getDefaultMaterial() const override | ||
{ | ||
static std::string _defaultMaterial; | ||
return _defaultMaterial; | ||
} | ||
|
||
const std::string& getActiveMaterial() const override | ||
{ | ||
return getDefaultMaterial(); | ||
} | ||
|
||
const AABB& getSurfaceBounds() const override | ||
{ | ||
return _bounds; | ||
} | ||
|
||
const std::vector<MeshVertex>& getVertexArray() const override | ||
{ | ||
return _vertices; | ||
} | ||
|
||
const std::vector<unsigned int>& getIndexArray() const override | ||
{ | ||
return _indices; | ||
} | ||
|
||
private: | ||
inline static Vector3 toVector3(const Vector3f& vector) | ||
{ | ||
return { vector.x(), vector.y(), vector.z() }; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "irender.h" | ||
#include "RenderableModelSurface.h" | ||
|
||
namespace model | ||
{ | ||
|
||
class NullModelBoxSurface : | ||
public RenderableModelSurface | ||
{ | ||
public: | ||
NullModelBoxSurface(const IIndexedModelSurface& surface, const IRenderEntity* entity, const Matrix4& localToWorld) : | ||
RenderableModelSurface(surface, entity, localToWorld) | ||
{} | ||
|
||
ShaderPtr captureWireShader(RenderSystem& renderSystem) override | ||
{ | ||
return renderSystem.capture(ColourShaderType::OrthoviewSolid, { 1.0f, 0, 0, 1 }); | ||
} | ||
|
||
ShaderPtr captureFillShader(RenderSystem& renderSystem) override | ||
{ | ||
return renderSystem.capture(BuiltInShaderType::MissingModel); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.