You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.ts 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * encantar.js
  3. * GPU-accelerated Augmented Reality for the web
  4. * Copyright (C) 2022-2024 Alexandre Martins <alemartf(at)gmail.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * main.ts
  20. * Entry point
  21. */
  22. import Speedy from 'speedy-vision';
  23. import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
  24. import { Settings } from './core/settings';
  25. import { Session, SessionOptions } from './core/session';
  26. import { TrackerFactory } from './trackers/tracker-factory';
  27. import { SourceFactory } from './sources/source-factory';
  28. import { Viewport, ViewportSettings } from './core/viewport';
  29. import { Vector2 } from './geometry/vector2';
  30. import { Vector3 } from './geometry/vector3';
  31. import { Utils } from './utils/utils';
  32. declare const __AR_VERSION__: string;
  33. declare const __AR_WEBSITE__: string;
  34. /**
  35. * GPU-accelerated Augmented Reality for the web
  36. */
  37. export default class AR
  38. {
  39. /**
  40. * Start a new session
  41. * @param options
  42. * @returns a promise that resolves to a new session
  43. */
  44. static startSession(options?: SessionOptions): SpeedyPromise<Session>
  45. {
  46. return Session.instantiate(options);
  47. }
  48. /**
  49. * Checks if the engine can be run in the browser the client is using
  50. * @returns true if the engine is compatible with the browser
  51. */
  52. static isSupported(): boolean
  53. {
  54. return Session.isSupported();
  55. }
  56. /**
  57. * Engine version
  58. */
  59. static get version(): string
  60. {
  61. return __AR_VERSION__;
  62. }
  63. /**
  64. * Speedy Vision
  65. */
  66. static get Speedy(): typeof Speedy
  67. {
  68. return Speedy;
  69. }
  70. /**
  71. * Trackers
  72. */
  73. static get Tracker(): typeof TrackerFactory
  74. {
  75. return TrackerFactory;
  76. }
  77. /**
  78. * Sources of data
  79. */
  80. static get Source(): typeof SourceFactory
  81. {
  82. return SourceFactory;
  83. }
  84. /**
  85. * Create a viewport
  86. * @param settings
  87. * @returns a new viewport with the specified settings
  88. */
  89. static Viewport(settings: ViewportSettings): Viewport
  90. {
  91. return new Viewport(settings);
  92. }
  93. /**
  94. * Create a new 2D vector
  95. * @param x x-coordinate
  96. * @param y y-coordinate
  97. * @returns a new 2D vector with the provided coordinates
  98. */
  99. static Vector2(x: number, y: number): Vector2
  100. {
  101. return new Vector2(x, y);
  102. }
  103. /**
  104. * Create a new 3D vector
  105. * @param x x-coordinate
  106. * @param y y-coordinate
  107. * @param z z-coordinate
  108. * @returns a new 3D vector with the provided coordinates
  109. */
  110. static Vector3(x: number, y: number, z: number): Vector3
  111. {
  112. return new Vector3(x, y, z);
  113. }
  114. /**
  115. * Global Settings
  116. */
  117. static get Settings(): typeof Settings
  118. {
  119. return Settings;
  120. }
  121. }
  122. // Freeze the namespace
  123. Object.freeze(AR);
  124. // Add Speedy Vision to global scope
  125. ((window: any) => window.Speedy = window.Speedy || Speedy)(window);
  126. // Display a notice
  127. Utils.log(
  128. `encantar.js version ${AR.version}. ` +
  129. `GPU-accelerated Augmented Reality for the web by Alexandre Martins. ` +
  130. __AR_WEBSITE__
  131. );