added model transform override

This commit is contained in:
Dante Ruiz 2018-01-11 16:41:45 -08:00
parent 980807c657
commit 96a97b5938
6 changed files with 43 additions and 8 deletions

View file

@ -537,7 +537,7 @@ void MyAvatar::simulate(float deltaTime) {
// we've achived our final adjusted position and rotation for the avatar // we've achived our final adjusted position and rotation for the avatar
// and all of its joints, now update our attachements. // and all of its joints, now update our attachements.
Avatar::simulateAttachments(deltaTime); Avatar::simulateAttachments(deltaTime);
Avatar::relayJointDataToChildren(); relayJointDataToChildren();
if (!_skeletonModel->hasSkeleton()) { if (!_skeletonModel->hasSkeleton()) {
// All the simulation that can be done has been done // All the simulation that can be done has been done

View file

@ -355,9 +355,7 @@ void Avatar::relayJointDataToChildren() {
auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child); auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
if (modelEntity) { if (modelEntity) {
if (modelEntity->getRelayParentJoints()) { if (modelEntity->getRelayParentJoints()) {
qDebug() << modelEntity->getJointMapCompleted();
if (!(modelEntity->getJointMapCompleted())) { if (!(modelEntity->getJointMapCompleted())) {
qDebug() << "constructing map";
QStringList modelJointNames = modelEntity->getJointNames(); QStringList modelJointNames = modelEntity->getJointNames();
int numJoints = modelJointNames.count(); int numJoints = modelJointNames.count();
std::vector<int> map; std::vector<int> map;
@ -388,7 +386,6 @@ void Avatar::relayJointDataToChildren() {
for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) { for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) {
int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex); int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex);
int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex)); int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex));
//qDebug() << jointIndex << "------" << index;
glm::quat jointRotation; glm::quat jointRotation;
glm::vec3 jointTranslation; glm::vec3 jointTranslation;
if (avatarJointIndex >=0) { if (avatarJointIndex >=0) {
@ -402,6 +399,8 @@ void Avatar::relayJointDataToChildren() {
modelEntity->setLocalJointTranslation(jointIndex, jointTranslation); modelEntity->setLocalJointTranslation(jointIndex, jointTranslation);
} }
} }
modelEntity->setOverrideTransform(_skeletonModel->getTransform());
modelEntity->simulateRelayedJoints(); modelEntity->simulateRelayedJoints();
} }
} }

View file

