Draw attach points as if they were equip-hotspots

This commit is contained in:
Anthony J. Thibault 2016-06-21 17:36:36 -07:00
parent 4f71f621f7
commit 2a82dddc2b
2 changed files with 53 additions and 4 deletions

View file

@ -10,9 +10,10 @@
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, Reticle, Messages, setEntityCustomData, getEntityCustomData, vec3toStr */ /*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, Reticle, Messages, setEntityCustomData, getEntityCustomData, vec3toStr, Xform */
Script.include("/~/system/libraries/utils.js"); Script.include("/~/system/libraries/utils.js");
Script.include("../libraries/Xform.js");
// //
// add lines where the hand ray picking is happening // add lines where the hand ray picking is happening
@ -879,21 +880,29 @@ function MyController(hand) {
var entities = Entities.findEntities(MyAvatar.position, HOTSPOT_DRAW_DISTANCE); var entities = Entities.findEntities(MyAvatar.position, HOTSPOT_DRAW_DISTANCE);
var i, l = entities.length; var i, l = entities.length;
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
var grabProps = Entities.getEntityProperties(entities[i], GRABBABLE_PROPERTIES); var props = Entities.getEntityProperties(entities[i], GRABBABLE_PROPERTIES);
// does this entity have an attach point? // does this entity have an attach point?
var wearableData = getEntityCustomData("wearable", entities[i], undefined); var wearableData = getEntityCustomData("wearable", entities[i], undefined);
if (wearableData && wearableData.joints) { if (wearableData && wearableData.joints) {
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"; var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
if (wearableData.joints[handJointName]) { if (wearableData.joints[handJointName]) {
var handOffsetPos = wearableData.joints[handJointName][0];
var handOffsetRot = wearableData.joints[handJointName][1];
var handOffsetXform = new Xform(handOffsetRot, handOffsetPos);
var objectXform = new Xform(props.rotation, props.position);
var overlayXform = Xform.mul(objectXform, handOffsetXform.inv());
// draw the hotspot // draw the hotspot
this.equipHotspotOverlays.push(Overlays.addOverlay("sphere", { this.equipHotspotOverlays.push(Overlays.addOverlay("sphere", {
position: grabProps.position, rotation: overlayXform.rot,
position: overlayXform.pos,
size: 0.2, size: 0.2,
color: { red: 90, green: 255, blue: 90 }, color: { red: 90, green: 255, blue: 90 },
alpha: 0.7, alpha: 0.7,
solid: true, solid: true,
visible: true, visible: true,
ignoreRayIntersection: false, ignoreRayIntersection: true,
drawInFront: false drawInFront: false
})); }));
} }

View file

@ -0,0 +1,40 @@
//
// Created by Anthony J. Thibault on 2016/06/21
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// ctor
Xform = function(rot, pos) {
this.rot = rot;
this.pos = pos;
}
Xform.ident = function() {
return new Xform({x: 0, y: 0, z: 0, w: 1}, {x: 0, y: 0, z: 0});
};
Xform.mul = function(lhs, rhs) {
var rot = Quat.multiply(lhs.rot, rhs.rot);
var pos = Vec3.sum(lhs.pos, Vec3.multiplyQbyV(lhs.rot, rhs.pos));
return new Xform(rot, pos);
};
Xform.prototype.inv = function() {
var invRot = Quat.inverse(this.rot);
var invPos = Vec3.multiply(-1, this.pos);
return new Xform(invRot, Vec3.multiplyQbyV(invRot, invPos));
};
Xform.prototype.mirrorX = function() {
return new Xform({x: this.rot.x, y: -this.rot.y, z: -this.rot.z, w: this.rot.w},
{x: -this.pos.x, y: this.pos.y, z: this.pos.z});
};
Xform.prototype.toString = function() {
var rot = this.rot;
var pos = this.pos;
return "Xform rot = (" + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "), pos = (" + pos.x + ", " + pos.y + ", " + pos.z + ")";
};