Skip to content

Commit

Permalink
ENH: Add star geometry to shapes tab (#669)
Browse files Browse the repository at this point in the history
Fixes #656
  • Loading branch information
ElDeveloper authored and antgonza committed Apr 20, 2018
1 parent 556247d commit 41268ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 33 additions & 2 deletions emperor/support_files/js/shapes.js
Expand Up @@ -5,9 +5,10 @@ define(['jquery', 'three', 'underscore'], function($, THREE, _) {

var SPHERE = 'Sphere', SQUARE = 'Square', CONE = 'Cone',
ICOSAHEDRON = 'Icosahedron', CYLINDER = 'Cylinder',
OCTAHEDRON = 'Diamond', RING = 'Ring';
OCTAHEDRON = 'Diamond', RING = 'Ring', STAR = 'Star';

var shapes = [SPHERE, OCTAHEDRON, CONE, CYLINDER, RING, SQUARE, ICOSAHEDRON];
var shapes = [SPHERE, OCTAHEDRON, CONE, CYLINDER, RING, SQUARE, ICOSAHEDRON,
STAR];

/**
*
Expand Down Expand Up @@ -54,6 +55,8 @@ define(['jquery', 'three', 'underscore'], function($, THREE, _) {
geom = new THREE.RingGeometry(factor / 1.618033, factor);
geom.rotateX(0.3);
return geom;
case STAR:
return StarGeometry(factor * 0.5);
case CYLINDER:
return new THREE.CylinderGeometry(factor, factor, 2 * factor, 10);
default:
Expand All @@ -66,6 +69,34 @@ define(['jquery', 'three', 'underscore'], function($, THREE, _) {
$shapesDropdown.append(new Option(shape, shape));
});

/**
* Create a star with 6 points.
*
* This code was adapted from:
* https://threejs.org/examples/#webgl_geometry_extrude_shapes
*
* @param {Float} scale The scale to apply to the geometry.
* @return {THREE.ShapeGeometry} The star geometry.
*
*/
function StarGeometry(scale) {
var pts = [], numPts = 6, l, a, shape, geometry;

for (var i = 0; i < numPts * 2; i++) {
l = i % 2 == 1 ? 1 : 2;
a = i / numPts * Math.PI;

pts.push(new THREE.Vector2(Math.cos(a) * l, Math.sin(a) * l));
}

shape = new THREE.Shape(pts);
geometry = new THREE.ShapeGeometry(shape);

geometry.scale(scale, scale, scale);
geometry.rotateX(0.3);
return geometry;
}

return {$shapesDropdown: $shapesDropdown, getGeometry: getGeometry,
shapes: shapes};
});
2 changes: 1 addition & 1 deletion tests/javascript_tests/test_shape_controller.js
Expand Up @@ -18,7 +18,7 @@ requirejs([
setup: function() {
// setup function
this.shapesAvailable = ['Sphere', 'Diamond', 'Cone', 'Cylinder',
'Ring', 'Square', 'Icosahedron'];
'Ring', 'Square', 'Icosahedron', 'Star'];
this.sharedDecompositionViewDict = {};

// setup function
Expand Down

0 comments on commit 41268ab

Please sign in to comment.