Skip to content

Commit f576550

Browse files
Logitech MX Ink improvements (#5756)
* Allow stylus visualization when in AR mode (i.e. Meta Quest passthrough / mixed reality). * Update Painter showcase example to support brush stroke size variation based on button/tip pressure applied. * Avoid directly modifying brush' data.size, use a sizeFactor variable instead.
1 parent 9ff61ff commit f576550

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

examples/showcase/painter/components/brush.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
AFRAME.registerComponent('brush', {
33
schema: {
44
color: {type: 'color', default: '#ef2d5e'},
5-
size: {default: 0.01, min: 0.001, max: 0.3},
5+
size: {default: 0.01, min: 0.001, max: 1.0},
6+
pressureMultiplier: {default: 5.0, min: 0.01, max: 10.0},
67
enabled: {default: true},
78
hand: {default: 'left'}
89
},
@@ -15,6 +16,7 @@ AFRAME.registerComponent('brush', {
1516
this.stroke = null;
1617
this.buttonsDown = 0;
1718
this.touches = 0;
19+
this.sizeFactor = 1.0;
1820

1921
this.onTouchStarted = this.onTouchStarted.bind(this);
2022
el.addEventListener('tiptouchstart', this.onTouchStarted);
@@ -26,6 +28,9 @@ AFRAME.registerComponent('brush', {
2628
this.onButtonUp = this.onButtonUp.bind(this);
2729
el.addEventListener('buttonup', this.onButtonUp);
2830

31+
this.onButtonChanged = this.onButtonChanged.bind(this);
32+
el.addEventListener('buttonchanged', this.onButtonChanged);
33+
2934
this.onControllerConnected = this.onControllerConnected.bind(this);
3035
el.addEventListener('controllerconnected', this.onControllerConnected);
3136

@@ -68,6 +73,16 @@ AFRAME.registerComponent('brush', {
6873
this.painting = false;
6974
},
7075

76+
onButtonChanged: function (evt) {
77+
if (!this.data.enabled) { return; }
78+
if (!this.painting) { return; }
79+
if (evt.detail.state.value === 1) {
80+
this.sizeFactor = 1.0;
81+
} else {
82+
this.sizeFactor = evt.detail.state.value * this.data.pressureMultiplier;
83+
}
84+
},
85+
7186
tick: (function () {
7287
var position = new THREE.Vector3();
7388
var rotation = new THREE.Quaternion();
@@ -84,12 +99,13 @@ AFRAME.registerComponent('brush', {
8499
}
85100
this.el.object3D.matrixWorld.decompose(position, rotation, scale);
86101
var pointerPosition = this.getPointerPosition(position, rotation);
102+
this.stroke.setSize(this.data.size * this.sizeFactor);
87103
this.stroke.addPoint(position, rotation, pointerPosition);
88104
};
89105
})(),
90106

91107
startNewStroke: function () {
92-
this.stroke = this.system.addNewStroke(this.color, this.data.size);
108+
this.stroke = this.system.addNewStroke(this.color, this.data.size * this.sizeFactor);
93109
},
94110

95111
getPointerPosition: (function () {

examples/showcase/painter/stroke-geometry.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ StrokeGeometry.prototype = {
9494
this.currentGeometry.attributes.normal.setXYZ(this.indices.normal++, x, y, z);
9595
},
9696

97+
setSize: (function () {
98+
return function (size) {
99+
if (this.size === size) {
100+
return;
101+
}
102+
this.size = size;
103+
};
104+
})(),
105+
97106
addPoint: (function () {
98107
var direction = new THREE.Vector3();
99108
var vertexA = new THREE.Vector3();

src/components/logitech-mx-ink-controls.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export var Component = registerComponent('logitech-mx-ink-controls', {
120120
var controllerObject3D = this.controllerObject3D;
121121
if (!this.data.model) { return; }
122122
if (controllerObject3D) {
123-
controllerObject3D.visible = this.el.sceneEl.is('vr-mode');
123+
controllerObject3D.visible = this.el.sceneEl.is('vr-mode') || this.el.sceneEl.is('ar-mode');
124124
this.el.setObject3D('mesh', controllerObject3D);
125125
return;
126126
}
@@ -163,7 +163,7 @@ export var Component = registerComponent('logitech-mx-ink-controls', {
163163
});
164164

165165
this.controllerObject3D = this.el.getObject3D('mesh');
166-
this.controllerObject3D.visible = this.el.sceneEl.is('vr-mode');
166+
this.controllerObject3D.visible = this.el.sceneEl.is('vr-mode') || this.el.sceneEl.is('ar-mode');
167167
},
168168

169169
onAxisMoved: function (evt) {

0 commit comments

Comments
 (0)