mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:36:45 +02:00
Merge pull request #3460 from PhilipRosedale/master
Added JS support for neck position for headMove script
This commit is contained in:
commit
2a5ec89e3b
5 changed files with 62 additions and 23 deletions
|
@ -16,24 +16,21 @@ var debug = false;
|
||||||
var movingWithHead = false;
|
var movingWithHead = false;
|
||||||
var headStartPosition, headStartDeltaPitch, headStartFinalPitch, headStartRoll, headStartYaw;
|
var headStartPosition, headStartDeltaPitch, headStartFinalPitch, headStartRoll, headStartYaw;
|
||||||
|
|
||||||
var HEAD_MOVE_DEAD_ZONE = 0.10;
|
var HEAD_MOVE_DEAD_ZONE = 0.03;
|
||||||
var HEAD_STRAFE_DEAD_ZONE = 0.0;
|
var HEAD_STRAFE_DEAD_ZONE = 0.03;
|
||||||
var HEAD_ROTATE_DEAD_ZONE = 0.0;
|
var HEAD_ROTATE_DEAD_ZONE = 10.0;
|
||||||
//var HEAD_THRUST_FWD_SCALE = 12000.0;
|
var HEAD_YAW_RATE = 2.0;
|
||||||
//var HEAD_THRUST_STRAFE_SCALE = 0.0;
|
|
||||||
var HEAD_YAW_RATE = 1.0;
|
|
||||||
var HEAD_PITCH_RATE = 1.0;
|
var HEAD_PITCH_RATE = 1.0;
|
||||||
//var HEAD_ROLL_THRUST_SCALE = 75.0;
|
|
||||||
//var HEAD_PITCH_LIFT_THRUST = 3.0;
|
|
||||||
var WALL_BOUNCE = 4000.0;
|
var WALL_BOUNCE = 4000.0;
|
||||||
|
var FIXED_WALK_VELOCITY = 1.5;
|
||||||
|
|
||||||
// Modify these values to tweak the strength of the motion.
|
// Modify these values to tweak the strength of the motion.
|
||||||
// A larger *FACTOR increases the speed.
|
// A larger *FACTOR increases the speed.
|
||||||
// A lower SHORT_TIMESCALE makes the motor achieve full speed faster.
|
// A lower SHORT_TIMESCALE makes the motor achieve full speed faster.
|
||||||
var HEAD_VELOCITY_FWD_FACTOR = 20.0;
|
var HEAD_VELOCITY_FWD_FACTOR = 20.0;
|
||||||
var HEAD_VELOCITY_LEFT_FACTOR = 20.0;
|
var HEAD_VELOCITY_LEFT_FACTOR = 0.0;
|
||||||
var HEAD_VELOCITY_UP_FACTOR = 20.0;
|
var HEAD_VELOCITY_UP_FACTOR = 20.0;
|
||||||
var SHORT_TIMESCALE = 0.125;
|
var SHORT_TIMESCALE = 0.01;
|
||||||
var VERY_LARGE_TIMESCALE = 1000000.0;
|
var VERY_LARGE_TIMESCALE = 1000000.0;
|
||||||
|
|
||||||
var xAxis = {x:1.0, y:0.0, z:0.0 };
|
var xAxis = {x:1.0, y:0.0, z:0.0 };
|
||||||
|
@ -43,9 +40,10 @@ var zAxis = {x:0.0, y:0.0, z:1.0 };
|
||||||
// If these values are set to something
|
// If these values are set to something
|
||||||
var maxVelocity = 1.25;
|
var maxVelocity = 1.25;
|
||||||
var noFly = true;
|
var noFly = true;
|
||||||
|
var fixedWalkVelocity = true;
|
||||||
|
|
||||||
//var roomLimits = { xMin: 618, xMax: 635.5, zMin: 528, zMax: 552.5 };
|
//var roomLimits = { xMin: 618, xMax: 635.5, zMin: 528, zMax: 552.5 };
|
||||||
var roomLimits = { xMin: -1, xMax: 0, zMin: 0, zMax: 0 };
|
var roomLimits = { xMin: 193.0, xMax: 206.5, zMin: 251.4, zMax: 269.5 };
|
||||||
|
|
||||||
function isInRoom(position) {
|
function isInRoom(position) {
|
||||||
var BUFFER = 2.0;
|
var BUFFER = 2.0;
|
||||||
|
@ -71,25 +69,46 @@ function moveWithHead(deltaTime) {
|
||||||
var deltaPitch = MyAvatar.getHeadDeltaPitch() - headStartDeltaPitch;
|
var deltaPitch = MyAvatar.getHeadDeltaPitch() - headStartDeltaPitch;
|
||||||
var deltaRoll = MyAvatar.getHeadFinalRoll() - headStartRoll;
|
var deltaRoll = MyAvatar.getHeadFinalRoll() - headStartRoll;
|
||||||
var velocity = MyAvatar.getVelocity();
|
var velocity = MyAvatar.getVelocity();
|
||||||
var bodyLocalCurrentHeadVector = Vec3.subtract(MyAvatar.getHeadPosition(), MyAvatar.position);
|
var position = MyAvatar.position;
|
||||||
bodyLocalCurrentHeadVector = Vec3.multiplyQbyV(Quat.angleAxis(-deltaYaw, {x:0, y: 1, z:0}), bodyLocalCurrentHeadVector);
|
var neckPosition = MyAvatar.getNeckPosition();
|
||||||
|
var bodyLocalCurrentHeadVector = Vec3.subtract(neckPosition, position);
|
||||||
|
bodyLocalCurrentHeadVector = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), bodyLocalCurrentHeadVector);
|
||||||
var headDelta = Vec3.subtract(bodyLocalCurrentHeadVector, headStartPosition);
|
var headDelta = Vec3.subtract(bodyLocalCurrentHeadVector, headStartPosition);
|
||||||
headDelta = Vec3.multiplyQbyV(Quat.inverse(Camera.getOrientation()), headDelta);
|
|
||||||
headDelta.y = 0.0; // Don't respond to any of the vertical component of head motion
|
headDelta.y = 0.0; // Don't respond to any of the vertical component of head motion
|
||||||
|
headDelta = Vec3.multiplyQbyV(MyAvatar.orientation, headDelta);
|
||||||
|
headDelta = Vec3.multiplyQbyV(Quat.inverse(Camera.getOrientation()), headDelta);
|
||||||
|
|
||||||
|
var length = Vec3.length(headDelta);
|
||||||
|
|
||||||
|
if (length > 1.0) {
|
||||||
|
// Needs fixed! Right now sometimes reported neck position jumps to a bad value
|
||||||
|
headDelta.x = headDelta.y = headDelta.z = 0.0;
|
||||||
|
length = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
// Thrust based on leaning forward and side-to-side
|
// Thrust based on leaning forward and side-to-side
|
||||||
var targetVelocity = {x:0.0, y:0.0, z:0.0};
|
var targetVelocity = {x:0.0, y:0.0, z:0.0};
|
||||||
|
if (length > HEAD_MOVE_DEAD_ZONE) {
|
||||||
|
targetVelocity = Vec3.multiply(headDelta, HEAD_VELOCITY_FWD_FACTOR);
|
||||||
|
}
|
||||||
|
/*
|
||||||
if (Math.abs(headDelta.z) > HEAD_MOVE_DEAD_ZONE) {
|
if (Math.abs(headDelta.z) > HEAD_MOVE_DEAD_ZONE) {
|
||||||
targetVelocity = Vec3.multiply(zAxis, -headDelta.z * HEAD_VELOCITY_FWD_FACTOR);
|
if (fixedWalkVelocity) {
|
||||||
|
targetVelocity = Vec3.multiply(zAxis, headDelta.z > 0 ? FIXED_WALK_VELOCITY : -FIXED_WALK_VELOCITY);
|
||||||
|
} else {
|
||||||
|
targetVelocity = Vec3.multiply(zAxis, headDelta.z * HEAD_VELOCITY_FWD_FACTOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Math.abs(headDelta.x) > HEAD_STRAFE_DEAD_ZONE) {
|
if (Math.abs(headDelta.x) > HEAD_STRAFE_DEAD_ZONE) {
|
||||||
var deltaVelocity = Vec3.multiply(xAxis, -headDelta.x * HEAD_VELOCITY_LEFT_FACTOR);
|
var deltaVelocity = Vec3.multiply(xAxis, headDelta.x * HEAD_VELOCITY_LEFT_FACTOR);
|
||||||
targetVelocity = Vec3.sum(targetVelocity, deltaVelocity);
|
targetVelocity = Vec3.sum(targetVelocity, deltaVelocity);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (Math.abs(deltaYaw) > HEAD_ROTATE_DEAD_ZONE) {
|
if (Math.abs(deltaYaw) > HEAD_ROTATE_DEAD_ZONE) {
|
||||||
var orientation = Quat.multiply(Quat.angleAxis((deltaYaw + deltaRoll) * HEAD_YAW_RATE * deltaTime, yAxis), MyAvatar.orientation);
|
var orientation = Quat.multiply(Quat.angleAxis((deltaYaw + deltaRoll) * HEAD_YAW_RATE * deltaTime, yAxis), MyAvatar.orientation);
|
||||||
MyAvatar.orientation = orientation;
|
MyAvatar.orientation = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thrust Up/Down based on head pitch
|
// Thrust Up/Down based on head pitch
|
||||||
if (!noFly) {
|
if (!noFly) {
|
||||||
var deltaVelocity = Vec3.multiply(yAxis, headDelta.y * HEAD_VELOCITY_UP_FACTOR);
|
var deltaVelocity = Vec3.multiply(yAxis, headDelta.y * HEAD_VELOCITY_UP_FACTOR);
|
||||||
|
@ -130,7 +149,8 @@ function moveWithHead(deltaTime) {
|
||||||
Controller.keyPressEvent.connect(function(event) {
|
Controller.keyPressEvent.connect(function(event) {
|
||||||
if (event.text == "SPACE" && !movingWithHead) {
|
if (event.text == "SPACE" && !movingWithHead) {
|
||||||
movingWithHead = true;
|
movingWithHead = true;
|
||||||
headStartPosition = Vec3.subtract(MyAvatar.getHeadPosition(), MyAvatar.position);
|
headStartPosition = Vec3.subtract(MyAvatar.getNeckPosition(), MyAvatar.position);
|
||||||
|
headStartPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), headStartPosition);
|
||||||
headStartDeltaPitch = MyAvatar.getHeadDeltaPitch();
|
headStartDeltaPitch = MyAvatar.getHeadDeltaPitch();
|
||||||
headStartFinalPitch = MyAvatar.getHeadFinalPitch();
|
headStartFinalPitch = MyAvatar.getHeadFinalPitch();
|
||||||
headStartRoll = MyAvatar.getHeadFinalRoll();
|
headStartRoll = MyAvatar.getHeadFinalRoll();
|
||||||
|
|
|
@ -97,6 +97,12 @@ glm::vec3 Avatar::getChestPosition() const {
|
||||||
return _skeletonModel.getNeckPosition(neckPosition) ? (_position + neckPosition) * 0.5f : _position;
|
return _skeletonModel.getNeckPosition(neckPosition) ? (_position + neckPosition) * 0.5f : _position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 Avatar::getNeckPosition() const {
|
||||||
|
glm::vec3 neckPosition;
|
||||||
|
return _skeletonModel.getNeckPosition(neckPosition) ? neckPosition : _position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
glm::quat Avatar::getWorldAlignedOrientation () const {
|
glm::quat Avatar::getWorldAlignedOrientation () const {
|
||||||
return computeRotationFromBodyToWorldUp() * getOrientation();
|
return computeRotationFromBodyToWorldUp() * getOrientation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,8 @@ public:
|
||||||
Q_INVOKABLE void setJointModelPositionAndOrientation(int index, const glm::vec3 position, const glm::quat& rotation);
|
Q_INVOKABLE void setJointModelPositionAndOrientation(int index, const glm::vec3 position, const glm::quat& rotation);
|
||||||
Q_INVOKABLE void setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position,
|
Q_INVOKABLE void setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position,
|
||||||
const glm::quat& rotation);
|
const glm::quat& rotation);
|
||||||
|
|
||||||
|
Q_INVOKABLE glm::vec3 getNeckPosition() const;
|
||||||
|
|
||||||
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
||||||
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
||||||
|
|
|
@ -32,6 +32,7 @@ Head::Head(Avatar* owningAvatar) :
|
||||||
_eyePosition(0.0f, 0.0f, 0.0f),
|
_eyePosition(0.0f, 0.0f, 0.0f),
|
||||||
_scale(1.0f),
|
_scale(1.0f),
|
||||||
_lastLoudness(0.0f),
|
_lastLoudness(0.0f),
|
||||||
|
_longTermAverageLoudness(-1.0f),
|
||||||
_audioAttack(0.0f),
|
_audioAttack(0.0f),
|
||||||
_angularVelocity(0,0,0),
|
_angularVelocity(0,0,0),
|
||||||
_renderLookatVectors(false),
|
_renderLookatVectors(false),
|
||||||
|
@ -62,7 +63,7 @@ void Head::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
||||||
// Update audio trailing average for rendering facial animations
|
|
||||||
if (isMine) {
|
if (isMine) {
|
||||||
MyAvatar* myAvatar = static_cast<MyAvatar*>(_owningAvatar);
|
MyAvatar* myAvatar = static_cast<MyAvatar*>(_owningAvatar);
|
||||||
|
|
||||||
|
@ -78,6 +79,18 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update audio trailing average for rendering facial animations
|
||||||
|
const float AUDIO_AVERAGING_SECS = 0.05f;
|
||||||
|
const float AUDIO_LONG_TERM_AVERAGING_SECS = 30.f;
|
||||||
|
_averageLoudness = glm::mix(_averageLoudness, _audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f));
|
||||||
|
|
||||||
|
if (_longTermAverageLoudness == -1.0) {
|
||||||
|
_longTermAverageLoudness = _averageLoudness;
|
||||||
|
} else {
|
||||||
|
_longTermAverageLoudness = glm::mix(_longTermAverageLoudness, _averageLoudness, glm::min(deltaTime / AUDIO_LONG_TERM_AVERAGING_SECS, 1.0f));
|
||||||
|
}
|
||||||
|
float deltaLoudness = glm::max(0.0f, _averageLoudness - _longTermAverageLoudness);
|
||||||
|
//qDebug() << "deltaLoudness: " << deltaLoudness;
|
||||||
|
|
||||||
if (!(_isFaceshiftConnected || billboard)) {
|
if (!(_isFaceshiftConnected || billboard)) {
|
||||||
// Update eye saccades
|
// Update eye saccades
|
||||||
|
@ -92,9 +105,6 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
||||||
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
_saccadeTarget = SACCADE_MAGNITUDE * randVector();
|
||||||
}
|
}
|
||||||
_saccade += (_saccadeTarget - _saccade) * 0.50f;
|
_saccade += (_saccadeTarget - _saccade) * 0.50f;
|
||||||
|
|
||||||
const float AUDIO_AVERAGING_SECS = 0.05f;
|
|
||||||
_averageLoudness = glm::mix(_averageLoudness, _audioLoudness, glm::min(deltaTime / AUDIO_AVERAGING_SECS, 1.0f));
|
|
||||||
|
|
||||||
// Detect transition from talking to not; force blink after that and a delay
|
// Detect transition from talking to not; force blink after that and a delay
|
||||||
bool forceBlink = false;
|
bool forceBlink = false;
|
||||||
|
@ -108,8 +118,8 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update audio attack data for facial animation (eyebrows and mouth)
|
// Update audio attack data for facial animation (eyebrows and mouth)
|
||||||
_audioAttack = 0.9f * _audioAttack + 0.1f * fabs(_audioLoudness - _lastLoudness);
|
_audioAttack = 0.9f * _audioAttack + 0.1f * fabs((_audioLoudness - _longTermAverageLoudness) - _lastLoudness);
|
||||||
_lastLoudness = _audioLoudness;
|
_lastLoudness = (_audioLoudness - _longTermAverageLoudness);
|
||||||
|
|
||||||
const float BROW_LIFT_THRESHOLD = 100.0f;
|
const float BROW_LIFT_THRESHOLD = 100.0f;
|
||||||
if (_audioAttack > BROW_LIFT_THRESHOLD) {
|
if (_audioAttack > BROW_LIFT_THRESHOLD) {
|
||||||
|
|
|
@ -121,6 +121,7 @@ private:
|
||||||
|
|
||||||
float _scale;
|
float _scale;
|
||||||
float _lastLoudness;
|
float _lastLoudness;
|
||||||
|
float _longTermAverageLoudness;
|
||||||
float _audioAttack;
|
float _audioAttack;
|
||||||
glm::vec3 _angularVelocity;
|
glm::vec3 _angularVelocity;
|
||||||
bool _renderLookatVectors;
|
bool _renderLookatVectors;
|
||||||
|
|
Loading…
Reference in a new issue