|
|
|
@@ -4,8 +4,8 @@
|
|
|
|
|
|
|
|
|
|
#include "AnimGraphResource.h"
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "3rdparty/json/json.hpp"
|
|
|
|
|
|
|
|
|
@@ -28,7 +28,8 @@ json sSocketToJson(const Socket& socket) {
|
|
|
|
|
result["name"] = socket.m_name;
|
|
|
|
|
result["type"] = sSocketTypeToStr(socket.m_type);
|
|
|
|
|
|
|
|
|
|
if (socket.m_type == SocketType::SocketTypeString && socket.m_value_string.size() > 0) {
|
|
|
|
|
if (socket.m_type == SocketType::SocketTypeString
|
|
|
|
|
&& socket.m_value_string.size() > 0) {
|
|
|
|
|
result["value"] = socket.m_value_string;
|
|
|
|
|
} else if (socket.m_value.flag) {
|
|
|
|
|
if (socket.m_type == SocketType::SocketTypeBool) {
|
|
|
|
@@ -141,7 +142,7 @@ json sAnimGraphNodeToJson(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!socket_connected) {
|
|
|
|
|
result["inputs"][socket.m_name] = sSocketToJson(socket);
|
|
|
|
|
result["inputs"].push_back(sSocketToJson(socket));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -154,7 +155,7 @@ json sAnimGraphNodeToJson(
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnimNodeResource sAnimGraphNodeFromJson(const json& json_node) {
|
|
|
|
|
AnimNodeResource sAnimGraphNodeFromJson(const json& json_node, int node_index) {
|
|
|
|
|
AnimNodeResource result;
|
|
|
|
|
|
|
|
|
|
result.m_name = json_node["name"];
|
|
|
|
@@ -172,11 +173,18 @@ AnimNodeResource sAnimGraphNodeFromJson(const json& json_node) {
|
|
|
|
|
property = sJsonToSocket(json_node["properties"][property.m_name]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0, n = result.m_socket_accessor->m_inputs.size(); j < n;
|
|
|
|
|
j++) {
|
|
|
|
|
Socket& input = result.m_socket_accessor->m_inputs[j];
|
|
|
|
|
if (json_node.contains("inputs") && json_node["inputs"].contains(input.m_name)) {
|
|
|
|
|
input = sJsonToSocket(json_node["inputs"][input.m_name]);
|
|
|
|
|
if (node_index != 0 && node_index != 1 && json_node.contains("inputs")) {
|
|
|
|
|
for (size_t j = 0, n = json_node["inputs"].size(); j < n; j++) {
|
|
|
|
|
assert(json_node["inputs"][j].contains("name"));
|
|
|
|
|
std::string input_name = json_node["inputs"][j]["name"];
|
|
|
|
|
Socket* input_socket =
|
|
|
|
|
result.m_socket_accessor->GetInputSocket(input_name.c_str());
|
|
|
|
|
if (input_socket == nullptr) {
|
|
|
|
|
std::cerr << "Could not find input socket with name " << input_name
|
|
|
|
|
<< " for node type " << result.m_type_name << std::endl;
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
*input_socket = sJsonToSocket(json_node["inputs"][j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -307,7 +315,7 @@ bool AnimGraphResource::loadFromFile(const char* filename) {
|
|
|
|
|
m_name = json_data["name"];
|
|
|
|
|
|
|
|
|
|
// Load nodes
|
|
|
|
|
for (size_t i = 0; i < json_data["nodes"].size(); i++) {
|
|
|
|
|
for (size_t i = 0, n = json_data["nodes"].size(); i < n; i++) {
|
|
|
|
|
const json& json_node = json_data["nodes"][i];
|
|
|
|
|
if (json_node["type"] != "AnimNodeResource") {
|
|
|
|
|
std::cerr
|
|
|
|
@@ -316,20 +324,20 @@ bool AnimGraphResource::loadFromFile(const char* filename) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnimNodeResource node = sAnimGraphNodeFromJson(json_node);
|
|
|
|
|
AnimNodeResource node = sAnimGraphNodeFromJson(json_node, i);
|
|
|
|
|
m_nodes.push_back(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Setup graph inputs and outputs
|
|
|
|
|
const json& graph_outputs = json_data["nodes"][0]["inputs"];
|
|
|
|
|
for (size_t i = 0; i < graph_outputs.size(); i++) {
|
|
|
|
|
for (size_t i = 0, n = graph_outputs.size(); i < n; i++) {
|
|
|
|
|
AnimNodeResource& graph_node = m_nodes[0];
|
|
|
|
|
graph_node.m_socket_accessor->m_inputs.push_back(
|
|
|
|
|
sJsonToSocket(graph_outputs[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const json& graph_inputs = json_data["nodes"][1]["outputs"];
|
|
|
|
|
for (size_t i = 0; i < graph_inputs.size(); i++) {
|
|
|
|
|
for (size_t i = 0, n = graph_inputs.size(); i < n; i++) {
|
|
|
|
|
AnimNodeResource& graph_node = m_nodes[1];
|
|
|
|
|
graph_node.m_socket_accessor->m_outputs.push_back(
|
|
|
|
|
sJsonToSocket(graph_inputs[i]));
|
|
|
|
@@ -387,7 +395,9 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
|
|
|
|
m_nodes[1].m_socket_accessor->m_outputs;
|
|
|
|
|
instance.m_node_descriptor->m_inputs = m_nodes[0].m_socket_accessor->m_inputs;
|
|
|
|
|
|
|
|
|
|
// inputs
|
|
|
|
|
//
|
|
|
|
|
// graph inputs
|
|
|
|
|
//
|
|
|
|
|
int input_block_size = 0;
|
|
|
|
|
std::vector<Socket>& graph_inputs = instance.getGraphInputs();
|
|
|
|
|
for (int i = 0; i < graph_inputs.size(); i++) {
|
|
|
|
@@ -408,7 +418,9 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
|
|
|
|
input_block_offset += sizeof(void*);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// outputs
|
|
|
|
|
//
|
|
|
|
|
// graph outputs
|
|
|
|
|
//
|
|
|
|
|
int output_block_size = 0;
|
|
|
|
|
std::vector<Socket>& graph_outputs = instance.getGraphOutputs();
|
|
|
|
|
for (int i = 0; i < graph_outputs.size(); i++) {
|
|
|
|
@@ -500,6 +512,41 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
|
|
|
|
connection_data_offset += source_socket->m_type_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// const node inputs
|
|
|
|
|
//
|
|
|
|
|
std::vector<Socket*> const_inputs =
|
|
|
|
|
getConstNodeInputs(instance, instance_node_descriptors);
|
|
|
|
|
int const_node_inputs_buffer_size = 0;
|
|
|
|
|
for (int i = 0, n = const_inputs.size(); i < n; i++) {
|
|
|
|
|
if (const_inputs[i]->m_type == SocketType::SocketTypeString) {
|
|
|
|
|
// TODO: implement string const node input support
|
|
|
|
|
std::cerr << "Error: const inputs for strings not yet implemented!"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
const_node_inputs_buffer_size += const_inputs[i]->m_type_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (const_node_inputs_buffer_size > 0) {
|
|
|
|
|
instance.m_const_node_inputs = new char[const_node_inputs_buffer_size];
|
|
|
|
|
memset(instance.m_const_node_inputs, '\0', const_node_inputs_buffer_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int const_input_buffer_offset = 0;
|
|
|
|
|
for (int i = 0, n = const_inputs.size(); i < n; i++) {
|
|
|
|
|
Socket* const_input = const_inputs[i];
|
|
|
|
|
|
|
|
|
|
// TODO: implement string const node input support
|
|
|
|
|
assert(const_input->m_type != SocketType::SocketTypeString);
|
|
|
|
|
|
|
|
|
|
*const_input->m_reference.ptr_ptr =
|
|
|
|
|
&instance.m_const_node_inputs[const_input_buffer_offset];
|
|
|
|
|
memcpy (*const_input->m_reference.ptr_ptr, &const_input->m_value, const_inputs[i]->m_type_size);
|
|
|
|
|
|
|
|
|
|
const_input_buffer_offset += const_inputs[i]->m_type_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_nodes.size(); i++) {
|
|
|
|
|
delete instance_node_descriptors[i];
|
|
|
|
|
}
|
|
|
|
@@ -554,3 +601,24 @@ void AnimGraphResource::setRuntimeNodeProperties(AnimGraph& instance) const {
|
|
|
|
|
delete node_instance_accessor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<Socket*> AnimGraphResource::getConstNodeInputs(
|
|
|
|
|
AnimGraph& instance,
|
|
|
|
|
std::vector<NodeDescriptorBase*>& instance_node_descriptors) const {
|
|
|
|
|
std::vector<Socket*> result;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_nodes.size(); i++) {
|
|
|
|
|
for (int j = 0, num_inputs = instance_node_descriptors[i]->m_inputs.size();
|
|
|
|
|
j < num_inputs;
|
|
|
|
|
j++) {
|
|
|
|
|
Socket& input = instance_node_descriptors[i]->m_inputs[j];
|
|
|
|
|
|
|
|
|
|
if (*input.m_reference.ptr_ptr == nullptr) {
|
|
|
|
|
memcpy(&input.m_value, &m_nodes[i].m_socket_accessor->m_inputs[j].m_value, sizeof(Socket::SocketValue));
|
|
|
|
|
result.push_back(&input);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|