mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Have OverlayTransformNode and similar define scale relative to nestable scale on creation time, and refactor code
This commit is contained in:
parent
714cfc5ef1
commit
836f810c41
9 changed files with 61 additions and 108 deletions
|
@ -383,6 +383,10 @@ std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const
|
|||
if (propMap["parentJointIndex"].isValid()) {
|
||||
parentJointIndex = propMap["parentJointIndex"].toInt();
|
||||
}
|
||||
glm::vec3 baseScale = glm::vec3(1);
|
||||
if (propMap["baseScale"].isValid()) {
|
||||
baseScale = vec3FromVariant(propMap["baseScale"]);
|
||||
}
|
||||
auto sharedNestablePointer = nestablePointer.lock();
|
||||
if (success && sharedNestablePointer) {
|
||||
NestableType nestableType = sharedNestablePointer->getNestableType();
|
||||
|
|
|
@ -7,24 +7,6 @@
|
|||
//
|
||||
#include "OverlayTransformNode.h"
|
||||
|
||||
OverlayTransformNode::OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex) :
|
||||
_overlay(overlay),
|
||||
_jointIndex(jointIndex)
|
||||
{}
|
||||
|
||||
Transform OverlayTransformNode::getTransform() {
|
||||
auto overlay = _overlay.lock();
|
||||
if (!overlay) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
bool success;
|
||||
Transform jointWorldTransform = overlay->getTransform(_jointIndex, success);
|
||||
if (!success) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
jointWorldTransform.setScale(overlay->getBounds().getScale());
|
||||
|
||||
return jointWorldTransform;
|
||||
glm::vec3 BaseNestableTransformNode<Base3DOverlay>::getActualScale(const std::shared_ptr<Base3DOverlay>& nestablePointer) const {
|
||||
return nestablePointer->getBounds().getScale();
|
||||
}
|
|
@ -8,19 +8,14 @@
|
|||
#ifndef hifi_OverlayTransformNode_h
|
||||
#define hifi_OverlayTransformNode_h
|
||||
|
||||
#include "TransformNode.h"
|
||||
#include "NestableTransformNode.h"
|
||||
|
||||
#include "Base3DOverlay.h"
|
||||
|
||||
// For 3D overlays only
|
||||
class OverlayTransformNode : public TransformNode {
|
||||
class OverlayTransformNode : public BaseNestableTransformNode<Base3DOverlay> {
|
||||
public:
|
||||
OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex);
|
||||
Transform getTransform() override;
|
||||
|
||||
protected:
|
||||
std::weak_ptr<Base3DOverlay> _overlay;
|
||||
int _jointIndex;
|
||||
OverlayTransformNode(std::weak_ptr<Base3DOverlay> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||
};
|
||||
|
||||
#endif // hifi_OverlayTransformNode_h
|
|
@ -7,24 +7,6 @@
|
|||
//
|
||||
#include "AvatarTransformNode.h"
|
||||
|
||||
AvatarTransformNode::AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex) :
|
||||
_avatar(avatar),
|
||||
_jointIndex(jointIndex)
|
||||
{}
|
||||
|
||||
Transform AvatarTransformNode::getTransform() {
|
||||
auto avatar = _avatar.lock();
|
||||
if (!avatar) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
bool success;
|
||||
Transform jointWorldTransform = avatar->getTransform(_jointIndex, success);
|
||||
if (!success) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
jointWorldTransform.setScale(avatar->scaleForChildren());
|
||||
|
||||
return jointWorldTransform;
|
||||
glm::vec3 BaseNestableTransformNode<Avatar>::getActualScale(const std::shared_ptr<Avatar>& nestablePointer) const {
|
||||
return nestablePointer->scaleForChildren();
|
||||
}
|
|
@ -8,18 +8,13 @@
|
|||
#ifndef hifi_AvatarTransformNode_h
|
||||
#define hifi_AvatarTransformNode_h
|
||||
|
||||
#include "TransformNode.h"
|
||||
#include "NestableTransformNode.h"
|
||||
|
||||
#include "Avatar.h"
|
||||
|
||||
class AvatarTransformNode : public TransformNode {
|
||||
class AvatarTransformNode : public BaseNestableTransformNode<Avatar> {
|
||||
public:
|
||||
AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex);
|
||||
Transform getTransform() override;
|
||||
|
||||
protected:
|
||||
AvatarWeakPointer _avatar;
|
||||
int _jointIndex;
|
||||
AvatarTransformNode(std::weak_ptr<Avatar> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||
};
|
||||
|
||||
#endif // hifi_AvatarTransformNode_h
|
|
@ -7,24 +7,6 @@
|
|||
//
|
||||
#include "EntityTransformNode.h"
|
||||
|
||||
EntityTransformNode::EntityTransformNode(EntityItemWeakPointer entity, int jointIndex) :
|
||||
_entity(entity),
|
||||
_jointIndex(jointIndex)
|
||||
{}
|
||||
|
||||
Transform EntityTransformNode::getTransform() {
|
||||
auto entity = _entity.lock();
|
||||
if (!entity) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
bool success;
|
||||
Transform jointWorldTransform = entity->getTransform(_jointIndex, success);
|
||||
if (!success) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
jointWorldTransform.setScale(entity->getScaledDimensions());
|
||||
|
||||
return jointWorldTransform;
|
||||
glm::vec3 BaseNestableTransformNode<EntityItem>::getActualScale(const std::shared_ptr<EntityItem>& nestablePointer) const {
|
||||
return nestablePointer->getScaledDimensions();
|
||||
}
|
|
@ -8,18 +8,13 @@
|
|||
#ifndef hifi_EntityTransformNode_h
|
||||
#define hifi_EntityTransformNode_h
|
||||
|
||||
#include "TransformNode.h"
|
||||
#include "NestableTransformNode.h"
|
||||
|
||||
#include "EntityItem.h"
|
||||
|
||||
class EntityTransformNode : public TransformNode {
|
||||
class EntityTransformNode : public BaseNestableTransformNode<EntityItem> {
|
||||
public:
|
||||
EntityTransformNode(EntityItemWeakPointer entity, int jointIndex);
|
||||
Transform getTransform() override;
|
||||
|
||||
protected:
|
||||
EntityItemWeakPointer _entity;
|
||||
int _jointIndex;
|
||||
EntityTransformNode(std::weak_ptr<EntityItem> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||
};
|
||||
|
||||
#endif // hifi_EntityTransformNode_h
|
|
@ -8,24 +8,6 @@
|
|||
|
||||
#include "NestableTransformNode.h"
|
||||
|
||||
NestableTransformNode::NestableTransformNode(SpatiallyNestableWeakPointer spatiallyNestable, int jointIndex) :
|
||||
_spatiallyNestable(spatiallyNestable),
|
||||
_jointIndex(jointIndex)
|
||||
{
|
||||
}
|
||||
|
||||
Transform NestableTransformNode::getTransform() {
|
||||
auto nestable = _spatiallyNestable.lock();
|
||||
if (!nestable) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
bool success;
|
||||
Transform jointWorldTransform = nestable->getTransform(_jointIndex, success);
|
||||
|
||||
if (success) {
|
||||
return jointWorldTransform;
|
||||
} else {
|
||||
return Transform();
|
||||
}
|
||||
glm::vec3 BaseNestableTransformNode<SpatiallyNestable>::getActualScale(const std::shared_ptr<SpatiallyNestable>& nestablePointer) const {
|
||||
return nestablePointer->getAbsoluteJointScaleInObjectFrame(_jointIndex);
|
||||
}
|
|
@ -12,14 +12,50 @@
|
|||
|
||||
#include "SpatiallyNestable.h"
|
||||
|
||||
class NestableTransformNode : public TransformNode {
|
||||
template <typename T>
|
||||
class BaseNestableTransformNode : public TransformNode {
|
||||
public:
|
||||
NestableTransformNode(SpatiallyNestableWeakPointer spatiallyNestable, int jointIndex);
|
||||
Transform getTransform() override;
|
||||
BaseNestableTransformNode(std::weak_ptr<T> spatiallyNestable, int jointIndex) :
|
||||
_spatiallyNestable(spatiallyNestable),
|
||||
_jointIndex(jointIndex) {
|
||||
auto nestablePointer = _spatiallyNestable.lock();
|
||||
if (nestablePointer) {
|
||||
glm::vec3 nestableDimensions = getActualScale(nestablePointer);
|
||||
if (!glm::any(glm::equal(nestableDimensions, glm::vec3(0.0f)))) {
|
||||
_baseScale = nestableDimensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Transform getTransform() {
|
||||
std::shared_ptr<T> nestable = _spatiallyNestable.lock();
|
||||
if (!nestable) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
bool success;
|
||||
Transform jointWorldTransform = nestable->getTransform(_jointIndex, success);
|
||||
|
||||
if (!success) {
|
||||
return Transform();
|
||||
}
|
||||
|
||||
jointWorldTransform.setScale(getActualScale(nestable) / _baseScale);
|
||||
|
||||
return jointWorldTransform;
|
||||
}
|
||||
|
||||
glm::vec3 getActualScale(const std::shared_ptr<T>& nestablePointer) const;
|
||||
|
||||
protected:
|
||||
SpatiallyNestableWeakPointer _spatiallyNestable;
|
||||
std::weak_ptr<T> _spatiallyNestable;
|
||||
int _jointIndex;
|
||||
glm::vec3 _baseScale { 1.0f };
|
||||
};
|
||||
|
||||
class NestableTransformNode : public BaseNestableTransformNode<SpatiallyNestable> {
|
||||
public:
|
||||
NestableTransformNode(std::weak_ptr<SpatiallyNestable> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||
};
|
||||
|
||||
#endif // hifi_NestableTransformNode_h
|
Loading…
Reference in a new issue