mirror of
https://github.com/overte-org/overte.git
synced 2025-08-17 04:27:13 +02:00
json writer sort of works. started on reader
This commit is contained in:
parent
81dc7cb8cf
commit
d0bbac2eb6
8 changed files with 181 additions and 47 deletions
|
@ -22,7 +22,7 @@ ToolWindow::ToolWindow(QWidget* parent) :
|
|||
_hasShown(false),
|
||||
_lastGeometry() {
|
||||
|
||||
setDockOptions(QMainWindow::ForceTabbedDocks);
|
||||
// setDockOptions(QMainWindow::ForceTabbedDocks);
|
||||
Application::getInstance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ bool ToolWindow::event(QEvent* event) {
|
|||
}
|
||||
|
||||
bool ToolWindow::eventFilter(QObject* sender, QEvent* event) {
|
||||
#if 0
|
||||
switch (event->type()) {
|
||||
case QEvent::WindowStateChange:
|
||||
if (Application::getInstance()->getWindow()->isMinimized()) {
|
||||
|
@ -77,7 +78,7 @@ bool ToolWindow::eventFilter(QObject* sender, QEvent* event) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "EntityScriptingInterface.h"
|
||||
#include "EntityItem.h"
|
||||
#include "EntityTree.h"
|
||||
#include "QVariantGLM.h"
|
||||
|
||||
bool EntityItem::_sendPhysicsUpdates = true;
|
||||
|
||||
|
@ -1152,10 +1153,54 @@ void EntityItem::updateLifetime(float value) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
QVariantMap BoxEntityItem::writeToMap() {
|
||||
QVariantMap EntityItem::writeToMap() {
|
||||
QVariantMap result;
|
||||
result["id"] = getID().toString();
|
||||
// result["id"] = getID().toString();
|
||||
result["type"] = _type;
|
||||
// result["animation-update-delta"] = getLastUpdated() <= getLastEdited() ? 0 : getLastUpdated() - getLastEdited();
|
||||
// result["simulation-update-delta"] = getLastSimulated() <= getLastEdited() ? 0 : getLastSimulated() - getLastEdited();
|
||||
result["created"] = _created;
|
||||
result["last-edited"] = _lastEdited;
|
||||
result["last-updated"] = _lastUpdated;
|
||||
result["dimensions"] = glmToQList(_dimensions);
|
||||
result["rotation"] = glmToQList(_rotation);
|
||||
result["density"] = _density;
|
||||
result["gravity"] = glmToQList(_gravity);
|
||||
result["damping"] = _damping;
|
||||
result["lifetime"] = _lifetime;
|
||||
result["script"] = _script;
|
||||
result["registration-point"] = glmToQList(_registrationPoint);
|
||||
result["angular-velocity"] = glmToQList(_angularVelocity);
|
||||
result["angular-damping"] = _angularDamping;
|
||||
result["visible"] = _visible;
|
||||
result["ignore-for-collisions"] = _ignoreForCollisions;
|
||||
result["collisions-will-move"] = _collisionsWillMove;
|
||||
result["locked"] = _locked;
|
||||
result["userData"] = _userData;
|
||||
|
||||
writeSubTypeToMap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void EntityItem::readFromMap(QVariantMap map) {
|
||||
_type = EntityTypes::getEntityTypeFromName(map["type"].toString());
|
||||
_created = map["created"].toULongLong();
|
||||
_lastEdited = map["last-edited"].toULongLong();
|
||||
_lastUpdated = map["last-updated"].toULongLong();
|
||||
_dimensions = qListToGlmVec3(map["dimensions"]);
|
||||
_rotation = qListToGlmQuat(map["rotation"]);
|
||||
_density = map["density"].toFloat();
|
||||
_gravity = qListToGlmVec3(map["gravity"]);
|
||||
_damping = map["damping"].toFloat();
|
||||
_lifetime = map["lifetime"].toFloat();
|
||||
_script = map["script"].toString();
|
||||
_registrationPoint = qListToGlmVec3(map["registration-point"]);
|
||||
_angularVelocity = qListToGlmVec3(map["angular-velocity"]);
|
||||
_angularDamping = map["angular-damping"].toFloat();
|
||||
_visible = map["visible"].toBool();
|
||||
_ignoreForCollisions = map["ignore-for-collisions"].toBool();
|
||||
_collisionsWillMove = map["collisions-will-move"].toBool();
|
||||
_locked = map["locked"].toBool();
|
||||
_userData = map["userData"].toString();
|
||||
}
|
||||
|
|
|
@ -294,6 +294,7 @@ public:
|
|||
|
||||
QVariantMap writeToMap();
|
||||
virtual void writeSubTypeToMap(QVariantMap& map) = 0;
|
||||
void readFromMap(QVariantMap map);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -983,43 +983,6 @@ void EntityTree::dumpTree() {
|
|||
recurseTreeWithOperator(&theOperator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class ToMapOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
ToMapOperator(QVariantMap& map) : RecurseOctreeOperator(), _map(map) {};
|
||||
bool preRecursion(OctreeElement* element) {return true;}
|
||||
bool postRecursion(OctreeElement* element) {
|
||||
qDebug() << " in ToMapOperator::preRecursion";
|
||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
|
||||
if (!_map.contains("Entities")) {
|
||||
_map["Entities"] = QVariantList();
|
||||
}
|
||||
// XXX is this causing a lot of copying?
|
||||
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
|
||||
foreach (EntityItem* entityItem, entities) {
|
||||
entitiesQList << entityItem->writeToMap();
|
||||
}
|
||||
_map["Entities"] = entitiesQList;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
QVariantMap& _map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool EntityTree::writeToMap(QVariantMap& entityDescription) {
|
||||
ToMapOperator theOperator(entityDescription);
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class PruneOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
virtual bool preRecursion(OctreeElement* element) { return true; }
|
||||
|
@ -1071,3 +1034,77 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
class ToMapOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
ToMapOperator(QVariantMap& map) : RecurseOctreeOperator(), _map(map) {};
|
||||
bool preRecursion(OctreeElement* element) {return true;}
|
||||
bool postRecursion(OctreeElement* element) {
|
||||
qDebug() << " in ToMapOperator::preRecursion";
|
||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
|
||||
// XXX is this causing a lot of copying?
|
||||
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
|
||||
foreach (EntityItem* entityItem, entities) {
|
||||
entitiesQList << entityItem->writeToMap();
|
||||
}
|
||||
_map["Entities"] = entitiesQList;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
QVariantMap& _map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool EntityTree::writeToMap(QVariantMap& entityDescription) {
|
||||
entityDescription["Entities"] = QVariantList();
|
||||
ToMapOperator theOperator(entityDescription);
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EntityTree::readFromMap(QVariantMap& map) {
|
||||
|
||||
|
||||
QVariantList entitiesQList = map["Entities"].toList();
|
||||
|
||||
foreach (QVariant entityQ, entitiesQList) {
|
||||
QVariantMap entityMap = entityQ.toMap();
|
||||
EntityTypes::EntityType entityType = EntityTypes::getEntityTypeFromName(entityMap["type"].toString());
|
||||
|
||||
if (entityType == EntityTypes::Unknown) {
|
||||
qDebug() << "unknown entity type" << entityMap["type"];
|
||||
}
|
||||
|
||||
const EntityItemID entityItemID();
|
||||
const EntityItemProperties entityItemProperties();
|
||||
EntityItem *entityItem = EntityTypes::constructEntityItem(entityType, entityItemID, entityItemProperties);
|
||||
|
||||
// switch (entityType) {
|
||||
// case EntityType::Model:
|
||||
// ei = ModelEntityItem();
|
||||
// break;
|
||||
// case EntityType::Box:
|
||||
// ei = BoxEntityItem();
|
||||
// break;
|
||||
// case EntityType::Sphere:
|
||||
// ei = SphereEntityItem();
|
||||
// break;
|
||||
// case EntityType::Light:
|
||||
// ei = LightEntityItem();
|
||||
// break;
|
||||
// case EntityType::Text:
|
||||
// ei = TextEntityItem();
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,7 @@ public:
|
|||
void setWantEditLogging(bool value) { _wantEditLogging = value; }
|
||||
|
||||
bool writeToMap(QVariantMap& entityDescription);
|
||||
bool readFromMap(QVariantMap& entityDescription);
|
||||
|
||||
signals:
|
||||
void deletingEntity(const EntityItemID& entityID);
|
||||
|
|
|
@ -401,9 +401,6 @@ QString ModelEntityItem::getAnimationSettings() const {
|
|||
return jsonByteString;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap ModelEntityItem::writeSubTypeToMap() {
|
||||
QVariantMap result;
|
||||
result["type"] = QString("model");
|
||||
return result;
|
||||
void ModelEntityItem::writeSubTypeToMap(QVariantMap& map) {
|
||||
map["type"] = QString("model");
|
||||
}
|
||||
|
|
31
libraries/shared/src/QVariantGLM.cpp
Normal file
31
libraries/shared/src/QVariantGLM.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// QVariantGLM.cpp
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Created by Seth Alves on 3/9/15.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "QVariantGLM.h"
|
||||
|
||||
QVariantList glmToQList(const glm::vec3& g) {
|
||||
return QVariantList() << g[0] << g[1] << g[2];
|
||||
}
|
||||
|
||||
QVariantList glmToQList(const glm::quat& g) {
|
||||
return QVariantList() << g[0] << g[1] << g[2] << g[3];
|
||||
}
|
||||
|
||||
glm::vec3 qListToGlmVec3(const QVariant q) {
|
||||
QVariantList qList = q.toList();
|
||||
return glm::vec3(qList[0].toFloat(), qList[1].toFloat(), qList[2].toFloat());
|
||||
}
|
||||
|
||||
glm::quat qListToGlmQuat(const QVariant q) {
|
||||
QVariantList qList = q.toList();
|
||||
return glm::quat(qList[0].toFloat(), qList[1].toFloat(), qList[2].toFloat(), qList[3].toFloat());
|
||||
}
|
||||
|
21
libraries/shared/src/QVariantGLM.h
Normal file
21
libraries/shared/src/QVariantGLM.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// QVariantGLM.h
|
||||
// libraries/shared/src
|
||||
//
|
||||
// Created by Seth Alves on 3/9/15.
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QVariantList>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
QVariantList glmToQList(const glm::vec3& g);
|
||||
QVariantList glmToQList(const glm::quat& g);
|
||||
glm::vec3 qListToGlmVec3(const QVariant q);
|
||||
glm::quat qListToGlmQuat(const QVariant q);
|
Loading…
Reference in a new issue