diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 833b53b729..0a455891f9 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -254,10 +254,10 @@ void AvatarMixer::broadcastAvatarData() { // potentially update the max full rate distance for this frame maxAvatarDistanceThisFrame = std::max(maxAvatarDistanceThisFrame, distanceToAvatar); - if (distanceToAvatar != 0.0f + if (distanceToAvatar != 0.0f && distribution(generator) > (nodeData->getFullRateDistance() / distanceToAvatar)) { - return; - } + return; + } AvatarDataSequenceNumber lastSeqToReceiver = nodeData->getLastBroadcastSequenceNumber(otherNode->getUUID()); AvatarDataSequenceNumber lastSeqFromSender = otherNodeData->getLastReceivedSequenceNumber(); diff --git a/examples/edit.js b/examples/edit.js index c45e66986a..7a16030afc 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1510,7 +1510,7 @@ PropertiesTool = function(opts) { if (entity.properties.rotation !== undefined) { entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation); } - if (entity.properties.keyLight.direction !== undefined) { + if (entity.properties.keyLight !== undefined && entity.properties.keyLight.direction !== undefined) { entity.properties.keyLight.direction = Vec3.multiply(RADIANS_TO_DEGREES, Vec3.toPolar(entity.properties.keyLight.direction)); entity.properties.keyLight.direction.z = 0.0; } @@ -1541,7 +1541,7 @@ PropertiesTool = function(opts) { var rotation = data.properties.rotation; data.properties.rotation = Quat.fromPitchYawRollDegrees(rotation.x, rotation.y, rotation.z); } - if (data.properties.keyLight.direction !== undefined) { + if (data.properties.keyLight !== undefined && data.properties.keyLight.direction !== undefined) { data.properties.keyLight.direction = Vec3.fromPolar( data.properties.keyLight.direction.x * DEGREES_TO_RADIANS, data.properties.keyLight.direction.y * DEGREES_TO_RADIANS); } diff --git a/examples/example/metavoxels/metavoxels.js b/examples/example/metavoxels/metavoxels.js deleted file mode 100644 index 32177cdcba..0000000000 --- a/examples/example/metavoxels/metavoxels.js +++ /dev/null @@ -1,41 +0,0 @@ -// -// metavoxels.js -// examples -// -// Copyright 2014 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 -// - -Script.setInterval(function() { - var spanner; - if (Math.random() < 0.5) { - spanner = new Sphere(); - } else { - spanner = new Cuboid(); - spanner.aspectX = 0.1 + Math.random() * 1.9; - spanner.aspectY = 0.1 + Math.random() * 1.9; - } - spanner.scale = 0.1 + Math.random() * 1.9; - spanner.rotation = Quat.fromPitchYawRollDegrees(Math.random() * 360.0, Math.random() * 360.0, Math.random() * 360.0); - spanner.translation = { x: 10.0 + Math.random() * 10.0, y: 10.0 + Math.random() * 10.0, z: 10.0 + Math.random() * 10.0 }; - - if (Math.random() < 0.5) { - var material = new MaterialObject(); - if (Math.random() < 0.5) { - material.diffuse = "http://www.fungibleinsight.com/faces/grass.jpg"; - } else { - material.diffuse = "http://www.fungibleinsight.com/faces/soil.jpg"; - } - Metavoxels.setVoxelMaterial(spanner, material); - - } else if (Math.random() < 0.5) { - Metavoxels.setVoxelColor(spanner, { red: Math.random() * 255.0, green: Math.random() * 255.0, - blue: Math.random() * 255.0 }); - - } else { - Metavoxels.setVoxelColor(spanner, { red: 0, green: 0, blue: 0, alpha: 0 }); - } -}, 1000); - diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index b3d7a5f6b6..412b413b2b 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -830,7 +830,7 @@ elZoneKeyLightColorRed.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightColorGreen.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightColorBlue.addEventListener('change', zoneKeyLightColorChangeFunction); - elZoneKeyLightIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('intensity','keyLight')); + elZoneKeyLightIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('keyLight','intensity')); elZoneKeyLightAmbientIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('keyLight','ambientIntensity')); var zoneKeyLightDirectionChangeFunction = createEmitGroupVec3PropertyUpdateFunction('keyLight','direction', elZoneKeyLightDirectionX, elZoneKeyLightDirectionY, elZoneKeyLightDirectionZ); elZoneKeyLightDirectionX.addEventListener('change', zoneKeyLightDirectionChangeFunction); @@ -1520,7 +1520,7 @@
Ambient URL
- +
diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index f38073f389..c10a8c23fe 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -47,6 +47,7 @@ if (this.painting) { return; } + this.whichHand = this.hand; if (this.hand === RIGHT_HAND) { this.getHandPosition = MyAvatar.getRightPalmPosition; this.getHandRotation = MyAvatar.getRightPalmRotation; @@ -183,6 +184,9 @@ }, releaseGrab: function() { + if(this.hand !== this.whichHand) { + return; + } this.stopPainting(); }, @@ -241,10 +245,8 @@ Overlays.deleteOverlay(this.laserPointer); // this.eraseBoard(); } - }; - // entity scripts always need to return a newly constructed object of our type return new Whiteboard(); }); \ No newline at end of file diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index cbc26da670..701112e1a8 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -16,186 +16,199 @@ Script.include("../../libraries/utils.js"); var scriptURL = Script.resolvePath("whiteboardEntityScript.js"); +var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/whiteboard.fbx"; + +var colorIndicatorBorderModelURL = "https://s3.amazonaws.com/hifi-public/eric/models/colorIndicatorBorder.fbx"; +var eraserModelURL = "https://s3.amazonaws.com/hifi-public/eric/models/eraser.fbx"; +var surfaceModelURL = "https://s3.amazonaws.com/hifi-public/eric/models/boardSurface.fbx"; var rotation = Quat.safeEulerAngles(Camera.getOrientation()); rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(rotation))); -center.y += 0.4; + +var whiteboardDimensions, colorIndicatorBoxDimensions, colorIndicatorBox, eraser, blocker; +var colorBoxes = []; var colors = [ - hexToRgb("#2F8E84"), hexToRgb("#66CCB3"), hexToRgb("#A43C37"), hexToRgb("#491849"), hexToRgb("#6AB03B"), hexToRgb("#993369"), - hexToRgb("#9B47C2") + hexToRgb("#000000") ]; -//WHITEBOARD -var whiteboardDimensions = { - x: 2, - y: 1.5, - z: 0.08 -}; var whiteboard = Entities.addEntity({ type: "Model", - modelURL: "https://hifi-public.s3.amazonaws.com/ozan/support/for_eric/whiteboard/whiteboard.fbx", - name: "whiteboard", + shapeType: "box", + modelURL: modelURL, + name: "whiteboard base", position: center, rotation: rotation, - script: scriptURL, - dimensions: whiteboardDimensions, - color: { - red: 255, - green: 255, - blue: 255 - } }); - -// COLOR INDICATOR BOX -var colorIndicatorDimensions = { - x: whiteboardDimensions.x, - y: 0.05, - z: 0.02 +var colorIndicatorPosition = { + x: center.x, + y: center.y, + z: center.z }; -scriptURL = Script.resolvePath("colorIndicatorEntityScript.js"); -var colorIndicatorPosition = Vec3.sum(center, { - x: 0, - y: whiteboardDimensions.y / 2 + colorIndicatorDimensions.y / 2, - z: 0 -}); -var colorIndicatorBox = Entities.addEntity({ - type: "Box", - name: "Color Indicator", - color: colors[0], - rotation: rotation, +colorIndicatorPosition.y += 1.55; +colorIndicatorPosition = Vec3.sum(colorIndicatorPosition, Vec3.multiply(-0.1, Quat.getFront(rotation))); +var colorIndicatorBorder = Entities.addEntity({ + type: "Model", position: colorIndicatorPosition, - dimensions: colorIndicatorDimensions, - script: scriptURL, - userData: JSON.stringify({ - whiteboard: whiteboard - }) + modelURL: colorIndicatorBorderModelURL, + rotation: rotation, + shapeType: "box" }); -Entities.editEntity(whiteboard, { +var surfaceCenter = Vec3.sum(center, Vec3.multiply(-0.1, Quat.getFront(rotation))); +surfaceCenter.y += 0.6; +var drawingSurface = Entities.addEntity({ + type: "Model", + modelURL: surfaceModelURL, + shapeType: "box", + name: "whiteboard surface", + position: surfaceCenter, + script: scriptURL, + rotation: rotation, userData: JSON.stringify({ color: { currentColor: colors[0] - }, - colorIndicator: colorIndicatorBox - }) -}); - -//COLOR BOXES -var direction = Quat.getRight(rotation); -var colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2)); -var colorBoxes = []; -var colorSquareDimensions = { - x: (whiteboardDimensions.x / 2) / (colors.length - 1), - y: 0.1, - z: 0.05 -}; -colorBoxPosition.y += whiteboardDimensions.y / 2 + colorIndicatorDimensions.y + colorSquareDimensions.y / 2; -var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 2); -var scriptURL = Script.resolvePath("colorSelectorEntityScript.js"); -for (var i = 0; i < colors.length; i++) { - var colorBox = Entities.addEntity({ - type: "Box", - name: "Color Selector", - position: colorBoxPosition, - dimensions: colorSquareDimensions, - rotation: rotation, - color: colors[i], - script: scriptURL, - userData: JSON.stringify({ - whiteboard: whiteboard, - colorIndicator: colorIndicatorBox - }) - }); - colorBoxes.push(colorBox); - colorBoxPosition = Vec3.sum(colorBoxPosition, spaceBetweenColorBoxes); -} - - -// BLACK BOX -var blackBoxDimensions = { - x: 0.3, - y: 0.3, - z: 0.01 -}; - -colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2 + blackBoxDimensions.x / 2 - 0.01)); -colorBoxPosition.y += 0.3; -var fragShaderURL = Script.resolvePath('blackInk.fs?v1' + Math.random()); -var blackBox = Entities.addEntity({ - type: 'Box', - name: "Black Color", - position: colorBoxPosition, - dimensions: blackBoxDimensions, - rotation: rotation, - color: { - red: 0, - green: 0, - blue: 0 - }, - script: scriptURL, - userData: JSON.stringify({ - whiteboard: whiteboard, - version: 2, - ProceduralEntity: { - shaderUrl: fragShaderURL } }) + }); +var lightPosition = Vec3.sum(center, Vec3.multiply(-3, Quat.getFront(rotation))); +var light = Entities.addEntity({ + type: 'Light', + name: 'whiteboard light', + position: lightPosition, + dimensions: {x: 10, y: 10, z: 10}, + intensity: 2, + color: {red: 255, green: 255, blue: 255} +}); -var eraseBoxDimensions = { - x: 0.5, - y: 0.1, - z: 0.01 -}; - - -var eraseBoxPosition = Vec3.sum(center, Vec3.multiply(direction, whiteboardDimensions.x / 2 + eraseBoxDimensions.x / 2 + 0.01)); -eraseBoxPosition.y += 0.3; +var eraserPosition = Vec3.sum(center, {x: 0, y: 2.05, z: 0 }); +eraserPosition = Vec3.sum(eraserPosition, Vec3.multiply(-0.1, rotation)); scriptURL = Script.resolvePath("eraseBoardEntityScript.js"); -var eraseAllText = Entities.addEntity({ - type: "Text", - position: eraseBoxPosition, +var eraser = Entities.addEntity({ + type: "Model", + modelURL: eraserModelURL, + position: eraserPosition, name: "Eraser", script: scriptURL, rotation: rotation, - dimensions: eraseBoxDimensions, - backgroundColor: { - red: 0, - green: 60, - blue: 0 - }, - textColor: { - red: 255, - green: 10, - blue: 10 - }, - text: "ERASE BOARD", - lineHeight: 0.07, userData: JSON.stringify({ - whiteboard: whiteboard + whiteboard: drawingSurface }) }); +Script.setTimeout(function() { + whiteboardDimensions = Entities.getEntityProperties(whiteboard, "naturalDimensions").naturalDimensions; + colorIndicatorBorderDimensions = Entities.getEntityProperties(colorIndicatorBorder, "naturalDimensions").naturalDimensions; + setUp(); +}, 2000) +function setUp() { + var blockerPosition = Vec3.sum(center, {x: 0, y: -1, z: 0 }); + blockerPosition = Vec3.sum(blockerPosition, Vec3.multiply(-1, Quat.getFront(rotation))); + blocker = Entities.addEntity({ + type: "Box", + rotation: rotation, + position: blockerPosition, + dimensions: {x: whiteboardDimensions.x, y: 1, z: 0.1}, + shapeType: "box", + visible: false + }); + + var eraseModelDimensions = Entities.getEntityProperties(eraser, "naturalDimensions").naturalDimensions; + Entities.editEntity(eraser, {dimensions: eraseModelDimensions}); + Entities.editEntity(colorIndicatorBorder, {dimensions: colorIndicatorBorderDimensions}); + + scriptURL = Script.resolvePath("colorIndicatorEntityScript.js"); + var colorIndicatorPosition = Vec3.sum(center, { + x: 0, + y: whiteboardDimensions.y / 2 + colorIndicatorBorderDimensions.y / 2, + z: 0 + }); + colorIndicatorPosition = Vec3.sum(colorIndicatorPosition, Vec3.multiply(-.1, Quat.getFront(rotation))); + var colorIndicatorBoxDimensions = Vec3.multiply(colorIndicatorBorderDimensions, 0.9); + colorIndicatorBox = Entities.addEntity({ + type: "Box", + name: "Color Indicator", + color: colors[0], + rotation: rotation, + position: colorIndicatorPosition, + dimensions: colorIndicatorBoxDimensions, + script: scriptURL, + userData: JSON.stringify({ + whiteboard: drawingSurface + }) + }); + + Entities.editEntity(drawingSurface, { + userData: JSON.stringify({ + color: { + currentColor: colors[0] + }, + colorIndicator: colorIndicatorBox + }) + }); + + //COLOR BOXES + var direction = Quat.getRight(rotation); + var colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2)); + var colorSquareDimensions = { + x: 0.13, + y: 0.13, + z: 0.002 + }; + + var palleteDepthOffset = -0.07; + var palleteHeightOffset = -0.28; + + colorBoxPosition = Vec3.sum(colorBoxPosition, Vec3.multiply(palleteDepthOffset, Quat.getFront(rotation))); + colorBoxPosition.y += palleteHeightOffset; + var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 1.76); + var palleteXOffset = Vec3.multiply(direction, 0.43); + colorBoxPosition = Vec3.sum(colorBoxPosition, palleteXOffset); + var scriptURL = Script.resolvePath("colorSelectorEntityScript.js"); + for (var i = 0; i < colors.length; i++) { + var colorBox = Entities.addEntity({ + type: "Box", + name: "Color Selector", + position: colorBoxPosition, + dimensions: colorSquareDimensions, + rotation: rotation, + color: colors[i], + script: scriptURL, + userData: JSON.stringify({ + whiteboard: drawingSurface, + colorIndicator: colorIndicatorBox + }) + }); + colorBoxes.push(colorBox); + colorBoxPosition = Vec3.sum(colorBoxPosition, spaceBetweenColorBoxes); + } + +} + function cleanup() { Entities.deleteEntity(whiteboard); - Entities.deleteEntity(eraseAllText); - Entities.deleteEntity(blackBox); + Entities.deleteEntity(drawingSurface); + Entities.deleteEntity(colorIndicatorBorder); + Entities.deleteEntity(eraser); Entities.deleteEntity(colorIndicatorBox); + Entities.deleteEntity(blocker); + Entities.deleteEntity(light); colorBoxes.forEach(function(colorBox) { Entities.deleteEntity(colorBox); }); } + // Uncomment this line to delete whiteboard and all associated entity on script close -Script.scriptEnding.connect(cleanup); \ No newline at end of file +// Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json index 682e0be1bf..515f6e96fe 100644 --- a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json +++ b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json @@ -197,7 +197,7 @@ "id": "rightHandOpen", "type": "clip", "data": { - "url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_right_hand.fbx", + "url": "https://hifi-public.s3.amazonaws.com/ozan/anim/grab/grab_right.fbx", "startFrame": 0.0, "endFrame": 0.0, "timeScale": 1.0, @@ -209,9 +209,9 @@ "id": "rightHandClose", "type": "clip", "data": { - "url": "http://hifi-public.s3.amazonaws.com/ozan/anim/squeeze_hands/right_hand_anim.fbx", - "startFrame": 15.0, - "endFrame": 15.0, + "url": "https://hifi-public.s3.amazonaws.com/ozan/anim/grab/grab_right.fbx", + "startFrame": 10.0, + "endFrame": 10.0, "timeScale": 1.0, "loopFlag": true }, @@ -346,7 +346,7 @@ "id": "leftHandOpen", "type": "clip", "data": { - "url": "http://hifi-public.s3.amazonaws.com/ozan/anim/hand_anims/point_left_hand.fbx", + "url": "https://hifi-public.s3.amazonaws.com/ozan/anim/grab/grab_left.fbx", "startFrame": 0.0, "endFrame": 0.0, "timeScale": 1.0, @@ -358,9 +358,9 @@ "id": "leftHandClose", "type": "clip", "data": { - "url": "http://hifi-public.s3.amazonaws.com/ozan/anim/squeeze_hands/left_hand_anim.fbx", - "startFrame": 15.0, - "endFrame": 15.0, + "url": "https://hifi-public.s3.amazonaws.com/ozan/anim/grab/grab_left.fbx", + "startFrame": 10.0, + "endFrame": 10.0, "timeScale": 1.0, "loopFlag": true }, diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index b528b67745..d4980596dd 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -313,7 +313,9 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) { bool adjustedFormatForAudioDevice(const QAudioDeviceInfo& audioDevice, const QAudioFormat& desiredAudioFormat, QAudioFormat& adjustedAudioFormat) { - if (!audioDevice.isFormatSupported(desiredAudioFormat)) { + // FIXME: directly using 24khz has a bug somewhere that causes channels to be swapped. + // Continue using our internal resampler, for now. + if (true || !audioDevice.isFormatSupported(desiredAudioFormat)) { qCDebug(audioclient) << "The desired format for audio I/O is" << desiredAudioFormat; qCDebug(audioclient, "The desired audio format is not supported by this device"); @@ -321,7 +323,7 @@ bool adjustedFormatForAudioDevice(const QAudioDeviceInfo& audioDevice, adjustedAudioFormat = desiredAudioFormat; adjustedAudioFormat.setChannelCount(2); - if (audioDevice.isFormatSupported(adjustedAudioFormat)) { + if (false && audioDevice.isFormatSupported(adjustedAudioFormat)) { return true; } else { adjustedAudioFormat.setChannelCount(1); diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 3f1e668cd0..342f995de7 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -50,7 +50,7 @@ AvatarSharedPointer AvatarHashMap::addAvatar(const QUuid& sessionUUID, const QWe avatar->setOwningAvatarMixer(mixerWeakPointer); QWriteLocker locker(&_hashLock); _avatarHash.insert(sessionUUID, avatar); - + emit avatarAddedEvent(sessionUUID); return avatar; } @@ -137,13 +137,16 @@ void AvatarHashMap::processKillAvatar(QSharedPointer packet, SharedNod // read the node id QUuid sessionUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); removeAvatar(sessionUUID); + } void AvatarHashMap::removeAvatar(const QUuid& sessionUUID) { QWriteLocker locker(&_hashLock); _avatarHash.remove(sessionUUID); + emit avatarRemovedEvent(sessionUUID); } void AvatarHashMap::sessionUUIDChanged(const QUuid& sessionUUID, const QUuid& oldUUID) { _lastOwnerSessionUUID = oldUUID; + emit avatarSessionChangedEvent(sessionUUID, oldUUID); } diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 93364eb1ef..a125784cd8 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -34,6 +34,11 @@ public: void withAvatarHash(std::function); int size() { return _avatarHash.size(); } +signals: + void avatarAddedEvent(const QUuid& sessionUUID); + void avatarRemovedEvent(const QUuid& sessionUUID); + void avatarSessionChangedEvent(const QUuid& sessionUUID,const QUuid& oldUUID); + public slots: bool isAvatarInRange(const glm::vec3 & position, const float range); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 68719cd265..259a82e4eb 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -775,7 +775,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons } // Don't respond to small continuous contacts. const float COLLISION_MINUMUM_PENETRATION = 0.002f; - if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) { + if ((collision.type == CONTACT_EVENT_TYPE_CONTINUE) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) { return; } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index f012ba6eee..cce3045049 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -736,18 +736,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // is sending us data with a known "last simulated" time. That time is likely in the past, and therefore // this "new" data is actually slightly out of date. We calculate the time we need to skip forward and // use our simulation helper routine to get a best estimate of where the entity should be. - const float MIN_TIME_SKIP = 0.0f; - const float MAX_TIME_SKIP = 1.0f; // in seconds - float skipTimeForward = glm::clamp((float)(now - lastSimulatedFromBufferAdjusted) / (float)(USECS_PER_SECOND), - MIN_TIME_SKIP, MAX_TIME_SKIP); - if (skipTimeForward > 0.0f) { - #ifdef WANT_DEBUG - qCDebug(entities) << "skipTimeForward:" << skipTimeForward; - #endif - // we want to extrapolate the motion forward to compensate for packet travel time, but - // we don't want the side effect of flag setting. - simulateKinematicMotion(skipTimeForward, false); - } + float skipTimeForward = (float)(now - lastSimulatedFromBufferAdjusted) / (float)(USECS_PER_SECOND); + + // we want to extrapolate the motion forward to compensate for packet travel time, but + // we don't want the side effect of flag setting. + simulateKinematicMotion(skipTimeForward, false); } if (overwriteLocalData) { @@ -887,6 +880,15 @@ void EntityItem::simulate(const quint64& now) { } void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) { +#ifdef WANT_DEBUG + qCDebug(entities) << "EntityItem::simulateKinematicMotion timeElapsed" << timeElapsed; +#endif + + const float MIN_TIME_SKIP = 0.0f; + const float MAX_TIME_SKIP = 1.0f; // in seconds + + timeElapsed = glm::clamp(timeElapsed, MIN_TIME_SKIP, MAX_TIME_SKIP); + if (hasActions()) { return; } diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 0efa0c0f39..274472b47d 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -259,7 +259,11 @@ void PhysicsEngine::stepSimulation() { _myAvatarController->preSimulation(); } - int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP); + auto onSubStep = [this]() { + updateContactMap(); + }; + + int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP, onSubStep); if (numSubsteps > 0) { BT_PROFILE("postSimulation"); _numSubsteps += (uint32_t)numSubsteps; @@ -268,7 +272,7 @@ void PhysicsEngine::stepSimulation() { if (_myAvatarController) { _myAvatarController->postSimulation(); } - updateContactMap(); + _hasOutgoingChanges = true; } } diff --git a/libraries/physics/src/ThreadSafeDynamicsWorld.cpp b/libraries/physics/src/ThreadSafeDynamicsWorld.cpp index b59103339c..8bf7cdab20 100644 --- a/libraries/physics/src/ThreadSafeDynamicsWorld.cpp +++ b/libraries/physics/src/ThreadSafeDynamicsWorld.cpp @@ -27,7 +27,7 @@ ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld( : btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration) { } -int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep) { +int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep, SubStepCallback onSubStep) { BT_PROFILE("stepSimulation"); int subSteps = 0; if (maxSubSteps) { @@ -70,6 +70,7 @@ int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, for (int i=0;i + +using SubStepCallback = std::function; + ATTRIBUTE_ALIGNED16(class) ThreadSafeDynamicsWorld : public btDiscreteDynamicsWorld { public: BT_DECLARE_ALIGNED_ALLOCATOR(); @@ -34,7 +38,7 @@ public: btCollisionConfiguration* collisionConfiguration); // virtual overrides from btDiscreteDynamicsWorld - int stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.)); + int stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.), SubStepCallback onSubStep = []() { }); void synchronizeMotionStates(); // btDiscreteDynamicsWorld::m_localTime is the portion of real-time that has not yet been simulated