mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi
This commit is contained in:
commit
2fa3ab7a14
40 changed files with 685 additions and 130 deletions
|
@ -13,7 +13,6 @@
|
|||
|
||||
Script.include("../libraries/utils.js");
|
||||
|
||||
|
||||
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
||||
var rightTriggerAction = RIGHT_HAND_CLICK;
|
||||
|
||||
|
@ -22,6 +21,10 @@ var GRAB_USER_DATA_KEY = "grabKey";
|
|||
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
||||
var leftTriggerAction = LEFT_HAND_CLICK;
|
||||
|
||||
var LIFETIME = 10;
|
||||
var EXTRA_TIME = 5;
|
||||
var POINTER_CHECK_TIME = 5000;
|
||||
|
||||
var ZERO_VEC = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
@ -42,7 +45,7 @@ var INTERSECT_COLOR = {
|
|||
blue: 10
|
||||
};
|
||||
|
||||
var GRAB_RADIUS = 1.0;
|
||||
var GRAB_RADIUS = 1.5;
|
||||
|
||||
var GRAB_COLOR = {
|
||||
red: 250,
|
||||
|
@ -59,8 +62,15 @@ var TRACTOR_BEAM_VELOCITY_THRESHOLD = 0.5;
|
|||
|
||||
var RIGHT = 1;
|
||||
var LEFT = 0;
|
||||
var rightController = new controller(RIGHT, rightTriggerAction, right4Action, "right")
|
||||
var leftController = new controller(LEFT, leftTriggerAction, left4Action, "left")
|
||||
var rightController = new controller(RIGHT, rightTriggerAction, right4Action, "right");
|
||||
var leftController = new controller(LEFT, leftTriggerAction, left4Action, "left");
|
||||
|
||||
|
||||
//Need to wait before calling these methods for some reason...
|
||||
Script.setTimeout(function() {
|
||||
rightController.checkPointer();
|
||||
leftController.checkPointer();
|
||||
}, 100)
|
||||
|
||||
function controller(side, triggerAction, pullAction, hand) {
|
||||
this.hand = hand;
|
||||
|
@ -92,7 +102,9 @@ function controller(side, triggerAction, pullAction, hand) {
|
|||
z: 1000
|
||||
},
|
||||
visible: false,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,6 +139,16 @@ controller.prototype.updateLine = function() {
|
|||
}
|
||||
|
||||
|
||||
controller.prototype.checkPointer = function() {
|
||||
var self = this;
|
||||
Script.setTimeout(function() {
|
||||
var props = Entities.getEntityProperties(self.pointer);
|
||||
Entities.editEntity(self.pointer, {
|
||||
lifetime: props.age + EXTRA_TIME
|
||||
});
|
||||
self.checkPointer();
|
||||
}, POINTER_CHECK_TIME);
|
||||
}
|
||||
|
||||
controller.prototype.checkForIntersections = function(origin, direction) {
|
||||
var pickRay = {
|
||||
|
@ -241,14 +263,22 @@ controller.prototype.grabEntity = function() {
|
|||
this.closeGrabbing = true;
|
||||
//check if our entity has instructions on how to be grabbed, otherwise, just use default relative position and rotation
|
||||
var userData = getEntityUserData(this.grabbedEntity);
|
||||
var relativePosition = ZERO_VEC;
|
||||
var relativeRotation = Quat.fromPitchYawRollDegrees(0, 0, 0);
|
||||
if(userData.spatialKey) {
|
||||
if(userData.spatialKey.relativePosition) {
|
||||
relativePosition = userData.spatialKey.relativePosition;
|
||||
|
||||
var objectRotation = Entities.getEntityProperties(this.grabbedEntity).rotation;
|
||||
var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
||||
|
||||
var objectPosition = Entities.getEntityProperties(this.grabbedEntity).position;
|
||||
var offset = Vec3.subtract(objectPosition, handPosition);
|
||||
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
|
||||
|
||||
var relativePosition = offsetPosition;
|
||||
var relativeRotation = offsetRotation;
|
||||
if (userData.grabFrame) {
|
||||
if (userData.grabFrame.relativePosition) {
|
||||
relativePosition = userData.grabFrame.relativePosition;
|
||||
}
|
||||
if(userData.spatialKey.relativeRotation) {
|
||||
relativeRotation = userData.spatialKey.relativeRotation;
|
||||
if (userData.grabFrame.relativeRotation) {
|
||||
relativeRotation = userData.grabFrame.relativeRotation;
|
||||
}
|
||||
}
|
||||
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
(function() {
|
||||
Script.include("../libraries/utils.js");
|
||||
SPATIAL_USER_DATA_KEY = "spatialKey";
|
||||
GRAB_FRAME_USER_DATA_KEY = "grabFrame";
|
||||
this.userData = {};
|
||||
|
||||
var TIP_OFFSET_Z = 0.14;
|
||||
|
@ -62,13 +62,14 @@
|
|||
this.sprayStream = function() {
|
||||
var forwardVec = Quat.getFront(self.properties.rotation);
|
||||
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
|
||||
forwardVec = Vec3.normalize(forwardVec);
|
||||
|
||||
var upVec = Quat.getUp(self.properties.rotation);
|
||||
var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z));
|
||||
position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y))
|
||||
Entities.editEntity(self.paintStream, {
|
||||
position: position,
|
||||
emitVelocity: forwardVec
|
||||
emitVelocity: Vec3.multiply(forwardVec, 4)
|
||||
});
|
||||
|
||||
//Now check for an intersection with an entity
|
||||
|
@ -155,12 +156,16 @@
|
|||
if (this.userData.grabKey && this.userData.grabKey.activated) {
|
||||
this.activated = true;
|
||||
}
|
||||
if(!this.userData.spatialKey) {
|
||||
if (!this.userData.grabFrame) {
|
||||
var data = {
|
||||
relativePosition: {x: 0, y: 0, z: 0},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0,0)
|
||||
relativePosition: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
|
||||
}
|
||||
setEntityCustomData(SPATIAL_USER_DATA_KEY, this.entityId, data);
|
||||
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data);
|
||||
}
|
||||
this.initialize();
|
||||
}
|
||||
|
@ -174,7 +179,6 @@
|
|||
running: false
|
||||
});
|
||||
|
||||
|
||||
this.paintStream = Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
animationSettings: animationSettings,
|
||||
|
|
7
examples/example/tests/test-includes/a.js
Normal file
7
examples/example/tests/test-includes/a.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
// a.js:
|
||||
Script.include('b.js');
|
||||
if (a === undefined) {
|
||||
a = 0;
|
||||
}
|
||||
a++;
|
||||
print('script a:' + a);
|
6
examples/example/tests/test-includes/b.js
Normal file
6
examples/example/tests/test-includes/b.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// b.js:
|
||||
if (b === undefined) {
|
||||
b = 0;
|
||||
}
|
||||
b++;
|
||||
print('script b: ' + b);
|
5
examples/example/tests/test-includes/start.js
Normal file
5
examples/example/tests/test-includes/start.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
// start.js:
|
||||
var a, b;
|
||||
print('initially: a:' + a + ' b:' + b);
|
||||
Script.include(['a.js', '../test-includes/a.js', 'b.js', 'a.js']);
|
||||
print('finally a:' + a + ' b:' + b);
|
45
examples/toys/flashlight/createFlashlight.js
Normal file
45
examples/toys/flashlight/createFlashlight.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// createFlashligh.js
|
||||
// examples/entityScripts
|
||||
//
|
||||
// Created by Sam Gateau on 9/9/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This is a toy script that create a flashlight entity that lit when grabbed
|
||||
// This can be run from an interface and the flashlight will get deleted from the domain when quitting
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
Script.include("https://hifi-public.s3.amazonaws.com/scripts/utilities.js");
|
||||
|
||||
|
||||
var scriptURL = "https://hifi-public.s3.amazonaws.com/scripts/toys/flashlight/flashlight.js?"+randInt(0,1000);
|
||||
|
||||
var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx";
|
||||
|
||||
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {x: 0, y: 0.5, z: 0}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
var flashlight = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
position: center,
|
||||
dimensions: {
|
||||
x: 0.04,
|
||||
y: 0.15,
|
||||
z: 0.04
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
shapeType: 'box',
|
||||
script: scriptURL
|
||||
});
|
||||
|
||||
|
||||
function cleanup() {
|
||||
Entities.deleteEntity(flashlight);
|
||||
}
|
||||
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
154
examples/toys/flashlight/flashlight.js
Normal file
154
examples/toys/flashlight/flashlight.js
Normal file
|
@ -0,0 +1,154 @@
|
|||
//
|
||||
// flashligh.js
|
||||
// examples/entityScripts
|
||||
//
|
||||
// Created by Sam Gateau on 9/9/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This is a toy script that can be added to the Flashlight model entity:
|
||||
// "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx"
|
||||
// that creates a spotlight attached with the flashlight model while the entity is grabbed
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function() {
|
||||
|
||||
function debugPrint(message) {
|
||||
// print(message);
|
||||
}
|
||||
|
||||
Script.include("../../libraries/utils.js");
|
||||
|
||||
var _this;
|
||||
|
||||
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
|
||||
// our this object, so we can access it in cases where we're called without a this (like in the case of various global signals)
|
||||
Flashlight = function() {
|
||||
_this = this;
|
||||
_this._hasSpotlight = false;
|
||||
_this._spotlight = null;
|
||||
};
|
||||
|
||||
// These constants define the Spotlight position and orientation relative to the model
|
||||
var MODEL_LIGHT_POSITION = {x: 0, y: 0, z: 0};
|
||||
var MODEL_LIGHT_ROTATION = Quat.angleAxis (-90, {x: 1, y: 0, z: 0});
|
||||
|
||||
// Evaluate the world light entity position and orientation from the model ones
|
||||
function evalLightWorldTransform(modelPos, modelRot) {
|
||||
return {p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)),
|
||||
q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION)};
|
||||
};
|
||||
|
||||
Flashlight.prototype = {
|
||||
|
||||
// update() will be called regulary, because we've hooked the update signal in our preload() function
|
||||
// we will check out userData for the grabData. In the case of the hydraGrab script, it will tell us
|
||||
// if we're currently being grabbed and if the person grabbing us is the current interfaces avatar.
|
||||
// we will watch this for state changes and print out if we're being grabbed or released when it changes.
|
||||
update: function() {
|
||||
var GRAB_USER_DATA_KEY = "grabKey";
|
||||
|
||||
// because the update() signal doesn't have a valid this, we need to use our memorized _this to access our entityID
|
||||
var entityID = _this.entityID;
|
||||
|
||||
// we want to assume that if there is no grab data, then we are not being grabbed
|
||||
var defaultGrabData = { activated: false, avatarId: null };
|
||||
|
||||
// this handy function getEntityCustomData() is available in utils.js and it will return just the specific section
|
||||
// of user data we asked for. If it's not available it returns our default data.
|
||||
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, entityID, defaultGrabData);
|
||||
|
||||
|
||||
// if the grabData says we're being grabbed, and the owner ID is our session, then we are being grabbed by this interface
|
||||
if (grabData.activated && grabData.avatarId == MyAvatar.sessionUUID) {
|
||||
|
||||
// remember we're being grabbed so we can detect being released
|
||||
_this.beingGrabbed = true;
|
||||
|
||||
var modelProperties = Entities.getEntityProperties(entityID);
|
||||
var lightTransform = evalLightWorldTransform(modelProperties.position, modelProperties.rotation);
|
||||
|
||||
// Create the spot light driven by this model if we don;t have one yet
|
||||
// Or make sure to keep it's position in sync
|
||||
if (!_this._hasSpotlight) {
|
||||
|
||||
_this._spotlight = Entities.addEntity({
|
||||
type: "Light",
|
||||
position: lightTransform.p,
|
||||
rotation: lightTransform.q,
|
||||
isSpotlight: true,
|
||||
dimensions: { x: 2, y: 2, z: 20 },
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
intensity: 2,
|
||||
exponent: 0.3,
|
||||
cutoff: 20
|
||||
});
|
||||
_this._hasSpotlight = true;
|
||||
|
||||
_this._startModelPosition = modelProperties.position;
|
||||
_this._startModelRotation = modelProperties.rotation;
|
||||
|
||||
debugPrint("Flashlight:: creating a spotlight");
|
||||
} else {
|
||||
// Updating the spotlight
|
||||
Entities.editEntity(_this._spotlight, {position: lightTransform.p, rotation: lightTransform.q});
|
||||
|
||||
debugPrint("Flashlight:: updating the spotlight");
|
||||
}
|
||||
|
||||
debugPrint("I'm being grabbed...");
|
||||
|
||||
} else if (_this.beingGrabbed) {
|
||||
|
||||
if (_this._hasSpotlight) {
|
||||
Entities.deleteEntity(_this._spotlight);
|
||||
debugPrint("Destroying flashlight spotlight...");
|
||||
}
|
||||
_this._hasSpotlight = false;
|
||||
_this._spotlight = null;
|
||||
|
||||
// Reset model to initial position
|
||||
Entities.editEntity(_this.entityID, {position: _this._startModelPosition, rotation: _this._startModelRotation,
|
||||
velocity: {x: 0, y: 0, z: 0}, angularVelocity: {x: 0, y: 0, z: 0}});
|
||||
|
||||
// if we are not being grabbed, and we previously were, then we were just released, remember that
|
||||
// and print out a message
|
||||
_this.beingGrabbed = false;
|
||||
debugPrint("I'm was released...");
|
||||
}
|
||||
},
|
||||
|
||||
// preload() will be called when the entity has become visible (or known) to the interface
|
||||
// it gives us a chance to set our local JavaScript object up. In this case it means:
|
||||
// * remembering our entityID, so we can access it in cases where we're called without an entityID
|
||||
// * connecting to the update signal so we can check our grabbed state
|
||||
preload: function(entityID) {
|
||||
_this.entityID = entityID;
|
||||
|
||||
var modelProperties = Entities.getEntityProperties(entityID);
|
||||
_this._startModelPosition = modelProperties.position;
|
||||
_this._startModelRotation = modelProperties.rotation;
|
||||
|
||||
Script.update.connect(this.update);
|
||||
},
|
||||
|
||||
// unload() will be called when our entity is no longer available. It may be because we were deleted,
|
||||
// or because we've left the domain or quit the application. In all cases we want to unhook our connection
|
||||
// to the update signal
|
||||
unload: function(entityID) {
|
||||
|
||||
if (_this._hasSpotlight) {
|
||||
Entities.deleteEntity(_this._spotlight);
|
||||
}
|
||||
_this._hasSpotlight = false;
|
||||
_this._spotlight = null;
|
||||
|
||||
Script.update.disconnect(this.update);
|
||||
},
|
||||
};
|
||||
|
||||
// entity scripts always need to return a newly constructed object of our type
|
||||
return new Flashlight();
|
||||
})
|
|
@ -52,6 +52,11 @@ Item {
|
|||
font.pixelSize: root.fontSize
|
||||
text: "Simrate: " + root.simrate
|
||||
}
|
||||
Text {
|
||||
color: root.fontColor;
|
||||
font.pixelSize: root.fontSize
|
||||
text: "Avatar Simrate: " + root.avatarSimrate
|
||||
}
|
||||
Text {
|
||||
color: root.fontColor;
|
||||
font.pixelSize: root.fontSize
|
||||
|
|
|
@ -786,6 +786,14 @@ void Application::aboutToQuit() {
|
|||
}
|
||||
|
||||
void Application::cleanupBeforeQuit() {
|
||||
// Terminate third party processes so that they're not left running in the event of a subsequent shutdown crash
|
||||
#ifdef HAVE_DDE
|
||||
DependencyManager::destroy<DdeFaceTracker>();
|
||||
#endif
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
DependencyManager::destroy<EyeTracker>();
|
||||
#endif
|
||||
|
||||
if (_keyboardFocusHighlightID > 0) {
|
||||
getOverlays().deleteOverlay(_keyboardFocusHighlightID);
|
||||
_keyboardFocusHighlightID = -1;
|
||||
|
@ -802,6 +810,7 @@ void Application::cleanupBeforeQuit() {
|
|||
|
||||
// first stop all timers directly or by invokeMethod
|
||||
// depending on what thread they run in
|
||||
_avatarUpdate->terminate();
|
||||
locationUpdateTimer->stop();
|
||||
balanceUpdateTimer->stop();
|
||||
identityPacketTimer->stop();
|
||||
|
@ -833,13 +842,6 @@ void Application::cleanupBeforeQuit() {
|
|||
|
||||
// destroy the AudioClient so it and its thread have a chance to go down safely
|
||||
DependencyManager::destroy<AudioClient>();
|
||||
|
||||
#ifdef HAVE_DDE
|
||||
DependencyManager::destroy<DdeFaceTracker>();
|
||||
#endif
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
DependencyManager::destroy<EyeTracker>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::emptyLocalCache() {
|
||||
|
@ -1068,7 +1070,7 @@ void Application::paintGL() {
|
|||
|
||||
// Before anything else, let's sync up the gpuContext with the true glcontext used in case anything happened
|
||||
renderArgs._context->syncCache();
|
||||
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
|
||||
auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
|
||||
|
||||
|
@ -1101,6 +1103,7 @@ void Application::paintGL() {
|
|||
_applicationOverlay.renderOverlay(&renderArgs);
|
||||
}
|
||||
|
||||
_myAvatar->startCapture();
|
||||
if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
|
||||
|
@ -1150,7 +1153,7 @@ void Application::paintGL() {
|
|||
if (!isHMDMode()) {
|
||||
_myCamera.update(1.0f / _fps);
|
||||
}
|
||||
|
||||
_myAvatar->endCapture();
|
||||
|
||||
// Primary rendering pass
|
||||
auto framebufferCache = DependencyManager::get<FramebufferCache>();
|
||||
|
@ -2172,6 +2175,18 @@ float Application::getAverageSimsPerSecond() {
|
|||
}
|
||||
return _simsPerSecondReport;
|
||||
}
|
||||
void Application::setAvatarSimrateSample(float sample) {
|
||||
_avatarSimsPerSecond.updateAverage(sample);
|
||||
}
|
||||
float Application::getAvatarSimrate() {
|
||||
uint64_t now = usecTimestampNow();
|
||||
|
||||
if (now - _lastAvatarSimsPerSecondUpdate > USECS_PER_SECOND) {
|
||||
_avatarSimsPerSecondReport = _avatarSimsPerSecond.getAverage();
|
||||
_lastAvatarSimsPerSecondUpdate = now;
|
||||
}
|
||||
return _avatarSimsPerSecondReport;
|
||||
}
|
||||
|
||||
void Application::setLowVelocityFilter(bool lowVelocityFilter) {
|
||||
InputDevice::setLowVelocityFilter(lowVelocityFilter);
|
||||
|
@ -2457,8 +2472,20 @@ void Application::init() {
|
|||
// Make sure any new sounds are loaded as soon as know about them.
|
||||
connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound);
|
||||
connect(_myAvatar, &MyAvatar::newCollisionSoundURL, DependencyManager::get<SoundCache>().data(), &SoundCache::getSound);
|
||||
|
||||
setAvatarUpdateThreading(Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading));
|
||||
}
|
||||
|
||||
void Application::setAvatarUpdateThreading(bool isThreaded) {
|
||||
if (_avatarUpdate) {
|
||||
getMyAvatar()->destroyAnimGraph();
|
||||
_avatarUpdate->terminate();
|
||||
}
|
||||
_avatarUpdate = new AvatarUpdate();
|
||||
_avatarUpdate->initialize(isThreaded);
|
||||
}
|
||||
|
||||
|
||||
void Application::closeMirrorView() {
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
|
||||
Menu::getInstance()->triggerOption(MenuOption::Mirror);
|
||||
|
@ -2535,18 +2562,19 @@ void Application::updateMyAvatarLookAtPosition() {
|
|||
auto eyeTracker = DependencyManager::get<EyeTracker>();
|
||||
|
||||
bool isLookingAtSomeone = false;
|
||||
bool isHMD = _avatarUpdate->isHMDMode();
|
||||
glm::vec3 lookAtSpot;
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
// When I am in mirror mode, just look right at the camera (myself); don't switch gaze points because when physically
|
||||
// looking in a mirror one's eyes appear steady.
|
||||
if (!isHMDMode()) {
|
||||
if (!isHMD) {
|
||||
lookAtSpot = _myCamera.getPosition();
|
||||
} else {
|
||||
lookAtSpot = _myCamera.getPosition() + transformPoint(_myAvatar->getSensorToWorldMatrix(), extractTranslation(getHMDSensorPose()));
|
||||
}
|
||||
} else if (eyeTracker->isTracking() && (isHMDMode() || eyeTracker->isSimulating())) {
|
||||
} else if (eyeTracker->isTracking() && (isHMD || eyeTracker->isSimulating())) {
|
||||
// Look at the point that the user is looking at.
|
||||
if (isHMDMode()) {
|
||||
if (isHMD) {
|
||||
glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
|
||||
glm::quat hmdRotation = glm::quat_cast(headPose);
|
||||
lookAtSpot = _myCamera.getPosition() +
|
||||
|
@ -2589,8 +2617,8 @@ void Application::updateMyAvatarLookAtPosition() {
|
|||
}
|
||||
} else {
|
||||
// I am not looking at anyone else, so just look forward
|
||||
if (isHMDMode()) {
|
||||
glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
|
||||
if (isHMD) {
|
||||
glm::mat4 headPose = _avatarUpdate->getHeadPose() ;
|
||||
glm::quat headRotation = glm::quat_cast(headPose);
|
||||
lookAtSpot = _myCamera.getPosition() +
|
||||
_myAvatar->getOrientation() * (headRotation * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
|
||||
|
@ -2817,9 +2845,6 @@ void Application::update(float deltaTime) {
|
|||
|
||||
updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
|
||||
|
||||
//loop through all the other avatars and simulate them...
|
||||
DependencyManager::get<AvatarManager>()->updateOtherAvatars(deltaTime);
|
||||
|
||||
updateCamera(deltaTime); // handle various camera tweaks like off axis projection
|
||||
updateDialogs(deltaTime); // update various stats dialogs if present
|
||||
updateCursor(deltaTime); // Handle cursor updates
|
||||
|
@ -2891,12 +2916,7 @@ void Application::update(float deltaTime) {
|
|||
_overlays.update(deltaTime);
|
||||
}
|
||||
|
||||
{
|
||||
PerformanceTimer perfTimer("myAvatar");
|
||||
updateMyAvatarLookAtPosition();
|
||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes
|
||||
DependencyManager::get<AvatarManager>()->updateMyAvatar(deltaTime);
|
||||
}
|
||||
_avatarUpdate->synchronousProcess();
|
||||
|
||||
{
|
||||
PerformanceTimer perfTimer("emitSimulating");
|
||||
|
@ -3477,7 +3497,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
|||
|
||||
// FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering.
|
||||
// Then we can move this logic into the Avatar::simulate call.
|
||||
_myAvatar->startRender();
|
||||
_myAvatar->preRender(renderArgs);
|
||||
_myAvatar->endRender();
|
||||
|
||||
|
||||
activeRenderingThread = QThread::currentThread();
|
||||
PROFILE_RANGE(__FUNCTION__);
|
||||
|
@ -3591,7 +3614,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
|||
_renderEngine->setRenderContext(renderContext);
|
||||
|
||||
// Before the deferred pass, let's try to use the render engine
|
||||
_myAvatar->startRenderRun();
|
||||
_renderEngine->run();
|
||||
_myAvatar->endRenderRun();
|
||||
|
||||
auto engineRC = _renderEngine->getRenderContext();
|
||||
sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems);
|
||||
|
@ -4761,9 +4786,11 @@ void Application::updateDisplayMode() {
|
|||
qDebug() << "Deferring plugin switch until out of painting";
|
||||
// Have the old plugin stop requesting renders
|
||||
oldDisplayPlugin->stop();
|
||||
QCoreApplication::postEvent(this, new LambdaEvent([this] {
|
||||
QTimer* timer = new QTimer();
|
||||
timer->singleShot(500, [this, timer] {
|
||||
timer->deleteLater();
|
||||
updateDisplayMode();
|
||||
}));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "Menu.h"
|
||||
#include "Physics.h"
|
||||
#include "Stars.h"
|
||||
#include "avatar/AvatarUpdate.h"
|
||||
#include "avatar/Avatar.h"
|
||||
#include "avatar/MyAvatar.h"
|
||||
#include "scripting/ControllerScriptingInterface.h"
|
||||
|
@ -335,6 +336,12 @@ public:
|
|||
|
||||
const QRect& getMirrorViewRect() const { return _mirrorViewRect; }
|
||||
|
||||
void updateMyAvatarLookAtPosition();
|
||||
AvatarUpdate* getAvatarUpdater() { return _avatarUpdate; }
|
||||
MyAvatar* getMyAvatar() { return _myAvatar; }
|
||||
float getAvatarSimrate();
|
||||
void setAvatarSimrateSample(float sample);
|
||||
|
||||
float getAverageSimsPerSecond();
|
||||
|
||||
signals:
|
||||
|
@ -405,6 +412,7 @@ public slots:
|
|||
void openUrl(const QUrl& url);
|
||||
|
||||
void updateMyAvatarTransform();
|
||||
void setAvatarUpdateThreading(bool isThreaded);
|
||||
|
||||
void domainSettingsReceived(const QJsonObject& domainSettingsObject);
|
||||
|
||||
|
@ -482,7 +490,6 @@ private:
|
|||
// Various helper functions called during update()
|
||||
void updateLOD();
|
||||
void updateMouseRay();
|
||||
void updateMyAvatarLookAtPosition();
|
||||
void updateThreads(float deltaTime);
|
||||
void updateCamera(float deltaTime);
|
||||
void updateDialogs(float deltaTime);
|
||||
|
@ -551,6 +558,10 @@ private:
|
|||
|
||||
KeyboardMouseDevice* _keyboardMouseDevice{ nullptr }; // Default input device, the good old keyboard mouse and maybe touchpad
|
||||
MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be)
|
||||
AvatarUpdate* _avatarUpdate {nullptr};
|
||||
SimpleMovingAverage _avatarSimsPerSecond {10};
|
||||
int _avatarSimsPerSecondReport {0};
|
||||
quint64 _lastAvatarSimsPerSecondUpdate {0};
|
||||
Camera _myCamera; // My view onto the world
|
||||
Camera _mirrorCamera; // Cammera for mirror view
|
||||
QRect _mirrorViewRect;
|
||||
|
|
|
@ -447,6 +447,8 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderFocusIndicator, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ShowWhosLookingAtMe, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::FixGaze, 0, false);
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableAvatarUpdateThreading, 0, false,
|
||||
qApp, SLOT(setAvatarUpdateThreading(bool)));
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableRigAnimations, 0, true,
|
||||
avatar, SLOT(setEnableRigAnimations(bool)));
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableAnimGraph, 0, false,
|
||||
|
|
|
@ -188,6 +188,7 @@ namespace MenuOption {
|
|||
const QString EchoServerAudio = "Echo Server Audio";
|
||||
const QString EditEntitiesHelp = "Edit Entities Help...";
|
||||
const QString Enable3DTVMode = "Enable 3DTV Mode";
|
||||
const QString EnableAvatarUpdateThreading = "Enable Avatar Update Threading";
|
||||
const QString EnableAnimGraph = "Enable Anim Graph";
|
||||
const QString EnableCharacterController = "Enable avatar collisions";
|
||||
const QString EnableRigAnimations = "Enable Rig Animations";
|
||||
|
|
|
@ -316,6 +316,7 @@ void Avatar::removeFromScene(AvatarSharedPointer self, std::shared_ptr<render::S
|
|||
}
|
||||
|
||||
void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) {
|
||||
startRender();
|
||||
if (_referential) {
|
||||
_referential->update();
|
||||
}
|
||||
|
@ -390,6 +391,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) {
|
|||
}
|
||||
|
||||
if (frustum->sphereInFrustum(getPosition(), boundingRadius) == ViewFrustum::OUTSIDE) {
|
||||
endRender();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -540,6 +542,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) {
|
|||
if (!isMyAvatar() || cameraMode != CAMERA_MODE_FIRST_PERSON) {
|
||||
renderDisplayName(batch, *renderArgs->_viewFrustum, renderArgs->_viewport);
|
||||
}
|
||||
endRender();
|
||||
}
|
||||
|
||||
glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
||||
|
@ -1019,6 +1022,7 @@ void Avatar::setBillboard(const QByteArray& billboard) {
|
|||
}
|
||||
|
||||
int Avatar::parseDataFromBuffer(const QByteArray& buffer) {
|
||||
startUpdate();
|
||||
if (!_initialized) {
|
||||
// now that we have data for this Avatar we are go for init
|
||||
init();
|
||||
|
@ -1034,6 +1038,7 @@ int Avatar::parseDataFromBuffer(const QByteArray& buffer) {
|
|||
if (_moving && _motionState) {
|
||||
_motionState->addDirtyFlags(EntityItem::DIRTY_POSITION);
|
||||
}
|
||||
endUpdate();
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,7 @@ public:
|
|||
void scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const;
|
||||
|
||||
void slamPosition(const glm::vec3& position);
|
||||
virtual void updateAttitude() { _skeletonModel.updateAttitude(); }
|
||||
|
||||
// Call this when updating Avatar position with a delta. This will allow us to
|
||||
// _accurately_ measure position changes and compute the resulting velocity
|
||||
|
|
|
@ -129,7 +129,9 @@ void AvatarManager::updateOtherAvatars(float deltaTime) {
|
|||
_avatarFades.push_back(avatarIterator.value());
|
||||
avatarIterator = _avatarHash.erase(avatarIterator);
|
||||
} else {
|
||||
avatar->startUpdate();
|
||||
avatar->simulate(deltaTime);
|
||||
avatar->endUpdate();
|
||||
++avatarIterator;
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +150,7 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
|
|||
render::PendingChanges pendingChanges;
|
||||
while (fadingIterator != _avatarFades.end()) {
|
||||
auto avatar = std::static_pointer_cast<Avatar>(*fadingIterator);
|
||||
avatar->startUpdate();
|
||||
avatar->setTargetScale(avatar->getScale() * SHRINK_RATE, true);
|
||||
if (avatar->getTargetScale() < MIN_FADE_SCALE) {
|
||||
avatar->removeFromScene(*fadingIterator, scene, pendingChanges);
|
||||
|
@ -156,6 +159,7 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
|
|||
avatar->simulate(deltaTime);
|
||||
++fadingIterator;
|
||||
}
|
||||
avatar->endUpdate();
|
||||
}
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
|
|
75
interface/src/avatar/AvatarUpdate.cpp
Normal file
75
interface/src/avatar/AvatarUpdate.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
//
|
||||
// AvatarUpdate.cpp
|
||||
// interface/src/avatar
|
||||
//
|
||||
// Created by Howard Stearns on 8/18/15.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
//
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include "Application.h"
|
||||
#include "AvatarManager.h"
|
||||
#include "AvatarUpdate.h"
|
||||
#include <display-plugins/DisplayPlugin.h>
|
||||
#include "InterfaceLogging.h"
|
||||
|
||||
AvatarUpdate::AvatarUpdate() : GenericThread(), _lastAvatarUpdate(0) {
|
||||
setObjectName("Avatar Update"); // GenericThread::initialize uses this to set the thread name.
|
||||
Settings settings;
|
||||
const int DEFAULT_TARGET_AVATAR_SIMRATE = 60;
|
||||
_targetInterval = USECS_PER_SECOND / settings.value("AvatarUpdateTargetSimrate", DEFAULT_TARGET_AVATAR_SIMRATE).toInt();
|
||||
}
|
||||
// We could have the constructor call initialize(), but GenericThread::initialize can take parameters.
|
||||
// Keeping it separately called by the client allows that client to pass those without our
|
||||
// constructor needing to know about them.
|
||||
|
||||
void AvatarUpdate::synchronousProcess() {
|
||||
|
||||
// Keep our own updated value, so that our asynchronous code can consult it.
|
||||
_isHMDMode = Application::getInstance()->isHMDMode();
|
||||
_headPose = Application::getInstance()->getActiveDisplayPlugin()->getHeadPose();
|
||||
|
||||
if (_updateBillboard) {
|
||||
Application::getInstance()->getMyAvatar()->doUpdateBillboard();
|
||||
}
|
||||
|
||||
if (!isThreaded()) {
|
||||
process();
|
||||
}
|
||||
}
|
||||
|
||||
bool AvatarUpdate::process() {
|
||||
PerformanceTimer perfTimer("AvatarUpdate");
|
||||
quint64 start = usecTimestampNow();
|
||||
quint64 deltaMicroseconds = start - _lastAvatarUpdate;
|
||||
_lastAvatarUpdate = start;
|
||||
float deltaSeconds = (float) deltaMicroseconds / (float) USECS_PER_SECOND;
|
||||
Application::getInstance()->setAvatarSimrateSample(1.0f / deltaSeconds);
|
||||
|
||||
QSharedPointer<AvatarManager> manager = DependencyManager::get<AvatarManager>();
|
||||
MyAvatar* myAvatar = manager->getMyAvatar();
|
||||
|
||||
//loop through all the other avatars and simulate them...
|
||||
//gets current lookat data, removes missing avatars, etc.
|
||||
manager->updateOtherAvatars(deltaSeconds);
|
||||
|
||||
myAvatar->startUpdate();
|
||||
Application::getInstance()->updateMyAvatarLookAtPosition();
|
||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes
|
||||
manager->updateMyAvatar(deltaSeconds);
|
||||
myAvatar->endUpdate();
|
||||
|
||||
if (!isThreaded()) {
|
||||
return true;
|
||||
}
|
||||
int elapsed = (usecTimestampNow() - start);
|
||||
int usecToSleep = _targetInterval - elapsed;
|
||||
if (usecToSleep < 0) {
|
||||
usecToSleep = 1; // always yield
|
||||
}
|
||||
usleep(usecToSleep);
|
||||
return true;
|
||||
}
|
43
interface/src/avatar/AvatarUpdate.h
Normal file
43
interface/src/avatar/AvatarUpdate.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// AvatarUpdate.h
|
||||
// interface/src/avatar
|
||||
//
|
||||
// Created by Howard Stearns on 8/18/15.
|
||||
///
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef __hifi__AvatarUpdate__
|
||||
#define __hifi__AvatarUpdate__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QTimer>
|
||||
|
||||
// Home for the avatarUpdate operations (e.g., whether on a separate thread, pipelined in various ways, etc.)
|
||||
// This might get folded into AvatarManager.
|
||||
class AvatarUpdate : public GenericThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AvatarUpdate();
|
||||
void synchronousProcess();
|
||||
void setRequestBillboardUpdate(bool needsUpdate) { _updateBillboard = needsUpdate; }
|
||||
|
||||
private:
|
||||
virtual bool process(); // No reason for other classes to invoke this.
|
||||
quint64 _lastAvatarUpdate; // microsoeconds
|
||||
quint64 _targetInterval; // microseconds
|
||||
bool _updateBillboard;
|
||||
|
||||
// Goes away if Application::getActiveDisplayPlugin() and friends are made thread safe:
|
||||
public:
|
||||
bool isHMDMode() { return _isHMDMode; }
|
||||
glm::mat4 getHeadPose() { return _headPose; }
|
||||
private:
|
||||
bool _isHMDMode;
|
||||
glm::mat4 _headPose;
|
||||
};
|
||||
|
||||
|
||||
#endif /* defined(__hifi__AvatarUpdate__) */
|
|
@ -389,7 +389,7 @@ glm::quat Head::getCameraOrientation() const {
|
|||
// to change the driving direction while in Oculus mode. It is used to support driving toward where you're
|
||||
// head is looking. Note that in oculus mode, your actual camera view and where your head is looking is not
|
||||
// always the same.
|
||||
if (qApp->isHMDMode()) {
|
||||
if (qApp->getAvatarUpdater()->isHMDMode()) {
|
||||
MyAvatar* myAvatar = dynamic_cast<MyAvatar*>(_owningAvatar);
|
||||
if (myAvatar && myAvatar->getStandingHMDSensorMode()) {
|
||||
return glm::quat_cast(myAvatar->getSensorToWorldMatrix()) * myAvatar->getHMDSensorOrientation();
|
||||
|
|
|
@ -266,8 +266,7 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
|
|||
if (getStandingHMDSensorMode()) {
|
||||
// set the body position/orientation to reflect motion due to the head.
|
||||
auto worldMat = _sensorToWorldMatrix * _bodySensorMatrix;
|
||||
setPosition(extractTranslation(worldMat));
|
||||
setOrientation(glm::quat_cast(worldMat));
|
||||
nextAttitude(extractTranslation(worldMat), glm::quat_cast(worldMat));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,7 +284,7 @@ void MyAvatar::updateSensorToWorldMatrix() {
|
|||
void MyAvatar::updateFromTrackers(float deltaTime) {
|
||||
glm::vec3 estimatedPosition, estimatedRotation;
|
||||
|
||||
bool inHmd = qApp->isHMDMode();
|
||||
bool inHmd = qApp->getAvatarUpdater()->isHMDMode();
|
||||
|
||||
if (isPlaying() && inHmd) {
|
||||
return;
|
||||
|
@ -705,19 +704,46 @@ float loadSetting(QSettings& settings, const char* name, float defaultValue) {
|
|||
return value;
|
||||
}
|
||||
|
||||
// Resource loading is not yet thread safe. If an animation is not loaded when requested by other than tha main thread,
|
||||
// we block in AnimationHandle::setURL => AnimationCache::getAnimation.
|
||||
// Meanwhile, the main thread will also eventually lock as it tries to render us.
|
||||
// If we demand the animation from the update thread while we're locked, we'll deadlock.
|
||||
// Until we untangle this, code puts the updates back on the main thread temporarilly and starts all the loading.
|
||||
void MyAvatar::safelyLoadAnimations() {
|
||||
qApp->setAvatarUpdateThreading(false);
|
||||
_rig->addAnimationByRole("idle");
|
||||
_rig->addAnimationByRole("walk");
|
||||
_rig->addAnimationByRole("backup");
|
||||
_rig->addAnimationByRole("leftTurn");
|
||||
_rig->addAnimationByRole("rightTurn");
|
||||
_rig->addAnimationByRole("leftStrafe");
|
||||
_rig->addAnimationByRole("rightStrafe");
|
||||
}
|
||||
|
||||
void MyAvatar::setEnableRigAnimations(bool isEnabled) {
|
||||
if (isEnabled) {
|
||||
safelyLoadAnimations();
|
||||
}
|
||||
_rig->setEnableRig(isEnabled);
|
||||
if (!isEnabled) {
|
||||
_rig->deleteAnimations();
|
||||
} else if (Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)) {
|
||||
qApp->setAvatarUpdateThreading(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::setEnableAnimGraph(bool isEnabled) {
|
||||
if (isEnabled) {
|
||||
safelyLoadAnimations();
|
||||
}
|
||||
_rig->setEnableAnimGraph(isEnabled);
|
||||
if (isEnabled) {
|
||||
if (_skeletonModel.readyToAddToScene()) {
|
||||
initAnimGraph();
|
||||
}
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)) {
|
||||
qApp->setAvatarUpdateThreading(true);
|
||||
}
|
||||
} else {
|
||||
destroyAnimGraph();
|
||||
}
|
||||
|
@ -804,6 +830,9 @@ void MyAvatar::loadData() {
|
|||
|
||||
settings.endGroup();
|
||||
_rig->setEnableRig(Menu::getInstance()->isOptionChecked(MenuOption::EnableRigAnimations));
|
||||
setEnableMeshVisible(Menu::getInstance()->isOptionChecked(MenuOption::MeshVisible));
|
||||
setEnableDebugDrawBindPose(Menu::getInstance()->isOptionChecked(MenuOption::AnimDebugDrawBindPose));
|
||||
setEnableDebugDrawAnimPose(Menu::getInstance()->isOptionChecked(MenuOption::AnimDebugDrawAnimPose));
|
||||
}
|
||||
|
||||
void MyAvatar::saveAttachmentData(const AttachmentData& attachment) const {
|
||||
|
@ -1243,7 +1272,7 @@ void MyAvatar::initAnimGraph() {
|
|||
// python2 -m SimpleHTTPServer&
|
||||
//auto graphUrl = QUrl("http://localhost:8000/avatar.json");
|
||||
auto graphUrl = QUrl("https://gist.githubusercontent.com/hyperlogic/7d6a0892a7319c69e2b9/raw/e2cb37aee601b6fba31d60eac3f6ae3ef72d4a66/avatar.json");
|
||||
_skeletonModel.initAnimGraph(graphUrl, _skeletonModel.getGeometry()->getFBXGeometry());
|
||||
_rig->initAnimGraph(graphUrl, _skeletonModel.getGeometry()->getFBXGeometry());
|
||||
}
|
||||
|
||||
void MyAvatar::destroyAnimGraph() {
|
||||
|
@ -1341,7 +1370,7 @@ void MyAvatar::updateOrientation(float deltaTime) {
|
|||
setOrientation(getOrientation() *
|
||||
glm::quat(glm::radians(glm::vec3(0.0f, _bodyYawDelta * deltaTime, 0.0f))));
|
||||
|
||||
if (qApp->isHMDMode()) {
|
||||
if (qApp->getAvatarUpdater()->isHMDMode()) {
|
||||
glm::quat orientation = glm::quat_cast(getSensorToWorldMatrix()) * getHMDSensorOrientation();
|
||||
glm::quat bodyOrientation = getWorldBodyOrientation();
|
||||
glm::quat localOrientation = glm::inverse(bodyOrientation) * orientation;
|
||||
|
@ -1562,6 +1591,7 @@ bool findAvatarAvatarPenetration(const glm::vec3 positionA, float radiusA, float
|
|||
}
|
||||
|
||||
void MyAvatar::maybeUpdateBillboard() {
|
||||
qApp->getAvatarUpdater()->setRequestBillboardUpdate(false);
|
||||
if (_billboardValid || !(_skeletonModel.isLoadedWithTextures() && getHead()->getFaceModel().isLoadedWithTextures())) {
|
||||
return;
|
||||
}
|
||||
|
@ -1570,7 +1600,9 @@ void MyAvatar::maybeUpdateBillboard() {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qApp->getAvatarUpdater()->setRequestBillboardUpdate(true);
|
||||
}
|
||||
void MyAvatar::doUpdateBillboard() {
|
||||
RenderArgs renderArgs(qApp->getGPUContext());
|
||||
QImage image = qApp->renderAvatarBillboard(&renderArgs);
|
||||
_billboard.clear();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "Avatar.h"
|
||||
|
||||
class ModelItemID;
|
||||
class AnimNode;
|
||||
|
||||
enum eyeContactTarget {
|
||||
LEFT_EYE,
|
||||
|
@ -151,6 +150,8 @@ public:
|
|||
static const float ZOOM_DEFAULT;
|
||||
|
||||
bool getStandingHMDSensorMode() const { return _standingHMDSensorMode; }
|
||||
void doUpdateBillboard();
|
||||
void destroyAnimGraph();
|
||||
|
||||
public slots:
|
||||
void increaseSize();
|
||||
|
@ -290,7 +291,7 @@ private:
|
|||
void maybeUpdateBillboard();
|
||||
void initHeadBones();
|
||||
void initAnimGraph();
|
||||
void destroyAnimGraph();
|
||||
void safelyLoadAnimations();
|
||||
|
||||
// Avatar Preferences
|
||||
QUrl _fullAvatarURLFromPreferences;
|
||||
|
|
|
@ -111,7 +111,7 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
Rig::HeadParameters params;
|
||||
params.modelRotation = getRotation();
|
||||
params.modelTranslation = getTranslation();
|
||||
params.enableLean = qApp->isHMDMode() && !myAvatar->getStandingHMDSensorMode();
|
||||
params.enableLean = qApp->getAvatarUpdater()->isHMDMode() && !myAvatar->getStandingHMDSensorMode();
|
||||
params.leanSideways = head->getFinalLeanSideways();
|
||||
params.leanForward = head->getFinalLeanForward();
|
||||
params.torsoTwist = head->getTorsoTwist();
|
||||
|
@ -148,13 +148,17 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
}
|
||||
}
|
||||
|
||||
// Called by Avatar::simulate after it has set the joint states (fullUpdate true if changed),
|
||||
// but just before head has been simulated.
|
||||
void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||
void SkeletonModel::updateAttitude() {
|
||||
setTranslation(_owningAvatar->getSkeletonPosition());
|
||||
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
setRotation(_owningAvatar->getOrientation() * refOrientation);
|
||||
setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale());
|
||||
}
|
||||
|
||||
// Called by Avatar::simulate after it has set the joint states (fullUpdate true if changed),
|
||||
// but just before head has been simulated.
|
||||
void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||
updateAttitude();
|
||||
setBlendshapeCoefficients(_owningAvatar->getHead()->getBlendshapeCoefficients());
|
||||
|
||||
Model::simulate(deltaTime, fullUpdate);
|
||||
|
@ -618,6 +622,3 @@ bool SkeletonModel::hasSkeleton() {
|
|||
void SkeletonModel::onInvalidate() {
|
||||
}
|
||||
|
||||
void SkeletonModel::initAnimGraph(const QUrl& url, const FBXGeometry& fbxGeometry) {
|
||||
_rig->initAnimGraph(url, fbxGeometry);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
|
||||
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
||||
virtual void updateRig(float deltaTime, glm::mat4 parentTransform);
|
||||
void updateAttitude();
|
||||
|
||||
void renderIKConstraints(gpu::Batch& batch);
|
||||
|
||||
|
@ -105,8 +106,6 @@ public:
|
|||
|
||||
virtual void onInvalidate() override;
|
||||
|
||||
void initAnimGraph(const QUrl& url, const FBXGeometry& fbxGeometry);
|
||||
|
||||
signals:
|
||||
|
||||
void skeletonLoaded();
|
||||
|
|
|
@ -236,29 +236,25 @@ void DdeFaceTracker::setEnabled(bool enabled) {
|
|||
cancelCalibration();
|
||||
}
|
||||
|
||||
|
||||
// isOpen() does not work as one might expect on QUdpSocket; don't test isOpen() before closing socket.
|
||||
_udpSocket.close();
|
||||
if (enabled) {
|
||||
_udpSocket.bind(_host, _serverPort);
|
||||
}
|
||||
|
||||
// Terminate any existing DDE process, perhaps left running after an Interface crash.
|
||||
// Do this even if !enabled in case user reset their settings after crash.
|
||||
const char* DDE_EXIT_COMMAND = "exit";
|
||||
_udpSocket.bind(_host, _serverPort);
|
||||
_udpSocket.writeDatagram(DDE_EXIT_COMMAND, DDE_SERVER_ADDR, _controlPort);
|
||||
|
||||
if (enabled && !_ddeProcess) {
|
||||
// Terminate any existing DDE process, perhaps left running after an Interface crash
|
||||
_udpSocket.writeDatagram(DDE_EXIT_COMMAND, DDE_SERVER_ADDR, _controlPort);
|
||||
_ddeStopping = false;
|
||||
|
||||
qCDebug(interfaceapp) << "DDE Face Tracker: Starting";
|
||||
_ddeProcess = new QProcess(qApp);
|
||||
connect(_ddeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(processFinished(int, QProcess::ExitStatus)));
|
||||
_ddeProcess->start(QCoreApplication::applicationDirPath() + DDE_PROGRAM_PATH, DDE_ARGUMENTS);
|
||||
}
|
||||
|
||||
|
||||
if (!enabled && _ddeProcess) {
|
||||
_ddeStopping = true;
|
||||
_udpSocket.writeDatagram(DDE_EXIT_COMMAND, DDE_SERVER_ADDR, _controlPort);
|
||||
qCDebug(interfaceapp) << "DDE Face Tracker: Stopping";
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -115,6 +115,7 @@ void Stats::updateStats() {
|
|||
STAT_UPDATE(serverCount, nodeList->size());
|
||||
STAT_UPDATE(framerate, (int)qApp->getFps());
|
||||
STAT_UPDATE(simrate, (int)Application::getInstance()->getAverageSimsPerSecond());
|
||||
STAT_UPDATE(avatarSimrate, (int)qApp->getAvatarSimrate());
|
||||
|
||||
auto bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
|
||||
STAT_UPDATE(packetInCount, bandwidthRecorder->getCachedTotalAverageInputPacketsPerSecond());
|
||||
|
|
|
@ -31,6 +31,7 @@ class Stats : public QQuickItem {
|
|||
STATS_PROPERTY(int, serverCount, 0)
|
||||
STATS_PROPERTY(int, framerate, 0)
|
||||
STATS_PROPERTY(int, simrate, 0)
|
||||
STATS_PROPERTY(int, avatarSimrate, 0)
|
||||
STATS_PROPERTY(int, avatarCount, 0)
|
||||
STATS_PROPERTY(int, packetInCount, 0)
|
||||
STATS_PROPERTY(int, packetOutCount, 0)
|
||||
|
@ -98,6 +99,7 @@ signals:
|
|||
void serverCountChanged();
|
||||
void framerateChanged();
|
||||
void simrateChanged();
|
||||
void avatarSimrateChanged();
|
||||
void avatarCountChanged();
|
||||
void packetInCountChanged();
|
||||
void packetOutCountChanged();
|
||||
|
|
|
@ -69,13 +69,13 @@ static NodeProcessFunc animNodeTypeToProcessFunc(AnimNode::Type type) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
#define READ_STRING(NAME, JSON_OBJ, ID, URL) \
|
||||
#define READ_STRING(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||
if (!NAME##_VAL.isString()) { \
|
||||
qCCritical(animation) << "AnimNodeLoader, error reading string" \
|
||||
<< #NAME << ", id =" << ID \
|
||||
<< ", url =" << URL.toDisplayString(); \
|
||||
return nullptr; \
|
||||
return ERROR_RETURN; \
|
||||
} \
|
||||
QString NAME = NAME##_VAL.toString()
|
||||
|
||||
|
@ -86,23 +86,23 @@ static NodeProcessFunc animNodeTypeToProcessFunc(AnimNode::Type type) {
|
|||
NAME = NAME##_VAL.toString(); \
|
||||
}
|
||||
|
||||
#define READ_BOOL(NAME, JSON_OBJ, ID, URL) \
|
||||
#define READ_BOOL(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||
if (!NAME##_VAL.isBool()) { \
|
||||
qCCritical(animation) << "AnimNodeLoader, error reading bool" \
|
||||
<< #NAME << ", id =" << ID \
|
||||
<< ", url =" << URL.toDisplayString(); \
|
||||
return nullptr; \
|
||||
return ERROR_RETURN; \
|
||||
} \
|
||||
bool NAME = NAME##_VAL.toBool()
|
||||
|
||||
#define READ_FLOAT(NAME, JSON_OBJ, ID, URL) \
|
||||
#define READ_FLOAT(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||
if (!NAME##_VAL.isDouble()) { \
|
||||
qCCritical(animation) << "AnimNodeLoader, error reading double" \
|
||||
<< #NAME << "id =" << ID \
|
||||
<< ", url =" << URL.toDisplayString(); \
|
||||
return nullptr; \
|
||||
return ERROR_RETURN; \
|
||||
} \
|
||||
float NAME = (float)NAME##_VAL.toDouble()
|
||||
|
||||
|
@ -171,11 +171,11 @@ static AnimNode::Pointer loadNode(const QJsonObject& jsonObj, const QUrl& jsonUr
|
|||
|
||||
static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||
|
||||
READ_STRING(url, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(startFrame, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(endFrame, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(timeScale, jsonObj, id, jsonUrl);
|
||||
READ_BOOL(loopFlag, jsonObj, id, jsonUrl);
|
||||
READ_STRING(url, jsonObj, id, jsonUrl, nullptr);
|
||||
READ_FLOAT(startFrame, jsonObj, id, jsonUrl, nullptr);
|
||||
READ_FLOAT(endFrame, jsonObj, id, jsonUrl, nullptr);
|
||||
READ_FLOAT(timeScale, jsonObj, id, jsonUrl, nullptr);
|
||||
READ_BOOL(loopFlag, jsonObj, id, jsonUrl, nullptr);
|
||||
|
||||
READ_OPTIONAL_STRING(startFrameVar, jsonObj);
|
||||
READ_OPTIONAL_STRING(endFrameVar, jsonObj);
|
||||
|
@ -202,7 +202,7 @@ static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString&
|
|||
|
||||
static AnimNode::Pointer loadBlendLinearNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl, nullptr);
|
||||
|
||||
READ_OPTIONAL_STRING(alphaVar, jsonObj);
|
||||
|
||||
|
@ -239,8 +239,8 @@ static AnimOverlay::BoneSet stringToBoneSetEnum(const QString& str) {
|
|||
|
||||
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||
|
||||
READ_STRING(boneSet, jsonObj, id, jsonUrl);
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
||||
READ_STRING(boneSet, jsonObj, id, jsonUrl, nullptr);
|
||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl, nullptr);
|
||||
|
||||
auto boneSetEnum = stringToBoneSetEnum(boneSet);
|
||||
if (boneSetEnum == AnimOverlay::NumBoneSets) {
|
||||
|
@ -278,12 +278,12 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
|||
auto smNode = std::static_pointer_cast<AnimStateMachine>(node);
|
||||
assert(smNode);
|
||||
|
||||
READ_STRING(currentState, jsonObj, nodeId, jsonUrl);
|
||||
READ_STRING(currentState, jsonObj, nodeId, jsonUrl, false);
|
||||
|
||||
auto statesValue = jsonObj.value("states");
|
||||
if (!statesValue.isArray()) {
|
||||
qCCritical(animation) << "AnimNodeLoader, bad array \"states\" in stateMachine node, id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// build a map for all children by name.
|
||||
|
@ -302,13 +302,13 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
|||
for (const auto& stateValue : statesArray) {
|
||||
if (!stateValue.isObject()) {
|
||||
qCCritical(animation) << "AnimNodeLoader, bad state object in \"states\", id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
auto stateObj = stateValue.toObject();
|
||||
|
||||
READ_STRING(id, stateObj, nodeId, jsonUrl);
|
||||
READ_FLOAT(interpTarget, stateObj, nodeId, jsonUrl);
|
||||
READ_FLOAT(interpDuration, stateObj, nodeId, jsonUrl);
|
||||
READ_STRING(id, stateObj, nodeId, jsonUrl, false);
|
||||
READ_FLOAT(interpTarget, stateObj, nodeId, jsonUrl, false);
|
||||
READ_FLOAT(interpDuration, stateObj, nodeId, jsonUrl, false);
|
||||
|
||||
READ_OPTIONAL_STRING(interpTargetVar, stateObj);
|
||||
READ_OPTIONAL_STRING(interpDurationVar, stateObj);
|
||||
|
@ -318,7 +318,7 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
|||
auto iter = childMap.find(stdId);
|
||||
if (iter == childMap.end()) {
|
||||
qCCritical(animation) << "AnimNodeLoader, could not find stateMachine child (state) with nodeId =" << nodeId << "stateId =" << id << "url =" << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto statePtr = std::make_shared<AnimStateMachine::State>(stdId, iter->second, interpTarget, interpDuration);
|
||||
|
@ -337,19 +337,19 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
|||
auto transitionsValue = stateObj.value("transitions");
|
||||
if (!transitionsValue.isArray()) {
|
||||
qCritical(animation) << "AnimNodeLoader, bad array \"transitions\" in stateMachine node, stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto transitionsArray = transitionsValue.toArray();
|
||||
for (const auto& transitionValue : transitionsArray) {
|
||||
if (!transitionValue.isObject()) {
|
||||
qCritical(animation) << "AnimNodeLoader, bad transition object in \"transtions\", stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
auto transitionObj = transitionValue.toObject();
|
||||
|
||||
READ_STRING(var, transitionObj, nodeId, jsonUrl);
|
||||
READ_STRING(state, transitionObj, nodeId, jsonUrl);
|
||||
READ_STRING(var, transitionObj, nodeId, jsonUrl, false);
|
||||
READ_STRING(state, transitionObj, nodeId, jsonUrl, false);
|
||||
|
||||
transitionMap.insert(TransitionMap::value_type(statePtr, StringPair(var.toStdString(), state.toStdString())));
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
|||
srcState->addTransition(AnimStateMachine::State::Transition(transition.second.first, iter->second));
|
||||
} else {
|
||||
qCCritical(animation) << "AnimNodeLoader, bad state machine transtion from srcState =" << srcState->_id.c_str() << "dstState =" << transition.second.second.c_str() << "nodeId =" << nodeId << "url = " << jsonUrl.toDisplayString();
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,53 @@ void AvatarData::setOrientation(const glm::quat& orientation, bool overideRefere
|
|||
}
|
||||
}
|
||||
|
||||
// There are a number of possible strategies for this set of tools through endRender, below.
|
||||
void AvatarData::nextAttitude(glm::vec3 position, glm::quat orientation) {
|
||||
avatarLock.lock();
|
||||
setPosition(position, true);
|
||||
setOrientation(orientation, true);
|
||||
avatarLock.unlock();
|
||||
}
|
||||
void AvatarData::startCapture() {
|
||||
avatarLock.lock();
|
||||
assert(_nextAllowed);
|
||||
_nextAllowed = false;
|
||||
_nextPosition = getPosition();
|
||||
_nextOrientation = getOrientation();
|
||||
}
|
||||
void AvatarData::endCapture() {
|
||||
avatarLock.unlock();
|
||||
}
|
||||
void AvatarData::startUpdate() {
|
||||
avatarLock.lock();
|
||||
}
|
||||
void AvatarData::endUpdate() {
|
||||
avatarLock.unlock();
|
||||
}
|
||||
void AvatarData::startRenderRun() {
|
||||
// I'd like to get rid of this and just (un)lock at (end-)startRender.
|
||||
// But somehow that causes judder in rotations.
|
||||
avatarLock.lock();
|
||||
}
|
||||
void AvatarData::endRenderRun() {
|
||||
avatarLock.unlock();
|
||||
}
|
||||
void AvatarData::startRender() {
|
||||
glm::vec3 pos = getPosition();
|
||||
glm::quat rot = getOrientation();
|
||||
setPosition(_nextPosition, true);
|
||||
setOrientation(_nextOrientation, true);
|
||||
updateAttitude();
|
||||
_nextPosition = pos;
|
||||
_nextOrientation = rot;
|
||||
}
|
||||
void AvatarData::endRender() {
|
||||
setPosition(_nextPosition, true);
|
||||
setOrientation(_nextOrientation, true);
|
||||
updateAttitude();
|
||||
_nextAllowed = true;
|
||||
}
|
||||
|
||||
float AvatarData::getTargetScale() const {
|
||||
if (_referential) {
|
||||
_referential->update();
|
||||
|
|
|
@ -200,6 +200,17 @@ public:
|
|||
glm::quat getOrientation() const;
|
||||
virtual void setOrientation(const glm::quat& orientation, bool overideReferential = false);
|
||||
|
||||
void nextAttitude(glm::vec3 position, glm::quat orientation); // Can be safely called at any time.
|
||||
void startCapture(); // start/end of the period in which the latest values are about to be captured for camera, etc.
|
||||
void endCapture();
|
||||
void startUpdate(); // start/end of update iteration
|
||||
void endUpdate();
|
||||
void startRender(); // start/end of rendering of this object
|
||||
void startRenderRun(); // start/end of entire scene.
|
||||
void endRenderRun();
|
||||
void endRender();
|
||||
virtual void updateAttitude() {} // Tell skeleton mesh about changes
|
||||
|
||||
glm::quat getHeadOrientation() const { return _headData->getOrientation(); }
|
||||
void setHeadOrientation(const glm::quat& orientation) { _headData->setOrientation(orientation); }
|
||||
|
||||
|
@ -358,6 +369,10 @@ protected:
|
|||
float _bodyPitch; // degrees
|
||||
float _bodyRoll; // degrees
|
||||
|
||||
glm::vec3 _nextPosition {};
|
||||
glm::quat _nextOrientation {};
|
||||
bool _nextAllowed {true};
|
||||
|
||||
// Body scale
|
||||
float _targetScale;
|
||||
|
||||
|
@ -407,6 +422,8 @@ protected:
|
|||
|
||||
SimpleMovingAverage _averageBytesReceived;
|
||||
|
||||
QMutex avatarLock; // Name is redundant, but it aids searches.
|
||||
|
||||
private:
|
||||
static QUrl _defaultFullAvatarModelUrl;
|
||||
// privatize the copy constructor and assignment operator so they cannot be called
|
||||
|
|
|
@ -25,6 +25,13 @@ ResourceRequest* ResourceManager::createResourceRequest(QObject* parent, const Q
|
|||
return new HTTPResourceRequest(parent, url);
|
||||
} else if (scheme == URL_SCHEME_ATP) {
|
||||
return new AssetResourceRequest(parent, url);
|
||||
} else {
|
||||
// check the degenerative file case: on windows we can often have urls of the form c:/filename
|
||||
// this checks for and works around that case.
|
||||
QUrl urlWithFileScheme { URL_SCHEME_FILE + ":///" + url.toString() };
|
||||
if (!urlWithFileScheme.toLocalFile().isEmpty()) {
|
||||
return new FileResourceRequest(parent, urlWithFileScheme);
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Unknown scheme (" << scheme << ") for URL: " << url.url();
|
||||
|
|
|
@ -409,8 +409,7 @@ void DynamicCharacterController::postSimulation() {
|
|||
glm::quat rotation = bulletToGLM(avatarTransform.getRotation());
|
||||
glm::vec3 position = bulletToGLM(avatarTransform.getOrigin());
|
||||
|
||||
_avatarData->setOrientation(rotation);
|
||||
_avatarData->setPosition(position - rotation * _shapeLocalOffset);
|
||||
_avatarData->nextAttitude(position - rotation * _shapeLocalOffset, rotation);
|
||||
_avatarData->setVelocity(bulletToGLM(_rigidBody->getLinearVelocity()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& size) {
|
|||
if (replaceIndex != std::string::npos) {
|
||||
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_BLOCK.size(), _shaderSource.toLocal8Bit().data());
|
||||
}
|
||||
qDebug() << "FragmentShader:\n" << fragmentShaderSource.c_str();
|
||||
//qDebug() << "FragmentShader:\n" << fragmentShaderSource.c_str();
|
||||
_fragmentShader = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShaderSource));
|
||||
_shader = gpu::ShaderPointer(gpu::Shader::createProgram(_vertexShader, _fragmentShader));
|
||||
gpu::Shader::makeProgram(*_shader);
|
||||
|
|
|
@ -1291,7 +1291,9 @@ void Model::simulateInternal(float deltaTime) {
|
|||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
|
||||
updateRig(deltaTime, parentTransform);
|
||||
|
||||
}
|
||||
void Model::updateClusterMatrices() {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
glm::mat4 zeroScale(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
glm::vec4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
glm::vec4(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
|
@ -1305,7 +1307,7 @@ void Model::simulateInternal(float deltaTime) {
|
|||
if (_showTrueJointTransforms) {
|
||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||
const FBXCluster& cluster = mesh.clusters.at(j);
|
||||
auto jointMatrix =_rig->getJointTransform(cluster.jointIndex);
|
||||
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
|
||||
state.clusterMatrices[j] = modelToWorld * jointMatrix * cluster.inverseBindMatrix;
|
||||
|
||||
// as an optimization, don't build cautrizedClusterMatrices if the boneSet is empty.
|
||||
|
@ -1319,7 +1321,7 @@ void Model::simulateInternal(float deltaTime) {
|
|||
} else {
|
||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||
const FBXCluster& cluster = mesh.clusters.at(j);
|
||||
auto jointMatrix = _rig->getJointVisibleTransform(cluster.jointIndex);
|
||||
auto jointMatrix = _rig->getJointVisibleTransform(cluster.jointIndex); // differs from above only in using get...VisibleTransform
|
||||
state.clusterMatrices[j] = modelToWorld * jointMatrix * cluster.inverseBindMatrix;
|
||||
|
||||
// as an optimization, don't build cautrizedClusterMatrices if the boneSet is empty.
|
||||
|
@ -1434,7 +1436,6 @@ AABox Model::getPartBounds(int meshIndex, int partIndex) {
|
|||
return calculateScaledOffsetAABox(_geometry->getFBXGeometry().meshExtents);
|
||||
}
|
||||
}
|
||||
|
||||
if (_geometry->getFBXGeometry().meshes.size() > meshIndex) {
|
||||
|
||||
// FIX ME! - This is currently a hack because for some mesh parts our efforts to calculate the bounding
|
||||
|
@ -1489,6 +1490,8 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran
|
|||
return;
|
||||
}
|
||||
|
||||
updateClusterMatrices();
|
||||
|
||||
const NetworkMesh& networkMesh = *(networkMeshes.at(meshIndex).get());
|
||||
const FBXMesh& mesh = geometry.meshes.at(meshIndex);
|
||||
const MeshState& state = _meshStates.at(meshIndex);
|
||||
|
|
|
@ -111,6 +111,7 @@ public:
|
|||
bool getSnapModelToRegistrationPoint() { return _snapModelToRegistrationPoint; }
|
||||
|
||||
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
||||
void updateClusterMatrices();
|
||||
|
||||
/// Returns a reference to the shared geometry.
|
||||
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
||||
|
|
|
@ -860,7 +860,14 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
|||
}
|
||||
QList<QUrl> urls;
|
||||
for (QString file : includeFiles) {
|
||||
urls.append(resolvePath(file));
|
||||
QUrl thisURL { resolvePath(file) };
|
||||
if (!_includedURLs.contains(thisURL)) {
|
||||
urls.append(thisURL);
|
||||
_includedURLs << thisURL;
|
||||
}
|
||||
else {
|
||||
qCDebug(scriptengine) << "Script.include() ignoring previously included url:" << thisURL;
|
||||
}
|
||||
}
|
||||
|
||||
BatchLoader* loader = new BatchLoader(urls);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QWaitCondition>
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
|
@ -152,6 +153,7 @@ protected:
|
|||
Sound* _avatarSound;
|
||||
int _numAvatarSoundSentBytes;
|
||||
bool _isAgent = false;
|
||||
QSet<QUrl> _includedURLs;
|
||||
|
||||
private:
|
||||
void stopAllTimers();
|
||||
|
|
|
@ -24,7 +24,7 @@ class GenericQueueThread : public GenericThread {
|
|||
public:
|
||||
using Queue = QQueue<T>;
|
||||
GenericQueueThread(QObject* parent = nullptr)
|
||||
: GenericThread(parent) {}
|
||||
: GenericThread() {}
|
||||
|
||||
virtual ~GenericQueueThread() {}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#include "GenericThread.h"
|
||||
|
||||
|
||||
GenericThread::GenericThread(QObject* parent) :
|
||||
QObject(parent),
|
||||
GenericThread::GenericThread() :
|
||||
QObject(),
|
||||
_stopThread(false),
|
||||
_isThreaded(false) // assume non-threaded, must call initialize()
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
class GenericThread : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GenericThread(QObject* parent = nullptr);
|
||||
GenericThread();
|
||||
virtual ~GenericThread();
|
||||
|
||||
/// Call to start the thread.
|
||||
|
|
|
@ -127,21 +127,20 @@ void AnimTests::testClipEvaulateWithVars() {
|
|||
|
||||
void AnimTests::testLoader() {
|
||||
auto url = QUrl("https://gist.githubusercontent.com/hyperlogic/857129fe04567cbe670f/raw/8ba57a8f0a76f88b39a11f77f8d9df04af9cec95/test.json");
|
||||
// NOTE: This will warn about missing "test01.fbx", "test02.fbx", etc. if the resource loading code doesn't handle relative pathnames!
|
||||
// However, the test will proceed.
|
||||
AnimNodeLoader loader(url);
|
||||
|
||||
const int timeout = 1000;
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(timeout);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
AnimNode::Pointer node = nullptr;
|
||||
connect(&loader, &AnimNodeLoader::success, [&](AnimNode::Pointer nodeIn) { node = nodeIn; });
|
||||
|
||||
loop.connect(&loader, SIGNAL(success(AnimNode::Pointer)), SLOT(quit()));
|
||||
loop.connect(&loader, SIGNAL(error(int, QString)), SLOT(quit()));
|
||||
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
|
||||
timer.start();
|
||||
QTimer::singleShot(timeout, &loop, SLOT(quit()));
|
||||
|
||||
loop.exec();
|
||||
|
||||
QVERIFY((bool)node);
|
||||
|
@ -184,42 +183,58 @@ void AnimTests::testLoader() {
|
|||
|
||||
void AnimTests::testVariant() {
|
||||
auto defaultVar = AnimVariant();
|
||||
auto boolVar = AnimVariant(true);
|
||||
auto intVar = AnimVariant(1);
|
||||
auto floatVar = AnimVariant(1.0f);
|
||||
auto vec3Var = AnimVariant(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
auto quatVar = AnimVariant(glm::quat(1.0f, 2.0f, 3.0f, 4.0f));
|
||||
auto boolVarTrue = AnimVariant(true);
|
||||
auto boolVarFalse = AnimVariant(false);
|
||||
auto intVarZero = AnimVariant(0);
|
||||
auto intVarOne = AnimVariant(1);
|
||||
auto intVarNegative = AnimVariant(-1);
|
||||
auto floatVarZero = AnimVariant(0.0f);
|
||||
auto floatVarOne = AnimVariant(1.0f);
|
||||
auto floatVarNegative = AnimVariant(-1.0f);
|
||||
auto vec3Var = AnimVariant(glm::vec3(1.0f, -2.0f, 3.0f));
|
||||
auto quatVar = AnimVariant(glm::quat(1.0f, 2.0f, -3.0f, 4.0f));
|
||||
auto mat4Var = AnimVariant(glm::mat4(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f),
|
||||
glm::vec4(5.0f, 6.0f, 7.0f, 8.0f),
|
||||
glm::vec4(5.0f, 6.0f, -7.0f, 8.0f),
|
||||
glm::vec4(9.0f, 10.0f, 11.0f, 12.0f),
|
||||
glm::vec4(13.0f, 14.0f, 15.0f, 16.0f)));
|
||||
QVERIFY(defaultVar.isBool());
|
||||
QVERIFY(defaultVar.getBool() == false);
|
||||
|
||||
QVERIFY(boolVar.isBool());
|
||||
QVERIFY(boolVar.getBool() == true);
|
||||
QVERIFY(boolVarTrue.isBool());
|
||||
QVERIFY(boolVarTrue.getBool() == true);
|
||||
QVERIFY(boolVarFalse.isBool());
|
||||
QVERIFY(boolVarFalse.getBool() == false);
|
||||
|
||||
QVERIFY(intVar.isInt());
|
||||
QVERIFY(intVar.getInt() == 1);
|
||||
QVERIFY(intVarZero.isInt());
|
||||
QVERIFY(intVarZero.getInt() == 0);
|
||||
QVERIFY(intVarOne.isInt());
|
||||
QVERIFY(intVarOne.getInt() == 1);
|
||||
QVERIFY(intVarNegative.isInt());
|
||||
QVERIFY(intVarNegative.getInt() == -1);
|
||||
|
||||
QVERIFY(floatVar.isFloat());
|
||||
QVERIFY(floatVar.getFloat() == 1.0f);
|
||||
QVERIFY(floatVarZero.isFloat());
|
||||
QVERIFY(floatVarZero.getFloat() == 0.0f);
|
||||
QVERIFY(floatVarOne.isFloat());
|
||||
QVERIFY(floatVarOne.getFloat() == 1.0f);
|
||||
QVERIFY(floatVarNegative.isFloat());
|
||||
QVERIFY(floatVarNegative.getFloat() == -1.0f);
|
||||
|
||||
QVERIFY(vec3Var.isVec3());
|
||||
auto v = vec3Var.getVec3();
|
||||
QVERIFY(v.x == 1.0f);
|
||||
QVERIFY(v.y == 2.0f);
|
||||
QVERIFY(v.y == -2.0f);
|
||||
QVERIFY(v.z == 3.0f);
|
||||
|
||||
QVERIFY(quatVar.isQuat());
|
||||
auto q = quatVar.getQuat();
|
||||
QVERIFY(q.w == 1.0f);
|
||||
QVERIFY(q.x == 2.0f);
|
||||
QVERIFY(q.y == 3.0f);
|
||||
QVERIFY(q.y == -3.0f);
|
||||
QVERIFY(q.z == 4.0f);
|
||||
|
||||
QVERIFY(mat4Var.isMat4());
|
||||
auto m = mat4Var.getMat4();
|
||||
QVERIFY(m[0].x == 1.0f);
|
||||
QVERIFY(m[1].z == -7.0f);
|
||||
QVERIFY(m[3].w == 16.0f);
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ void testByteCountCodedStable(const T& value) {
|
|||
Q_ASSERT(decoder.data == coder.data);
|
||||
#ifndef QT_NO_DEBUG
|
||||
auto consumed = decoder.decode(encoded.data(), encoded.size());
|
||||
#endif
|
||||
Q_ASSERT(consumed == (unsigned int)originalEncodedSize);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
@ -124,9 +124,9 @@ void testPropertyFlags(uint32_t value) {
|
|||
{
|
||||
#ifndef QT_NO_DEBUG
|
||||
int decodeSize = decodeNew.decode((const uint8_t*)encoded.data(), encoded.size());
|
||||
#endif
|
||||
Q_ASSERT(originalSize == decodeSize);
|
||||
Q_ASSERT(decodeNew == original);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue