Skip to content

Various adjustments #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bd4822d
optionally pass in entity in event to enable specifying which entity …
InfiniteLee Feb 1, 2018
9b9c775
aframe master doesn't always have evt.detail
InfiniteLee Feb 22, 2018
f01f496
Merge branch 'master' into feature/set-grab-target
InfiniteLee Mar 13, 2018
0c956b8
optionally use world position when calculating hand distance for stre…
InfiniteLee Mar 14, 2018
c5be38e
fix quotes
InfiniteLee Mar 14, 2018
e7c7afa
Merge branch 'feature/stretchable-world-pos' into mr-social-client/ma…
InfiniteLee Mar 14, 2018
dcf2d5c
update dist
InfiniteLee Mar 14, 2018
be32bae
rename
InfiniteLee Mar 14, 2018
0df9e94
Merge branch 'feature/stretchable-world-pos' into mr-social-client/ma…
InfiniteLee Mar 14, 2018
24feda2
just use default
InfiniteLee Apr 17, 2018
7250b14
Merge branch 'feature/stretchable-world-pos' into mr-social-client/ma…
InfiniteLee Apr 17, 2018
369faf6
call emitCancelable so the grab-start event is properly fired on the …
InfiniteLee Apr 23, 2018
e4d91f4
Merge branch 'feature/set-grab-target' into mr-social-client/master
InfiniteLee Apr 23, 2018
c9eb93f
Use shared vectors and quaternions when calling getWorldPosition/Quat…
johnshaughnessy May 8, 2018
579024a
Merge pull request #1 from MozillaReality/grabbable-gc-fix
johnshaughnessy May 8, 2018
df3c055
activatable reaction component
InfiniteLee Jul 19, 2018
667560b
add property maxGrabBehavior to specify the behavior to follow when m…
InfiniteLee Jul 19, 2018
f8f9781
Merge branch 'master' into hubs/master
InfiniteLee Jul 19, 2018
a3b8461
Merge branch 'feature/activatable' into hubs/master
InfiniteLee Jul 19, 2018
bf839d4
Merge branch 'feature/max-grab-behavior' into hubs/master
InfiniteLee Jul 19, 2018
2b8c341
lint fixes
InfiniteLee Jul 19, 2018
2fc7697
Merge branch 'feature/max-grab-behavior' into hubs/master
InfiniteLee Jul 19, 2018
04aa99a
getting multiple to work correctly.
InfiniteLee Jul 20, 2018
a7e93b7
Merge branch 'feature/activatable' into hubs/master
InfiniteLee Jul 20, 2018
e979d1c
fixed and simplified the activatable component.
InfiniteLee Jul 20, 2018
6f1fdff
Merge branch 'feature/activatable' into hubs/master
InfiniteLee Jul 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 58 additions & 38 deletions dist/super-hands.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ AFRAME.registerComponent('super-hands', {
let carried = this.state.get(this.GRAB_EVENT);
this.dispatchMouseEventAll('mousedown', this.el);
this.gehClicking = new Set(this.hoverEls);
const detail = {
hand: this.el,
buttonEvent: evt
};
if (!carried) {
carried = this.findTarget(this.GRAB_EVENT, {
hand: this.el,
buttonEvent: evt
});
if (evt.detail && evt.detail.targetEntity && !this.emitCancelable(evt.detail.targetEntity, this.GRAB_EVENT, detail)) {
carried = evt.detail.targetEntity;
} else {
carried = this.findTarget(this.GRAB_EVENT, detail);
}
if (carried) {
this.state.set(this.GRAB_EVENT, carried);
this._unHover(carried);
Expand Down Expand Up @@ -844,25 +849,30 @@ AFRAME.registerComponent('grabbable', inherit(base, {
this.yFactor = (this.data.invert ? -1 : 1) * !this.data.suppressY;
},
tick: function () {
var entityPosition;
if (this.grabber) {
// reflect on z-axis to point in same direction as the laser
this.targetPosition.copy(this.grabDirection);
this.targetPosition.applyQuaternion(this.grabber.object3D.getWorldQuaternion()).setLength(this.grabDistance).add(this.grabber.object3D.getWorldPosition()).add(this.grabOffset);
if (this.deltaPositionIsValid) {
// relative position changes work better with nested entities
this.deltaPosition.sub(this.targetPosition);
entityPosition = this.el.getAttribute('position');
this.destPosition.x = entityPosition.x - this.deltaPosition.x * this.xFactor;
this.destPosition.y = entityPosition.y - this.deltaPosition.y * this.yFactor;
this.destPosition.z = entityPosition.z - this.deltaPosition.z * this.zFactor;
this.el.setAttribute('position', this.destPosition);
} else {
this.deltaPositionIsValid = true;
var q = new THREE.Quaternion();
var v = new THREE.Vector3();

return function () {
var entityPosition;
if (this.grabber) {
// reflect on z-axis to point in same direction as the laser
this.targetPosition.copy(this.grabDirection);
this.targetPosition.applyQuaternion(this.grabber.object3D.getWorldQuaternion(q)).setLength(this.grabDistance).add(this.grabber.object3D.getWorldPosition(v)).add(this.grabOffset);
if (this.deltaPositionIsValid) {
// relative position changes work better with nested entities
this.deltaPosition.sub(this.targetPosition);
entityPosition = this.el.getAttribute('position');
this.destPosition.x = entityPosition.x - this.deltaPosition.x * this.xFactor;
this.destPosition.y = entityPosition.y - this.deltaPosition.y * this.yFactor;
this.destPosition.z = entityPosition.z - this.deltaPosition.z * this.zFactor;
this.el.setAttribute('position', this.destPosition);
} else {
this.deltaPositionIsValid = true;
}
this.deltaPosition.copy(this.targetPosition);
}
this.deltaPosition.copy(this.targetPosition);
}
},
};
}(),
remove: function () {
this.el.removeEventListener(this.GRAB_EVENT, this.start);
this.el.removeEventListener(this.UNGRAB_EVENT, this.end);
Expand Down Expand Up @@ -913,19 +923,23 @@ AFRAME.registerComponent('grabbable', inherit(base, {
}
},
resetGrabber: function () {
let raycaster;
if (!this.grabber) {
return false;
}
raycaster = this.grabber.getAttribute('raycaster');
this.deltaPositionIsValid = false;
this.grabDistance = this.el.object3D.getWorldPosition().distanceTo(this.grabber.object3D.getWorldPosition());
if (raycaster) {
this.grabDirection = raycaster.direction;
this.grabOffset = raycaster.origin;
}
return true;
},
var objPos = new THREE.Vector3();
var grabPos = new THREE.Vector3();
return function () {
let raycaster;
if (!this.grabber) {
return false;
}
raycaster = this.grabber.getAttribute('raycaster');
this.deltaPositionIsValid = false;
this.grabDistance = this.el.object3D.getWorldPosition(objPos).distanceTo(this.grabber.object3D.getWorldPosition(grabPos));
if (raycaster) {
this.grabDirection = raycaster.direction;
this.grabOffset = raycaster.origin;
}
return true;
};
}(),
lostGrabber: function (evt) {
let i = this.grabbers.indexOf(evt.relatedTarget);
// if a queued, non-physics grabber leaves the collision zone, forget it
Expand Down Expand Up @@ -1075,7 +1089,8 @@ AFRAME.registerComponent('stretchable', inherit(base, {
schema: {
usePhysics: { default: 'ifavailable' },
invert: { default: false },
physicsUpdateRate: { default: 100 }
physicsUpdateRate: { default: 100 },
useWorldPosition: { default: false }
},
init: function () {
this.STRETCHED_STATE = 'stretched';
Expand All @@ -1102,8 +1117,13 @@ AFRAME.registerComponent('stretchable', inherit(base, {
return;
}
this.scale.copy(this.el.getAttribute('scale'));
this.handPos.copy(this.stretchers[0].getAttribute('position'));
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'));
if (this.data.useWorldPosition) {
this.stretchers[0].object3D.getWorldPosition(this.handPos);
this.stretchers[1].object3D.getWorldPosition(this.otherHandPos);
} else {
this.handPos.copy(this.stretchers[0].getAttribute('position'));
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'));
}
const currentStretch = this.handPos.distanceTo(this.otherHandPos);
let deltaStretch = 1;
if (this.previousStretch !== null && currentStretch !== 0) {
Expand Down
6 changes: 3 additions & 3 deletions dist/super-hands.min.js

Large diffs are not rendered by default.

66 changes: 62 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require('./reaction_components/drag-droppable.js')
require('./reaction_components/draggable.js')
require('./reaction_components/droppable.js')
require('./reaction_components/clickable.js')
require('./reaction_components/activatable.js')

/**
* Super Hands component for A-Frame.
Expand Down Expand Up @@ -58,6 +59,18 @@ AFRAME.registerComponent('super-hands', {
'pointdown', 'thumbdown', 'pointingend', 'pistolend',
'thumbstickup', 'mouseup', 'touchend']
},
activateStartButtons: {
default: ['gripdown', 'trackpaddown', 'triggerdown', 'gripclose',
'abuttondown', 'bbuttondown', 'xbuttondown', 'ybuttondown',
'pointup', 'thumbup', 'pointingstart', 'pistolstart',
'thumbstickdown', 'mousedown', 'touchstart']
},
activateEndButtons: {
default: ['gripup', 'trackpadup', 'triggerup', 'gripopen',
'abuttonup', 'bbuttonup', 'xbuttonup', 'ybuttonup',
'pointdown', 'thumbdown', 'pointingend', 'pistolend',
'thumbstickup', 'mouseup', 'touchend']
},
interval: { default: 0 }
},

Expand All @@ -82,6 +95,8 @@ AFRAME.registerComponent('super-hands', {
this.DRAGOVER_EVENT = 'dragover-start'
this.UNDRAGOVER_EVENT = 'dragover-end'
this.DRAGDROP_EVENT = 'drag-drop'
this.ACTIVATE_EVENT = 'activate-start'
this.DEACTIVATE_EVENT = 'activate-end'

// links to other systems/components
this.otherSuperHand = null
Expand All @@ -106,6 +121,8 @@ AFRAME.registerComponent('super-hands', {
this.onStretchEndButton = this.onStretchEndButton.bind(this)
this.onDragDropStartButton = this.onDragDropStartButton.bind(this)
this.onDragDropEndButton = this.onDragDropEndButton.bind(this)
this.onActivateStartButton = this.onActivateStartButton.bind(this)
this.onActivateEndButton = this.onActivateEndButton.bind(this)
this.system.registerMe(this)
},

Expand Down Expand Up @@ -168,11 +185,16 @@ AFRAME.registerComponent('super-hands', {
let carried = this.state.get(this.GRAB_EVENT)
this.dispatchMouseEventAll('mousedown', this.el)
this.gehClicking = new Set(this.hoverEls)
const detail = {
hand: this.el,
buttonEvent: evt
}
if (!carried) {
carried = this.findTarget(this.GRAB_EVENT, {
hand: this.el,
buttonEvent: evt
})
if (evt.detail && evt.detail.targetEntity && !this.emitCancelable(evt.detail.targetEntity, this.GRAB_EVENT, detail)) {
carried = evt.detail.targetEntity
} else {
carried = this.findTarget(this.GRAB_EVENT, detail)
}
if (carried) {
this.state.set(this.GRAB_EVENT, carried)
this._unHover(carried)
Expand Down Expand Up @@ -281,6 +303,30 @@ AFRAME.registerComponent('super-hands', {
}
}
},
onActivateStartButton: function (evt) {
const carried = this.state.get(this.GRAB_EVENT)
let activated = this.state.get(this.ACTIVATE_EVENT)
if (carried) {
if (!activated && !this.emitCancelable(carried, this.ACTIVATE_EVENT, {hand: this.el, buttonEvent: evt})) {
activated = this.state.get(this.ACTIVATE_EVENT)
}
if (activated) {
this.state.set(this.ACTIVATE_EVENT, activated)
}
}
},
onActivateEndButton: function (evt) {
const carried = this.state.get(this.GRAB_EVENT)
let deactivated = this.state.get(this.DEACTIVATE_EVENT)
if (carried) {
if (!deactivated && !this.emitCancelable(carried, this.DEACTIVATE_EVENT, {hand: this.el, buttonEvent: evt})) {
deactivated = this.state.get(this.DEACTIVATE_EVENT)
}
if (deactivated) {
this.state.set(this.DEACTIVATE_EVENT, deactivated)
}
}
},
processHitEl: function (hitEl, intersection) {
const dist = intersection && intersection.distance
const sects = this.hoverElsIntersections
Expand Down Expand Up @@ -434,6 +480,9 @@ AFRAME.registerComponent('super-hands', {
this.data.dragDropStartButtons.forEach(b => {
this.el.addEventListener(b, this.onDragDropStartButton)
})
this.data.activateStartButtons.forEach(b => {
this.el.addEventListener(b, this.onActivateStartButton)
})
this.data.dragDropEndButtons.forEach(b => {
this.el.addEventListener(b, this.onDragDropEndButton)
})
Expand All @@ -443,6 +492,9 @@ AFRAME.registerComponent('super-hands', {
this.data.grabEndButtons.forEach(b => {
this.el.addEventListener(b, this.onGrabEndButton)
})
this.data.activateEndButtons.forEach(b => {
this.el.addEventListener(b, this.onActivateEndButton)
})
},
unRegisterListeners: function (data) {
data = data || this.data
Expand All @@ -463,6 +515,9 @@ AFRAME.registerComponent('super-hands', {
data.stretchStartButtons.forEach(b => {
this.el.removeEventListener(b, this.onStretchStartButton)
})
data.activateStartButtons.forEach(b => {
this.el.removeEventListener(b, this.onActivateStartButton)
})
data.stretchEndButtons.forEach(b => {
this.el.removeEventListener(b, this.onStretchEndButton)
})
Expand All @@ -472,6 +527,9 @@ AFRAME.registerComponent('super-hands', {
data.dragDropEndButtons.forEach(b => {
this.el.removeEventListener(b, this.onDragDropEndButton)
})
data.activateEndButtons.forEach(b => {
this.el.removeEventListener(b, this.onActivateEndButton)
})
},
emitCancelable: function (target, name, detail) {
var data, evt
Expand Down
38 changes: 38 additions & 0 deletions reaction_components/activatable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* global AFRAME */
const inherit = AFRAME.utils.extendDeep
const buttonCore = require('./prototypes/buttons-proto.js')

AFRAME.registerComponent('activatable', inherit({}, buttonCore, {
multiple: true,
schema: {
buttonStartEvent: {default: ''},
buttonEndEvent: {default: ''},
activatedState: {default: 'activated'}
},
init: function () {
this.ACTIVATE_EVENT = 'activate-start'
this.DEACTIVATE_EVENT = 'activate-end'

this.activateStart = this.activateStart.bind(this)
this.activateEnd = this.activateEnd.bind(this)

this.el.addEventListener(this.ACTIVATE_EVENT, this.activateStart)
this.el.addEventListener(this.DEACTIVATE_EVENT, this.activateEnd)
},
remove: function () {
this.el.removeEventListener(this.ACTIVATE_EVENT, this.activateStart)
this.el.removeEventListener(this.DEACTIVATE_EVENT, this.activateEnd)
},
activateStart: function (evt) {
if (evt.defaultPrevented || !this.startButtonOk(evt)) { return }
if (evt.detail.buttonEvent.type !== this.data.buttonStartEvent) { return }
this.el.addState(this.data.activatedState)
if (evt.preventDefault) { evt.preventDefault() }
},
activateEnd: function (evt) {
if (evt.defaultPrevented || !this.endButtonOk(evt)) { return }
if (evt.detail.buttonEvent.type !== this.data.buttonEndEvent) { return }
this.el.removeState(this.data.activatedState)
if (evt.preventDefault) { evt.preventDefault() }
}
}))
Loading