mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 01:01:35 +02:00
move to-map recurse operator class to its own file
This commit is contained in:
parent
109271de3d
commit
2d4a95c634
3 changed files with 95 additions and 64 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "MovingEntitiesOperator.h"
|
||||
#include "UpdateEntityOperator.h"
|
||||
#include "QVariantGLM.h"
|
||||
#include "RecurseOctreeToMapOperator.h"
|
||||
|
||||
EntityTree::EntityTree(bool shouldReaverage) :
|
||||
Octree(shouldReaverage),
|
||||
|
@ -1042,73 +1043,10 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
class ToMapOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
ToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine) :
|
||||
RecurseOctreeOperator(),
|
||||
_map(map),
|
||||
_top(top),
|
||||
_engine(engine)
|
||||
{
|
||||
// if some element "top" was given, only save information for that element and it's children.
|
||||
if (_top) {
|
||||
_withinTop = false;
|
||||
} else {
|
||||
// top was NULL, export entire tree.
|
||||
_withinTop = true;
|
||||
}
|
||||
};
|
||||
bool preRecursion(OctreeElement* element) {
|
||||
if (element == _top) {
|
||||
_withinTop = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool postRecursion(OctreeElement* element) {
|
||||
|
||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
|
||||
|
||||
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
|
||||
|
||||
foreach (EntityItem* entityItem, entities) {
|
||||
EntityItemProperties properties = entityItem->getProperties();
|
||||
|
||||
// XXX this is copied out of EntityScriptingInterface::getEntityProperties
|
||||
// is it needed here?
|
||||
|
||||
// if (entityItem->getType() == EntityTypes::Model) {
|
||||
// const FBXGeometry* geometry = getGeometryForEntity(entityItem);
|
||||
// if (geometry) {
|
||||
// properties.setSittingPoints(geometry->sittingPoints);
|
||||
// Extents meshExtents = geometry->getUnscaledMeshExtents();
|
||||
// properties.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
|
||||
// }
|
||||
// }
|
||||
|
||||
QScriptValue qScriptValues =
|
||||
EntityItemPropertiesToScriptValue(_engine, properties);
|
||||
|
||||
entitiesQList << qScriptValues.toVariant();
|
||||
}
|
||||
_map["Entities"] = entitiesQList;
|
||||
if (element == _top) {
|
||||
_withinTop = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
QVariantMap& _map;
|
||||
OctreeElement *_top;
|
||||
QScriptEngine *_engine;
|
||||
bool _withinTop;
|
||||
};
|
||||
|
||||
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElement* element) {
|
||||
entityDescription["Entities"] = QVariantList();
|
||||
QScriptEngine scriptEngine;
|
||||
ToMapOperator theOperator(entityDescription, element, &scriptEngine);
|
||||
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine);
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
return true;
|
||||
}
|
||||
|
|
69
libraries/entities/src/RecurseOctreeToMapOperator.cpp
Normal file
69
libraries/entities/src/RecurseOctreeToMapOperator.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// RecurseOctreeToMapOperator.cpp
|
||||
// libraries/entities/src
|
||||
//
|
||||
// Created by Seth Alves on 3/6/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 "RecurseOctreeToMapOperator.h"
|
||||
|
||||
|
||||
RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine) :
|
||||
RecurseOctreeOperator(),
|
||||
_map(map),
|
||||
_top(top),
|
||||
_engine(engine)
|
||||
{
|
||||
// if some element "top" was given, only save information for that element and it's children.
|
||||
if (_top) {
|
||||
_withinTop = false;
|
||||
} else {
|
||||
// top was NULL, export entire tree.
|
||||
_withinTop = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool RecurseOctreeToMapOperator::preRecursion(OctreeElement* element) {
|
||||
if (element == _top) {
|
||||
_withinTop = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) {
|
||||
|
||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
|
||||
|
||||
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
|
||||
|
||||
foreach (EntityItem* entityItem, entities) {
|
||||
EntityItemProperties properties = entityItem->getProperties();
|
||||
|
||||
// XXX this is copied out of EntityScriptingInterface::getEntityProperties
|
||||
// is it needed here?
|
||||
|
||||
// if (entityItem->getType() == EntityTypes::Model) {
|
||||
// const FBXGeometry* geometry = getGeometryForEntity(entityItem);
|
||||
// if (geometry) {
|
||||
// properties.setSittingPoints(geometry->sittingPoints);
|
||||
// Extents meshExtents = geometry->getUnscaledMeshExtents();
|
||||
// properties.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
|
||||
// }
|
||||
// }
|
||||
|
||||
QScriptValue qScriptValues =
|
||||
EntityItemPropertiesToScriptValue(_engine, properties);
|
||||
|
||||
entitiesQList << qScriptValues.toVariant();
|
||||
}
|
||||
_map["Entities"] = entitiesQList;
|
||||
if (element == _top) {
|
||||
_withinTop = false;
|
||||
}
|
||||
return true;
|
||||
}
|
24
libraries/entities/src/RecurseOctreeToMapOperator.h
Normal file
24
libraries/entities/src/RecurseOctreeToMapOperator.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// RecurseOctreeToMapOperator.h
|
||||
// libraries/entities/src
|
||||
//
|
||||
// Created by Seth Alves on 3/6/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 "EntityTree.h"
|
||||
|
||||
class RecurseOctreeToMapOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine);
|
||||
bool preRecursion(OctreeElement* element);
|
||||
bool postRecursion(OctreeElement* element);
|
||||
private:
|
||||
QVariantMap& _map;
|
||||
OctreeElement *_top;
|
||||
QScriptEngine *_engine;
|
||||
bool _withinTop;
|
||||
};
|
Loading…
Reference in a new issue