Skip to content

Commit

Permalink
Solving multiple shapes display order with new function addOrdered
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysterix committed May 1, 2014
1 parent 673f6eb commit d4fe4c1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions js/isomer.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ Isomer.prototype.add = function (item, baseColor) {
}
};

/**
* Adds an array of shapes to the scene, sorting their faces globally
* so that they are displayed in the right order
*
* Input is given as an array of {shape: yourShape, color: yourColor}
*/

Isomer.prototype.addOrdered = function (item) {
var Point = Isomer.Point;
var observer = new Point(-10, -10, 10);
var pathList = [];
var index = 0;

for (var i = 0; i < item.length; i++) {
for(var j = 0 ; j < item[i].shape.paths.length ; j++){
pathList[index] = {
path: item[i].shape.paths[j],
color: item[i].color,
distance: item[i].shape._pathDistances(item[i].shape.paths[j], observer)
};
index++;
}
}
pathList.sort(function(pathA, pathB){return (pathB.distance.averageDistance - pathA.distance.averageDistance)});

for (var i = 0 ; i < pathList.length ; i++) {
this._addPath(pathList[i].path, pathList[i].color);
}
};

/**
* Adds a path to the scene
Expand Down

0 comments on commit d4fe4c1

Please # to comment.