@ -209,6 +209,12 @@ void RenderableModelEntityItem::updateModelBounds() {
updateRenderItems = true; updateRenderItems = true;
} }
if (getRelayParentJoints()) {
model->setOverrideTransform(true);
} else {
model->setOverrideTransform(false);
}
if (model->getScaleToFitDimensions() != getScaledDimensions() || if (model->getScaleToFitDimensions() != getScaledDimensions() ||
model->getRegistrationPoint() != getRegistrationPoint()) { model->getRegistrationPoint() != getRegistrationPoint()) {
// The machinery for updateModelBounds will give existing models the opportunity to fix their // The machinery for updateModelBounds will give existing models the opportunity to fix their
@ -709,13 +715,15 @@ void RenderableModelEntityItem::setCollisionShape(const btCollisionShape* shape)
} }
void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) { void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) {
if (jointMap.size() > 0) {
_jointMap = jointMap; _jointMap = jointMap;
_jointMapCompleted = true; _jointMapCompleted = true;
}
}; };
int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) { int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) {
int result = -1; int result = -1;
int mapSize = _jointMap.size(); int mapSize = (int) _jointMap.size();
if (modelJointIndex >=0 && modelJointIndex < mapSize) { if (modelJointIndex >=0 && modelJointIndex < mapSize) {
result = _jointMap[modelJointIndex]; result = _jointMap[modelJointIndex];
} }
@ -854,6 +862,13 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const {
return glm::vec3(); return glm::vec3();
} }
void RenderableModelEntityItem::setOverrideTransform(const Transform& transform) {
auto model = getModel();
if (model) {
model->overrideModelTransform(transform);
}
}
bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) { bool RenderableModelEntityItem::setLocalJointRotation(int index, const glm::quat& rotation) {
autoResizeJointArrays(); autoResizeJointArrays();
bool result = false; bool result = false;

View file

@ -87,6 +87,7 @@ public:
bool getJointMapCompleted(); bool getJointMapCompleted();
void setJointMap(std::vector<int> jointMap); void setJointMap(std::vector<int> jointMap);
int avatarJointIndex(int modelJointIndex); int avatarJointIndex(int modelJointIndex);
void setOverrideTransform(const Transform& transform);
// these are in the frame of this object (model space) // these are in the frame of this object (model space)
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override; virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;

View file

@ -144,7 +144,13 @@ void Model::setTransformNoUpdateRenderItems(const Transform& transform) {
} }
Transform Model::getTransform() const { Transform Model::getTransform() const {
if (_spatiallyNestableOverride) { if (_overrideModelTransform) {
Transform transform;
transform.setTranslation(getOverrideTranslation());
transform.setRotation(getOverrideRotation());
transform.setScale(getScale());
return transform;
} else if (_spatiallyNestableOverride) {
bool success; bool success;
Transform transform = _spatiallyNestableOverride->getTransform(success); Transform transform = _spatiallyNestableOverride->getTransform(success);
if (success) { if (success) {
@ -1363,6 +1369,12 @@ void Model::deleteGeometry() {
_collisionGeometry.reset(); _collisionGeometry.reset();
} }
void Model::overrideModelTransform(const Transform& transform) {
_overrideTranslation = transform.getTranslation();
_overrideRotation = transform.getRotation();
_overrideModelTransform = true;
}
AABox Model::getRenderableMeshBound() const { AABox Model::getRenderableMeshBound() const {
if (!isLoaded()) { if (!isLoaded()) {
return AABox(); return AABox();

View file

@ -208,10 +208,14 @@ public:
void setTranslation(const glm::vec3& translation); void setTranslation(const glm::vec3& translation);
void setRotation(const glm::quat& rotation); void setRotation(const glm::quat& rotation);
void overrideModelTransform(const Transform& transform);
void setOverrideTransform(bool override) { _overrideModelTransform = override; };
void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK
const glm::vec3& getTranslation() const { return _translation; } const glm::vec3& getTranslation() const { return _translation; }
const glm::quat& getRotation() const { return _rotation; } const glm::quat& getRotation() const { return _rotation; }
const glm::vec3& getOverrideTranslation() const { return _overrideTranslation; }
const glm::quat& getOverrideRotation() const { return _overrideRotation; }
glm::vec3 getNaturalDimensions() const; glm::vec3 getNaturalDimensions() const;
@ -302,6 +306,9 @@ protected:
glm::quat _rotation; glm::quat _rotation;
glm::vec3 _scale; glm::vec3 _scale;
glm::vec3 _overrideTranslation;
glm::quat _overrideRotation;
// For entity models this is the translation for the minimum extent of the model (in original mesh coordinate space) // For entity models this is the translation for the minimum extent of the model (in original mesh coordinate space)
// to the model's registration point. For avatar models this is the translation from the avatar's hips, as determined // to the model's registration point. For avatar models this is the translation from the avatar's hips, as determined
// by the default pose, to the origin. // by the default pose, to the origin.
@ -362,6 +369,7 @@ protected:
QMutex _mutex; QMutex _mutex;
bool _overrideModelTransform { false };
bool _triangleSetsValid { false }; bool _triangleSetsValid { false };
void calculateTriangleSets(); void calculateTriangleSets();
QVector<TriangleSet> _modelSpaceMeshTriangleSets; // model space triangles for all sub meshes QVector<TriangleSet> _modelSpaceMeshTriangleSets; // model space triangles for all sub meshes