Merge branch 'master' of github.com:highfidelity/hifi into model-scripting

This commit is contained in:
Seth Alves 2017-01-31 21:27:00 -08:00
commit adaee0e62c
8 changed files with 103 additions and 26 deletions

View file

@ -75,6 +75,14 @@ Item {
source: buttonOutline
}
function urlHelper(src) {
if (src.match(/\bhttp/)) {
return src;
} else {
return "../../../" + src;
}
}
Image {
id: icon
width: 50
@ -84,7 +92,7 @@ Item {
anchors.bottomMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
fillMode: Image.Stretch
source: "../../../" + tabletButton.icon
source: tabletButton.urlHelper(tabletButton.icon)
}
ColorOverlay {
@ -185,7 +193,7 @@ Item {
PropertyChanges {
target: icon
source: "../../../" + tabletButton.activeIcon
source: tabletButton.urlHelper(tabletButton.activeIcon)
}
},
State {

View file

@ -688,6 +688,13 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
somethingChanged = true;
_simulationOwner.clearCurrentOwner();
}
} else if (newSimOwner.matchesValidID(myNodeID) && !_hasBidOnSimulation) {
// entity-server tells us that we have simulation ownership while we never requested this for this EntityItem,
// this could happen when the user reloads the cache and entity tree.
_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
somethingChanged = true;
_simulationOwner.clearCurrentOwner();
weOwnSimulation = false;
} else if (_simulationOwner.set(newSimOwner)) {
_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
somethingChanged = true;
@ -1278,7 +1285,7 @@ void EntityItem::grabSimulationOwnership() {
auto nodeList = DependencyManager::get<NodeList>();
if (_simulationOwner.matchesValidID(nodeList->getSessionUUID())) {
// we already own it
_simulationOwner.promotePriority(SCRIPT_POKE_SIMULATION_PRIORITY);
_simulationOwner.promotePriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
} else {
// we don't own it yet
_simulationOwner.setPendingPriority(SCRIPT_GRAB_SIMULATION_PRIORITY, usecTimestampNow());
@ -1889,6 +1896,10 @@ void EntityItem::setPendingOwnershipPriority(quint8 priority, const quint64& tim
_simulationOwner.setPendingPriority(priority, timestamp);
}
void EntityItem::rememberHasSimulationOwnershipBid() const {
_hasBidOnSimulation = true;
}
QString EntityItem::actionsToDebugString() {
QString result;
QVector<QByteArray> serializedActions;

View file

@ -321,6 +321,7 @@ public:
void updateSimulationOwner(const SimulationOwner& owner);
void clearSimulationOwnership();
void setPendingOwnershipPriority(quint8 priority, const quint64& timestamp);
void rememberHasSimulationOwnershipBid() const;
const QString& getMarketplaceID() const { return _marketplaceID; }
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
@ -497,16 +498,16 @@ protected:
mutable AABox _cachedAABox;
mutable AACube _maxAACube;
mutable AACube _minAACube;
mutable bool _recalcAABox = true;
mutable bool _recalcMinAACube = true;
mutable bool _recalcMaxAACube = true;
mutable bool _recalcAABox { true };
mutable bool _recalcMinAACube { true };
mutable bool _recalcMaxAACube { true };
float _localRenderAlpha;
float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3
float _density { ENTITY_ITEM_DEFAULT_DENSITY }; // kg/m^3
// NOTE: _volumeMultiplier is used to allow some mass properties code exist in the EntityItem base class
// rather than in all of the derived classes. If we ever collapse these classes to one we could do it a
// different way.
float _volumeMultiplier = 1.0f;
float _volumeMultiplier { 1.0f };
glm::vec3 _gravity;
glm::vec3 _acceleration;
float _damping;
@ -516,7 +517,7 @@ protected:
QString _script; /// the value of the script property
QString _loadedScript; /// the value of _script when the last preload signal was sent
quint64 _scriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// the script loaded property used for forced reload
quint64 _scriptTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// the script loaded property used for forced reload
QString _serverScripts;
/// keep track of time when _serverScripts property was last changed
@ -524,7 +525,7 @@ protected:
/// the value of _scriptTimestamp when the last preload signal was sent
// NOTE: on construction we want this to be different from _scriptTimestamp so we intentionally bump it
quint64 _loadedScriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP + 1 };
quint64 _loadedScriptTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP + 1 };
QString _collisionSoundURL;
SharedSoundPointer _collisionSound;
@ -562,8 +563,8 @@ protected:
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
// these backpointers are only ever set/cleared by friends:
EntityTreeElementPointer _element = nullptr; // set by EntityTreeElement
void* _physicsInfo = nullptr; // set by EntitySimulation
EntityTreeElementPointer _element { nullptr }; // set by EntityTreeElement
void* _physicsInfo { nullptr }; // set by EntitySimulation
bool _simulated; // set by EntitySimulation
bool addActionInternal(EntitySimulationPointer simulation, EntityActionPointer action);
@ -580,12 +581,15 @@ protected:
// are used to keep track of and work around this situation.
void checkWaitingToRemove(EntitySimulationPointer simulation = nullptr);
mutable QSet<QUuid> _actionsToRemove;
mutable bool _actionDataDirty = false;
mutable bool _actionDataNeedsTransmit = false;
mutable bool _actionDataDirty { false };
mutable bool _actionDataNeedsTransmit { false };
// _previouslyDeletedActions is used to avoid an action being re-added due to server round-trip lag
static quint64 _rememberDeletedActionTime;
mutable QHash<QUuid, quint64> _previouslyDeletedActions;
// per entity keep state if it ever bid on simulation, so that we can ignore false simulation ownership
mutable bool _hasBidOnSimulation { false };
QUuid _sourceUUID; /// the server node UUID we came from
bool _clientOnly { false };
@ -594,7 +598,7 @@ protected:
// physics related changes from the network to suppress any duplicates and make
// sure redundant applications are idempotent
glm::vec3 _lastUpdatedPositionValue;
glm::quat _lastUpdatedRotationValue;
glm::quat _lastUpdatedRotationValue;
glm::vec3 _lastUpdatedVelocityValue;
glm::vec3 _lastUpdatedAngularVelocityValue;
glm::vec3 _lastUpdatedAccelerationValue;

View file

@ -231,6 +231,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
// and make note of it now, so we can act on it right away.
propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
entity->setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
entity->rememberHasSimulationOwnershipBid();
}
entity->setLastBroadcast(usecTimestampNow());
@ -444,6 +445,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
// we make a bid for simulation ownership
properties.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
entity->pokeSimulationOwnership();
entity->rememberHasSimulationOwnershipBid();
}
}
if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) {

View file

@ -582,6 +582,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
_nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS;
// copy _outgoingPriority into pendingPriority...
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
// don't forget to remember that we have made a bid
_entity->rememberHasSimulationOwnershipBid();
// ...then reset _outgoingPriority in preparation for the next frame
_outgoingPriority = 0;
} else if (_outgoingPriority != _entity->getSimulationPriority()) {

View file

@ -170,14 +170,14 @@ public:
/**jsdoc
* Returns the current value of this button's properties
* @function TabletButtonProxy#getProperties
* @returns {object}
* @returns {ButtonProperties}
*/
Q_INVOKABLE QVariantMap getProperties() const;
/**jsdoc
* Replace the values of some of this button's properties
* @function TabletButtonProxy#editProperties
* @param properties {object} set of properties to change
* @param {ButtonProperties} properties - set of properties to change
*/
Q_INVOKABLE void editProperties(QVariantMap properties);
@ -199,4 +199,13 @@ protected:
QVariantMap _properties;
};
/**jsdoc
* @typedef TabletButtonProxy.ButtonProperties
* @property {string} text - button caption
* @property {string} icon - url to button icon. (50 x 50)
* @property {string} activeText - button caption when button is active
* @property {string} activeIcon - url to button icon used when button is active. (50 x 50)
* @property {string} isActive - true when button is active.
*/
#endif // hifi_TabletScriptingInterface_h

View file

@ -24,6 +24,7 @@ var CAMERA_MATRIX = -7;
var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0};
var TABLET_TEXTURE_RESOLUTION = { x: 480, y: 706 };
var INCHES_TO_METERS = 1 / 39.3701;
var NO_HANDS = -1;
var TABLET_URL = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx";
@ -35,18 +36,21 @@ var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-wi
// * position - position in front of the user
// * rotation - rotation of entity so it faces the user.
function calcSpawnInfo(hand, height) {
var noHands = -1;
var finalPosition;
if (HMD.active && hand !== noHands) {
var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position;
var headRot = (HMD.active && Camera.mode === "first person") ? HMD.orientation : Camera.orientation;
if (HMD.active && hand !== NO_HANDS) {
var handController = getControllerWorldLocation(hand, true);
var controllerPosition = handController.position;
// compute the angle of the chord with length (height / 2)
var theta = Math.asin(height / (2 * Vec3.distance(HMD.position, controllerPosition)));
var theta = Math.asin(height / (2 * Vec3.distance(headPos, controllerPosition)));
// then we can use this angle to rotate the vector between the HMD position and the center of the tablet.
// this vector, u, will become our new look at direction.
var d = Vec3.normalize(Vec3.subtract(HMD.position, controllerPosition));
var d = Vec3.normalize(Vec3.subtract(headPos, controllerPosition));
var w = Vec3.normalize(Vec3.cross(Y_AXIS, d));
var q = Quat.angleAxis(theta * (180 / Math.PI), w);
var u = Vec3.multiplyQbyV(q, d);
@ -64,8 +68,8 @@ function calcSpawnInfo(hand, height) {
rotation: lookAtRot
};
} else {
var front = Quat.getFront(Camera.orientation);
finalPosition = Vec3.sum(Camera.position, Vec3.multiply(0.6, front));
var front = Quat.getFront(headRot);
finalPosition = Vec3.sum(headPos, Vec3.multiply(0.6, front));
var orientation = Quat.lookAt({x: 0, y: 0, z: 0}, front, {x: 0, y: 1, z: 0});
return {
position: finalPosition,
@ -198,6 +202,11 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
_this.geometryChanged(geometry);
};
Window.geometryChanged.connect(this.myGeometryChanged);
this.myCameraModeChanged = function(newMode) {
_this.cameraModeChanged(newMode);
};
Camera.modeUpdated.connect(this.myCameraModeChanged);
};
WebTablet.prototype.setHomeButtonTexture = function() {
@ -228,11 +237,11 @@ WebTablet.prototype.destroy = function () {
Controller.mouseReleaseEvent.disconnect(this.myMouseReleaseEvent);
Window.geometryChanged.disconnect(this.myGeometryChanged);
Camera.modeUpdated.disconnect(this.myCameraModeChanged);
};
WebTablet.prototype.geometryChanged = function (geometry) {
if (!HMD.active) {
var NO_HANDS = -1;
var tabletProperties = {};
// compute position, rotation & parentJointIndex of the tablet
this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
@ -288,7 +297,6 @@ WebTablet.prototype.onHmdChanged = function () {
Controller.mouseReleaseEvent.connect(this.myMouseReleaseEvent);
}
var NO_HANDS = -1;
var tabletProperties = {};
// compute position, rotation & parentJointIndex of the tablet
this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
@ -370,6 +378,18 @@ WebTablet.prototype.mousePressEvent = function (event) {
}
};
WebTablet.prototype.cameraModeChanged = function (newMode) {
// reposition the tablet.
// This allows HMD.position to reflect the new camera mode.
if (HMD.active) {
var self = this;
var tabletProperties = {};
// compute position, rotation & parentJointIndex of the tablet
self.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties);
Entities.editEntity(self.tabletEntityID, tabletProperties);
}
};
function rayIntersectPlane(planePosition, planeNormal, rayStart, rayDirection) {
var rayDirectionDotPlaneNormal = Vec3.dot(rayDirection, planeNormal);
if (rayDirectionDotPlaneNormal > 0.00001 || rayDirectionDotPlaneNormal < -0.00001) {

View file

@ -0,0 +1,21 @@
(function() {
var MINIMUM_LIGHT_INTENSITY = 100.0;
var MAXIMUM_LIGHT_INTENSITY = 125.0;
// Return a random number between `low` (inclusive) and `high` (exclusive)
function randFloat(low, high) {
return low + Math.random() * (high - low);
}
var self = this;
this.preload = function(entityID) {
self.intervalID = Script.setInterval(function() {
Entities.editEntity(entityID, {
intensity: randFloat(MINIMUM_LIGHT_INTENSITY, MAXIMUM_LIGHT_INTENSITY)
});
}, 100);
};
this.unload = function() {
Script.clearInterval(self.intervalID);
}
});