animationNode.vwf.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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.startTranslationSIM = this.position || goog.vec.Vec3.create();
  38. var deltaTranslation = this.translationFromValue( translation );
  39. this.stopTranslationSIM = goog.vec.Vec3.add(
  40. this.startTranslationSIM,
  41. deltaTranslation,
  42. goog.vec.Vec3.create()
  43. );
  44. if(duration > 0) {
  45. this.animationDuration = duration;
  46. this.animationUpdate = function(time, duration) {
  47. this.position = goog.vec.Vec3.lerp(
  48. this.startTranslationSIM, this.stopTranslationSIM,
  49. time >= duration ? 1 : time / duration,
  50. goog.vec.Vec3.create()
  51. );
  52. }
  53. this.animationPlay(0, duration);
  54. }
  55. else {
  56. this.position = this.stopTranslationSIM;
  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.startTranslationSIM = this.position || goog.vec.Vec3.create();
  73. this.stopTranslationSIM = this.translationFromValue( translation );
  74. if(duration > 0) {
  75. this.animationDuration = duration;
  76. this.animationUpdate = function(time, duration) {
  77. this.position = goog.vec.Vec3.lerp(
  78. this.startTranslationSIM, this.stopTranslationSIM,
  79. duration == 0 ? duration : time / duration,
  80. goog.vec.Vec3.create()
  81. );
  82. }
  83. this.animationPlay(0, duration);
  84. }
  85. else {
  86. this.position = this.stopTranslationSIM;
  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. let rotationValue = this.translationFromValue(rotation);
  105. let deltaQuaternion = (new THREE.Quaternion()).setFromEuler(new THREE.Euler(
  106. (THREE.Math.degToRad(rotationValue[0])),
  107. (THREE.Math.degToRad(rotationValue[1])),
  108. (THREE.Math.degToRad(rotationValue[2])), 'YXZ'
  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. let rotationValue = this.translationFromValue(rotation);
  126. let stopQuaternion = (new THREE.Quaternion()).setFromEuler(new THREE.Euler(
  127. (THREE.Math.degToRad(rotationValue[0])),
  128. (THREE.Math.degToRad(rotationValue[1])),
  129. (THREE.Math.degToRad(rotationValue[2])), 'YXZ'
  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.startQuaternionSIM = (new THREE.Quaternion()).setFromEuler(new THREE.Euler(
  149. (THREE.Math.degToRad(this.rotation[0])),
  150. (THREE.Math.degToRad(this.rotation[1])),
  151. (THREE.Math.degToRad(this.rotation[2])), 'YXZ'
  152. ));
  153. var deltaQuaternion = (new THREE.Quaternion).copy(quaternion);
  154. if ( ! frame || frame == "rotated" ) {
  155. this.stopQuaternionSIM = (new THREE.Quaternion()).multiplyQuaternions(deltaQuaternion, this.startQuaternionSIM);
  156. } else if ( frame == "scaled" ) {
  157. this.stopQuaternionSIM = (new THREE.Quaternion()).multiplyQuaternions(this.startQuaternionSIM, deltaQuaternion);
  158. }
  159. //this.stopQuaternionSIM = (new THREE.Quaternion()).copy(quaternion);
  160. if(duration > 0) {
  161. this.animationDuration = duration;
  162. this.animationUpdate = function(time, duration) {
  163. let q = new THREE.Quaternion();
  164. let e = new THREE.Euler();
  165. let step = (time >= duration) ? 1 : time / duration;
  166. THREE.Quaternion.slerp(this.startQuaternionSIM, this.stopQuaternionSIM, q, step || 0);
  167. let interp = e.setFromQuaternion(q, 'YXZ');
  168. this.rotation = [THREE.Math.radToDeg(interp.x), THREE.Math.radToDeg(interp.y), THREE.Math.radToDeg(interp.z)];
  169. }
  170. this.animationPlay(0, duration);
  171. }
  172. else {
  173. let eE = new THREE.Euler();
  174. let eQ = (new THREE.Quaternion).copy(this.stopQuaternionSIM);
  175. let interpE = eE.setFromQuaternion(eQ, 'YXZ');
  176. this.rotation = [THREE.Math.radToDeg(interpE.x),THREE.Math.radToDeg(interpE.y), THREE.Math.radToDeg(interpE.z)];
  177. //this.quaternion = this.stopQuaternionSIM;
  178. } //@ sourceURL=node3.animation.quaterniateBy.vwf
  179. ## Rotate to given quaternion over duration.
  180. ##
  181. ## @name node3.animation.vwf#quaterniateTo
  182. ## @function
  183. ##
  184. ## @param {Array} quaternion
  185. ## @param {Number} duration
  186. ##
  187. ## @returns undefined
  188. quaterniateTo:
  189. parameters:
  190. - quaternion
  191. - duration
  192. body: |
  193. this.startQuaternionSIM = (new THREE.Quaternion()).setFromEuler(new THREE.Euler(
  194. (THREE.Math.degToRad(this.rotation[0])),
  195. (THREE.Math.degToRad(this.rotation[1])),
  196. (THREE.Math.degToRad(this.rotation[2])), 'YXZ'
  197. ));
  198. this.stopQuaternionSIM = (new THREE.Quaternion).copy(quaternion);
  199. if(duration > 0) {
  200. this.animationDuration = duration;
  201. this.animationUpdate = function(time, duration) {
  202. let q = new THREE.Quaternion();
  203. let e = new THREE.Euler();
  204. let step = (time >= duration) ? 1 : time / duration;
  205. THREE.Quaternion.slerp(this.startQuaternionSIM, this.stopQuaternionSIM, q, step || 0);
  206. let interp = e.setFromQuaternion(q, 'YXZ');
  207. this.rotation = [THREE.Math.radToDeg(interp.x), THREE.Math.radToDeg(interp.y), THREE.Math.radToDeg(interp.z)];
  208. }
  209. this.animationPlay(0, duration);
  210. }
  211. else {
  212. let eE = new THREE.Euler();
  213. let eQ = (new THREE.Quaternion).copy(this.stopQuaternionSIM);
  214. let interpE = eE.setFromQuaternion(eQ, 'YXZ');
  215. this.rotation = [THREE.Math.radToDeg(interpE.x),THREE.Math.radToDeg(interpE.y), THREE.Math.radToDeg(interpE.z)];
  216. //this.quaternion = this.stopQuaternionSIM;
  217. } //@ sourceURL=node3.animation.quaterniateTo.vwf
  218. ## Scale by given scale over duration.
  219. ##
  220. ## @name node3.animation.vwf#scaleBy
  221. ## @function
  222. ##
  223. ## @param {Array} scale
  224. ## @param {Number} duration
  225. ##
  226. ## @returns undefined
  227. scaleBy:
  228. parameters:
  229. - scale
  230. - duration
  231. body: |
  232. this.startScaleSIM = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  233. var deltaScale = this.translationFromValue( scale );
  234. this.stopScaleSIM = goog.vec.Vec3.createFromValues(
  235. this.startScaleSIM[0] * deltaScale[0],
  236. this.startScaleSIM[1] * deltaScale[1],
  237. this.startScaleSIM[2] * deltaScale[2]
  238. );
  239. if(duration > 0) {
  240. this.animationDuration = duration;
  241. this.animationUpdate = function(time, duration) {
  242. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  243. this.startScaleSIM, this.stopScaleSIM,
  244. duration == 0 ? duration : time / duration,
  245. goog.vec.Vec3.create()
  246. );
  247. }
  248. this.animationPlay(0, duration);
  249. }
  250. else {
  251. this.scale = this.stopScaleSIM;
  252. } //@ sourceURL=node3.animation.scaleBy.vwf
  253. ## Scale to given scale over duration.
  254. ##
  255. ## @name node3.animation.vwf#scaleTo
  256. ## @function
  257. ##
  258. ## @param {Array} scale
  259. ## @param {Number} duration
  260. ##
  261. ## @returns undefined
  262. scaleTo:
  263. parameters:
  264. - scale
  265. - duration
  266. body: |
  267. this.startScaleSIM = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  268. this.stopScaleSIM = this.translationFromValue( scale );
  269. if(duration > 0) {
  270. this.animationDuration = duration;
  271. this.animationUpdate = function(time, duration) {
  272. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  273. this.startScaleSIM, this.stopScaleSIM,
  274. duration == 0 ? duration : time / duration,
  275. goog.vec.Vec3.create()
  276. );
  277. }
  278. this.animationPlay(0, duration);
  279. }
  280. else {
  281. this.scale = this.stopScaleSIM;
  282. }//@ sourceURL=node3.animation.scaleTo.vwf
  283. ## Transform by the given amount over duration.
  284. ##
  285. ## @name node3.animation.vwf#transformBy
  286. ## @function
  287. ##
  288. ## @param {Array} transform
  289. ## @param {Number} duration
  290. ##
  291. ## @returns undefined
  292. transformBy:
  293. parameters:
  294. - transform
  295. - duration
  296. body: |
  297. var startTransform = this.transform || goog.vec.Vec3.create();
  298. var deltaTransform = this.transformFromValue( transform );
  299. // Left multiply by the delta
  300. var stopTransform = goog.vec.Mat4.multMat( deltaTransform, startTransform, goog.vec.Mat4.createFloat32() );
  301. this.transformTo( stopTransform, duration ); //@ sourceURL=node3.animation.transformBy.vwf
  302. ## Transform to given transform over duration.
  303. ##
  304. ## @name node3.animation.vwf#transformTo
  305. ## @function
  306. ##
  307. ## @param {Array} transform
  308. ## @param {Number} duration
  309. ##
  310. ## @returns undefined
  311. transformTo:
  312. parameters:
  313. - transform
  314. - duration
  315. body: |
  316. var stopTransform = this.transformFromValue( transform ) || goog.vec.Mat4.createIdentity();
  317. if ( duration > 0 ) {
  318. // Calculate the start and stop translations
  319. this.startTranslationSIM = this.translation || goog.vec.Vec3.create();
  320. this.stopTranslationSIM = goog.vec.Vec3.create();
  321. goog.vec.Mat4.getColumn( stopTransform, 3, this.stopTranslationSIM );
  322. // Calculate the start and stop quaternion and scale
  323. this.startScaleSIM = this.scale || goog.vec.Vec3.createFromValues( 1, 1, 1 );
  324. this.stopScaleSIM = goog.vec.Vec3.create();
  325. this.startQuaternionSIM = this.quaternion || goog.vec.Quaternion.createFromValues( 0, 0, 0, 1 );
  326. this.stopQuaternionSIM = goog.vec.Quaternion.fromRotationMatrix4(
  327. this.unscaledTransform( stopTransform || goog.vec.Mat4.createIdentity(), this.stopScaleSIM, goog.vec.Mat4.create() ),
  328. goog.vec.Quaternion.create()
  329. );
  330. this.animationDuration = duration;
  331. // Call the appropriate functions to do the translation and quaterniation (that is totally a word)
  332. this.animationUpdate = function(time, duration) {
  333. this.translation = goog.vec.Vec3.lerp(
  334. this.startTranslationSIM, this.stopTranslationSIM,
  335. duration == 0 ? duration : time / duration,
  336. goog.vec.Vec3.create()
  337. );
  338. this.quaternion = goog.vec.Quaternion.slerp(
  339. this.startQuaternionSIM, this.stopQuaternionSIM,
  340. duration == 0 ? duration : time / duration,
  341. goog.vec.Quaternion.create()
  342. );
  343. this.scale = goog.vec.Vec3.lerp( // TODO: should be geometric interpolation
  344. this.startScaleSIM, this.stopScaleSIM,
  345. duration == 0 ? duration : time / duration,
  346. goog.vec.Vec3.create()
  347. );
  348. }
  349. this.animationPlay(0, duration);
  350. }
  351. else {
  352. this.transform = stopTransform;
  353. } //@ sourceURL=node3.animation.transformTo.vwf
  354. ## Transform the world transform by the given amount over duration.
  355. ##
  356. ## @name node3.animation.vwf#worldTransformBy
  357. ## @function
  358. ##
  359. ## @param {Array} transform
  360. ## @param {Number} duration
  361. ##
  362. ## @returns undefined
  363. worldTransformBy:
  364. parameters:
  365. - transform
  366. - duration
  367. body: |
  368. var startWorldTransform = this.worldTransform || goog.vec.Mat4.create();
  369. var deltaTransform = this.transformFromValue( transform );
  370. // Left multiply by the delta
  371. var stopWorldTransform = goog.vec.Mat4.multMat( deltaTransform, startWorldTransform,
  372. goog.vec.Mat4.createFloat32() );
  373. this.worldTransformTo( stopWorldTransform, duration ) //@ sourceURL=node3.animation.worldTransformBy.vwf
  374. ## Transform the world transform to given transform over duration.
  375. ##
  376. ## @name node3.animation.vwf#worldTransformTo
  377. ## @function
  378. ##
  379. ## @param {Array} transform
  380. ## @param {Number} duration
  381. ##
  382. ## @returns undefined
  383. worldTransformTo:
  384. parameters:
  385. - transform
  386. - duration
  387. body: |
  388. var stopWorldTransform = this.transformFromValue( transform );
  389. var stopTransform;
  390. if ( this.parent && this.parent.worldTransform ) {
  391. // We need to find the local transform that will bring about the desired world transform
  392. // The math for this looks like -
  393. // (new worldTransform) = (parentWorldTransform) * (transform)
  394. // So, if we left multiply both sides by the inverse of the parentWorldTransform...
  395. // inv(parentWorldTransform) * (new worldTransform) = (transform)
  396. // Find the inverse parent worldTransform
  397. var inverseParentWorldTransform = goog.vec.Mat4.createFloat32();
  398. if ( goog.vec.Mat4.invert( this.parent.worldTransform, inverseParentWorldTransform ) ) {
  399. // Left multiply the new worldTransform by the inverse parent worldTransform
  400. stopTransform = goog.vec.Mat4.multMat( inverseParentWorldTransform, stopWorldTransform,
  401. goog.vec.Mat4.createFloat32() );
  402. }
  403. else {
  404. stopTransform = goog.vec.Mat4.createIdentity();
  405. this.logger.error( "Parent '" + this.parent.id + "' transform matrix is not invertible: " +
  406. this.parent.transform );
  407. }
  408. }
  409. else {
  410. stopTransform = stopWorldTransform;
  411. }
  412. this.transformTo( stopTransform, duration ); //@ sourceURL=node3.animation.worldTransformTo.vwf
  413. event:
  414. changingTransformFromView: