fix softEntity edge cases

This commit is contained in:
Dante Ruiz 2018-01-12 15:31:54 -08:00
parent 5b82c7bc41
commit 283b9a8003
7 changed files with 27 additions and 15 deletions

View file

@ -352,10 +352,10 @@ void Avatar::updateAvatarEntities() {
void Avatar::relayJointDataToChildren() {
forEachChild([&](SpatiallyNestablePointer child) {
if (child->getNestableType() == NestableType::Entity) {
auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
if (modelEntity) {
if (modelEntity->getRelayParentJoints()) {
if (!(modelEntity->getJointMapCompleted())) {
if (!modelEntity->getJointMapCompleted() || _reconstructSoftEntitiesJointMap) {
QStringList modelJointNames = modelEntity->getJointNames();
int numJoints = modelJointNames.count();
std::vector<int> map;
@ -365,7 +365,6 @@ void Avatar::relayJointDataToChildren() {
int avatarJointIndex = getJointIndex(jointName);
glm::quat jointRotation;
glm::vec3 jointTranslation;
qDebug() << avatarJointIndex;
if (avatarJointIndex < 0) {
jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex);
jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex);
@ -385,7 +384,6 @@ void Avatar::relayJointDataToChildren() {
int numJoints = modelJointNames.count();
for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) {
int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex);
int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex));
glm::quat jointRotation;
glm::vec3 jointTranslation;
if (avatarJointIndex >=0) {
@ -406,6 +404,7 @@ void Avatar::relayJointDataToChildren() {
}
}
});
_reconstructSoftEntitiesJointMap = false;
}
void Avatar::simulate(float deltaTime, bool inView) {
@ -1259,6 +1258,7 @@ void Avatar::setModelURLFinished(bool success) {
invalidateJointIndicesCache();
_isAnimatingScale = true;
_reconstructSoftEntitiesJointMap = true;
if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) {
const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts

View file

@ -383,6 +383,7 @@ protected:
bool _isAnimatingScale { false };
bool _mustFadeIn { false };
bool _isFading { false };
bool _reconstructSoftEntitiesJointMap { false };
float _modelScale { 1.0f };
static int _jointConesID;

View file

@ -209,12 +209,6 @@ void RenderableModelEntityItem::updateModelBounds() {
updateRenderItems = true;
}
if (getRelayParentJoints()) {
model->setOverrideTransform(true);
} else {
model->setOverrideTransform(false);
}
if (model->getScaleToFitDimensions() != getScaledDimensions() ||
model->getRegistrationPoint() != getRegistrationPoint()) {
// The machinery for updateModelBounds will give existing models the opportunity to fix their
@ -718,7 +712,10 @@ void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) {
if (jointMap.size() > 0) {
_jointMap = jointMap;
_jointMapCompleted = true;
return;
}
_jointMapCompleted = false;
};
int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) {
@ -865,7 +862,7 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const {
void RenderableModelEntityItem::setOverrideTransform(const Transform& transform, const glm::vec3& offset) {
auto model = getModel();
if (model) {
model->overrideModelTransform(transform, offset);
model->overrideModelTransformAndOffset(transform, offset);
}
}
@ -972,6 +969,17 @@ void RenderableModelEntityItem::simulateRelayedJoints() {
}
}
void RenderableModelEntityItem::stopModelOverrideIfNoParent() {
auto model = getModel();
if (model) {
bool overriding = model->isOverridingModelTransformAndOffset();
QUuid parentID = getParentID();
if (overriding && (!_relayParentJoints || parentID.isNull())) {
model->stopTransformAndOffsetOverride();
}
}
}
void RenderableModelEntityItem::copyAnimationJointDataToModel() {
auto model = getModel();
if (!model || !model->isLoaded()) {
@ -1323,6 +1331,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
}
entity->updateModelBounds();
entity->stopModelOverrideIfNoParent();
if (model->isVisible() != _visible) {
// FIXME: this seems like it could be optimized if we tracked our last known visible state in

View file

@ -81,6 +81,7 @@ public:
void setCollisionShape(const btCollisionShape* shape) override;
virtual bool contains(const glm::vec3& point) const override;
void stopModelOverrideIfNoParent();
virtual bool shouldBePhysical() const override;
void simulateRelayedJoints();

View file

@ -1369,7 +1369,7 @@ void Model::deleteGeometry() {
_collisionGeometry.reset();
}
void Model::overrideModelTransform(const Transform& transform, const glm::vec3& offset) {
void Model::overrideModelTransformAndOffset(const Transform& transform, const glm::vec3& offset) {
_overrideTranslation = transform.getTranslation();
_overrideRotation = transform.getRotation();
_overrideModelTransform = true;

View file

@ -208,8 +208,9 @@ public:
void setTranslation(const glm::vec3& translation);
void setRotation(const glm::quat& rotation);
void overrideModelTransform(const Transform& transform, const glm::vec3& offset);
void setOverrideTransform(bool override) { _overrideModelTransform = override; };
void overrideModelTransformAndOffset(const Transform& transform, const glm::vec3& offset);
bool isOverridingModelTransformAndOffset() { return _overrideModelTransform; };
void stopTransformAndOffsetOverride() { _overrideModelTransform = false; };
void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK
const glm::vec3& getTranslation() const { return _translation; }

View file

@ -165,7 +165,7 @@ function wearAttachment(attachment) {
position: attachment.position,
rotation: attachment.rotation,
parentJointIndex: -1
});
}, true);
}
}