proctree.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. proctree.js
  3. Copyright (c) 2012, Paul Brunt
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of tree.js nor the
  13. names of its contributors may be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
  19. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. (function(window){
  27. var Tree=function(data){
  28. for(var i in data){
  29. if(this.properties[i]!==undefined){
  30. this.properties[i]=data[i];
  31. }
  32. }
  33. this.properties.rseed=this.properties.seed;
  34. this.root=new Branch([0,this.properties.trunkLength,0]);
  35. this.root.length=this.properties.initalBranchLength;
  36. this.verts=[];
  37. this.faces=[];
  38. this.normals=[];
  39. this.UV=[];
  40. this.vertsTwig=[];
  41. this.normalsTwig=[];
  42. this.facesTwig=[];
  43. this.uvsTwig=[];
  44. this.root.split(null,null,this.properties);
  45. this.createForks();
  46. this.createTwigs();
  47. this.doFaces();
  48. this.calcNormals();
  49. };
  50. Tree.prototype.properties={
  51. clumpMax:0.8,
  52. clumpMin:0.5,
  53. lengthFalloffFactor:0.85,
  54. lengthFalloffPower:1,
  55. branchFactor:2.0,
  56. radiusFalloffRate:0.6,
  57. climbRate:1.5,
  58. trunkKink:0.00,
  59. maxRadius:0.25,
  60. treeSteps:2,
  61. taperRate:0.95,
  62. twistRate:13,
  63. segments:6,
  64. levels:3,
  65. sweepAmount:0,
  66. initalBranchLength:0.85,
  67. trunkLength:2.5,
  68. dropAmount: 0.0,
  69. growAmount: 0.0,
  70. vMultiplier:0.2,
  71. twigScale:2.0,
  72. seed:10,
  73. rseed:10,
  74. random:function(a){
  75. if(!a) a=this.rseed++;
  76. return Math.abs(Math.cos(a+a*a));
  77. }
  78. };
  79. Tree.prototype.calcNormals=function(){
  80. var normals=this.normals;
  81. var faces=this.faces;
  82. var verts=this.verts;
  83. var allNormals=[];
  84. for(var i=0;i<verts.length;i++){
  85. allNormals[i]=[];
  86. }
  87. for(i=0;i<faces.length;i++){
  88. var face=faces[i];
  89. var norm=normalize(cross(subVec(verts[face[1]],verts[face[2]]),subVec(verts[face[1]],verts[face[0]])));
  90. allNormals[face[0]].push(norm);
  91. allNormals[face[1]].push(norm);
  92. allNormals[face[2]].push(norm);
  93. }
  94. for(i=0;i<allNormals.length;i++){
  95. var total=[0,0,0];
  96. var l=allNormals[i].length;
  97. for(var j=0;j<l;j++){
  98. total=addVec(total,scaleVec(allNormals[i][j],1/l));
  99. }
  100. normals[i]=total;
  101. }
  102. };
  103. Tree.prototype.doFaces=function(branch){
  104. if(!branch) branch=this.root;
  105. var segments=this.properties.segments;
  106. var faces=this.faces;
  107. var verts=this.verts;
  108. var UV=this.UV;
  109. if(!branch.parent){
  110. for(i=0;i<verts.length;i++){
  111. UV[i]=[0,0];
  112. }
  113. var tangent=normalize(cross(subVec(branch.child0.head,branch.head),subVec(branch.child1.head,branch.head)));
  114. var normal=normalize(branch.head);
  115. var angle=Math.acos(dot(tangent,[-1,0,0]));
  116. if(dot(cross([-1,0,0],tangent),normal)>0) angle=2*Math.PI-angle;
  117. var segOffset=Math.round((angle/Math.PI/2*segments));
  118. for(var i=0;i<segments;i++){
  119. var v1=branch.ring0[i];
  120. var v2=branch.root[(i+segOffset+1)%segments];
  121. var v3=branch.root[(i+segOffset)%segments];
  122. var v4=branch.ring0[(i+1)%segments];
  123. faces.push([v1,v4,v3]);
  124. faces.push([v4,v2,v3]);
  125. UV[(i+segOffset)%segments]=[Math.abs(i/segments-0.5)*2,0];
  126. var len=length(subVec(verts[branch.ring0[i]],verts[branch.root[(i+segOffset)%segments]]))*this.properties.vMultiplier;
  127. UV[branch.ring0[i]]=[Math.abs(i/segments-0.5)*2,len];
  128. UV[branch.ring2[i]]=[Math.abs(i/segments-0.5)*2,len];
  129. }
  130. }
  131. if(branch.child0.ring0){
  132. var segOffset0,segOffset1;
  133. var match0,match1;
  134. var v1=normalize(subVec(verts[branch.ring1[0]],branch.head));
  135. var v2=normalize(subVec(verts[branch.ring2[0]],branch.head));
  136. v1=scaleInDirection(v1,normalize(subVec(branch.child0.head,branch.head)),0);
  137. v2=scaleInDirection(v2,normalize(subVec(branch.child1.head,branch.head)),0);
  138. for(i=0;i<segments;i++){
  139. var d=normalize(subVec(verts[branch.child0.ring0[i]],branch.child0.head));
  140. var l=dot(d,v1);
  141. if(segOffset0===undefined || l>match0){
  142. match0=l;
  143. segOffset0=segments-i;
  144. }
  145. d=normalize(subVec(verts[branch.child1.ring0[i]],branch.child1.head));
  146. l=dot(d,v2);
  147. if(segOffset1==undefined || l>match1){
  148. match1=l;
  149. segOffset1=segments-i;
  150. }
  151. }
  152. var UVScale=this.properties.maxRadius/branch.radius;
  153. for(i=0;i<segments;i++){
  154. v1=branch.child0.ring0[i];
  155. v2=branch.ring1[(i+segOffset0+1)%segments];
  156. v3=branch.ring1[(i+segOffset0)%segments];
  157. v4=branch.child0.ring0[(i+1)%segments];
  158. faces.push([v1,v4,v3]);
  159. faces.push([v4,v2,v3]);
  160. v1=branch.child1.ring0[i];
  161. v2=branch.ring2[(i+segOffset1+1)%segments];
  162. v3=branch.ring2[(i+segOffset1)%segments];
  163. v4=branch.child1.ring0[(i+1)%segments];
  164. faces.push([v1,v2,v3]);
  165. faces.push([v1,v4,v2]);
  166. var len1=length(subVec(verts[branch.child0.ring0[i]],verts[branch.ring1[(i+segOffset0)%segments]]))*UVScale;
  167. var uv1=UV[branch.ring1[(i+segOffset0-1)%segments]];
  168. UV[branch.child0.ring0[i]]=[uv1[0],uv1[1]+len1*this.properties.vMultiplier];
  169. UV[branch.child0.ring2[i]]=[uv1[0],uv1[1]+len1*this.properties.vMultiplier];
  170. var len2=length(subVec(verts[branch.child1.ring0[i]],verts[branch.ring2[(i+segOffset1)%segments]]))*UVScale;
  171. var uv2=UV[branch.ring2[(i+segOffset1-1)%segments]];
  172. UV[branch.child1.ring0[i]]=[uv2[0],uv2[1]+len2*this.properties.vMultiplier];
  173. UV[branch.child1.ring2[i]]=[uv2[0],uv2[1]+len2*this.properties.vMultiplier];
  174. }
  175. this.doFaces(branch.child0);
  176. this.doFaces(branch.child1);
  177. }else{
  178. for(var i=0;i<segments;i++){
  179. faces.push([branch.child0.end,branch.ring1[(i+1)%segments],branch.ring1[i]]);
  180. faces.push([branch.child1.end,branch.ring2[(i+1)%segments],branch.ring2[i]]);
  181. var len=length(subVec(verts[branch.child0.end],verts[branch.ring1[i]]));
  182. UV[branch.child0.end]=[Math.abs(i/segments-1-0.5)*2,len*this.properties.vMultiplier];
  183. var len=length(subVec(verts[branch.child1.end],verts[branch.ring2[i]]));
  184. UV[branch.child1.end]=[Math.abs(i/segments-0.5)*2,len*this.properties.vMultiplier];
  185. }
  186. }
  187. };
  188. Tree.prototype.createTwigs=function(branch){
  189. if(!branch) branch=this.root;
  190. var vertsTwig=this.vertsTwig;
  191. var normalsTwig=this.normalsTwig;
  192. var facesTwig=this.facesTwig;
  193. var uvsTwig=this.uvsTwig;
  194. if(!branch.child0){
  195. var tangent=normalize(cross(subVec(branch.parent.child0.head,branch.parent.head),subVec(branch.parent.child1.head,branch.parent.head)));
  196. var binormal=normalize(subVec(branch.head,branch.parent.head));
  197. var normal=cross(tangent,binormal);
  198. var vert1=vertsTwig.length;
  199. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,this.properties.twigScale)),scaleVec(binormal,this.properties.twigScale*2-branch.length)));
  200. var vert2=vertsTwig.length;
  201. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,-this.properties.twigScale)),scaleVec(binormal,this.properties.twigScale*2-branch.length)));
  202. var vert3=vertsTwig.length;
  203. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,-this.properties.twigScale)),scaleVec(binormal,-branch.length)));
  204. var vert4=vertsTwig.length;
  205. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,this.properties.twigScale)),scaleVec(binormal,-branch.length)));
  206. var vert8=vertsTwig.length;
  207. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,this.properties.twigScale)),scaleVec(binormal,this.properties.twigScale*2-branch.length)));
  208. var vert7=vertsTwig.length;
  209. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,-this.properties.twigScale)),scaleVec(binormal,this.properties.twigScale*2-branch.length)));
  210. var vert6=vertsTwig.length;
  211. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,-this.properties.twigScale)),scaleVec(binormal,-branch.length)));
  212. var vert5=vertsTwig.length;
  213. vertsTwig.push(addVec(addVec(branch.head,scaleVec(tangent,this.properties.twigScale)),scaleVec(binormal,-branch.length)));
  214. facesTwig.push([vert1,vert2,vert3]);
  215. facesTwig.push([vert4,vert1,vert3]);
  216. facesTwig.push([vert6,vert7,vert8]);
  217. facesTwig.push([vert6,vert8,vert5]);
  218. normal=normalize(cross(subVec(vertsTwig[vert1],vertsTwig[vert3]),subVec(vertsTwig[vert2],vertsTwig[vert3])));
  219. var normal2=normalize(cross(subVec(vertsTwig[vert7],vertsTwig[vert6]),subVec(vertsTwig[vert8],vertsTwig[vert6])));
  220. normalsTwig.push(normal);
  221. normalsTwig.push(normal);
  222. normalsTwig.push(normal);
  223. normalsTwig.push(normal);
  224. normalsTwig.push(normal2);
  225. normalsTwig.push(normal2);
  226. normalsTwig.push(normal2);
  227. normalsTwig.push(normal2);
  228. uvsTwig.push([0,1]);
  229. uvsTwig.push([1,1]);
  230. uvsTwig.push([1,0]);
  231. uvsTwig.push([0,0]);
  232. uvsTwig.push([0,1]);
  233. uvsTwig.push([1,1]);
  234. uvsTwig.push([1,0]);
  235. uvsTwig.push([0,0]);
  236. }else{
  237. this.createTwigs(branch.child0);
  238. this.createTwigs(branch.child1);
  239. }
  240. };
  241. Tree.prototype.createForks=function(branch,radius){
  242. if(!branch) branch=this.root;
  243. if(!radius) radius=this.properties.maxRadius;
  244. branch.radius=radius;
  245. if(radius>branch.length) radius=branch.length;
  246. var verts=this.verts;
  247. var segments=this.properties.segments;
  248. var segmentAngle=Math.PI*2/segments;
  249. if(!branch.parent){
  250. //create the root of the tree
  251. branch.root=[];
  252. var axis=[0,1,0];
  253. for(var i=0;i<segments;i++){
  254. var vec=vecAxisAngle([-1,0,0],axis,-segmentAngle*i);
  255. branch.root.push(verts.length);
  256. verts.push(scaleVec(vec,radius/this.properties.radiusFalloffRate));
  257. }
  258. }
  259. //cross the branches to get the left
  260. //add the branches to get the up
  261. if(branch.child0){
  262. if(branch.parent){
  263. var axis=normalize(subVec(branch.head,branch.parent.head));
  264. }else{
  265. var axis=normalize(branch.head);
  266. }
  267. var axis1=normalize(subVec(branch.head,branch.child0.head));
  268. var axis2=normalize(subVec(branch.head,branch.child1.head));
  269. var tangent=normalize(cross(axis1,axis2));
  270. branch.tangent=tangent;
  271. var axis3=normalize(cross(tangent,normalize(addVec(scaleVec(axis1,-1),scaleVec(axis2,-1)))));
  272. var dir=[axis2[0],0,axis2[2]];
  273. var centerloc=addVec(branch.head,scaleVec(dir,-this.properties.maxRadius/2));
  274. var ring0=branch.ring0=[];
  275. var ring1=branch.ring1=[];
  276. var ring2=branch.ring2=[];
  277. var scale=this.properties.radiusFalloffRate;
  278. if(branch.child0.type=="trunk" || branch.type=="trunk") {
  279. scale=1/this.properties.taperRate;
  280. }
  281. //main segment ring
  282. var linch0=verts.length;
  283. ring0.push(linch0);
  284. ring2.push(linch0);
  285. verts.push(addVec(centerloc,scaleVec(tangent,radius*scale)));
  286. var start=verts.length-1;
  287. var d1=vecAxisAngle(tangent,axis2,1.57);
  288. var d2=normalize(cross(tangent,axis));
  289. var s=1/dot(d1,d2);
  290. for(var i=1;i<segments/2;i++){
  291. var vec=vecAxisAngle(tangent,axis2,segmentAngle*i);
  292. ring0.push(start+i);
  293. ring2.push(start+i);
  294. vec=scaleInDirection(vec,d2,s);
  295. verts.push(addVec(centerloc,scaleVec(vec,radius*scale)));
  296. }
  297. var linch1=verts.length;
  298. ring0.push(linch1);
  299. ring1.push(linch1);
  300. verts.push(addVec(centerloc,scaleVec(tangent,-radius*scale)));
  301. for(var i=segments/2+1;i<segments;i++){
  302. var vec=vecAxisAngle(tangent,axis1,segmentAngle*i);
  303. ring0.push(verts.length);
  304. ring1.push(verts.length);
  305. verts.push(addVec(centerloc,scaleVec(vec,radius*scale)));
  306. }
  307. ring1.push(linch0);
  308. ring2.push(linch1);
  309. var start=verts.length-1;
  310. for(var i=1;i<segments/2;i++){
  311. var vec=vecAxisAngle(tangent,axis3,segmentAngle*i);
  312. ring1.push(start+i);
  313. ring2.push(start+(segments/2-i));
  314. var v=scaleVec(vec,radius*scale);
  315. verts.push(addVec(centerloc,v));
  316. }
  317. //child radius is related to the brans direction and the length of the branch
  318. var length0=length(subVec(branch.head,branch.child0.head));
  319. var length1=length(subVec(branch.head,branch.child1.head));
  320. var radius0=1*radius*this.properties.radiusFalloffRate;
  321. var radius1=1*radius*this.properties.radiusFalloffRate;
  322. if(branch.child0.type=="trunk") radius0=radius*this.properties.taperRate;
  323. this.createForks(branch.child0,radius0);
  324. this.createForks(branch.child1,radius1);
  325. }else{
  326. //add points for the ends of braches
  327. branch.end=verts.length;
  328. //branch.head=addVec(branch.head,scaleVec([this.properties.xBias,this.properties.yBias,this.properties.zBias],branch.length*3));
  329. verts.push(branch.head);
  330. }
  331. };
  332. var Branch=function(head,parent){
  333. this.head=head;
  334. this.parent=parent;
  335. };
  336. Branch.prototype.child0=null;
  337. Branch.prototype.child1=null;
  338. Branch.prototype.parent=null;
  339. Branch.prototype.head=null;
  340. Branch.prototype.length=1;
  341. Branch.prototype.mirrorBranch=function(vec,norm,properties){
  342. var v=cross(norm,cross(vec,norm));
  343. var s=properties.branchFactor*dot(v,vec);
  344. return [vec[0]-v[0]*s,vec[1]-v[1]*s,vec[2]-v[2]*s];
  345. };
  346. Branch.prototype.split=function(level,steps,properties,l1,l2){
  347. if(l1==undefined) l1=1;
  348. if(l2==undefined) l2=1;
  349. if(level==undefined) level=properties.levels;
  350. if(steps==undefined) steps=properties.treeSteps;
  351. var rLevel=properties.levels-level;
  352. var po;
  353. if(this.parent){
  354. po=this.parent.head;
  355. }else{
  356. po=[0,0,0];
  357. this.type="trunk";
  358. }
  359. var so=this.head;
  360. var dir=normalize(subVec(so,po));
  361. var normal = cross(dir,[dir[2],dir[0],dir[1]]);
  362. var tangent = cross(dir,normal);
  363. var r=properties.random(rLevel*10+l1*5+l2+properties.seed);
  364. var r2=properties.random(rLevel*10+l1*5+l2+1+properties.seed);
  365. var clumpmax=properties.clumpMax;
  366. var clumpmin=properties.clumpMin;
  367. var adj=addVec(scaleVec(normal,r),scaleVec(tangent,1-r));
  368. if(r>0.5) adj=scaleVec(adj,-1);
  369. var clump=(clumpmax-clumpmin)*r+clumpmin
  370. var newdir=normalize(addVec(scaleVec(adj,1-clump),scaleVec(dir,clump)));
  371. var newdir2=this.mirrorBranch(newdir,dir,properties);
  372. if(r>0.5){
  373. var tmp=newdir;
  374. newdir=newdir2;
  375. newdir2=tmp;
  376. }
  377. if(steps>0){
  378. var angle=steps/properties.treeSteps*2*Math.PI*properties.twistRate;
  379. newdir2=normalize([Math.sin(angle),r,Math.cos(angle)]);
  380. }
  381. var growAmount=level*level/(properties.levels*properties.levels)*properties.growAmount;
  382. var dropAmount=rLevel*properties.dropAmount
  383. var sweepAmount=rLevel*properties.sweepAmount;
  384. newdir=normalize(addVec(newdir,[sweepAmount,dropAmount+growAmount,0]));
  385. newdir2=normalize(addVec(newdir2,[sweepAmount,dropAmount+growAmount,0]));
  386. var head0=addVec(so,scaleVec(newdir,this.length));
  387. var head1=addVec(so,scaleVec(newdir2,this.length));
  388. this.child0=new Branch(head0,this);
  389. this.child1=new Branch(head1,this);
  390. this.child0.length=Math.pow(this.length,properties.lengthFalloffPower)*properties.lengthFalloffFactor;
  391. this.child1.length=Math.pow(this.length,properties.lengthFalloffPower)*properties.lengthFalloffFactor;
  392. if(level>0){
  393. if(steps>0){
  394. this.child0.head=addVec(this.head,[(r-0.5)*2*properties.trunkKink,properties.climbRate,(r-0.5)*2*properties.trunkKink]);
  395. this.child0.type="trunk";
  396. this.child0.length=this.length*properties.taperRate;
  397. this.child0.split(level,steps-1,properties,l1+1,l2);
  398. }else{
  399. this.child0.split(level-1,0,properties,l1+1,l2);
  400. }
  401. this.child1.split(level-1,0,properties,l1,l2+1);
  402. }
  403. };
  404. var dot=function(v1,v2){
  405. return v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
  406. };
  407. var cross=function(v1,v2){
  408. return [v1[1]*v2[2]-v1[2]*v2[1],v1[2]*v2[0]-v1[0]*v2[2],v1[0]*v2[1]-v1[1]*v2[0]];
  409. };
  410. var length=function(v){
  411. return Math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
  412. };
  413. var normalize=function(v){
  414. var l=length(v);
  415. return scaleVec(v,1/l);
  416. };
  417. var scaleVec=function(v,s){
  418. return [v[0]*s,v[1]*s,v[2]*s];
  419. };
  420. var subVec=function(v1,v2){
  421. return [v1[0]-v2[0],v1[1]-v2[1],v1[2]-v2[2]];
  422. };
  423. var addVec=function(v1,v2){
  424. return [v1[0]+v2[0],v1[1]+v2[1],v1[2]+v2[2]];
  425. };
  426. var vecAxisAngle=function(vec,axis,angle){
  427. //v cos(T) + (axis x v) * sin(T) + axis*(axis . v)(1-cos(T)
  428. var cosr=Math.cos(angle);
  429. var sinr=Math.sin(angle);
  430. return addVec(addVec(scaleVec(vec,cosr),scaleVec(cross(axis,vec),sinr)),scaleVec(axis,dot(axis,vec)*(1-cosr)));
  431. };
  432. var scaleInDirection=function(vector,direction,scale){
  433. var currentMag=dot(vector,direction);
  434. var change=scaleVec(direction,currentMag*scale-currentMag);
  435. return addVec(vector,change);
  436. };
  437. Tree.flattenArray=function(input){
  438. var retArray=[];
  439. for(var i=0;i<input.length;i++){
  440. for(var j=0;j<input[i].length;j++){
  441. retArray.push(input[i][j]);
  442. }
  443. }
  444. return retArray;
  445. }
  446. window.Tree=Tree;
  447. })(window);