-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject3D.jsx
51 lines (47 loc) · 1.34 KB
/
Object3D.jsx
1
function Object3D(polylist){ this.polys = polylist; this.polycount = this.polys.length;}Object3D.prototype.applyTransform = function(m3){ app.scriptPreferences.enableRedraw = false; for(var i = 0; i < this.polycount; i++){ var poly = this.polys[i]; poly.applyTransform(m3); poly.draw(); } this.polys.sort(function(poly1, poly2){ var center1 = poly1.minZ(); var center2 = poly2.minZ(); if(center1 > center2){ return -1 } if(center2 > center1){ return 1; } return 0; }); for(var i = 0; i < this.polycount; i++){ var poly = this.polys[i]; poly.shape.bringToFront(); } for(var i = 0; i < this.polycount; i++){ var poly = this.polys[i]; poly.line && poly.line.bringToFront(); } app.scriptPreferences.enableRedraw = true;}Object3D.prototype.getCenter = function(){ var total = 0; var x = 0; var y = 0; var z = 0; for(var i = 0; i < this.polycount; i++){ var poly = this.polys[i]; var center = poly.getCenter(); x += center.x; y += center.y; z += center.z; total ++; } return new Vector3D(x/total, y/total, z/total); }