From 28bacb4d82672666677cc8cce76c5722ace0d150 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 11 May 2015 13:26:52 -0700 Subject: [PATCH 1/3] add center in zone button to edit.js --- examples/edit.js | 19 +++++++++++++++++++ examples/html/entityProperties.html | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/examples/edit.js b/examples/edit.js index 64050d92aa..9c7db22eca 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1295,6 +1295,25 @@ PropertiesTool = function(opts) { pushCommandForSelections(); selectionManager._update(); } + } else if (data.action == "centerAtmosphereToZone") { + if (selectionManager.hasSelection()) { + selectionManager.saveProperties(); + for (var i = 0; i < selectionManager.selections.length; i++) { + var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + if (properties.type == "Zone") { + var centerOfZone = properties.boundingBox.center; + var atmosphereCenter = { x: centerOfZone.x, + y: centerOfZone.y - properties.atmosphere.innerRadius, + z: centerOfZone.z }; + + Entities.editEntity(selectionManager.selections[i], { + atmosphere: { center: atmosphereCenter }, + }); + } + } + pushCommandForSelections(); + selectionManager._update(); + } } } }); diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 56fc84ef96..4247a5e6cb 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -300,6 +300,8 @@ var elZoneAtmosphereCenterX = document.getElementById("property-zone-atmosphere-center-x"); var elZoneAtmosphereCenterY = document.getElementById("property-zone-atmosphere-center-y"); var elZoneAtmosphereCenterZ = document.getElementById("property-zone-atmosphere-center-z"); + var elCenterAtmosphereToZone = document.getElementById("center-atmosphere-in-zone"); + var elZoneAtmosphereInnerRadius = document.getElementById("property-zone-atmosphere-inner-radius"); var elZoneAtmosphereOuterRadius = document.getElementById("property-zone-atmosphere-outer-radius"); var elZoneAtmosphereMieScattering = document.getElementById("property-zone-atmosphere-mie-scattering"); @@ -705,6 +707,12 @@ percentage: parseInt(elRescaleDimensionsPct.value), })); }); + elCenterAtmosphereToZone.addEventListener("click", function() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "centerAtmosphereToZone", + })); + }); window.onblur = function() { // Fake a change event @@ -1156,6 +1164,9 @@
X
Y
Z
+
+ +
From 73428ec12d15bb2af8182d620338471cf3de6807 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 11 May 2015 14:21:58 -0700 Subject: [PATCH 2/3] add support to not displace very large clipboards on import --- examples/edit.js | 7 +++++-- .../scripting/ClipboardScriptingInterface.cpp | 4 ++++ .../scripting/ClipboardScriptingInterface.h | 1 + libraries/entities/src/EntityTree.cpp | 21 +++++++++++++++++++ libraries/entities/src/EntityTree.h | 2 ++ libraries/entities/src/EntityTreeElement.cpp | 10 +++++++++ libraries/entities/src/EntityTreeElement.h | 2 ++ libraries/shared/src/Extents.cpp | 6 ++++++ libraries/shared/src/Extents.h | 6 ++++++ 9 files changed, 57 insertions(+), 2 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 9c7db22eca..1bc4a34393 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -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) { diff --git a/interface/src/scripting/ClipboardScriptingInterface.cpp b/interface/src/scripting/ClipboardScriptingInterface.cpp index 616fc5f141..f833ad43cc 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.cpp +++ b/interface/src/scripting/ClipboardScriptingInterface.cpp @@ -14,6 +14,10 @@ ClipboardScriptingInterface::ClipboardScriptingInterface() { } +float ClipboardScriptingInterface::getClipboardContentsLargestDimension() { + return Application::getInstance()->getEntityClipboard()->getContentsLargestDimension(); +} + bool ClipboardScriptingInterface::exportEntities(const QString& filename, const QVector& entityIDs) { return Application::getInstance()->exportEntities(filename, entityIDs); } diff --git a/interface/src/scripting/ClipboardScriptingInterface.h b/interface/src/scripting/ClipboardScriptingInterface.h index 92204af60d..73bebd4836 100644 --- a/interface/src/scripting/ClipboardScriptingInterface.h +++ b/interface/src/scripting/ClipboardScriptingInterface.h @@ -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& entityIDs); bool exportEntities(const QString& filename, float x, float y, float z, float s); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 1b59d3bd8e..ef49aca87a 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -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(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); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index f99160f4ed..76d648cf46 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -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); diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 349bd51372..3acc5fbcef 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -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..."; diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 0b28dd30d0..658dfeab92 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -196,6 +196,8 @@ public: bool pruneChildren(); + void expandExtentsToContents(Extents& extents); + protected: virtual void init(unsigned char * octalCode); EntityTree* _myTree; diff --git a/libraries/shared/src/Extents.cpp b/libraries/shared/src/Extents.cpp index 02e09bfa3c..f48ba3c99f 100644 --- a/libraries/shared/src/Extents.cpp +++ b/libraries/shared/src/Extents.cpp @@ -14,6 +14,7 @@ #include #include +#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); diff --git a/libraries/shared/src/Extents.h b/libraries/shared/src/Extents.h index 024d72013a..489d48b1c1 100644 --- a/libraries/shared/src/Extents.h +++ b/libraries/shared/src/Extents.h @@ -19,6 +19,8 @@ #include #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); From a2a1bf4e8cab30984cf10716f02407b3242720f5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 11 May 2015 16:32:27 -0700 Subject: [PATCH 3/3] make stars fade in as sun drops below horizon --- interface/src/Application.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 088b2ddf96..dc38f64f58 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3220,18 +3220,40 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs // compute starfield alpha based on distance from atmosphere float alpha = 1.0f; bool hasStars = true; + if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { // TODO: handle this correctly for zones const EnvironmentData& closestData = _environment.getClosestData(theCamera.getPosition()); - + if (closestData.getHasStars()) { + const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f; + const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f; + + glm::vec3 sunDirection = (getAvatarPosition() - closestData.getSunLocation()) + / closestData.getAtmosphereOuterRadius(); float height = glm::distance(theCamera.getPosition(), closestData.getAtmosphereCenter()); if (height < closestData.getAtmosphereInnerRadius()) { + // If we're inside the atmosphere, then determine if our keyLight is below the horizon alpha = 0.0f; + if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { + float directionY = glm::clamp(sunDirection.y, + -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) + + APPROXIMATE_DISTANCE_FROM_HORIZON; + alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); + } + + } else if (height < closestData.getAtmosphereOuterRadius()) { alpha = (height - closestData.getAtmosphereInnerRadius()) / (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius()); + + if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { + float directionY = glm::clamp(sunDirection.y, + -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) + + APPROXIMATE_DISTANCE_FROM_HORIZON; + alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); + } } } else { hasStars = false;