Simplify filenames in scene/node

This commit is contained in:
Vsevolod Kremianskii 2021-06-14 11:44:53 +07:00
parent afdd80f3b3
commit b4432595b4
40 changed files with 428 additions and 429 deletions

View file

@ -308,14 +308,14 @@ target_precompile_headers(libvideo PRIVATE src/engine/pch.h)
set(SCENE_HEADERS
src/engine/scene/animeventlistener.h
src/engine/scene/animproperties.h
src/engine/scene/node/cameranode.h
src/engine/scene/node/dummynode.h
src/engine/scene/node/emitternode.h
src/engine/scene/node/grassnode.h
src/engine/scene/node/lightnode.h
src/engine/scene/node/meshnode.h
src/engine/scene/node/camera.h
src/engine/scene/node/dummy.h
src/engine/scene/node/emitter.h
src/engine/scene/node/grass.h
src/engine/scene/node/light.h
src/engine/scene/node/mesh.h
src/engine/scene/node/model.h
src/engine/scene/node/modelnode.h
src/engine/scene/node/modelnodescenenode.h
src/engine/scene/node/scenenode.h
src/engine/scene/nodeelement.h
src/engine/scene/pipeline/control.h
@ -325,14 +325,14 @@ set(SCENE_HEADERS
src/engine/scene/types.h)
set(SCENE_SOURCES
src/engine/scene/node/cameranode.cpp
src/engine/scene/node/emitternode.cpp
src/engine/scene/node/grassnode.cpp
src/engine/scene/node/lightnode.cpp
src/engine/scene/node/meshnode.cpp
src/engine/scene/node/camera.cpp
src/engine/scene/node/emitter.cpp
src/engine/scene/node/grass.cpp
src/engine/scene/node/light.cpp
src/engine/scene/node/mesh.cpp
src/engine/scene/node/model.cpp
src/engine/scene/node/model_animation.cpp
src/engine/scene/node/modelnode.cpp
src/engine/scene/node/modelnode_animation.cpp
src/engine/scene/node/modelnodescenenode.cpp
src/engine/scene/node/scenenode.cpp
src/engine/scene/pipeline/control.cpp
src/engine/scene/pipeline/world.cpp

View file

@ -18,8 +18,8 @@
#include "animated.h"
#include "../../graphics/types.h"
#include "../../scene/node/cameranode.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/camera.h"
#include "../../scene/node/model.h"
using namespace std;

View file

@ -18,7 +18,7 @@
#include "dialog.h"
#include "../../graphics/types.h"
#include "../../scene/node/cameranode.h"
#include "../../scene/node/camera.h"
using namespace std;

View file

@ -18,7 +18,7 @@
#include "firstperson.h"
#include "../../graphics/types.h"
#include "../../scene/node/cameranode.h"
#include "../../scene/node/camera.h"
using namespace std;

View file

@ -17,7 +17,7 @@
#include "thirdperson.h"
#include "../../scene/node/cameranode.h"
#include "../../scene/node/camera.h"
#include "../game.h"

View file

@ -17,7 +17,7 @@
#pragma once
#include "../../../scene/node/modelnode.h"
#include "../../../scene/node/model.h"
#include "../../../scene/scenegraph.h"
#include "../../character.h"

View file

@ -23,7 +23,7 @@
#include "../../../graphics/model/models.h"
#include "../../../graphics/texture/textures.h"
#include "../../../resource/resources.h"
#include "../../../scene/node/modelnode.h"
#include "../../../scene/node/model.h"
#include "../../game.h"
#include "../../portrait.h"

View file

@ -17,7 +17,7 @@
#pragma once
#include "../../../scene/node/modelnode.h"
#include "../../../scene/node/model.h"
#include "../../portrait.h"

View file

@ -21,7 +21,7 @@
#include "../../../gui/control/label.h"
#include "../../../gui/control/listbox.h"
#include "../../../gui/control/slider.h"
#include "../../../scene/node/modelnode.h"
#include "../../../scene/node/model.h"
#include "../gui.h"

View file

@ -21,7 +21,7 @@
#include "../../gui/control/label.h"
#include "../../gui/control/listbox.h"
#include "../../resource/types.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/model.h"
#include "../../scene/scenegraph.h"
#include "../types.h"

View file

@ -30,7 +30,7 @@
#include "../../resource/format/visreader.h"
#include "../../resource/resources.h"
#include "../../resource/strings.h"
#include "../../scene/node/grassnode.h"
#include "../../scene/node/grass.h"
#include "../../scene/types.h"
#include "../enginetype/location.h"

View file

@ -24,7 +24,7 @@
#include "../../resource/format/gffreader.h"
#include "../../resource/types.h"
#include "../../scene/animeventlistener.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/model.h"
#include "../../script/types.h"
#include "../d20/attributes.h"

View file

@ -22,7 +22,7 @@
#include "../../graphics/walkmesh/walkmeshes.h"
#include "../../resource/resources.h"
#include "../../resource/strings.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/model.h"
#include "../../scene/types.h"
#include "../../script/scripts.h"

View file

@ -20,7 +20,7 @@
#include "../../graphics/model/models.h"
#include "../../graphics/walkmesh/walkmeshes.h"
#include "../../resource/resources.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/model.h"
#include "../../script/types.h"
#include "../game.h"

View file

@ -18,7 +18,7 @@
#pragma once
#include "../graphics/walkmesh/walkmesh.h"
#include "../scene/node/modelnode.h"
#include "../scene/node/model.h"
namespace reone {

View file

@ -21,7 +21,7 @@
#include "../../graphics/framebuffer.h"
#include "../../graphics/texture/texture.h"
#include "../../resource/format/gffreader.h"
#include "../../scene/node/modelnode.h"
#include "../../scene/node/model.h"
#include "../../scene/pipeline/control.h"
#include "../../scene/scenegraph.h"
#include "../types.h"

View file

@ -17,8 +17,8 @@
#include "scenebuilder.h"
#include "../scene/node/cameranode.h"
#include "../scene/node/meshnode.h"
#include "../scene/node/camera.h"
#include "../scene/node/mesh.h"
#include "../scene/scenegraph.h"
using namespace std;

View file

@ -20,7 +20,7 @@
#include "../graphics/options.h"
#include "../graphics/services.h"
#include "../scene/node/modelnode.h"
#include "../scene/node/model.h"
#include "../scene/scenegraph.h"
namespace reone {

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "cameranode.h"
#include "camera.h"
using namespace std;

View file

@ -17,7 +17,7 @@
#pragma once
#include "modelnodescenenode.h"
#include "modelnode.h"
namespace reone {

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "emitternode.h"
#include "emitter.h"
#include "../../common/guardutil.h"
#include "../../common/random.h"
@ -24,8 +24,7 @@
#include "../scenegraph.h"
#include "cameranode.h"
#include "modelnode.h"
#include "camera.h"
using namespace std;

View file

@ -23,7 +23,7 @@
#include "../nodeelement.h"
#include "modelnodescenenode.h"
#include "modelnode.h"
namespace reone {

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "grassnode.h"
#include "grass.h"
#include "../../common/guardutil.h"
#include "../../graphics/mesh/meshes.h"

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "lightnode.h"
#include "light.h"
#include "../../common/guardutil.h"
#include "../../graphics/mesh/meshes.h"
@ -24,7 +24,7 @@
#include "../scenegraph.h"
#include "cameranode.h"
#include "camera.h"
using namespace std;

View file

@ -19,7 +19,7 @@
#include "../../graphics/model/modelnode.h"
#include "modelnodescenenode.h"
#include "modelnode.h"
namespace reone {

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "meshnode.h"
#include "mesh.h"
#include "../../common/log.h"
#include "../../common/guardutil.h"
@ -24,9 +24,9 @@
#include "../scenegraph.h"
#include "cameranode.h"
#include "lightnode.h"
#include "modelnode.h"
#include "camera.h"
#include "light.h"
#include "model.h"
using namespace std;

View file

@ -17,7 +17,7 @@
#pragma once
#include "modelnodescenenode.h"
#include "modelnode.h"
#include "../../graphics/material.h"
#include "../../graphics/materials.h"

View file

@ -0,0 +1,190 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../../common/collectionutil.h"
#include "../../common/log.h"
#include "../../common/guardutil.h"
#include "../scenegraph.h"
#include "../types.h"
#include "emitter.h"
#include "light.h"
#include "mesh.h"
#include "model.h"
using namespace std;
using namespace reone::graphics;
namespace reone {
namespace scene {
ModelSceneNode::ModelSceneNode(
shared_ptr<Model> model,
ModelUsage usage,
SceneGraph *sceneGraph,
IAnimationEventListener *animEventListener
) :
SceneNode(model->name(), SceneNodeType::Model, sceneGraph),
_model(model),
_usage(usage),
_animEventListener(animEventListener) {
ensureNotNull(model, "model");
_volumetric = true;
buildNodeTree(_model->rootNode(), this);
computeAABB();
}
void ModelSceneNode::buildNodeTree(shared_ptr<ModelNode> node, SceneNode *parent) {
// Convert model node to scene node
shared_ptr<ModelNodeSceneNode> sceneNode;
if (node->isMesh()) {
sceneNode = newMeshSceneNode(node);
} else if (node->isLight()) {
sceneNode = newLightSceneNode(node);
} else if (node->isEmitter()) {
sceneNode = newEmitterSceneNode(node);
} else {
sceneNode = newDummySceneNode(node);
}
if (node->isSkinMesh()) {
// Reparent skin meshes to prevent animation being applied twice
glm::mat4 transform(node->parent()->absoluteTransform() * node->localTransform());
sceneNode->setLocalTransform(move(transform));
addChild(sceneNode);
} else {
sceneNode->setLocalTransform(node->localTransform());
parent->addChild(sceneNode);
}
_nodeByName.insert(make_pair(node->name(), sceneNode));
if (node->isReference()) {
auto model = make_shared<ModelSceneNode>(node->reference()->model, _usage, _sceneGraph, _animEventListener);
attach(node->name(), move(model));
}
for (auto &child : node->children()) {
buildNodeTree(child, sceneNode.get());
}
}
void ModelSceneNode::update(float dt) {
// Optimization: skip invisible models
if (!_visible) return;
SceneNode::update(dt);
updateAnimations(dt);
}
void ModelSceneNode::computeAABB() {
_aabb.reset();
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Mesh) {
shared_ptr<ModelNode> modelNode(node.second->modelNode());
AABB modelSpaceAABB(modelNode->mesh()->mesh->aabb() * modelNode->absoluteTransform());
_aabb.expand(modelSpaceAABB);
}
}
for (auto &attachment : _attachments) {
if (attachment.second->type() == SceneNodeType::Model) {
AABB modelSpaceAABB(attachment.second->aabb() * attachment.second->absoluteTransform() * _absTransformInv);
_aabb.expand(modelSpaceAABB);
}
}
}
unique_ptr<DummySceneNode> ModelSceneNode::newDummySceneNode(shared_ptr<ModelNode> node) const {
return make_unique<DummySceneNode>(node, _sceneGraph);
}
unique_ptr<MeshSceneNode> ModelSceneNode::newMeshSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<MeshSceneNode>(this, node, _sceneGraph);
}
unique_ptr<LightSceneNode> ModelSceneNode::newLightSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<LightSceneNode>(this, node, _sceneGraph);
}
unique_ptr<EmitterSceneNode> ModelSceneNode::newEmitterSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<EmitterSceneNode>(this, node, _sceneGraph);
}
void ModelSceneNode::signalEvent(const string &name) {
debug(boost::format("Model '%s': event '%s' signalled") % _model->name() % name, 3);
if (name == "detonate") {
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Emitter) {
static_pointer_cast<EmitterSceneNode>(node.second)->detonate();
}
}
} else if (_animEventListener) {
_animEventListener->onEventSignalled(name);
}
}
void ModelSceneNode::attach(const string &parentName, shared_ptr<SceneNode> node) {
auto maybeParent = _nodeByName.find(parentName);
if (maybeParent == _nodeByName.end()) return;
shared_ptr<ModelNodeSceneNode> parent(maybeParent->second);
parent->addChild(node);
_attachments.insert(make_pair(parentName, node));
computeAABB();
}
shared_ptr<ModelNodeSceneNode> ModelSceneNode::getNodeByName(const string &name) const {
return getFromLookupOrNull(_nodeByName, name);
}
shared_ptr<SceneNode> ModelSceneNode::getAttachment(const string &parentName) const {
auto parent = _model->getNodeByName(parentName);
return parent ? getFromLookupOrNull(_attachments, parent->name()) : nullptr;
}
void ModelSceneNode::setDiffuseTexture(shared_ptr<Texture> texture) {
for (auto &child : _children) {
if (child->type() == SceneNodeType::Mesh) {
static_pointer_cast<MeshSceneNode>(child)->setDiffuseTexture(texture);
}
}
}
void ModelSceneNode::setAppliedForce(glm::vec3 force) {
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Mesh) {
static_pointer_cast<MeshSceneNode>(node.second)->setAppliedForce(force);
}
}
for (auto &attachment : _attachments) {
if (attachment.second->type() == SceneNodeType::Model) {
static_pointer_cast<ModelSceneNode>(attachment.second)->setAppliedForce(force);
}
}
}
} // namespace scene
} // namespace reone

