mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-30 19:23:22 +02:00
fix up parenting for 3d line overlays, have handControllerGrab use a child overlay for search/far-grab so the updates are smoother
This commit is contained in:
parent
8e91fc3dde
commit
7c4869eb73
3 changed files with 124 additions and 62 deletions
interface/src/ui/overlays
scripts/system/controllers
|
@ -23,10 +23,13 @@ Line3DOverlay::Line3DOverlay() :
|
|||
|
||||
Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) :
|
||||
Base3DOverlay(line3DOverlay),
|
||||
_start(line3DOverlay->_start),
|
||||
_end(line3DOverlay->_end),
|
||||
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
|
||||
{
|
||||
setParentID(line3DOverlay->getParentID());
|
||||
setParentJointIndex(line3DOverlay->getParentJointIndex());
|
||||
setLocalTransform(line3DOverlay->getLocalTransform());
|
||||
_direction = line3DOverlay->getDirection();
|
||||
_length = line3DOverlay->getLength();
|
||||
}
|
||||
|
||||
Line3DOverlay::~Line3DOverlay() {
|
||||
|
@ -37,17 +40,14 @@ Line3DOverlay::~Line3DOverlay() {
|
|||
}
|
||||
|
||||
glm::vec3 Line3DOverlay::getStart() const {
|
||||
bool success;
|
||||
glm::vec3 worldStart = localToWorld(_start, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::getStart failed";
|
||||
}
|
||||
return worldStart;
|
||||
return getPosition();
|
||||
}
|
||||
|
||||
glm::vec3 Line3DOverlay::getEnd() const {
|
||||
bool success;
|
||||
glm::vec3 worldEnd = localToWorld(_end, getParentID(), getParentJointIndex(), success);
|
||||
|
||||
glm::vec3 localEnd = getLocalEnd();
|
||||
glm::vec3 worldEnd = localToWorld(localEnd, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::getEnd failed";
|
||||
}
|
||||
|
@ -55,25 +55,28 @@ glm::vec3 Line3DOverlay::getEnd() const {
|
|||
}
|
||||
|
||||
void Line3DOverlay::setStart(const glm::vec3& start) {
|
||||
bool success;
|
||||
_start = worldToLocal(start, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::setStart failed";
|
||||
}
|
||||
setPosition(start);
|
||||
}
|
||||
|
||||
void Line3DOverlay::setEnd(const glm::vec3& end) {
|
||||
bool success;
|
||||
_end = worldToLocal(end, getParentID(), getParentJointIndex(), success);
|
||||
|
||||
glm::vec3 localStart = getLocalStart();
|
||||
glm::vec3 localEnd = worldToLocal(end, getParentID(), getParentJointIndex(), success);
|
||||
if (!success) {
|
||||
qDebug() << "Line3DOverlay::setEnd failed";
|
||||
return;
|
||||
}
|
||||
|
||||
glm::vec3 offset = localEnd - localStart;
|
||||
_direction = glm::normalize(offset);
|
||||
_length = glm::length(offset);
|
||||
}
|
||||
|
||||
AABox Line3DOverlay::getBounds() const {
|
||||
auto extents = Extents{};
|
||||
extents.addPoint(_start);
|
||||
extents.addPoint(_end);
|
||||
extents.addPoint(getStart());
|
||||
extents.addPoint(getEnd());
|
||||
extents.transform(getTransform());
|
||||
|
||||
return AABox(extents);
|
||||
|
@ -90,18 +93,19 @@ void Line3DOverlay::render(RenderArgs* args) {
|
|||
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||
auto batch = args->_batch;
|
||||
if (batch) {
|
||||
batch->setModelTransform(getTransform());
|
||||
// batch->setModelTransform(getTransform());
|
||||
|
||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||
if (getIsDashedLine()) {
|
||||
// TODO: add support for color to renderDashedLine()
|
||||
geometryCache->bindSimpleProgram(*batch, false, false, false, true, true);
|
||||
geometryCache->renderDashedLine(*batch, _start, _end, colorv4, _geometryCacheID);
|
||||
geometryCache->renderDashedLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID);
|
||||
} else if (_glow > 0.0f) {
|
||||
geometryCache->renderGlowLine(*batch, _start, _end, colorv4, _glow, _glowWidth, _geometryCacheID);
|
||||
geometryCache->renderGlowLine(*batch, getStart(), getEnd(),
|
||||
colorv4, _glow, _glowWidth, _geometryCacheID);
|
||||
} else {
|
||||
geometryCache->bindSimpleProgram(*batch, false, false, false, true, true);
|
||||
geometryCache->renderLine(*batch, _start, _end, colorv4, _geometryCacheID);
|
||||
geometryCache->renderLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +120,10 @@ const render::ShapeKey Line3DOverlay::getShapeKey() {
|
|||
|
||||
void Line3DOverlay::setProperties(const QVariantMap& originalProperties) {
|
||||
QVariantMap properties = originalProperties;
|
||||
glm::vec3 newStart(0.0f);
|
||||
bool newStartSet { false };
|
||||
glm::vec3 newEnd(0.0f);
|
||||
bool newEndSet { false };
|
||||
|
||||
auto start = properties["start"];
|
||||
// if "start" property was not there, check to see if they included aliases: startPoint
|
||||
|
@ -123,13 +131,18 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) {
|
|||
start = properties["startPoint"];
|
||||
}
|
||||
if (start.isValid()) {
|
||||
setStart(vec3FromVariant(start));
|
||||
newStart = vec3FromVariant(start);
|
||||
newStartSet = true;
|
||||
}
|
||||
properties.remove("start"); // so that Base3DOverlay doesn't respond to it
|
||||
|
||||
auto localStart = properties["localStart"];
|
||||
if (localStart.isValid()) {
|
||||
_start = vec3FromVariant(localStart);
|
||||
setLocalPosition(vec3FromVariant(localStart));
|
||||
// in case "end" isn't updated...
|
||||
glm::vec3 offset = getLocalEnd() - getLocalStart();
|
||||
_direction = glm::normalize(offset);
|
||||
_length = glm::length(offset);
|
||||
}
|
||||
properties.remove("localStart"); // so that Base3DOverlay doesn't respond to it
|
||||
|
||||
|
@ -139,15 +152,34 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) {
|
|||
end = properties["endPoint"];
|
||||
}
|
||||
if (end.isValid()) {
|
||||
setEnd(vec3FromVariant(end));
|
||||
newEnd = vec3FromVariant(end);
|
||||
newEndSet = true;
|
||||
}
|
||||
properties.remove("end"); // so that Base3DOverlay doesn't respond to it
|
||||
|
||||
auto localEnd = properties["localEnd"];
|
||||
if (localEnd.isValid()) {
|
||||
_end = vec3FromVariant(localEnd);
|
||||
glm::vec3 offset = vec3FromVariant(localEnd) - getLocalStart();
|
||||
_direction = glm::normalize(offset);
|
||||
_length = glm::length(offset);
|
||||
}
|
||||
properties.remove("localEnd"); // so that Base3DOverlay doesn't respond to it
|
||||
|
||||
auto length = properties["length"];
|
||||
if (length.isValid()) {
|
||||
_length = length.toFloat();
|
||||
}
|
||||
|
||||
Base3DOverlay::setProperties(properties);
|
||||
|
||||
// these are saved until after Base3DOverlay::setProperties so parenting infomation can be set, first
|
||||
if (newStartSet) {
|
||||
setStart(newStart);
|
||||
}
|
||||
if (newEndSet) {
|
||||
setEnd(newEnd);
|
||||
}
|
||||
|
||||
auto glow = properties["glow"];
|
||||
if (glow.isValid()) {
|
||||
setGlow(glow.toFloat());
|
||||
|
@ -161,7 +193,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) {
|
|||
setGlow(glowWidth.toFloat());
|
||||
}
|
||||
|
||||
Base3DOverlay::setProperties(properties);
|
||||
}
|
||||
|
||||
QVariant Line3DOverlay::getProperty(const QString& property) {
|
||||
|
@ -171,6 +202,15 @@ QVariant Line3DOverlay::getProperty(const QString& property) {
|
|||
if (property == "end" || property == "endPoint" || property == "p2") {
|
||||
return vec3toVariant(getEnd());
|
||||
}
|
||||
if (property == "localStart") {
|
||||
return vec3toVariant(getLocalStart());
|
||||
}
|
||||
if (property == "localEnd") {
|
||||
return vec3toVariant(getLocalEnd());
|
||||
}
|
||||
if (property == "length") {
|
||||
return QVariant(getLength());
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
|
|
@ -47,13 +47,17 @@ public:
|
|||
|
||||
virtual void locationChanged(bool tellPhysics = true) override;
|
||||
|
||||
protected:
|
||||
glm::vec3 _start;
|
||||
glm::vec3 _end;
|
||||
glm::vec3 getDirection() const { return _direction; }
|
||||
float getLength() const { return _length; }
|
||||
glm::vec3 getLocalStart() const { return getLocalPosition(); }
|
||||
glm::vec3 getLocalEnd() const { return getLocalStart() + _direction * _length; }
|
||||
|
||||
private:
|
||||
glm::vec3 _direction; // in parent frame
|
||||
float _length { 1.0 }; // in parent frame
|
||||
float _glow { 0.0 };
|
||||
float _glowWidth { 0.0 };
|
||||
int _geometryCacheID;
|
||||
};
|
||||
|
||||
|
||||
#endif // hifi_Line3DOverlay_h
|
||||
|
|
|
@ -739,6 +739,10 @@ function MyController(hand) {
|
|||
this.stylus = null;
|
||||
this.homeButtonTouched = false;
|
||||
|
||||
this.controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
|
||||
"_CONTROLLER_RIGHTHAND" :
|
||||
"_CONTROLLER_LEFTHAND");
|
||||
|
||||
// Until there is some reliable way to keep track of a "stack" of parentIDs, we'll have problems
|
||||
// when more than one avatar does parenting grabs on things. This script tries to work
|
||||
// around this with two associative arrays: previousParentID and previousParentJointIndex. If
|
||||
|
@ -913,9 +917,7 @@ function MyController(hand) {
|
|||
ignoreRayIntersection: true,
|
||||
drawInFront: false,
|
||||
parentID: AVATAR_SELF_ID,
|
||||
parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
|
||||
"_CONTROLLER_RIGHTHAND" :
|
||||
"_CONTROLLER_LEFTHAND")
|
||||
parentJointIndex: this.controllerJointIndex
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -999,29 +1001,51 @@ function MyController(hand) {
|
|||
|
||||
this.overlayLineOn = function(closePoint, farPoint, color) {
|
||||
if (this.overlayLine === null) {
|
||||
var lineProperties = {
|
||||
glow: 1.0,
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
color: color,
|
||||
ignoreRayIntersection: true, // always ignore this
|
||||
drawInFront: true, // Even when burried inside of something, show it.
|
||||
visible: true,
|
||||
alpha: 1
|
||||
};
|
||||
var lineProperties;
|
||||
if (this.hand === RIGHT_HAND) {
|
||||
lineProperties = {
|
||||
glow: 1.0,
|
||||
lineWidth: 5,
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
color: color,
|
||||
ignoreRayIntersection: true, // always ignore this
|
||||
drawInFront: true, // Even when burried inside of something, show it.
|
||||
visible: true,
|
||||
alpha: 1,
|
||||
parentID: AVATAR_SELF_ID,
|
||||
parentJointIndex: this.controllerJointIndex
|
||||
};
|
||||
} else {
|
||||
lineProperties = {
|
||||
glow: 1.0,
|
||||
lineWidth: 5,
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
color: color,
|
||||
ignoreRayIntersection: true, // always ignore this
|
||||
drawInFront: true, // Even when burried inside of something, show it.
|
||||
visible: true,
|
||||
alpha: 1,
|
||||
};
|
||||
}
|
||||
this.overlayLine = Overlays.addOverlay("line3d", lineProperties);
|
||||
|
||||
} else {
|
||||
Overlays.editOverlay(this.overlayLine, {
|
||||
lineWidth: 5,
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
color: color,
|
||||
visible: true,
|
||||
ignoreRayIntersection: true, // always ignore this
|
||||
drawInFront: true, // Even when burried inside of something, show it.
|
||||
alpha: 1
|
||||
});
|
||||
if (this.hand === RIGHT_HAND) {
|
||||
Overlays.editOverlay(this.overlayLine, {
|
||||
// start: closePoint,
|
||||
// end: farPoint,
|
||||
length: Vec3.distance(farPoint, closePoint),
|
||||
color: color,
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(this.overlayLine, {
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
color: color,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2342,9 +2366,7 @@ function MyController(hand) {
|
|||
this.actionID = null;
|
||||
var handJointIndex;
|
||||
if (this.ignoreIK) {
|
||||
handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
|
||||
"_CONTROLLER_RIGHTHAND" :
|
||||
"_CONTROLLER_LEFTHAND");
|
||||
handJointIndex = this.controllerJointIndex;
|
||||
} else {
|
||||
handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand");
|
||||
}
|
||||
|
@ -3055,9 +3077,7 @@ function MyController(hand) {
|
|||
return true;
|
||||
}
|
||||
|
||||
var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
|
||||
"_CONTROLLER_RIGHTHAND" :
|
||||
"_CONTROLLER_LEFTHAND");
|
||||
var controllerJointIndex = this.controllerJointIndex;
|
||||
if (props.parentJointIndex == controllerJointIndex) {
|
||||
return true;
|
||||
}
|
||||
|
@ -3083,9 +3103,7 @@ function MyController(hand) {
|
|||
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, handJointIndex));
|
||||
|
||||
// find children of faux controller joint
|
||||
var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ?
|
||||
"_CONTROLLER_RIGHTHAND" :
|
||||
"_CONTROLLER_LEFTHAND");
|
||||
var controllerJointIndex = this.controllerJointIndex;
|
||||
children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex));
|
||||
children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerJointIndex));
|
||||
|
||||
|
|
Loading…
Reference in a new issue