refactor: Rename ModelSceneNode to MeshSceneNode

This commit is contained in:
Vsevolod Kremianskii 2020-09-15 22:23:26 +07:00
parent 06051bd3ab
commit 430a37263f
6 changed files with 25 additions and 25 deletions

View file

@ -118,7 +118,7 @@ set(HEADERS
src/render/modelinstance.h
src/render/scene/aabbnode.h
src/render/scene/lightnode.h
src/render/scene/modelnode.h
src/render/scene/meshnode.h
src/render/scene/scenegraph.h
src/render/scene/scenenode.h
src/render/shaders.h
@ -237,7 +237,7 @@ set(SOURCES
src/render/modelinstance.cpp
src/render/scene/aabbnode.cpp
src/render/scene/lightnode.cpp
src/render/scene/modelnode.cpp
src/render/scene/meshnode.cpp
src/render/scene/scenegraph.cpp
src/render/scene/scenenode.cpp
src/render/shaders.cpp

View file

@ -26,7 +26,7 @@
#include "../resources/resources.h"
#include "mesh/aabb.h"
#include "scene/modelnode.h"
#include "scene/meshnode.h"
#include "scene/scenegraph.h"
#include "modelinstance.h"
@ -224,7 +224,7 @@ void ModelInstance::fill(SceneGraph &scene, const glm::mat4 &baseTransform, bool
if (shouldRender(node)) {
glm::mat4 transform(baseTransform * getNodeTransform(node));
shared_ptr<ModelSceneNode> sceneNode(new ModelSceneNode(this, &node, transform));
shared_ptr<MeshSceneNode> sceneNode(new MeshSceneNode(this, &node, transform));
scene.add(sceneNode);
if (debug) {

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "modelnode.h"
#include "meshnode.h"
using namespace std;
@ -23,27 +23,27 @@ namespace reone {
namespace render {
ModelSceneNode::ModelSceneNode(const ModelInstance *model, const ModelNode *modelNode, const glm::mat4 &transform) :
MeshSceneNode::MeshSceneNode(const ModelInstance *model, const ModelNode *modelNode, const glm::mat4 &transform) :
SceneNode(transform), _model(model), _modelNode(modelNode) {
assert(_model && _modelNode);
_origin = glm::vec4(_modelNode->mesh()->aabb().center(), 1.0f) * transform;
}
bool ModelSceneNode::isTransparent() const {
bool MeshSceneNode::isTransparent() const {
shared_ptr<ModelMesh> mesh(_modelNode->mesh());
return (mesh && mesh->isTransparent()) || _modelNode->alpha() < 1.0f;
}
const ModelInstance *ModelSceneNode::model() const {
const ModelInstance *MeshSceneNode::model() const {
return _model;
}
const ModelNode *ModelSceneNode::modelNode() const {
const ModelNode *MeshSceneNode::modelNode() const {
return _modelNode;
}
const glm::vec3 &ModelSceneNode::origin() const {
const glm::vec3 &MeshSceneNode::origin() const {
return _origin;
}

View file

@ -26,9 +26,9 @@ namespace reone {
namespace render {
class ModelSceneNode : public SceneNode {
class MeshSceneNode : public SceneNode {
public:
ModelSceneNode(const ModelInstance *model, const ModelNode *modelNode, const glm::mat4 &transform);
MeshSceneNode(const ModelInstance *model, const ModelNode *modelNode, const glm::mat4 &transform);
bool isTransparent() const;

View file

@ -30,16 +30,16 @@ namespace reone {
namespace render {
void SceneGraph::clear() {
_opaqueModels.clear();
_transparentModels.clear();
_opaqueMeshes.clear();
_transparentMeshes.clear();
_aabbNodes.clear();
}
void SceneGraph::add(const shared_ptr<ModelSceneNode> &node) {
void SceneGraph::add(const shared_ptr<MeshSceneNode> &node) {
if (node->isTransparent()) {
_transparentModels.push_back(node);
_transparentMeshes.push_back(node);
} else {
_opaqueModels.push_back(node);
_opaqueMeshes.push_back(node);
}
}
@ -48,19 +48,19 @@ void SceneGraph::add(const shared_ptr<AABBSceneNode> &node) {
}
void SceneGraph::prepare(const glm::vec3 &cameraPosition) {
for (auto &node : _transparentModels) {
for (auto &node : _transparentMeshes) {
node->setDistanceToCamera(glm::distance2(node->origin(), cameraPosition));
}
std::sort(_transparentModels.begin(), _transparentModels.end(), [](const shared_ptr<ModelSceneNode> &left, const shared_ptr<ModelSceneNode> &right) {
std::sort(_transparentMeshes.begin(), _transparentMeshes.end(), [](const shared_ptr<MeshSceneNode> &left, const shared_ptr<MeshSceneNode> &right) {
return left->distanceToCamera() > right->distanceToCamera();
});
}
void SceneGraph::render() const {
for (auto &node : _opaqueModels) {
for (auto &node : _opaqueMeshes) {
node->model()->render(*node->modelNode(), node->transform());
}
for (auto &node : _transparentModels) {
for (auto &node : _transparentMeshes) {
node->model()->render(*node->modelNode(), node->transform());
}
AABBMesh &aabb = TheAABBMesh;

View file

@ -23,7 +23,7 @@
#include "glm/vec3.hpp"
#include "aabbnode.h"
#include "modelnode.h"
#include "meshnode.h"
namespace reone {
@ -34,14 +34,14 @@ public:
SceneGraph() = default;
void clear();
void add(const std::shared_ptr<ModelSceneNode> &node);
void add(const std::shared_ptr<MeshSceneNode> &node);
void add(const std::shared_ptr<AABBSceneNode> &node);
void prepare(const glm::vec3 &cameraPosition);
void render() const;
private:
std::vector<std::shared_ptr<ModelSceneNode>> _opaqueModels;
std::vector<std::shared_ptr<ModelSceneNode>> _transparentModels;
std::vector<std::shared_ptr<MeshSceneNode>> _opaqueMeshes;
std::vector<std::shared_ptr<MeshSceneNode>> _transparentMeshes;
std::vector<std::shared_ptr<AABBSceneNode>> _aabbNodes;
SceneGraph(const SceneGraph &) = delete;