Skip to content
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

Hand painting #275

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!-- camera -->
<a-entity id="acamera" camera></a-entity>
<!-- hand controls -->
<a-entity id="left-hand"
<!-- <a-entity id="left-hand"
brush
paint-controls="hand: left"
blink-controls="cameraRig: #cameraRig; startEvents: aim; endEvents: teleport; hitCylinderColor: #ff3468; curveHitColor: #ff3468; curveMissColor: #333333; curveLineWidth: 0.01; hitEntity: #hitEntityLeft"
Expand Down Expand Up @@ -129,8 +129,10 @@
rotation="-90 0 0">
</a-entity>
</a-entity>
</a-entity>
<a-entity id="right-hand"
</a-entity> -->
<!-- <a-entity id="leftHand" hand-tracking-controls="hand: left; modelColor: purple" brush paint-controls="hand: left" ui></a-entity> -->
<a-entity id="rightHand" hand-tracking-controls="hand: right; modelColor: purple" right-hand-log brush paint-controls="hand: right" ui></a-entity>
<!-- <a-entity id="right-hand"
brush
paint-controls="hand: right"
blink-controls="cameraRig: #cameraRig; startEvents: aim; endEvents: teleport; hitCylinderColor: #ff3468; curveHitColor: #ff3468; curveMissColor: #333333; curveLineWidth: 0.01; hitEntity: #hitEntityRight"
Expand Down Expand Up @@ -206,7 +208,7 @@
rotation="-90 0 0">
</a-entity>
</a-entity>
</a-entity>
</a-entity> -->
</a-entity>
</a-scene>
<a href="https://aframe.io/a-painter/"><div id="apainter-logo" class="hidden"></div><div id="apainter-author" style="display:none" class="hidden">authorname</div></a>
Expand Down
43 changes: 42 additions & 1 deletion src/components/brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ AFRAME.registerComponent('brush', {
this.model = this.el.getObject3D('mesh');
this.drawing = false;

this.self = this;

var self = this;

this.el.addEventListener('undo', function(evt) {
Expand All @@ -34,6 +36,34 @@ AFRAME.registerComponent('brush', {
document.getElementById('ui_undo').play();
});

console.log('system is');
console.log(this.system);
console.log('el is');
console.log(this);
console.log('obj is');
console.log(this.obj);

this.el.addEventListener('paint-hand-start', function (evt) {
// console.log(self.el.components['hand-tracking-controls'].indexTipPosition);
// console.log(this.components['hand-tracking-controls'].indexTipPosition);
if (!self.active) {
console.log('starting stroke');
self.startNewStroke();
self.active = true;
}
this.hand = 'right';
});

this.el.addEventListener('paint-hand-end', function (evt) {
if (self.active) {
self.previousEntity = self.currentEntity;
self.currentStroke = null;
}
self.active = false;
this.hand = 'right';
console.log('ending stroke');
});

this.el.addEventListener('paint', function (evt) {
if (!self.data.enabled) { return; }
// Trigger
Expand Down Expand Up @@ -72,9 +102,20 @@ AFRAME.registerComponent('brush', {

return function tick (time, delta) {
if (this.currentStroke && this.active) {
// console.log('wutbegin');
// console.log(this);
// console.log(this.el.components['hand-tracking-controls'].indexTipPosition);
// console.log('wutend');

const lol = this.el.components['hand-tracking-controls'].indexTipPosition.clone();
console.log(lol);
this.obj.matrixWorld.decompose(position, rotation, scale);
console.log(lol);
position = lol;

var pointerPosition = this.system.getPointerPosition(position, rotation, this.hand);
this.currentStroke.addPoint(position, rotation, pointerPosition, this.sizeModifier, time);
//console.log(pointerPosition);
this.currentStroke.addPoint(position, rotation, pointerPosition, 3.0, time);
}
};
})(),
Expand Down
2 changes: 2 additions & 0 deletions src/components/paint-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ AFRAME.registerComponent('paint-controls', {
});

el.addEventListener('controllerconnected', function (evt) {
console.log(evt);

var controllerName = evt.detail.name;
var hand = evt.detail.component.data.hand;

Expand Down
9 changes: 8 additions & 1 deletion src/systems/brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,14 @@ AFRAME.registerSystem('brush', {
right: new THREE.Vector3(0, 0, 1),
},
mult: -.12
}
},
'hand-tracking-controls': {
vec: {
left: new THREE.Vector3(-2, 0, 2.8),
right: new THREE.Vector3(2, 0, 2.8)
},
mult: -0.025
},
};

return function getPointerPosition (position, orientation, hand) {
Expand Down
9 changes: 7 additions & 2 deletions src/systems/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ AFRAME.registerSystem('painter', {
mappings: {
painting: {
common: {
'grip.down': 'undo',
'trigger.changed': 'paint'
'grip.changed': 'paint',
'trigger.down': 'undo'
},

'hand-tracking-controls': {
'pinchmoved': 'paint-hand-start',
'pinchended': 'paint-hand-end',
},

'vive-controls': {
Expand Down