Advertisement
Guest User

Untitled

a guest
May 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 115.01 KB | None | 0 0
  1. ///<reference path='easeljs.d.ts'/>
  2. var __extends = this.__extends || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. __.prototype = b.prototype;
  6. d.prototype = new __();
  7. };
  8. var MouseTarget = (function (_super) {
  9. __extends(MouseTarget, _super);
  10. function MouseTarget(tag) {
  11. _super.call(this);
  12. this.tag = tag;
  13. this.mouseEnabled = true;
  14. this.cursor = 'pointer';
  15. }
  16. return MouseTarget;
  17. })(createjs.Shape); //class
  18. ///<reference path='easeljs.d.ts'/>
  19. ///<reference path='mousetarget.ts'/>
  20. //Mdodified with new default settings
  21. var SliderCB = (function (_super) {
  22. __extends(SliderCB, _super);
  23. function SliderCB(width, height, tag, bgndColor) {
  24. _super.call(this);
  25. this.width = width;
  26. this.height = height;
  27. this.value = 0;
  28. this.trackHeight = 6;
  29. this.font = 'bold 12px Arial';
  30. this.tag = 0;
  31. this.multiplier = 1;
  32. this.min = 0;
  33. this.max = 10;
  34. this.color1 = '#bbbbbb';
  35. this.color2 = '#eeeeee';
  36. this.trackColor1 = '#0063b5';
  37. this.trackColor2 = '#3d95e4';
  38. this.prefix = '';
  39. this.postfix = '';
  40. this.thumbRadius = 8;
  41. this.dp = 0;
  42. this.showZeroPostfix = false;
  43. this.showValue = true;
  44. this.labelAlign = 'center';
  45. this.style = 0;
  46.  
  47. //this.thumbRadius = 0.4 * this.height;
  48. this.tag = tag;
  49. var ms = new MouseTarget(0);
  50. if (!bgndColor) {
  51. bgndColor = '#ffffff';
  52. }
  53.  
  54. ms.graphics.beginFill(bgndColor).drawRect(0, 0, this.width, this.height);
  55. this.addChild(ms);
  56. ms.addEventListener('mousedown', this.doTargetMouse);
  57. ms.addEventListener('pressmove', this.doTargetMouse);
  58. ms.addEventListener('pressup', this.doTargetMouse);
  59.  
  60. // ms.mouseEnabled = true;
  61. // ms.cursor = 'pointer';
  62. this.gauge = new createjs.Shape();
  63. this.addChild(this.gauge);
  64. this.thumb = new createjs.Shape();
  65. this.thumb.y = 0.5 * this.height;
  66. this.addChild(this.thumb);
  67. this.thumb.mouseEnabled = false;
  68. this.gauge.mouseEnabled = false;
  69.  
  70. this.drawThumb();
  71. this.drawGauge(0);
  72.  
  73. this.valueLabel = new createjs.Text("", this.font, "#0000000");
  74. this.valueLabel.textAlign = 'left';
  75. this.valueLabel.x = 0;
  76. this.valueLabel.y = -10;
  77. this.addChild(this.valueLabel);
  78. this.valueLabel.mouseEnabled = false;
  79. }
  80. SliderCB.prototype.drawThumb = function () {
  81. var g = this.thumb.graphics;
  82. g.clear();
  83. if (this.style == 0) {
  84. g.ss(1).s('#333333');
  85. g.rf([this.color1, this.color2, this.color1], [0.4, 0.8, 1], 0, 0, 0, 0, 0, this.thumbRadius);
  86. g.dc(0, 0, this.thumbRadius).ef();
  87. } else {
  88. g.ss(1).s('#333333').lf(['#f0f0f0', '#c0c0c0'], [0, 1], 0, 0, 0, 2 * this.thumbRadius);
  89. g.dr(-this.thumbRadius, -this.thumbRadius, 2 * this.thumbRadius, 2 * this.thumbRadius).ef();
  90. }
  91. };
  92.  
  93. SliderCB.prototype.drawGauge = function (px) {
  94. var y = (this.height - this.trackHeight) / 2;
  95.  
  96. var g = this.gauge.graphics;
  97. g.clear();
  98. g.ss(1).s('#9a9a9a');
  99. g.beginFill('#ffffff');
  100. g.drawRect(0, y, this.width, this.trackHeight);
  101. g.ef();
  102. if (px > 0) {
  103. g.lf([this.trackColor1, this.trackColor2, this.trackColor1], [0, 0.5, 1], 0, y, 0, y + this.trackHeight);
  104. g.drawRect(0, y, px, this.trackHeight);
  105. }
  106. };
  107.  
  108. SliderCB.prototype.mouseToValue = function (px) {
  109. var delta = (this.max - this.min) / this.width;
  110. var n = this.min + px * delta;
  111. if (n > this.max) {
  112. n = this.max;
  113. } else if (n < this.min) {
  114. n = this.min;
  115. }
  116. return n;
  117. };
  118.  
  119. SliderCB.prototype.valueToMouse = function () {
  120. var delta = (this.max - this.min) / this.width;
  121.  
  122. //var n: number = this.min + px * delta;
  123. var px = (this.value - this.min) / delta;
  124. return px;
  125. };
  126.  
  127. SliderCB.prototype.doText = function () {
  128. if (this.showValue) {
  129. var pf;
  130. if (this.showZeroPostfix || this.value > 0) {
  131. pf = this.postfix;
  132. } else {
  133. pf = '';
  134. }
  135.  
  136. if (this.dp == 0) {
  137. this.valueLabel.text = this.prefix + (this.multiplier * Math.round(this.value)).toFixed() + pf;
  138. } else {
  139. this.valueLabel.text = this.prefix + this.value.toFixed(this.dp) + pf;
  140. }
  141. } else {
  142. this.valueLabel.text = this.prefix;
  143. }
  144.  
  145. if (this.labelAlign === 'left') {
  146. //this.valueLabel.regX = 0;
  147. } else if (this.labelAlign === 'center') {
  148. //this.valueLabel.regX = 0.5 * this.valueLabel.getMeasuredWidth();
  149. } else if (this.labelAlign === 'right') {
  150. //this.valueLabel.regX = this.valueLabel.getMeasuredWidth();
  151. }
  152. };
  153.  
  154. SliderCB.prototype.doTargetMouse = function (e) {
  155. var p = e.target.parent;
  156. var px;
  157. px = (e.target.globalToLocal(e.stageX, e.stageY)).x;
  158. p.setPixelValue(px, e.type);
  159. //if (e.type == "pressup") {
  160. //canUpdate = false
  161. //}
  162. //else {
  163. //canUpdate = true
  164. //}
  165. };
  166.  
  167. SliderCB.prototype.getValue = function () {
  168. return this.value;
  169. };
  170.  
  171. SliderCB.prototype.setValue = function (value) {
  172. if (this.dp == 0)
  173. this.value = Math.round(value);
  174. else
  175. this.value = value;
  176. var px = this.valueToMouse();
  177. this.drawGauge(px);
  178. if (px < this.thumbRadius) {
  179. this.thumb.x = this.thumbRadius;
  180. } else if (px > this.width - this.thumbRadius) {
  181. this.thumb.x = this.width - this.thumbRadius;
  182. } else {
  183. this.thumb.x = px;
  184. }
  185. this.doText();
  186. };
  187.  
  188. SliderCB.prototype.setPixelValue = function (px, type) {
  189. if (px > this.width) {
  190. px = this.width;
  191. } else if (px < 0) {
  192. px = 0;
  193. }
  194. this.value = this.mouseToValue(px);
  195. this.drawGauge(px);
  196.  
  197. if (px < this.thumbRadius) {
  198. this.thumb.x = this.thumbRadius;
  199. } else if (px > this.width - this.thumbRadius) {
  200. this.thumb.x = this.width - this.thumbRadius;
  201. } else {
  202. this.thumb.x = px;
  203. }
  204.  
  205. this.doText();
  206.  
  207. if (this.fcallback) {
  208. this.fcallback(this.tag, this.value, type);
  209. } else {
  210. stage.update();
  211. }
  212. };
  213.  
  214. SliderCB.prototype.setTrackHeight = function (value) {
  215. this.trackHeight = value;
  216. var px = this.valueToMouse();
  217. this.drawGauge(px);
  218. };
  219.  
  220. SliderCB.prototype.setThumbRadius = function (value) {
  221. this.thumbRadius = value;
  222. this.drawThumb();
  223. };
  224.  
  225. SliderCB.prototype.setLabelAlign = function (value) {
  226. this.labelAlign = value;
  227. this.valueLabel.textAlign = value;
  228. if (value === 'left') {
  229. this.valueLabel.x = 0;
  230. } else if (value === 'center') {
  231. this.valueLabel.x = 0.5 * this.width;
  232. } else if (value === 'right') {
  233. this.valueLabel.x = this.width;
  234. }
  235. };
  236.  
  237. SliderCB.prototype.setTextOffsetY = function (value) {
  238. this.valueLabel.y = value;
  239. };
  240. SliderCB.prototype.setTextFont = function (fs) {
  241. this.valueLabel.font = fs;
  242. };
  243.  
  244. SliderCB.prototype.setTag = function (value) {
  245. this.getChildAt(0).tag = value;
  246. };
  247.  
  248. SliderCB.prototype.setFont = function (value, color) {
  249. this.valueLabel.font = value;
  250. if (color) {
  251. this.valueLabel.color = color;
  252. }
  253. };
  254.  
  255. SliderCB.prototype.setColors = function (c1, c2) {
  256. this.color1 = c1;
  257. this.color2 = c2;
  258. };
  259. SliderCB.prototype.setTrackColor = function (c1, c2) {
  260. this.trackColor1 = c1;
  261. this.trackColor2 = c2;
  262. };
  263.  
  264. SliderCB.prototype.doEnabled = function (value) {
  265. this.getChildAt(0).mouseEnabled = value;
  266. };
  267.  
  268. SliderCB.prototype.setText = function (s) {
  269. this.valueLabel.text = s;
  270. };
  271.  
  272. SliderCB.prototype.addCallback = function (f) {
  273. this.fcallback = f;
  274. };
  275.  
  276. SliderCB.prototype.setStyle = function (n, thumbRad) {
  277. this.style = n;
  278. if (thumbRad) {
  279. this.thumbRadius = thumbRad;
  280. }
  281. this.drawThumb();
  282. };
  283. return SliderCB;
  284. })(createjs.Container);
  285. ///<reference path='easeljs.d.ts'/>
  286. ///<reference path='mousetarget.ts'/>
  287. var PJRadioButton = (function (_super) {
  288. __extends(PJRadioButton, _super);
  289. function PJRadioButton(width, height, tag, caption, bgndColor) {
  290. _super.call(this);
  291. this.width = width;
  292. this.height = height;
  293. this.bgndColor = '#ffffff';
  294. this.btn = new createjs.Shape();
  295. this.check = new createjs.Shape();
  296. this.font = 'bold 14px Arial';
  297. this.color1 = '#cccccc';
  298. this.color2 = '#fefefe';
  299. this.checked = false;
  300. if (bgndColor) {
  301. this.bgndColor = bgndColor;
  302. }
  303. this.btnRadius = 0.3 * this.height;
  304. this.mt = new MouseTarget(tag);
  305.  
  306. this.addChild(this.mt);
  307.  
  308. this.addChild(this.btn);
  309. this.btn.x = this.btnRadius;
  310. this.btn.y = 0.5 * this.height;
  311. this.drawBtnBgnd();
  312. this.btn.mouseEnabled = false;
  313.  
  314. this.addChild(this.check);
  315. this.check.x = this.btnRadius;
  316. this.check.y = 0.5 * this.height;
  317. this.check.visible = false;
  318. this.check.graphics.beginFill('#000000').drawCircle(0, 0, 0.5 * this.btnRadius).endFill();
  319. this.check.mouseEnabled = false;
  320.  
  321. if (caption) {
  322. this.captionLabel = new createjs.Text(caption, this.font);
  323. this.captionLabel.regY = 0.5 * this.captionLabel.getMeasuredHeight();
  324. this.captionLabel.x = 2.5 * this.btnRadius;
  325. this.captionLabel.y = 0.5 * this.height;
  326. this.addChild(this.captionLabel);
  327.  
  328. if (caption.indexOf('\n') != -1) {
  329. //var a = caption.split('\n');
  330. //var w = Math.max(a[0].getMeasuredWidth(), a[1].getMeasuredWidth());
  331. //w = this.width;
  332. } else {
  333. this.width = this.captionLabel.x + this.captionLabel.getMeasuredWidth();
  334. }
  335.  
  336. this.captionLabel.mouseEnabled = false;
  337. }
  338. this.mt.graphics.beginFill(this.bgndColor).drawRect(0, 0, this.width, this.height).endFill();
  339. }
  340. PJRadioButton.prototype.addMouseEvent = function (f) {
  341. this.getChildAt(0).addEventListener('mousedown', f);
  342. };
  343.  
  344. PJRadioButton.prototype.drawBtnBgnd = function () {
  345. var g = this.btn.graphics;
  346. g.clear();
  347. g.setStrokeStyle(1, 1, 1, 1, true).beginStroke('#9a9a9a');
  348. g.beginRadialGradientFill([this.color2, this.color1], [0.25, 1], 0, 0, 0, 0, 0, this.btnRadius);
  349. g.drawCircle(0, 0, this.btnRadius).endFill();
  350. };
  351.  
  352. PJRadioButton.prototype.setCheck = function (value) {
  353. this.check.visible = value;
  354. this.checked = value;
  355. };
  356.  
  357. PJRadioButton.prototype.doEnabled = function (value) {
  358. var bgnd = this.getChildAt(0);
  359. bgnd.mouseEnabled = value;
  360. if (value)
  361. this.alpha = 1;
  362. else
  363. this.alpha = 0.5;
  364. };
  365.  
  366. PJRadioButton.prototype.setFont = function (value, offset) {
  367. this.captionLabel.font = value;
  368. this.captionLabel.regY = 0.5 * this.captionLabel.getMeasuredHeight();
  369. if (offset) {
  370. this.captionLabel.y = 0.5 * this.height + offset;
  371. } else {
  372. this.captionLabel.y = 0.5 * this.height;
  373. }
  374.  
  375. this.width = this.captionLabel.x + this.captionLabel.getMeasuredWidth();
  376. var mt = this.getChildAt(0);
  377. mt.graphics.c().beginFill(this.bgndColor).drawRect(0, 0, this.width, this.height).endFill();
  378. };
  379.  
  380. PJRadioButton.prototype.setWidth = function (w) {
  381. this.width = w;
  382. this.mt.graphics.clear().beginFill(this.bgndColor).drawRect(0, 0, this.width, this.height).endFill();
  383. };
  384. return PJRadioButton;
  385. })(createjs.Container); //class
  386. ///<reference path='../../common/ts/easeljs.d.ts'/>
  387. var Wood = (function () {
  388. function Wood() {
  389. }
  390. Wood.jtCornerMT = 0;
  391. Wood.jtDoubleMT = 2;
  392. Wood.jtGroovedFrameMT = 1;
  393. Wood.jtHaunchedMT = 3;
  394. Wood.jtLooseWedgedMT = 4;
  395. Wood.jtStoppedMT = 5;
  396. Wood.jtThroughMT = 6;
  397. Wood.jtTwinMT1 = 7;
  398. Wood.jtTwinMT2 = 8;
  399. Wood.jtWedgedMT = 9;
  400. Wood.jtDowel1 = 10;
  401.  
  402. Wood.jtDowel2 = 11;
  403. Wood.jtDowel3 = 12;
  404. Wood.jtDowelButt = 36;
  405. Wood.jtCornerBridle = 14;
  406. Wood.jtTBridle = 15;
  407. Wood.jtLap = 21;
  408. Wood.jtCornerHalving = 17;
  409. Wood.jtTHalving = 18;
  410. Wood.jtCrossHalving = 19;
  411. Wood.jtDovetailHalving = 20;
  412.  
  413. Wood.jtThroughDovetail = 16;
  414. Wood.jtLappedDovetail = 22;
  415. Wood.jtFinger = 23;
  416. Wood.jtStoppedHousing = 24;
  417. Wood.jtThroughHousing = 25;
  418. Wood.jtEdgeToEdgeButt = 26;
  419. Wood.jtMitredButt1 = 27;
  420. Wood.jtMitredButt2 = 28;
  421. Wood.jtSplinedEdgeToEdge = 29;
  422. Wood.jtSplinedMitre = 30;
  423.  
  424. Wood.jtSquareEndButt = 31;
  425. Wood.jtSquareEndButt2 = 32;
  426. Wood.jtTongueGroove = 33;
  427. Wood.jtGroove = 38;
  428. Wood.jtBiscuit = 35;
  429. Wood.jtButtRub = 13;
  430. Wood.jtDwrGroove = 37;
  431. Wood.jtRebate = 34;
  432.  
  433. Wood.clfFace = 0;
  434. Wood.clfEndGrain = 1;
  435. Wood.clfHole = 2;
  436. Wood.clfDowel = 3;
  437. Wood.clfDowelHole = 4;
  438. Wood.clfPanel = 5;
  439. return Wood;
  440. })();
  441.  
  442. var Vertex = (function () {
  443. function Vertex(x, y, z) {
  444. this.x = x;
  445. this.y = y;
  446. this.z = z;
  447. }
  448. return Vertex;
  449. })();
  450.  
  451. var Matrix = (function () {
  452. function Matrix() {
  453. this.m = new Array(3);
  454. this.m[0] = [1, 0, 0];
  455. this.m[1] = [0, 1, 0];
  456. this.m[2] = [0, 0, 1];
  457. }
  458. return Matrix;
  459. })();
  460.  
  461. var RotationMatrix = (function (_super) {
  462. __extends(RotationMatrix, _super);
  463. function RotationMatrix(deg, style) {
  464. _super.call(this);
  465.  
  466. var a = deg * Math.PI / 180;
  467. var c = Math.cos(a);
  468. var s = Math.sin(a);
  469.  
  470. if (style == 0) {
  471. this.m[1][1] = c;
  472. this.m[1][2] = -s;
  473. this.m[2][1] = s;
  474. this.m[2][2] = c;
  475. } else if (style == 1) {
  476. this.m[0][0] = c;
  477. this.m[0][2] = s;
  478. this.m[2][0] = -s;
  479. this.m[2][2] = c;
  480. } else {
  481. this.m[0][0] = c;
  482. this.m[0][1] = s;
  483. this.m[1][0] = -s;
  484. this.m[1][1] = c;
  485. }
  486. }
  487. return RotationMatrix;
  488. })(Matrix);
  489.  
  490. //************************************************************************************************************
  491. var BaseJoint = (function () {
  492. function BaseJoint() {
  493. this.vertexList = [];
  494. this.faceList = [];
  495. this.xOffset = 0;
  496. this.yOffset = 0;
  497. }
  498. BaseJoint.prototype.draw = function (g) {
  499. };
  500.  
  501. BaseJoint.prototype.rotate = function (ax, ay) {
  502. };
  503.  
  504. BaseJoint.prototype.explode = function (g, dx) {
  505. };
  506. return BaseJoint;
  507. })();
  508.  
  509. var eyePos = 1000;
  510. var zoom = 0.75 * eyePos;
  511. var clEdge = '#5b3a3a';
  512. var clDowelEdge = '#8C8056';
  513. var lightPos = new Vertex(-1000, -1000, -1000);
  514.  
  515. //************************************************************************************************************
  516. //p1 is next vertex anticlockwise from p0
  517. //p2 -> vertex clockwise from P0
  518. //Calculates the cosine of the angle between the unit normal to the face and a
  519. //unit vector from the face to the eye position. Dot product of these vectors.
  520. //If -90 <= angle <= 90 then the cosine is +ve and the face is visible
  521. function visible3DFace(p0, p1, p2) {
  522. var a = (p1.y - p0.y) * (p2.z - p0.z) - (p2.y - p0.y) * (p1.z - p0.z);
  523. var b = -((p1.x - p0.x) * (p2.z - p0.z) - (p2.x - p0.x) * (p1.z - p0.z));
  524. var c = (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
  525.  
  526. return (-p0.x * a - p0.y * b + c * (-eyePos - p0.z)) > 0;
  527. }
  528.  
  529. //************************************************************************************************************
  530. //p1 is next vertex anticlockwise from p0
  531. //p2 -> vertex clockwise from P0
  532. //Calculates the cosine of the angle between the unit normal to the face and a
  533. //unit vector from the face to the light position. Dot product of these vectors
  534. function getFaceColor(p0, p1, p2, baseColor) {
  535. var res = '';
  536. var a = (p1.y - p0.y) * (p2.z - p0.z) - (p2.y - p0.y) * (p1.z - p0.z);
  537. var b = -((p1.x - p0.x) * (p2.z - p0.z) - (p2.x - p0.x) * (p1.z - p0.z));
  538. var c = (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
  539. var magN = Math.sqrt(a * a + b * b + c * c);
  540. var magV = 1 / Math.sqrt((lightPos.x - p0.x) * (lightPos.x - p0.x) + (lightPos.y - p0.y) * (lightPos.y - p0.y) + (lightPos.z - p0.z) * (lightPos.z - p0.z));
  541. magN = magV / magN;
  542. var cs = (lightPos.x - p0.x) * a * magN + (lightPos.y - p0.y) * b * magN + c * (lightPos.z - p0.z) * magN;
  543. if (cs < -1)
  544. cs = -1;
  545. else if (cs > 1)
  546. cs = 1;
  547.  
  548. var n = Math.floor(Math.acos(cs) * 180 / Math.PI * 0.67);
  549. var r, g;
  550.  
  551. switch (baseColor) {
  552. case Wood.clfFace:
  553. if (n <= 90) {
  554. r = 240 - n;
  555. g = 180 - n;
  556. b = 90 - n;
  557. } else {
  558. r = 240 - n;
  559. g = 180 - n;
  560. b = 0;
  561. }
  562. break;
  563. case Wood.clfEndGrain:
  564. r = 0xff - n;
  565. g = 0xca - n;
  566. b = 0x9f - n;
  567. break;
  568. case Wood.clfDowel:
  569. r = 255 - n;
  570. g = 225 - n;
  571. b = 120;
  572. break;
  573. case Wood.clfDowelHole:
  574. r = 225 - n;
  575. g = 160 - n;
  576. b = 0;
  577. break;
  578. case Wood.clfPanel:
  579. r = 255 - n;
  580. g = 220 - n;
  581. b = 150 - n;
  582. break;
  583. default:
  584. //holes
  585. r = 190 - n;
  586. g = 120 - n;
  587. b = 0;
  588. }
  589. res = 'RGB(' + r.toFixed() + ', ' + g.toFixed() + ', ' + b.toFixed() + ')';
  590. return res;
  591. }
  592.  
  593. //************************************************************************************************************
  594. //Projection of 3D point on the viewing plane
  595. function get2dPoint(p, xOff, yOff) {
  596. var r = zoom / (eyePos + p.z);
  597. return new createjs.Point(r * p.x + xOff, r * p.y + yOff);
  598. }
  599.  
  600. function get2dPointEx(p, xOff, yOff, zoomScale) {
  601. var r = zoomScale / (eyePos + p.z);
  602. return new createjs.Point(r * p.x + xOff, r * p.y + yOff);
  603. }
  604.  
  605. //************************************************************************************************************
  606. function matMultiply(m1, m2) {
  607. var mat = new Matrix();
  608. var h, j, k;
  609. var n;
  610. for (h = 0; h < 3; h++) {
  611. for (j = 0; j < 3; j++) {
  612. n = 0;
  613. for (k = 0; k < 3; k++) {
  614. n = n + m1.m[h][k] * m2.m[k][j];
  615. }
  616. mat.m[h][j] = n;
  617. }
  618. }
  619.  
  620. return mat;
  621. }
  622.  
  623. //************************************************************************************************************
  624. //Transform a vertex, p with the matrix, mat
  625. function applyMatrix(p, mat) {
  626. var x = (p.x * mat.m[0][0] + p.y * mat.m[1][0] + p.z * mat.m[2][0]);
  627. var y = (p.x * mat.m[0][1] + p.y * mat.m[1][1] + p.z * mat.m[2][1]);
  628. var z = (p.x * mat.m[0][2] + p.y * mat.m[1][2] + p.z * mat.m[2][2]);
  629. return new Vertex(x, y, z);
  630. }
  631.  
  632. //************************************************************************************************************
  633. //Return a joint name from the joint ID
  634. function getJointName(nID) {
  635. var res = '';
  636. switch (nID) {
  637. case Wood.jtBiscuit:
  638. res = 'Biscuit joint';
  639. break;
  640. case Wood.jtButtRub:
  641. res = 'Butt rub joint';
  642. break;
  643. case Wood.jtCornerBridle:
  644. res = 'Corner Bridle joint';
  645. break;
  646. case Wood.jtCornerHalving:
  647. res = 'Corner Halving joint';
  648. break;
  649. case Wood.jtCornerMT:
  650. res = 'Corner mortise & tenon';
  651. break;
  652. case Wood.jtCrossHalving:
  653. res = 'Cross Halving joint';
  654. break;
  655. case Wood.jtDoubleMT:
  656. res = 'Forked mortise + tenon';
  657. break;
  658. case Wood.jtDovetailHalving:
  659. res = 'Dovetail Halving joint';
  660. break;
  661. case Wood.jtDowel1:
  662. res = 'Dowel joint(1)';
  663. break;
  664. case Wood.jtDowel2:
  665. res = 'Dowel joint(2)';
  666. break;
  667. case Wood.jtDowel3:
  668. res = 'Dowel joint(3)';
  669. break;
  670. case Wood.jtDowelButt:
  671. res = 'Dowelled butt joint';
  672. break;
  673. case Wood.jtEdgeToEdgeButt:
  674. res = 'Edge to edge butt joint';
  675. break;
  676. case Wood.jtFinger:
  677. res = 'Finger joint';
  678. break;
  679. case Wood.jtGroove:
  680. res = 'Groove (1)';
  681. break;
  682. case Wood.jtGroovedFrameMT:
  683. res = 'Grooved-frame mortise & tenon';
  684. break;
  685. case Wood.jtHaunchedMT:
  686. res = 'Haunched mortise & tenon';
  687. break;
  688. case Wood.jtLap:
  689. res = 'Lap joint';
  690. break;
  691. case Wood.jtLappedDovetail:
  692. res = 'Lapped Dovetail';
  693. break;
  694. case Wood.jtLooseWedgedMT:
  695. res = 'Loose wedged mortise & tenon';
  696. break;
  697. case Wood.jtMitredButt1:
  698. res = 'Mitred butt joint(1)';
  699. break;
  700. case Wood.jtMitredButt2:
  701. res = 'Mitred butt joint(2)';
  702. break;
  703. case Wood.jtSplinedEdgeToEdge:
  704. res = 'Splined edge to edge';
  705. break;
  706. case Wood.jtSplinedMitre:
  707. res = 'Splined mitre joint';
  708. break;
  709. case Wood.jtSquareEndButt:
  710. res = 'Square ended butt joint(1)';
  711. break;
  712. case Wood.jtSquareEndButt2:
  713. res = 'Square ended butt joint(2)';
  714. break;
  715. case Wood.jtStoppedHousing:
  716. res = 'Stopped Housing';
  717. break;
  718. case Wood.jtStoppedMT:
  719. res = 'Stopped mortise & tenon';
  720. break;
  721. case Wood.jtTBridle:
  722. res = 'T-Bridle joint';
  723. break;
  724. case Wood.jtTHalving:
  725. res = 'T-Halving joint';
  726. break;
  727. case Wood.jtThroughDovetail:
  728. res = 'Through Dovetail';
  729. break;
  730. case Wood.jtThroughHousing:
  731. res = 'Through Housing';
  732. break;
  733. case Wood.jtThroughMT:
  734. res = 'Through mortise & tenon';
  735. break;
  736. case Wood.jtTongueGroove:
  737. res = 'Tongue+Groove joint';
  738. break;
  739. case Wood.jtTwinMT1:
  740. res = 'Twin mortise & tenon(1)';
  741. break;
  742. case Wood.jtTwinMT2:
  743. res = 'Twin mortise & tenon(2)';
  744. break;
  745. case Wood.jtWedgedMT:
  746. res = 'Wedged mortise + tenon';
  747. break;
  748. case Wood.jtDwrGroove:
  749. res = 'Groove (2)';
  750. break;
  751. case Wood.jtRebate:
  752. res = 'Rebate joint';
  753. break;
  754. default:
  755. res = '';
  756. }
  757. return res;
  758. }
  759.  
  760. //***************************************************************************************************************
  761. //Return path + filename for the ajax_* file with the joint info
  762. function getInfoFilename(nID) {
  763. var res = '';
  764. switch (nID) {
  765. case Wood.jtBiscuit:
  766. res = 'ajax_e2e_biscuit.html';
  767. break;
  768. case Wood.jtButtRub:
  769. res = 'ajax_butt_rub.html';
  770. break;
  771. case Wood.jtCornerBridle:
  772. res = 'ajax_bridle_corner.html';
  773. break;
  774. case Wood.jtCornerHalving:
  775. res = 'ajax_halving_corner.html';
  776. break;
  777. case Wood.jtCornerMT:
  778. res = 'ajax_corner_mt.html';
  779. break;
  780. case Wood.jtCrossHalving:
  781. res = 'ajax_halving_cross.html';
  782. break;
  783. case Wood.jtDoubleMT:
  784. res = 'ajax_double_mt.html';
  785. break;
  786. case Wood.jtDovetailHalving:
  787. res = 'ajax_halving_tee.html';
  788. break;
  789. case Wood.jtDowel1:
  790. res = 'ajax_dowel.html';
  791. break;
  792. case Wood.jtDowel2:
  793. res = 'ajax_dowel.html';
  794. break;
  795. case Wood.jtDowel3:
  796. res = 'ajax_dowel.html';
  797. break;
  798. case Wood.jtDowelButt:
  799. res = 'ajax_dowel_butt.html';
  800. break;
  801. case Wood.jtEdgeToEdgeButt:
  802. res = 'ajax_e2e_butt.html';
  803. break;
  804. case Wood.jtFinger:
  805. res = 'ajax_finger.html';
  806. break;
  807. case Wood.jtGroove:
  808. res = 'ajax_rebate.html';
  809. break;
  810. case Wood.jtGroovedFrameMT:
  811. res = 'ajax_grooved_frame_mt.html';
  812. break;
  813. case Wood.jtHaunchedMT:
  814. res = 'ajax_haunched_mt.html';
  815. break;
  816. case Wood.jtLap:
  817. res = 'ajax_lap.html';
  818. break;
  819. case Wood.jtLappedDovetail:
  820. res = 'ajax_lapped_dovetail.html';
  821. break;
  822. case Wood.jtLooseWedgedMT:
  823. res = 'ajax_loose_wedged_mt.html';
  824. break;
  825. case Wood.jtMitredButt1:
  826. res = 'ajax_mitre_butt.html';
  827. break;
  828. case Wood.jtMitredButt2:
  829. res = 'ajax_mitre_butt.html';
  830. break;
  831. case Wood.jtSplinedEdgeToEdge:
  832. res = 'ajax_e2e_splined.html';
  833. break;
  834. case Wood.jtSplinedMitre:
  835. res = 'ajax_mitre_splined.html';
  836. break;
  837. case Wood.jtSquareEndButt:
  838. res = 'ajax_sq_end_butt.html';
  839. break;
  840. case Wood.jtSquareEndButt2:
  841. res = 'ajax_sq_end_butt.html';
  842. break;
  843. case Wood.jtStoppedHousing:
  844. res = 'ajax_stopped_housing.html';
  845. break;
  846. case Wood.jtStoppedMT:
  847. res = 'ajax_stopped_mt.html';
  848. break;
  849. case Wood.jtTBridle:
  850. res = 'ajax_bridle_tee.html';
  851. break;
  852. case Wood.jtTHalving:
  853. res = 'ajax_halving_tee.html';
  854. break;
  855. case Wood.jtThroughDovetail:
  856. res = 'ajax_through_dovetail.html';
  857. break;
  858. case Wood.jtThroughHousing:
  859. res = 'ajax_through_housing.html';
  860. break;
  861. case Wood.jtThroughMT:
  862. res = 'ajax_through_mt.html';
  863. break;
  864. case Wood.jtTongueGroove:
  865. res = 'ajax_e2e_grooved.html';
  866. break;
  867. case Wood.jtTwinMT1:
  868. res = 'ajax_twin_mt.html';
  869. break;
  870. case Wood.jtTwinMT2:
  871. res = 'ajax_twin_mt.html';
  872. break;
  873. case Wood.jtWedgedMT:
  874. res = 'ajax_loose_wedged_mt.html';
  875. break;
  876. case Wood.jtDwrGroove:
  877. res = 'ajax_drawer_groove.html';
  878. break;
  879. case Wood.jtRebate:
  880. res = 'ajax_rebate.html';
  881. break;
  882. default:
  883. res = '';
  884. }
  885. res = '/programmes/woodjoints/pages/' + res;
  886. return res;
  887. }
  888. ///<reference path='../../common/ts/easeljs.d.ts'/>
  889. var Thumbnail = (function (_super) {
  890. __extends(Thumbnail, _super);
  891. function Thumbnail(tn, jointID, hotspot) {
  892. _super.call(this);
  893. this.jointID = jointID;
  894. this.hotspot = hotspot;
  895. this.selRect = new createjs.Shape();
  896. var bgnd = new createjs.Shape();
  897. bgnd.graphics.f('#ffffff').drawRect(0, 0, 72, 50);
  898. this.addChild(bgnd);
  899. this.addChild(tn);
  900. bgnd.addEventListener('mousedown', this.doClick);
  901.  
  902. //#445DF4
  903. //#81A1FB
  904. this.selRect.graphics.s('#445DF4').dr(0, 0, 70, 50);
  905. this.addChild(this.selRect);
  906. this.selRect.visible = false;
  907. }
  908. Thumbnail.prototype.doClick = function (e) {
  909. var p = e.target.parent;
  910. if (p.fcallback) {
  911. p.fcallback(p.jointID, p.hotspot);
  912. }
  913. };
  914.  
  915. Thumbnail.prototype.addCallback = function (f) {
  916. this.fcallback = f;
  917. };
  918.  
  919. Thumbnail.prototype.setSelected = function (value) {
  920. this.selRect.visible = value;
  921. };
  922. return Thumbnail;
  923. })(createjs.Container); //class
  924. ///<reference path='../../common/ts/easeljs.d.ts'/>
  925. ///<reference path='wood3d.ts'/>
  926. var ButtRubJoint = (function (_super) {
  927. __extends(ButtRubJoint, _super);
  928. function ButtRubJoint(dx) {
  929. _super.call(this);
  930. this.dlist = [];
  931. this.xShift = 0;
  932. this.xShift = dx;
  933. this.vertexList = new Array(24);
  934. this.initJoint();
  935. this.initFaceList();
  936. }
  937. ButtRubJoint.prototype.initJoint = function () {
  938. var dy = 100;
  939.  
  940. this.vertexList[0] = new Vertex(this.xShift + 200, -dy, 70);
  941. this.vertexList[1] = new Vertex(this.xShift + 200, -dy, 100);
  942. this.vertexList[2] = new Vertex(this.xShift, -dy, 100);
  943. this.vertexList[3] = new Vertex(this.xShift, -dy, 70);
  944. this.vertexList[4] = new Vertex(this.xShift + 200, dy, 70);
  945. this.vertexList[5] = new Vertex(this.xShift + 200, dy, 100);
  946. this.vertexList[6] = new Vertex(this.xShift, dy, 100);
  947. this.vertexList[7] = new Vertex(this.xShift, dy, 70);
  948.  
  949. this.vertexList[8] = new Vertex(-this.xShift, -dy, -200);
  950. this.vertexList[9] = new Vertex(-this.xShift, -dy, 100);
  951. this.vertexList[10] = new Vertex(-this.xShift - 30, -dy, 100);
  952. this.vertexList[11] = new Vertex(-this.xShift - 30, -dy, -200);
  953. this.vertexList[12] = new Vertex(-this.xShift, dy, -200);
  954. this.vertexList[13] = new Vertex(-this.xShift, dy, 100);
  955. this.vertexList[14] = new Vertex(-this.xShift - 30, dy, 100);
  956. this.vertexList[15] = new Vertex(-this.xShift - 30, dy, -200);
  957.  
  958. this.vertexList[16] = new Vertex(this.xShift, -dy, -this.xShift + 25);
  959. this.vertexList[17] = new Vertex(this.xShift + 50, -dy, -this.xShift + 70);
  960. this.vertexList[18] = new Vertex(this.xShift, -dy, -this.xShift + 70);
  961.  
  962. this.vertexList[19] = new Vertex(this.xShift, dy, -this.xShift + 25);
  963. this.vertexList[20] = new Vertex(this.xShift + 50, dy, -this.xShift + 70);
  964. this.vertexList[21] = new Vertex(this.xShift, dy, -this.xShift + 70);
  965.  
  966. this.vertexList[22] = new Vertex(this.xShift + 50, -dy, -this.xShift + 25);
  967. this.vertexList[23] = new Vertex(this.xShift + 50, dy, -this.xShift + 25);
  968. };
  969.  
  970. ButtRubJoint.prototype.initFaceList = function () {
  971. this.faceList = new Array(17);
  972. this.faceList[0] = [1, 0, 4, 5];
  973. this.faceList[1] = [3, 2, 6, 7];
  974. this.faceList[2] = [0, 1, 2, 3];
  975. this.faceList[3] = [0, 3, 7, 4];
  976. this.faceList[4] = [4, 7, 6, 5];
  977. this.faceList[5] = [8, 12, 13, 9];
  978. this.faceList[6] = [11, 10, 14, 15];
  979. this.faceList[7] = [8, 9, 10, 11];
  980. this.faceList[8] = [8, 11, 15, 12];
  981. this.faceList[9] = [12, 15, 14, 13];
  982. this.faceList[10] = [16, 19, 20, 17];
  983. this.faceList[11] = [17, 20, 21, 18];
  984. this.faceList[12] = [16, 18, 21, 19];
  985. this.faceList[13] = [16, 17, 18];
  986. this.faceList[14] = [19, 21, 20];
  987.  
  988. this.faceList[15] = [1, 5, 6, 2];
  989. this.faceList[16] = [10, 9, 13, 14];
  990. };
  991.  
  992. ButtRubJoint.prototype.drawFaces = function (g) {
  993. var j, k, n;
  994. var p0;
  995. var p1;
  996. var p2;
  997. var p;
  998. var a = [];
  999. var nface;
  1000. var face = [];
  1001. var color;
  1002. var p2d;
  1003. g.clear();
  1004. for (j = 0; j < this.dlist.length; j++) {
  1005. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  1006. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  1007. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  1008. if (visible3DFace(p0, p1, p2)) {
  1009. nface = this.dlist[j];
  1010. face = this.faceList[nface];
  1011. a = new Array(face.length);
  1012. for (k = 0; k < face.length; k++) {
  1013. p = this.vertexList[face[k]];
  1014. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  1015. }
  1016.  
  1017. switch (nface) {
  1018. case 2:
  1019. case 4:
  1020. case 7:
  1021. case 9:
  1022. case 13:
  1023. case 14:
  1024. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1025. break;
  1026. default:
  1027. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1028. }
  1029.  
  1030. g.f(color).s(clEdge);
  1031. g.mt(a[0].x, a[0].y);
  1032. for (n = 1; n < face.length; n++) {
  1033. g.lt(a[n].x, a[n].y);
  1034. }
  1035. g.cp().es().ef();
  1036. }
  1037. }
  1038. };
  1039.  
  1040. //***************************************************************************************************************
  1041. ButtRubJoint.prototype.draw = function (g) {
  1042. var j;
  1043. var mx = new RotationMatrix(rx, 0);
  1044. var my = new RotationMatrix(ry, 1);
  1045. var mat = matMultiply(mx, my);
  1046.  
  1047. this.initJoint();
  1048.  
  1049. for (j = 0; j < this.vertexList.length; j++) {
  1050. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  1051. }
  1052.  
  1053. if (rx >= 0) {
  1054. if (ry > 90) {
  1055. this.dlist = [5, 11, 12, 13, 1, 15, 2, 6, 7, 16]; //<<<<<<<<<<<<<<<
  1056. } else if (ry >= 0) {
  1057. this.dlist = [0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9];
  1058. } else if (ry >= -90) {
  1059. this.dlist = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14];
  1060. } else {
  1061. this.dlist = [5, 7, 16, 3, 10, 12, 13, 11, 15, 1, 2, 0];
  1062. }
  1063. } else if (rx < 0) {
  1064. if (ry > 90) {
  1065. this.dlist = [3, 11, 12, 14, 15, 4, 1, 5, 6, 9, 16];
  1066. } else if (ry >= 0) {
  1067. this.dlist = [1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 5, 6, 7, 8, 9];
  1068. } else if (ry >= -90) {
  1069. this.dlist = [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 10, 11, 12, 13, 14];
  1070. } else {
  1071. this.dlist = [5, 9, 16, 3, 10, 11, 12, 13, 14, 0, 1, 4, 15];
  1072. }
  1073. }
  1074.  
  1075. this.drawFaces(g);
  1076. };
  1077.  
  1078. ButtRubJoint.prototype.explode = function (g, dx) {
  1079. this.xShift = dx;
  1080. this.draw(g);
  1081. };
  1082. return ButtRubJoint;
  1083. })(BaseJoint);
  1084. ///<reference path='../../common/ts/easeljs.d.ts'/>
  1085. ///<reference path='wood3d.ts'/>
  1086. var ThroughDovetail = (function (_super) {
  1087. __extends(ThroughDovetail, _super);
  1088. function ThroughDovetail(dx) {
  1089. _super.call(this);
  1090. this.dlist = [];
  1091. this.xShift = 0;
  1092. this.xShift = dx;
  1093. this.vertexList = new Array(48);
  1094. this.initJoint();
  1095. this.initFaceList();
  1096. }
  1097. //private initJoint() {
  1098. //var dz:number = -15;
  1099. ////left
  1100. //this.vertexList[0] = new Vertex( -150, -50, dz);
  1101. //this.vertexList[1] = new Vertex(30, -50, dz);
  1102. //this.vertexList[2] = new Vertex(30, -30, dz);
  1103. //this.vertexList[3] = new Vertex(0, -30, dz);
  1104. //this.vertexList[4] = new Vertex(0, 40, dz);
  1105. //this.vertexList[5] = new Vertex(30, 40, dz);
  1106. //this.vertexList[6] = new Vertex(30, 60, dz);
  1107. //this.vertexList[7] = new Vertex(0, 60, dz);
  1108. //this.vertexList[8] = new Vertex(0, 130, dz);
  1109. //this.vertexList[9] = new Vertex(30, 130, dz);
  1110. //this.vertexList[10] = new Vertex(30, 150, dz);
  1111. //this.vertexList[11] = new Vertex( -150, 150, dz);
  1112. //
  1113. //this.vertexList[12] = new Vertex( -150, -50, -dz);
  1114. //this.vertexList[13] = new Vertex(30, -50, -dz);
  1115. //this.vertexList[14] = new Vertex(30, -25, -dz);
  1116. //this.vertexList[15] = new Vertex(0, -25, -dz);
  1117. //this.vertexList[16] = new Vertex(0, 35, -dz);
  1118. //this.vertexList[17] = new Vertex(30, 35, -dz);
  1119. //this.vertexList[18] = new Vertex(30, 65, -dz);
  1120. //this.vertexList[19] = new Vertex(0, 65, -dz);
  1121. //this.vertexList[20] = new Vertex(0, 125, -dz);
  1122. //this.vertexList[21] = new Vertex(30, 125, -dz);
  1123. //this.vertexList[22] = new Vertex(30, 150, -dz);
  1124. //this.vertexList[23] = new Vertex( -150, 150, -dz);
  1125. //
  1126. ////socket half of Dovetail
  1127. //this.vertexList[24] = new Vertex(30 + this.xShift, -50, 15);
  1128. //this.vertexList[25] = new Vertex(30 + this.xShift, -25, 15);
  1129. //this.vertexList[26] = new Vertex(30 + this.xShift, -30, -15);
  1130. //this.vertexList[27] = new Vertex(30 + this.xShift, 40, -15);
  1131. //this.vertexList[28] = new Vertex(30 + this.xShift, 35, 15);
  1132. //this.vertexList[29] = new Vertex(30 + this.xShift, 65, 15);
  1133. //this.vertexList[30] = new Vertex(30 + this.xShift, 60, -15);
  1134. //this.vertexList[31] = new Vertex(30 + this.xShift, 130, -15);
  1135. //this.vertexList[32] = new Vertex(30 + this.xShift, 125, 15);
  1136. //this.vertexList[33] = new Vertex(30 + this.xShift, 150, 15);
  1137. //this.vertexList[34] = new Vertex(30 + this.xShift, 150, 150);
  1138. //this.vertexList[35] = new Vertex(30 + this.xShift, -50, 150);
  1139. //
  1140. //this.vertexList[36] = new Vertex(this.xShift, -50, 15);
  1141. //this.vertexList[37] = new Vertex(this.xShift, -25, 15);
  1142. //this.vertexList[38] = new Vertex(this.xShift, -30, -15);
  1143. //this.vertexList[39] = new Vertex(this.xShift, 40, -15);
  1144. //this.vertexList[40] = new Vertex(this.xShift, 35, 15);
  1145. //this.vertexList[41] = new Vertex(this.xShift, 65, 15);
  1146. //this.vertexList[42] = new Vertex(this.xShift, 60, -15);
  1147. //this.vertexList[43] = new Vertex(this.xShift, 130, -15);
  1148. //this.vertexList[44] = new Vertex(this.xShift, 125, 15);
  1149. //this.vertexList[45] = new Vertex(this.xShift, 150, 15);
  1150. //this.vertexList[46] = new Vertex(this.xShift, 150, 150);
  1151. //this.vertexList[47] = new Vertex(this.xShift, -50, 150);
  1152. //}
  1153. ThroughDovetail.prototype.initJoint = function () {
  1154. var dz = -15;
  1155. var dx = 0.5 * this.xShift;
  1156.  
  1157. //left
  1158. this.vertexList[0] = new Vertex(-150 - dx, -50, dz);
  1159. this.vertexList[1] = new Vertex(30 - dx, -50, dz);
  1160. this.vertexList[2] = new Vertex(30 - dx, -30, dz);
  1161. this.vertexList[3] = new Vertex(0 - dx, -30, dz);
  1162. this.vertexList[4] = new Vertex(0 - dx, 40, dz);
  1163. this.vertexList[5] = new Vertex(30 - dx, 40, dz);
  1164. this.vertexList[6] = new Vertex(30 - dx, 60, dz);
  1165. this.vertexList[7] = new Vertex(0 - dx, 60, dz);
  1166. this.vertexList[8] = new Vertex(0 - dx, 130, dz);
  1167. this.vertexList[9] = new Vertex(30 - dx, 130, dz);
  1168. this.vertexList[10] = new Vertex(30 - dx, 150, dz);
  1169. this.vertexList[11] = new Vertex(-150 - dx, 150, dz);
  1170.  
  1171. this.vertexList[12] = new Vertex(-150 - dx, -50, -dz);
  1172. this.vertexList[13] = new Vertex(30 - dx, -50, -dz);
  1173. this.vertexList[14] = new Vertex(30 - dx, -25, -dz);
  1174. this.vertexList[15] = new Vertex(0 - dx, -25, -dz);
  1175. this.vertexList[16] = new Vertex(0 - dx, 35, -dz);
  1176. this.vertexList[17] = new Vertex(30 - dx, 35, -dz);
  1177. this.vertexList[18] = new Vertex(30 - dx, 65, -dz);
  1178. this.vertexList[19] = new Vertex(0 - dx, 65, -dz);
  1179. this.vertexList[20] = new Vertex(0 - dx, 125, -dz);
  1180. this.vertexList[21] = new Vertex(30 - dx, 125, -dz);
  1181. this.vertexList[22] = new Vertex(30 - dx, 150, -dz);
  1182. this.vertexList[23] = new Vertex(-150 - dx, 150, -dz);
  1183.  
  1184. //socket half of Dovetail
  1185. this.vertexList[24] = new Vertex(30 + dx, -50, 15);
  1186. this.vertexList[25] = new Vertex(30 + dx, -25, 15);
  1187. this.vertexList[26] = new Vertex(30 + dx, -30, -15);
  1188. this.vertexList[27] = new Vertex(30 + dx, 40, -15);
  1189. this.vertexList[28] = new Vertex(30 + dx, 35, 15);
  1190. this.vertexList[29] = new Vertex(30 + dx, 65, 15);
  1191. this.vertexList[30] = new Vertex(30 + dx, 60, -15);
  1192. this.vertexList[31] = new Vertex(30 + dx, 130, -15);
  1193. this.vertexList[32] = new Vertex(30 + dx, 125, 15);
  1194. this.vertexList[33] = new Vertex(30 + dx, 150, 15);
  1195. this.vertexList[34] = new Vertex(30 + dx, 150, 150);
  1196. this.vertexList[35] = new Vertex(30 + dx, -50, 150);
  1197.  
  1198. this.vertexList[36] = new Vertex(dx, -50, 15);
  1199. this.vertexList[37] = new Vertex(dx, -25, 15);
  1200. this.vertexList[38] = new Vertex(dx, -30, -15);
  1201. this.vertexList[39] = new Vertex(dx, 40, -15);
  1202. this.vertexList[40] = new Vertex(dx, 35, 15);
  1203. this.vertexList[41] = new Vertex(dx, 65, 15);
  1204. this.vertexList[42] = new Vertex(dx, 60, -15);
  1205. this.vertexList[43] = new Vertex(dx, 130, -15);
  1206. this.vertexList[44] = new Vertex(dx, 125, 15);
  1207. this.vertexList[45] = new Vertex(dx, 150, 15);
  1208. this.vertexList[46] = new Vertex(dx, 150, 150);
  1209. this.vertexList[47] = new Vertex(dx, -50, 150);
  1210. };
  1211.  
  1212. ThroughDovetail.prototype.initFaceList = function () {
  1213. this.faceList = new Array(30);
  1214. this.faceList[0] = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
  1215. this.faceList[1] = [0, 1, 13, 12];
  1216. this.faceList[2] = [0, 12, 23, 11];
  1217. this.faceList[3] = [10, 11, 23, 22];
  1218. this.faceList[4] = [2, 14, 13, 1];
  1219. this.faceList[5] = [2, 3, 15, 14];
  1220. this.faceList[6] = [4, 5, 17, 16];
  1221. this.faceList[7] = [6, 18, 17, 5];
  1222. this.faceList[8] = [6, 7, 19, 18];
  1223. this.faceList[9] = [8, 9, 21, 20];
  1224. this.faceList[10] = [10, 22, 21, 9];
  1225. this.faceList[11] = [4, 16, 15, 3];
  1226. this.faceList[12] = [8, 20, 19, 7];
  1227. this.faceList[13] = [35, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34];
  1228. this.faceList[14] = [36, 24, 35, 47];
  1229. this.faceList[15] = [33, 45, 46, 34];
  1230. this.faceList[16] = [37, 25, 24, 36];
  1231. this.faceList[17] = [38, 26, 25, 37];
  1232. this.faceList[18] = [39, 27, 26, 38];
  1233. this.faceList[19] = [27, 39, 40, 28];
  1234. this.faceList[20] = [41, 29, 28, 40];
  1235. this.faceList[21] = [42, 30, 29, 41];
  1236. this.faceList[22] = [43, 31, 30, 42];
  1237. this.faceList[23] = [31, 43, 44, 32];
  1238. this.faceList[24] = [45, 33, 32, 44];
  1239. this.faceList[25] = [36, 47, 46, 45];
  1240. this.faceList[26] = [40, 39, 38, 37];
  1241. this.faceList[27] = [44, 43, 42, 41];
  1242.  
  1243. this.faceList[28] = [34, 46, 47, 35];
  1244. this.faceList[29] = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
  1245. };
  1246.  
  1247. ThroughDovetail.prototype.drawFaces = function (g) {
  1248. var j, k, n;
  1249. var p0;
  1250. var p1;
  1251. var p2;
  1252. var p;
  1253. var a = [];
  1254. var nface;
  1255. var face = [];
  1256. var color;
  1257. var ap;
  1258. g.clear();
  1259. for (j = 0; j < this.dlist.length; j++) {
  1260. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  1261. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  1262. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  1263. if (visible3DFace(p0, p1, p2)) {
  1264. nface = this.dlist[j];
  1265. face = this.faceList[nface];
  1266. a = new Array(face.length);
  1267. for (k = 0; k < face.length; k++) {
  1268. p = this.vertexList[face[k]];
  1269. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  1270. }
  1271.  
  1272. switch (nface) {
  1273. case 2:
  1274. case 4:
  1275. case 7:
  1276. case 10:
  1277. case 11:
  1278. case 12:
  1279. case 16:
  1280. case 18:
  1281. case 20:
  1282. case 22:
  1283. case 24:
  1284. case 28:
  1285. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1286. g.f(color).s(clEdge);
  1287. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef().es();
  1288. break;
  1289.  
  1290. case 25:
  1291. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1292.  
  1293. if (this.xShift > 0) {
  1294. g.f(color).ss(1, 2).s(color);
  1295. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef();
  1296.  
  1297. ap = get2dPoint(this.vertexList[37], this.xOffset, this.yOffset);
  1298. g.s(clEdge).mt(ap.x, ap.y).lt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y);
  1299.  
  1300. ap = get2dPoint(this.vertexList[40], this.xOffset, this.yOffset);
  1301. g.mt(ap.x, ap.y);
  1302. ap = get2dPoint(this.vertexList[41], this.xOffset, this.yOffset);
  1303. g.lt(ap.x, ap.y);
  1304. ap = get2dPoint(this.vertexList[44], this.xOffset, this.yOffset);
  1305. g.mt(ap.x, ap.y).lt(a[3].x, a[3].y).es();
  1306. } else {
  1307. g.f(color).s(clEdge).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef().es();
  1308. }
  1309. break;
  1310.  
  1311. case 26:
  1312. case 27:
  1313. color = getFaceColor(this.vertexList[47], this.vertexList[46], this.vertexList[36], Wood.clfFace);
  1314. g.f(color).ss(1, 2).s(color);
  1315. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef();
  1316. g.s(clEdge).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y);
  1317.  
  1318. break;
  1319. default:
  1320. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1321. g.f(color).s(clEdge);
  1322. g.mt(a[0].x, a[0].y);
  1323. for (n = 1; n < face.length; n++) {
  1324. g.lt(a[n].x, a[n].y);
  1325. }
  1326. g.cp().es().ef();
  1327. }
  1328. }
  1329. }
  1330. };
  1331.  
  1332. //***************************************************************************************************************
  1333. ThroughDovetail.prototype.draw = function (g) {
  1334. var j;
  1335. var mx = new RotationMatrix(rx, 0);
  1336. var my = new RotationMatrix(ry, 1);
  1337. var mat = matMultiply(mx, my);
  1338.  
  1339. this.initJoint();
  1340.  
  1341. for (j = 0; j < this.vertexList.length; j++) {
  1342. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  1343. }
  1344.  
  1345. if (rx >= 0) {
  1346. if (ry > 90) {
  1347. this.dlist = [11, 12, 9, 21, 27, 6, 17, 26, 29, 25, 14, 28, 1, 2];
  1348. } else if (ry >= 0) {
  1349. this.dlist = [25, 24, 20, 16, 5, 26, 19, 6, 8, 27, 23, 9, 0, 3, 15, 18, 22, 2];
  1350. } else if (ry >= -90) {
  1351. this.dlist = [25, 16, 20, 24, 11, 12, 5, 4, 26, 18, 19, 6, 7, 8, 27, 23, 9, 10, 22, 13, 0, 15, 3]; //<<<<<<<<<<<<<<<<<<
  1352. } else {
  1353. this.dlist = [12, 11, 9, 27, 6, 10, 21, 7, 17, 26, 4, 29, 13, 14, 28, 1, 25];
  1354. }
  1355. } else if (rx < 0) {
  1356. if (ry > 90) {
  1357. this.dlist = [11, 12, 5, 26, 19, 8, 27, 23, 29, 25, 3, 2, 15, 28];
  1358. } else if (ry >= 0) {
  1359. this.dlist = [25, 14, 16, 20, 24, 9, 27, 21, 8, 6, 26, 17, 5, 22, 18, 1, 2, 0];
  1360. } else if (ry >= -90) {
  1361. this.dlist = [25, 26, 27, 12, 11, 24, 20, 16, 9, 10, 21, 8, 7, 6, 17, 5, 4, 22, 18, 13, 1, 14, 0];
  1362. } else {
  1363. this.dlist = [26, 11, 12, 5, 4, 19, 8, 7, 29, 23, 27, 25, 28, 10, 3, 15, 13];
  1364. }
  1365. }
  1366.  
  1367. this.drawFaces(g);
  1368. };
  1369.  
  1370. ThroughDovetail.prototype.explode = function (g, dx) {
  1371. this.xShift = dx;
  1372. this.draw(g);
  1373. };
  1374. return ThroughDovetail;
  1375. })(BaseJoint);
  1376. ///<reference path='../../common/ts/easeljs.d.ts'/>
  1377. ///<reference path='wood3d.ts'/>
  1378. var LapJoint = (function (_super) {
  1379. __extends(LapJoint, _super);
  1380. function LapJoint(dx) {
  1381. _super.call(this);
  1382. this.dlist = [];
  1383. this.xShift = 0;
  1384. this.xShift = dx;
  1385. this.vertexList = new Array(24);
  1386. this.initJoint();
  1387. this.initFaceList();
  1388. }
  1389. LapJoint.prototype.initJoint = function () {
  1390. var dy = 100;
  1391.  
  1392. this.vertexList[0] = new Vertex(this.xShift, -dy, 200);
  1393. this.vertexList[1] = new Vertex(this.xShift, -dy, 30);
  1394. this.vertexList[2] = new Vertex(this.xShift + 20, -dy, 30);
  1395. this.vertexList[3] = new Vertex(this.xShift + 20, -dy, 0);
  1396. this.vertexList[4] = new Vertex(this.xShift + 30, -dy, 0);
  1397. this.vertexList[5] = new Vertex(this.xShift + 30, -dy, 200);
  1398.  
  1399. this.vertexList[6] = new Vertex(this.xShift, dy, 200);
  1400. this.vertexList[7] = new Vertex(this.xShift, dy, 30);
  1401. this.vertexList[8] = new Vertex(this.xShift + 20, dy, 30);
  1402. this.vertexList[9] = new Vertex(this.xShift + 20, dy, 0);
  1403. this.vertexList[10] = new Vertex(this.xShift + 30, dy, 0);
  1404. this.vertexList[11] = new Vertex(this.xShift + 30, dy, 200);
  1405.  
  1406. this.vertexList[12] = new Vertex(-this.xShift - 200, -dy, 30);
  1407. this.vertexList[13] = new Vertex(-this.xShift - 200, -dy, 0);
  1408. this.vertexList[14] = new Vertex(-this.xShift + 20, -dy, 0);
  1409. this.vertexList[15] = new Vertex(-this.xShift + 20, -dy, 30);
  1410.  
  1411. this.vertexList[16] = new Vertex(-this.xShift - 200, dy, 30);
  1412. this.vertexList[17] = new Vertex(-this.xShift - 200, dy, 0);
  1413. this.vertexList[18] = new Vertex(-this.xShift + 20, dy, 0);
  1414. this.vertexList[19] = new Vertex(-this.xShift + 20, dy, 30);
  1415.  
  1416. //graain
  1417. this.vertexList[20] = new Vertex(this.xShift, -dy, 0);
  1418. this.vertexList[21] = new Vertex(this.xShift, dy, 0);
  1419.  
  1420. this.vertexList[22] = new Vertex(this.xShift + 30, -dy, 30);
  1421. this.vertexList[23] = new Vertex(this.xShift + 30, dy, 30);
  1422. };
  1423.  
  1424. LapJoint.prototype.initFaceList = function () {
  1425. this.faceList = new Array(14);
  1426. this.faceList[0] = [0, 6, 7, 1];
  1427. this.faceList[1] = [1, 7, 8, 2];
  1428. this.faceList[2] = [2, 8, 9, 3];
  1429. this.faceList[3] = [3, 9, 10, 4];
  1430. this.faceList[4] = [5, 4, 10, 11];
  1431. this.faceList[5] = [0, 1, 2, 3, 4, 5];
  1432. this.faceList[6] = [6, 11, 10, 9, 8, 7];
  1433. this.faceList[7] = [13, 17, 18, 14];
  1434. this.faceList[8] = [15, 14, 18, 19];
  1435. this.faceList[9] = [12, 13, 14, 15];
  1436. this.faceList[10] = [12, 16, 17, 13];
  1437. this.faceList[11] = [17, 16, 19, 18];
  1438.  
  1439. this.faceList[12] = [12, 15, 19, 16];
  1440. this.faceList[13] = [6, 0, 5, 11];
  1441. };
  1442.  
  1443. LapJoint.prototype.drawFaces = function (g) {
  1444. var j, k, n;
  1445. var p0;
  1446. var p1;
  1447. var p2;
  1448. var p;
  1449. var a = [];
  1450. var nface;
  1451. var face = [];
  1452. var color;
  1453. var p2d;
  1454. g.clear();
  1455. for (j = 0; j < this.dlist.length; j++) {
  1456. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  1457. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  1458. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  1459. if (visible3DFace(p0, p1, p2)) {
  1460. nface = this.dlist[j];
  1461. face = this.faceList[nface];
  1462. a = new Array(face.length);
  1463. for (k = 0; k < face.length; k++) {
  1464. p = this.vertexList[face[k]];
  1465. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  1466. }
  1467.  
  1468. switch (nface) {
  1469. case 1:
  1470. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1471. break;
  1472. default:
  1473. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1474. }
  1475.  
  1476. g.f(color).s(clEdge);
  1477. g.mt(a[0].x, a[0].y);
  1478. for (n = 1; n < face.length; n++) {
  1479. g.lt(a[n].x, a[n].y);
  1480. }
  1481. g.cp().es().ef();
  1482. }
  1483. }
  1484. };
  1485.  
  1486. //***************************************************************************************************************
  1487. LapJoint.prototype.draw = function (g) {
  1488. var j;
  1489. var mx = new RotationMatrix(rx, 0);
  1490. var my = new RotationMatrix(ry, 1);
  1491. var mat = matMultiply(mx, my);
  1492.  
  1493. this.initJoint();
  1494.  
  1495. for (j = 0; j < this.vertexList.length; j++) {
  1496. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  1497. }
  1498.  
  1499. if (rx >= 0) {
  1500. if (ry > 90) {
  1501. this.dlist = [1, 2, 8, 12, 10, 5, 0, 13, 9];
  1502. } else if (ry >= 0) {
  1503. this.dlist = [0, 1, 2, 3, 6, 10, 8, 7, 11, 10];
  1504. } else if (ry >= -90) {
  1505. this.dlist = [0, 1, 8, 2, 3, 4, 11, 6, 7];
  1506. } else {
  1507. this.dlist = [1, 2, 8, 12, 4, 5, 0, 13, 9];
  1508. }
  1509. } else if (rx < 0) {
  1510. if (ry > 90) {
  1511. this.dlist = [1, 2, 8, 13, 12, 10, 0, 6, 11];
  1512. } else if (ry >= 0) {
  1513. this.dlist = [0, 1, 2, 3, 5, 10, 9, 7, 8];
  1514. } else if (ry >= -90) {
  1515. this.dlist = [0, 1, 8, 2, 7, 3, 9, 5, 4];
  1516. } else {
  1517. this.dlist = [1, 2, 8, 12, 0, 11, 6, 4, 13];
  1518. }
  1519. }
  1520.  
  1521. this.drawFaces(g);
  1522. };
  1523.  
  1524. LapJoint.prototype.explode = function (g, dx) {
  1525. this.xShift = dx;
  1526. this.draw(g);
  1527. };
  1528. return LapJoint;
  1529. })(BaseJoint);
  1530. ///<reference path='../../common/ts/easeljs.d.ts'/>
  1531. ///<reference path='wood3d.ts'/>
  1532. var MitreButt2 = (function (_super) {
  1533. __extends(MitreButt2, _super);
  1534. function MitreButt2(dx) {
  1535. _super.call(this);
  1536. this.dlist = [];
  1537. this.xShift = 0;
  1538. this.xShift = dx;
  1539. this.vertexList = new Array(16);
  1540. this.initJoint();
  1541. this.initFaceList();
  1542. }
  1543. MitreButt2.prototype.initJoint = function () {
  1544. var dy = -100;
  1545. this.vertexList[0] = new Vertex(30 + this.xShift, dy, -30);
  1546. this.vertexList[1] = new Vertex(30 + this.xShift, dy, 200);
  1547. this.vertexList[2] = new Vertex(this.xShift, dy, 200);
  1548. this.vertexList[3] = new Vertex(this.xShift, dy, 0);
  1549. this.vertexList[4] = new Vertex(30 + this.xShift, -dy, -30);
  1550. this.vertexList[5] = new Vertex(30 + this.xShift, -dy, 200);
  1551. this.vertexList[6] = new Vertex(this.xShift, -dy, 200);
  1552. this.vertexList[7] = new Vertex(this.xShift, -dy, 0);
  1553.  
  1554. this.vertexList[8] = new Vertex(30 - this.xShift, dy, -30);
  1555. this.vertexList[9] = new Vertex(-this.xShift, dy, 0);
  1556. this.vertexList[10] = new Vertex(-200 - this.xShift, dy, 0);
  1557. this.vertexList[11] = new Vertex(-200 - this.xShift, dy, -30);
  1558. this.vertexList[12] = new Vertex(30 - this.xShift, -dy, -30);
  1559. this.vertexList[13] = new Vertex(-this.xShift, -dy, 0);
  1560. this.vertexList[14] = new Vertex(-200 - this.xShift, -dy, 0);
  1561. this.vertexList[15] = new Vertex(-200 - this.xShift, -dy, -30);
  1562. };
  1563.  
  1564. MitreButt2.prototype.initFaceList = function () {
  1565. this.faceList = new Array(12);
  1566. this.faceList[0] = [0, 4, 5, 1];
  1567. this.faceList[1] = [1, 5, 6, 2];
  1568. this.faceList[2] = [3, 2, 6, 7];
  1569. this.faceList[3] = [7, 4, 0, 3];
  1570. this.faceList[4] = [0, 1, 2, 3];
  1571. this.faceList[5] = [4, 7, 6, 5];
  1572.  
  1573. this.faceList[6] = [11, 15, 12, 8];
  1574. this.faceList[7] = [12, 13, 9, 8];
  1575. this.faceList[8] = [10, 9, 13, 14];
  1576. this.faceList[9] = [11, 10, 14, 15];
  1577. this.faceList[10] = [11, 8, 9, 10];
  1578. this.faceList[11] = [15, 14, 13, 12];
  1579. };
  1580.  
  1581. MitreButt2.prototype.drawFaces = function (g) {
  1582. var j, k, n;
  1583. var p0;
  1584. var p1;
  1585. var p2;
  1586. var p;
  1587. var a = [];
  1588. var nface;
  1589. var face = [];
  1590. var color;
  1591. var p2d;
  1592. g.clear();
  1593. for (j = 0; j < this.dlist.length; j++) {
  1594. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  1595. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  1596. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  1597. if (visible3DFace(p0, p1, p2)) {
  1598. nface = this.dlist[j];
  1599. face = this.faceList[nface];
  1600. a = new Array(face.length);
  1601. for (k = 0; k < face.length; k++) {
  1602. p = this.vertexList[face[k]];
  1603. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  1604. }
  1605.  
  1606. switch (nface) {
  1607. case 1:
  1608. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1609. break;
  1610. default:
  1611. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1612. }
  1613.  
  1614. g.f(color).s(clEdge);
  1615. g.mt(a[0].x, a[0].y);
  1616. for (n = 1; n < face.length; n++) {
  1617. g.lt(a[n].x, a[n].y);
  1618. }
  1619. g.cp().es().ef();
  1620. }
  1621. }
  1622. };
  1623.  
  1624. //***************************************************************************************************************
  1625. MitreButt2.prototype.draw = function (g) {
  1626. var j;
  1627. var mx = new RotationMatrix(rx, 0);
  1628. var my = new RotationMatrix(ry, 1);
  1629. var mat = matMultiply(mx, my);
  1630.  
  1631. this.initJoint();
  1632.  
  1633. for (j = 0; j < this.vertexList.length; j++) {
  1634. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  1635. }
  1636.  
  1637. if (rx >= 0) {
  1638. if (ry > 90) {
  1639. this.dlist = [7, 3, 2, 4, 1, 8, 9, 10];
  1640. } else if (ry >= 0) {
  1641. this.dlist = [2, 3, 7, 5, 5, 0, 6, 9, 11];
  1642. } else if (ry >= -90) {
  1643. this.dlist = [2, 7, 3, 11, 5, 6, 0];
  1644. } else {
  1645. this.dlist = [3, 7, 8, 10, 2, 4, 1, 0];
  1646. }
  1647. } else if (rx < 0) {
  1648. if (ry > 90) {
  1649. this.dlist = [3, 7, 1, 11, 8, 2, 5, 9];
  1650. } else if (ry >= 0) {
  1651. this.dlist = [2, 3, 7, 5, 4, 0, 6, 9, 10];
  1652. } else if (ry >= -90) {
  1653. this.dlist = [2, 7, 3, 10, 4, 6, 0];
  1654. } else {
  1655. this.dlist = [7, 3, 8, 11, 2, 5, 1, 0];
  1656. }
  1657. }
  1658.  
  1659. this.drawFaces(g);
  1660. };
  1661.  
  1662. MitreButt2.prototype.explode = function (g, dx) {
  1663. this.xShift = dx;
  1664. this.draw(g);
  1665. };
  1666. return MitreButt2;
  1667. })(BaseJoint);
  1668. ///<reference path='../../common/ts/easeljs.d.ts'/>
  1669. ///<reference path='wood3d.ts'/>
  1670. var SplinedMitre = (function (_super) {
  1671. __extends(SplinedMitre, _super);
  1672. function SplinedMitre(dx) {
  1673. _super.call(this);
  1674. this.dlist = [];
  1675. this.xShift = 0;
  1676. this.xShift = dx;
  1677. this.vertexList = new Array(104);
  1678. this.initJoint();
  1679. this.initFaceList();
  1680. }
  1681. SplinedMitre.prototype.initJoint = function () {
  1682. var dz;
  1683. var dy;
  1684. var ds;
  1685.  
  1686. //
  1687. if (this.xShift > 75) {
  1688. //open joint, but leave splines out
  1689. dz = (this.xShift - 75) * 2.5;
  1690. ds = 60;
  1691. dy = 20;
  1692. } else {
  1693. //shut joint and move splines in
  1694. dz = 0;
  1695. ds = 60 * this.xShift / 75;
  1696. dy = ds / 3;
  1697. }
  1698. var dt = 4;
  1699.  
  1700. this.vertexList[0] = new Vertex(0, -100, dz);
  1701. this.vertexList[1] = new Vertex(30, -100, -30 + dz);
  1702. this.vertexList[2] = new Vertex(-200 - dz, -100, -30);
  1703.  
  1704. this.vertexList[3] = new Vertex(15, -65, dz - 15);
  1705. this.vertexList[4] = new Vertex(30, -75, -30 + dz);
  1706. this.vertexList[5] = new Vertex(30, -65, dz);
  1707. this.vertexList[6] = new Vertex(15, -65 + dt, dz - 15);
  1708. this.vertexList[7] = new Vertex(30, -75 + dt, -30 + dz);
  1709. this.vertexList[8] = new Vertex(30, -65 + dt, dz);
  1710.  
  1711. this.vertexList[9] = new Vertex(15, -35, dz - 15);
  1712. this.vertexList[10] = new Vertex(30, -25, -30 + dz);
  1713. this.vertexList[11] = new Vertex(30, -35, dz);
  1714. this.vertexList[12] = new Vertex(15, -35 + dt, dz - 15);
  1715. this.vertexList[13] = new Vertex(30, -25 + dt, -30 + dz);
  1716. this.vertexList[14] = new Vertex(30, -35 + dt, dz);
  1717.  
  1718. this.vertexList[15] = new Vertex(15, 35 - dt, dz - 15);
  1719. this.vertexList[16] = new Vertex(30, 25 - dt, -30 + dz);
  1720. this.vertexList[17] = new Vertex(30, 35 - dt, dz);
  1721. this.vertexList[18] = new Vertex(15, 35, dz - 15);
  1722. this.vertexList[19] = new Vertex(30, 25, -30 + dz);
  1723. this.vertexList[20] = new Vertex(30, 35, dz);
  1724.  
  1725. this.vertexList[21] = new Vertex(15, 65 - dt, dz - 15);
  1726. this.vertexList[22] = new Vertex(30, 75 - dt, -30 + dz);
  1727. this.vertexList[23] = new Vertex(30, 65 - dt, dz);
  1728. this.vertexList[24] = new Vertex(15, 65, dz - 15);
  1729. this.vertexList[25] = new Vertex(30, 75, -30 + dz);
  1730. this.vertexList[26] = new Vertex(30, 65, dz);
  1731.  
  1732. this.vertexList[27] = new Vertex(0, 100, dz);
  1733. this.vertexList[28] = new Vertex(30, 100, -30 + dz);
  1734. this.vertexList[29] = new Vertex(-200 - dz, -100, 0);
  1735.  
  1736. this.vertexList[30] = new Vertex(0, -100, 200 + dz);
  1737. this.vertexList[31] = new Vertex(30, -100, 200 + dz);
  1738. this.vertexList[32] = new Vertex(30, 100, 200 + dz);
  1739. this.vertexList[33] = new Vertex(0, 100, 200 + dz);
  1740.  
  1741. //spline 1 ->top - slides out and up
  1742. this.vertexList[34] = new Vertex(ds, -65 - dy, -30);
  1743. this.vertexList[35] = new Vertex(30 + ds, -75 - dy, -30);
  1744. this.vertexList[36] = new Vertex(30 + ds, -65 - dy, 0);
  1745. this.vertexList[37] = new Vertex(ds, -65 + dt - dy, -30);
  1746. this.vertexList[38] = new Vertex(30 + ds, -75 + dt - dy, -30);
  1747. this.vertexList[39] = new Vertex(30 + ds, -65 + dt - dy, 0);
  1748.  
  1749. //spline 2 - slides out and down ->positive y shift
  1750. this.vertexList[40] = new Vertex(0, -35 + dy, -30 - ds);
  1751. this.vertexList[41] = new Vertex(30, -25 + dy, -30 - ds);
  1752. this.vertexList[42] = new Vertex(30, -35 + dy, -ds);
  1753. this.vertexList[43] = new Vertex(0, -35 + dt + dy, -30 - ds);
  1754. this.vertexList[44] = new Vertex(30, -25 + dt + dy, -30 - ds);
  1755. this.vertexList[45] = new Vertex(30, -35 + dt + dy, -ds);
  1756.  
  1757. //spline 3 - slides out and up -> negative y shift
  1758. this.vertexList[46] = new Vertex(ds, 35 - dt - dy, -30);
  1759. this.vertexList[47] = new Vertex(30 + ds, 25 - dt - dy, -30);
  1760. this.vertexList[48] = new Vertex(30 + ds, 35 - dt - dy, 0);
  1761. this.vertexList[49] = new Vertex(ds, 35 - dy, -30);
  1762. this.vertexList[50] = new Vertex(30 + ds, 25 - dy, -30);
  1763. this.vertexList[51] = new Vertex(30 + ds, 35 - dy, 0);
  1764.  
  1765. //spline 4 ->bottom - slides out and down ->positive y shift
  1766. this.vertexList[52] = new Vertex(0, 65 - dt + dy, -30 - ds);
  1767. this.vertexList[53] = new Vertex(30, 75 - dt + dy, -30 - ds);
  1768. this.vertexList[54] = new Vertex(30, 65 - dt + dy, -ds);
  1769. this.vertexList[55] = new Vertex(0, 65 + dy, -30 - ds);
  1770. this.vertexList[56] = new Vertex(30, 75 + dy, -30 - ds);
  1771. this.vertexList[57] = new Vertex(30, 65 + dy, -ds);
  1772.  
  1773. //left hand side - shifted to -x
  1774. this.vertexList[58] = new Vertex(-200 - dz, 100, -30);
  1775. this.vertexList[59] = new Vertex(30 - dz, -100, -30);
  1776. this.vertexList[60] = new Vertex(-dz, -100, 0);
  1777.  
  1778. this.vertexList[61] = new Vertex(-dz, -65, -30);
  1779. this.vertexList[62] = new Vertex(30 - dz, -75, -30);
  1780. this.vertexList[63] = new Vertex(15 - dz, -65, -15);
  1781. this.vertexList[64] = new Vertex(-dz, -65 + dt, -30);
  1782. this.vertexList[65] = new Vertex(30 - dz, -75 + dt, -30);
  1783. this.vertexList[66] = new Vertex(15 - dz, -65 + dt, -15);
  1784.  
  1785. this.vertexList[67] = new Vertex(-dz, -35, -30);
  1786. this.vertexList[68] = new Vertex(30 - dz, -25, -30);
  1787. this.vertexList[69] = new Vertex(15 - dz, -35, -15);
  1788. this.vertexList[70] = new Vertex(-dz, -35 + dt, -30);
  1789. this.vertexList[71] = new Vertex(30 - dz, -25 + dt, -30);
  1790. this.vertexList[72] = new Vertex(15 - dz, -35 + dt, -15);
  1791.  
  1792. this.vertexList[73] = new Vertex(-dz, 35 - dt, -30);
  1793. this.vertexList[74] = new Vertex(30 - dz, 25 - dt, -30);
  1794. this.vertexList[75] = new Vertex(15 - dz, 35 - dt, -15);
  1795. this.vertexList[76] = new Vertex(-dz, 35, -30);
  1796. this.vertexList[77] = new Vertex(30 - dz, 25, -30);
  1797. this.vertexList[78] = new Vertex(15 - dz, 35, -15);
  1798.  
  1799. this.vertexList[79] = new Vertex(-dz, 65 - dt, -30);
  1800. this.vertexList[80] = new Vertex(30 - dz, 75 - dt, -30);
  1801. this.vertexList[81] = new Vertex(15 - dz, 65 - dt, -15);
  1802. this.vertexList[82] = new Vertex(-dz, 65, -30);
  1803. this.vertexList[83] = new Vertex(30 - dz, 75, -30);
  1804. this.vertexList[84] = new Vertex(15 - dz, 65, -15);
  1805. this.vertexList[85] = new Vertex(-200 - dz, 100, 0);
  1806. this.vertexList[86] = new Vertex(30 - dz, 100, -30);
  1807. this.vertexList[87] = new Vertex(-dz, 100, 0);
  1808.  
  1809. //extra point to reshape splines when they enter slots
  1810. if (ds >= 30) {
  1811. //top spline shift -> +x,-y
  1812. this.vertexList[88] = new Vertex(ds, -65 - dy, -30);
  1813. this.vertexList[89] = new Vertex(ds + 15, -65 - dy, -15);
  1814. this.vertexList[90] = new Vertex(ds, -65 - dy + dt, -30);
  1815. this.vertexList[91] = new Vertex(ds + 15, -65 - dy + dt, -15);
  1816.  
  1817. //spline2 shift -> -z,+y
  1818. this.vertexList[92] = new Vertex(30, -35 + dy, -ds);
  1819. this.vertexList[93] = new Vertex(15, -35 + dy, -15 - ds);
  1820. this.vertexList[94] = new Vertex(30, -35 + dt + dy, -ds);
  1821. this.vertexList[95] = new Vertex(15, -35 + dy + dt, -15 - ds);
  1822.  
  1823. //spline 3 shift -> +x,-y
  1824. this.vertexList[96] = new Vertex(ds, 35 - dt - dy, -30);
  1825. this.vertexList[97] = new Vertex(ds + 15, 35 - dt - dy, -15);
  1826. this.vertexList[98] = new Vertex(ds, 35 - dy, -30);
  1827. this.vertexList[99] = new Vertex(ds + 15, 35 - dy, -15);
  1828.  
  1829. //spline 4 shift -> -z,+y
  1830. this.vertexList[100] = new Vertex(30, 65 - dt + dy, -ds);
  1831. this.vertexList[101] = new Vertex(15, 65 + dy - dt, -15 - ds);
  1832. this.vertexList[102] = new Vertex(30, 65 + dy, -ds);
  1833. this.vertexList[103] = new Vertex(15, 65 + dy, -15 - ds);
  1834. } else {
  1835. //spline 1 shift -> +x,-y
  1836. this.vertexList[88] = new Vertex(30, -75, -30);
  1837. this.vertexList[89] = new Vertex(30, -65 - dy, -ds);
  1838. this.vertexList[90] = new Vertex(30, -75 + dt, -30);
  1839. this.vertexList[91] = new Vertex(30, -65 - dy + dt, -ds);
  1840.  
  1841. //spline2 shift -> -z,+y
  1842. this.vertexList[92] = new Vertex(30, -25, -30);
  1843. this.vertexList[93] = new Vertex(ds, -35 + dy, -30);
  1844. this.vertexList[94] = new Vertex(30, -25 + dt, -30);
  1845. this.vertexList[95] = new Vertex(ds, -35 + dt + dy, -30);
  1846.  
  1847. //spline 3 shift -> +x,-y
  1848. this.vertexList[96] = new Vertex(30, 25 - dt, -30);
  1849. this.vertexList[97] = new Vertex(30, 35 - dt - dy, -ds);
  1850. this.vertexList[98] = new Vertex(30, 25, -30);
  1851. this.vertexList[99] = new Vertex(30, 35 - dy, -ds);
  1852.  
  1853. //spline 4 shift -> -z,+y
  1854. this.vertexList[100] = new Vertex(30, 75 - dt, -30);
  1855. this.vertexList[101] = new Vertex(ds, 65 - dt + dy, -30);
  1856. this.vertexList[102] = new Vertex(30, 75, -30);
  1857. this.vertexList[103] = new Vertex(ds, 65 + dy, -30);
  1858. }
  1859. };
  1860.  
  1861. SplinedMitre.prototype.initFaceList = function () {
  1862. this.faceList = new Array(56);
  1863. this.faceList[0] = [3, 6, 8, 5];
  1864. this.faceList[1] = [61, 64, 66, 63];
  1865. this.faceList[2] = [9, 12, 14, 11];
  1866. this.faceList[3] = [67, 70, 72, 69];
  1867. this.faceList[4] = [15, 18, 20, 17];
  1868. this.faceList[5] = [73, 76, 78, 75];
  1869. this.faceList[6] = [21, 24, 26, 23];
  1870. this.faceList[7] = [79, 82, 84, 81];
  1871. this.faceList[8] = [4, 3, 5];
  1872. this.faceList[9] = [61, 63, 62];
  1873. this.faceList[10] = [6, 7, 8];
  1874. this.faceList[11] = [64, 65, 66];
  1875. this.faceList[12] = [9, 11, 10];
  1876. this.faceList[13] = [67, 69, 68];
  1877. this.faceList[14] = [12, 13, 14];
  1878. this.faceList[15] = [70, 71, 72];
  1879. this.faceList[16] = [15, 17, 16];
  1880. this.faceList[17] = [73, 75, 74];
  1881. this.faceList[18] = [18, 19, 20];
  1882. this.faceList[19] = [76, 77, 78];
  1883. this.faceList[20] = [21, 23, 22];
  1884. this.faceList[21] = [79, 81, 80];
  1885. this.faceList[22] = [24, 25, 26];
  1886. this.faceList[23] = [82, 83, 84];
  1887. this.faceList[24] = [34, 37, 38, 35];
  1888. this.faceList[25] = [35, 38, 39, 36];
  1889. this.faceList[26] = [88, 35, 36, 89];
  1890. this.faceList[27] = [38, 90, 91, 39];
  1891. this.faceList[28] = [34, 36, 39, 37];
  1892. this.faceList[29] = [40, 43, 44, 41];
  1893. this.faceList[30] = [41, 44, 45, 42];
  1894. this.faceList[31] = [40, 41, 92, 93];
  1895. this.faceList[32] = [44, 43, 95, 94];
  1896. this.faceList[33] = [95, 43, 40, 93];
  1897. this.faceList[34] = [46, 49, 50, 47];
  1898. this.faceList[35] = [47, 50, 51, 48];
  1899. this.faceList[36] = [96, 47, 48, 97];
  1900. this.faceList[37] = [50, 98, 99, 51];
  1901. this.faceList[38] = [46, 48, 51, 49];
  1902. this.faceList[39] = [52, 55, 56, 53];
  1903. this.faceList[40] = [53, 56, 57, 54];
  1904. this.faceList[41] = [52, 53, 100, 101];
  1905. this.faceList[42] = [56, 55, 103, 102];
  1906. this.faceList[43] = [103, 55, 52, 101];
  1907. this.faceList[44] = [2, 29, 85, 58];
  1908. this.faceList[45] = [60, 59, 62, 63, 66, 65, 68, 69, 72, 71, 74, 75, 78, 77, 80, 81, 84, 83, 86, 87];
  1909. this.faceList[46] = [0, 27, 28, 25, 24, 21, 22, 19, 18, 15, 16, 13, 12, 9, 10, 7, 6, 3, 4, 1];
  1910. this.faceList[47] = [31, 1, 4, 5, 8, 7, 10, 11, 14, 13, 16, 17, 20, 19, 22, 23, 26, 25, 28, 32];
  1911. this.faceList[48] = [2, 58, 86, 83, 82, 79, 80, 77, 76, 73, 74, 71, 70, 67, 68, 65, 64, 61, 62, 59];
  1912. this.faceList[49] = [0, 1, 31, 30];
  1913. this.faceList[50] = [2, 59, 60, 29];
  1914. this.faceList[51] = [0, 30, 33, 27];
  1915. this.faceList[52] = [27, 33, 32, 28];
  1916. this.faceList[53] = [93, 42, 45, 95];
  1917. this.faceList[54] = [101, 54, 57, 103];
  1918. this.faceList[55] = [58, 85, 87, 86];
  1919. };
  1920.  
  1921. SplinedMitre.prototype.drawFaces = function (g) {
  1922. var j, k, n;
  1923. var p0;
  1924. var p1;
  1925. var p2;
  1926. var p;
  1927. var a = [];
  1928. var nface;
  1929. var face = [];
  1930. var color;
  1931. var p2d;
  1932. g.clear();
  1933. for (j = 0; j < this.dlist.length; j++) {
  1934. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  1935. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  1936. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  1937. if (visible3DFace(p0, p1, p2)) {
  1938. nface = this.dlist[j];
  1939. face = this.faceList[nface];
  1940. a = new Array(face.length);
  1941. for (k = 0; k < face.length; k++) {
  1942. p = this.vertexList[face[k]];
  1943. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  1944. }
  1945.  
  1946. //switch(nface){
  1947. //case 1:
  1948. //color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1949. //break;
  1950. //default:
  1951. //color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1952. //}
  1953. if (nface < 24) {
  1954. color = getFaceColor(p1, p2, p0, Wood.clfHole);
  1955. g.f(color).s(clEdge);
  1956. g.mt(a[0].x, a[0].y);
  1957. for (n = 1; n < face.length; n++) {
  1958. g.lt(a[n].x, a[n].y);
  1959. }
  1960. g.cp().es().ef();
  1961. } else if (nface < 44) {
  1962. color = getFaceColor(p1, p2, p0, Wood.clfPanel);
  1963.  
  1964. if ((nface == 33) || (nface == 34) || (nface == 43)) {
  1965. g.f(color).ss(1, 2).s(color);
  1966. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef();
  1967. g.s(clDowelEdge).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).es();
  1968. } else {
  1969. g.f(color).s(clDowelEdge);
  1970. g.mt(a[0].x, a[0].y);
  1971. for (n = 1; n < face.length; n++) {
  1972. g.lt(a[n].x, a[n].y);
  1973. }
  1974. g.cp().es().ef();
  1975. }
  1976. } else if ((nface == 53) || (nface == 54)) {
  1977. color = getFaceColor(p1, p2, p0, Wood.clfPanel);
  1978. g.f(color).ss(1, 2).s(color);
  1979. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp().ef();
  1980. g.s(clDowelEdge).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).es();
  1981. } else if ((nface == 44) || (nface == 45) || (nface == 46)) {
  1982. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  1983. g.f(color).s(clEdge);
  1984. g.mt(a[0].x, a[0].y);
  1985. for (n = 1; n < face.length; n++) {
  1986. g.lt(a[n].x, a[n].y);
  1987. }
  1988. g.cp().es().ef();
  1989. } else {
  1990. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  1991. g.f(color).s(clEdge);
  1992. g.mt(a[0].x, a[0].y);
  1993. for (n = 1; n < face.length; n++) {
  1994. g.lt(a[n].x, a[n].y);
  1995. }
  1996. g.cp().es().ef();
  1997. }
  1998. }
  1999. }
  2000. };
  2001.  
  2002. //***************************************************************************************************************
  2003. SplinedMitre.prototype.draw = function (g) {
  2004. var j;
  2005. var mx = new RotationMatrix(rx, 0);
  2006. var my = new RotationMatrix(ry, 1);
  2007. var mat = matMultiply(mx, my);
  2008.  
  2009. this.initJoint();
  2010.  
  2011. for (j = 0; j < this.vertexList.length; j++) {
  2012. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  2013. }
  2014.  
  2015. var flag = visible3DFace(this.vertexList[4], this.vertexList[1], this.vertexList[3]);
  2016.  
  2017. if (this.xShift > 75) {
  2018. //mitre joint open
  2019. if ((rx >= 0) && flag) {
  2020. if (ry <= 0) {
  2021. this.dlist = [
  2022. 51, 0, 2, 4, 6, 1, 3, 5, 7,
  2023. 8, 10, 12, 14, 16, 18, 20, 22, 46, 47, 52,
  2024. 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 45,
  2025. 48, 55, 44,
  2026. 24, 25, 26, 27, 28,
  2027. 34, 35, 36, 37, 38,
  2028. 29, 30, 31, 32, 33, 53,
  2029. 39, 40, 41, 42, 43, 54];
  2030. } else {
  2031. this.dlist = [
  2032. 51, 0, 2, 4, 6, 1, 3, 5, 7,
  2033. 8, 10, 12, 14, 16, 18, 20, 22, 46, 47, 52,
  2034. 24, 25, 26, 27, 28,
  2035. 34, 35, 36, 37, 38,
  2036. 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 45,
  2037. 48, 55, 44,
  2038. 29, 30, 31, 32, 33, 53,
  2039. 39, 40, 41, 42, 43, 54];
  2040. }
  2041. } else if ((rx >= 0) && !flag) {
  2042. this.dlist = [
  2043. 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
  2044. 45, 48, 55,
  2045. 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
  2046. 47, 52,
  2047. 29, 30, 31, 32,
  2048. 39, 40, 41, 42,
  2049. 24, 25, 26, 27,
  2050. 34, 35, 36, 37];
  2051. } else if ((rx < 0) && flag) {
  2052. if (ry <= 0) {
  2053. this.dlist = [
  2054. 51, 0, 2, 4, 6, 22, 20, 18, 16, 14, 12, 10, 8,
  2055. 46, 45, 47, 49,
  2056. 7, 5, 3, 1, 23, 21, 19, 17, 15, 13, 11, 9,
  2057. 34, 35, 36, 37, 38,
  2058. 24, 25, 26, 27, 28,
  2059. 48, 50, 44,
  2060. 39, 40, 41, 42, 43, 54, 29, 30, 31, 32, 33, 53];
  2061. } else {
  2062. this.dlist = [
  2063. 34, 35, 36, 37, 38, 24, 25, 26, 27, 28,
  2064. 51, 0, 2, 4, 6, 22, 20, 18, 16, 14, 12, 10, 8,
  2065. 46, 45, 47, 49,
  2066. 7, 5, 3, 1, 23, 21, 19, 17, 15, 13, 11, 9,
  2067. 48, 50, 44,
  2068. 39, 40, 41, 42, 43, 54, 29, 30, 31, 32, 33, 53];
  2069. }
  2070. } else if ((rx < 0) && !flag) {
  2071. this.dlist = [
  2072. 7, 5, 3, 1, 23, 21, 19, 17, 15, 13, 11, 9,
  2073. 45, 48, 50,
  2074. 51, 0, 2, 4, 6, 22, 20, 18, 16, 14, 12, 10, 8,
  2075. 47, 49,
  2076. 39, 40, 41, 42, 43,
  2077. 34, 35, 36, 37, 38,
  2078. 29, 30, 31, 32, 33,
  2079. 24, 25, 26, 27, 28];
  2080. }
  2081. } else {
  2082. //mitre joint together
  2083. if ((rx >= 0) && (ry >= 0)) {
  2084. this.dlist = [
  2085. 26, 27,
  2086. 36, 37,
  2087. 51, 0, 1, 2, 3, 4, 5, 6, 7,
  2088. 8, 9, 10, 11, 12, 13, 14, 15, 16,
  2089. 17, 18, 19, 20, 21, 22, 23, 53, 54, 28, 38, 24, 34,
  2090. 48, 55, 52,
  2091. 29, 31, 32, 33,
  2092. 39, 41, 42, 43, 44];
  2093. } else if ((rx >= 0) && (ry < 0)) {
  2094. this.dlist = [
  2095. 0, 1, 2, 3, 4, 5, 6, 7,
  2096. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  2097. 48, 47,
  2098. 24, 25, 26, 27,
  2099. 29, 30, 31, 32,
  2100. 34, 35, 36, 37,
  2101. 39, 40, 41, 42, 55, 52];
  2102. } else if ((rx < 0) && (ry >= 0)) {
  2103. this.dlist = [
  2104. 51, 6, 7, 4, 5, 3, 2, 1, 0,
  2105. 22, 23, 20, 21, 18, 19, 16, 17,
  2106. 14, 15, 12, 13, 10, 11, 8, 9,
  2107. 53, 54,
  2108. 47,
  2109. 34, 35, 36, 37, 38,
  2110. 24, 25, 26, 27, 28,
  2111. 48, 33, 43,
  2112. 39, 40, 41, 42,
  2113. 29, 30, 31, 32, 44, 49, 50];
  2114. } else {
  2115. this.dlist = [
  2116. 51, 6, 7, 4, 5, 3, 2, 1, 0,
  2117. 22, 23, 20, 21, 18, 19, 16, 17,
  2118. 14, 15, 12, 13, 10, 11, 8, 9,
  2119. 44, 47, 48,
  2120. 39, 40, 41, 42, 43,
  2121. 29, 30, 31, 32, 33,
  2122. 34, 35, 36, 37, 38,
  2123. 28, 24, 26, 25, 27,
  2124. 50, 49];
  2125. }
  2126. }
  2127.  
  2128. this.drawFaces(g);
  2129. };
  2130.  
  2131. SplinedMitre.prototype.explode = function (g, dx) {
  2132. this.xShift = dx;
  2133. this.draw(g);
  2134. };
  2135. return SplinedMitre;
  2136. })(BaseJoint);
  2137. ///<reference path='../../common/ts/easeljs.d.ts'/>
  2138. ///<reference path='wood3d.ts'/>
  2139. var SquareEndButt2 = (function (_super) {
  2140. __extends(SquareEndButt2, _super);
  2141. function SquareEndButt2(dx) {
  2142. _super.call(this);
  2143. this.dlist = [];
  2144. this.xShift = 0;
  2145. this.xShift = dx;
  2146. this.vertexList = new Array(16);
  2147. this.initJoint();
  2148. this.initFaceList();
  2149. }
  2150. SquareEndButt2.prototype.initJoint = function () {
  2151. //
  2152. var y = 100;
  2153. var x = this.xShift / 2;
  2154. var z = 15;
  2155.  
  2156. //left cuboid
  2157. this.vertexList[0] = new Vertex(-x - 200, -y, z);
  2158. this.vertexList[1] = new Vertex(-x, -y, z);
  2159. this.vertexList[2] = new Vertex(-x, -y, -z);
  2160. this.vertexList[3] = new Vertex(-x - 200, -y, -z);
  2161.  
  2162. this.vertexList[4] = new Vertex(-x - 200, y, z);
  2163. this.vertexList[5] = new Vertex(-x, y, z);
  2164. this.vertexList[6] = new Vertex(-x, y, -z);
  2165. this.vertexList[7] = new Vertex(-x - 200, y, -z);
  2166.  
  2167. //right cuboid
  2168. this.vertexList[8] = new Vertex(x, -y, 200);
  2169. this.vertexList[9] = new Vertex(x + 30, -y, 200);
  2170. this.vertexList[10] = new Vertex(x + 30, -y, -z);
  2171. this.vertexList[11] = new Vertex(x, -y, -z);
  2172.  
  2173. this.vertexList[12] = new Vertex(x, y, 200);
  2174. this.vertexList[13] = new Vertex(x + 30, y, 200);
  2175. this.vertexList[14] = new Vertex(x + 30, y, -z);
  2176. this.vertexList[15] = new Vertex(x, y, -z);
  2177. };
  2178.  
  2179. SquareEndButt2.prototype.initFaceList = function () {
  2180. this.faceList = new Array(12);
  2181.  
  2182. //left
  2183. this.faceList[0] = [0, 3, 2, 1];
  2184. this.faceList[1] = [4, 5, 6, 7];
  2185. this.faceList[2] = [2, 3, 7, 6];
  2186. this.faceList[3] = [0, 1, 5, 4];
  2187. this.faceList[4] = [5, 1, 2, 6];
  2188. this.faceList[5] = [0, 4, 7, 3];
  2189.  
  2190. //right
  2191. this.faceList[6] = [8, 11, 10, 9];
  2192. this.faceList[7] = [12, 13, 14, 15];
  2193. this.faceList[8] = [9, 10, 14, 13];
  2194. this.faceList[9] = [8, 12, 15, 11];
  2195. this.faceList[10] = [10, 11, 15, 14];
  2196. this.faceList[11] = [8, 9, 13, 12];
  2197. };
  2198.  
  2199. SquareEndButt2.prototype.drawFaces = function (g) {
  2200. var j, k, n;
  2201. var p0;
  2202. var p1;
  2203. var p2;
  2204. var p;
  2205. var a = [];
  2206. var nface;
  2207. var face = [];
  2208. var color;
  2209. var p2d;
  2210. g.clear();
  2211. for (j = 0; j < this.dlist.length; j++) {
  2212. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  2213. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  2214. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  2215. if (visible3DFace(p0, p1, p2)) {
  2216. nface = this.dlist[j];
  2217. face = this.faceList[nface];
  2218. a = new Array(face.length);
  2219. for (k = 0; k < face.length; k++) {
  2220. p = this.vertexList[face[k]];
  2221. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  2222. }
  2223.  
  2224. switch (nface) {
  2225. case 4:
  2226. case 5:
  2227. case 10:
  2228. case 11:
  2229. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  2230. break;
  2231. default:
  2232. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  2233. }
  2234.  
  2235. g.f(color).s(clEdge);
  2236. g.mt(a[0].x, a[0].y);
  2237. for (n = 1; n < face.length; n++) {
  2238. g.lt(a[n].x, a[n].y);
  2239. }
  2240. g.cp().es().ef();
  2241. }
  2242. }
  2243. };
  2244.  
  2245. //***************************************************************************************************************
  2246. SquareEndButt2.prototype.draw = function (g) {
  2247. var j;
  2248. var mx = new RotationMatrix(rx, 0);
  2249. var my = new RotationMatrix(ry, 1);
  2250. var mat = matMultiply(mx, my);
  2251.  
  2252. this.initJoint();
  2253.  
  2254. for (j = 0; j < this.vertexList.length; j++) {
  2255. this.vertexList[j] = applyMatrix(this.vertexList[j], mat);
  2256. }
  2257.  
  2258. if (ry >= 0) {
  2259. this.dlist = [6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5];
  2260. } else {
  2261. this.dlist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
  2262. }
  2263.  
  2264. this.drawFaces(g);
  2265. };
  2266.  
  2267. SquareEndButt2.prototype.explode = function (g, dx) {
  2268. this.xShift = dx;
  2269. this.draw(g);
  2270. };
  2271. return SquareEndButt2;
  2272. })(BaseJoint);
  2273. ///<reference path='../../common/ts/easeljs.d.ts'/>
  2274. ///<reference path='wood3d.ts'/>
  2275. /**********************************************************************************************************/
  2276. /*Return xyx coordinates of a horizontal cylinder made up off 20 faces.
  2277. nLength is the length and radius is the radius.
  2278. The first and last entries in the array are identical, since it makes the drawing code easier
  2279. N.B. nLength = length of dowel /2
  2280. */
  2281. function getCylinder(x0, y0, z0, nLength, radius) {
  2282. var j, a;
  2283. var da = Math.PI / 10;
  2284.  
  2285. var res = new Array(42);
  2286. for (j = 0; j <= 20; j++) {
  2287. a = j * da;
  2288. res[j] = new Vertex(x0 - nLength, y0 + radius * Math.sin(a), z0 + radius * Math.cos(a));
  2289. res[j + 21] = new Vertex(x0 + nLength, res[j].y, res[j].z);
  2290. }
  2291. return res;
  2292. }
  2293.  
  2294. /*****************************************************************************************************
  2295. * Return 3D points to define a cylindrical hole from x0 to x0 - nLength
  2296. ******************************************************************************************************/
  2297. function getLeftHole(x0, y0, z0, nLength, radius) {
  2298. var j, a;
  2299. var da = Math.PI / 10;
  2300.  
  2301. var res = new Array(42);
  2302. for (j = 0; j <= 20; j++) {
  2303. a = j * da;
  2304. res[j] = new Vertex(x0, y0 + radius * Math.sin(a), z0 + radius * Math.cos(a));
  2305. res[j + 21] = new Vertex(x0 - nLength, res[j].y, res[j].z);
  2306. }
  2307. return res;
  2308. }
  2309.  
  2310. /*****************************************************************************************************
  2311. * Return 3D points to define a cylindrical hole from x0 to x0 + nLength
  2312. ******************************************************************************************************/
  2313. function getRightHole(x0, y0, z0, nLength, radius) {
  2314. var j, a;
  2315. var da = Math.PI / 10;
  2316.  
  2317. var res = new Array(42);
  2318. for (j = 0; j <= 20; j++) {
  2319. a = j * da;
  2320. res[j] = new Vertex(x0, y0 - radius * Math.sin(a), z0 + radius * Math.cos(a));
  2321. res[j + 21] = new Vertex(x0 + nLength, res[j].y, res[j].z);
  2322. }
  2323. return res;
  2324. }
  2325.  
  2326. /*********************************************************************************************************
  2327. * Draw a cylinder centered at (x0, y0, z0)
  2328. */
  2329. function drawCylinder(g, x0, y0, z0, nLength, radius, mat, xOff, yOff) {
  2330. var c = [];
  2331. var j;
  2332. var a = new Array(4);
  2333. var p0;
  2334. var p1;
  2335. var p2;
  2336. var p3;
  2337. var color;
  2338. var ap;
  2339.  
  2340. c = getCylinder(x0, y0, z0, nLength, radius);
  2341. for (j = 0; j < c.length; j++) {
  2342. c[j] = applyMatrix(c[j], mat);
  2343. }
  2344.  
  2345. for (j = 0; j <= 19; j++) {
  2346. p0 = c[j];
  2347. p1 = c[j + 21];
  2348. p2 = c[j + 22];
  2349. p3 = c[j + 1];
  2350. if (visible3DFace(p1, p2, p0)) {
  2351. a[0] = get2dPoint(p0, xOff, yOff);
  2352. a[1] = get2dPoint(p1, xOff, yOff);
  2353. a[2] = get2dPoint(p2, xOff, yOff);
  2354. a[3] = get2dPoint(p3, xOff, yOff);
  2355.  
  2356. color = getFaceColor(p1, p2, p0, Wood.clfDowel);
  2357. g.f(color).s(color).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp();
  2358. //g.s(clEdge).mt(a[1].x, a[1].y).lt(a[2].x, a[2].y).es();
  2359. }
  2360. }
  2361.  
  2362. //draw end faces
  2363. p0 = c[0];
  2364. p1 = c[1];
  2365. p2 = c[2];
  2366. if (visible3DFace(p1, p2, p0)) {
  2367. color = getFaceColor(p1, p2, p0, Wood.clfDowel);
  2368. ap = get2dPoint(c[0], xOff, yOff);
  2369. g.s(clDowelEdge).mt(ap.x, ap.y);
  2370. for (j = 1; j <= 20; j++) {
  2371. ap = get2dPoint(c[j], xOff, yOff);
  2372. g.lt(ap.x, ap.y);
  2373. }
  2374. }
  2375.  
  2376. //
  2377. p0 = c[23];
  2378. p1 = c[22];
  2379. p2 = c[21];
  2380. if (visible3DFace(p1, p2, p0)) {
  2381. color = getFaceColor(p1, p2, p0, Wood.clfDowel);
  2382. ap = get2dPoint(c[21], xOff, yOff);
  2383. g.s(clDowelEdge).mt(ap.x, ap.y);
  2384. for (j = 1; j <= 20; j++) {
  2385. ap = get2dPoint(c[j + 21], xOff, yOff);
  2386. g.lt(ap.x, ap.y);
  2387. }
  2388. }
  2389. }
  2390.  
  2391. /*********************************************************************************************************
  2392. * Draw a dowel hole for the left cuboid
  2393. *******************************************************************************************************/
  2394. function drawLeftHole(g, x0, y0, z0, nLength, radius, mat, xOff, yOff) {
  2395. var c = [];
  2396. var j;
  2397. var a = new Array(4);
  2398. var p0;
  2399. var p1;
  2400. var p2;
  2401. var p3;
  2402. var color;
  2403. var ap;
  2404. var res = new Array(21);
  2405.  
  2406. c = getLeftHole(x0, y0, z0, nLength, radius);
  2407. for (j = 0; j < c.length; j++) {
  2408. c[j] = applyMatrix(c[j], mat);
  2409. }
  2410.  
  2411. for (j = 0; j <= 19; j++) {
  2412. p0 = c[j];
  2413. p1 = c[j + 21];
  2414. p2 = c[j + 22];
  2415. p3 = c[j + 1];
  2416. if (visible3DFace(p1, p2, p0)) {
  2417. a[0] = get2dPoint(p0, xOff, yOff);
  2418. a[1] = get2dPoint(p1, xOff, yOff);
  2419. a[2] = get2dPoint(p2, xOff, yOff);
  2420. a[3] = get2dPoint(p3, xOff, yOff);
  2421.  
  2422. color = getFaceColor(p1, p2, p0, Wood.clfDowelHole);
  2423. g.f(color).s(color).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp();
  2424. }
  2425. }
  2426.  
  2427. p0 = c[23];
  2428. p1 = c[22];
  2429. p2 = c[21];
  2430. if (visible3DFace(p1, p2, p0)) {
  2431. color = getFaceColor(p1, p2, p0, Wood.clfDowel);
  2432. ap = get2dPoint(c[21], xOff, yOff);
  2433. g.s(clEdge).mt(ap.x, ap.y);
  2434. for (j = 1; j <= 20; j++) {
  2435. ap = get2dPoint(c[j + 21], xOff, yOff);
  2436. g.lt(ap.x, ap.y);
  2437. }
  2438. }
  2439.  
  2440. for (j = 0; j <= 20; j++) {
  2441. res[j] = get2dPoint(c[j], xOff, yOff);
  2442. }
  2443. return res;
  2444. }
  2445.  
  2446. /*********************************************************************************************************
  2447. * Draw a dowel hole for the right cuboid
  2448. *******************************************************************************************************/
  2449. function drawRightHole(g, x0, y0, z0, nLength, radius, mat, xOff, yOff) {
  2450. var c = [];
  2451. var j;
  2452. var a = new Array(4);
  2453. var p0;
  2454. var p1;
  2455. var p2;
  2456. var p3;
  2457. var color;
  2458. var ap;
  2459. var res = new Array(21);
  2460.  
  2461. c = getRightHole(x0, y0, z0, nLength, radius);
  2462. for (j = 0; j < c.length; j++) {
  2463. c[j] = applyMatrix(c[j], mat);
  2464. }
  2465.  
  2466. for (j = 0; j <= 19; j++) {
  2467. p0 = c[j];
  2468. p1 = c[j + 21];
  2469. p2 = c[j + 22];
  2470. p3 = c[j + 1];
  2471. if (visible3DFace(p1, p2, p0)) {
  2472. a[0] = get2dPoint(p0, xOff, yOff);
  2473. a[1] = get2dPoint(p1, xOff, yOff);
  2474. a[2] = get2dPoint(p2, xOff, yOff);
  2475. a[3] = get2dPoint(p3, xOff, yOff);
  2476.  
  2477. color = getFaceColor(p1, p2, p0, Wood.clfDowelHole);
  2478. g.f(color).s(color).mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).cp();
  2479. }
  2480. }
  2481.  
  2482. p0 = c[23];
  2483. p1 = c[22];
  2484. p2 = c[21];
  2485. if (visible3DFace(p1, p2, p0)) {
  2486. color = getFaceColor(p1, p2, p0, Wood.clfDowel);
  2487. ap = get2dPoint(c[21], xOff, yOff);
  2488. g.s(clEdge).mt(ap.x, ap.y);
  2489. for (j = 1; j <= 20; j++) {
  2490. ap = get2dPoint(c[j + 21], xOff, yOff);
  2491. g.lt(ap.x, ap.y);
  2492. }
  2493. }
  2494.  
  2495. for (j = 0; j <= 20; j++) {
  2496. res[j] = get2dPoint(c[j], xOff, yOff);
  2497. }
  2498. return res;
  2499. }
  2500. ///<reference path='../../common/ts/easeljs.d.ts'/>
  2501. ///<reference path='wood3d.ts'/>
  2502. ///<reference path='dowel-utils.ts'/>
  2503. var DowelButt = (function (_super) {
  2504. __extends(DowelButt, _super);
  2505. function DowelButt(dx) {
  2506. _super.call(this);
  2507. this.dlist = [];
  2508. this.xShift = 0;
  2509. this.xShift = 1.5 * dx;
  2510. this.vertexList = new Array(16);
  2511. this.initJoint();
  2512. this.initFaceList();
  2513. }
  2514. DowelButt.prototype.initJoint = function () {
  2515. var y = 100;
  2516. var x = this.xShift / 2;
  2517. var z = 15;
  2518.  
  2519. //left cuboid
  2520. this.vertexList[0] = new Vertex(-x - 200, -y, z);
  2521. this.vertexList[1] = new Vertex(-x, -y, z);
  2522. this.vertexList[2] = new Vertex(-x, -y, -z);
  2523. this.vertexList[3] = new Vertex(-x - 200, -y, -z);
  2524.  
  2525. this.vertexList[4] = new Vertex(-x - 200, y, z);
  2526. this.vertexList[5] = new Vertex(-x, y, z);
  2527. this.vertexList[6] = new Vertex(-x, y, -z);
  2528. this.vertexList[7] = new Vertex(-x - 200, y, -z);
  2529.  
  2530. //right cuboid
  2531. this.vertexList[8] = new Vertex(x, -y, 200);
  2532. this.vertexList[9] = new Vertex(x + 30, -y, 200);
  2533. this.vertexList[10] = new Vertex(x + 30, -y, -z);
  2534. this.vertexList[11] = new Vertex(x, -y, -z);
  2535.  
  2536. this.vertexList[12] = new Vertex(x, y, 200);
  2537. this.vertexList[13] = new Vertex(x + 30, y, 200);
  2538. this.vertexList[14] = new Vertex(x + 30, y, -z);
  2539. this.vertexList[15] = new Vertex(x, y, -z);
  2540. };
  2541.  
  2542. DowelButt.prototype.initFaceList = function () {
  2543. this.faceList = new Array(12);
  2544.  
  2545. //left
  2546. this.faceList[0] = [0, 3, 2, 1];
  2547. this.faceList[1] = [4, 5, 6, 7];
  2548. this.faceList[2] = [2, 3, 7, 6];
  2549. this.faceList[3] = [0, 1, 5, 4];
  2550. this.faceList[4] = [5, 1, 2, 6];
  2551. this.faceList[5] = [0, 4, 7, 3];
  2552.  
  2553. //right
  2554. this.faceList[6] = [8, 11, 10, 9];
  2555. this.faceList[7] = [12, 13, 14, 15];
  2556. this.faceList[8] = [9, 10, 14, 13];
  2557. this.faceList[9] = [8, 12, 15, 11];
  2558. this.faceList[10] = [10, 11, 15, 14];
  2559. this.faceList[11] = [8, 9, 13, 12];
  2560. };
  2561.  
  2562. DowelButt.prototype.drawFaces = function (g) {
  2563. var j, k, n;
  2564. var p0;
  2565. var p1;
  2566. var p2;
  2567. var p;
  2568. var a = [];
  2569. var nface;
  2570. var face = [];
  2571. var color;
  2572. var p2d;
  2573. var hp = [];
  2574. var hp1 = [];
  2575. var hp2 = [];
  2576. var r = 8;
  2577. for (j = 0; j < this.dlist.length; j++) {
  2578. p0 = this.vertexList[this.faceList[this.dlist[j]][0]];
  2579. p1 = this.vertexList[this.faceList[this.dlist[j]][1]];
  2580. p2 = this.vertexList[this.faceList[this.dlist[j]][2]];
  2581. if (visible3DFace(p0, p1, p2)) {
  2582. nface = this.dlist[j];
  2583. face = this.faceList[nface];
  2584. a = new Array(face.length);
  2585. for (k = 0; k < face.length; k++) {
  2586. p = this.vertexList[face[k]];
  2587. a[k] = get2dPoint(p, this.xOffset, this.yOffset);
  2588. }
  2589.  
  2590. switch (nface) {
  2591. case 4:
  2592. case 5:
  2593. case 10:
  2594. case 11:
  2595. color = getFaceColor(p1, p2, p0, Wood.clfEndGrain);
  2596. break;
  2597. default:
  2598. color = getFaceColor(p1, p2, p0, Wood.clfFace);
  2599. }
  2600.  
  2601. if ((nface == 4) && (this.xShift > 40)) {
  2602. hp = drawLeftHole(g, -this.xShift / 2, -80, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2603. hp1 = drawLeftHole(g, -this.xShift / 2, 0, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2604. hp2 = drawLeftHole(g, -this.xShift / 2, 80, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2605. g.f(color).s(clEdge);
  2606. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).lt(a[0].x, a[0].y);
  2607. g.mt(hp[0].x, hp[0].y);
  2608. for (n = 0; n <= 20; n++) {
  2609. g.lt(hp[n].x, hp[n].y);
  2610. }
  2611. g.mt(hp1[0].x, hp1[0].y);
  2612. for (n = 0; n <= 20; n++) {
  2613. g.lt(hp1[n].x, hp1[n].y);
  2614. }
  2615.  
  2616. g.mt(hp2[0].x, hp2[0].y);
  2617. for (n = 0; n <= 20; n++) {
  2618. g.lt(hp2[n].x, hp2[n].y);
  2619. }
  2620. g.cp().es().ef();
  2621. } else if ((nface == 9) && (this.xShift > 40)) {
  2622. hp = drawRightHole(g, this.xShift / 2, -80, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2623. hp1 = drawRightHole(g, this.xShift / 2, 0, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2624. hp2 = drawRightHole(g, this.xShift / 2, 80, 0, 20, r, this.mat, this.xOffset, this.yOffset);
  2625. g.f(color).s(clEdge);
  2626. g.mt(a[0].x, a[0].y).lt(a[1].x, a[1].y).lt(a[2].x, a[2].y).lt(a[3].x, a[3].y).lt(a[0].x, a[0].y);
  2627. g.mt(hp[0].x, hp[0].y);
  2628. for (n = 0; n <= 20; n++) {
  2629. g.lt(hp[n].x, hp[n].y);
  2630. }
  2631. g.mt(hp1[0].x, hp1[0].y);
  2632. for (n = 0; n <= 20; n++) {
  2633. g.lt(hp1[n].x, hp1[n].y);
  2634. }
  2635. g.mt(hp2[0].x, hp2[0].y);
  2636. for (n = 0; n <= 20; n++) {
  2637. g.lt(hp2[n].x, hp2[n].y);
  2638. }
  2639. g.cp().es().ef();
  2640. } else {
  2641. g.f(color).s(clEdge);
  2642. g.mt(a[0].x, a[0].y);
  2643. for (n = 1; n < face.length; n++) {
  2644. g.lt(a[n].x, a[n].y);
  2645. }
  2646. g.cp().es().ef();
  2647. }
  2648. }
  2649. }
  2650. };
  2651.  
  2652. //***************************************************************************************************************
  2653. DowelButt.prototype.draw = function (g) {
  2654. var j;
  2655. var mx = new RotationMatrix(rx, 0);
  2656. var my = new RotationMatrix(ry, 1);
  2657. this.mat = matMultiply(mx, my);
  2658. this.initJoint();
  2659. var r = 8;
  2660. var dx;
  2661.  
  2662. //dx = 20;
  2663. if (this.xShift < 40)
  2664. dx = this.xShift / 2;
  2665. else
  2666. dx = 20;
  2667.  
  2668. for (j = 0; j < this.vertexList.length; j++) {
  2669. this.vertexList[j] = applyMatrix(this.vertexList[j], this.mat);
  2670. }
  2671.  
  2672. g.clear();
  2673. if (rx >= 0) {
  2674. if (ry > 90) {
  2675. this.dlist = [9, 6, 7, 8, 10, 11];
  2676. this.drawFaces(g);
  2677. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2678. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2679. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2680. this.dlist = [4, 0, 1, 2, 3, 5];
  2681. this.drawFaces(g);
  2682. } else if (ry >= 0) {
  2683. this.dlist = [9, 6, 7, 8, 10, 11];
  2684. this.drawFaces(g);
  2685. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2686. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2687. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2688. this.dlist = [4, 0, 1, 2, 3, 5];
  2689. this.drawFaces(g);
  2690. } else if (ry >= -90) {
  2691. this.dlist = [4, 0, 1, 2, 3, 5];
  2692. this.drawFaces(g);
  2693. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2694. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2695. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2696. this.dlist = [9, 6, 7, 8, 10, 11];
  2697. this.drawFaces(g);
  2698. } else {
  2699. this.dlist = [4, 0, 1, 2, 3, 5];
  2700. this.drawFaces(g);
  2701. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2702. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2703. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2704. this.dlist = [9, 6, 7, 8, 10, 11];
  2705. this.drawFaces(g);
  2706. }
  2707. } else if (rx < 0) {
  2708. if (ry > 90) {
  2709. this.dlist = [9, 6, 7, 8, 10, 11];
  2710. this.drawFaces(g);
  2711. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2712. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2713. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2714.  
  2715. this.dlist = [4, 0, 1, 2, 3, 5];
  2716. this.drawFaces(g);
  2717. } else if (ry >= 0) {
  2718. this.dlist = [9, 6, 7, 8, 10, 11];
  2719. this.drawFaces(g);
  2720. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2721. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2722. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2723. this.dlist = [4, 0, 1, 2, 3, 5];
  2724. this.drawFaces(g);
  2725. } else if (ry >= -90) {
  2726. this.dlist = [4, 0, 1, 2, 3, 5];
  2727. this.drawFaces(g);
  2728. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2729. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2730. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2731. this.dlist = [9, 6, 7, 8, 10, 11];
  2732. this.drawFaces(g);
  2733. } else {
  2734. this.dlist = [4, 0, 1, 2, 3, 5];
  2735. this.drawFaces(g);
  2736. drawCylinder(g, 0, -80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2737. drawCylinder(g, 0, 0, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2738. drawCylinder(g, 0, 80, 0, dx, r, this.mat, this.xOffset, this.yOffset);
  2739. this.dlist = [9, 6, 7, 8, 10, 11];
  2740. this.drawFaces(g);
  2741. }
  2742. }
  2743. };
  2744.  
  2745. DowelButt.prototype.explode = function (g, dx) {
  2746. this.xShift = 1.5 * dx;
  2747. this.draw(g);
  2748. };
  2749. return DowelButt;
  2750. })(BaseJoint);
  2751. ///<reference path='../../../common/ts/easeljs.d.ts'/>
  2752. ///<reference path='../../../common/ts/slider-cb.ts'/>
  2753. ///<reference path='../../../common/ts/pjradiobutton.ts'/>
  2754. ///<reference path='../../wood3d/wood3d.ts'/>
  2755. ///<reference path='../../wood3d/thumbnail.ts'/>
  2756. ///<reference path='../../wood3d/butt-rub.ts'/>
  2757. ///<reference path='../../wood3d/through-dovetail.ts'/>
  2758. ///<reference path='../../wood3d/lap-joint.ts'/>
  2759. ///<reference path='../../wood3d/mitre-butt2.ts'/>
  2760. ///<reference path='../../wood3d/splined-mitre.ts'/>
  2761. ///<reference path='../../wood3d/sqend-butt2.ts'/>
  2762. ///<reference path='../../wood3d/dowel-butt.ts'/>
  2763.  
  2764. var dpr = 1;
  2765. var scale = 1;
  2766. var baseWidth = 620;
  2767. var baseHeight = 400;
  2768. var stage;
  2769. var drag = false;
  2770. var mx = 0;
  2771. var my = 0;
  2772. var rx = 0;
  2773. var ry = 0;
  2774. var view = new createjs.Shape();
  2775. var joint;
  2776. var thumbs = new Array(7);
  2777.  
  2778. var explodeSlider = new SliderCB(300, 30, 0);
  2779. var info = new createjs.Text('', 'bold 14px Arial', '#ffffff');
  2780. var ryMax = 180;
  2781.  
  2782. var canUpdate = false;
  2783.  
  2784. function init() {
  2785. if (window.devicePixelRatio) {
  2786. dpr = window.devicePixelRatio;
  2787. }
  2788. scale = dpr;
  2789.  
  2790. // get a reference to the canvas we'll be working with:
  2791. var canvas = document.getElementById('canvas');
  2792.  
  2793. // create a stage object to work with the canvas. This is the top level node in the display list:
  2794. stage = new createjs.Stage(canvas);
  2795.  
  2796. //set the canvas size
  2797. var ua = navigator.userAgent.toLowerCase();
  2798. var isAndroid = ua.indexOf("android") > -1;
  2799. if (isAndroid) {
  2800. doFixedResize();
  2801. } else {
  2802. doScaleResize();
  2803. window.addEventListener("orientationchange", function () {
  2804. doScaleResize();
  2805. }, false);
  2806. }
  2807.  
  2808. // enable touch interactions if supported on the current device:
  2809. createjs.Touch.enable(stage);
  2810.  
  2811. //disable mouseover
  2812. stage.enableMouseOver(0);
  2813.  
  2814. var mt = new createjs.Shape();
  2815. mt.graphics.f('#003D84').dr(-200, -180, 400, 360);
  2816. mt.setTransform(200, 180);
  2817. stage.addChild(mt);
  2818. mt.addEventListener('mousedown', doMouse);
  2819. mt.addEventListener('pressmove', doMouse);
  2820. mt.addEventListener('pressup', doMouse);
  2821.  
  2822. view.setTransform(200, 180);
  2823. stage.addChild(view);
  2824.  
  2825. var msk = new createjs.Shape();
  2826. msk.graphics.f('#000000').dr(0, 0, 400, 360);
  2827. view.mask = msk;
  2828.  
  2829. info.setTransform(5, 5);
  2830. stage.addChild(info);
  2831. initGroupImage();
  2832. initThumbnails();
  2833. initControls();
  2834.  
  2835. showThumbnails(0x1);
  2836. doThumbnailClick(Wood.jtButtRub, 0x1);
  2837.  
  2838. createjs.Ticker.timingMode = createjs.Ticker.RAF;
  2839. createjs.Ticker.addEventListener("tick", doTick);
  2840. }
  2841.  
  2842. //**************************************************************************************************************
  2843. // ToDo add default rx and ry values here
  2844. //**************************************************************************************************************
  2845. function initJoint(jointID) {
  2846. switch (jointID) {
  2847. case Wood.jtDowelButt:
  2848. rx = -20;
  2849. ry = 20;
  2850. joint = new DowelButt(100);
  2851. joint.xOffset = 30;
  2852. joint.yOffset = 14;
  2853. break;
  2854.  
  2855. case Wood.jtLap:
  2856. rx = -25;
  2857. ry = -19;
  2858. joint = new LapJoint(100);
  2859. joint.xOffset = 38;
  2860. joint.yOffset = 14;
  2861. break;
  2862.  
  2863. case Wood.jtThroughDovetail:
  2864. rx = -17;
  2865. ry = -32;
  2866. joint = new ThroughDovetail(100);
  2867. joint.xOffset = 5;
  2868. joint.yOffset = -20;
  2869. break;
  2870.  
  2871. case Wood.jtMitredButt2:
  2872. rx = -23;
  2873. ry = -19;
  2874. joint = new MitreButt2(100);
  2875. joint.xOffset = 40;
  2876. joint.yOffset = 12;
  2877. break;
  2878.  
  2879. case Wood.jtSplinedMitre:
  2880. rx = -16;
  2881. ry = -20;
  2882. joint = new SplinedMitre(100);
  2883. joint.xOffset = 27;
  2884. joint.yOffset = 2;
  2885. break;
  2886.  
  2887. case Wood.jtSquareEndButt2:
  2888. rx = -16;
  2889. ry = -25;
  2890. joint = new SquareEndButt2(100);
  2891. joint.xOffset = 13;
  2892. joint.yOffset = 2;
  2893. break;
  2894.  
  2895. case Wood.jtButtRub:
  2896. rx = -27;
  2897. ry = 15;
  2898. joint = new ButtRubJoint(100);
  2899. joint.xOffset = -32;
  2900. joint.yOffset = -7;
  2901. break;
  2902. }
  2903. }
  2904.  
  2905. //*****************************************************************************************************
  2906. //Two sliders to zoom and explode the joint
  2907. //*****************************************************************************************************
  2908. function initControls() {
  2909. explodeSlider.min = -100000;
  2910. explodeSlider.max = 100000;
  2911. explodeSlider.showValue = false;
  2912. explodeSlider.setTransform(50, 365);
  2913. explodeSlider.setValue(0);
  2914. stage.addChild(explodeSlider);
  2915. explodeSlider.addCallback(sliderChange);
  2916.  
  2917. var slider = new SliderCB(300, 30, 1);
  2918. slider.min = 0.50;
  2919. slider.max = 1.00;
  2920. slider.dp = 2;
  2921.  
  2922. slider.showValue = false;
  2923. slider.setTransform(405, 330, 1, 1, -90);
  2924. slider.setValue(0.75);
  2925. stage.addChild(slider);
  2926. slider.addCallback(sliderChange);
  2927. }
  2928.  
  2929. //*****************************************************************************************************
  2930. //Large group image with radio buttons
  2931. //*****************************************************************************************************
  2932. function initGroupImage() {
  2933. var mc = new lib.BoxGroup();
  2934. mc.setTransform(440, 4);
  2935. stage.addChild(mc);
  2936. }
  2937.  
  2938. //*****************************************************************************************************
  2939. //Joint thumbnails - these are all in wood-lib.js
  2940. //*****************************************************************************************************
  2941. function initThumbnails() {
  2942. var holder = new createjs.Container();
  2943. holder.setTransform(440, 160);
  2944. stage.addChild(holder);
  2945.  
  2946. var tn = new Thumbnail(new lib.Buttrub(), Wood.jtButtRub, 0x1);
  2947. holder.addChild(tn);
  2948. tn.addCallback(doThumbnailClick);
  2949. thumbs[0] = tn;
  2950.  
  2951. tn = new Thumbnail(new lib.ThroughDovetail(), Wood.jtThroughDovetail, 0x1);
  2952. holder.addChild(tn);
  2953. tn.addCallback(doThumbnailClick);
  2954. thumbs[1] = tn;
  2955.  
  2956. tn = new Thumbnail(new lib.LapJoint(), Wood.jtLap, 0x1);
  2957. holder.addChild(tn);
  2958. tn.addCallback(doThumbnailClick);
  2959. thumbs[2] = tn;
  2960.  
  2961. tn = new Thumbnail(new lib.MitreButt2(), Wood.jtMitredButt2, 0x1);
  2962. holder.addChild(tn);
  2963. tn.addCallback(doThumbnailClick);
  2964. thumbs[3] = tn;
  2965.  
  2966. tn = new Thumbnail(new lib.SplinedMitre(), Wood.jtSplinedMitre, 0x1);
  2967. holder.addChild(tn);
  2968. tn.addCallback(doThumbnailClick);
  2969. thumbs[4] = tn;
  2970.  
  2971. tn = new Thumbnail(new lib.SqEndButt2(), Wood.jtSquareEndButt2, 0x1);
  2972. holder.addChild(tn);
  2973. tn.addCallback(doThumbnailClick);
  2974. thumbs[5] = tn;
  2975.  
  2976. tn = new Thumbnail(new lib.DowelButt(), Wood.jtDowelButt, 0x1);
  2977. holder.addChild(tn);
  2978. tn.addCallback(doThumbnailClick);
  2979. thumbs[6] = tn;
  2980. }
  2981.  
  2982. //*****************************************************************************************************
  2983. //Input hs as 0x1, 0x10, 0x100 or 0x1000.
  2984. //Each thumbnail has a hotspot value which is a binary 4 bit number, so we mask this hs to determine
  2985. //if the joint thumbnail should be displayed
  2986. //*****************************************************************************************************
  2987. function showThumbnails(hs) {
  2988. var j;
  2989. var x = 0;
  2990. var y = 0;
  2991. var n;
  2992. var count = 0;
  2993. var tn;
  2994. var firstTN = 0;
  2995.  
  2996. for (j = 0; j < thumbs.length; j++) {
  2997. tn = thumbs[j];
  2998. n = tn.hotspot;
  2999. if ((n & hs) == hs) {
  3000. if (count == 0)
  3001. firstTN = tn.jointID;
  3002.  
  3003. if (count < 6) {
  3004. x = 80 * (count % 2);
  3005. y = 55 * Math.floor(count / 2);
  3006. } else {
  3007. x = 0;
  3008. y = 165; // 60 * ((count - 6) % 3);
  3009. }
  3010.  
  3011. tn.setTransform(x, y);
  3012. tn.visible = true;
  3013. count++;
  3014. } else {
  3015. tn.visible = false;
  3016. }
  3017. }
  3018. return firstTN;
  3019. }
  3020.  
  3021. //*****************************************************************************************************
  3022. //Handle the rotation of the 3D display
  3023. //*****************************************************************************************************
  3024. function doMouse(e) {
  3025. if (e.type == 'mousedown') {
  3026. drag = true;
  3027. mx = e.localX;
  3028. my = e.localY;
  3029. } else if (e.type == 'pressmove') {
  3030. if (drag) {
  3031. ry += (e.localX - mx);
  3032. rx += (my - e.localY);
  3033.  
  3034. if (rx < -90)
  3035. rx = -90;
  3036. else if (rx > 90)
  3037. rx = 90;
  3038.  
  3039. if (ry < -ryMax)
  3040. ry = -ryMax;
  3041. else if (ry > ryMax)
  3042. ry = ryMax;
  3043. mx = e.localX;
  3044. my = e.localY;
  3045. joint.draw(view.graphics);
  3046. }
  3047. } else if (e.type == 'pressup') {
  3048. drag = false;
  3049. }
  3050. canUpdate = true;
  3051. }
  3052.  
  3053. //*****************************************************************************************************
  3054. //Handle slider changes to zoom or explode the joint.
  3055. //*****************************************************************************************************
  3056. function sliderChange(tag, value) {
  3057. if (tag == 0) {
  3058. joint.explode(view.graphics, 100 - value);
  3059. } else if (tag == 1) {
  3060. zoom = value * eyePos;
  3061. joint.draw(view.graphics);
  3062. }
  3063. canUpdate = true;
  3064. }
  3065.  
  3066. //*****************************************************************************************************
  3067. //Callback function to handle a click on one of the thumbnails
  3068. //*****************************************************************************************************
  3069. function doThumbnailClick(jointID, hotspot) {
  3070. info.text = getJointName(jointID);
  3071. explodeSlider.setValue(0);
  3072. initJoint(jointID);
  3073. joint.draw(view.graphics);
  3074.  
  3075. var j;
  3076. for (j = 0; j < thumbs.length; j++) {
  3077. thumbs[j].setSelected(thumbs[j].jointID == jointID);
  3078. }
  3079. if (jointID == Wood.jtSplinedMitre)
  3080. ryMax = 90;
  3081. else
  3082. ryMax = 180;
  3083. stage.update();
  3084. $('#info').load(getInfoFilename(jointID));
  3085. }
  3086.  
  3087. function doTick(e) {
  3088. if (canUpdate) {
  3089. stage.update();
  3090. canUpdate = false;
  3091. }
  3092. }
  3093.  
  3094. //--------------------------------------------------------------------------------------------------------------
  3095. //Initialize the animation
  3096. //--------------------------------------------------------------------------------------------------------------
  3097. window.onload = function () {
  3098. init();
  3099. stage.update();
  3100. };
  3101.  
  3102. //--------------------------------------------------------------------------------------------------------------
  3103. //Resize the animation
  3104. //--------------------------------------------------------------------------------------------------------------
  3105. function doFixedResize() {
  3106. var max = Math.min(screen.width, screen.height) - 40;
  3107. var targetWidth;
  3108. var targetHeight;
  3109. targetWidth = $('#content').width();
  3110. if (targetWidth > max) {
  3111. targetWidth = max;
  3112. }
  3113. targetHeight = targetWidth * baseHeight / baseWidth;
  3114. $('canvas').width(targetWidth);
  3115. $('canvas').height(targetHeight);
  3116. if (stage) {
  3117. stage.canvas.width = targetWidth * dpr;
  3118. stage.canvas.height = targetHeight * dpr;
  3119. scale = dpr * targetWidth / baseWidth;
  3120. stage.scaleX = scale;
  3121. stage.scaleY = scale;
  3122. stage.update();
  3123. }
  3124. }
  3125.  
  3126. function doScaleResize() {
  3127. var w;
  3128. var targetWidth;
  3129. var maxSize = Math.max(screen.width, screen.height);
  3130. var minSize = Math.min(screen.width, screen.height);
  3131. if (window.matchMedia("(orientation: portrait)").matches) {
  3132. w = minSize - 40;
  3133. } else {
  3134. w = maxSize - 40;
  3135. }
  3136.  
  3137. var availableHeight = $(window).height() - $('#content').offset().top - 10;
  3138. targetWidth = $('#content').width();
  3139. if (targetWidth > w)
  3140. targetWidth = w;
  3141. var targetHeight = targetWidth * baseHeight / baseWidth;
  3142.  
  3143. if (targetHeight > availableHeight) {
  3144. targetHeight = availableHeight;
  3145. targetWidth = targetHeight * baseWidth / baseHeight;
  3146. }
  3147.  
  3148. $('canvas').width(targetWidth);
  3149. $('canvas').height(targetHeight);
  3150. if (stage) {
  3151. stage.canvas.width = targetWidth * dpr;
  3152. stage.canvas.height = targetHeight * dpr;
  3153. scale = dpr * targetWidth / baseWidth;
  3154. stage.scaleX = scale;
  3155. stage.scaleY = scale;
  3156. stage.update();
  3157. }
  3158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement