animationNode.vwf.yaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. ## @name node3.animation.vwf
  14. ## @namespace
  15. ---
  16. extends:
  17. http://vwf.example.com/animation/animation.vwf
  18. methods:
  19. animationUpdate:
  20. parameters:
  21. - time
  22. - duration
  23. ## Translate by given translation over duration.
  24. ##
  25. ## @name node3.animation.vwf#translateBy
  26. ## @function
  27. ##
  28. ## @param {Array} translation
  29. ## @param {Number} duration
  30. ##
  31. ## @returns undefined
  32. translateBy:
  33. parameters:
  34. - translation
  35. - duration
  36. body: |
  37. this.startTranslation$ = this.translation || goog.vec.Vec3.create();
  38. var deltaTranslation = this.translationFromValue( translation );
  39. this.stopTranslation$ = goog.vec.Vec3.add(
  40. this.startTranslation$,
  41. deltaTranslation,
  42. goog.vec.Vec3.create()
  43. );
  44. if(duration > 0) {
  45. this.animationDuration = duration;
  46. this.animationUpdate = function(time, duration) {
  47. this.translation = goog.vec.Vec3.lerp(
  48. this.startTranslation$, this.stopTranslation$,
  49. time >= duration ? 1 : time / duration,
  50. goog.vec.Vec3.create()
  51. );
  52. }
  53. this.animationPlay(0, duration);
  54. }
  55. else {
  56. this.translation = this.stopTranslation$;
  57. } //@ sourceURL=node3.animation.translateBy.vwf
  58. ## Translate to given translation over duration.
  59. ##
  60. ## @name node3.animation.vwf#translateTo
  61. ## @function
  62. ##
  63. ## @param {Array} translation
  64. ## @param {Number} duration
  65. ##
  66. ## @returns undefined
  67. translateTo:
  68. parameters:
  69. - translation
  70. - duration
  71. body: |
  72. this.startTranslation$ = this.translation || goog.vec.Vec3.create();
  73. this.stopTranslation$ = this.translationFromValue( translation );
  74. if(duration > 0) {
  75. this.animationDuration = duration;
  76. this.animationUpdate = function(time, duration) {
  77. this.translation = goog.vec.Vec3.lerp(
  78. this.startTranslation$, this.stopTranslation$,
  79. duration == 0 ? duration : time / duration,
  80. goog.vec.Vec3.create()
  81. );
  82. }
  83. this.animationPlay(0, duration);
  84. }
  85. else {
  86. this.translation = this.stopTranslation$;
  87. } //@ sourceURL=node3.animation.translateTo.vwf
  88. ## Rotate by given rotation over duration.
  89. ##
  90. ## @name node3.animation.vwf#rotateBy
  91. ## @function
  92. ##
  93. ## @param {Array} rotation
  94. ## @param {Number} [duration]
  95. ## @param {String} [frame]
  96. ##
  97. ## @returns undefined
  98. rotateBy:
  99. parameters:
  100. - rotation
  101. - duration
  102. - frame
  103. body: |
  104. var rotation = this.rotationFromValue( rotation );
  105. var deltaQuaternion = goog.vec.Quaternion.fromAngleAxis(
  106. rotation[3] * Math.PI / 180,
  107. goog.vec.Vec3.createFromValues( rotation[0], rotation[1], rotation[2] ),
  108. goog.vec.Quaternion.create()
  109. );
  110. this.quaterniateBy( deltaQuaternion, duration, frame ); //@ sourceURL=node3.animation.rotateBy.vwf
  111. ## Rotate to given rotation over duration.
  112. ##
  113. ## @name node3.animation.vwf#rotateTo
  114. ## @function
  115. ##
  116. ## @param {Array} rotation
  117. ## @param {Number} duration
  118. ##
  119. ## @returns undefined
  120. rotateTo:
  121. parameters:
  122. - rotation
  123. - duration
  124. body: |
  125. var rotation = this.rotationFromValue( rotation );
  126. var stopQuaternion = goog.vec.Quaternion.fromAngleAxis(
  127. rotation[3] * Math.PI / 180,
  128. goog.vec.Vec3.createFromValues( rotation[0], rotation[1], rotation[2] ),
  129. goog.vec.Quaternion.create()
  130. );
  131. this.quaterniateTo( stopQuaternion, duration ); //@ sourceURL=node3.animation.rotateTo.vwf
  132. ## Rotate by given quaternion over duration.
  133. ##
  134. ## @name node3.animation.vwf#quaterniateBy
  135. ## @function
  136. ##
  137. ## @param {Array} quaternion
  138. ## @param {Number} [duration]
  139. ## @param {String} [frame]
  140. ##
  141. ## @returns undefined
  142. quaterniateBy:
  143. parameters:
  144. - quaternion
  145. - duration
  146. - frame
  147. body: |
  148. this.startQuaternion$ = this.quaternion || goog.vec.Quaternion.createFromValues( 0, 0, 0, 1 );
  149. var deltaQuaternion = this.quaternionFromValue( quaternion );
  150. if ( ! frame || frame == "rotated" ) {
  151. this.stopQuaternion$ = goog.vec.Quaternion.concat(
  152. deltaQuaternion,
  153. this.startQuaternion$,
  154. goog.vec.Quaternion.create()
  155. );
  156. } else if ( frame == "scaled" ) {
  157. this.stopQuaternion$ = goog.vec.Quaternion.concat(
  158. this.startQuaternion$,
  159. deltaQuaternion,
  160. goog.vec.Quaternion.create()
  161. );
  162. }
  163. if(duration > 0) {
  164. this.animationDuration = duration;
  165. this.animationUpdate = function(time, duration) {
  166. this.quaternion = goog.vec.Quaternion.slerp(
  167. this.startQuaternion$, this.stopQuaternion$,
  168. time >= duration ? 1 : time / duration,
  169. goog.vec.Quaternion.create()
  170. );
  171. }
  172. this.animationPlay(0, duration);
  173. }
  174. else {
  175. this.quaternion = this.stopQuaternion$;
  176. } //@ sourceURL=node3.animation.quaterniateBy.vwf
  177. ## Rotate to given quaternion over duration.
  178. ##
  179. ## @name node3.animation.vwf#quaterniateTo
  180. ## @function
  181. ##
  182. ## @param {Array} quaternion
  183. ## @param {Number} duration
  184. ##
  185. ## @returns undefined
  186. quaterniateTo:
  187. parameters:
  188. - quaternion
  189. - duration
  190. body: |
  191. this.startQuaternion$ = this.quaternion || goog.vec.Quaternion.createFromValues( 0, 0, 0, 1 );
  192. this.stopQuaternion$ = this.quaternionFromValue( quaternion );
  193. if(duration > 0) {
  194. this.animationDuration = duration;
  195. this.animationUpdate = function(time, duration) {
  196. this.quaternion = goog.vec.Quaternion.slerp(
  197. this.startQuaternion$, this.stopQuaternion$,
  198. duration == 0 ? duration : time / duration,
  199. goog.vec.Quaternion.create()
  200. );
  201. }
  202. this.animationPlay(0, duration);
  203. }
  204. else {
  205. this.quaternion = this.stopQuaternion$;
  206. } //@ sourceURL=node3.animation.quaterniateTo.vwf
  207. ## Scale by given scale over duration.
  208. ##
  209. ## @name node3.animation.vwf#scaleBy
  210. ## @function
  211. ##
  212. ## @param {Array} scale
  213. ## @param {Number} duration
  214. ##
  215. ## @returns undefined
  216. scaleBy:
  217. parameters:
  218. - scale
  219. - duration
  220. body: |
  221. this.startScale$ = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  222. var deltaScale = this.scaleFromValue( scale );
  223. this.stopScale$ = goog.vec.Vec3.createFromValues(
  224. this.startScale$[0] * deltaScale[0],
  225. this.startScale$[1] * deltaScale[1],
  226. this.startScale$[2] * deltaScale[2]
  227. );
  228. if(duration > 0) {
  229. this.animationDuration = duration;
  230. this.animationUpdate = function(time, duration) {
  231. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  232. this.startScale$, this.stopScale$,
  233. duration == 0 ? duration : time / duration,
  234. goog.vec.Vec3.create()
  235. );
  236. }
  237. this.animationPlay(0, duration);
  238. }
  239. else {
  240. this.scale = this.stopScale$;
  241. } //@ sourceURL=node3.animation.scaleBy.vwf
  242. ## Scale to given scale over duration.
  243. ##
  244. ## @name node3.animation.vwf#scaleTo
  245. ## @function
  246. ##
  247. ## @param {Array} scale
  248. ## @param {Number} duration
  249. ##
  250. ## @returns undefined
  251. scaleTo:
  252. parameters:
  253. - scale
  254. - duration
  255. body: |
  256. this.startScale$ = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  257. this.stopScale$ = this.scaleFromValue( scale );
  258. if(duration > 0) {
  259. this.animationDuration = duration;
  260. this.animationUpdate = function(time, duration) {
  261. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  262. this.startScale$, this.stopScale$,
  263. duration == 0 ? duration : time / duration,
  264. goog.vec.Vec3.create()
  265. );
  266. }
  267. this.animationPlay(0, duration);
  268. }
  269. else {
  270. this.scale = this.stopScale$;
  271. }//@ sourceURL=node3.animation.scaleTo.vwf
  272. ## Transform by the given amount over duration.
  273. ##
  274. ## @name node3.animation.vwf#transformBy
  275. ## @function
  276. ##
  277. ## @param {Array} transform
  278. ## @param {Number} duration
  279. ##
  280. ## @returns undefined
  281. transformBy:
  282. parameters:
  283. - transform
  284. - duration
  285. body: |
  286. var startTransform = this.transform || goog.vec.Vec3.create();
  287. var deltaTransform = this.transformFromValue( transform );
  288. // Left multiply by the delta
  289. var stopTransform = goog.vec.Mat4.multMat( deltaTransform, startTransform, goog.vec.Mat4.createFloat32() );
  290. this.transformTo( stopTransform, duration ); //@ sourceURL=node3.animation.transformBy.vwf
  291. ## Transform to given transform over duration.
  292. ##
  293. ## @name node3.animation.vwf#transformTo
  294. ## @function
  295. ##
  296. ## @param {Array} transform
  297. ## @param {Number} duration
  298. ##
  299. ## @returns undefined
  300. transformTo:
  301. parameters:
  302. - transform
  303. - duration
  304. body: |
  305. var stopTransform = this.transformFromValue( transform ) || goog.vec.Mat4.createIdentity();
  306. if ( duration > 0 ) {
  307. // Calculate the start and stop translations
  308. this.startTranslation$ = this.translation || goog.vec.Vec3.create();
  309. this.stopTranslation$ = goog.vec.Vec3.create();
  310. goog.vec.Mat4.getColumn( stopTransform, 3, this.stopTranslation$ );
  311. // Calculate the start and stop quaternion and scale
  312. this.startScale$ = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  313. this.stopScale$ = goog.vec.Vec3.create();
  314. this.startQuaternion$ = this.quaternion || goog.vec.Quaternion.createFromValues( 0, 0, 0, 1 );
  315. this.stopQuaternion$ = goog.vec.Quaternion.fromRotationMatrix4(
  316. this.unscaledTransform( stopTransform || goog.vec.Mat4.createIdentity(), this.stopScale$, goog.vec.Mat4.create() ),
  317. goog.vec.Quaternion.create()
  318. );
  319. this.animationDuration = duration;
  320. // Call the appropriate functions to do the translation and quaterniation (that is totally a word)
  321. this.animationUpdate = function(time, duration) {
  322. this.translation = goog.vec.Vec3.lerp(
  323. this.startTranslation$, this.stopTranslation$,
  324. duration == 0 ? duration : time / duration,
  325. goog.vec.Vec3.create()
  326. );
  327. this.quaternion = goog.vec.Quaternion.slerp(
  328. this.startQuaternion$, this.stopQuaternion$,
  329. duration == 0 ? duration : time / duration,
  330. goog.vec.Quaternion.create()
  331. );
  332. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  333. this.startScale$, this.stopScale$,
  334. duration == 0 ? duration : time / duration,
  335. goog.vec.Vec3.create()
  336. );
  337. }
  338. this.animationPlay(0, duration);
  339. }
  340. else {
  341. this.transform = stopTransform;
  342. } //@ sourceURL=node3.animation.transformTo.vwf
  343. ## Transform the world transform by the given amount over duration.
  344. ##
  345. ## @name node3.animation.vwf#worldTransformBy
  346. ## @function
  347. ##
  348. ## @param {Array} transform
  349. ## @param {Number} duration
  350. ##
  351. ## @returns undefined
  352. worldTransformBy:
  353. parameters:
  354. - transform
  355. - duration
  356. body: |
  357. var startWorldTransform = this.worldTransform || goog.vec.Mat4.create();
  358. var deltaTransform = this.transformFromValue( transform );
  359. // Left multiply by the delta
  360. var stopWorldTransform = goog.vec.Mat4.multMat( deltaTransform, startWorldTransform,
  361. goog.vec.Mat4.createFloat32() );
  362. this.worldTransformTo( stopWorldTransform, duration ) //@ sourceURL=node3.animation.worldTransformBy.vwf
  363. ## Transform the world transform to given transform over duration.
  364. ##
  365. ## @name node3.animation.vwf#worldTransformTo
  366. ## @function
  367. ##
  368. ## @param {Array} transform
  369. ## @param {Number} duration
  370. ##
  371. ## @returns undefined
  372. worldTransformTo:
  373. parameters:
  374. - transform
  375. - duration
  376. body: |
  377. var stopWorldTransform = this.transformFromValue( transform );
  378. var stopTransform;
  379. if ( this.parent && this.parent.worldTransform ) {
  380. // We need to find the local transform that will bring about the desired world transform
  381. // The math for this looks like -
  382. // (new worldTransform) = (parentWorldTransform) * (transform)
  383. // So, if we left multiply both sides by the inverse of the parentWorldTransform...
  384. // inv(parentWorldTransform) * (new worldTransform) = (transform)
  385. // Find the inverse parent worldTransform
  386. var inverseParentWorldTransform = goog.vec.Mat4.createFloat32();
  387. if ( goog.vec.Mat4.invert( this.parent.worldTransform, inverseParentWorldTransform ) ) {
  388. // Left multiply the new worldTransform by the inverse parent worldTransform
  389. stopTransform = goog.vec.Mat4.multMat( inverseParentWorldTransform, stopWorldTransform,
  390. goog.vec.Mat4.createFloat32() );
  391. }
  392. else {
  393. stopTransform = goog.vec.Mat4.createIdentity();
  394. this.logger.error( "Parent '" + this.parent.id + "' transform matrix is not invertible: " +
  395. this.parent.transform );
  396. }
  397. }
  398. else {
  399. stopTransform = stopWorldTransform;
  400. }
  401. this.transformTo( stopTransform, duration ); //@ sourceURL=node3.animation.worldTransformTo.vwf
  402. event:
  403. changingTransformFromView: