diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index d9109703cb..fb9b2a94a0 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,8 @@ Agent::Agent(NLPacket& packet) : DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false)) { DependencyManager::get()->setPacketSender(&_entityEditSender); - + + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -110,11 +112,12 @@ void Agent::run() { ThreadedAssignment::commonInit(AGENT_LOGGING_NAME, NodeType::Agent); auto nodeList = DependencyManager::get(); - nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() - << NodeType::AudioMixer - << NodeType::AvatarMixer - << NodeType::EntityServer - ); + nodeList->addSetOfNodeTypesToNodeInterestSet({ + NodeType::AudioMixer, + NodeType::AvatarMixer, + NodeType::EntityServer, + NodeType::AssetServer + }); _pingTimer = new QTimer(this); connect(_pingTimer, SIGNAL(timeout()), SLOT(sendPingRequests())); diff --git a/examples/acScripts/baseballCrowd.js b/examples/acScripts/baseballCrowd.js new file mode 100644 index 0000000000..5007c64b16 --- /dev/null +++ b/examples/acScripts/baseballCrowd.js @@ -0,0 +1,21 @@ +// +// baseballCrowd.js +// examples/acScripts +// +// Created by Stephen Birarda on 10/20/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var crowd1 = SoundCache.getSound("atp:0e921b644464d56d5b412ea2ea1d83f8ff3f7506c4b0471ea336a4770daf3b82.wav"); + +function maybePlaySound(deltaTime) { + if (crowd1.downloaded && !crowd1.isPlaying) { + Audio.playSound(crowd1, { position: { x: 0, y: 0, z: 0}, loop: true}); + Script.update.disconnect(maybePlaySound); + } +} + +Script.update.connect(maybePlaySound); diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 80fb4c8e40..612aec8739 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -579,7 +579,8 @@ function MyController(hand, triggerAction) { timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, relativeRotation: this.offsetRotation, - lifetime: ACTION_LIFETIME + lifetime: ACTION_LIFETIME, + kinematic: (grabbableData.kinematicGrab && (grabbableData.kinematicGrab === true)) }); if (this.actionID === NULL_ACTION_ID) { this.actionID = null; diff --git a/examples/toys/baseball.js b/examples/toys/baseball.js new file mode 100755 index 0000000000..f3f26a1f4b --- /dev/null +++ b/examples/toys/baseball.js @@ -0,0 +1,92 @@ +// +// baseball.js +// examples/toys +// +// Created by Stephen Birarda on 10/20/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var ROBOT_MODEL = "atp:ea02100c2ee63a8b9c0495557f32041be18ec94def157592e84a816665ce2f6e.fbx"; +var ROBOT_POSITION = { x: -0.54, y: 1.21, z: 2.57 } + +var BAT_MODEL = "atp:07bdd769a57ff15ebe9331ae4e2c2eae8886a6792b4790cce03b4716eb3a81c7.fbx" +var BAT_COLLISION_MODEL = "atp:1211ee12bc8ab0bb744e8582e15e728a00ca70a808550fc46d7284799b9a868a.obj" + +// add the fresh robot at home plate +var robot = Entities.addEntity({ + name: 'Robot', + type: 'Model', + modelURL: ROBOT_MODEL, + position: ROBOT_POSITION, + animation: { + url: ROBOT_MODEL + } +}); + +// add the bat +var bat = Entities.addEntity({ + name: 'Bat', + type: 'Model', + modelURL: BAT_MODEL +}) + +var lastTriggerValue = 0.0; + +function checkTriggers() { + var rightTrigger = Controller.getTriggerValue(1); + + if (rightTrigger == 0) { + if (lastTriggerValue > 0) { + // the trigger was just released, play out to the last frame of the swing + Entities.editEntity(robot, { + animation: { + running: true, + currentFrame: 21, + lastFrame: 115 + } + }); + } + } else { + if (lastTriggerValue == 0) { + // the trigger was just depressed, start the swing + Entities.editEntity(robot, { + animation: { + running: true, + currentFrame: 0, + lastFrame: 21 + } + }); + } + } + + lastTriggerValue = rightTrigger; +} + +var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position +var ACTION_LIFETIME = 15; // seconds + +function moveBat() { + var forearmPosition = Entities.getJointPosition(robot, 40); + var forearmRotation = Entities.getJointRotation(robot, 40); + + Vec3.print("forearmPosition=", forearmPosition); + + Entities.addAction("spring", bat, { + targetPosition: forearmPosition, + targetRotation: forearmRotation, + tag: "bat-to-forearm", + linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, + angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME + lifetime: ACTION_LIFETIME + }); +} + +function update() { + checkTriggers(); +} + +// hook the update so we can check controller triggers +Script.update.connect(update); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e604bdb925..a7c2ff09f4 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -575,3 +575,28 @@ bool RenderableModelEntityItem::contains(const glm::vec3& point) const { return false; } + +glm::vec3 RenderableModelEntityItem::getJointPosition(int jointIndex) const { + glm::vec3 position; + + if (_model) { + if (!_model->getJointPositionInWorldFrame(jointIndex, position)) { + position = glm::vec3(); + } + } + + return position; +} + +glm::quat RenderableModelEntityItem::getJointRotation(int jointIndex) const { + glm::quat rotation; + + if (_model) { + if (!_model->getJointRotationInWorldFrame(jointIndex, rotation)) { + rotation = glm::quat(); + } + } + + return rotation; +} + diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 4dc1cced48..64629ad291 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -67,6 +67,9 @@ public: void computeShapeInfo(ShapeInfo& info); virtual bool contains(const glm::vec3& point) const; + + virtual glm::vec3 getJointPosition(int jointIndex) const override; + virtual glm::quat getJointRotation(int jointIndex) const override; private: void remapTextures(); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 01d46e0a91..f18e216bb3 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -681,82 +681,75 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, return result; } -glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { +EntityItemPointer EntityScriptingInterface::checkForTreeEntityAndTypeMatch(const QUuid& entityID, + EntityTypes::EntityType entityType) { if (!_entityTree) { - return glm::vec3(0.0f); + return EntityItemPointer(); } - + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID; + qDebug() << "EntityScriptingInterface::checkForTreeEntityAndTypeMatch - no entity with ID" << entityID; + return entity; + } + + if (entityType != EntityTypes::Unknown && entity->getType() != entityType) { + return EntityItemPointer(); + } + + return entity; +} + +glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { + auto polyVoxEntity = std::dynamic_pointer_cast(entity); + return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); + } else { return glm::vec3(0.0f); } - - EntityTypes::EntityType entityType = entity->getType(); - if (entityType != EntityTypes::PolyVox) { - return glm::vec3(0.0f); - } - - auto polyVoxEntity = std::dynamic_pointer_cast(entity); - return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); } glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { - if (!_entityTree) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { + auto polyVoxEntity = std::dynamic_pointer_cast(entity); + return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); + } else { return glm::vec3(0.0f); } - - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); - if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID; - return glm::vec3(0.0f); - } - - EntityTypes::EntityType entityType = entity->getType(); - if (entityType != EntityTypes::PolyVox) { - return glm::vec3(0.0f); - } - - auto polyVoxEntity = std::dynamic_pointer_cast(entity); - return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); } glm::vec3 EntityScriptingInterface::voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords) { - if (!_entityTree) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { + auto polyVoxEntity = std::dynamic_pointer_cast(entity); + return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); + } else { return glm::vec3(0.0f); } - - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); - if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToLocalCoords no entity with ID" << entityID; - return glm::vec3(0.0f); - } - - EntityTypes::EntityType entityType = entity->getType(); - if (entityType != EntityTypes::PolyVox) { - return glm::vec3(0.0f); - } - - auto polyVoxEntity = std::dynamic_pointer_cast(entity); - return polyVoxEntity->voxelCoordsToLocalCoords(voxelCoords); } glm::vec3 EntityScriptingInterface::localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords) { - if (!_entityTree) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::PolyVox)) { + auto polyVoxEntity = std::dynamic_pointer_cast(entity); + return polyVoxEntity->localCoordsToVoxelCoords(localCoords); + } else { return glm::vec3(0.0f); } - - EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); - if (!entity) { - qCDebug(entities) << "EntityScriptingInterface::localCoordsToVoxelCoords no entity with ID" << entityID; - return glm::vec3(0.0f); - } - - EntityTypes::EntityType entityType = entity->getType(); - if (entityType != EntityTypes::PolyVox) { - return glm::vec3(0.0f); - } - - auto polyVoxEntity = std::dynamic_pointer_cast(entity); - return polyVoxEntity->localCoordsToVoxelCoords(localCoords); +} + +glm::vec3 EntityScriptingInterface::getJointPosition(const QUuid& entityID, int jointIndex) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto modelEntity = std::dynamic_pointer_cast(entity); + return modelEntity->getJointPosition(jointIndex); + } else { + return glm::vec3(0.0f); + } +} + +glm::quat EntityScriptingInterface::getJointRotation(const QUuid& entityID, int jointIndex) { + if (auto entity = checkForTreeEntityAndTypeMatch(entityID, EntityTypes::Model)) { + auto modelEntity = std::dynamic_pointer_cast(entity); + return modelEntity->getJointRotation(jointIndex); + } else { + return glm::quat(); + } } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index d764cd7bab..4578c2d7ff 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -150,6 +150,9 @@ public slots: Q_INVOKABLE glm::vec3 worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords); Q_INVOKABLE glm::vec3 voxelCoordsToLocalCoords(const QUuid& entityID, glm::vec3 voxelCoords); Q_INVOKABLE glm::vec3 localCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 localCoords); + + Q_INVOKABLE glm::vec3 getJointPosition(const QUuid& entityID, int jointIndex); + Q_INVOKABLE glm::quat getJointRotation(const QUuid& entityID, int jointIndex); signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); @@ -182,6 +185,9 @@ private: bool setVoxels(QUuid entityID, std::function actor); bool setPoints(QUuid entityID, std::function actor); void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties); + + EntityItemPointer checkForTreeEntityAndTypeMatch(const QUuid& entityID, + EntityTypes::EntityType entityType = EntityTypes::Unknown); /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index e8ffcab3e7..66d46bcf4c 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -120,6 +120,9 @@ public: virtual bool shouldBePhysical() const; static void cleanupLoadedAnimations(); + + virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); } + virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); } private: void setAnimationSettings(const QString& value); // only called for old bitstream format diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index b7f1205847..6a1b46340c 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -89,7 +89,6 @@ AssetRequest* AssetClient::createRequest(const QString& hash, const QString& ext // Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case) request->moveToThread(thread()); - request->setParent(this); return request; } else { @@ -105,7 +104,6 @@ AssetUpload* AssetClient::createUpload(const QString& filename) { auto upload = new AssetUpload(filename); upload->moveToThread(thread()); - upload->setParent(this); return upload; } else { @@ -118,7 +116,6 @@ AssetUpload* AssetClient::createUpload(const QByteArray& data, const QString& ex auto upload = new AssetUpload(data, extension); upload->moveToThread(thread()); - upload->setParent(this); return upload; } else { diff --git a/libraries/octree/src/OctreeHeadlessViewer.h b/libraries/octree/src/OctreeHeadlessViewer.h index 605db15cd2..cebfa5a928 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.h +++ b/libraries/octree/src/OctreeHeadlessViewer.h @@ -46,6 +46,7 @@ public slots: // setters for camera attributes void setPosition(const glm::vec3& position) { _viewFrustum.setPosition(position); } void setOrientation(const glm::quat& orientation) { _viewFrustum.setOrientation(orientation); } + void setKeyholeRadius(float keyholdRadius) { _viewFrustum.setKeyholeRadius(keyholdRadius); } // setters for LOD and PPS void setVoxelSizeScale(float sizeScale) { _voxelSizeScale = sizeScale; } diff --git a/libraries/render-utils/src/GlWindow.cpp b/libraries/render-utils/src/GlWindow.cpp index 78ac046b59..248b9305e2 100644 --- a/libraries/render-utils/src/GlWindow.cpp +++ b/libraries/render-utils/src/GlWindow.cpp @@ -43,11 +43,9 @@ bool GlWindow::makeCurrent() { qDebug() << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); }); - #ifndef QT_NO_DEBUG - QOpenGLContext * currentContext = - #endif - QOpenGLContext::currentContext(); + QOpenGLContext * currentContext = QOpenGLContext::currentContext(); Q_ASSERT(_context == currentContext); + return makeCurrentResult; } diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 80327b7e54..30b72891dd 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -147,7 +147,7 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ModelRender::Locatio batch.setResourceTexture(ModelRender::DIFFUSE_MAP_SLOT, textureCache->getGrayTexture()); } } else { - batch.setResourceTexture(ModelRender::DIFFUSE_MAP_SLOT, textureCache->getGrayTexture()); + batch.setResourceTexture(ModelRender::DIFFUSE_MAP_SLOT, textureCache->getWhiteTexture()); } // Normal map diff --git a/libraries/ui/src/VrMenu.cpp b/libraries/ui/src/VrMenu.cpp index a2cc7f0214..57df4d5306 100644 --- a/libraries/ui/src/VrMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -108,13 +108,10 @@ void VrMenu::addMenu(QMenu* menu) { Q_ASSERT(false); } QVariant returnedValue; - #ifndef QT_NO_DEBUG - bool invokeResult = - #endif - QMetaObject::invokeMethod(this, "addMenu", Qt::DirectConnection, - Q_RETURN_ARG(QVariant, returnedValue), - Q_ARG(QVariant, QVariant::fromValue(qmlParent)), - Q_ARG(QVariant, QVariant::fromValue(menu->title()))); + bool invokeResult = QMetaObject::invokeMethod(this, "addMenu", Qt::DirectConnection, + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, QVariant::fromValue(qmlParent)), + Q_ARG(QVariant, QVariant::fromValue(menu->title()))); Q_ASSERT(invokeResult); QObject* result = returnedValue.value(); Q_ASSERT(result); @@ -150,13 +147,11 @@ void VrMenu::addAction(QMenu* menu, QAction* action) { QObject* menuQml = findMenuObject(userData->uuid.toString()); Q_ASSERT(menuQml); QVariant returnedValue; - #ifndef QT_NO_DEBUG - bool invokeResult = - #endif - QMetaObject::invokeMethod(this, "addItem", Qt::DirectConnection, - Q_RETURN_ARG(QVariant, returnedValue), - Q_ARG(QVariant, QVariant::fromValue(menuQml)), - Q_ARG(QVariant, QVariant::fromValue(action->text()))); + + bool invokeResult = QMetaObject::invokeMethod(this, "addItem", Qt::DirectConnection, + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, QVariant::fromValue(menuQml)), + Q_ARG(QVariant, QVariant::fromValue(action->text()))); Q_ASSERT(invokeResult); QObject* result = returnedValue.value(); Q_ASSERT(result); @@ -173,14 +168,11 @@ void VrMenu::insertAction(QAction* before, QAction* action) { } QObject* menu = beforeQml->parent(); QVariant returnedValue; - #ifndef QT_NO_DEBUG - bool invokeResult = - #endif - QMetaObject::invokeMethod(this, "insertItem", Qt::DirectConnection, - Q_RETURN_ARG(QVariant, returnedValue), - Q_ARG(QVariant, QVariant::fromValue(menu)), - Q_ARG(QVariant, QVariant::fromValue(beforeQml)), - Q_ARG(QVariant, QVariant::fromValue(action->text()))); + bool invokeResult = QMetaObject::invokeMethod(this, "insertItem", Qt::DirectConnection, + Q_RETURN_ARG(QVariant, returnedValue), + Q_ARG(QVariant, QVariant::fromValue(menu)), + Q_ARG(QVariant, QVariant::fromValue(beforeQml)), + Q_ARG(QVariant, QVariant::fromValue(action->text()))); Q_ASSERT(invokeResult); QObject* result = returnedValue.value(); Q_ASSERT(result); @@ -199,9 +191,5 @@ void VrMenu::removeAction(QAction* action) { bool invokeResult = QMetaObject::invokeMethod(this, "removeItem", Qt::DirectConnection, Q_ARG(QVariant, QVariant::fromValue(menu)), Q_ARG(QVariant, QVariant::fromValue(item))); -#ifndef QT_NO_DEBUG Q_ASSERT(invokeResult); -#else - Q_UNUSED(invokeResult); -#endif }