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

StraightEdge brush #174

Open
wants to merge 2 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
Binary file added brushes/thumb_straightedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/brushes/straightedge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* globals AFRAME THREE */
AFRAME.registerBrush('straightedge',
{
init: function (color, width) {
this.material = new THREE.LineBasicMaterial({
color: this.data.color,
linewidth: 15,
side: THREE.DoubleSide
});
this.geometry = new THREE.BufferGeometry();
this.positions = new Float32Array(2 * 3);
this.geometry.addAttribute('position', new THREE.BufferAttribute(this.positions, 3));
this.line = new THREE.Line(this.geometry, this.material)
this.line.frustumCulled = false;
this.object3D.add(this.line);
},

addPoint: function (position, orientation, pointerPosition, pressure, timestamp) {
this.material.linewidth = this.data.size * 100

if (this.data.numPoints == 0) {
this.positions[0] = pointerPosition.x;
this.positions[1] = pointerPosition.y;
this.positions[2] = pointerPosition.z;
}

// Always set the second position, even when its the first point,
// otherwise there will be a quick line to 0,0,0 before the second point
// is added.
this.positions[3] = pointerPosition.x;
this.positions[4] = pointerPosition.y;
this.positions[5] = pointerPosition.z;

this.geometry.attributes.position.needsUpdate = true
return true;
}
},
{thumbnail: 'brushes/thumb_straightedge.png', spacing: 0.01}
);
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ require('./brushes/stamp.js');
require('./brushes/spheres.js');
require('./brushes/cubes.js');
require('./brushes/rainbow.js');
require('./brushes/straightedge.js');