task.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. this.enter = function() {
  2. // If this task has a parent task, get the scene node from the parent
  3. // Else, search for it via the scenePath
  4. var parentTaskArray = this.find( "parent::element(*,'http://vwf.example.com/lesson/task.vwf')" );
  5. if ( parentTaskArray.length ) {
  6. var parentTask = parentTaskArray[ 0 ];
  7. this.scene = parentTask.scene;
  8. }
  9. // If a camera pose has been specified for this task, move the camera to it
  10. if ( this.cameraPoseRef ) {
  11. var cameraPoseSearchResults = this.find( this.cameraPoseRef );
  12. if ( cameraPoseSearchResults && cameraPoseSearchResults.length ) {
  13. var newCameraPose = cameraPoseSearchResults[ 0 ];
  14. if ( newCameraPose.translation && newCameraPose.quaternion ) {
  15. if ( this.scene ) {
  16. var camera = this.scene.camera;
  17. if ( camera ) {
  18. var duration = 2;
  19. camera.worldTransformTo( newCameraPose.worldTransform, duration);
  20. this.in(duration).cameraTransformComplete();
  21. } else {
  22. console.error( "Could not find camera - to move the 3D camera using cameraPose, make sure the " +
  23. "scene derives from navScene.vwf or another component that defines a valid camera" );
  24. }
  25. } else {
  26. console.error( "Scene property is not set - must be set for task to find camera to move" );
  27. }
  28. } else {
  29. console.error( "Camera pose '" + this.cameraPoseRef + "' is not a valid node3" );
  30. }
  31. } else {
  32. console.error( "Could not find camera pose: " + this.cameraPoseRef + " - will not move camera" );
  33. }
  34. }
  35. this.status = "entered";
  36. // Fire the entering event which runs lesson-specific code
  37. this.entering( this.text );
  38. // Activate subtasks if they exist
  39. this.taskIndex = null;
  40. if ( this.subtasks && this.subtasks.length ) {
  41. this.next();
  42. }
  43. //@ sourceURL=task.enter
  44. }
  45. this.next = function() {
  46. // If the first subtask has not been run yet (so taskIndex is null), initialize it
  47. // Else, exit the current subtask and increment taskIndex
  48. if ( this.taskIndex == null )
  49. this.taskIndex = 0;
  50. else {
  51. var oldSubtask = this.subtasks[ this.taskIndex ];
  52. oldSubtask.completed = oldSubtask.events.flush( this );
  53. oldSubtask.exit();
  54. this.taskIndex++;
  55. }
  56. // If there are subtasks still to run, enter the next one
  57. // Else, mark this task as complete
  58. if ( this.taskIndex < this.subtasks.length ) {
  59. var newSubtask = this.subtasks[ this.taskIndex ];
  60. newSubtask.enter();
  61. newSubtask.completed = newSubtask.events.add( function() { this.in(0).next(); }, this );
  62. }
  63. else
  64. this.completed();
  65. //@ sourceURL=task.next
  66. }
  67. this.exit = function() {
  68. // TODO: Find the scene node properly to make this possible
  69. // this.scene.events.flush( this );
  70. // Fire the exiting event
  71. this.exiting();
  72. this.status = "inactive";
  73. }
  74. this.completed = function() {
  75. this.status = "completed";
  76. }