mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:17:02 +02:00
add support to not displace very large clipboards on import
This commit is contained in:
parent
28bacb4d82
commit
73428ec12d
9 changed files with 57 additions and 2 deletions
|
@ -1030,8 +1030,11 @@ function importSVO(importURL) {
|
||||||
var success = Clipboard.importEntities(importURL);
|
var success = Clipboard.importEntities(importURL);
|
||||||
|
|
||||||
if (success) {
|
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);
|
var pastedEntityIDs = Clipboard.pasteEntities(position);
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
ClipboardScriptingInterface::ClipboardScriptingInterface() {
|
ClipboardScriptingInterface::ClipboardScriptingInterface() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ClipboardScriptingInterface::getClipboardContentsLargestDimension() {
|
||||||
|
return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension();
|
||||||
|
}
|
||||||
|
|
||||||
bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
|
bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
|
||||||
return Application::getInstance()->exportEntities(filename, entityIDs);
|
return Application::getInstance()->exportEntities(filename, entityIDs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ signals:
|
||||||
void readyToImport();
|
void readyToImport();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
float getClipboardContentsLargestDimension(); /// returns the largest dimension of everything on the clipboard
|
||||||
bool importEntities(const QString& filename);
|
bool importEntities(const QString& filename);
|
||||||
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
|
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);
|
||||||
bool exportEntities(const QString& filename, float x, float y, float z, float s);
|
bool exportEntities(const QString& filename, float x, float y, float z, float s);
|
||||||
|
|
|
@ -1068,6 +1068,27 @@ void EntityTree::debugDumpMap() {
|
||||||
qCDebug(entities) << "-----------------------------------------------------";
|
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 {
|
class DebugOperator : public RecurseOctreeOperator {
|
||||||
public:
|
public:
|
||||||
virtual bool preRecursion(OctreeElement* element);
|
virtual bool preRecursion(OctreeElement* element);
|
||||||
|
|
|
@ -166,6 +166,8 @@ public:
|
||||||
|
|
||||||
bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues);
|
bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues);
|
||||||
bool readFromMap(QVariantMap& entityDescription);
|
bool readFromMap(QVariantMap& entityDescription);
|
||||||
|
|
||||||
|
float getContentsLargestDimension();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
|
|
|
@ -819,6 +819,16 @@ bool EntityTreeElement::pruneChildren() {
|
||||||
return somethingPruned;
|
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() {
|
void EntityTreeElement::debugDump() {
|
||||||
qCDebug(entities) << "EntityTreeElement...";
|
qCDebug(entities) << "EntityTreeElement...";
|
||||||
|
|
|
@ -196,6 +196,8 @@ public:
|
||||||
|
|
||||||
bool pruneChildren();
|
bool pruneChildren();
|
||||||
|
|
||||||
|
void expandExtentsToContents(Extents& extents);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void init(unsigned char * octalCode);
|
virtual void init(unsigned char * octalCode);
|
||||||
EntityTree* _myTree;
|
EntityTree* _myTree;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
|
#include "AABox.h"
|
||||||
#include "Extents.h"
|
#include "Extents.h"
|
||||||
|
|
||||||
void Extents::reset() {
|
void Extents::reset() {
|
||||||
|
@ -37,6 +38,11 @@ void Extents::addPoint(const glm::vec3& point) {
|
||||||
maximum = glm::max(maximum, 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) {
|
void Extents::rotate(const glm::quat& rotation) {
|
||||||
glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z);
|
glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z);
|
||||||
glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z);
|
glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z);
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "StreamUtils.h"
|
#include "StreamUtils.h"
|
||||||
|
|
||||||
|
class AABox;
|
||||||
|
|
||||||
class Extents {
|
class Extents {
|
||||||
public:
|
public:
|
||||||
/// set minimum and maximum to FLT_MAX and -FLT_MAX respectively
|
/// set minimum and maximum to FLT_MAX and -FLT_MAX respectively
|
||||||
|
@ -28,6 +30,10 @@ public:
|
||||||
/// expand current limits to contain other extents
|
/// expand current limits to contain other extents
|
||||||
void addExtents(const Extents& 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
|
/// \param point new point to compare against existing limits
|
||||||
/// compare point to current limits and expand them if necessary to contain point
|
/// compare point to current limits and expand them if necessary to contain point
|
||||||
void addPoint(const glm::vec3& point);
|
void addPoint(const glm::vec3& point);
|
||||||
|
|
Loading…
Reference in a new issue