mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
XML visitor for session saving (with toolkit for GLM saving to XML)
This commit is contained in:
@@ -219,15 +219,16 @@ set(VMIX_SRCS
|
|||||||
ImageShader.cpp
|
ImageShader.cpp
|
||||||
Scene.cpp
|
Scene.cpp
|
||||||
Primitives.cpp
|
Primitives.cpp
|
||||||
Visitor.cpp
|
SessionVisitor.cpp
|
||||||
Settings.cpp
|
Settings.cpp
|
||||||
Resource.cpp
|
Resource.cpp
|
||||||
FileDialog.cpp
|
FileDialog.cpp
|
||||||
ImGuiToolkit.cpp
|
|
||||||
GstToolkit.cpp
|
|
||||||
MediaPlayer.cpp
|
MediaPlayer.cpp
|
||||||
RenderingManager.cpp
|
RenderingManager.cpp
|
||||||
UserInterfaceManager.cpp
|
UserInterfaceManager.cpp
|
||||||
|
ImGuiToolkit.cpp
|
||||||
|
GstToolkit.cpp
|
||||||
|
tinyxml2Toolkit.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(VMIX_RSC_FILES
|
set(VMIX_RSC_FILES
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Visitor.h"
|
#include "SessionVisitor.h"
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "Primitives.h"
|
#include "Primitives.h"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define XMLVISITOR_H
|
#define XMLVISITOR_H
|
||||||
|
|
||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
|
#include "tinyxml2Toolkit.h"
|
||||||
|
|
||||||
class SessionVisitor : public Visitor {
|
class SessionVisitor : public Visitor {
|
||||||
|
|
||||||
|
|||||||
207
Visitor.cpp
207
Visitor.cpp
@@ -1,207 +0,0 @@
|
|||||||
#include "Visitor.h"
|
|
||||||
#include "Log.h"
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "Primitives.h"
|
|
||||||
#include "MediaPlayer.h"
|
|
||||||
#include "GstToolkit.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <glm/ext/vector_float4.hpp>
|
|
||||||
#include <glm/ext/matrix_float4x4.hpp>
|
|
||||||
#include <glm/gtc/matrix_access.hpp>
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
|
||||||
#include <glm/gtx/string_cast.hpp>
|
|
||||||
|
|
||||||
#include <tinyxml2.h>
|
|
||||||
using namespace tinyxml2;
|
|
||||||
|
|
||||||
#ifndef XMLCheckResult
|
|
||||||
#define XMLCheckResult(a_eResult) if (a_eResult != XML_SUCCESS) { Log::Warning("XML error %i\n", a_eResult); return; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SessionVisitor::SessionVisitor(std::string filename) : filename_(filename)
|
|
||||||
{
|
|
||||||
xmlDoc_ = new XMLDocument;
|
|
||||||
xmlCurrent_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(Group &n)
|
|
||||||
{
|
|
||||||
XMLElement *xmlParent = xmlCurrent_;
|
|
||||||
xmlCurrent_ = xmlDoc_->NewElement("Group");
|
|
||||||
visit( (Node&) n);
|
|
||||||
|
|
||||||
for (int node = 0; node < n.numChildren(); ++node)
|
|
||||||
{
|
|
||||||
Node *child = n.getChild(node);
|
|
||||||
|
|
||||||
Group *g = dynamic_cast<Group *>(child);
|
|
||||||
if (g != nullptr) {
|
|
||||||
g->accept(*this);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TexturedRectangle *tr = dynamic_cast<TexturedRectangle *>(child);
|
|
||||||
if (tr != nullptr) {
|
|
||||||
tr->accept(*this);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaRectangle *mr = dynamic_cast<MediaRectangle *>(child);
|
|
||||||
if (mr != nullptr) {
|
|
||||||
mr->accept(*this);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
LineStrip *ls = dynamic_cast<LineStrip *>(child);
|
|
||||||
if (ls != nullptr) {
|
|
||||||
ls->accept(*this);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Primitive *p = dynamic_cast<Primitive *>(child);
|
|
||||||
if (p != nullptr) {
|
|
||||||
p->accept(*this);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// recursive
|
|
||||||
xmlParent->InsertEndChild(xmlCurrent_);
|
|
||||||
xmlCurrent_ = xmlParent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec3 vector)
|
|
||||||
{
|
|
||||||
XMLElement *newelement = doc->NewElement( "vec3" );
|
|
||||||
newelement->SetAttribute("x", vector[0]);
|
|
||||||
newelement->SetAttribute("y", vector[1]);
|
|
||||||
newelement->SetAttribute("z", vector[2]);
|
|
||||||
return newelement;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec4 vector)
|
|
||||||
{
|
|
||||||
XMLElement *newelement = doc->NewElement( "vec4" );
|
|
||||||
newelement->SetAttribute("x", vector[0]);
|
|
||||||
newelement->SetAttribute("y", vector[1]);
|
|
||||||
newelement->SetAttribute("z", vector[2]);
|
|
||||||
newelement->SetAttribute("w", vector[3]);
|
|
||||||
return newelement;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::mat4 matrix)
|
|
||||||
{
|
|
||||||
XMLElement *newelement = doc->NewElement( "mat4" );
|
|
||||||
for (int r = 0 ; r < 4 ; r ++)
|
|
||||||
{
|
|
||||||
glm::vec4 row = glm::row(matrix, r);
|
|
||||||
XMLElement *rowxml = XMLElementGLM(doc, row);
|
|
||||||
rowxml->SetAttribute("row", r);
|
|
||||||
newelement->InsertEndChild(rowxml);
|
|
||||||
}
|
|
||||||
return newelement;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(Node &n)
|
|
||||||
{
|
|
||||||
XMLElement *transform = XMLElementGLM(xmlDoc_, n.transform_);
|
|
||||||
xmlCurrent_->InsertEndChild(transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(Primitive &n)
|
|
||||||
{
|
|
||||||
visit( (Node&) n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(TexturedRectangle &n)
|
|
||||||
{
|
|
||||||
// type specific
|
|
||||||
XMLElement *xmlParent = xmlCurrent_;
|
|
||||||
xmlCurrent_ = xmlDoc_->NewElement("TexturedRectangle");
|
|
||||||
|
|
||||||
XMLElement *image = xmlDoc_->NewElement("filename");
|
|
||||||
xmlCurrent_->InsertEndChild(image);
|
|
||||||
XMLText *filename = xmlDoc_->NewText( n.getResourcePath().c_str() );
|
|
||||||
image->InsertEndChild(filename);
|
|
||||||
|
|
||||||
// inherited from Primitive
|
|
||||||
visit( (Primitive&) n);
|
|
||||||
|
|
||||||
// recursive
|
|
||||||
xmlParent->InsertEndChild(xmlCurrent_);
|
|
||||||
xmlCurrent_ = xmlParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(MediaRectangle &n)
|
|
||||||
{
|
|
||||||
// type specific
|
|
||||||
XMLElement *xmlParent = xmlCurrent_;
|
|
||||||
xmlCurrent_ = xmlDoc_->NewElement("MediaRectangle");
|
|
||||||
|
|
||||||
XMLElement *media = xmlDoc_->NewElement("filename");
|
|
||||||
xmlCurrent_->InsertEndChild(media);
|
|
||||||
XMLText *filename = xmlDoc_->NewText( n.getMediaPath().c_str() );
|
|
||||||
media->InsertEndChild(filename);
|
|
||||||
|
|
||||||
// TODO : visit MediaPlayer
|
|
||||||
|
|
||||||
// inherited from Primitive
|
|
||||||
visit( (Primitive&) n);
|
|
||||||
|
|
||||||
// recursive
|
|
||||||
xmlParent->InsertEndChild(xmlCurrent_);
|
|
||||||
xmlCurrent_ = xmlParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(LineStrip &n)
|
|
||||||
{
|
|
||||||
// type specific
|
|
||||||
XMLElement *xmlParent = xmlCurrent_;
|
|
||||||
xmlCurrent_ = xmlDoc_->NewElement("LineStrip");
|
|
||||||
|
|
||||||
XMLElement *color = XMLElementGLM(xmlDoc_, n.getColor());
|
|
||||||
color->SetAttribute("type", "RGBA");
|
|
||||||
xmlCurrent_->InsertEndChild(color);
|
|
||||||
|
|
||||||
std::vector<glm::vec3> points = n.getPoints();
|
|
||||||
for(size_t i = 0; i < points.size(); ++i)
|
|
||||||
{
|
|
||||||
XMLElement *p = XMLElementGLM(xmlDoc_, points[i]);
|
|
||||||
p->SetAttribute("point", (int) i);
|
|
||||||
xmlCurrent_->InsertEndChild(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// inherited from Primitive
|
|
||||||
visit( (Primitive&) n);
|
|
||||||
|
|
||||||
// recursive
|
|
||||||
xmlParent->InsertEndChild(xmlCurrent_);
|
|
||||||
xmlCurrent_ = xmlParent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionVisitor::visit(Scene &n)
|
|
||||||
{
|
|
||||||
XMLDeclaration *pDec = xmlDoc_->NewDeclaration();
|
|
||||||
xmlDoc_->InsertFirstChild(pDec);
|
|
||||||
|
|
||||||
XMLElement *pRoot = xmlDoc_->NewElement("Session");
|
|
||||||
xmlDoc_->InsertEndChild(pRoot);
|
|
||||||
|
|
||||||
std::string s = "Saved on " + GstToolkit::date_time_string();
|
|
||||||
XMLComment *pComment = xmlDoc_->NewComment(s.c_str());
|
|
||||||
pRoot->InsertEndChild(pComment);
|
|
||||||
|
|
||||||
// save scene
|
|
||||||
xmlCurrent_ = pRoot;
|
|
||||||
n.getRoot()->accept(*this);
|
|
||||||
|
|
||||||
XMLError eResult = xmlDoc_->SaveFile(filename_.c_str());
|
|
||||||
XMLCheckResult(eResult);
|
|
||||||
}
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "tinyxml2Toolkit.h"
|
|
||||||
|
|
||||||
// Forward declare different kind of Node
|
// Forward declare different kind of Node
|
||||||
class Node;
|
class Node;
|
||||||
class Primitive;
|
class Primitive;
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -35,7 +35,7 @@
|
|||||||
#include "MediaPlayer.h"
|
#include "MediaPlayer.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "Primitives.h"
|
#include "Primitives.h"
|
||||||
#include "Visitor.h"
|
#include "SessionVisitor.h"
|
||||||
|
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
using namespace tinyxml2;
|
using namespace tinyxml2;
|
||||||
|
|
||||||
|
#include <glm/ext/vector_float3.hpp>
|
||||||
#include <glm/ext/vector_float4.hpp>
|
#include <glm/ext/vector_float4.hpp>
|
||||||
#include <glm/ext/matrix_float4x4.hpp>
|
#include <glm/ext/matrix_float4x4.hpp>
|
||||||
#include <glm/gtc/matrix_access.hpp>
|
#include <glm/gtc/matrix_access.hpp>
|
||||||
|
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec3 vector)
|
XMLElement *tinyxml2::XMLElementGLM(XMLDocument *doc, glm::vec3 vector)
|
||||||
{
|
{
|
||||||
XMLElement *newelement = doc->NewElement( "vec3" );
|
XMLElement *newelement = doc->NewElement( "vec3" );
|
||||||
newelement->SetAttribute("x", vector[0]);
|
newelement->SetAttribute("x", vector[0]);
|
||||||
@@ -17,7 +18,7 @@ XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec3 vector)
|
|||||||
return newelement;
|
return newelement;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec4 vector)
|
XMLElement *tinyxml2::XMLElementGLM(XMLDocument *doc, glm::vec4 vector)
|
||||||
{
|
{
|
||||||
XMLElement *newelement = doc->NewElement( "vec4" );
|
XMLElement *newelement = doc->NewElement( "vec4" );
|
||||||
newelement->SetAttribute("x", vector[0]);
|
newelement->SetAttribute("x", vector[0]);
|
||||||
@@ -27,7 +28,7 @@ XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec4 vector)
|
|||||||
return newelement;
|
return newelement;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLElement *XMLElementGLM(XMLDocument *doc, glm::mat4 matrix)
|
XMLElement *tinyxml2::XMLElementGLM(XMLDocument *doc, glm::mat4 matrix)
|
||||||
{
|
{
|
||||||
XMLElement *newelement = doc->NewElement( "mat4" );
|
XMLElement *newelement = doc->NewElement( "mat4" );
|
||||||
for (int r = 0 ; r < 4 ; r ++)
|
for (int r = 0 ; r < 4 ; r ++)
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace tinyxml2 {
|
|||||||
class XMLDocument;
|
class XMLDocument;
|
||||||
class XMLElement;
|
class XMLElement;
|
||||||
|
|
||||||
tinyxml2::XMLElement *XMLElementGLM(tinyxml2::XMLDocument *doc, glm::vec3 vector);
|
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec3 vector);
|
||||||
tinyxml2::XMLElement *XMLElementGLM(tinyxml2::XMLDocument *doc, glm::vec4 vector);
|
XMLElement *XMLElementGLM(XMLDocument *doc, glm::vec4 vector);
|
||||||
tinyxml2::XMLElement *XMLElementGLM(tinyxml2::XMLDocument *doc, glm::mat4 matrix);
|
XMLElement *XMLElementGLM(XMLDocument *doc, glm::mat4 matrix);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user