View file

@ -0,0 +1,160 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "../../graphics/lip/animation.h"
#include "../../graphics/model/model.h"
#include "../animeventlistener.h"
#include "../animproperties.h"
#include "../types.h"
#include "dummy.h"
#include "emitter.h"
#include "light.h"
#include "mesh.h"
namespace reone {
namespace scene {
constexpr float kDefaultDrawDistance = 1024.0f;
class ModelSceneNode : public SceneNode {
public:
ModelSceneNode(
std::shared_ptr<graphics::Model> model,
ModelUsage usage,
SceneGraph *sceneGraph,
IAnimationEventListener *animEventListener = nullptr);
void update(float dt) override;
void computeAABB();
void signalEvent(const std::string &name);
std::shared_ptr<ModelNodeSceneNode> getNodeByName(const std::string &name) const;
std::shared_ptr<graphics::Model> model() const { return _model; }
ModelUsage usage() const { return _usage; }
float drawDistance() const { return _drawDistance; }
void setDrawDistance(float distance) { _drawDistance = distance; }
void setDiffuseTexture(std::shared_ptr<graphics::Texture> texture);
void setAppliedForce(glm::vec3 force);
// Animation
void playAnimation(const std::string &name, AnimationProperties properties = AnimationProperties());
void playAnimation(std::shared_ptr<graphics::Animation> anim, std::shared_ptr<graphics::LipAnimation> lipAnim = nullptr, AnimationProperties properties = AnimationProperties());
bool isAnimationFinished() const;
void setInanimateNodes(std::set<std::string> nodes) { _inanimateNodes = std::move(nodes); }
// END Animation
// Attachments
void attach(const std::string &parentName, std::shared_ptr<SceneNode> node);
std::shared_ptr<SceneNode> getAttachment(const std::string &parentName) const;
// END Attachments
private:
enum class AnimationBlendMode {
Single,
Blend,
Overlay
};
struct AnimationStateFlags {
static constexpr int transform = 1;
static constexpr int alpha = 2;
static constexpr int selfIllumColor = 4;
};
struct AnimationState {
int flags { 0 };
glm::mat4 transform { 1.0f };
float alpha { 0.0f };
glm::vec3 selfIllumColor { 0.0f };
};
struct AnimationChannel {
std::shared_ptr<graphics::Animation> anim;
std::shared_ptr<graphics::LipAnimation> lipAnim;
AnimationProperties properties;
float time { 0.0f };
std::unordered_map<std::string, AnimationState> stateByName;
bool freeze { false }; /**< channel time is not to be updated */
bool transition { false }; /**< when computing states, use animation transition time as channel time */
bool finished { false }; /**< finished channels will be erased from the queue */
AnimationChannel(std::shared_ptr<graphics::Animation> anim, std::shared_ptr<graphics::LipAnimation> lipAnim, AnimationProperties properties) :
anim(std::move(anim)),
lipAnim(std::move(lipAnim)),
properties(std::move(properties)) {
}
};
std::shared_ptr<graphics::Model> _model;
ModelUsage _usage;
IAnimationEventListener *_animEventListener;
float _drawDistance { kDefaultDrawDistance };
// Lookups
std::unordered_map<std::string, std::shared_ptr<ModelNodeSceneNode>> _nodeByName;
std::unordered_map<std::string, std::shared_ptr<SceneNode>> _attachments;
// END Lookups
// Animation
std::deque<AnimationChannel> _animChannels;
AnimationBlendMode _animBlendMode { AnimationBlendMode::Single };
std::set<std::string> _inanimateNodes; /**< names of nodes that are not to be animated */
// END Animation
void buildNodeTree(std::shared_ptr<graphics::ModelNode> node, SceneNode *parent);
std::unique_ptr<DummySceneNode> newDummySceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<MeshSceneNode> newMeshSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<LightSceneNode> newLightSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<EmitterSceneNode> newEmitterSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
// Animation
void updateAnimations(float dt);
void updateAnimationChannel(AnimationChannel &channel, float dt);
void computeAnimationStates(AnimationChannel &channel, float time, const graphics::ModelNode &modelNode);
void applyAnimationStates(const graphics::ModelNode &modelNode);
void computeBoneTransforms();
static AnimationBlendMode getAnimationBlendMode(int flags);
// END Animation
};
} // namespace scene
} // namespace reone

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "modelnode.h"
#include "model.h"
#include "../../common/collectionutil.h"

