make changes

This commit is contained in:
Dante Ruiz 2018-01-10 16:50:41 -08:00
parent d0bff29471
commit 980807c657
3 changed files with 69 additions and 17 deletions

View file

@ -355,24 +355,52 @@ void Avatar::relayJointDataToChildren() {
auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
if (modelEntity) {
if (modelEntity->getRelayParentJoints()) {
QStringList modelJointNames = modelEntity->getJointNames();
QStringList avatarJointNames = getJointNames();
foreach (const QString& jointName, modelJointNames) {
bool containsJoint = avatarJointNames.contains(jointName);
glm::quat jointRotation;
glm::vec3 jointTranslation;
if (!containsJoint) {
int jointIndex = modelEntity->getJointIndex(jointName);
jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex);
jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex);
} else {
int jointIndex = getJointIndex(jointName);
jointRotation = getJointRotation(jointIndex);
jointTranslation = getJointTranslation(jointIndex);
qDebug() << modelEntity->getJointMapCompleted();
if (!(modelEntity->getJointMapCompleted())) {
qDebug() << "constructing map";
QStringList modelJointNames = modelEntity->getJointNames();
int numJoints = modelJointNames.count();
std::vector<int> map;
map.reserve(numJoints);
for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) {
QString jointName = modelJointNames.at(jointIndex);
int avatarJointIndex = getJointIndex(jointName);
glm::quat jointRotation;
glm::vec3 jointTranslation;
qDebug() << avatarJointIndex;
if (avatarJointIndex < 0) {
jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex);
jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex);
map.push_back(-1);
} else {
int jointIndex = getJointIndex(jointName);
jointRotation = getJointRotation(jointIndex);
jointTranslation = getJointTranslation(jointIndex);
map.push_back(avatarJointIndex);
}
modelEntity->setLocalJointRotation(jointIndex, jointRotation);
modelEntity->setLocalJointTranslation(jointIndex, jointTranslation);
}
modelEntity->setJointMap(map);
} else {
QStringList modelJointNames = modelEntity->getJointNames();
int numJoints = modelJointNames.count();
for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) {
int avatarJointIndex = modelEntity->avatarJointIndex(jointIndex);
int index = modelEntity->getJointIndex(modelJointNames.at(jointIndex));
//qDebug() << jointIndex << "------" << index;
glm::quat jointRotation;
glm::vec3 jointTranslation;
if (avatarJointIndex >=0) {
jointRotation = getJointRotation(avatarJointIndex);
jointTranslation = getJointTranslation(avatarJointIndex);
} else {
jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex);
jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex);
}
modelEntity->setLocalJointRotation(jointIndex, jointRotation);
modelEntity->setLocalJointTranslation(jointIndex, jointTranslation);
}
int modelJointIndex = modelEntity->getJointIndex(jointName);
modelEntity->setLocalJointRotation(modelJointIndex, jointRotation);
modelEntity->setLocalJointTranslation(modelJointIndex, jointTranslation);
}
modelEntity->simulateRelayedJoints();
}

View file

@ -708,6 +708,21 @@ void RenderableModelEntityItem::setCollisionShape(const btCollisionShape* shape)
}
}
void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) {
_jointMap = jointMap;
_jointMapCompleted = true;
};
int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) {
int result = -1;
int mapSize = _jointMap.size();
if (modelJointIndex >=0 && modelJointIndex < mapSize) {
result = _jointMap[modelJointIndex];
}
return result;
}
bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
auto model = getModel();
if (EntityItem::contains(point) && model && _compoundShapeResource && _compoundShapeResource->isLoaded()) {
@ -813,6 +828,10 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind
return setLocalJointTranslation(index, jointRelativePose.trans());
}
bool RenderableModelEntityItem::getJointMapCompleted() {
return _jointMapCompleted;
}
glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const {
auto model = getModel();
if (model) {

View file

@ -84,6 +84,9 @@ public:
virtual bool shouldBePhysical() const override;
void simulateRelayedJoints();
bool getJointMapCompleted();
void setJointMap(std::vector<int> jointMap);
int avatarJointIndex(int modelJointIndex);
// these are in the frame of this object (model space)
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
@ -119,7 +122,9 @@ private:
void getCollisionGeometryResource();
GeometryResource::Pointer _compoundShapeResource;
bool _jointMapCompleted { false };
bool _originalTexturesRead { false };
std::vector<int> _jointMap;
QVariantMap _originalTextures;
bool _dimensionsInitialized { true };
bool _needsJointSimulation { false };