root / trunk / web / dojo / dojox / gfx3d / object.js
History | View | Annotate | Download (18.3 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.gfx3d.object"]){ |
||
| 9 | dojo._hasResource["dojox.gfx3d.object"]=true; |
||
| 10 | dojo.provide("dojox.gfx3d.object");
|
||
| 11 | dojo.require("dojox.gfx");
|
||
| 12 | dojo.require("dojox.gfx3d.lighting");
|
||
| 13 | dojo.require("dojox.gfx3d.scheduler");
|
||
| 14 | dojo.require("dojox.gfx3d.vector");
|
||
| 15 | dojo.require("dojox.gfx3d.gradient");
|
||
| 16 | var out=function(o,x){ |
||
| 17 | if(arguments.length>1){ |
||
| 18 | o=x; |
||
| 19 | } |
||
| 20 | var e={};
|
||
| 21 | for(var i in o){ |
||
| 22 | if(i in e){ |
||
| 23 | continue;
|
||
| 24 | } |
||
| 25 | } |
||
| 26 | }; |
||
| 27 | dojo.declare("dojox.gfx3d.Object",null,{constructor:function(){ |
||
| 28 | this.object=null; |
||
| 29 | this.matrix=null; |
||
| 30 | this.cache=null; |
||
| 31 | this.renderer=null; |
||
| 32 | this.parent=null; |
||
| 33 | this.strokeStyle=null; |
||
| 34 | this.fillStyle=null; |
||
| 35 | this.shape=null; |
||
| 36 | },setObject:function(_1){ |
||
| 37 | this.object=dojox.gfx.makeParameters(this.object,_1); |
||
| 38 | return this; |
||
| 39 | },setTransform:function(_2){ |
||
| 40 | this.matrix=dojox.gfx3d.matrix.clone(_2?dojox.gfx3d.matrix.normalize(_2):dojox.gfx3d.identity,true); |
||
| 41 | return this; |
||
| 42 | },applyRightTransform:function(_3){ |
||
| 43 | return _3?this.setTransform([this.matrix,_3]):this; |
||
| 44 | },applyLeftTransform:function(_4){ |
||
| 45 | return _4?this.setTransform([_4,this.matrix]):this; |
||
| 46 | },applyTransform:function(_5){ |
||
| 47 | return _5?this.setTransform([this.matrix,_5]):this; |
||
| 48 | },setFill:function(_6){ |
||
| 49 | this.fillStyle=_6;
|
||
| 50 | return this; |
||
| 51 | },setStroke:function(_7){ |
||
| 52 | this.strokeStyle=_7;
|
||
| 53 | return this; |
||
| 54 | },toStdFill:function(_8,_9){ |
||
| 55 | return (this.fillStyle&&typeof this.fillStyle["type"]!="undefined")?_8[this.fillStyle.type](_9,this.fillStyle.finish,this.fillStyle.color):this.fillStyle; |
||
| 56 | },invalidate:function(){ |
||
| 57 | this.renderer.addTodo(this); |
||
| 58 | },destroy:function(){ |
||
| 59 | if(this.shape){ |
||
| 60 | var p=this.shape.getParent(); |
||
| 61 | if(p){
|
||
| 62 | p.remove(this.shape);
|
||
| 63 | } |
||
| 64 | this.shape=null; |
||
| 65 | } |
||
| 66 | },render:function(_a){ |
||
| 67 | throw "Pure virtual function, not implemented"; |
||
| 68 | },draw:function(_b){ |
||
| 69 | throw "Pure virtual function, not implemented"; |
||
| 70 | },getZOrder:function(){ |
||
| 71 | return 0; |
||
| 72 | },getOutline:function(){ |
||
| 73 | return null; |
||
| 74 | }}); |
||
| 75 | dojo.declare("dojox.gfx3d.Scene",dojox.gfx3d.Object,{constructor:function(){ |
||
| 76 | this.objects=[];
|
||
| 77 | this.todos=[];
|
||
| 78 | this.schedule=dojox.gfx3d.scheduler.zOrder;
|
||
| 79 | this._draw=dojox.gfx3d.drawer.conservative;
|
||
| 80 | },setFill:function(_c){ |
||
| 81 | this.fillStyle=_c;
|
||
| 82 | dojo.forEach(this.objects,function(_d){ |
||
| 83 | _d.setFill(_c); |
||
| 84 | }); |
||
| 85 | return this; |
||
| 86 | },setStroke:function(_e){ |
||
| 87 | this.strokeStyle=_e;
|
||
| 88 | dojo.forEach(this.objects,function(_f){ |
||
| 89 | _f.setStroke(_e); |
||
| 90 | }); |
||
| 91 | return this; |
||
| 92 | },render:function(_10,_11){ |
||
| 93 | var m=dojox.gfx3d.matrix.multiply(_10,this.matrix); |
||
| 94 | if(_11){
|
||
| 95 | this.todos=this.objects; |
||
| 96 | } |
||
| 97 | dojo.forEach(this.todos,function(_12){ |
||
| 98 | _12.render(m,_11); |
||
| 99 | }); |
||
| 100 | },draw:function(_13){ |
||
| 101 | this.objects=this.schedule(this.objects); |
||
| 102 | this._draw(this.todos,this.objects,this.renderer); |
||
| 103 | },addTodo:function(_14){ |
||
| 104 | if(dojo.every(this.todos,function(_15){ |
||
| 105 | return _15!=_14;
|
||
| 106 | })){
|
||
| 107 | this.todos.push(_14);
|
||
| 108 | this.invalidate();
|
||
| 109 | } |
||
| 110 | },invalidate:function(){ |
||
| 111 | this.parent.addTodo(this); |
||
| 112 | },getZOrder:function(){ |
||
| 113 | var _16=0; |
||
| 114 | dojo.forEach(this.objects,function(_17){ |
||
| 115 | _16+=_17.getZOrder(); |
||
| 116 | }); |
||
| 117 | return (this.objects.length>1)?_16/this.objects.length:0; |
||
| 118 | }}); |
||
| 119 | dojo.declare("dojox.gfx3d.Edges",dojox.gfx3d.Object,{constructor:function(){ |
||
| 120 | this.object=dojo.clone(dojox.gfx3d.defaultEdges);
|
||
| 121 | },setObject:function(_18,_19){ |
||
| 122 | this.object=dojox.gfx.makeParameters(this.object,(_18 instanceof Array)?{points:_18,style:_19}:_18); |
||
| 123 | return this; |
||
| 124 | },getZOrder:function(){ |
||
| 125 | var _1a=0; |
||
| 126 | dojo.forEach(this.cache,function(_1b){ |
||
| 127 | _1a+=_1b.z; |
||
| 128 | }); |
||
| 129 | return (this.cache.length>1)?_1a/this.cache.length:0; |
||
| 130 | },render:function(_1c){ |
||
| 131 | var m=dojox.gfx3d.matrix.multiply(_1c,this.matrix); |
||
| 132 | this.cache=dojo.map(this.object.points,function(_1d){ |
||
| 133 | return dojox.gfx3d.matrix.multiplyPoint(m,_1d);
|
||
| 134 | }); |
||
| 135 | },draw:function(){ |
||
| 136 | var c=this.cache; |
||
| 137 | if(this.shape){ |
||
| 138 | this.shape.setShape(""); |
||
| 139 | }else{
|
||
| 140 | this.shape=this.renderer.createPath(); |
||
| 141 | } |
||
| 142 | var p=this.shape.setAbsoluteMode("absolute"); |
||
| 143 | if(this.object.style=="strip"||this.object.style=="loop"){ |
||
| 144 | p.moveTo(c[0].x,c[0].y); |
||
| 145 | dojo.forEach(c.slice(1),function(_1e){ |
||
| 146 | p.lineTo(_1e.x,_1e.y); |
||
| 147 | }); |
||
| 148 | if(this.object.style=="loop"){ |
||
| 149 | p.closePath(); |
||
| 150 | } |
||
| 151 | }else{
|
||
| 152 | for(var i=0;i<this.cache.length;){ |
||
| 153 | p.moveTo(c[i].x,c[i].y); |
||
| 154 | i++; |
||
| 155 | p.lineTo(c[i].x,c[i].y); |
||
| 156 | i++; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | p.setStroke(this.strokeStyle);
|
||
| 160 | }}); |
||
| 161 | dojo.declare("dojox.gfx3d.Orbit",dojox.gfx3d.Object,{constructor:function(){ |
||
| 162 | this.object=dojo.clone(dojox.gfx3d.defaultOrbit);
|
||
| 163 | },render:function(_1f){ |
||
| 164 | var m=dojox.gfx3d.matrix.multiply(_1f,this.matrix); |
||
| 165 | var _20=[0,Math.PI/4,Math.PI/3]; |
||
| 166 | var _21=dojox.gfx3d.matrix.multiplyPoint(m,this.object.center); |
||
| 167 | var _22=dojo.map(_20,function(_23){ |
||
| 168 | return {x:this.center.x+this.radius*Math.cos(_23),y:this.center.y+this.radius*Math.sin(_23),z:this.center.z}; |
||
| 169 | },this.object);
|
||
| 170 | _22=dojo.map(_22,function(_24){
|
||
| 171 | return dojox.gfx3d.matrix.multiplyPoint(m,_24);
|
||
| 172 | }); |
||
| 173 | var _25=dojox.gfx3d.vector.normalize(_22);
|
||
| 174 | _22=dojo.map(_22,function(_26){
|
||
| 175 | return dojox.gfx3d.vector.substract(_26,_21);
|
||
| 176 | }); |
||
| 177 | var A={xx:_22[0].x*_22[0].y,xy:_22[0].y*_22[0].y,xz:1,yx:_22[1].x*_22[1].y,yy:_22[1].y*_22[1].y,yz:1,zx:_22[2].x*_22[2].y,zy:_22[2].y*_22[2].y,zz:1,dx:0,dy:0,dz:0}; |
||
| 178 | var B=dojo.map(_22,function(_27){ |
||
| 179 | return -Math.pow(_27.x,2); |
||
| 180 | }); |
||
| 181 | var X=dojox.gfx3d.matrix.multiplyPoint(dojox.gfx3d.matrix.invert(A),B[0],B[1],B[2]); |
||
| 182 | var _28=Math.atan2(X.x,1-X.y)/2; |
||
| 183 | var _29=dojo.map(_22,function(_2a){ |
||
| 184 | return dojox.gfx.matrix.multiplyPoint(dojox.gfx.matrix.rotate(-_28),_2a.x,_2a.y);
|
||
| 185 | }); |
||
| 186 | var a=Math.pow(_29[0].x,2); |
||
| 187 | var b=Math.pow(_29[0].y,2); |
||
| 188 | var c=Math.pow(_29[1].x,2); |
||
| 189 | var d=Math.pow(_29[1].y,2); |
||
| 190 | var rx=Math.sqrt((a*d-b*c)/(d-b));
|
||
| 191 | var ry=Math.sqrt((a*d-b*c)/(a-c));
|
||
| 192 | this.cache={cx:_21.x,cy:_21.y,rx:rx,ry:ry,theta:_28,normal:_25}; |
||
| 193 | },draw:function(_2b){ |
||
| 194 | if(this.shape){ |
||
| 195 | this.shape.setShape(this.cache); |
||
| 196 | }else{
|
||
| 197 | this.shape=this.renderer.createEllipse(this.cache); |
||
| 198 | } |
||
| 199 | this.shape.applyTransform(dojox.gfx.matrix.rotateAt(this.cache.theta,this.cache.cx,this.cache.cy)).setStroke(this.strokeStyle).setFill(this.toStdFill(_2b,this.cache.normal)); |
||
| 200 | }}); |
||
| 201 | dojo.declare("dojox.gfx3d.Path3d",dojox.gfx3d.Object,{constructor:function(){ |
||
| 202 | this.object=dojo.clone(dojox.gfx3d.defaultPath3d);
|
||
| 203 | this.segments=[];
|
||
| 204 | this.absolute=true; |
||
| 205 | this.last={};
|
||
| 206 | this.path=""; |
||
| 207 | },_collectArgs:function(_2c,_2d){ |
||
| 208 | for(var i=0;i<_2d.length;++i){ |
||
| 209 | var t=_2d[i];
|
||
| 210 | if(typeof (t)=="boolean"){ |
||
| 211 | _2c.push(t?1:0); |
||
| 212 | }else{
|
||
| 213 | if(typeof (t)=="number"){ |
||
| 214 | _2c.push(t); |
||
| 215 | }else{
|
||
| 216 | if(t instanceof Array){ |
||
| 217 | this._collectArgs(_2c,t);
|
||
| 218 | }else{
|
||
| 219 | if("x" in t&&"y" in t){ |
||
| 220 | _2c.push(t.x); |
||
| 221 | _2c.push(t.y); |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } |
||
| 227 | },_validSegments:{m:3,l:3,z:0},_pushSegment:function(_2e,_2f){ |
||
| 228 | var _30=this._validSegments[_2e.toLowerCase()],_31; |
||
| 229 | if(typeof (_30)=="number"){ |
||
| 230 | if(_30){
|
||
| 231 | if(_2f.length>=_30){
|
||
| 232 | _31={action:_2e,args:_2f.slice(0,_2f.length-_2f.length%_30)};
|
||
| 233 | this.segments.push(_31);
|
||
| 234 | } |
||
| 235 | }else{
|
||
| 236 | _31={action:_2e,args:[]};
|
||
| 237 | this.segments.push(_31);
|
||
| 238 | } |
||
| 239 | } |
||
| 240 | },moveTo:function(){ |
||
| 241 | var _32=[];
|
||
| 242 | this._collectArgs(_32,arguments); |
||
| 243 | this._pushSegment(this.absolute?"M":"m",_32); |
||
| 244 | return this; |
||
| 245 | },lineTo:function(){ |
||
| 246 | var _33=[];
|
||
| 247 | this._collectArgs(_33,arguments); |
||
| 248 | this._pushSegment(this.absolute?"L":"l",_33); |
||
| 249 | return this; |
||
| 250 | },closePath:function(){ |
||
| 251 | this._pushSegment("Z",[]); |
||
| 252 | return this; |
||
| 253 | },render:function(_34){ |
||
| 254 | var m=dojox.gfx3d.matrix.multiply(_34,this.matrix); |
||
| 255 | var _35=""; |
||
| 256 | var _36=this._validSegments; |
||
| 257 | dojo.forEach(this.segments,function(_37){ |
||
| 258 | _35+=_37.action; |
||
| 259 | for(var i=0;i<_37.args.length;i+=_36[_37.action.toLowerCase()]){ |
||
| 260 | var pt=dojox.gfx3d.matrix.multiplyPoint(m,_37.args[i],_37.args[i+1],_37.args[i+2]); |
||
| 261 | _35+=" "+pt.x+" "+pt.y; |
||
| 262 | } |
||
| 263 | }); |
||
| 264 | this.cache=_35;
|
||
| 265 | },_draw:function(){ |
||
| 266 | return this.parent.createPath(this.cache); |
||
| 267 | }}); |
||
| 268 | dojo.declare("dojox.gfx3d.Triangles",dojox.gfx3d.Object,{constructor:function(){ |
||
| 269 | this.object=dojo.clone(dojox.gfx3d.defaultTriangles);
|
||
| 270 | },setObject:function(_38,_39){ |
||
| 271 | if(_38 instanceof Array){ |
||
| 272 | this.object=dojox.gfx.makeParameters(this.object,{points:_38,style:_39}); |
||
| 273 | }else{
|
||
| 274 | this.object=dojox.gfx.makeParameters(this.object,_38); |
||
| 275 | } |
||
| 276 | return this; |
||
| 277 | },render:function(_3a){ |
||
| 278 | var m=dojox.gfx3d.matrix.multiply(_3a,this.matrix); |
||
| 279 | var c=dojo.map(this.object.points,function(_3b){ |
||
| 280 | return dojox.gfx3d.matrix.multiplyPoint(m,_3b);
|
||
| 281 | }); |
||
| 282 | this.cache=[];
|
||
| 283 | var _3c=c.slice(0,2); |
||
| 284 | var _3d=c[0]; |
||
| 285 | if(this.object.style=="strip"){ |
||
| 286 | dojo.forEach(c.slice(2),function(_3e){ |
||
| 287 | _3c.push(_3e); |
||
| 288 | _3c.push(_3c[0]);
|
||
| 289 | this.cache.push(_3c);
|
||
| 290 | _3c=_3c.slice(1,3); |
||
| 291 | },this);
|
||
| 292 | }else{
|
||
| 293 | if(this.object.style=="fan"){ |
||
| 294 | dojo.forEach(c.slice(2),function(_3f){ |
||
| 295 | _3c.push(_3f); |
||
| 296 | _3c.push(_3d); |
||
| 297 | this.cache.push(_3c);
|
||
| 298 | _3c=[_3d,_3f]; |
||
| 299 | },this);
|
||
| 300 | }else{
|
||
| 301 | for(var i=0;i<c.length;){ |
||
| 302 | this.cache.push([c[i],c[i+1],c[i+2],c[i]]); |
||
| 303 | i+=3;
|
||
| 304 | } |
||
| 305 | } |
||
| 306 | } |
||
| 307 | },draw:function(_40){ |
||
| 308 | this.cache=dojox.gfx3d.scheduler.bsp(this.cache,function(it){ |
||
| 309 | return it;
|
||
| 310 | }); |
||
| 311 | if(this.shape){ |
||
| 312 | this.shape.clear();
|
||
| 313 | }else{
|
||
| 314 | this.shape=this.renderer.createGroup(); |
||
| 315 | } |
||
| 316 | dojo.forEach(this.cache,function(_41){ |
||
| 317 | this.shape.createPolyline(_41).setStroke(this.strokeStyle).setFill(this.toStdFill(_40,dojox.gfx3d.vector.normalize(_41))); |
||
| 318 | },this);
|
||
| 319 | },getZOrder:function(){ |
||
| 320 | var _42=0; |
||
| 321 | dojo.forEach(this.cache,function(_43){ |
||
| 322 | _42+=(_43[0].z+_43[1].z+_43[2].z)/3; |
||
| 323 | }); |
||
| 324 | return (this.cache.length>1)?_42/this.cache.length:0; |
||
| 325 | }}); |
||
| 326 | dojo.declare("dojox.gfx3d.Quads",dojox.gfx3d.Object,{constructor:function(){ |
||
| 327 | this.object=dojo.clone(dojox.gfx3d.defaultQuads);
|
||
| 328 | },setObject:function(_44,_45){ |
||
| 329 | this.object=dojox.gfx.makeParameters(this.object,(_44 instanceof Array)?{points:_44,style:_45}:_44); |
||
| 330 | return this; |
||
| 331 | },render:function(_46){ |
||
| 332 | var m=dojox.gfx3d.matrix.multiply(_46,this.matrix),i; |
||
| 333 | var c=dojo.map(this.object.points,function(_47){ |
||
| 334 | return dojox.gfx3d.matrix.multiplyPoint(m,_47);
|
||
| 335 | }); |
||
| 336 | this.cache=[];
|
||
| 337 | if(this.object.style=="strip"){ |
||
| 338 | var _48=c.slice(0,2); |
||
| 339 | for(i=2;i<c.length;){ |
||
| 340 | _48=_48.concat([c[i],c[i+1],_48[0]]); |
||
| 341 | this.cache.push(_48);
|
||
| 342 | _48=_48.slice(2,4); |
||
| 343 | i+=2;
|
||
| 344 | } |
||
| 345 | }else{
|
||
| 346 | for(i=0;i<c.length;){ |
||
| 347 | this.cache.push([c[i],c[i+1],c[i+2],c[i+3],c[i]]); |
||
| 348 | i+=4;
|
||
| 349 | } |
||
| 350 | } |
||
| 351 | },draw:function(_49){ |
||
| 352 | this.cache=dojox.gfx3d.scheduler.bsp(this.cache,function(it){ |
||
| 353 | return it;
|
||
| 354 | }); |
||
| 355 | if(this.shape){ |
||
| 356 | this.shape.clear();
|
||
| 357 | }else{
|
||
| 358 | this.shape=this.renderer.createGroup(); |
||
| 359 | } |
||
| 360 | for(var x=0;x<this.cache.length;x++){ |
||
| 361 | this.shape.createPolyline(this.cache[x]).setStroke(this.strokeStyle).setFill(this.toStdFill(_49,dojox.gfx3d.vector.normalize(this.cache[x]))); |
||
| 362 | } |
||
| 363 | },getZOrder:function(){ |
||
| 364 | var _4a=0; |
||
| 365 | for(var x=0;x<this.cache.length;x++){ |
||
| 366 | var i=this.cache[x]; |
||
| 367 | _4a+=(i[0].z+i[1].z+i[2].z+i[3].z)/4; |
||
| 368 | } |
||
| 369 | return (this.cache.length>1)?_4a/this.cache.length:0; |
||
| 370 | }}); |
||
| 371 | dojo.declare("dojox.gfx3d.Polygon",dojox.gfx3d.Object,{constructor:function(){ |
||
| 372 | this.object=dojo.clone(dojox.gfx3d.defaultPolygon);
|
||
| 373 | },setObject:function(_4b){ |
||
| 374 | this.object=dojox.gfx.makeParameters(this.object,(_4b instanceof Array)?{path:_4b}:_4b); |
||
| 375 | return this; |
||
| 376 | },render:function(_4c){ |
||
| 377 | var m=dojox.gfx3d.matrix.multiply(_4c,this.matrix); |
||
| 378 | this.cache=dojo.map(this.object.path,function(_4d){ |
||
| 379 | return dojox.gfx3d.matrix.multiplyPoint(m,_4d);
|
||
| 380 | }); |
||
| 381 | this.cache.push(this.cache[0]); |
||
| 382 | },draw:function(_4e){ |
||
| 383 | if(this.shape){ |
||
| 384 | this.shape.setShape({points:this.cache}); |
||
| 385 | }else{
|
||
| 386 | this.shape=this.renderer.createPolyline({points:this.cache}); |
||
| 387 | } |
||
| 388 | this.shape.setStroke(this.strokeStyle).setFill(this.toStdFill(_4e,dojox.gfx3d.matrix.normalize(this.cache))); |
||
| 389 | },getZOrder:function(){ |
||
| 390 | var _4f=0; |
||
| 391 | for(var x=0;x<this.cache.length;x++){ |
||
| 392 | _4f+=this.cache[x].z;
|
||
| 393 | } |
||
| 394 | return (this.cache.length>1)?_4f/this.cache.length:0; |
||
| 395 | },getOutline:function(){ |
||
| 396 | return this.cache.slice(0,3); |
||
| 397 | }}); |
||
| 398 | dojo.declare("dojox.gfx3d.Cube",dojox.gfx3d.Object,{constructor:function(){ |
||
| 399 | this.object=dojo.clone(dojox.gfx3d.defaultCube);
|
||
| 400 | this.polygons=[];
|
||
| 401 | },setObject:function(_50){ |
||
| 402 | this.object=dojox.gfx.makeParameters(this.object,_50); |
||
| 403 | },render:function(_51){ |
||
| 404 | var a=this.object.top; |
||
| 405 | var g=this.object.bottom; |
||
| 406 | var b={x:g.x,y:a.y,z:a.z}; |
||
| 407 | var c={x:g.x,y:g.y,z:a.z}; |
||
| 408 | var d={x:a.x,y:g.y,z:a.z}; |
||
| 409 | var e={x:a.x,y:a.y,z:g.z}; |
||
| 410 | var f={x:g.x,y:a.y,z:g.z}; |
||
| 411 | var h={x:a.x,y:g.y,z:g.z}; |
||
| 412 | var _52=[a,b,c,d,e,f,g,h];
|
||
| 413 | var m=dojox.gfx3d.matrix.multiply(_51,this.matrix); |
||
| 414 | var p=dojo.map(_52,function(_53){ |
||
| 415 | return dojox.gfx3d.matrix.multiplyPoint(m,_53);
|
||
| 416 | }); |
||
| 417 | a=p[0];
|
||
| 418 | b=p[1];
|
||
| 419 | c=p[2];
|
||
| 420 | d=p[3];
|
||
| 421 | e=p[4];
|
||
| 422 | f=p[5];
|
||
| 423 | g=p[6];
|
||
| 424 | h=p[7];
|
||
| 425 | this.cache=[[a,b,c,d,a],[e,f,g,h,e],[a,d,h,e,a],[d,c,g,h,d],[c,b,f,g,c],[b,a,e,f,b]];
|
||
| 426 | },draw:function(_54){ |
||
| 427 | this.cache=dojox.gfx3d.scheduler.bsp(this.cache,function(it){ |
||
| 428 | return it;
|
||
| 429 | }); |
||
| 430 | var _55=this.cache.slice(3); |
||
| 431 | if(this.shape){ |
||
| 432 | this.shape.clear();
|
||
| 433 | }else{
|
||
| 434 | this.shape=this.renderer.createGroup(); |
||
| 435 | } |
||
| 436 | for(var x=0;x<_55.length;x++){ |
||
| 437 | this.shape.createPolyline(_55[x]).setStroke(this.strokeStyle).setFill(this.toStdFill(_54,dojox.gfx3d.vector.normalize(_55[x]))); |
||
| 438 | } |
||
| 439 | },getZOrder:function(){ |
||
| 440 | var top=this.cache[0][0]; |
||
| 441 | var _56=this.cache[1][2]; |
||
| 442 | return (top.z+_56.z)/2; |
||
| 443 | }}); |
||
| 444 | dojo.declare("dojox.gfx3d.Cylinder",dojox.gfx3d.Object,{constructor:function(){ |
||
| 445 | this.object=dojo.clone(dojox.gfx3d.defaultCylinder);
|
||
| 446 | },render:function(_57){ |
||
| 447 | var m=dojox.gfx3d.matrix.multiply(_57,this.matrix); |
||
| 448 | var _58=[0,Math.PI/4,Math.PI/3]; |
||
| 449 | var _59=dojox.gfx3d.matrix.multiplyPoint(m,this.object.center); |
||
| 450 | var _5a=dojo.map(_58,function(_5b){ |
||
| 451 | return {x:this.center.x+this.radius*Math.cos(_5b),y:this.center.y+this.radius*Math.sin(_5b),z:this.center.z}; |
||
| 452 | },this.object);
|
||
| 453 | _5a=dojo.map(_5a,function(_5c){
|
||
| 454 | return dojox.gfx3d.vector.substract(dojox.gfx3d.matrix.multiplyPoint(m,_5c),_59);
|
||
| 455 | }); |
||
| 456 | var A={xx:_5a[0].x*_5a[0].y,xy:_5a[0].y*_5a[0].y,xz:1,yx:_5a[1].x*_5a[1].y,yy:_5a[1].y*_5a[1].y,yz:1,zx:_5a[2].x*_5a[2].y,zy:_5a[2].y*_5a[2].y,zz:1,dx:0,dy:0,dz:0}; |
||
| 457 | var B=dojo.map(_5a,function(_5d){ |
||
| 458 | return -Math.pow(_5d.x,2); |
||
| 459 | }); |
||
| 460 | var X=dojox.gfx3d.matrix.multiplyPoint(dojox.gfx3d.matrix.invert(A),B[0],B[1],B[2]); |
||
| 461 | var _5e=Math.atan2(X.x,1-X.y)/2; |
||
| 462 | var _5f=dojo.map(_5a,function(_60){ |
||
| 463 | return dojox.gfx.matrix.multiplyPoint(dojox.gfx.matrix.rotate(-_5e),_60.x,_60.y);
|
||
| 464 | }); |
||
| 465 | var a=Math.pow(_5f[0].x,2); |
||
| 466 | var b=Math.pow(_5f[0].y,2); |
||
| 467 | var c=Math.pow(_5f[1].x,2); |
||
| 468 | var d=Math.pow(_5f[1].y,2); |
||
| 469 | var rx=Math.sqrt((a*d-b*c)/(d-b));
|
||
| 470 | var ry=Math.sqrt((a*d-b*c)/(a-c));
|
||
| 471 | if(rx<ry){
|
||
| 472 | var t=rx;
|
||
| 473 | rx=ry; |
||
| 474 | ry=t; |
||
| 475 | _5e-=Math.PI/2;
|
||
| 476 | } |
||
| 477 | var top=dojox.gfx3d.matrix.multiplyPoint(m,dojox.gfx3d.vector.sum(this.object.center,{x:0,y:0,z:this.object.height})); |
||
| 478 | var _61=this.fillStyle.type=="constant"?this.fillStyle.color:dojox.gfx3d.gradient(this.renderer.lighting,this.fillStyle,this.object.center,this.object.radius,Math.PI,2*Math.PI,m); |
||
| 479 | if(isNaN(rx)||isNaN(ry)||isNaN(_5e)){
|
||
| 480 | rx=this.object.radius,ry=0,_5e=0; |
||
| 481 | } |
||
| 482 | this.cache={center:_59,top:top,rx:rx,ry:ry,theta:_5e,gradient:_61}; |
||
| 483 | },draw:function(){ |
||
| 484 | var c=this.cache,v=dojox.gfx3d.vector,m=dojox.gfx.matrix,_62=[c.center,c.top],_63=v.substract(c.top,c.center); |
||
| 485 | if(v.dotProduct(_63,this.renderer.lighting.incident)>0){ |
||
| 486 | _62=[c.top,c.center]; |
||
| 487 | _63=v.substract(c.center,c.top); |
||
| 488 | } |
||
| 489 | var _64=this.renderer.lighting[this.fillStyle.type](_63,this.fillStyle.finish,this.fillStyle.color),d=Math.sqrt(Math.pow(c.center.x-c.top.x,2)+Math.pow(c.center.y-c.top.y,2)); |
||
| 490 | if(this.shape){ |
||
| 491 | this.shape.clear();
|
||
| 492 | }else{
|
||
| 493 | this.shape=this.renderer.createGroup(); |
||
| 494 | } |
||
| 495 | this.shape.createPath("").moveTo(0,-c.rx).lineTo(d,-c.rx).lineTo(d,c.rx).lineTo(0,c.rx).arcTo(c.ry,c.rx,0,true,true,0,-c.rx).setFill(c.gradient).setStroke(this.strokeStyle).setTransform([m.translate(_62[0]),m.rotate(Math.atan2(_62[1].y-_62[0].y,_62[1].x-_62[0].x))]); |
||
| 496 | if(c.rx>0&&c.ry>0){ |
||
| 497 | this.shape.createEllipse({cx:_62[1].x,cy:_62[1].y,rx:c.rx,ry:c.ry}).setFill(_64).setStroke(this.strokeStyle).applyTransform(m.rotateAt(c.theta,_62[1])); |
||
| 498 | } |
||
| 499 | }}); |
||
| 500 | dojo.declare("dojox.gfx3d.Viewport",dojox.gfx.Group,{constructor:function(){ |
||
| 501 | this.dimension=null; |
||
| 502 | this.objects=[];
|
||
| 503 | this.todos=[];
|
||
| 504 | this.renderer=this; |
||
| 505 | this.schedule=dojox.gfx3d.scheduler.zOrder;
|
||
| 506 | this.draw=dojox.gfx3d.drawer.conservative;
|
||
| 507 | this.deep=false; |
||
| 508 | this.lights=[];
|
||
| 509 | this.lighting=null; |
||
| 510 | },setCameraTransform:function(_65){ |
||
| 511 | this.camera=dojox.gfx3d.matrix.clone(_65?dojox.gfx3d.matrix.normalize(_65):dojox.gfx3d.identity,true); |
||
| 512 | this.invalidate();
|
||
| 513 | return this; |
||
| 514 | },applyCameraRightTransform:function(_66){ |
||
| 515 | return _66?this.setCameraTransform([this.camera,_66]):this; |
||
| 516 | },applyCameraLeftTransform:function(_67){ |
||
| 517 | return _67?this.setCameraTransform([_67,this.camera]):this; |
||
| 518 | },applyCameraTransform:function(_68){ |
||
| 519 | return this.applyCameraRightTransform(_68); |
||
| 520 | },setLights:function(_69,_6a,_6b){ |
||
| 521 | this.lights=(_69 instanceof Array)?{sources:_69,ambient:_6a,specular:_6b}:_69; |
||
| 522 | var _6c={x:0,y:0,z:1}; |
||
| 523 | this.lighting=new dojox.gfx3d.lighting.Model(_6c,this.lights.sources,this.lights.ambient,this.lights.specular); |
||
| 524 | this.invalidate();
|
||
| 525 | return this; |
||
| 526 | },addLights:function(_6d){ |
||
| 527 | return this.setLights(this.lights.sources.concat(_6d)); |
||
| 528 | },addTodo:function(_6e){ |
||
| 529 | if(dojo.every(this.todos,function(_6f){ |
||
| 530 | return _6f!=_6e;
|
||
| 531 | })){
|
||
| 532 | this.todos.push(_6e);
|
||
| 533 | } |
||
| 534 | },invalidate:function(){ |
||
| 535 | this.deep=true; |
||
| 536 | this.todos=this.objects; |
||
| 537 | },setDimensions:function(dim){ |
||
| 538 | if(dim){
|
||
| 539 | var w=dojo.isString(dim.width)?parseInt(dim.width):dim.width;
|
||
| 540 | var h=dojo.isString(dim.height)?parseInt(dim.height):dim.height;
|
||
| 541 | var trs=this.rawNode.style; |
||
| 542 | trs.height=h; |
||
| 543 | trs.width=w; |
||
| 544 | this.dimension={width:w,height:h}; |
||
| 545 | }else{
|
||
| 546 | this.dimension=null; |
||
| 547 | } |
||
| 548 | },render:function(){ |
||
| 549 | if(!this.todos.length){ |
||
| 550 | return;
|
||
| 551 | } |
||
| 552 | var m=dojox.gfx3d.matrix;
|
||
| 553 | for(var x=0;x<this.todos.length;x++){ |
||
| 554 | this.todos[x].render(dojox.gfx3d.matrix.normalize([m.cameraRotateXg(180),m.cameraTranslate(0,this.dimension.height,0),this.camera]),this.deep); |
||
| 555 | } |
||
| 556 | this.objects=this.schedule(this.objects); |
||
| 557 | this.draw(this.todos,this.objects,this); |
||
| 558 | this.todos=[];
|
||
| 559 | this.deep=false; |
||
| 560 | }}); |
||
| 561 | dojox.gfx3d.Viewport.nodeType=dojox.gfx.Group.nodeType; |
||
| 562 | dojox.gfx3d._creators={createEdges:function(_70,_71){
|
||
| 563 | return this.create3DObject(dojox.gfx3d.Edges,_70,_71); |
||
| 564 | },createTriangles:function(_72,_73){ |
||
| 565 | return this.create3DObject(dojox.gfx3d.Triangles,_72,_73); |
||
| 566 | },createQuads:function(_74,_75){ |
||
| 567 | return this.create3DObject(dojox.gfx3d.Quads,_74,_75); |
||
| 568 | },createPolygon:function(_76){ |
||
| 569 | return this.create3DObject(dojox.gfx3d.Polygon,_76); |
||
| 570 | },createOrbit:function(_77){ |
||
| 571 | return this.create3DObject(dojox.gfx3d.Orbit,_77); |
||
| 572 | },createCube:function(_78){ |
||
| 573 | return this.create3DObject(dojox.gfx3d.Cube,_78); |
||
| 574 | },createCylinder:function(_79){ |
||
| 575 | return this.create3DObject(dojox.gfx3d.Cylinder,_79); |
||
| 576 | },createPath3d:function(_7a){ |
||
| 577 | return this.create3DObject(dojox.gfx3d.Path3d,_7a); |
||
| 578 | },createScene:function(){ |
||
| 579 | return this.create3DObject(dojox.gfx3d.Scene); |
||
| 580 | },create3DObject:function(_7b,_7c,_7d){ |
||
| 581 | var obj=new _7b(); |
||
| 582 | this.adopt(obj);
|
||
| 583 | if(_7c){
|
||
| 584 | obj.setObject(_7c,_7d); |
||
| 585 | } |
||
| 586 | return obj;
|
||
| 587 | },adopt:function(obj){ |
||
| 588 | obj.renderer=this.renderer;
|
||
| 589 | obj.parent=this;
|
||
| 590 | this.objects.push(obj);
|
||
| 591 | this.addTodo(obj);
|
||
| 592 | return this; |
||
| 593 | },abandon:function(obj,_7e){ |
||
| 594 | for(var i=0;i<this.objects.length;++i){ |
||
| 595 | if(this.objects[i]==obj){ |
||
| 596 | this.objects.splice(i,1); |
||
| 597 | } |
||
| 598 | } |
||
| 599 | obj.parent=null;
|
||
| 600 | return this; |
||
| 601 | },setScheduler:function(_7f){ |
||
| 602 | this.schedule=_7f;
|
||
| 603 | },setDrawer:function(_80){ |
||
| 604 | this.draw=_80;
|
||
| 605 | }}; |
||
| 606 | dojo.extend(dojox.gfx3d.Viewport,dojox.gfx3d._creators); |
||
| 607 | dojo.extend(dojox.gfx3d.Scene,dojox.gfx3d._creators); |
||
| 608 | delete dojox.gfx3d._creators;
|
||
| 609 | dojo.extend(dojox.gfx.Surface,{createViewport:function(){
|
||
| 610 | var _81=this.createObject(dojox.gfx3d.Viewport,null,true); |
||
| 611 | _81.setDimensions(this.getDimensions());
|
||
| 612 | return _81;
|
||
| 613 | }}); |
||
| 614 | } |