mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
added model transform override
This commit is contained in:
parent
980807c657
commit
96a97b5938
6 changed files with 43 additions and 8 deletions
|
@ -537,7 +537,7 @@ void MyAvatar::simulate(float deltaTime) {
|
|||
// we've achived our final adjusted position and rotation for the avatar
|
||||
// and all of its joints, now update our attachements.
|
||||
Avatar::simulateAttachments(deltaTime);
|
||||
Avatar::relayJointDataToChildren();
|
||||
relayJointDataToChildren();
|
||||
|
||||
if (!_skeletonModel->hasSkeleton()) {
|
||||
// All the simulation that can be done has been done
|
||||
|
|
|
@ -355,9 +355,7 @@ void Avatar::relayJointDataToChildren() {
|
|||
auto modelEntity = std::dynamic_pointer_cast<RenderableModelEntityItem>(child);
|
||||
if (modelEntity) {
|
||||
if (modelEntity->getRelayParentJoints()) {
|
||||
qDebug() << modelEntity->getJointMapCompleted();
|
||||
if (!(modelEntity->getJointMapCompleted())) {
|
||||
qDebug() << "constructing map";
|
||||
QStringList modelJointNames = modelEntity->getJointNames();
|
||||
int numJoints = modelJointNames.count();
|
||||
std::vector<int> map;
|
||||
|
@ -388,7 +386,6 @@ void Avatar::relayJointDataToChildren() {
|
|||
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) {
|
||||
|
@ -402,6 +399,8 @@ void Avatar::relayJointDataToChildren() {
|
|||
modelEntity->setLocalJointTranslation(jointIndex, jointTranslation);
|
||||
}
|
||||
}
|
||||
|
||||
modelEntity->setOverrideTransform(_skeletonModel->getTransform());
|
||||
modelEntity->simulateRelayedJoints();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,6 +209,12 @@ 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
|
||||
|
@ -709,13 +715,15 @@ void RenderableModelEntityItem::setCollisionShape(const btCollisionShape* shape)
|
|||
}
|
||||
|
||||
void RenderableModelEntityItem::setJointMap(std::vector<int> jointMap) {
|
||||
_jointMap = jointMap;
|
||||
_jointMapCompleted = true;
|
||||
if (jointMap.size() > 0) {
|
||||
_jointMap = jointMap;
|
||||
_jointMapCompleted = true;
|
||||
}
|
||||
};
|
||||
|
||||
int RenderableModelEntityItem::avatarJointIndex(int modelJointIndex) {
|
||||
int result = -1;
|
||||
int mapSize = _jointMap.size();
|
||||
int mapSize = (int) _jointMap.size();
|
||||
if (modelJointIndex >=0 && modelJointIndex < mapSize) {
|
||||
result = _jointMap[modelJointIndex];
|
||||
}
|
||||
|
@ -854,6 +862,13 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const {
|
|||
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) {
|
||||
autoResizeJointArrays();
|
||||
bool result = false;
|
||||
|
|
|
@ -87,6 +87,7 @@ public:
|
|||
bool getJointMapCompleted();
|
||||
void setJointMap(std::vector<int> jointMap);
|
||||
int avatarJointIndex(int modelJointIndex);
|
||||
void setOverrideTransform(const Transform& transform);
|
||||
|
||||
// these are in the frame of this object (model space)
|
||||
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
|
||||
|
|
|
@ -144,7 +144,13 @@ void Model::setTransformNoUpdateRenderItems(const Transform& transform) {
|
|||
}
|
||||
|
||||
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;
|
||||
Transform transform = _spatiallyNestableOverride->getTransform(success);
|
||||
if (success) {
|
||||
|
@ -1363,6 +1369,12 @@ void Model::deleteGeometry() {
|
|||
_collisionGeometry.reset();
|
||||
}
|
||||
|
||||
void Model::overrideModelTransform(const Transform& transform) {
|
||||
_overrideTranslation = transform.getTranslation();
|
||||
_overrideRotation = transform.getRotation();
|
||||
_overrideModelTransform = true;
|
||||
}
|
||||
|
||||
AABox Model::getRenderableMeshBound() const {
|
||||
if (!isLoaded()) {
|
||||
return AABox();
|
||||
|
|
|
@ -208,10 +208,14 @@ public:
|
|||
|
||||
void setTranslation(const glm::vec3& translation);
|
||||
void setRotation(const glm::quat& rotation);
|
||||
void overrideModelTransform(const Transform& transform);
|
||||
void setOverrideTransform(bool override) { _overrideModelTransform = override; };
|
||||
void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK
|
||||
|
||||
const glm::vec3& getTranslation() const { return _translation; }
|
||||
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;
|
||||
|
||||
|
@ -302,6 +306,9 @@ protected:
|
|||
glm::quat _rotation;
|
||||
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)
|
||||
// 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.
|
||||
|
@ -362,6 +369,7 @@ protected:
|
|||
|
||||
QMutex _mutex;
|
||||
|
||||
bool _overrideModelTransform { false };
|
||||
bool _triangleSetsValid { false };
|
||||
void calculateTriangleSets();
|
||||
QVector<TriangleSet> _modelSpaceMeshTriangleSets; // model space triangles for all sub meshes
|
||||
|
|
Loading…
Reference in a new issue