選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_DEVELOPMENT_MODE__: string;
  34. declare const __AR_WEBSITE__: string;
  35. /**
  36. * GPU-accelerated Augmented Reality for the web
  37. */
  38. export default class AR
  39. {
  40. /**
  41. * Start a new session
  42. * @param options
  43. * @returns a promise that resolves to a new session
  44. */
  45. static startSession(options?: SessionOptions): SpeedyPromise<Session>
  46. {
  47. return Session.instantiate(options);
  48. }
  49. /**
  50. * Checks if the engine can be run in the browser the client is using
  51. * @returns true if the engine is compatible with the browser
  52. */
  53. static isSupported(): boolean
  54. {
  55. return Session.isSupported();
  56. }
  57. /**
  58. * Engine version
  59. */
  60. static get version(): string
  61. {
  62. if(__AR_DEVELOPMENT_MODE__)
  63. return __AR_VERSION__ + '-dev';
  64. else
  65. return __AR_VERSION__;
  66. }
  67. /**
  68. * Speedy Vision
  69. */
  70. static get Speedy(): typeof Speedy
  71. {
  72. return Speedy;
  73. }
  74. /**
  75. * Trackers
  76. */
  77. static get Tracker(): typeof TrackerFactory
  78. {
  79. return TrackerFactory;
  80. }
  81. /**
  82. * Sources of data
  83. */
  84. static get Source(): typeof SourceFactory
  85. {
  86. return SourceFactory;
  87. }
  88. /**
  89. * Create a viewport
  90. * @param settings
  91. * @returns a new viewport with the specified settings
  92. */
  93. static Viewport(settings: ViewportSettings): Viewport
  94. {
  95. return new Viewport(settings);
  96. }
  97. /**
  98. * Create a new 2D vector
  99. * @param x x-coordinate
  100. * @param y y-coordinate
  101. * @returns a new 2D vector with the provided coordinates
  102. */
  103. static Vector2(x: number, y: number): Vector2
  104. {
  105. return new Vector2(x, y);
  106. }
  107. /**
  108. * Create a new 3D vector
  109. * @param x x-coordinate
  110. * @param y y-coordinate
  111. * @param z z-coordinate
  112. * @returns a new 3D vector with the provided coordinates
  113. */
  114. static Vector3(x: number, y: number, z: number): Vector3
  115. {
  116. return new Vector3(x, y, z);
  117. }
  118. /**
  119. * Global Settings
  120. */
  121. static get Settings(): typeof Settings
  122. {
  123. return Settings;
  124. }
  125. }
  126. // Freeze the namespace
  127. Object.freeze(AR);
  128. // Add Speedy Vision to global scope
  129. ((window: any) => window.Speedy = window.Speedy || Speedy)(window);
  130. // Display a notice
  131. Utils.log(
  132. `encantar.js version ${AR.version}. ` +
  133. `GPU-accelerated Augmented Reality for the web by Alexandre Martins. ` +
  134. __AR_WEBSITE__
  135. );