Merge pull request #13969 from SamGondelman/modelBugs

Fixing Model animation bugs
This commit is contained in:
Sam Gateau 2018-09-18 11:28:37 -07:00 committed by GitHub
commit d768809fbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 66 deletions

View file

@ -1322,6 +1322,8 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
emit DependencyManager::get<scriptable::ModelProviderFactory>()->
modelRemovedFromScene(entity->getEntityItemID(), NestableType::Entity, _model);
}
setKey(false);
_didLastVisualGeometryRequestSucceed = false;
return;
}
@ -1347,6 +1349,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
if (_parsedModelURL != model->getURL()) {
withWriteLock([&] {
_texturesLoaded = false;
_jointMappingCompleted = false;
model->setURL(_parsedModelURL);
});
}
@ -1457,7 +1460,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
mapJoints(entity, model->getJointNames());
//else the joint have been mapped before but we have a new animation to load
} else if (_animation && (_animation->getURL().toString() != entity->getAnimationURL())) {
_animation = DependencyManager::get<AnimationCache>()->getAnimation(entity->getAnimationURL());
_jointMappingCompleted = false;
mapJoints(entity, model->getJointNames());
}

View file

@ -187,7 +187,7 @@ private:
const void* _collisionMeshKey { nullptr };
// used on client side
bool _jointMappingCompleted{ false };
bool _jointMappingCompleted { false };
QVector<int> _jointMapping; // domain is index into model-joints, range is index into animation-joints
AnimationPointer _animation;
QUrl _parsedModelURL;

View file

@ -66,7 +66,9 @@ EntityItemProperties ModelEntityItem::getProperties(EntityPropertyFlags desiredP
COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslationsSet, getJointTranslationsSet);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(jointTranslations, getJointTranslations);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(relayParentJoints, getRelayParentJoints);
_animationProperties.getProperties(properties);
withReadLock([&] {
_animationProperties.getProperties(properties);
});
return properties;
}
@ -123,15 +125,18 @@ int ModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
// grab a local copy of _animationProperties to avoid multiple locks
int bytesFromAnimation;
AnimationPropertyGroup animationProperties;
withReadLock([&] {
AnimationPropertyGroup animationProperties = _animationProperties;
animationProperties = _animationProperties;
bytesFromAnimation = animationProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
propertyFlags, overwriteLocalData, animationPropertiesChanged);
if (animationPropertiesChanged) {
applyNewAnimationProperties(animationProperties);
somethingChanged = true;
}
});
if (animationPropertiesChanged) {
withWriteLock([&] {
applyNewAnimationProperties(animationProperties);
});
somethingChanged = true;
}
bytesRead += bytesFromAnimation;
dataAt += bytesFromAnimation;
@ -305,69 +310,77 @@ void ModelEntityItem::setAnimationURL(const QString& url) {
void ModelEntityItem::setAnimationSettings(const QString& value) {
// NOTE: this method only called for old bitstream format
AnimationPropertyGroup animationProperties;
withReadLock([&] {
animationProperties = _animationProperties;
});
// the animations setting is a JSON string that may contain various animation settings.
// if it includes fps, currentFrame, or running, those values will be parsed out and
// will over ride the regular animation settings
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
QJsonObject settingsAsJsonObject = settingsAsJson.object();
QVariantMap settingsMap = settingsAsJsonObject.toVariantMap();
if (settingsMap.contains("fps")) {
float fps = settingsMap["fps"].toFloat();
animationProperties.setFPS(fps);
}
// old settings used frameIndex
if (settingsMap.contains("frameIndex")) {
float currentFrame = settingsMap["frameIndex"].toFloat();
animationProperties.setCurrentFrame(currentFrame);
}
if (settingsMap.contains("running")) {
bool running = settingsMap["running"].toBool();
if (running != animationProperties.getRunning()) {
animationProperties.setRunning(running);
}
}
if (settingsMap.contains("firstFrame")) {
float firstFrame = settingsMap["firstFrame"].toFloat();
animationProperties.setFirstFrame(firstFrame);
}
if (settingsMap.contains("lastFrame")) {
float lastFrame = settingsMap["lastFrame"].toFloat();
animationProperties.setLastFrame(lastFrame);
}
if (settingsMap.contains("loop")) {
bool loop = settingsMap["loop"].toBool();
animationProperties.setLoop(loop);
}
if (settingsMap.contains("hold")) {
bool hold = settingsMap["hold"].toBool();
animationProperties.setHold(hold);
}
if (settingsMap.contains("allowTranslation")) {
bool allowTranslation = settingsMap["allowTranslation"].toBool();
animationProperties.setAllowTranslation(allowTranslation);
}
withWriteLock([&] {
auto animationProperties = _animationProperties;
// the animations setting is a JSON string that may contain various animation settings.
// if it includes fps, currentFrame, or running, those values will be parsed out and
// will over ride the regular animation settings
QJsonDocument settingsAsJson = QJsonDocument::fromJson(value.toUtf8());
QJsonObject settingsAsJsonObject = settingsAsJson.object();
QVariantMap settingsMap = settingsAsJsonObject.toVariantMap();
if (settingsMap.contains("fps")) {
float fps = settingsMap["fps"].toFloat();
animationProperties.setFPS(fps);
}
// old settings used frameIndex
if (settingsMap.contains("frameIndex")) {
float currentFrame = settingsMap["frameIndex"].toFloat();
animationProperties.setCurrentFrame(currentFrame);
}
if (settingsMap.contains("running")) {
bool running = settingsMap["running"].toBool();
if (running != animationProperties.getRunning()) {
animationProperties.setRunning(running);
}
}
if (settingsMap.contains("firstFrame")) {
float firstFrame = settingsMap["firstFrame"].toFloat();
animationProperties.setFirstFrame(firstFrame);
}
if (settingsMap.contains("lastFrame")) {
float lastFrame = settingsMap["lastFrame"].toFloat();
animationProperties.setLastFrame(lastFrame);
}
if (settingsMap.contains("loop")) {
bool loop = settingsMap["loop"].toBool();
animationProperties.setLoop(loop);
}
if (settingsMap.contains("hold")) {
bool hold = settingsMap["hold"].toBool();
animationProperties.setHold(hold);
}
if (settingsMap.contains("allowTranslation")) {
bool allowTranslation = settingsMap["allowTranslation"].toBool();
animationProperties.setAllowTranslation(allowTranslation);
}
applyNewAnimationProperties(animationProperties);
});
}
void ModelEntityItem::setAnimationIsPlaying(bool value) {
_flags |= Simulation::DIRTY_UPDATEABLE;
_animationProperties.setRunning(value);
withWriteLock([&] {
_animationProperties.setRunning(value);
});
}
void ModelEntityItem::setAnimationFPS(float value) {
_flags |= Simulation::DIRTY_UPDATEABLE;
_animationProperties.setFPS(value);
withWriteLock([&] {
_animationProperties.setFPS(value);
});
}
// virtual
@ -557,11 +570,9 @@ void ModelEntityItem::setColor(const xColor& value) {
// Animation related items...
AnimationPropertyGroup ModelEntityItem::getAnimationProperties() const {
AnimationPropertyGroup result;
withReadLock([&] {
result = _animationProperties;
return resultWithReadLock<AnimationPropertyGroup>([&] {
return _animationProperties;
});
return result;
}
bool ModelEntityItem::hasAnimation() const {
@ -582,6 +593,18 @@ void ModelEntityItem::setAnimationCurrentFrame(float value) {
});
}
void ModelEntityItem::setAnimationAllowTranslation(bool value) {
withWriteLock([&] {
_animationProperties.setAllowTranslation(value);
});
}
bool ModelEntityItem::getAnimationAllowTranslation() const {
return resultWithReadLock<bool>([&] {
return _animationProperties.getAllowTranslation();
});
}
void ModelEntityItem::setAnimationLoop(bool loop) {
withWriteLock([&] {
_animationProperties.setLoop(loop);

View file

@ -88,8 +88,8 @@ public:
void setAnimationIsPlaying(bool value);
void setAnimationFPS(float value);
void setAnimationAllowTranslation(bool value) { _animationProperties.setAllowTranslation(value); };
bool getAnimationAllowTranslation() const { return _animationProperties.getAllowTranslation(); };
void setAnimationAllowTranslation(bool value);
bool getAnimationAllowTranslation() const;
void setAnimationLoop(bool loop);
bool getAnimationLoop() const;