add support to not displace very large clipboards on import

This commit is contained in:
ZappoMan 2015-05-11 14:21:58 -07:00
parent 28bacb4d82
commit 73428ec12d
9 changed files with 57 additions and 2 deletions

View file

@ -1030,8 +1030,11 @@ function importSVO(importURL) {
var success = Clipboard.importEntities(importURL);
if (success) {
var position = getPositionToCreateEntity();
var VERY_LARGE = 10000;
var position = { x: 0, y: 0, z: 0};
if (Clipboard.getClipboardContentsLargestDimension() < VERY_LARGE) {
position = getPositionToCreateEntity();
}
var pastedEntityIDs = Clipboard.pasteEntities(position);
if (isActive) {

View file

@ -14,6 +14,10 @@
ClipboardScriptingInterface::ClipboardScriptingInterface() {
}
float ClipboardScriptingInterface::getClipboardContentsLargestDimension() {
return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension();
}
bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
return Application::getInstance()->exportEntities(filename, entityIDs);
}

View file

@ -22,6 +22,7 @@ signals:
void readyToImport();
public slots:
float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard
bool importEntities(const QString& filename);
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
bool exportEntities(const QString& filename, float x, float y, float z, float s);

View file

@ -1068,6 +1068,27 @@ void EntityTree::debugDumpMap() {
qCDebug(entities) << "-----------------------------------------------------";
}
class ContentsDimensionOperator : public RecurseOctreeOperator {
public:
virtual bool preRecursion(OctreeElement* element);
virtual bool postRecursion(OctreeElement* element) { return true; }
float getLargestDimension() const { return _contentExtents.largestDimension(); }
private:
Extents _contentExtents;
};
bool ContentsDimensionOperator::preRecursion(OctreeElement* element) {
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
entityTreeElement->expandExtentsToContents(_contentExtents);
return true;
}
float EntityTree::getContentsLargestDimension() {
ContentsDimensionOperator theOperator;
recurseTreeWithOperator(&theOperator);
return theOperator.getLargestDimension();
}
class DebugOperator : public RecurseOctreeOperator {
public:
virtual bool preRecursion(OctreeElement* element);

View file

@ -166,6 +166,8 @@ public:
bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues);
bool readFromMap(QVariantMap& entityDescription);
float getContentsLargestDimension();
signals:
void deletingEntity(const EntityItemID& entityID);

View file

@ -819,6 +819,16 @@ bool EntityTreeElement::pruneChildren() {
return somethingPruned;
}
void EntityTreeElement::expandExtentsToContents(Extents& extents) {
if (_entityItems->size()) {
for (uint16_t i = 0; i < _entityItems->size(); i++) {
EntityItem* entity = (*_entityItems)[i];
extents.add(entity->getAABox());
}
}
}
void EntityTreeElement::debugDump() {
qCDebug(entities) << "EntityTreeElement...";

View file

@ -196,6 +196,8 @@ public:
bool pruneChildren();
void expandExtentsToContents(Extents& extents);
protected:
virtual void init(unsigned char * octalCode);
EntityTree* _myTree;

View file

@ -14,6 +14,7 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/transform.hpp>
#include "AABox.h"
#include "Extents.h"
void Extents::reset() {
@ -37,6 +38,11 @@ void Extents::addPoint(const glm::vec3& point) {
maximum = glm::max(maximum, point);
}
void Extents::add(const AABox& box) {
minimum = glm::min(minimum, box.getMinimumPoint());
maximum = glm::max(maximum, box.getMaximumPoint());
}
void Extents::rotate(const glm::quat& rotation) {
glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z);
glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z);

View file

@ -19,6 +19,8 @@
#include <QDebug>
#include "StreamUtils.h"
class AABox;
class Extents {
public:
/// set minimum and maximum to FLT_MAX and -FLT_MAX respectively
@ -28,6 +30,10 @@ public:
/// expand current limits to contain other extents
void addExtents(const Extents& extents);
/// \param aabox another intance of extents
/// expand current limits to contain other aabox
void add(const AABox& box);
/// \param point new point to compare against existing limits
/// compare point to current limits and expand them if necessary to contain point
void addPoint(const glm::vec3& point);