From 663b9c393ed0fea62e2280793ad147cfd03c5deb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Dec 2014 12:43:34 -0800 Subject: [PATCH 01/14] add debugging --- libraries/entities/src/ModelEntityItem.cpp | 9 +++++++++ libraries/entities/src/ModelEntityItem.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b9bf75178f..ab5a1ee2a9 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,6 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { _animationURL = url; } +void ModelEntityItem::setAnimationFrameIndex(float value) { + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; + qDebug() << " value:" << value; + qDebug() << " was:" << _animationLoop.getFrameIndex(); + } + _animationLoop.setFrameIndex(value); +} + void ModelEntityItem::setAnimationSettings(const QString& value) { // the animations setting is a JSON string that may contain various animation settings. // if it includes fps, frameIndex, or running, those values will be parsed out and diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 6b4ca2416a..3cf2df899d 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -75,7 +75,7 @@ public: void setModelURL(const QString& url) { _modelURL = url; } void setAnimationURL(const QString& url); static const float DEFAULT_ANIMATION_FRAME_INDEX; - void setAnimationFrameIndex(float value) { _animationLoop.setFrameIndex(value); } + void setAnimationFrameIndex(float value); void setAnimationSettings(const QString& value); static const bool DEFAULT_ANIMATION_IS_PLAYING; From a0ec2ddfe96b845b467ccb47beb18ee082d71542 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 29 Dec 2014 21:07:04 -0800 Subject: [PATCH 02/14] clamp frame index between 0 and 100,000 --- libraries/animation/src/AnimationLoop.cpp | 9 +++++---- libraries/animation/src/AnimationLoop.h | 8 +++++--- libraries/entities/src/ModelEntityItem.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libraries/animation/src/AnimationLoop.cpp b/libraries/animation/src/AnimationLoop.cpp index 75a3cdd338..e60df1eaf9 100644 --- a/libraries/animation/src/AnimationLoop.cpp +++ b/libraries/animation/src/AnimationLoop.cpp @@ -12,16 +12,18 @@ #include "AnimationCache.h" #include "AnimationLoop.h" +const float AnimationLoop::MAXIMUM_POSSIBLE_FRAME = 100000.0f; + AnimationLoop::AnimationLoop() : _fps(30.0f), _loop(false), _hold(false), _startAutomatically(false), _firstFrame(0.0f), - _lastFrame(FLT_MAX), + _lastFrame(MAXIMUM_POSSIBLE_FRAME), _running(false), _frameIndex(0.0f), - _maxFrameIndexHint(FLT_MAX) + _maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME) { } @@ -53,10 +55,9 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati void AnimationLoop::simulate(float deltaTime) { _frameIndex += deltaTime * _fps; - // If we knew the number of frames from the animation, we'd consider using it here // animationGeometry.animationFrames.size() - float maxFrame = _maxFrameIndexHint; + float maxFrame = _maxFrameIndexHint; float endFrameIndex = qMin(_lastFrame, maxFrame - (_loop ? 0.0f : 1.0f)); float startFrameIndex = qMin(_firstFrame, endFrameIndex); if ((!_loop && (_frameIndex < startFrameIndex || _frameIndex > endFrameIndex)) || startFrameIndex == endFrameIndex) { diff --git a/libraries/animation/src/AnimationLoop.h b/libraries/animation/src/AnimationLoop.h index aff2cd86ee..d4537c4656 100644 --- a/libraries/animation/src/AnimationLoop.h +++ b/libraries/animation/src/AnimationLoop.h @@ -16,6 +16,8 @@ class AnimationDetails; class AnimationLoop { public: + static const float MAXIMUM_POSSIBLE_FRAME; + AnimationLoop(); AnimationLoop(const AnimationDetails& animationDetails); AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame, @@ -33,10 +35,10 @@ public: void setStartAutomatically(bool startAutomatically); bool getStartAutomatically() const { return _startAutomatically; } - void setFirstFrame(float firstFrame) { _firstFrame = firstFrame; } + void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getFirstFrame() const { return _firstFrame; } - void setLastFrame(float lastFrame) { _lastFrame = lastFrame; } + void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getLastFrame() const { return _lastFrame; } void setRunning(bool running); @@ -45,7 +47,7 @@ public: void setFrameIndex(float frameIndex) { _frameIndex = glm::clamp(frameIndex, _firstFrame, _lastFrame); } float getFrameIndex() const { return _frameIndex; } - void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = value; } + void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = glm::clamp(value, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getMaxFrameIndexHint() const { return _maxFrameIndexHint; } void start() { setRunning(true); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 28dcbc44ca..0989068f2a 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,11 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { } void ModelEntityItem::setAnimationFrameIndex(float value) { +#ifdef WANT_DEBUG if (isAnimatingSomething()) { qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; qDebug() << " value:" << value; qDebug() << " was:" << _animationLoop.getFrameIndex(); + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); } +#endif _animationLoop.setFrameIndex(value); } @@ -425,6 +429,17 @@ void ModelEntityItem::setAnimationSettings(const QString& value) { if (settingsMap.contains("frameIndex")) { float frameIndex = settingsMap["frameIndex"].toFloat(); +#ifdef WANT_DEBUG + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationSettings() calling setAnimationFrameIndex()..."; + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); + qDebug() << " settings:" << value; + qDebug() << " settingsMap[frameIndex]:" << settingsMap["frameIndex"]; + qDebug(" frameIndex: %20.5f", frameIndex); + } +#endif + setAnimationFrameIndex(frameIndex); } From ca35520796b081b98160bc0147393c709b0eec3f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 29 Dec 2014 22:24:16 -0800 Subject: [PATCH 03/14] Hydra hands deactivate when placed back on controller base, removed measuring non-movement for inactivity --- interface/src/devices/SixenseManager.cpp | 39 ++++++++---------------- interface/src/devices/SixenseManager.h | 3 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index e2b4fedd50..5fb4a71091 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -84,10 +84,8 @@ void SixenseManager::initialize() { #ifdef HAVE_SIXENSE if (!_isInitialized) { - _lastMovement = 0; - _amountMoved = glm::vec3(0.0f); _lowVelocityFilter = false; - + _controllersAtBase = true; _calibrationState = CALIBRATION_STATE_IDLE; // By default we assume the _neckBase (in orb frame) is as high above the orb // as the "torso" is below it. @@ -146,15 +144,11 @@ void SixenseManager::setFilter(bool filter) { void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE + Hand* hand = Application::getInstance()->getAvatar()->getHand(); if (_isInitialized && _isEnabled) { - // if the controllers haven't been moved in a while, disable - const unsigned int MOVEMENT_DISABLE_SECONDS = 3; - if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) { - Hand* hand = Application::getInstance()->getAvatar()->getHand(); - for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { - it->setActive(false); - } - _lastMovement = usecTimestampNow(); + // Disable the hands (and return to default pose) if both controllers are at base station + for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { + it->setActive(!_controllersAtBase); } #ifdef __APPLE__ @@ -172,8 +166,6 @@ void SixenseManager::update(float deltaTime) { _hydrasConnected = true; UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra"); } - MyAvatar* avatar = Application::getInstance()->getAvatar(); - Hand* hand = avatar->getHand(); #ifdef __APPLE__ SixenseBaseFunction sixenseGetMaxControllers = @@ -192,7 +184,7 @@ void SixenseManager::update(float deltaTime) { SixenseTakeIntAndSixenseControllerData sixenseGetNewestData = (SixenseTakeIntAndSixenseControllerData) _sixenseLibrary->resolve("sixenseGetNewestData"); #endif - + int numControllersAtBase = 0; int numActiveControllers = 0; for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) { if (!sixenseIsControllerEnabled(i)) { @@ -221,14 +213,11 @@ void SixenseManager::update(float deltaTime) { qDebug("Found new Sixense controller, ID %i", data->controller_index); } - palm->setActive(true); - // Read controller buttons and joystick into the hand palm->setControllerButtons(data->buttons); palm->setTrigger(data->trigger); palm->setJoystick(data->joystick_x, data->joystick_y); - // Emulate the mouse so we can use scripts if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) { emulateMouse(palm, numActiveControllers - 1); @@ -238,6 +227,12 @@ void SixenseManager::update(float deltaTime) { glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]); position *= METERS_PER_MILLIMETER; + // Check to see if this hand/controller is on the base + const float CONTROLLER_AT_BASE_DISTANCE = 0.075f; + if (glm::length(position) < CONTROLLER_AT_BASE_DISTANCE) { + numControllersAtBase++; + } + // Transform the measured position into body frame. glm::vec3 neck = _neckBase; // Zeroing y component of the "neck" effectively raises the measured position a little bit. @@ -274,14 +269,6 @@ void SixenseManager::update(float deltaTime) { palm->setRawRotation(rotation); } - // use the velocity to determine whether there's any movement (if the hand isn't new) - const float MOVEMENT_DISTANCE_THRESHOLD = 0.003f; - _amountMoved += rawVelocity * deltaTime; - if (glm::length(_amountMoved) > MOVEMENT_DISTANCE_THRESHOLD && foundHand) { - _lastMovement = usecTimestampNow(); - _amountMoved = glm::vec3(0.0f); - } - // Store the one fingertip in the palm structure so we can track velocity const float FINGER_LENGTH = 0.3f; // meters const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); @@ -298,7 +285,7 @@ void SixenseManager::update(float deltaTime) { if (numActiveControllers == 2) { updateCalibration(controllers); } - + _controllersAtBase = (numControllersAtBase == 2); } #endif // HAVE_SIXENSE } diff --git a/interface/src/devices/SixenseManager.h b/interface/src/devices/SixenseManager.h index 1954ac91bc..0a7ab78c0e 100644 --- a/interface/src/devices/SixenseManager.h +++ b/interface/src/devices/SixenseManager.h @@ -91,8 +91,6 @@ private: bool _isInitialized; bool _isEnabled; bool _hydrasConnected; - quint64 _lastMovement; - glm::vec3 _amountMoved; // for mouse emulation with the two controllers bool _triggerPressed[2]; @@ -101,6 +99,7 @@ private: int _oldY[2]; bool _lowVelocityFilter; + bool _controllersAtBase; }; #endif // hifi_SixenseManager_h From a474243f08e8b866fa0a9273ee94b406031354cf Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:21:50 -0800 Subject: [PATCH 04/14] Update to ignore mouseRelease events if mousePress event handles by tool --- examples/editEntities.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index 0b5c089c07..632fed088c 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -494,8 +494,10 @@ var mouseHasMovedSincePress = false; function mousePressEvent(event) { mouseHasMovedSincePress = false; + mouseCapturedByTool = false; - if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) { + if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || gridTool.mousePressEvent(event)) { + mouseCapturedByTool = true; return; } if (isActive) { @@ -519,6 +521,7 @@ function mousePressEvent(event) { } var highlightedEntityID = { isKnownID: false }; +var mouseCapturedByTool = false; function mouseMoveEvent(event) { mouseHasMovedSincePress = true; @@ -563,6 +566,9 @@ function mouseReleaseEvent(event) { if (isActive && selectionManager.hasSelection()) { tooltip.show(false); } + if (mouseCapturedByTool) { + return; + } cameraManager.mouseReleaseEvent(event); From 9a6bce3767a553c3e35f0dfcd7862b84b0b3da9d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:26:44 -0800 Subject: [PATCH 05/14] Add getters/setters to Grid --- examples/libraries/gridTool.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 7d98befec8..f9fc07f4dd 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -27,9 +27,6 @@ Grid = function(opts) { majorGridEvery: 2, }); - that.getMinorIncrement = function() { return minorGridSpacing; }; - that.getMajorIncrement = function() { return minorGridSpacing * majorGridEvery; }; - that.visible = false; that.enabled = false; @@ -37,13 +34,39 @@ Grid = function(opts) { return origin; } + that.getMinorIncrement = function() { return minorGridWidth; }; + that.getMajorIncrement = function() { return minorGridWidth * majorGridEvery; }; + + that.getMinorGridWidth = function() { return minorGridWidth; }; + that.setMinorGridWidth = function(value) { + minorGridWidth = value; + updateGrid(); + }; + + that.getMajorGridEvery = function() { return majorGridEvery; }; + that.setMajorGridEvery = function(value) { + majorGridEvery = value; + updateGrid(); + }; + + that.getColorIndex = function() { return colorIndex; }; + that.setColorIndex = function(value) { + colorIndex = value; + updateGrid(); + }; + that.getSnapToGrid = function() { return snapToGrid; }; + that.setSnapToGrid = function(value) { + snapToGrid = value; + that.emitUpdate(); + }; that.setEnabled = function(enabled) { that.enabled = enabled; updateGrid(); } + that.getVisible = function() { return that.visible; }; that.setVisible = function(visible, noUpdate) { that.visible = visible; updateGrid(); From fdba41a69dd5871556c2ac514a7b13dec4c88e9c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:27:16 -0800 Subject: [PATCH 06/14] Add grid colors to Grid --- examples/libraries/gridTool.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index f9fc07f4dd..242dbb0d10 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -1,8 +1,14 @@ Grid = function(opts) { var that = {}; - var color = { red: 100, green: 152, blue: 203 }; - var gridColor = { red: 100, green: 152, blue: 203 }; + var colors = [ + { red: 102, green: 180, blue: 126 }, + { red: 83, green: 210, blue: 83 }, + { red: 235, green: 173, blue: 0 }, + { red: 210, green: 115, blue: 0 }, + { red: 48, green: 116, blue: 119 }, + ]; + var colorIndex = 0; var gridAlpha = 1.0; var origin = { x: 0, y: 0, z: 0 }; var majorGridEvery = 5; @@ -20,7 +26,7 @@ Grid = function(opts) { var gridOverlay = Overlays.addOverlay("grid", { position: { x: 0 , y: 0, z: 0 }, visible: true, - color: { red: 0, green: 0, blue: 128 }, + color: colors[0], alpha: 1.0, rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), minorGridWidth: 0.1, @@ -149,7 +155,6 @@ Grid = function(opts) { gridSize: halfSize, visible: that.visible, snapToGrid: snapToGrid, - gridColor: gridColor, }); } }; @@ -175,8 +180,8 @@ Grid = function(opts) { majorGridEvery = data.majorGridEvery; } - if (data.gridColor) { - gridColor = data.gridColor; + if (data.colorIndex !== undefined) { + colorIndex = data.colorIndex; } if (data.gridSize) { @@ -196,8 +201,8 @@ Grid = function(opts) { visible: that.visible && that.enabled, minorGridWidth: minorGridSpacing, majorGridEvery: majorGridEvery, - color: gridColor, - alpha: gridAlpha, + color: colors[colorIndex], + alpha: gridAlpha, }); that.emitUpdate(); From fbd189bde301f29305c771bcc76323b254d06ae0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:28:10 -0800 Subject: [PATCH 07/14] Rename minorGridSpacing to minorGridWidth --- examples/libraries/gridTool.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 242dbb0d10..82ac6bbba4 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -12,14 +12,13 @@ Grid = function(opts) { var gridAlpha = 1.0; var origin = { x: 0, y: 0, z: 0 }; var majorGridEvery = 5; - var minorGridSpacing = 0.2; + var minorGridWidth = 0.2; var halfSize = 40; var yOffset = 0.001; var worldSize = 16384; var minorGridWidth = 0.5; - var majorGridWidth = 1.5; var snapToGrid = false; @@ -107,7 +106,7 @@ Grid = function(opts) { dimensions = { x: 0, y: 0, z: 0 }; } - var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing; + var spacing = majorOnly ? (minorGridWidth * majorGridEvery) : minorGridWidth; position = Vec3.subtract(position, origin); @@ -123,7 +122,7 @@ Grid = function(opts) { return delta; } - var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing; + var spacing = majorOnly ? (minorGridWidth * majorGridEvery) : minorGridWidth; var snappedDelta = { x: Math.round(delta.x / spacing) * spacing, @@ -150,7 +149,7 @@ Grid = function(opts) { if (that.onUpdate) { that.onUpdate({ origin: origin, - minorGridSpacing: minorGridSpacing, + minorGridWidth: minorGridWidth, majorGridEvery: majorGridEvery, gridSize: halfSize, visible: that.visible, @@ -172,8 +171,8 @@ Grid = function(opts) { that.setPosition(pos, true); } - if (data.minorGridSpacing) { - minorGridSpacing = data.minorGridSpacing; + if (data.minorGridWidth) { + minorGridWidth = data.minorGridWidth; } if (data.majorGridEvery) { @@ -199,7 +198,7 @@ Grid = function(opts) { Overlays.editOverlay(gridOverlay, { position: { x: origin.y, y: origin.y, z: -origin.y }, visible: that.visible && that.enabled, - minorGridWidth: minorGridSpacing, + minorGridWidth: minorGridWidth, majorGridEvery: majorGridEvery, color: colors[colorIndex], alpha: gridAlpha, From 552a421f24ed8b856e8868ce3e2368c8135b552a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:31:29 -0800 Subject: [PATCH 08/14] Update grid tool to be an overlay --- examples/libraries/gridTool.js | 286 +++++++++++++++++++++++++++++---- 1 file changed, 256 insertions(+), 30 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 82ac6bbba4..95c4ae19f3 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -226,46 +226,272 @@ Grid = function(opts) { GridTool = function(opts) { var that = {}; + var UI_URL = HIFI_PUBLIC_BUCKET + "images/tools/grid-toolbar.svg"; + var UI_WIDTH = 854; + var UI_HEIGHT = 37; + var horizontalGrid = opts.horizontalGrid; - var verticalGrid = opts.verticalGrid; - var listeners = []; - var url = Script.resolvePath('html/gridControls.html'); - var webView = new WebWindow('Grid', url, 200, 280); + var uiOverlays = {}; + var allOverlays = []; - horizontalGrid.addListener(function(data) { - webView.eventBridge.emitScriptEvent(JSON.stringify(data)); - selectionDisplay.updateHandles(); - }); + function addUIOverlay(key, overlay, x, y, width, height) { + uiOverlays[key] = { + overlay: overlay, + x: x, + y: y, + width: width, + height: height, + }; + allOverlays.push(overlay); + } - webView.eventBridge.webEventReceived.connect(function(data) { - data = JSON.parse(data); - if (data.type == "init") { - horizontalGrid.emitUpdate(); - } else if (data.type == "update") { - horizontalGrid.update(data); - for (var i = 0; i < listeners.length; i++) { - listeners[i](data); - } - } else if (data.type == "action") { - var action = data.action; - if (action == "moveToAvatar") { - grid.setPosition(MyAvatar.position); - } else if (action == "moveToSelection") { - var newPosition = selectionManager.worldPosition; - newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 }); - grid.setPosition(newPosition); - } + var lastKnownWindowWidth = null; + function repositionUI() { + if (lastKnownWindowWidth == Window.innerWidth) { + return; } - }); - that.addListener = function(callback) { - listeners.push(callback); + lastKnownWindowWidth = Window.innerWidth; + var x = Window.innerWidth / 2 - UI_WIDTH / 2; + var y = 10; + + for (var key in uiOverlays) { + info = uiOverlays[key]; + Overlays.editOverlay(info.overlay, { + x: x + info.x, + y: y + info.y, + }); + } + } + + // "Spritesheet" is laid out horizontally in this order + var UI_SPRITE_LIST = [ + { name: "gridText", width: 54 }, + { name: "visibleCheckbox", width: 60 }, + { name: "snapToGridCheckbox", width: 105 }, + + { name: "color0", width: 27 }, + { name: "color1", width: 27 }, + { name: "color2", width: 27 }, + { name: "color3", width: 27 }, + { name: "color4", width: 27 }, + + { name: "minorGridIcon", width: 34 }, + { name: "minorGridDecrease", width: 25 }, + { name: "minorGridInput", width: 26 }, + { name: "minorGridIncrease", width: 25 }, + + { name: "majorGridIcon", width: 40 }, + { name: "majorGridDecrease", width: 25 }, + { name: "majorGridInput", width: 26 }, + { name: "majorGridIncrease", width: 25 }, + + { name: "yPositionLabel", width: 160 }, + { name: "moveToLabel", width: 54 }, + { name: "moveToAvatar", width: 26 }, + { name: "moveToSelection", width: 34 }, + ]; + + // Add all overlays from spritesheet + var baseOverlay = null; + var x = 0; + for (var i = 0; i < UI_SPRITE_LIST.length; i++) { + var info = UI_SPRITE_LIST[i]; + + var props = { + imageURL: UI_URL, + subImage: { x: x, y: 0, width: info.width, height: UI_HEIGHT }, + width: info.width, + height: UI_HEIGHT, + alpha: 1.0, + visible: false, + }; + + var overlay; + if (baseOverlay == null) { + overlay = Overlays.addOverlay("image", { + imageURL: UI_URL, + }); + baseOverlay = overlay; + } else { + overlay = Overlays.cloneOverlay(baseOverlay); + } + + Overlays.editOverlay(overlay, props); + + addUIOverlay(info.name, overlay, x, 0, info.width, UI_HEIGHT); + + x += info.width; + } + + // Add Text overlays + var textProperties = { + color: { red: 255, green: 255, blue: 255 }, + topMargin: 6, + leftMargin: 4, + alpha: 1, + backgroundAlpha: 0, + text: "", + font: { size: 12 }, + visible: false, + }; + var minorGridWidthText = Overlays.addOverlay("text", textProperties); + var majorGridEveryText = Overlays.addOverlay("text", textProperties); + var yPositionText = Overlays.addOverlay("text", textProperties); + + addUIOverlay('minorGridWidthText', minorGridWidthText, 414, 8, 24, 24); + addUIOverlay('majorGridEveryText', majorGridEveryText, 530, 8, 24, 24); + addUIOverlay('yPositionText', yPositionText, 660, 8, 24, 24); + + var NUM_COLORS = 5; + function updateColorIndex(index) { + if (index < 0 || index >= NUM_COLORS) { + return; + } + + for (var i = 0 ; i < NUM_COLORS; i++) { + var info = uiOverlays['color' + i]; + Overlays.editOverlay(info.overlay, { + subImage: { + x: info.x, + y: i == index ? UI_HEIGHT : 0, + width: info.width, + height: info.height, + } + }); + } + } + + function updateGridVisible(value) { + var info = uiOverlays.visibleCheckbox; + Overlays.editOverlay(info.overlay, { + subImage: { + x: info.x, + y: value ? UI_HEIGHT : 0, + width: info.width, + height: info.height, + } + }); + } + + function updateSnapToGrid(value) { + var info = uiOverlays.snapToGridCheckbox; + Overlays.editOverlay(info.overlay, { + subImage: { + x: info.x, + y: value ? UI_HEIGHT : 0, + width: info.width, + height: info.height, + } + }); + } + + function updateMinorGridWidth(value) { + Overlays.editOverlay(minorGridWidthText, { + text: value.toFixed(1), + }); + } + + function updateMajorGridEvery(value) { + Overlays.editOverlay(majorGridEveryText, { + text: value, + }); + } + + function updateYPosition(value) { + Overlays.editOverlay(yPositionText, { + text: value.toFixed(2), + }); + } + + function updateOverlays() { + updateGridVisible(horizontalGrid.getVisible()); + updateSnapToGrid(horizontalGrid.getSnapToGrid()); + updateColorIndex(horizontalGrid.getColorIndex()); + + updateMinorGridWidth(horizontalGrid.getMinorGridWidth()); + updateMajorGridEvery(horizontalGrid.getMajorGridEvery()); + + updateYPosition(horizontalGrid.getOrigin().y); } that.setVisible = function(visible) { - webView.setVisible(visible); + for (var i = 0; i < allOverlays.length; i++) { + Overlays.editOverlay(allOverlays[i], { visible: visible }); + } } + that.mousePressEvent = function(event) { + var overlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); + + if (allOverlays.indexOf(overlay) >= 0) { + if (overlay == uiOverlays.color0.overlay) { + horizontalGrid.setColorIndex(0); + } else if (overlay == uiOverlays.color1.overlay) { + horizontalGrid.setColorIndex(1); + } else if (overlay == uiOverlays.color2.overlay) { + horizontalGrid.setColorIndex(2); + } else if (overlay == uiOverlays.color3.overlay) { + horizontalGrid.setColorIndex(3); + } else if (overlay == uiOverlays.color4.overlay) { + horizontalGrid.setColorIndex(4); + } else if (overlay == uiOverlays.visibleCheckbox.overlay) { + horizontalGrid.setVisible(!horizontalGrid.getVisible()); + } else if (overlay == uiOverlays.snapToGridCheckbox.overlay) { + horizontalGrid.setSnapToGrid(!horizontalGrid.getSnapToGrid()); + } else if (overlay == uiOverlays.moveToAvatar.overlay) { + horizontalGrid.setPosition(MyAvatar.position); + } else if (overlay == uiOverlays.moveToSelection.overlay) { + var newPosition = selectionManager.worldPosition; + newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 }); + horizontalGrid.setPosition(newPosition); + } else if (overlay == uiOverlays.minorGridDecrease.overlay) { + var newValue = Math.max(0.1, horizontalGrid.getMinorGridWidth() - 0.1); + horizontalGrid.setMinorGridWidth(newValue); + } else if (overlay == uiOverlays.minorGridIncrease.overlay) { + horizontalGrid.setMinorGridWidth(horizontalGrid.getMinorGridWidth() + 0.1); + } else if (overlay == uiOverlays.majorGridDecrease.overlay) { + var newValue = Math.max(2, horizontalGrid.getMajorGridEvery() - 1); + horizontalGrid.setMajorGridEvery(newValue); + } else if (overlay == uiOverlays.majorGridIncrease.overlay) { + horizontalGrid.setMajorGridEvery(horizontalGrid.getMajorGridEvery() + 1); + } else if (overlay == uiOverlays.yPositionLabel.overlay) { + var newValue = Window.prompt("Y Position:", horizontalGrid.getOrigin().y.toFixed(4)); + if (newValue !== null) { + var y = parseFloat(newValue) + if (isNaN(y)) { + Window.alert("Invalid position"); + } else { + horizontalGrid.setPosition({ x: 0, y: y, z: 0 }); + } + } + } + + // Clicking anywhere within the toolbar will "consume" this press event + return true; + } + + return false; + }; + + that.mouseReleaseEvent = function(event) { + }; + + Script.scriptEnding.connect(function() { + for (var i = 0; i < allOverlays.length; i++) { + Overlays.deleteOverlay(allOverlays[i]); + } + }); + Script.update.connect(repositionUI); + + horizontalGrid.addListener(function() { + selectionDisplay.updateHandles(); + updateOverlays(); + }); + + updateOverlays(); + repositionUI(); + return that; }; From a0cb40597b416eba0294141e3cb4834e7ef9afd6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:31:47 -0800 Subject: [PATCH 09/14] Remove gridControls.html --- examples/html/gridControls.html | 167 -------------------------------- 1 file changed, 167 deletions(-) delete mode 100644 examples/html/gridControls.html diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html deleted file mode 100644 index 06090da423..0000000000 --- a/examples/html/gridControls.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - -
- -
- -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - -
- -
- - - -
-
- - - -
-
- - From 16bf4e87e624326a982557e6611b39978075d3c7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:34:59 -0800 Subject: [PATCH 10/14] Remove unused function --- examples/libraries/gridTool.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 95c4ae19f3..79ec70b13f 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -475,9 +475,6 @@ GridTool = function(opts) { return false; }; - that.mouseReleaseEvent = function(event) { - }; - Script.scriptEnding.connect(function() { for (var i = 0; i < allOverlays.length; i++) { Overlays.deleteOverlay(allOverlays[i]); From 1da253d39f72facfd23717b87e1e20183ce4b05a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 12:13:40 -0800 Subject: [PATCH 11/14] Remove duplicate minorGridWidth variable --- examples/libraries/gridTool.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 79ec70b13f..e222ff3adb 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -18,8 +18,6 @@ Grid = function(opts) { var worldSize = 16384; - var minorGridWidth = 0.5; - var snapToGrid = false; var gridOverlay = Overlays.addOverlay("grid", { From c9b3b5ff7d523b7b26b6b4aab6c16eb09e4c165d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Dec 2014 12:30:38 -0800 Subject: [PATCH 12/14] Scale back on first dropped packet, use Qt send/receive buffer size options rather than setsockopt/getsockopt. --- .../metavoxels/src/DatagramSequencer.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/libraries/metavoxels/src/DatagramSequencer.cpp b/libraries/metavoxels/src/DatagramSequencer.cpp index 65d548ba1c..e236ffd217 100644 --- a/libraries/metavoxels/src/DatagramSequencer.cpp +++ b/libraries/metavoxels/src/DatagramSequencer.cpp @@ -353,7 +353,7 @@ void DatagramSequencer::sendRecordLost(const SendRecord& record) { if (_packetDropCount == 0 || record.packetNumber == _lastPacketDropped + 1) { _packetDropCount++; _lastPacketDropped = record.packetNumber; - const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 3; + const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 1; if (_packetDropCount >= CONSECUTIVE_DROPS_BEFORE_REDUCTION && record.packetNumber >= _packetRateDecreasePacketNumber) { _packetsPerGroup = qMax(_packetsPerGroup * 0.5f, 1.0f); _slowStartThreshold = _packetsPerGroup; diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 5e13f6bbc9..b0c2defd9b 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -147,28 +147,21 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { } void LimitedNodeList::changeSocketBufferSizes(int numBytes) { - // change the socket send buffer size to be 1MB - int oldBufferSize = 0; - -#ifdef Q_OS_WIN - int sizeOfInt = sizeof(oldBufferSize); -#else - unsigned int sizeOfInt = sizeof(oldBufferSize); -#endif - for (int i = 0; i < 2; i++) { - int bufferOpt = (i == 0) ? SO_SNDBUF : SO_RCVBUF; - - getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&oldBufferSize), &sizeOfInt); - - setsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&numBytes), - sizeof(numBytes)); - - QString bufferTypeString = (i == 0) ? "send" : "receive"; - + QAbstractSocket::SocketOption bufferOpt; + QString bufferTypeString; + if (i == 0) { + bufferOpt = QAbstractSocket::SendBufferSizeSocketOption; + bufferTypeString = "send"; + + } else { + bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption; + bufferTypeString = "receive"; + } + int oldBufferSize = _nodeSocket.socketOption(bufferOpt).toInt(); if (oldBufferSize < numBytes) { - int newBufferSize = 0; - getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&newBufferSize), &sizeOfInt); + _nodeSocket.setSocketOption(bufferOpt, numBytes); + int newBufferSize = _nodeSocket.socketOption(bufferOpt).toInt(); qDebug() << "Changed socket" << bufferTypeString << "buffer size from" << oldBufferSize << "to" << newBufferSize << "bytes"; From 0d07875f94ff51685bb4a33d13a1f22e90b349b6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Dec 2014 12:54:12 -0800 Subject: [PATCH 13/14] Fix overflow warning. --- interface/src/ModelUploader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ModelUploader.cpp b/interface/src/ModelUploader.cpp index e702d9db76..89b6a4c9c0 100644 --- a/interface/src/ModelUploader.cpp +++ b/interface/src/ModelUploader.cpp @@ -55,8 +55,8 @@ static const QString MODEL_URL = "/api/v1/models"; static const QString SETTING_NAME = "LastModelUploadLocation"; -static const int BYTES_PER_MEGABYTES = 1024 * 1024; -static const unsigned long MAX_SIZE = 50 * 1024 * BYTES_PER_MEGABYTES; // 50 GB (Virtually remove limit) +static const long long BYTES_PER_MEGABYTES = 1024 * 1024; +static const unsigned long long MAX_SIZE = 50 * 1024 * BYTES_PER_MEGABYTES; // 50 GB (Virtually remove limit) static const int MAX_TEXTURE_SIZE = 1024; static const int TIMEOUT = 1000; static const int MAX_CHECK = 30; From ea69dcaf29f5d802b5cd27f97a46bcc65972ef38 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 13:10:23 -0800 Subject: [PATCH 14/14] Update grid colors --- examples/libraries/gridTool.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index e222ff3adb..2462caff23 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -2,11 +2,11 @@ Grid = function(opts) { var that = {}; var colors = [ - { red: 102, green: 180, blue: 126 }, - { red: 83, green: 210, blue: 83 }, - { red: 235, green: 173, blue: 0 }, - { red: 210, green: 115, blue: 0 }, - { red: 48, green: 116, blue: 119 }, + { red: 0, green: 255, blue: 0 }, + { red: 255, green: 255, blue: 255 }, + { red: 0, green: 0, blue: 0 }, + { red: 0, green: 0, blue: 255 }, + { red: 255, green: 0, blue: 0 }, ]; var colorIndex = 0; var gridAlpha = 1.0;