Evaluation of very simple graphs works.

This commit is contained in:
Martin Felis
2023-03-28 22:00:58 +02:00
parent e38c0b4934
commit 08283d9bcf
7 changed files with 94 additions and 12 deletions
+22
View File
@@ -49,6 +49,27 @@ struct AnimGraph {
}
}
}
m_node_input_connections.clear();
if (m_node_output_connections.size() > 0) {
std::vector<AnimGraphConnection>& graph_inputs =
m_node_output_connections[0];
for (size_t i = 0, n = graph_inputs.size(); i < n; i++) {
AnimGraphConnection& connection = graph_inputs[i];
if (connection.m_target_socket.m_type
== SocketType::SocketTypeAnimation) {
AnimData* graph_anim_output = static_cast<AnimData*>(
connection.m_target_socket.m_reference.ptr);
assert(graph_anim_output != nullptr);
// we have to explicitly call the destructor as the AnimData* was
// initialized using a placement new operator.
graph_anim_output->m_local_matrices.vector::~vector();
}
}
}
m_node_output_connections.clear();
delete[] m_input_buffer;
delete[] m_output_buffer;
@@ -56,6 +77,7 @@ struct AnimGraph {
for (int i = 0; i < m_nodes.size(); i++) {
delete m_nodes[i];
}
m_nodes.clear();
delete m_socket_accessor;
}
+3 -3
View File
@@ -416,10 +416,10 @@ inline void NodeSocketAccessorBase::SetSocketValue<const bool&>(
}
template <>
inline void NodeSocketAccessorBase::SetSocketValue<const float&>(
inline void NodeSocketAccessorBase::SetSocketValue<float>(
Socket* socket,
const float& value) {
socket->m_value.float_value = value;
float value) {
*static_cast<float*>(socket->m_reference.ptr) = value;
}
template <>
+5 -1
View File
@@ -85,7 +85,7 @@ void AnimGraphEditorRenderSidebar(
if (property.m_type == SocketType::SocketTypeFloat) {
ImGui::SliderFloat(
property.m_name.c_str(),
reinterpret_cast<float*>(property.m_reference.ptr),
reinterpret_cast<float*>(&property.m_value.float_value),
-100.f,
100.f);
} else if (property.m_type == SocketType::SocketTypeBool) {
@@ -219,6 +219,10 @@ void AnimGraphEditorUpdate() {
node_type_name = "MathFloatToVec3Node";
}
if (ImGui::MenuItem("ConstScalarNode")) {
node_type_name = "ConstScalarNode";
}
if (node_type_name != "") {
AnimNodeResource node_resource =
AnimNodeResourceFactory(node_type_name);
+2
View File
@@ -65,6 +65,8 @@ bool AnimSamplerNode::Init(AnimGraphContext& context) {
return false;
}
archive >> *m_animation;
context.m_animation_map[m_filename] = m_animation;
}
+30 -1
View File
@@ -197,6 +197,11 @@ struct AnimSamplerNode : public AnimNode {
virtual ~AnimSamplerNode();
virtual bool Init(AnimGraphContext& context) override;
void UpdateTime(float time_last, float time_now) override {
m_time_last = time_last;
m_time_now = fmodf(time_last + (time_now - time_last), m_animation->duration());
m_state = AnimNodeEvalState::TimeUpdated;
}
virtual void Evaluate(AnimGraphContext& context) override;
};
@@ -210,6 +215,27 @@ struct NodeSocketAccessor<AnimSamplerNode> : public NodeSocketAccessorBase {
}
};
//
// ConstScalarNode
//
struct ConstScalarNode : public AnimNode {
float* o_value = nullptr;
float value = 0.f;
virtual void Evaluate(AnimGraphContext& context){
*o_value = value;
};
};
template <>
struct NodeSocketAccessor<ConstScalarNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
ConstScalarNode* node = dynamic_cast<ConstScalarNode*>(node_);
RegisterOutput("ScalarOutput", &node->o_value);
RegisterProperty("ScalarValue", &node->value);
}
};
//
// MathAddNode
//
@@ -236,7 +262,6 @@ struct NodeSocketAccessor<MathAddNode> : public NodeSocketAccessorBase {
}
};
//
// MathFloatToVec3Node
//
@@ -282,6 +307,8 @@ static inline AnimNode* AnimNodeFactory(const std::string& name) {
result = new MathAddNode;
} else if (name == "MathFloatToVec3Node") {
result = new MathFloatToVec3Node;
} else if (name == "ConstScalarNode") {
result = new ConstScalarNode;
}
if (result != nullptr) {
@@ -308,6 +335,8 @@ static inline NodeSocketAccessorBase* AnimNodeAccessorFactory(
return new NodeSocketAccessor<MathAddNode>(node);
} else if (node_type_name == "MathFloatToVec3Node") {
return new NodeSocketAccessor<MathFloatToVec3Node>(node);
} else if (node_type_name == "ConstScalarNode") {
return new NodeSocketAccessor<ConstScalarNode>(node);
} else {
std::cerr << "Invalid node type name " << node_type_name << "."
<< std::endl;
+1 -1
View File
@@ -534,7 +534,7 @@ void AnimGraphResource::setRuntimeNodeProperties(AnimGraph& instance) const {
property.m_value.flag);
break;
case SocketType::SocketTypeFloat:
node_instance_accessor->SetPropertyReferenceValue(
node_instance_accessor->SetPropertyValue(
name,
property.m_value.float_value);
break;