//>>built
define("dojox/gfx3d/object","dojo/_base/array dojo/_base/declare dojo/_base/lang dojox/gfx dojox/gfx/matrix ./_base ./scheduler ./gradient ./vector ./matrix ./lighting".split(" "),function(k,q,p,r,u,f,w,x,t,h,y){var v=w.scheduler;q("dojox.gfx3d.Object",null,{constructor:function(){this.shape=this.fillStyle=this.strokeStyle=this.parent=this.renderer=this.cache=this.matrix=this.object=null},setObject:function(a){this.object=r.makeParameters(this.object,a);return this},setTransform:function(a){this.matrix=
h.clone(a?h.normalize(a):f.identity,!0);return this},applyRightTransform:function(a){return a?this.setTransform([this.matrix,a]):this},applyLeftTransform:function(a){return a?this.setTransform([a,this.matrix]):this},applyTransform:function(a){return a?this.setTransform([this.matrix,a]):this},setFill:function(a){this.fillStyle=a;return this},setStroke:function(a){this.strokeStyle=a;return this},toStdFill:function(a,b){return this.fillStyle&&"undefined"!=typeof this.fillStyle.type?a[this.fillStyle.type](b,
this.fillStyle.finish,this.fillStyle.color):this.fillStyle},invalidate:function(){this.renderer.addTodo(this)},destroy:function(){if(this.shape){var a=this.shape.getParent();a&&a.remove(this.shape);this.shape=null}},render:function(a){throw"Pure virtual function, not implemented";},draw:function(a){throw"Pure virtual function, not implemented";},getZOrder:function(){return 0},getOutline:function(){return null}});q("dojox.gfx3d.Scene",f.Object,{constructor:function(){this.objects=[];this.todos=[];
this.schedule=v.zOrder;this._draw=f.drawer.conservative},setFill:function(a){this.fillStyle=a;k.forEach(this.objects,function(b){b.setFill(a)});return this},setStroke:function(a){this.strokeStyle=a;k.forEach(this.objects,function(b){b.setStroke(a)});return this},render:function(a,b){var c=h.multiply(a,this.matrix);b&&(this.todos=this.objects);k.forEach(this.todos,function(d){d.render(c,b)})},draw:function(a){this.objects=this.schedule(this.objects);this._draw(this.todos,this.objects,this.renderer)},
addTodo:function(a){k.every(this.todos,function(b){return b!=a})&&(this.todos.push(a),this.invalidate())},invalidate:function(){this.parent.addTodo(this)},getZOrder:function(){var a=0;k.forEach(this.objects,function(b){a+=b.getZOrder()});return 1<this.objects.length?a/this.objects.length:0}});q("dojox.gfx3d.Edges",f.Object,{constructor:function(){this.object=p.clone(f.defaultEdges)},setObject:function(a,b){this.object=r.makeParameters(this.object,a instanceof Array?{points:a,style:b}:a);return this},
getZOrder:function(){var a=0;k.forEach(this.cache,function(b){a+=b.z});return 1<this.cache.length?a/this.cache.length:0},render:function(a){var b=h.multiply(a,this.matrix);this.cache=k.map(this.object.points,function(c){return h.multiplyPoint(b,c)})},draw:function(){var a=this.cache;this.shape?this.shape.setShape(""):this.shape=this.renderer.createPath();var b=this.shape.setAbsoluteMode("absolute");if("strip"==this.object.style||"loop"==this.object.style)b.moveTo(a[0].x,a[0].y),k.forEach(a.slice(1),
function(d){b.lineTo(d.x,d.y)}),"loop"==this.object.style&&b.closePath();else for(var c=0;c<this.cache.length;)b.moveTo(a[c].x,a[c].y),c++,b.lineTo(a[c].x,a[c].y),c++;b.setStroke(this.strokeStyle)}});q("dojox.gfx3d.Orbit",f.Object,{constructor:function(){this.object=p.clone(f.defaultOrbit)},render:function(a){var b=h.multiply(a,this.matrix);a=[0,Math.PI/4,Math.PI/3];var c=h.multiplyPoint(b,this.object.center),d=k.map(a,function(l){return{x:this.center.x+this.radius*Math.cos(l),y:this.center.y+this.radius*
Math.sin(l),z:this.center.z}},this.object);d=k.map(d,function(l){return h.multiplyPoint(b,l)});a=t.normalize(d);d=k.map(d,function(l){return t.substract(l,c)});var e={xx:d[0].x*d[0].y,xy:d[0].y*d[0].y,xz:1,yx:d[1].x*d[1].y,yy:d[1].y*d[1].y,yz:1,zx:d[2].x*d[2].y,zy:d[2].y*d[2].y,zz:1,dx:0,dy:0,dz:0},g=k.map(d,function(l){return-Math.pow(l.x,2)});e=h.multiplyPoint(h.invert(e),g[0],g[1],g[2]);var m=Math.atan2(e.x,1-e.y)/2,n=k.map(d,function(l){return u.multiplyPoint(u.rotate(-m),l.x,l.y)});d=Math.pow(n[0].x,
2);e=Math.pow(n[0].y,2);g=Math.pow(n[1].x,2);n=Math.pow(n[1].y,2);this.cache={cx:c.x,cy:c.y,rx:Math.sqrt((d*n-e*g)/(n-e)),ry:Math.sqrt((d*n-e*g)/(d-g)),theta:m,normal:a}},draw:function(a){this.shape?this.shape.setShape(this.cache):this.shape=this.renderer.createEllipse(this.cache);this.shape.applyTransform(u.rotateAt(this.cache.theta,this.cache.cx,this.cache.cy)).setStroke(this.strokeStyle).setFill(this.toStdFill(a,this.cache.normal))}});q("dojox.gfx3d.Path3d",f.Object,{constructor:function(){this.object=
p.clone(f.defaultPath3d);this.segments=[];this.absolute=!0;this.last={};this.path=""},_collectArgs:function(a,b){for(var c=0;c<b.length;++c){var d=b[c];"boolean"==typeof d?a.push(d?1:0):"number"==typeof d?a.push(d):d instanceof Array?this._collectArgs(a,d):"x"in d&&"y"in d&&(a.push(d.x),a.push(d.y))}},_validSegments:{m:3,l:3,z:0},_pushSegment:function(a,b){var c=this._validSegments[a.toLowerCase()];"number"==typeof c&&(c?b.length>=c&&(c={action:a,args:b.slice(0,b.length-b.length%c)},this.segments.push(c)):
(c={action:a,args:[]},this.segments.push(c)))},moveTo:function(){var a=[];this._collectArgs(a,arguments);this._pushSegment(this.absolute?"M":"m",a);return this},lineTo:function(){var a=[];this._collectArgs(a,arguments);this._pushSegment(this.absolute?"L":"l",a);return this},closePath:function(){this._pushSegment("Z",[]);return this},render:function(a){var b=h.multiply(a,this.matrix),c="",d=this._validSegments;k.forEach(this.segments,function(e){c+=e.action;for(var g=0;g<e.args.length;g+=d[e.action.toLowerCase()]){var m=
h.multiplyPoint(b,e.args[g],e.args[g+1],e.args[g+2]);c+=" "+m.x+" "+m.y}});this.cache=c},_draw:function(){return this.parent.createPath(this.cache)}});q("dojox.gfx3d.Triangles",f.Object,{constructor:function(){this.object=p.clone(f.defaultTriangles)},setObject:function(a,b){this.object=a instanceof Array?r.makeParameters(this.object,{points:a,style:b}):r.makeParameters(this.object,a);return this},render:function(a){var b=h.multiply(a,this.matrix);a=k.map(this.object.points,function(g){return h.multiplyPoint(b,
g)});this.cache=[];var c=a.slice(0,2),d=a[0];if("strip"==this.object.style)k.forEach(a.slice(2),function(g){c.push(g);c.push(c[0]);this.cache.push(c);c=c.slice(1,3)},this);else if("fan"==this.object.style)k.forEach(a.slice(2),function(g){c.push(g);c.push(d);this.cache.push(c);c=[d,g]},this);else for(var e=0;e<a.length;)this.cache.push([a[e],a[e+1],a[e+2],a[e]]),e+=3},draw:function(a){this.cache=v.bsp(this.cache,function(b){return b});this.shape?this.shape.clear():this.shape=this.renderer.createGroup();
k.forEach(this.cache,function(b){this.shape.createPolyline(b).setStroke(this.strokeStyle).setFill(this.toStdFill(a,t.normalize(b)))},this)},getZOrder:function(){var a=0;k.forEach(this.cache,function(b){a+=(b[0].z+b[1].z+b[2].z)/3});return 1<this.cache.length?a/this.cache.length:0}});q("dojox.gfx3d.Quads",f.Object,{constructor:function(){this.object=p.clone(f.defaultQuads)},setObject:function(a,b){this.object=r.makeParameters(this.object,a instanceof Array?{points:a,style:b}:a);return this},render:function(a){var b=
h.multiply(a,this.matrix),c=k.map(this.object.points,function(e){return h.multiplyPoint(b,e)});this.cache=[];if("strip"==this.object.style){var d=c.slice(0,2);for(a=2;a<c.length;)d=d.concat([c[a],c[a+1],d[0]]),this.cache.push(d),d=d.slice(2,4),a+=2}else for(a=0;a<c.length;)this.cache.push([c[a],c[a+1],c[a+2],c[a+3],c[a]]),a+=4},draw:function(a){this.cache=f.scheduler.bsp(this.cache,function(c){return c});this.shape?this.shape.clear():this.shape=this.renderer.createGroup();for(var b=0;b<this.cache.length;b++)this.shape.createPolyline(this.cache[b]).setStroke(this.strokeStyle).setFill(this.toStdFill(a,
t.normalize(this.cache[b])))},getZOrder:function(){for(var a=0,b=0;b<this.cache.length;b++){var c=this.cache[b];a+=(c[0].z+c[1].z+c[2].z+c[3].z)/4}return 1<this.cache.length?a/this.cache.length:0}});q("dojox.gfx3d.Polygon",f.Object,{constructor:function(){this.object=p.clone(f.defaultPolygon)},setObject:function(a){this.object=r.makeParameters(this.object,a instanceof Array?{path:a}:a);return this},render:function(a){var b=h.multiply(a,this.matrix);this.cache=k.map(this.object.path,function(c){return h.multiplyPoint(b,
c)});this.cache.push(this.cache[0])},draw:function(a){this.shape?this.shape.setShape({points:this.cache}):this.shape=this.renderer.createPolyline({points:this.cache});this.shape.setStroke(this.strokeStyle).setFill(this.toStdFill(a,h.normalize(this.cache)))},getZOrder:function(){for(var a=0,b=0;b<this.cache.length;b++)a+=this.cache[b].z;return 1<this.cache.length?a/this.cache.length:0},getOutline:function(){return this.cache.slice(0,3)}});q("dojox.gfx3d.Cube",f.Object,{constructor:function(){this.object=
p.clone(f.defaultCube);this.polygons=[]},setObject:function(a){this.object=r.makeParameters(this.object,a)},render:function(a){var b=this.object.top,c=this.object.bottom,d={x:c.x,y:b.y,z:b.z},e={x:c.x,y:c.y,z:b.z},g={x:b.x,y:c.y,z:b.z},m={x:b.x,y:b.y,z:c.z},n={x:c.x,y:b.y,z:c.z},l={x:b.x,y:c.y,z:c.z};b=[b,d,e,g,m,n,c,l];var z=h.multiply(a,this.matrix);a=k.map(b,function(A){return h.multiplyPoint(z,A)});b=a[0];d=a[1];e=a[2];g=a[3];m=a[4];n=a[5];c=a[6];l=a[7];this.cache=[[b,d,e,g,b],[m,n,c,l,m],[b,
g,l,m,b],[g,e,c,l,g],[e,d,n,c,e],[d,b,m,n,d]]},draw:function(a){this.cache=f.scheduler.bsp(this.cache,function(d){return d});var b=this.cache.slice(3);this.shape?this.shape.clear():this.shape=this.renderer.createGroup();for(var c=0;c<b.length;c++)this.shape.createPolyline(b[c]).setStroke(this.strokeStyle).setFill(this.toStdFill(a,t.normalize(b[c])))},getZOrder:function(){return(this.cache[0][0].z+this.cache[1][2].z)/2}});q("dojox.gfx3d.Cylinder",f.Object,{constructor:function(){this.object=p.clone(f.defaultCylinder)},
render:function(a){var b=h.multiply(a,this.matrix);a=[0,Math.PI/4,Math.PI/3];var c=h.multiplyPoint(b,this.object.center);a=k.map(a,function(l){return{x:this.center.x+this.radius*Math.cos(l),y:this.center.y+this.radius*Math.sin(l),z:this.center.z}},this.object);a=k.map(a,function(l){return t.substract(h.multiplyPoint(b,l),c)});var d={xx:a[0].x*a[0].y,xy:a[0].y*a[0].y,xz:1,yx:a[1].x*a[1].y,yy:a[1].y*a[1].y,yz:1,zx:a[2].x*a[2].y,zy:a[2].y*a[2].y,zz:1,dx:0,dy:0,dz:0},e=k.map(a,function(l){return-Math.pow(l.x,
2)});d=h.multiplyPoint(h.invert(d),e[0],e[1],e[2]);var g=Math.atan2(d.x,1-d.y)/2;a=k.map(a,function(l){return u.multiplyPoint(u.rotate(-g),l.x,l.y)});d=Math.pow(a[0].x,2);e=Math.pow(a[0].y,2);var m=Math.pow(a[1].x,2),n=Math.pow(a[1].y,2);a=Math.sqrt((d*n-e*m)/(n-e));d=Math.sqrt((d*n-e*m)/(d-m));a<d&&(e=a,a=d,d=e,g-=Math.PI/2);e=h.multiplyPoint(b,t.sum(this.object.center,{x:0,y:0,z:this.object.height}));m="constant"==this.fillStyle.type?this.fillStyle.color:x(this.renderer.lighting,this.fillStyle,
this.object.center,this.object.radius,Math.PI,2*Math.PI,b);if(isNaN(a)||isNaN(d)||isNaN(g))a=this.object.radius,g=d=0;this.cache={center:c,top:e,rx:a,ry:d,theta:g,gradient:m}},draw:function(){var a=this.cache,b=[a.center,a.top],c=t.substract(a.top,a.center);0<t.dotProduct(c,this.renderer.lighting.incident)&&(b=[a.top,a.center],c=t.substract(a.center,a.top));c=this.renderer.lighting[this.fillStyle.type](c,this.fillStyle.finish,this.fillStyle.color);var d=Math.sqrt(Math.pow(a.center.x-a.top.x,2)+Math.pow(a.center.y-
a.top.y,2));this.shape?this.shape.clear():this.shape=this.renderer.createGroup();this.shape.createPath("").moveTo(0,-a.rx).lineTo(d,-a.rx).lineTo(d,a.rx).lineTo(0,a.rx).arcTo(a.ry,a.rx,0,!0,!0,0,-a.rx).setFill(a.gradient).setStroke(this.strokeStyle).setTransform([u.translate(b[0]),u.rotate(Math.atan2(b[1].y-b[0].y,b[1].x-b[0].x))]);0<a.rx&&0<a.ry&&this.shape.createEllipse({cx:b[1].x,cy:b[1].y,rx:a.rx,ry:a.ry}).setFill(c).setStroke(this.strokeStyle).applyTransform(u.rotateAt(a.theta,b[1]))}});q("dojox.gfx3d.Viewport",
r.Group,{constructor:function(){this.dimension=null;this.objects=[];this.todos=[];this.renderer=this;this.schedule=f.scheduler.zOrder;this.draw=f.drawer.conservative;this.deep=!1;this.lights=[];this.lighting=null},setCameraTransform:function(a){this.camera=h.clone(a?h.normalize(a):f.identity,!0);this.invalidate();return this},applyCameraRightTransform:function(a){return a?this.setCameraTransform([this.camera,a]):this},applyCameraLeftTransform:function(a){return a?this.setCameraTransform([a,this.camera]):
this},applyCameraTransform:function(a){return this.applyCameraRightTransform(a)},setLights:function(a,b,c){this.lights=a instanceof Array?{sources:a,ambient:b,specular:c}:a;this.lighting=new y.Model({x:0,y:0,z:1},this.lights.sources,this.lights.ambient,this.lights.specular);this.invalidate();return this},addLights:function(a){return this.setLights(this.lights.sources.concat(a))},addTodo:function(a){k.every(this.todos,function(b){return b!=a})&&this.todos.push(a)},invalidate:function(){this.deep=!0;
this.todos=this.objects},setDimensions:function(a){if(a){var b=p.isString(a.width)?parseInt(a.width):a.width;a=p.isString(a.height)?parseInt(a.height):a.height;if(this.rawNode){var c=this.rawNode.style;c?(c.height=a,c.width=b):(this.rawNode.width=b,this.rawNode.height=a)}this.dimension={width:b,height:a}}else this.dimension=null},render:function(){if(this.todos.length){for(var a=0;a<this.todos.length;a++)this.todos[a].render(h.normalize([h.cameraRotateXg(180),h.cameraTranslate(0,this.dimension.height,
0),this.camera]),this.deep);this.objects=this.schedule(this.objects);this.draw(this.todos,this.objects,this);this.todos=[];this.deep=!1}}});f.Viewport.nodeType=r.Group.nodeType;f._creators={createEdges:function(a,b){return this.create3DObject(f.Edges,a,b)},createTriangles:function(a,b){return this.create3DObject(f.Triangles,a,b)},createQuads:function(a,b){return this.create3DObject(f.Quads,a,b)},createPolygon:function(a){return this.create3DObject(f.Polygon,a)},createOrbit:function(a){return this.create3DObject(f.Orbit,
a)},createCube:function(a){return this.create3DObject(f.Cube,a)},createCylinder:function(a){return this.create3DObject(f.Cylinder,a)},createPath3d:function(a){return this.create3DObject(f.Path3d,a)},createScene:function(){return this.create3DObject(f.Scene)},create3DObject:function(a,b,c){a=new a;this.adopt(a);b&&a.setObject(b,c);return a},adopt:function(a){a.renderer=this.renderer;a.parent=this;this.objects.push(a);this.addTodo(a);return this},abandon:function(a,b){for(var c=0;c<this.objects.length;++c)this.objects[c]==
a&&this.objects.splice(c,1);a.parent=null;return this},setScheduler:function(a){this.schedule=a},setDrawer:function(a){this.draw=a}};p.extend(f.Viewport,f._creators);p.extend(f.Scene,f._creators);delete f._creators;p.extend(r.Surface,{createViewport:function(){var a=this.createObject(f.Viewport,null,!0);a.setDimensions(this.getDimensions());return a}});return f.Object});