Merge branch 'master' of https://github.com/highfidelity/hifi into purple

This commit is contained in:
samcake 2017-02-06 10:16:41 -08:00
commit 9fd1d5114c
37 changed files with 426 additions and 84 deletions

View file

@ -30,6 +30,24 @@ Item {
return -1;
}
function sortButtons() {
var children = [];
for (var i = 0; i < flowMain.children.length; i++) {
children[i] = flowMain.children[i];
}
children.sort(function (a, b) {
if (a.sortOrder === b.sortOrder) {
// subsort by stableOrder, because JS sort is not stable in qml.
return a.stableOrder - b.stableOrder;
} else {
return a.sortOrder - b.sortOrder;
}
});
flowMain.children = children;
}
// called by C++ code when a button should be added to the tablet
function addButtonProxy(properties) {
var component = Qt.createComponent("TabletButton.qml");
@ -42,6 +60,9 @@ Item {
// pass a reference to the tabletRoot object to the button.
button.tabletRoot = parent.parent;
sortButtons();
return button;
}
@ -221,6 +242,7 @@ Item {
flowMain.children[index].state = state;
}
}
function nextItem() {
setCurrentItemState("base state");
var nextColumnIndex = (columnIndex + 3 + 1) % 3;

View file

@ -11,6 +11,8 @@ Item {
property bool isActive: false
property bool inDebugMode: false
property bool isEntered: false
property double sortOrder: 100
property int stableOrder: 0
property var tabletRoot;
width: 129
height: 129

View file

@ -54,7 +54,10 @@ FocusScope {
onEntered: iconColorOverlay.color = "#1fc6a6";
onExited: iconColorOverlay.color = "#ffffff";
// navigate back to root level menu
onClicked: buildMenu();
onClicked: {
buildMenu();
tabletRoot.playButtonClickSound();
}
}
}
@ -79,10 +82,12 @@ FocusScope {
onEntered: breadcrumbText.color = "#1fc6a6";
onExited: breadcrumbText.color = "#34a2c7";
// navigate back to parent level menu if there is one
onClicked:
onClicked: {
if (breadcrumbText.text !== "Menu") {
menuPopperUpper.closeLastMenu();
}
tabletRoot.playButtonClickSound();
}
}
}
}

View file

@ -75,7 +75,10 @@ FocusScope {
anchors.fill: parent
hoverEnabled: true
onEntered: listView.currentIndex = index
onClicked: root.selected(item)
onClicked: {
root.selected(item)
tabletRoot.playButtonClickSound();
}
}
}

View file

@ -540,6 +540,9 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context);
Setting::Handle<int> sessionRunTime{ "sessionRunTime", 0 };
const float DEFAULT_HMD_TABLET_SCALE_PERCENT = 100.0f;
const float DEFAULT_DESKTOP_TABLET_SCALE_PERCENT = 75.0f;
Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption) :
QApplication(argc, argv),
_shouldRunServer(runServer),
@ -557,6 +560,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
_previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),
_fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
_hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT),
_desktopTabletScale("desktopTabletScale", DEFAULT_DESKTOP_TABLET_SCALE_PERCENT),
_constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true),
_scaleMirror(1.0f),
_rotateMirror(0.0f),
@ -2318,6 +2323,14 @@ void Application::setFieldOfView(float fov) {
}
}
void Application::setHMDTabletScale(float hmdTabletScale) {
_hmdTabletScale.set(hmdTabletScale);
}
void Application::setDesktopTabletScale(float desktopTabletScale) {
_desktopTabletScale.set(desktopTabletScale);
}
void Application::setSettingConstrainToolbarPosition(bool setting) {
_constrainToolbarPosition.set(setting);
DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);

View file

@ -208,6 +208,11 @@ public:
float getFieldOfView() { return _fieldOfView.get(); }
void setFieldOfView(float fov);
float getHMDTabletScale() { return _hmdTabletScale.get(); }
void setHMDTabletScale(float hmdTabletScale);
float getDesktopTabletScale() { return _desktopTabletScale.get(); }
void setDesktopTabletScale(float desktopTabletScale);
float getSettingConstrainToolbarPosition() { return _constrainToolbarPosition.get(); }
void setSettingConstrainToolbarPosition(bool setting);
@ -539,6 +544,8 @@ private:
Setting::Handle<QString> _previousScriptLocation;
Setting::Handle<float> _fieldOfView;
Setting::Handle<float> _hmdTabletScale;
Setting::Handle<float> _desktopTabletScale;
Setting::Handle<bool> _constrainToolbarPosition;
float _scaleMirror;

View file

@ -70,10 +70,27 @@ void setupPreferences() {
}
// UI
static const QString UI_CATEGORY { "UI" };
{
auto getter = []()->bool { return qApp->getSettingConstrainToolbarPosition(); };
auto setter = [](bool value) { qApp->setSettingConstrainToolbarPosition(value); };
preferences->addPreference(new CheckPreference("UI", "Constrain Toolbar Position to Horizontal Center", getter, setter));
preferences->addPreference(new CheckPreference(UI_CATEGORY, "Constrain Toolbar Position to Horizontal Center", getter, setter));
}
{
auto getter = []()->float { return qApp->getHMDTabletScale(); };
auto setter = [](float value) { qApp->setHMDTabletScale(value); };
auto preference = new SpinnerPreference(UI_CATEGORY, "HMD Tablet Scale %", getter, setter);
preference->setMin(20);
preference->setMax(500);
preferences->addPreference(preference);
}
{
auto getter = []()->float { return qApp->getDesktopTabletScale(); };
auto setter = [](float value) { qApp->setDesktopTabletScale(value); };
auto preference = new SpinnerPreference(UI_CATEGORY, "Desktop Tablet Scale %", getter, setter);
preference->setMin(20);
preference->setMax(500);
preferences->addPreference(preference);
}
// Snapshots

View file

@ -281,7 +281,15 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
APPEND_ENTITY_PROPERTY(PROP_HREF, getHref());
APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription());
APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, getActionData());
APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, getParentID());
// convert AVATAR_SELF_ID to actual sessionUUID.
QUuid actualParentID = getParentID();
if (actualParentID == AVATAR_SELF_ID) {
auto nodeList = DependencyManager::get<NodeList>();
actualParentID = nodeList->getSessionUUID();
}
APPEND_ENTITY_PROPERTY(PROP_PARENT_ID, actualParentID);
APPEND_ENTITY_PROPERTY(PROP_PARENT_JOINT_INDEX, getParentJointIndex());
APPEND_ENTITY_PROPERTY(PROP_QUERY_AA_CUBE, getQueryAACube());
APPEND_ENTITY_PROPERTY(PROP_LAST_EDITED_BY, getLastEditedBy());

View file

@ -190,11 +190,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
propertiesWithSimID.setOwningAvatarID(myNodeID);
}
if (propertiesWithSimID.getParentID() == AVATAR_SELF_ID) {
qCDebug(entities) << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID";
propertiesWithSimID.setParentID(QUuid());
}
auto dimensions = propertiesWithSimID.getDimensions();
float volume = dimensions.x * dimensions.y * dimensions.z;
auto density = propertiesWithSimID.getDensity();
@ -223,17 +218,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
}
}
if (_bidOnSimulationOwnership) {
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
auto nodeList = DependencyManager::get<NodeList>();
const QUuid myNodeID = nodeList->getSessionUUID();
// 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());
propertiesWithSimID.setLastEdited(entity->getLastEdited());
} else {
@ -372,9 +356,6 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
if (!scriptSideProperties.parentIDChanged()) {
properties.setParentID(entity->getParentID());
} else if (scriptSideProperties.getParentID() == AVATAR_SELF_ID) {
qCDebug(entities) << "ERROR: Cannot set entity parent ID to the local-only MyAvatar ID";
properties.setParentID(QUuid());
}
if (!scriptSideProperties.parentJointIndexChanged()) {
properties.setParentJointIndex(entity->getParentJointIndex());

View file

@ -934,7 +934,7 @@ void EntityTree::initEntityEditFilterEngine(QScriptEngine* engine, std::function
_hasEntityEditFilter = true;
}
bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged) {
bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd) {
if (!_entityEditFilterEngine) {
propertiesOut = propertiesIn;
wasChanged = false; // not changed
@ -953,6 +953,7 @@ bool EntityTree::filterProperties(EntityItemProperties& propertiesIn, EntityItem
auto in = QJsonValue::fromVariant(inputValues.toVariant()); // grab json copy now, because the inputValues might be side effected by the filter.
QScriptValueList args;
args << inputValues;
args << isAdd;
QScriptValue result = _entityEditFilterFunction.call(_nullObjectForFilter, args);
if (_entityEditFilterHadUncaughtExceptions()) {
@ -989,6 +990,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
}
int processedBytes = 0;
bool isAdd = false;
// we handle these types of "edit" packets
switch (message.getType()) {
case PacketType::EntityErase: {
@ -998,6 +1000,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
}
case PacketType::EntityAdd:
isAdd = true; // fall through to next case
case PacketType::EntityEdit: {
quint64 startDecode = 0, endDecode = 0;
quint64 startLookup = 0, endLookup = 0;
@ -1040,7 +1043,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
}
// If this was an add, we also want to tell the client that sent this edit that the entity was not added.
if (message.getType() == PacketType::EntityAdd) {
if (isAdd) {
QWriteLocker locker(&_recentlyDeletedEntitiesLock);
_recentlyDeletedEntityItemIDs.insert(usecTimestampNow(), entityItemID);
validEditPacket = passedWhiteList;
@ -1050,7 +1053,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
}
}
if ((message.getType() == PacketType::EntityAdd ||
if ((isAdd ||
(message.getType() == PacketType::EntityEdit && properties.lifetimeChanged())) &&
!senderNode->getCanRez() && senderNode->getCanRezTmp()) {
// this node is only allowed to rez temporary entities. if need be, cap the lifetime.
@ -1068,9 +1071,11 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
startFilter = usecTimestampNow();
bool wasChanged = false;
// Having (un)lock rights bypasses the filter.
bool allowed = senderNode->isAllowedEditor() || filterProperties(properties, properties, wasChanged);
bool allowed = senderNode->isAllowedEditor() || filterProperties(properties, properties, wasChanged, isAdd);
if (!allowed) {
auto timestamp = properties.getLastEdited();
properties = EntityItemProperties();
properties.setLastEdited(timestamp);
}
if (!allowed || wasChanged) {
bumpTimestamp(properties);
@ -1110,7 +1115,7 @@ int EntityTree::processEditPacketData(ReceivedMessage& message, const unsigned c
existingEntity->markAsChangedOnServer();
endUpdate = usecTimestampNow();
_totalUpdates++;
} else if (message.getType() == PacketType::EntityAdd) {
} else if (isAdd) {
bool failedAdd = !allowed;
if (!allowed) {
qCDebug(entities) << "Filtered entity add. ID:" << entityItemID;

View file

@ -357,7 +357,7 @@ protected:
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged);
bool filterProperties(EntityItemProperties& propertiesIn, EntityItemProperties& propertiesOut, bool& wasChanged, bool isAdd);
bool _hasEntityEditFilter{ false };
QScriptEngine* _entityEditFilterEngine{};
QScriptValue _entityEditFilterFunction{};

View file

@ -74,7 +74,7 @@ QImage processSourceImage(const QImage& srcImage, bool cubemap) {
if (targetSize != srcImageSize) {
PROFILE_RANGE(resource_parse, "processSourceImage Rectify");
qDebug(modelLog) << "Resizing texture from " << srcImageSize.x << "x" << srcImageSize.y << " to " << targetSize.x << "x" << targetSize.y;
qCDebug(modelLog) << "Resizing texture from " << srcImageSize.x << "x" << srcImageSize.y << " to " << targetSize.x << "x" << targetSize.y;
return srcImage.scaled(fromGlm(targetSize));
}
@ -201,7 +201,7 @@ const QImage& image, bool isLinear, bool doCompress) {
}
}
#define CPU_MIPMAPS 1
#define CPU_MIPMAPS 0
void generateMips(gpu::Texture* texture, QImage& image, gpu::Element formatMip) {
#if CPU_MIPMAPS

View file

@ -203,7 +203,11 @@ void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
BT_PROFILE("kinematicIntegration");
// This is physical kinematic motion which steps strictly by the subframe count
// of the physics simulation and uses full gravity for acceleration.
_entity->setAcceleration(_entity->getGravity());
if (_entity->hasAncestorOfType(NestableType::Avatar)) {
_entity->setAcceleration(glm::vec3(0.0f));
} else {
_entity->setAcceleration(_entity->getGravity());
}
uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
_entity->stepKinematicMotion(dt);

View file

@ -388,10 +388,13 @@ QQuickItem* TabletProxy::getQmlMenu() const {
//
const QString UUID_KEY = "uuid";
const QString STABLE_ORDER_KEY = "stableOrder";
static int s_stableOrder = 1;
TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _properties(properties) {
TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _stableOrder(++s_stableOrder), _properties(properties) {
// this is used to uniquely identify this button.
_properties[UUID_KEY] = _uuid;
_properties[STABLE_ORDER_KEY] = _stableOrder;
}
void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {

View file

@ -194,6 +194,7 @@ signals:
protected:
QUuid _uuid;
int _stableOrder;
mutable std::mutex _mutex;
QQuickItem* _qmlButton { nullptr };
QVariantMap _properties;
@ -206,6 +207,7 @@ protected:
* @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.
* @property {number} sortOrder - determines sort order on tablet. lower numbers will appear before larger numbers. default is 100
*/
#endif // hifi_TabletScriptingInterface_h

View file

@ -227,15 +227,26 @@ void KinectPlugin::init() {
static const QString KINECT_PLUGIN { "Kinect" };
{
auto getter = [this]()->bool { return _enabled; };
auto setter = [this](bool value) { _enabled = value; saveSettings(); };
auto setter = [this](bool value) {
_enabled = value; saveSettings();
if (!_enabled) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
userInputMapper->withLock([&, this]() {
_inputDevice->clearState();
});
}
};
auto preference = new CheckPreference(KINECT_PLUGIN, "Enabled", getter, setter);
preferences->addPreference(preference);
}
}
bool KinectPlugin::isSupported() const {
// FIXME -- check to see if there's a camera or not...
return true;
bool supported = false;
#ifdef HAVE_KINECT
supported = initializeDefaultSensor();
#endif
return supported;
}
bool KinectPlugin::activate() {
@ -250,13 +261,29 @@ bool KinectPlugin::activate() {
userInputMapper->registerDevice(_inputDevice);
return initializeDefaultSensor();
} else {
return false;
}
return false;
}
bool KinectPlugin::initializeDefaultSensor() {
bool KinectPlugin::isHandController() const {
bool sensorAvailable = false;
#ifdef HAVE_KINECT
if (_kinectSensor) {
BOOLEAN sensorIsAvailable = FALSE;
HRESULT hr = _kinectSensor->get_IsAvailable(&sensorIsAvailable);
sensorAvailable = SUCCEEDED(hr) && (sensorIsAvailable == TRUE);
}
#endif
return _enabled && _initialized && sensorAvailable;
}
bool KinectPlugin::initializeDefaultSensor() const {
#ifdef HAVE_KINECT
if (_initialized) {
return true;
}
HRESULT hr;
hr = GetDefaultKinectSensor(&_kinectSensor);
@ -289,6 +316,7 @@ bool KinectPlugin::initializeDefaultSensor() {
return false;
}
_initialized = true;
return true;
#else
return false;
@ -527,3 +555,9 @@ void KinectPlugin::InputDevice::update(float deltaTime, const controller::InputC
}
}
void KinectPlugin::InputDevice::clearState() {
for (size_t i = 0; i < KinectJointIndex::Size; i++) {
int poseIndex = KinectJointIndexToPoseIndex((KinectJointIndex)i);
_poseStateMap[poseIndex] = controller::Pose();
}
}

View file

@ -41,7 +41,7 @@ template<class Interface> inline void SafeRelease(Interface *& pInterfaceToRelea
class KinectPlugin : public InputPlugin {
Q_OBJECT
public:
bool isHandController() const override { return true; }
bool isHandController() const override;
// Plugin functions
virtual void init() override;
@ -79,6 +79,8 @@ protected:
void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData,
const std::vector<KinectPlugin::KinectJoint>& joints, const std::vector<KinectPlugin::KinectJoint>& prevJoints);
void clearState();
};
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
@ -86,7 +88,8 @@ protected:
static const char* NAME;
static const char* KINECT_ID_STRING;
bool _enabled;
bool _enabled { false };
mutable bool _initialized { false };
// copy of data directly from the KinectDataReader SDK
std::vector<KinectJoint> _joints;
@ -97,18 +100,18 @@ protected:
// Kinect SDK related items...
bool KinectPlugin::initializeDefaultSensor();
bool KinectPlugin::initializeDefaultSensor() const;
void updateBody();
#ifdef HAVE_KINECT
void ProcessBody(INT64 time, int bodyCount, IBody** bodies);
// Current Kinect
IKinectSensor* _kinectSensor { nullptr };
ICoordinateMapper* _coordinateMapper { nullptr };
mutable IKinectSensor* _kinectSensor { nullptr };
mutable ICoordinateMapper* _coordinateMapper { nullptr };
// Body reader
IBodyFrameReader* _bodyFrameReader { nullptr };
mutable IBodyFrameReader* _bodyFrameReader { nullptr };
#endif
};

View file

@ -177,7 +177,8 @@
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/bubble-i.svg",
text: buttonName
text: buttonName,
sortOrder: 4
});
}
onBubbleToggled();

View file

@ -143,6 +143,7 @@ var ONE_VEC = {
};
var NULL_UUID = "{00000000-0000-0000-0000-000000000000}";
var AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}";
var DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 };
var INCHES_TO_METERS = 1.0 / 39.3701;
@ -895,9 +896,7 @@ function MyController(hand) {
if (!SHOW_GRAB_POINT_SPHERE) {
return;
}
if (!MyAvatar.sessionUUID) {
return;
}
if (!this.grabPointSphere) {
this.grabPointSphere = Overlays.addOverlay("sphere", {
localPosition: getGrabPointSphereOffset(this.handToController()),
@ -909,7 +908,7 @@ function MyController(hand) {
visible: true,
ignoreRayIntersection: true,
drawInFront: false,
parentID: MyAvatar.sessionUUID,
parentID: AVATAR_SELF_ID,
parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
"_CONTROLLER_RIGHTHAND" :
"_CONTROLLER_LEFTHAND")
@ -961,9 +960,6 @@ function MyController(hand) {
if (this.stylus) {
return;
}
if (!MyAvatar.sessionUUID) {
return;
}
var stylusProperties = {
url: Script.resourcesPath() + "meshes/tablet-stylus-fat.fbx",
@ -977,7 +973,7 @@ function MyController(hand) {
visible: true,
ignoreRayIntersection: true,
drawInFront: false,
parentID: MyAvatar.sessionUUID,
parentID: AVATAR_SELF_ID,
parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
"_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" :
"_CAMERA_RELATIVE_CONTROLLER_LEFTHAND")
@ -2341,7 +2337,7 @@ function MyController(hand) {
}
var reparentProps = {
parentID: MyAvatar.sessionUUID,
parentID: AVATAR_SELF_ID,
parentJointIndex: handJointIndex,
velocity: {x: 0, y: 0, z: 0},
angularVelocity: {x: 0, y: 0, z: 0}
@ -2478,7 +2474,7 @@ function MyController(hand) {
if (this.state == STATE_HOLD && now - this.lastUnequipCheckTime > MSECS_PER_SEC * CHECK_TOO_FAR_UNEQUIP_TIME) {
this.lastUnequipCheckTime = now;
if (props.parentID == MyAvatar.sessionUUID) {
if (props.parentID == AVATAR_SELF_ID) {
var handPosition;
if (this.ignoreIK) {
handPosition = getControllerWorldLocation(this.handToController(), false).position;
@ -2572,7 +2568,7 @@ function MyController(hand) {
};
this.maybeScale = function(props) {
if (!objectScalingEnabled) {
if (!objectScalingEnabled || this.isTablet(this.grabbedEntity)) {
return;
}
@ -2911,7 +2907,7 @@ function MyController(hand) {
var pos3D = intersectInfo.point;
if (this.state == STATE_OVERLAY_STYLUS_TOUCHING &&
!this.deadspotExpired &&
!this.tabletStabbed &&
intersectInfo.distance < WEB_STYLUS_LENGTH / 2.0 + WEB_TOUCH_TOO_CLOSE) {
// they've stabbed the tablet, don't send events until they pull back
this.tabletStabbed = true;
@ -2919,8 +2915,15 @@ function MyController(hand) {
this.tabletStabbedPos3D = pos3D;
return;
}
if (this.tabletStabbed) {
return;
var origin = {x: this.tabletStabbedPos2D.x, y: this.tabletStabbedPos2D.y, z: 0};
var point = {x: pos2D.x, y: pos2D.y, z: 0};
var offset = Vec3.distance(origin, point);
var radius = 0.05;
if (offset < radius) {
return;
}
}
if (Overlays.keyboardFocusOverlay != this.grabbedOverlay) {
@ -3012,7 +3015,7 @@ function MyController(hand) {
};
this.thisHandIsParent = function(props) {
if (props.parentID != MyAvatar.sessionUUID) {
if (props.parentID !== MyAvatar.sessionUUID && props.parentID !== AVATAR_SELF_ID) {
return false;
}
@ -3046,16 +3049,21 @@ function MyController(hand) {
// find children of avatar's hand joint
var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand");
var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, handJointIndex);
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, handJointIndex));
// find children of faux controller joint
var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
"_CONTROLLER_RIGHTHAND" :
"_CONTROLLER_LEFTHAND");
children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex));
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerJointIndex));
// find children of faux camera-relative controller joint
var controllerCRJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
"_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" :
"_CAMERA_RELATIVE_CONTROLLER_LEFTHAND");
children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerCRJointIndex));
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerCRJointIndex));
children.forEach(function(childID) {
if (childID !== _this.stylus) {

View file

@ -210,7 +210,10 @@ var toolBar = (function () {
var button = toolBar.addButton({
objectName: name,
imageURL: imageUrl,
buttonState: 1,
imageOffOut: 1,
imageOffIn: 2,
imageOnOut: 0,
imageOnIn: 2,
alpha: 0.9,
visible: true
});
@ -250,7 +253,8 @@ var toolBar = (function () {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
activeButton = tablet.addButton({
icon: "icons/tablet-icons/edit-i.svg",
text: "EDIT"
text: "EDIT",
sortOrder: 10
});
}

View file

@ -39,7 +39,8 @@ if (Settings.getValue("HUDUIEnabled")) {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/goto-i.svg",
text: buttonName
text: buttonName,
sortOrder: 8
});
}

View file

@ -30,7 +30,8 @@
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/help-i.svg",
text: buttonName
text: buttonName,
sortOrder: 6
});
}
var enabled = false;

View file

@ -59,7 +59,8 @@ function onHmdChanged(isHmd) {
} else {
button.editProperties({
icon: "icons/tablet-icons/switch-i.svg",
text: "VR"
text: "VR",
sortOrder: 2
});
}
desktopOnlyViews.forEach(function (view) {
@ -82,7 +83,8 @@ if (headset) {
} else {
button = tablet.addButton({
icon: "icons/tablet-icons/switch-a.svg",
text: "SWITCH"
text: "SWITCH",
sortOrder: 2
});
}
onHmdChanged(HMD.active);

View file

@ -24,14 +24,18 @@ 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 AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}";
var TABLET_URL = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx";
var NO_HANDS = -1;
// will need to be recaclulated if dimensions of fbx model change.
var TABLET_NATURAL_DIMENSIONS = {x: 33.797, y: 50.129, z: 2.269};
var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-close.png";
// var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-close.png";
var TABLET_MODEL_PATH = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx";
// var TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx";
// returns object with two fields:
// * position - position in front of the user
// * rotation - rotation of entity so it faces the user.
@ -95,7 +99,12 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
var tabletScaleFactor = this.width / TABLET_NATURAL_DIMENSIONS.x;
this.height = TABLET_NATURAL_DIMENSIONS.y * tabletScaleFactor;
this.depth = TABLET_NATURAL_DIMENSIONS.z * tabletScaleFactor;
this.dpi = dpi || DEFAULT_DPI;
if (dpi) {
this.dpi = dpi;
} else {
this.dpi = DEFAULT_DPI * (DEFAULT_WIDTH / this.width);
}
var tabletProperties = {
name: "WebTablet Tablet",
@ -105,7 +114,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
"grabbableKey": {"grabbable": true}
}),
dimensions: {x: this.width, y: this.height, z: this.depth},
parentID: MyAvatar.sessionUUID
parentID: AVATAR_SELF_ID
};
// compute position, rotation & parentJointIndex of the tablet
@ -252,12 +261,14 @@ WebTablet.prototype.geometryChanged = function (geometry) {
// calclulate the appropriate position of the tablet in world space, such that it fits in the center of the screen.
// with a bit of padding on the top and bottom.
WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function () {
var DEFAULT_DESKTOP_TABLET_SCALE = 75;
var DESKTOP_TABLET_SCALE = Settings.getValue("desktopTabletScale") || DEFAULT_DESKTOP_TABLET_SCALE;
var fov = (Settings.getValue('fieldOfView') || DEFAULT_VERTICAL_FIELD_OF_VIEW) * (Math.PI / 180);
var MAX_PADDING_FACTOR = 2.2;
var PADDING_FACTOR = Math.min(Window.innerHeight / TABLET_TEXTURE_RESOLUTION.y, MAX_PADDING_FACTOR);
var TABLET_HEIGHT = (TABLET_TEXTURE_RESOLUTION.y / this.dpi) * INCHES_TO_METERS;
var WEB_ENTITY_Z_OFFSET = (this.depth / 2);
var dist = (PADDING_FACTOR * TABLET_HEIGHT) / (2 * Math.tan(fov / 2)) - WEB_ENTITY_Z_OFFSET;
var dist = (PADDING_FACTOR * TABLET_HEIGHT) / (2 * Math.tan(fov / 2) * (DESKTOP_TABLET_SCALE / 100)) - WEB_ENTITY_Z_OFFSET;
return {
position: Vec3.sum(Camera.position, Vec3.multiply(dist, Quat.getFront(Camera.orientation))),
rotation: Quat.multiply(Camera.orientation, ROT_Y_180)
@ -318,6 +329,7 @@ WebTablet.prototype.register = function() {
WebTablet.prototype.cleanUpOldTabletsOnJoint = function(jointIndex) {
var children = Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, jointIndex);
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, jointIndex));
print("cleanup " + children);
children.forEach(function(childID) {
var props = Entities.getEntityProperties(childID, ["name"]);
@ -335,6 +347,7 @@ WebTablet.prototype.cleanUpOldTablets = function() {
this.cleanUpOldTabletsOnJoint(SENSOR_TO_ROOM_MATRIX);
this.cleanUpOldTabletsOnJoint(CAMERA_MATRIX);
this.cleanUpOldTabletsOnJoint(65529);
this.cleanUpOldTabletsOnJoint(65534);
};
WebTablet.prototype.unregister = function() {
@ -357,7 +370,7 @@ WebTablet.prototype.getPosition = function () {
WebTablet.prototype.mousePressEvent = function (event) {
var pickRay = Camera.computePickRay(event.x, event.y);
var entityPickResults = Entities.findRayIntersection(pickRay, true); // non-accurate picking
var entityPickResults = Entities.findRayIntersection(pickRay, true, [this.tabletEntityID]); // non-accurate picking
if (entityPickResults.intersects && entityPickResults.entityID === this.tabletEntityID) {
var overlayPickResults = Overlays.findRayIntersection(pickRay);
if (overlayPickResults.intersects && overlayPickResults.overlayID === HMD.homeButtonID) {

View file

@ -19,7 +19,9 @@ var MARKETPLACE_URL = "https://metaverse.highfidelity.com/marketplace";
var MARKETPLACE_URL_INITIAL = MARKETPLACE_URL + "?"; // Append "?" to signal injected script that it's the initial page.
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js");
var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
// var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
// Event bridge messages.
var CLARA_IO_DOWNLOAD = "CLARA.IO DOWNLOAD";
@ -132,7 +134,8 @@ if (Settings.getValue("HUDUIEnabled")) {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
marketplaceButton = tablet.addButton({
icon: "icons/tablet-icons/market-i.svg",
text: "MARKET"
text: "MARKET",
sortOrder: 9
});
}

View file

@ -10,14 +10,16 @@
//
var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
//var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
(function() {
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: "icons/tablet-icons/menu-i.svg",
text: "MENU"
text: "MENU",
sortOrder: 3
});
function onClicked() {
var entity = HMD.tabletID;
Entities.editEntity(entity, {textures: JSON.stringify({"tex.close": HOME_BUTTON_TEXTURE})});
@ -29,5 +31,5 @@ var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-
Script.scriptEnding.connect(function () {
button.clicked.disconnect(onClicked);
tablet.removeButton(button);
})
}());
});
}());

View file

@ -40,7 +40,8 @@ if (Settings.getValue("HUDUIEnabled")) {
icon: "icons/tablet-icons/mic-a.svg",
text: buttonName,
activeIcon: "icons/tablet-icons/mic-i.svg",
activeText: "UNMUTE"
activeText: "UNMUTE",
sortOrder: 1
});
}
onMuteToggled();

View file

@ -493,7 +493,8 @@ if (Settings.getValue("HUDUIEnabled")) {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
text: buttonName,
icon: "icons/tablet-icons/people-i.svg"
icon: "icons/tablet-icons/people-i.svg",
sortOrder: 7
});
}
var isWired = false;

View file

@ -36,7 +36,8 @@ if (Settings.getValue("HUDUIEnabled")) {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/snap-i.svg",
text: buttonName
text: buttonName,
sortOrder: 5
});
}

View file

@ -24,7 +24,11 @@
function showTabletUI() {
tabletShown = true;
print("show tablet-ui");
UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", null, null, activeHand, true);
var DEFAULT_WIDTH = 0.4375;
var DEFAULT_HMD_TABLET_SCALE = 100;
var HMD_TABLET_SCALE = Settings.getValue("hmdTabletScale") || DEFAULT_HMD_TABLET_SCALE;
UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", DEFAULT_WIDTH * (HMD_TABLET_SCALE / 100), null, activeHand, true);
UIWebTablet.register();
HMD.tabletID = UIWebTablet.tabletEntityID;
HMD.homeButtonID = UIWebTablet.homeButtonEntity;

View file

@ -35,7 +35,8 @@
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: "icons/tablet-icons/people-i.svg",
text: "Users"
text: "USERS",
sortOrder: 11
});
function onClicked() {

View file

@ -33,7 +33,8 @@ if (Settings.getValue("HUDUIEnabled")) {
button = tablet.addButton({
icon: "icons/tablet-icons/users-i.svg",
text: "USERS",
isActive: Menu.isOptionChecked(MENU_ITEM)
isActive: Menu.isOptionChecked(MENU_ITEM),
sortOrder: 11
});
}

Binary file not shown.

View file

@ -0,0 +1,48 @@
//
// spawnStopwatch.js
//
// Created by Ryan Huffman on 1/20/17.
// Copyright 2017 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 positionToSpawn = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.rotation));
var stopwatchID = Entities.addEntity({
type: "Model",
name: "stopwatch/base",
position: positionToSpawn,
modelURL: "http://hifi-content.s3.amazonaws.com/alan/dev/Stopwatch.fbx",
dimensions: {"x":4.129462242126465,"y":1.058512806892395,"z":5.773681640625}
});
var secondHandID = Entities.addEntity({
type: "Model",
name: "stopwatch/seconds",
parentID: stopwatchID,
localPosition: {"x":-0.004985813982784748,"y":0.39391064643859863,"z":0.8312804698944092},
dimensions: {"x":0.14095762372016907,"y":0.02546107769012451,"z":1.6077008247375488},
registrationPoint: {"x":0.5,"y":0.5,"z":1},
modelURL: "http://hifi-content.s3.amazonaws.com/alan/dev/Stopwatch-sec-hand.fbx",
});
var minuteHandID = Entities.addEntity({
type: "Model",
name: "stopwatch/minutes",
parentID: stopwatchID,
localPosition: {"x":-0.0023056098725646734,"y":0.3308190703392029,"z":0.21810021996498108},
dimensions: {"x":0.045471154153347015,"y":0.015412690117955208,"z":0.22930574417114258},
registrationPoint: {"x":0.5,"y":0.5,"z":1},
modelURL: "http://hifi-content.s3.amazonaws.com/alan/dev/Stopwatch-min-hand.fbx",
});
Entities.editEntity(stopwatchID, {
userData: JSON.stringify({
secondHandID: secondHandID,
minuteHandID: minuteHandID,
}),
script: Script.resolvePath("stopwatchClient.js"),
serverScripts: Script.resolvePath("stopwatchServer.js")
});

View file

@ -0,0 +1,22 @@
//
// stopwatchServer.js
//
// Created by Ryan Huffman on 1/20/17.
// Copyright 2017 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
//
(function() {
var messageChannel;
this.preload = function(entityID) {
this.messageChannel = "STOPWATCH-" + entityID;
};
function click() {
Messages.sendMessage(this.messageChannel, 'click');
}
this.startNearTrigger = click;
this.startFarTrigger = click;
this.clickDownOnEntity = click;
});

View file

@ -0,0 +1,119 @@
//
// stopwatchServer.js
//
// Created by Ryan Huffman on 1/20/17.
// Copyright 2017 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
//
(function() {
var self = this;
self.equipped = false;
self.isActive = false;
self.secondHandID = null;
self.minuteHandID = null;
self.tickSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/huffman/tick.wav");
self.tickInjector = null;
self.tickIntervalID = null;
self.chimeSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/huffman/chime.wav");
self.preload = function(entityID) {
print("Preloading stopwatch: ", entityID);
self.entityID = entityID;
self.messageChannel = "STOPWATCH-" + entityID;
var userData = Entities.getEntityProperties(self.entityID, 'userData').userData;
var data = JSON.parse(userData);
self.secondHandID = data.secondHandID;
self.minuteHandID = data.minuteHandID;
self.resetTimer();
Messages.subscribe(self.messageChannel);
Messages.messageReceived.connect(this, self.messageReceived);
};
self.unload = function() {
print("Unloading stopwatch:", self.entityID);
self.resetTimer();
Messages.unsubscribe(self.messageChannel);
Messages.messageReceived.disconnect(this, self.messageReceived);
};
self.messageReceived = function(channel, message, sender) {
print("Message received", channel, sender, message);
if (channel === self.messageChannel && message === 'click') {
if (self.isActive) {
self.resetTimer();
} else {
self.startTimer();
}
}
};
self.getStopwatchPosition = function() {
return Entities.getEntityProperties(self.entityID, "position").position;
};
self.resetTimer = function() {
print("Stopping stopwatch");
if (self.tickInjector) {
self.tickInjector.stop();
}
if (self.tickIntervalID !== null) {
Script.clearInterval(self.tickIntervalID);
self.tickIntervalID = null;
}
Entities.editEntity(self.secondHandID, {
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
angularVelocity: { x: 0, y: 0, z: 0 },
});
Entities.editEntity(self.minuteHandID, {
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
angularVelocity: { x: 0, y: 0, z: 0 },
});
self.isActive = false;
};
self.startTimer = function() {
print("Starting stopwatch");
if (!self.tickInjector) {
self.tickInjector = Audio.playSound(self.tickSound, {
position: self.getStopwatchPosition(),
volume: 0.7,
loop: true
});
} else {
self.tickInjector.restart();
}
var seconds = 0;
self.tickIntervalID = Script.setInterval(function() {
if (self.tickInjector) {
self.tickInjector.setOptions({
position: self.getStopwatchPosition(),
volume: 0.7,
loop: true
});
}
seconds++;
const degreesPerTick = -360 / 60;
Entities.editEntity(self.secondHandID, {
rotation: Quat.fromPitchYawRollDegrees(0, seconds * degreesPerTick, 0),
});
if (seconds % 60 == 0) {
Entities.editEntity(self.minuteHandID, {
rotation: Quat.fromPitchYawRollDegrees(0, (seconds / 60) * degreesPerTick, 0),
});
Audio.playSound(self.chimeSound, {
position: self.getStopwatchPosition(),
volume: 1.0,
loop: false
});
}
}, 1000);
self.isActive = true;
};
});

Binary file not shown.