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); auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
if (modelEntity) { if (modelEntity) {
if (modelEntity->getRelayParentJoints()) { if (modelEntity->getRelayParentJoints()) {
qDebug() << modelEntity->getJointMapCompleted();
if (!(modelEntity->getJointMapCompleted())) {
qDebug() << "constructing map";
QStringList modelJointNames = modelEntity->getJointNames(); QStringList modelJointNames = modelEntity->getJointNames();
QStringList avatarJointNames = getJointNames(); int numJoints = modelJointNames.count();
foreach (const QString& jointName, modelJointNames) { std::vector<int> map;
bool containsJoint = avatarJointNames.contains(jointName); map.reserve(numJoints);
for (int jointIndex = 0; jointIndex < numJoints; jointIndex++) {
QString jointName = modelJointNames.at(jointIndex);
int avatarJointIndex = getJointIndex(jointName);
glm::quat jointRotation; glm::quat jointRotation;
glm::vec3 jointTranslation; glm::vec3 jointTranslation;
if (!containsJoint) { qDebug() << avatarJointIndex;
int jointIndex = modelEntity->getJointIndex(jointName); if (avatarJointIndex < 0) {
jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex); jointRotation = modelEntity->getAbsoluteJointRotationInObjectFrame(jointIndex);
jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex); jointTranslation = modelEntity->getAbsoluteJointTranslationInObjectFrame(jointIndex);
map.push_back(-1);
} else { } else {
int jointIndex = getJointIndex(jointName); int jointIndex = getJointIndex(jointName);
jointRotation = getJointRotation(jointIndex); jointRotation = getJointRotation(jointIndex);
jointTranslation = getJointTranslation(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(); 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 { bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
auto model = getModel(); auto model = getModel();
if (EntityItem::contains(point) && model && _compoundShapeResource && _compoundShapeResource->isLoaded()) { if (EntityItem::contains(point) && model && _compoundShapeResource && _compoundShapeResource->isLoaded()) {
@ -813,6 +828,10 @@ bool RenderableModelEntityItem::setAbsoluteJointTranslationInObjectFrame(int ind
return setLocalJointTranslation(index, jointRelativePose.trans()); return setLocalJointTranslation(index, jointRelativePose.trans());
} }
bool RenderableModelEntityItem::getJointMapCompleted() {
return _jointMapCompleted;
}
glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const { glm::quat RenderableModelEntityItem::getLocalJointRotation(int index) const {
auto model = getModel(); auto model = getModel();
if (model) { if (model) {

View file

@ -84,6 +84,9 @@ public:
virtual bool shouldBePhysical() const override; virtual bool shouldBePhysical() const override;
void simulateRelayedJoints(); void simulateRelayedJoints();
bool getJointMapCompleted();
void setJointMap(std::vector<int> jointMap);
int avatarJointIndex(int modelJointIndex);
// 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;
@ -119,7 +122,9 @@ private:
void getCollisionGeometryResource(); void getCollisionGeometryResource();
GeometryResource::Pointer _compoundShapeResource; GeometryResource::Pointer _compoundShapeResource;
bool _jointMapCompleted { false };
bool _originalTexturesRead { false }; bool _originalTexturesRead { false };
std::vector<int> _jointMap;
QVariantMap _originalTextures; QVariantMap _originalTextures;
bool _dimensionsInitialized { true }; bool _dimensionsInitialized { true };
bool _needsJointSimulation { false }; bool _needsJointSimulation { false };