mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +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()) {
|
if (propMap["parentJointIndex"].isValid()) {
|
||||||
parentJointIndex = propMap["parentJointIndex"].toInt();
|
parentJointIndex = propMap["parentJointIndex"].toInt();
|
||||||
}
|
}
|
||||||
|
glm::vec3 baseScale = glm::vec3(1);
|
||||||
|
if (propMap["baseScale"].isValid()) {
|
||||||
|
baseScale = vec3FromVariant(propMap["baseScale"]);
|
||||||
|
}
|
||||||
auto sharedNestablePointer = nestablePointer.lock();
|
auto sharedNestablePointer = nestablePointer.lock();
|
||||||
if (success && sharedNestablePointer) {
|
if (success && sharedNestablePointer) {
|
||||||
NestableType nestableType = sharedNestablePointer->getNestableType();
|
NestableType nestableType = sharedNestablePointer->getNestableType();
|
||||||
|
|
|
@ -7,24 +7,6 @@
|
||||||
//
|
//
|
||||||
#include "OverlayTransformNode.h"
|
#include "OverlayTransformNode.h"
|
||||||
|
|
||||||
OverlayTransformNode::OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex) :
|
glm::vec3 BaseNestableTransformNode<Base3DOverlay>::getActualScale(const std::shared_ptr<Base3DOverlay>& nestablePointer) const {
|
||||||
_overlay(overlay),
|
return nestablePointer->getBounds().getScale();
|
||||||
_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;
|
|
||||||
}
|
}
|
|
@ -8,19 +8,14 @@
|
||||||
#ifndef hifi_OverlayTransformNode_h
|
#ifndef hifi_OverlayTransformNode_h
|
||||||
#define hifi_OverlayTransformNode_h
|
#define hifi_OverlayTransformNode_h
|
||||||
|
|
||||||
#include "TransformNode.h"
|
#include "NestableTransformNode.h"
|
||||||
|
|
||||||
#include "Base3DOverlay.h"
|
#include "Base3DOverlay.h"
|
||||||
|
|
||||||
// For 3D overlays only
|
// For 3D overlays only
|
||||||
class OverlayTransformNode : public TransformNode {
|
class OverlayTransformNode : public BaseNestableTransformNode<Base3DOverlay> {
|
||||||
public:
|
public:
|
||||||
OverlayTransformNode(std::weak_ptr<Base3DOverlay> overlay, int jointIndex);
|
OverlayTransformNode(std::weak_ptr<Base3DOverlay> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||||
Transform getTransform() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::weak_ptr<Base3DOverlay> _overlay;
|
|
||||||
int _jointIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_OverlayTransformNode_h
|
#endif // hifi_OverlayTransformNode_h
|
|
@ -7,24 +7,6 @@
|
||||||
//
|
//
|
||||||
#include "AvatarTransformNode.h"
|
#include "AvatarTransformNode.h"
|
||||||
|
|
||||||
AvatarTransformNode::AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex) :
|
glm::vec3 BaseNestableTransformNode<Avatar>::getActualScale(const std::shared_ptr<Avatar>& nestablePointer) const {
|
||||||
_avatar(avatar),
|
return nestablePointer->scaleForChildren();
|
||||||
_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;
|
|
||||||
}
|
}
|
|
@ -8,18 +8,13 @@
|
||||||
#ifndef hifi_AvatarTransformNode_h
|
#ifndef hifi_AvatarTransformNode_h
|
||||||
#define hifi_AvatarTransformNode_h
|
#define hifi_AvatarTransformNode_h
|
||||||
|
|
||||||
#include "TransformNode.h"
|
#include "NestableTransformNode.h"
|
||||||
|
|
||||||
#include "Avatar.h"
|
#include "Avatar.h"
|
||||||
|
|
||||||
class AvatarTransformNode : public TransformNode {
|
class AvatarTransformNode : public BaseNestableTransformNode<Avatar> {
|
||||||
public:
|
public:
|
||||||
AvatarTransformNode(AvatarWeakPointer avatar, int jointIndex);
|
AvatarTransformNode(std::weak_ptr<Avatar> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||||
Transform getTransform() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
AvatarWeakPointer _avatar;
|
|
||||||
int _jointIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarTransformNode_h
|
#endif // hifi_AvatarTransformNode_h
|
|
@ -7,24 +7,6 @@
|
||||||
//
|
//
|
||||||
#include "EntityTransformNode.h"
|
#include "EntityTransformNode.h"
|
||||||
|
|
||||||
EntityTransformNode::EntityTransformNode(EntityItemWeakPointer entity, int jointIndex) :
|
glm::vec3 BaseNestableTransformNode<EntityItem>::getActualScale(const std::shared_ptr<EntityItem>& nestablePointer) const {
|
||||||
_entity(entity),
|
return nestablePointer->getScaledDimensions();
|
||||||
_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;
|
|
||||||
}
|
}
|
|
@ -8,18 +8,13 @@
|
||||||
#ifndef hifi_EntityTransformNode_h
|
#ifndef hifi_EntityTransformNode_h
|
||||||
#define hifi_EntityTransformNode_h
|
#define hifi_EntityTransformNode_h
|
||||||
|
|
||||||
#include "TransformNode.h"
|
#include "NestableTransformNode.h"
|
||||||
|
|
||||||
#include "EntityItem.h"
|
#include "EntityItem.h"
|
||||||
|
|
||||||
class EntityTransformNode : public TransformNode {
|
class EntityTransformNode : public BaseNestableTransformNode<EntityItem> {
|
||||||
public:
|
public:
|
||||||
EntityTransformNode(EntityItemWeakPointer entity, int jointIndex);
|
EntityTransformNode(std::weak_ptr<EntityItem> spatiallyNestable, int jointIndex) : BaseNestableTransformNode(spatiallyNestable, jointIndex) {};
|
||||||
Transform getTransform() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
EntityItemWeakPointer _entity;
|
|
||||||
int _jointIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityTransformNode_h
|
#endif // hifi_EntityTransformNode_h
|
|
@ -8,24 +8,6 @@
|
||||||
|
|
||||||
#include "NestableTransformNode.h"
|
#include "NestableTransformNode.h"
|
||||||
|
|
||||||
NestableTransformNode::NestableTransformNode(SpatiallyNestableWeakPointer spatiallyNestable, int jointIndex) :
|
glm::vec3 BaseNestableTransformNode<SpatiallyNestable>::getActualScale(const std::shared_ptr<SpatiallyNestable>& nestablePointer) const {
|
||||||
_spatiallyNestable(spatiallyNestable),
|
return nestablePointer->getAbsoluteJointScaleInObjectFrame(_jointIndex);
|
||||||
_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();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -12,14 +12,50 @@
|
||||||
|
|
||||||
#include "SpatiallyNestable.h"
|
#include "SpatiallyNestable.h"
|
||||||
|
|
||||||
class NestableTransformNode : public TransformNode {
|
template <typename T>
|
||||||
|
class BaseNestableTransformNode : public TransformNode {
|
||||||
public:
|
public:
|
||||||
NestableTransformNode(SpatiallyNestableWeakPointer spatiallyNestable, int jointIndex);
|
BaseNestableTransformNode(std::weak_ptr<T> spatiallyNestable, int jointIndex) :
|
||||||
Transform getTransform() override;
|
_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:
|
protected:
|
||||||
SpatiallyNestableWeakPointer _spatiallyNestable;
|
std::weak_ptr<T> _spatiallyNestable;
|
||||||
int _jointIndex;
|
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
|
#endif // hifi_NestableTransformNode_h
|
Loading…
Reference in a new issue