NavigationInfo.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author Bart McLeod, [email protected]
  3. * @since September 20, 2016
  4. *
  5. * Conversion of a VRML 97 NavigationInfo node to a ThreeJs camera
  6. */
  7. VrmlParser.Renderer.ThreeJs.VrmlNode[ 'NavigationInfo' ] = function (originalNode, debug) {
  8. this.debug = debug;
  9. this.node = originalNode;
  10. this.node.has = function (property) {
  11. return ('undefined' !== typeof this[ property ] && null !== this[ property ]);
  12. };
  13. this.controls = null;
  14. };
  15. VrmlParser.Renderer.ThreeJs.VrmlNode.NavigationInfo.prototype = {
  16. /**
  17. * Utility to easily switch logging on and off with the debug flag.
  18. * @param obj
  19. */
  20. log: function (obj) {
  21. if ( this.debug ) {
  22. console.log(obj);
  23. }
  24. },
  25. /**
  26. * Uses the NavigationInfo from the original VRML to determine the best
  27. * match for controls in ThreeJs.
  28. *
  29. * @todo: Figure out of support for avatarSize is possible
  30. * @todo: Support for headlight
  31. * @todo: Figure out if visibilityLimit can be implemented, could this be the 'far' property of the camera?
  32. * @todo: Create controls that mimic the original design of VRML better.
  33. * @param scene
  34. */
  35. parse: function (scene) {
  36. this.log('From NavigationInfo');
  37. var speed = undefined !== this.node.speed ? this.node.speed : 1;
  38. if ( undefined !== this.node.type ) {
  39. switch ( this.node.type.toLowerCase() ) {
  40. case 'fly': // fly
  41. this.log('fly!');
  42. // use global controls and camera, no better solution at hand
  43. controls = new THREE.FlyControls(camera);
  44. controls.movementSpeed = speed;
  45. break;
  46. }
  47. } else {
  48. this.log('fly!');
  49. // use global controls and camera, no better solution at hand
  50. controls = new THREE.FlyControls(camera);
  51. controls.movementSpeed = speed;
  52. }
  53. /** Example of originalNode
  54. * avatarSize [ 0.1, 1.6, 0.2,]
  55. * headlight FALSE
  56. * speed 4
  57. * type "FLY"
  58. * visibilityLimit 0.0
  59. */
  60. }
  61. }