View file

@ -15,18 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../../common/collectionutil.h"
#include "../../common/log.h"
#include "../../common/guardutil.h"
#include "../scenegraph.h"
#include "../types.h"
#include "emitternode.h"
#include "lightnode.h"
#include "meshnode.h"
#include "modelnode.h"
#include "../../common/guardutil.h"
using namespace std;
using namespace reone::graphics;
@ -35,154 +27,11 @@ namespace reone {
namespace scene {
ModelSceneNode::ModelSceneNode(
shared_ptr<Model> model,
ModelUsage usage,
SceneGraph *sceneGraph,
IAnimationEventListener *animEventListener
) :
SceneNode(model->name(), SceneNodeType::Model, sceneGraph),
_model(model),
_usage(usage),
_animEventListener(animEventListener) {
ModelNodeSceneNode::ModelNodeSceneNode(shared_ptr<ModelNode> modelNode, SceneNodeType type, SceneGraph *sceneGraph) :
SceneNode(modelNode->name(), type, sceneGraph),
_modelNode(modelNode) {
ensureNotNull(model, "model");
_volumetric = true;
buildNodeTree(_model->rootNode(), this);
computeAABB();
}
void ModelSceneNode::buildNodeTree(shared_ptr<ModelNode> node, SceneNode *parent) {
// Convert model node to scene node
shared_ptr<ModelNodeSceneNode> sceneNode;
if (node->isMesh()) {
sceneNode = newMeshSceneNode(node);
} else if (node->isLight()) {
sceneNode = newLightSceneNode(node);
} else if (node->isEmitter()) {
sceneNode = newEmitterSceneNode(node);
} else {
sceneNode = newDummySceneNode(node);
}
if (node->isSkinMesh()) {
// Reparent skin meshes to prevent animation being applied twice
glm::mat4 transform(node->parent()->absoluteTransform() * node->localTransform());
sceneNode->setLocalTransform(move(transform));
addChild(sceneNode);
} else {
sceneNode->setLocalTransform(node->localTransform());
parent->addChild(sceneNode);
}
_nodeByName.insert(make_pair(node->name(), sceneNode));
if (node->isReference()) {
auto model = make_shared<ModelSceneNode>(node->reference()->model, _usage, _sceneGraph, _animEventListener);
attach(node->name(), move(model));
}
for (auto &child : node->children()) {
buildNodeTree(child, sceneNode.get());
}
}
void ModelSceneNode::update(float dt) {
// Optimization: skip invisible models
if (!_visible) return;
SceneNode::update(dt);
updateAnimations(dt);
}
void ModelSceneNode::computeAABB() {
_aabb.reset();
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Mesh) {
shared_ptr<ModelNode> modelNode(node.second->modelNode());
AABB modelSpaceAABB(modelNode->mesh()->mesh->aabb() * modelNode->absoluteTransform());
_aabb.expand(modelSpaceAABB);
}
}
for (auto &attachment : _attachments) {
if (attachment.second->type() == SceneNodeType::Model) {
AABB modelSpaceAABB(attachment.second->aabb() * attachment.second->absoluteTransform() * _absTransformInv);
_aabb.expand(modelSpaceAABB);
}
}
}
unique_ptr<DummySceneNode> ModelSceneNode::newDummySceneNode(shared_ptr<ModelNode> node) const {
return make_unique<DummySceneNode>(node, _sceneGraph);
}
unique_ptr<MeshSceneNode> ModelSceneNode::newMeshSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<MeshSceneNode>(this, node, _sceneGraph);
}
unique_ptr<LightSceneNode> ModelSceneNode::newLightSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<LightSceneNode>(this, node, _sceneGraph);
}
unique_ptr<EmitterSceneNode> ModelSceneNode::newEmitterSceneNode(shared_ptr<ModelNode> node) const {
return make_unique<EmitterSceneNode>(this, node, _sceneGraph);
}
void ModelSceneNode::signalEvent(const string &name) {
debug(boost::format("Model '%s': event '%s' signalled") % _model->name() % name, 3);
if (name == "detonate") {
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Emitter) {
static_pointer_cast<EmitterSceneNode>(node.second)->detonate();
}
}
} else if (_animEventListener) {
_animEventListener->onEventSignalled(name);
}
}
void ModelSceneNode::attach(const string &parentName, shared_ptr<SceneNode> node) {
auto maybeParent = _nodeByName.find(parentName);
if (maybeParent == _nodeByName.end()) return;
shared_ptr<ModelNodeSceneNode> parent(maybeParent->second);
parent->addChild(node);
_attachments.insert(make_pair(parentName, node));
computeAABB();
}
shared_ptr<ModelNodeSceneNode> ModelSceneNode::getNodeByName(const string &name) const {
return getFromLookupOrNull(_nodeByName, name);
}
shared_ptr<SceneNode> ModelSceneNode::getAttachment(const string &parentName) const {
auto parent = _model->getNodeByName(parentName);
return parent ? getFromLookupOrNull(_attachments, parent->name()) : nullptr;
}
void ModelSceneNode::setDiffuseTexture(shared_ptr<Texture> texture) {
for (auto &child : _children) {
if (child->type() == SceneNodeType::Mesh) {
static_pointer_cast<MeshSceneNode>(child)->setDiffuseTexture(texture);
}
}
}
void ModelSceneNode::setAppliedForce(glm::vec3 force) {
for (auto &node : _nodeByName) {
if (node.second->type() == SceneNodeType::Mesh) {
static_pointer_cast<MeshSceneNode>(node.second)->setAppliedForce(force);
}
}
for (auto &attachment : _attachments) {
if (attachment.second->type() == SceneNodeType::Model) {
static_pointer_cast<ModelSceneNode>(attachment.second)->setAppliedForce(force);
}
}
ensureNotNull(modelNode, "modelNode");
}
} // namespace scene

View file

@ -17,142 +17,28 @@
#pragma once
#include "../../graphics/lip/animation.h"
#include "../../graphics/model/model.h"
#include "../../graphics/model/modelnode.h"
#include "../animeventlistener.h"
#include "../animproperties.h"
#include "../types.h"
#include "dummynode.h"
#include "emitternode.h"
#include "lightnode.h"
#include "meshnode.h"
#include "scenenode.h"
namespace reone {
namespace scene {
constexpr float kDefaultDrawDistance = 1024.0f;
class ModelSceneNode : public SceneNode {
class ModelNodeSceneNode : public SceneNode {
public:
ModelSceneNode(
std::shared_ptr<graphics::Model> model,
ModelUsage usage,
SceneGraph *sceneGraph,
IAnimationEventListener *animEventListener = nullptr);
std::shared_ptr<graphics::ModelNode> modelNode() const { return _modelNode; }
const glm::mat4 &boneTransform() const { return _boneTransform; }
void update(float dt) override;
void setBoneTransform(glm::mat4 transform) { _boneTransform = std::move(transform); }
void computeAABB();
void signalEvent(const std::string &name);
protected:
std::shared_ptr<graphics::ModelNode> _modelNode;
std::shared_ptr<ModelNodeSceneNode> getNodeByName(const std::string &name) const;
std::shared_ptr<graphics::Model> model() const { return _model; }
ModelUsage usage() const { return _usage; }
float drawDistance() const { return _drawDistance; }
void setDrawDistance(float distance) { _drawDistance = distance; }
void setDiffuseTexture(std::shared_ptr<graphics::Texture> texture);
void setAppliedForce(glm::vec3 force);
// Animation
void playAnimation(const std::string &name, AnimationProperties properties = AnimationProperties());
void playAnimation(std::shared_ptr<graphics::Animation> anim, std::shared_ptr<graphics::LipAnimation> lipAnim = nullptr, AnimationProperties properties = AnimationProperties());
bool isAnimationFinished() const;
void setInanimateNodes(std::set<std::string> nodes) { _inanimateNodes = std::move(nodes); }
// END Animation
// Attachments
void attach(const std::string &parentName, std::shared_ptr<SceneNode> node);
std::shared_ptr<SceneNode> getAttachment(const std::string &parentName) const;
// END Attachments
ModelNodeSceneNode(std::shared_ptr<graphics::ModelNode> modelNode, SceneNodeType type, SceneGraph *sceneGraph);
private:
enum class AnimationBlendMode {
Single,
Blend,
Overlay
};
struct AnimationStateFlags {
static constexpr int transform = 1;
static constexpr int alpha = 2;
static constexpr int selfIllumColor = 4;
};
struct AnimationState {
int flags { 0 };
glm::mat4 transform { 1.0f };
float alpha { 0.0f };
glm::vec3 selfIllumColor { 0.0f };
};
struct AnimationChannel {
std::shared_ptr<graphics::Animation> anim;
std::shared_ptr<graphics::LipAnimation> lipAnim;
AnimationProperties properties;
float time { 0.0f };
std::unordered_map<std::string, AnimationState> stateByName;
bool freeze { false }; /**< channel time is not to be updated */
bool transition { false }; /**< when computing states, use animation transition time as channel time */
bool finished { false }; /**< finished channels will be erased from the queue */
AnimationChannel(std::shared_ptr<graphics::Animation> anim, std::shared_ptr<graphics::LipAnimation> lipAnim, AnimationProperties properties) :
anim(std::move(anim)),
lipAnim(std::move(lipAnim)),
properties(std::move(properties)) {
}
};
std::shared_ptr<graphics::Model> _model;
ModelUsage _usage;
IAnimationEventListener *_animEventListener;
float _drawDistance { kDefaultDrawDistance };
// Lookups
std::unordered_map<std::string, std::shared_ptr<ModelNodeSceneNode>> _nodeByName;
std::unordered_map<std::string, std::shared_ptr<SceneNode>> _attachments;
// END Lookups
// Animation
std::deque<AnimationChannel> _animChannels;
AnimationBlendMode _animBlendMode { AnimationBlendMode::Single };
std::set<std::string> _inanimateNodes; /**< names of nodes that are not to be animated */
// END Animation
void buildNodeTree(std::shared_ptr<graphics::ModelNode> node, SceneNode *parent);
std::unique_ptr<DummySceneNode> newDummySceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<MeshSceneNode> newMeshSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<LightSceneNode> newLightSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
std::unique_ptr<EmitterSceneNode> newEmitterSceneNode(std::shared_ptr<graphics::ModelNode> node) const;
// Animation
void updateAnimations(float dt);
void updateAnimationChannel(AnimationChannel &channel, float dt);
void computeAnimationStates(AnimationChannel &channel, float time, const graphics::ModelNode &modelNode);
void applyAnimationStates(const graphics::ModelNode &modelNode);
void computeBoneTransforms();
static AnimationBlendMode getAnimationBlendMode(int flags);
// END Animation
glm::mat4 _boneTransform { 1.0f }; /**< model space transform relative to the rest pose */
};
} // namespace scene

View file

@ -1,39 +0,0 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "modelnodescenenode.h"
#include "../../common/guardutil.h"
using namespace std;
using namespace reone::graphics;
namespace reone {
namespace scene {
ModelNodeSceneNode::ModelNodeSceneNode(shared_ptr<ModelNode> modelNode, SceneNodeType type, SceneGraph *sceneGraph) :
SceneNode(modelNode->name(), type, sceneGraph),
_modelNode(modelNode) {
ensureNotNull(modelNode, "modelNode");
}
} // namespace scene
} // namespace reone

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2020-2021 The reone project contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "../../graphics/model/modelnode.h"
#include "scenenode.h"
namespace reone {
namespace scene {
class ModelNodeSceneNode : public SceneNode {
public:
std::shared_ptr<graphics::ModelNode> modelNode() const { return _modelNode; }
const glm::mat4 &boneTransform() const { return _boneTransform; }
void setBoneTransform(glm::mat4 transform) { _boneTransform = std::move(transform); }
protected:
std::shared_ptr<graphics::ModelNode> _modelNode;
ModelNodeSceneNode(std::shared_ptr<graphics::ModelNode> modelNode, SceneNodeType type, SceneGraph *sceneGraph);
private:
glm::mat4 _boneTransform { 1.0f }; /**< model space transform relative to the rest pose */
};
} // namespace scene
} // namespace reone

View file

@ -22,7 +22,7 @@
#include "../../graphics/texture/textures.h"
#include "../../graphics/texture/textureutil.h"
#include "../node/cameranode.h"
#include "../node/camera.h"
#include "../scenegraph.h"
using namespace std;

View file

@ -25,8 +25,8 @@
#include "../../graphics/texture/tgawriter.h"
#include "../../graphics/window.h"
#include "../node/cameranode.h"
#include "../node/lightnode.h"
#include "../node/camera.h"
#include "../node/light.h"
#include "../scenegraph.h"
using namespace std;

View file

@ -19,12 +19,12 @@
#include "../graphics/mesh/meshes.h"
#include "node/cameranode.h"
#include "node/emitternode.h"
#include "node/grassnode.h"
#include "node/lightnode.h"
#include "node/meshnode.h"
#include "node/modelnode.h"
#include "node/camera.h"
#include "node/emitter.h"
#include "node/grass.h"
#include "node/light.h"
#include "node/mesh.h"
#include "node/model.h"
using namespace std;

View file

@ -20,11 +20,11 @@
#include "../graphics/options.h"
#include "../graphics/services.h"
#include "node/cameranode.h"
#include "node/emitternode.h"
#include "node/grassnode.h"
#include "node/lightnode.h"
#include "node/meshnode.h"
#include "node/camera.h"
#include "node/emitter.h"
#include "node/grass.h"
#include "node/light.h"
#include "node/mesh.h"
namespace reone {