MyAvatar: Toggleable head hiding in 1st person

This commit is contained in:
Ada 2025-02-07 09:37:34 +10:00
parent 7a59a27eec
commit 126c21a8fb
4 changed files with 53 additions and 1 deletions

View file

@ -688,6 +688,36 @@ Flickable {
}
}
}
Item {
Layout.preferredWidth: parent.width
Layout.preferredHeight: 35
Layout.topMargin: 16
HifiStylesUit.RalewayRegular {
id: enableHeadClippingHeader
text: "Hide Head in 1st Person"
anchors.left: parent.left
anchors.top: parent.top
width: 200
height: parent.height
size: 16
color: "#FFFFFF"
}
HifiControlsUit.CheckBox {
id: enableHeadClipping
checked: MyAvatar.getHeadClippingEnabled()
boxSize: 16
spacing: -1
colorScheme: hifi.colorSchemes.dark
anchors.left: enableHeadClippingHeader.right
anchors.leftMargin: 20
anchors.top: parent.top
onCheckedChanged: {
MyAvatar.setHeadClippingEnabled(enableHeadClipping.checked);
}
}
}
}
ColumnLayout {

View file

@ -204,6 +204,7 @@ MyAvatar::MyAvatar(QThread* thread) :
_eyeContactTarget(LEFT_EYE),
_realWorldFieldOfView("realWorldFieldOfView",
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
_headClipping("headClipping", true),
_useAdvancedMovementControls("advancedMovementForHandControllersIsChecked", true),
_showPlayArea("showPlayArea", true),
_smoothOrientationTimer(std::numeric_limits<float>::max()),
@ -3256,7 +3257,8 @@ bool MyAvatar::shouldRenderHead(const RenderArgs* renderArgs) const {
bool overrideAnim = _skeletonModel ? _skeletonModel->getRig().isPlayingOverrideAnimation() : false;
bool isInMirror = renderArgs->_mirrorDepth > 0;
bool insideHead = cameraInsideHead(renderArgs->getViewFrustum().getPosition());
return !defaultMode || isInMirror || (!firstPerson && !insideHead) || (overrideAnim && !insideHead);
bool forceDisabled = !getHeadClippingEnabled();
return forceDisabled || !defaultMode || isInMirror || (!firstPerson && !insideHead) || (overrideAnim && !insideHead);
}
void MyAvatar::setRotationRecenterFilterLength(float length) {

View file

@ -654,6 +654,13 @@ public:
void setRealWorldFieldOfView(float realWorldFov) { _realWorldFieldOfView.set(realWorldFov); }
/*@jsdoc
* Sets whether the avatar's head should be hidden in first-person mode.
* @function MyAvatar.setHeadClippingEnabled
* @param {boolean} enable - <code>true</code> will scale the avatar's head in first person to hide it; <code>false</code> will leave the head full and visible in first person, which may have visible near-Z clipping or obstruct the player's view.
*/
Q_INVOKABLE void setHeadClippingEnabled(bool enable) { _headClipping.set(enable); }
/*@jsdoc
* Gets the position in world coordinates of the point directly between your avatar's eyes assuming your avatar was in its
* default pose. This is a reference position; it does not change as your avatar's head moves relative to the avatar
@ -668,6 +675,13 @@ public:
float getRealWorldFieldOfView() { return _realWorldFieldOfView.get(); }
/*@jsdoc
* Gets whether the avatar's head mesh will be hidden in first person mode.
* @function MyAvatar.getHeadClippingEnabled
* @returns {boolean} Whether head clipping is enabled.
*/
Q_INVOKABLE bool getHeadClippingEnabled() const { return _headClipping.get(); }
/*@jsdoc
* Overrides the default avatar animations.
* <p>The avatar animation system includes a set of default animations along with rules for how those animations are blended
@ -2776,6 +2790,7 @@ private:
bool _isPointTargetValid { true };
Setting::Handle<float> _realWorldFieldOfView;
Setting::Handle<bool> _headClipping;
Setting::Handle<bool> _useAdvancedMovementControls;
Setting::Handle<bool> _showPlayArea;

View file

@ -254,6 +254,11 @@ void setupPreferences() {
auto setter = [](bool value) { qApp->setCameraClippingEnabled(value); };
preferences->addPreference(new CheckPreference(VIEW_CATEGORY, "Enable 3rd Person Camera Clipping?", getter, setter));
}
{
auto getter = [myAvatar]()->bool { return myAvatar->getHeadClippingEnabled(); };
auto setter = [myAvatar](bool value) { myAvatar->setHeadClippingEnabled(value); };
preferences->addPreference(new CheckPreference(VIEW_CATEGORY, "Hide Head in 1st Person", getter, setter));
}
// Snapshots
static const QString SNAPSHOTS { "Snapshots" };