From 1161f33b4502cbf51722a851a610878abf43b7f5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 14 May 2015 20:25:29 -0700 Subject: [PATCH 1/3] laser-poiner script for mouse --- examples/pointer.js | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 examples/pointer.js diff --git a/examples/pointer.js b/examples/pointer.js new file mode 100644 index 0000000000..2d7b601baa --- /dev/null +++ b/examples/pointer.js @@ -0,0 +1,76 @@ + +var lineEntityID = null; +var lineIsRezzed = false; + + +function nearLinePoint(targetPosition) { + var handPosition = MyAvatar.getRightPalmPosition(); + var along = Vec3.subtract(targetPosition, handPosition); + along = Vec3.normalize(along); + along = Vec3.multiply(along, 0.4); + return Vec3.sum(handPosition, along); +} + + +function removeLine() { + if (lineIsRezzed) { + Entities.deleteEntity(lineEntityID); + lineEntityID = null; + lineIsRezzed = false; + } +} + + +function createOrUpdateLine(event) { + var pickRay = Camera.computePickRay(event.x, event.y); + var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking + + if (lineIsRezzed) { + Entities.editEntity(lineEntityID, { + position: nearLinePoint(intersection.intersection), + dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), + lifetime: 30 // renew lifetime + }); + + } else { + lineIsRezzed = true; + lineEntityID = Entities.addEntity({ + type: "Line", + position: nearLinePoint(intersection.intersection), + dimensions: Vec3.subtract(intersection.intersection, nearLinePoint(intersection.intersection)), + color: { red: 255, green: 255, blue: 255 }, + lifetime: 30 // if someone crashes while pointing, don't leave the line there forever. + }); + } +} + + +function mousePressEvent(event) { + if (!event.isLeftButton) { + return; + } + if (lineIsRezzed) { + return; + } + createOrUpdateLine(event); + if (lineIsRezzed) { + Controller.mouseMoveEvent.connect(mouseMoveEvent); + } + } + + +function mouseMoveEvent(event) { + createOrUpdateLine(event); +} + + +function mouseReleaseEvent() { + if (lineIsRezzed) { + Controller.mouseMoveEvent.disconnect(mouseMoveEvent); + } + removeLine(); +} + + +Controller.mousePressEvent.connect(mousePressEvent); +Controller.mouseReleaseEvent.connect(mouseReleaseEvent); From e462617a6b39434fab68effbafb666e7f1aa001a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 15 May 2015 10:29:24 -0700 Subject: [PATCH 2/3] add error log debug for script fail --- libraries/script-engine/src/ScriptCache.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index 5025d02918..8f854cfdc3 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is isPending = true; bool alreadyWaiting = _scriptUsers.contains(url); _scriptUsers.insert(url, scriptUser); - + if (alreadyWaiting) { qCDebug(scriptengine) << "Already downloading script at:" << url.toString(); } else { @@ -43,7 +44,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is QNetworkRequest networkRequest = QNetworkRequest(url); networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - qCDebug(scriptengine) << "Downloading script at:" << url.toString(); + qCDebug(scriptengine) << "Downloading script at" << url.toString(); QNetworkReply* reply = networkAccessManager.get(networkRequest); connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded); } @@ -56,7 +57,7 @@ void ScriptCache::scriptDownloaded() { QUrl url = reply->url(); QList scriptUsers = _scriptUsers.values(url); _scriptUsers.remove(url); - + if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) { _scriptCache[url] = reply->readAll(); qCDebug(scriptengine) << "Done downloading script at:" << url.toString(); @@ -65,7 +66,9 @@ void ScriptCache::scriptDownloaded() { user->scriptContentsAvailable(url, _scriptCache[url]); } } else { - qCDebug(scriptengine) << "ERROR Loading file:" << reply->url().toString(); + qCWarning(scriptengine) << "Error loading script from URL " << reply->url().toString() + << "- HTTP status code is" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() + << "and error from QNetworkReply is" << reply->errorString(); foreach(ScriptUser* user, scriptUsers) { user->errorInLoadingScript(url); } @@ -73,4 +76,4 @@ void ScriptCache::scriptDownloaded() { reply->deleteLater(); } - + From 9f7a56e3e54dd7bb2355c250036220c23cdc5cd2 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 15 May 2015 11:00:28 -0700 Subject: [PATCH 3/3] Ask audio injector to delete itself. Put in null guards. Tune parameters (including higher threshold). --- .../src/EntityTreeRenderer.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 49187c3b2f..1d888bd7da 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -1111,6 +1111,9 @@ void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) { EntityItem* entity = entityTree->findEntityByEntityItemID(id); + if (!entity) { + return; + } QUuid simulatorID = entity->getSimulatorID(); if (simulatorID.isNull() || (simulatorID != myNodeID)) { return; // Only one injector per simulation, please. @@ -1124,20 +1127,24 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT const float linearVelocity = glm::length(collision.penetration) * COLLISION_PENTRATION_TO_VELOCITY; const float energy = mass * linearVelocity * linearVelocity / 2.0f; const glm::vec3 position = collision.contactPoint; - const float COLLISION_ENERGY_AT_FULL_VOLUME = 1.0f; + const float COLLISION_ENERGY_AT_FULL_VOLUME = 0.5f; const float COLLISION_MINIMUM_VOLUME = 0.001f; const float energyFactorOfFull = fmin(1.0f, energy / COLLISION_ENERGY_AT_FULL_VOLUME); if (energyFactorOfFull < COLLISION_MINIMUM_VOLUME) { return; } - SharedSoundPointer sound = DependencyManager::get().data()->getSound(QUrl(collisionSoundURL)); - if (!sound->isReady()) { + auto soundCache = DependencyManager::get(); + if (soundCache.isNull()) { + return; + } + SharedSoundPointer sound = soundCache.data()->getSound(QUrl(collisionSoundURL)); + if (sound.isNull() || !sound->isReady()) { return; } // This is a hack. Quiet sound aren't really heard at all, so we compress everything to the range [1-c, 1], if we play it all. - const float COLLISION_SOUND_COMPRESSION_RANGE = 0.95f; + const float COLLISION_SOUND_COMPRESSION_RANGE = 0.7f; float volume = energyFactorOfFull; volume = (volume * COLLISION_SOUND_COMPRESSION_RANGE) + (1.0f - COLLISION_SOUND_COMPRESSION_RANGE); @@ -1148,6 +1155,7 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT options.volume = volume; AudioInjector* injector = new AudioInjector(sound.data(), options); injector->setLocalAudioInterface(_localAudioInterface); + injector->triggerDeleteAfterFinish(); QThread* injectorThread = new QThread(); injectorThread->setObjectName("Audio Injector Thread"); injector->moveToThread(injectorThread); @@ -1168,7 +1176,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons } // Don't respond to small continuous contacts. It causes deadlocks when locking the entityTree. // Note that any entity script is likely to Entities.getEntityProperties(), which locks the tree. - const float COLLISION_MINUMUM_PENETRATION = 0.001; + const float COLLISION_MINUMUM_PENETRATION = 0.005; if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) { return; }