transformTool.vwf.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of an editable node3 behavior
  14. ##
  15. ## @name node3edit.vwf
  16. ## @namespace
  17. ---
  18. extends: http://vwf.example.com/node3.vwf
  19. properties:
  20. ttPositions:
  21. ttPoints:
  22. boxCenter:
  23. pivotPoint:
  24. methods:
  25. createTool:
  26. getToolDimensions:
  27. createToolGeometry:
  28. deleteGeometry:
  29. createPointList:
  30. testTool:
  31. objectSelected:
  32. calcBoxCenter:
  33. removeChildren:
  34. events:
  35. transformUpdated:
  36. scripts:
  37. - |
  38. this.initialize = function() {
  39. //console.info( "== initialize == transformTool == initialize ==" );
  40. this.objBoundingBox = undefined;
  41. this.selectedID = undefined;
  42. this.selectedNode = undefined;
  43. }
  44. this.transformUpdated = this.events.add( function( ID ) {
  45. } );
  46. this.objectSelected = function( node ) {
  47. if ( node ) {
  48. this.selectedNode = node;
  49. this.selectedID = this.selectedNode.id;
  50. } else {
  51. if ( this.children.length > 0 ) {
  52. this.selectedNode = this.children[0];
  53. this.selectedID = this.selectedNode.id;
  54. } else {
  55. this.selectedID = undefined;
  56. this.selectedNode = undefined;
  57. }
  58. }
  59. if ( this.selectedNode ) {
  60. this.createTool();
  61. }
  62. };
  63. this.testTool = function() {
  64. this.createToolGeometry( 100, 100, 100 );
  65. this.position = [ 0, 0, 0 ];
  66. }
  67. this.createTool = function() {
  68. this.objBoundingBox = this.selectedNode.boundingbox;
  69. if ( this.objBoundingBox ) {
  70. this.calcBoxCenter();
  71. var dim = this.getToolDimensions();
  72. if ( dim ) {
  73. this.createToolGeometry( dim[0], dim[1], dim[2] );
  74. }
  75. }
  76. }
  77. this.calcBoxCenter = function() {
  78. if ( this.objBoundingBox ) {
  79. var min = this.objBoundingBox.min;
  80. var max = this.objBoundingBox.max;
  81. var dX = max.x-min.x;
  82. var dY = max.y-min.y;
  83. var dZ = max.z-min.z;
  84. this.boxCenter = goog.vec.Vec3.add(
  85. goog.vec.Vec3.createFromArray( [ min.x, min.y, min.z ] ),
  86. goog.vec.Vec3.scale(
  87. goog.vec.Vec3.createFromArray( [ dX, dY, dZ ] ),
  88. 0.5,
  89. goog.vec.Vec3.create()
  90. ),
  91. goog.vec.Vec3.create()
  92. );
  93. //console.info( " this.boxCenter = " + Array.prototype.slice.call( this.boxCenter ) );
  94. }
  95. }
  96. this.deleteGeometry = function() {
  97. if ( this.children["transXPos"] !== undefined ) {
  98. this.children["transXPos"].deleteGeometry();
  99. }
  100. if ( this.children["transXNeg"] !== undefined ) {
  101. this.children["transXNeg"].deleteGeometry();
  102. }
  103. if ( this.children["transYPos"] !== undefined ) {
  104. this.children["transYPos"].deleteGeometry();
  105. }
  106. if ( this.children["transYNeg"] !== undefined ) {
  107. this.children["transYNeg"].deleteGeometry();
  108. }
  109. if ( this.children["transZPos"] !== undefined ) {
  110. this.children["transZPos"].deleteGeometry();
  111. }
  112. if ( this.children["transZNeg"] !== undefined ) {
  113. this.children["transZNeg"].deleteGeometry();
  114. }
  115. if ( this.children["rotX"] !== undefined ) {
  116. this.children["rotX"].deleteGeometry();
  117. }
  118. if ( this.children["rotY"] !== undefined ) {
  119. this.children["rotY"].deleteGeometry();
  120. }
  121. if ( this.children["rotZ"] !== undefined ) {
  122. this.children["rotY"].deleteGeometry();
  123. }
  124. if ( this.children["scaler"] !== undefined ) {
  125. this.children["scaler"].deleteGeometry();
  126. }
  127. }
  128. this.removeChildren = function() {
  129. //console.info( "DESELECTING: " + this.selectedID );
  130. if ( this.children ) {
  131. for ( var i = this.children.length-1; i >= 0; i-- ) {
  132. this.children.delete( node.children[i] );
  133. }
  134. }
  135. }
  136. this.getToolDimensions = function() {
  137. if ( this.objBoundingBox ) {
  138. var dX = this.objBoundingBox.max.x-this.objBoundingBox.min.x;
  139. var dY = this.objBoundingBox.max.y-this.objBoundingBox.min.y;
  140. var dZ = this.objBoundingBox.max.z-this.objBoundingBox.min.z;
  141. return [ dX, dY, dZ ];
  142. }
  143. return undefined;
  144. }
  145. this.createToolGeometry = function( dx, dy, dz ) {
  146. this.createPointList( dx, dy, dz );
  147. var path = "http://vwf.example.com/tools/transform/";
  148. if ( this.ttPoints ){
  149. // translate xPos 9,18,15,12
  150. if ( this.children["transXPos"] === undefined ) {
  151. this.children.create( "transXPos", { "includes": path + "translateXPos.vwf" }, function( child ) {
  152. child.createGeometry();
  153. } );
  154. } else {
  155. this.children["transXPos"].createGeometry();
  156. }
  157. // translate xNeg 21,24,27,30
  158. if ( this.children["transXNeg"] === undefined ) {
  159. this.children.create( "transXNeg", { "includes": path + "translateXNeg.vwf" }, function( child ) {
  160. child.createGeometry();
  161. } );
  162. } else {
  163. this.children["transXNeg"].createGeometry();
  164. }
  165. // translate yPos 48,49,50,51
  166. if ( this.children["transYPos"] === undefined ) {
  167. this.children.create( "transYPos", { "includes": path + "translateYPos.vwf" }, function( child ) {
  168. child.createGeometry();
  169. } );
  170. } else {
  171. this.children["transYPos"].createGeometry();
  172. }
  173. // translate yNeg 52,53,54,55
  174. if ( this.children["transYNeg"] === undefined ) {
  175. this.children.create( "transYNeg", { "includes": path + "translateYNeg.vwf" }, function( child ) {
  176. child.createGeometry();
  177. } );
  178. } else {
  179. this.children["transYNeg"].createGeometry();
  180. }
  181. // translate zPos 32,34,36,38
  182. if ( this.children["transZPos"] === undefined ) {
  183. this.children.create( "transZPos", { "includes": path + "translateZPos.vwf" }, function( child ) {
  184. child.createGeometry();
  185. } );
  186. } else {
  187. this.children["transZPos"].createGeometry();
  188. }
  189. // translate zNeg 40,46,44,42
  190. if ( this.children["transZNeg"] === undefined ) {
  191. this.children.create( "transZNeg", { "includes": path + "translateZNeg.vwf" }, function( child ) {
  192. child.createGeometry();
  193. } );
  194. } else {
  195. this.children["transZNeg"].createGeometry();
  196. }
  197. // rotate X yPos 34,35,37,36
  198. // rotate X yNeg 33,32,38,39
  199. // rotate X yPos 44,45,43,42
  200. // rotate X yNeg 47,46,40,41
  201. // rotate X zPos 39,54,53,33
  202. // rotate X zNeg 55,47,41,52
  203. // rotate X zPos 50,49,35,37
  204. // rotate X zNeg 43,48,51,45
  205. if ( this.children["rotX"] === undefined ) {
  206. this.children.create( "rotX", { "includes": path + "rotationX.vwf" }, function( child) {
  207. child.createGeometry();
  208. } );
  209. } else {
  210. this.children["rotX"].createGeometry();
  211. }
  212. // rotate Z yPos 12,13,16,15
  213. // rotate Z yNeg 10,9,18,19
  214. // rotate Z yPos 24,25,28,27
  215. // rotate Z yNeg 22,21,30,31
  216. // rotate Z xPos 16,48,49,13
  217. // rotate Z xNeg 28,51,50,25
  218. // rotate Z xPos 52,19,10,53
  219. // rotate Z xNeg 22,54,55,31
  220. if ( this.children["rotY"] === undefined ) {
  221. this.children.create( "rotY", { "includes": path + "rotationY.vwf" }, function( child) {
  222. child.createGeometry();
  223. } );
  224. } else {
  225. this.children["rotY"].createGeometry();
  226. }
  227. // rotate Z yPos 12,13,16,15
  228. // rotate Z yNeg 10,9,18,19
  229. // rotate Z yPos 24,25,28,27
  230. // rotate Z yNeg 22,21,30,31
  231. // rotate Z xPos 16,48,49,13
  232. // rotate Z xNeg 28,51,50,25
  233. // rotate Z xPos 52,19,10,53
  234. // rotate Z xNeg 22,54,55,31
  235. if ( this.children["rotZ"] === undefined ) {
  236. this.children.create( "rotZ", { "includes": path + "rotationZ.vwf" }, function( child) {
  237. child.createGeometry();
  238. } );
  239. } else {
  240. this.children["rotZ"].createGeometry();
  241. }
  242. if ( this.children["scaler"] === undefined ) {
  243. this.children.create( "scaler", { "includes": path + "scaleXYZ.vwf" }, function( child) {
  244. child.createGeometry();
  245. } );
  246. } else {
  247. this.children["scaler"].createGeometry();
  248. }
  249. }
  250. }
  251. this.createPointList = function( dX, dY, dZ ) {
  252. var points = [];
  253. //console.info( "createPointList( " +dX+ ", "+dY+ ", "+ +dZ+ " )" );
  254. var fHalfX = dX * 0.6;
  255. var fHalfY = dY * 0.6;
  256. var fHalfZ = dZ * 0.6;
  257. var fXThick = dX * 0.08;
  258. var fYThick = dY * 0.08;
  259. var fZThick = dZ * 0.08;
  260. var rp;
  261. points.push( [ fHalfX, -fHalfY, fHalfZ ] ); //0
  262. points.push( [ fHalfX, fHalfY, fHalfZ ] ); //1
  263. points.push( [ -fHalfX, fHalfY, fHalfZ ] ); //2
  264. points.push( [ -fHalfX, -fHalfY, fHalfZ ] ); //3
  265. points.push( [ fHalfX, -fHalfY, -fHalfZ ] ); //4
  266. points.push( [ fHalfX, fHalfY, -fHalfZ ] ); //5
  267. points.push( [ -fHalfX, fHalfY, -fHalfZ ] ); //6
  268. points.push( [ -fHalfX, -fHalfY, -fHalfZ ] ); //7
  269. // x pos
  270. // y-neg z-pos
  271. rp = points[ 0 ];
  272. points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //8
  273. points.push( [ rp[0], fYThick + rp[1], -fZThick + rp[2] ] ); //9
  274. points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //10
  275. // y-pos z-pos
  276. rp = points[ 1 ];
  277. points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //11
  278. points.push( [ rp[0], -fYThick + rp[1], -fZThick + rp[2] ] ); //12
  279. points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //13
  280. // y-pos z-neg
  281. rp = points[ 5 ];
  282. points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //14
  283. points.push( [ rp[0], -fYThick + rp[1], fZThick + rp[2] ] ); //15
  284. points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //16
  285. // y-neg z-neg
  286. rp = points[ 4 ];
  287. points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //17
  288. points.push( [ rp[0], fYThick + rp[1], fZThick + rp[2] ] ); //18
  289. points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //19
  290. // x neg
  291. // y-neg z-pos
  292. rp = points[ 3 ];
  293. points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //20
  294. points.push( [ rp[0], fYThick + rp[1], -fZThick + rp[2] ] ); //21
  295. points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //22
  296. // y-pos z-pos
  297. rp = points[ 2 ];
  298. points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //23
  299. points.push( [ rp[0], -fYThick + rp[1], -fZThick + rp[2] ] ); //24
  300. points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //25
  301. // y-pos z-neg
  302. rp = points[ 6 ];
  303. points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //26
  304. points.push( [ rp[0], -fYThick + rp[1], fZThick + rp[2] ] ); //27
  305. points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //28
  306. // y-neg z-neg
  307. rp = points[ 7 ];
  308. points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //29
  309. points.push( [ rp[0], fYThick + rp[1], fZThick + rp[2] ] ); //30
  310. points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //31
  311. // z pos
  312. // x-pos y-neg
  313. //8
  314. rp = points[ 0 ];
  315. points.push( [ -fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //32
  316. points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //33
  317. // x-pos y-pos
  318. //11
  319. rp = points[ 1 ];
  320. points.push( [ -fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //34
  321. points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //35
  322. // x-neg y-pos
  323. //23
  324. rp = points[ 2 ];
  325. points.push( [ fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //36
  326. points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //37
  327. // x-neg y-neg
  328. //20
  329. rp = points[ 3 ];
  330. points.push( [ fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //38
  331. points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //39
  332. // z neg
  333. // x-pos y-neg
  334. //17
  335. rp = points[ 4 ];
  336. points.push( [ -fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //40
  337. points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //41
  338. // x-pos y-pos
  339. //14
  340. rp = points[ 5 ];
  341. points.push( [ -fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //42
  342. points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //43
  343. // x-neg y-pos
  344. //26
  345. rp = points[ 6 ];
  346. points.push( [ fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //44
  347. points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //45
  348. // x-neg y-neg
  349. //29
  350. rp = points[ 7 ];
  351. points.push( [ fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //46
  352. points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //47
  353. // y pos
  354. // x-pos z-neg
  355. //16
  356. rp = points[ 5 ];
  357. points.push( [ -fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //48
  358. //43
  359. // x-pos z-pos
  360. //13
  361. rp = points[ 1 ];
  362. points.push( [ -fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //49
  363. //35
  364. // x-neg z-pos
  365. //25
  366. rp = points[ 2 ];
  367. points.push( [ fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //50
  368. //37
  369. // x-neg z-neg
  370. //28
  371. rp = points[ 6 ];
  372. points.push( [ fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //51
  373. //45
  374. // y neg
  375. // x-pos z-neg
  376. //19
  377. rp = points[ 4 ];
  378. points.push( [ -fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //52
  379. //41
  380. // x-pos z-pos
  381. //10
  382. rp = points[ 0 ];
  383. points.push( [ -fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //53
  384. //33
  385. // x-neg z-pos
  386. //22
  387. rp = points[ 3 ];
  388. points.push( [ fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //54
  389. //39
  390. // x-neg z-neg
  391. //31
  392. rp = points[ 7 ];
  393. points.push( [ fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //55
  394. //47
  395. this.ttPositions = points;
  396. var pts = [];
  397. for ( var i = 0; i < points.length; i++ ) {
  398. //console.info( " points["+i+"] = " +points[i] );
  399. pts.push( points[i][0] );
  400. pts.push( points[i][1] );
  401. pts.push( points[i][2] );
  402. }
  403. this.ttPoints = pts;
  404. }//@ sourceURL=transformTool.vwf