├── .gitignore ├── .npmignore ├── .travis.yml ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── CLA.md ├── CONTRIBUTING.md ├── CopyrightNotice.md ├── LICENSE.txt ├── README.md ├── dist ├── argon.core.js ├── argon.js └── argon.min.js ├── docs ├── assets │ ├── css │ │ ├── main.css │ │ └── main.css.map │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ └── js │ │ ├── main.js │ │ └── search.js ├── classes │ ├── androidwebviewconnectservice.html │ ├── argonconfigurationmanager.html │ ├── argonsystem.html │ ├── argonsystemprovider.html │ ├── canvasviewport.html │ ├── commandqueue.html │ ├── configuration.html │ ├── connectservice.html │ ├── contextservice.html │ ├── contextserviceprovider.html │ ├── debugconnectservice.html │ ├── defaultuiservice.html │ ├── deprecatedvuforiadataset.html │ ├── deviceframestate.html │ ├── deviceservice.html │ ├── deviceserviceprovider.html │ ├── devicestablestate.html │ ├── domconnectservice.html │ ├── emptyrealityviewer.html │ ├── entitypose.html │ ├── entityservice.html │ ├── entityserviceprovider.html │ ├── event.html │ ├── focusservice.html │ ├── focusserviceprovider.html │ ├── hostedrealityviewer.html │ ├── liverealityviewer.html │ ├── loopbackconnectservice.html │ ├── messagechannelfactory.html │ ├── messagechannellike.html │ ├── messageeventlike.html │ ├── permission.html │ ├── permissionservice.html │ ├── permissionserviceprovider.html │ ├── realityservice.html │ ├── realityserviceprovider.html │ ├── realityviewer.html │ ├── realityviewerfactory.html │ ├── serializedsubviewlist.html │ ├── sessionconnectservice.html │ ├── sessionport.html │ ├── sessionportfactory.html │ ├── sessionservice.html │ ├── subview.html │ ├── synchronousmessagechannel.html │ ├── viewelement.html │ ├── viewport.html │ ├── viewservice.html │ ├── viewserviceprovider.html │ ├── visibilityservice.html │ ├── visibilityserviceprovider.html │ ├── vuforiaapi.html │ ├── vuforiaobjecttracker.html │ ├── vuforiaservice.html │ ├── vuforiaserviceprovider.html │ ├── vuforiatracker.html │ └── wkwebviewconnectservice.html ├── enums │ ├── permissionstate.html │ ├── posestatus.html │ ├── role.html │ ├── subviewtype.html │ └── viewportmode.html ├── globals.html ├── index.html ├── interfaces │ ├── contextframestate.html │ ├── deprecatedeyeparameters.html │ ├── deprecatedpartialframestate.html │ ├── errormessage.html │ ├── geolocationoptions.html │ ├── message.html │ ├── messagehandlermap.html │ ├── messageportlike.html │ ├── readonlyserializedsubview.html │ ├── serializeddevicestate.html │ ├── serializedentitystatemap.html │ ├── vuforiadatasetevent.html │ ├── vuforiadatasetloadevent.html │ └── vuforiatrackables.html └── modules │ ├── serializedentitystate.html │ └── serializedsubview.html ├── index.d.ts ├── index.html ├── jspm.browser.js ├── jspm.config.js ├── package.json ├── src ├── README.md ├── argon.d.ts ├── argon.ts ├── cesium │ ├── MapzenTerrariumTerrainProvider.d.ts │ ├── MapzenTerrariumTerrainProvider.ts │ ├── cesium-extensions.d.ts │ ├── cesium-extensions.ts │ ├── cesium-imports.d.ts │ └── cesium-imports.ts ├── common.d.ts ├── common.ts ├── context.d.ts ├── context.ts ├── device.d.ts ├── device.ts ├── entity.d.ts ├── entity.ts ├── focus.d.ts ├── focus.ts ├── permission.d.ts ├── permission.ts ├── reality-viewers │ ├── base.d.ts │ ├── base.ts │ ├── empty.d.ts │ ├── empty.ts │ ├── hosted.d.ts │ ├── hosted.ts │ ├── live.d.ts │ └── live.ts ├── reality.d.ts ├── reality.ts ├── session.d.ts ├── session.ts ├── ui.d.ts ├── ui.ts ├── utils.d.ts ├── utils.ts ├── utils │ ├── command-queue.d.ts │ ├── command-queue.ts │ ├── event.d.ts │ ├── event.ts │ ├── message-channel.d.ts │ ├── message-channel.ts │ ├── ui-event-forwarder.d.ts │ ├── ui-event-forwarder.ts │ ├── ui-event-synthesizer.d.ts │ └── ui-event-synthesizer.ts ├── view.d.ts ├── view.ts ├── visibility.d.ts ├── visibility.ts ├── vuforia.d.ts ├── vuforia.ts ├── webvr.d.ts └── webvr.ts ├── test ├── app │ ├── custom_reality.d.ts │ ├── custom_reality.html │ ├── custom_reality.js │ ├── custom_reality.ts │ ├── dataset │ │ ├── StonesAndChips.dat │ │ └── StonesAndChips.xml │ ├── example.d.ts │ ├── example.js │ ├── example.ts │ ├── index.html │ └── three.min.js ├── index.html ├── runner.js ├── test.d.ts ├── test.js └── test.ts ├── tsconfig.build.json ├── tsconfig.json ├── tsfmt.json └── types ├── cesium ├── index.d.ts └── package.json ├── declarations.d.ts └── mobile-detect ├── index.d.ts └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | jspm_packages 3 | .vscode/tasks.json 4 | .tmp 5 | src/**/*.js 6 | src/**/*.js.map 7 | npm-debug.log 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /* 2 | !src 3 | *.ts 4 | !dist 5 | !types 6 | !*.d.ts 7 | !*.js 8 | !CopyrightNotice 9 | jspm.* 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "6" 5 | - "node" 6 | 7 | cache: 8 | directories: 9 | - node_modules 10 | 11 | before_install: 12 | - npm install 13 | - jspm install -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Tests", 11 | "program": "${workspaceRoot}/node_modules/jspm/jspm.js", 12 | "cwd": "${workspaceRoot}", 13 | "outFiles": [], 14 | "protocol": "legacy", 15 | "sourceMaps": true, 16 | "args": [ 17 | "run", 18 | "test/runner.js" 19 | ] 20 | }, 21 | { 22 | "type": "node", 23 | "request": "attach", 24 | "name": "Attach to Process", 25 | "port": 5858, 26 | "outFiles": [], 27 | "sourceMaps": true 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "typescript.tsdk": "node_modules/typescript/lib", 4 | "files.exclude": { 5 | "**/.git": true, 6 | "**/.svn": true, 7 | "**/.hg": true, 8 | "**/.DS_Store": true, 9 | "src/**/*.js": true, 10 | "src/**/*.map": true, 11 | "src/**/*.d.ts": true, 12 | "example/**/*.js*": true, 13 | "example/**/*.d.ts": true 14 | } 15 | } -------------------------------------------------------------------------------- /CLA.md: -------------------------------------------------------------------------------- 1 | ## Georgia Tech Research Corporation 2 | ### Individual Contributor License Agreement ("Agreement") 3 | 4 | #### (*CLA can be signed electronically [using this form](https://docs.google.com/forms/d/1wl5Rg7ishq6nsfbMVoif6322NOzhjdyryHvxmiCQITc/viewform?c=0&w=1&usp=mail_form_link)*) 5 | 6 | Thank you for your interest in Georgia Tech Research Corporation (“GTRC”) software. In order to clarify the intellectual property license granted with Contributions from any person or entity, GTRC must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. 7 | 8 | This license is for your protection as a Contributor as well as the protection of GTRC and its users; it does not change your rights to use your own Contributions for any other purpose. 9 | 10 | If you have not already done so, please complete and sign this CLA. **You may sign this CLA electronically [using this form](https://docs.google.com/forms/d/1wl5Rg7ishq6nsfbMVoif6322NOzhjdyryHvxmiCQITc/viewform?c=0&w=1&usp=mail_form_link)**, or you may print, then scan and email a pdf file of this Agreement to industry@gatech.edu. If necessary, send an original signed Agreement to Georgia Tech Research Corporation, Attn: Director of Licensing, 505 10th Street NW, Atlanta, Georgia 30332-0415, U.S.A. 11 | 12 | Please read this document carefully before signing and keep a copy for your records. 13 | 14 | Full name: ______________________________________________________ 15 | 16 | Mailing Address: ________________________________________________ 17 | 18 | Mailing Address (cont'd): _______________________________________ 19 | 20 | Country: ______________________________________________________ 21 | 22 | Telephone: ______________________________________________________ 23 | 24 | E-Mail: ______________________________________________________ 25 | 26 | Github id: ______________________________________________________ 27 | 28 | 29 | 30 | 31 | You accept and agree to the following terms and conditions for Your present and future Contributions submitted to GTRC. In return, GTRC shall not use Your Contributions in a way that is contrary to the public benefit or inconsistent with its nonprofit status and bylaws in effect at the time of the Contribution. Except for the license granted herein to GTRC and recipients of software distributed by GTRC, You reserve all right, title, and interest in and to Your Contributions. 32 | 33 | 1. Definitions. 34 | "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with GTRC. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 35 | "Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to GTRC for inclusion in, or documentation of, any of the products owned or managed by GTRC (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to GTRC or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, GTRC for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution." 36 | 37 | 2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to GTRC and to recipients of software distributed by GTRC a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works. 38 | 39 | 3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to GTRC and to recipients of software distributed by GTRC a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed. 40 | 41 | 4. You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to GTRC, or that your employer has executed a separate license agreement with GTRC. 42 | 43 | 5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions. 44 | 45 | 6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. 46 | 47 | 7. Should You wish to submit work that is not Your original creation, You may submit it to GTRC separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as 48 | "Submitted on behalf of a third-party: [named here]". 49 | 50 | 8. You agree to notify GTRC of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect. 51 | 52 | Please sign: __________________________________ Date: ________________ 53 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Argon 2 | 3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: 4 | 5 | #### Table of Contents 6 | 7 | [How can I help?](#how-can-i-help) 8 | * [Submitting an Issue](#submitting-an-issue) 9 | * [Opening a Pull Request](#opening-a-pull-request) 10 | 11 | [:sparkles:Style:sparkles:](#style-guidelines) 12 | * [Branching Scheme](#our-branching-model) 13 | * [Typescript](#typescript-style) 14 | 15 | [Tests](#testing) 16 | 17 | ## How can I help? 18 | 19 | You can help in so many ways! 20 | Whether it's asking questions on our slack or on StackOverflow or even contributing code, we love any help we can get! 21 | 22 | ### Submitting an Issue 23 | 24 | If you think you've found a bug, first search the issues. If an issue already exists, please add a comment expressing your interest and any additional information. This helps us prioritize issues. 25 | 26 | If a related issue does not exist, submit a new one. Please be concise and include as much of the following information as is relevant: 27 | * Minimum amount of sample code or steps to demonstrate or reproduce the issue 28 | * Screenshot or video capture if appropriate. 29 | * Your device operating system and version, the Argon Browser version, and the argon.js version. Are they all up-to-date? Is the issue specific to one of them? 30 | * Did this work in a previous version? 31 | * Ideas for how to fix or workaround the issue. Also mention if you are willing to help fix it. If so, we can often provide guidance and the issue may get fixed more quickly with your help. 32 | 33 | ### Opening a Pull Request 34 | 35 | In general, you should make your pull request against the `develop` branch. 36 | You can use the following prefixes in your branch name to make the purpose clear: 37 | * `fix/` 38 | * `feat/` 39 | 40 | Pull request tips 41 | * If your pull request fixes an existing issue, include a link to the issue in the description (like this: [#1]). 42 | * If your pull request needs additional work, include a [task list](https://github.com/blog/1375%0A-task-lists-in-gfm-issues-pulls-comments). 43 | * Once you are done making new commits to address feedback, add a comment to the pull request such as `"this is ready"` since GitHub doesn't notify us about commits. 44 | 45 | 46 | ## Style Guidelines 47 | 48 | The general style guidelines are as follows: 49 | 50 | * We use 4 spaces to indent **all** source files 51 | * No trailing spaces 52 | 53 | The typescript style is described in our `.tslint.json` file. 54 | Our tests will automatically check for style and print out helpful messages. 55 | 56 | 57 | ### Our Branching Model 58 | 59 | We follow a pretty simple branching model. 60 | 61 | Our primary working branh is the `develop` branch. Once in a while, the `develop` branch is 62 | tagged with a new release version and merged into the master branch. 63 | 64 | ## Testing 65 | 66 | In general, all our tests should run by executing `npm test`. 67 | -------------------------------------------------------------------------------- /CopyrightNotice.md: -------------------------------------------------------------------------------- 1 | ## Copyright 2016 Georgia Tech Research Corporation 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | 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 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # argon.js 2 | 3 | An open-standards augmented reality platform for the web. Initially created to supporting creating AR web applications for [the Argon4 browser](https://app.argonjs.io), argon.js is now aimed at supporting AR in any web browser, using whatever capabilities are available on each platform. 4 | 5 | *This software was created as part of a research project at the 6 | Augmented Environments Lab at Georgia Tech. To support our research, 7 | we request that if you make use of this software, you let us know 8 | how you used it by sending mail to Blair MacIntyre (blair@cc.gatech.edu).* 9 | 10 | If you would like to help improve Argon4 and argon.js, you can see our current and future [Roadmap](https://trello.com/b/gBsEa8eg/argon-public-roadmap). 11 | 12 | ## Support 13 | 14 | * [Documentation](https://docs.argonjs.io/) 15 | * [API Reference](https://api.argonjs.io/) 16 | 17 | ## Quick Start 18 | 19 | To install the argon.js library manually, include one of the following scripts in your project: 20 | 21 | * argon.min.js [\[latest\]](https://unpkg.com/@argonjs/argon@^1/dist/argon.min.js) [\[dev\]](https://rawgit.com/argonjs/argon/develop/dist/argon.min.js) - includes WebVR polyfill 22 | * argon.js [\[latest\]](https://unpkg.com/@argonjs/argon@^1/dist/argon.js) [\[dev\]](https://rawgit.com/argonjs/argon/develop/dist/argon.js) - includes WebVR polyfill 23 | * argon.core.js [\[latest\]](https://unpkg.com/@argonjs/argon@^1/dist/argon.core.js) [\[dev\]](https://rawgit.com/argonjs/argon/develop/dist/argon.core.js) 24 | 25 | > Note: These are UMD builds, meaning they should be compatible with standard module formats (commonjs, AMD, global). The [dev] link may point to an unstable build, and should only be used if you want the latest in-progress version from the develop branch. 26 | 27 | To install with npm: 28 | 29 | ```sh 30 | npm install @argonjs/argon@^1.0 31 | ``` 32 | 33 | To install with jspm: 34 | 35 | ```sh 36 | jspm install npm:@argonjs/argon@^1.0 37 | ``` 38 | 39 | ### Usage 40 | 41 | In your es6 modules, `import` the package `"@argonjs/argon"`: 42 | 43 | ```js 44 | import * as Argon from '@argonjs/argon' 45 | ``` 46 | 47 | If you aren't using es6 modules, `require` the package `"@argonjs/argon"`: 48 | 49 | ```js 50 | var Argon = require('@argonjs/argon'); 51 | ``` 52 | 53 | If you aren't using modules at all, no worries! The *argon.js* library will 54 | create a global `Argon` variable that exposes the same API. 55 | 56 | ## Typescript 57 | 58 | If you are using Typescript 2.0 and would like to leverage 59 | *argon.js* typings (you should!), simply install *argon.js* using `npm` 60 | as described above (even if you are not using modules in your 61 | project). However, if you aren't using modules, just be sure 62 | to include a triple-slash reference so that the typescript 63 | compiler knows you are using *argon.js* globally: 64 | 65 | ```ts 66 | /// 67 | ``` 68 | 69 | Finally, make sure your `tsconfig.json` contains the following 70 | compiler options: 71 | 72 | ```json 73 | { 74 | "compilerOptions": { 75 | "moduleResolution": "node", 76 | "lib": [ 77 | "dom", 78 | "es2015" 79 | ] 80 | } 81 | } 82 | ``` 83 | 84 | After that, you can enjoy rich editing support for 85 | *argon.js* in any editor that supports Typescript! We recommend 86 | [Visual Studio Code](https://code.visualstudio.com). 87 | 88 | ## Build Guide 89 | 90 | * Clone argon 91 | 92 | ```sh 93 | git clone https://github.com/argonjs/argon.git 94 | ``` 95 | 96 | * Make sure you have node.js/npm installed (There are many guides for this online) 97 | * Install jspm globally: 98 | 99 | ```sh 100 | npm install jspm -g 101 | ``` 102 | 103 | * Go to the directory where you have argon.js downloaded and install dependencies 104 | 105 | ```sh 106 | npm install 107 | jspm install 108 | ``` 109 | 110 | * To run the typescript compiler and create a build, execute: 111 | 112 | ```sh 113 | npm run build 114 | ``` 115 | 116 | * To test Argon, execute: 117 | 118 | ```sh 119 | npm run test 120 | ``` 121 | -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /docs/classes/viewelement.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ViewElement | argon.js 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 |
42 |
43 | Menu 44 |
45 |
46 |
47 |
48 |
49 |
50 | 58 |

Class ViewElement

59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |

Hierarchy

67 |
    68 |
  • 69 | ViewElement 70 |
  • 71 |
72 |
73 |
74 | 94 |
95 |
96 | 155 |
156 |

Generated using TypeDoc

157 |
158 |
159 | 160 | 161 | 170 | 171 | -------------------------------------------------------------------------------- /docs/interfaces/message.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Message | argon.js 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 |
42 |
43 | Menu 44 |
45 |
46 |
47 |
48 |
49 |
50 | 58 |

Interface Message

59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |

Hierarchy

67 |
    68 |
  • 69 | Message 70 |
  • 71 |
72 |
73 |
74 |

Indexable

75 |
[key: string]: any
76 |
77 |
78 | 98 |
99 |
100 | 159 |
160 |

Generated using TypeDoc

161 |
162 |
163 | 164 | 165 | 174 | 175 | -------------------------------------------------------------------------------- /docs/interfaces/messagehandlermap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | MessageHandlerMap | argon.js 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 |
42 |
43 | Menu 44 |
45 |
46 |
47 |
48 |
49 |
50 | 58 |

Interface MessageHandlerMap

59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |

Describes a map from message topic to MessageHandler.

69 |
70 |
71 |
72 |
73 |

Hierarchy

74 |
    75 |
  • 76 | MessageHandlerMap 77 |
  • 78 |
79 |
80 |
81 |

Indexable

82 |
[topic: string]: MessageHandler
83 |
84 |
85 |

Describes a map from message topic to MessageHandler.

86 |
87 |
88 |
89 |
90 | 110 |
111 |
112 | 171 |
172 |

Generated using TypeDoc

173 |
174 |
175 | 176 | 177 | 186 | 187 | -------------------------------------------------------------------------------- /docs/interfaces/serializedentitystatemap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SerializedEntityStateMap | argon.js 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 |
42 |
43 | Menu 44 |
45 |
46 |
47 |
48 |
49 |
50 | 58 |

Interface SerializedEntityStateMap

59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |

A map of entity ids and their associated poses.

69 |
70 |
71 |
72 |
73 |

Hierarchy

74 |
    75 |
  • 76 | SerializedEntityStateMap 77 |
  • 78 |
79 |
80 |
81 |

Indexable

82 |
[id: string]: SerializedEntityState | null
83 |
84 |
85 |

A map of entity ids and their associated poses.

86 |
87 |
88 |
89 |
90 | 110 |
111 |
112 | 171 |
172 |

Generated using TypeDoc

173 |
174 |
175 | 176 | 177 | 186 | 187 | -------------------------------------------------------------------------------- /docs/interfaces/vuforiatrackables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | VuforiaTrackables | argon.js 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 |
42 |
43 | Menu 44 |
45 |
46 |
47 |
48 |
49 |
50 | 58 |

Interface VuforiaTrackables

59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |

A map from names of trackable data sets to their ids, names, and sizes TODO

69 |
70 |
71 |
72 |
73 |

Hierarchy

74 |
    75 |
  • 76 | VuforiaTrackables 77 |
  • 78 |
79 |
80 |
81 |

Indexable

82 |
[name: string]: object
83 |
84 |
85 |

A map from names of trackable data sets to their ids, names, and sizes TODO

86 |
87 |
88 |
    89 |
90 |
91 |
92 | 112 |
113 |
114 | 173 |
174 |

Generated using TypeDoc

175 |
176 |
177 | 178 | 179 | 188 | 189 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export * from './src/argon' 3 | export as namespace Argon; -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 |

Test Runner

11 |

Test App

12 |

Documentation

13 | 14 | -------------------------------------------------------------------------------- /jspm.browser.js: -------------------------------------------------------------------------------- 1 | SystemJS.config({ 2 | paths: { 3 | "github:": "jspm_packages/github/", 4 | "npm:": "jspm_packages/npm/" 5 | } 6 | }); 7 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # argon.js 2 | 3 | An open-standards augmented reality platform for the web 4 | 5 | *This software was created as part of a research project at the 6 | Augmented Environments Lab at Georgia Tech. To support our research, 7 | we request that if you make use of this software, you let us know 8 | how you used it by sending mail to Blair MacIntyre (blair@cc.gatech.edu).* 9 | 10 | ## API 11 | 12 | There are essentially 3 types of systems that are defined by the *argon.js* framework: 13 | 14 | * **[[REALITY_AUGMENTOR]]** - a system that is responsible for *augmenting* a view of reality. 15 | * **[[REALITY_VIEW]]** - a system that is responsible for *presenting* a view of reality 16 | * **[[REALITY_MANAGER]]** - a system that is responsible for *blending* a particular **Reality View** with 17 | one or more **Reality Augmentors** 18 | 19 | Traditionally, Augmented Reality (AR) apps have had to take on all three of these roles 20 | at once. However, by separating these concerns out, each role can be easily swapped out 21 | with another implmentation, allowing for a much more flexible and adaptive AR application 22 | ecosystem. 23 | 24 | The *argon.js* framework also anticipates a future in which AR-enabled browsers 25 | (functioning as a **Reality Manager**) may give users control over the way they interact 26 | with AR content, and let the user (not the applications) control how they are displayed 27 | by allowing the user to change their view of reality. For example, a user may want to 28 | switch from live video, to remote video, to a virtual flyover of their—all while an AR 29 | application is running. Similarly, in these future browsers, users may want to run 30 | multiple AR applications simultaneously, and different application requirements may 31 | cause the browser to use different views of reality for the different applications. 32 | We are exploring these ideas within the [Argon](http://argonjs.io/argon-app/) browser 33 | (which already allows multiple apps to run and be visible at the same time, for example), 34 | and these use-cases have informed the design of *argon.js*. 35 | 36 | ### The structure of an AR-enabled app 37 | 38 | In general, we simply call [[init]] to initailize our app: 39 | 40 | ```js 41 | var app = Argon.init(); 42 | ``` 43 | 44 | > ***Note:*** By default, this will initialize your app with a role appropriate for 45 | the environment in which it is executing. If your app is running within a 46 | **Reality Manager** such as the [Argon Browser](http://argonjs.io/argon-app/), 47 | then it will be initialized with the role of a **Reality Augmentor**. If your app 48 | is running in a standalone manner, then it will be elevated to the role of a 49 | **Reality Manager**. In general, this detail does not affect the way you write your app, 50 | as *argon.js* includes default implementations of the responsbilities of a 51 | **Reality Manager**. However, if your app detects that it is running as a 52 | **Reality Manager**, it may assume more control over the entire experience. 53 | 54 | The object returned by [[init]] is an instance of [[ArgonSystem]]. By convention, we 55 | store this instance in a variable called `app`. Various services are made available 56 | via this instance. For example, your app will need to continually respond to changes 57 | in the world in order to update it's augmentations. [[ArgonSystem.updateEvent]] 58 | let's you setup a callback for that purpose: 59 | 60 | ```ts 61 | app.updateEvent.addEventListener(function (){ 62 | // update our augmentations 63 | }) 64 | ``` 65 | 66 | In *argon.js*, all objects are represented in geospatial coordinates, using [cesium.js 67 | Entities](https://cesiumjs.org/Cesium/Build/Documentation/Entity.html) (a subset 68 | of Cesium's API is availabe in the `Argon.Cesium` namespace). [[ArgonSystem.context]] 69 | exposes a [[ContextService]] instance whose purpose is to keep track of entities that 70 | you can augment, or subscribe to new entities so that your app can be made aware of 71 | them. Via the [[ContextService.getEntityPose]] method, you can convert an Entity from 72 | geospatial coordinates into your local scenegraph coordinates. 73 | 74 | In your `update` event handler, you can, for example, query the current 75 | pose of an Entity by calling [[ContextService.getEntityPose]] and 76 | passing the desired entity instance. 77 | 78 | Finally, we can listen to the render event in order to render 79 | our augmentations in a timely manner: 80 | 81 | ```ts 82 | app.renderEvent.addEventListener(function (){ 83 | // render our augmentations 84 | }) 85 | ``` 86 | 87 | *argon.js* is itself entirely decoupled from any particular rendering library, 88 | but does aim to provide a level of abstraction that makes it easy to integrate 89 | with the library of your choice. 90 | 91 | Check out the [tutorials](http://docs.argonjs.io/tutorials/) for more 92 | concrete examples of *argon.js* AR-enabled apps. 93 | 94 | ### The structure of a Reality View 95 | 96 | TODO 97 | 98 | ### The structure of a Reality Manager 99 | 100 | TODO -------------------------------------------------------------------------------- /src/argon.d.ts: -------------------------------------------------------------------------------- 1 | import 'aurelia-polyfills'; 2 | import * as DI from 'aurelia-dependency-injection'; 3 | import * as Cesium from './cesium/cesium-imports'; 4 | import './webvr'; 5 | import { SessionService } from './session'; 6 | import { Configuration } from './common'; 7 | import { Event } from './utils'; 8 | import { EntityService, EntityServiceProvider } from './entity'; 9 | import { ContextService, ContextServiceProvider } from './context'; 10 | import { FocusService, FocusServiceProvider } from './focus'; 11 | import { DeviceService, DeviceServiceProvider } from './device'; 12 | import { RealityService, RealityServiceProvider } from './reality'; 13 | import { ViewService, ViewServiceProvider } from './view'; 14 | import { VisibilityService, VisibilityServiceProvider } from './visibility'; 15 | import { VuforiaService, VuforiaServiceProvider } from './vuforia'; 16 | import { PermissionService, PermissionServiceProvider } from './permission'; 17 | import { RealityViewer } from './reality-viewers/base'; 18 | import { EmptyRealityViewer } from './reality-viewers/empty'; 19 | import { LiveRealityViewer } from './reality-viewers/live'; 20 | import { HostedRealityViewer } from './reality-viewers/hosted'; 21 | export { DI, Cesium }; 22 | export * from './common'; 23 | export * from './context'; 24 | export * from './entity'; 25 | export * from './focus'; 26 | export * from './device'; 27 | export * from './reality'; 28 | export * from './session'; 29 | export * from './ui'; 30 | export * from './utils'; 31 | export * from './view'; 32 | export * from './visibility'; 33 | export * from './vuforia'; 34 | export * from './permission'; 35 | export { RealityViewer, EmptyRealityViewer, LiveRealityViewer, HostedRealityViewer }; 36 | export declare class ArgonSystemProvider { 37 | entity: EntityServiceProvider; 38 | context: ContextServiceProvider; 39 | focus: FocusServiceProvider; 40 | device: DeviceServiceProvider; 41 | visibility: VisibilityServiceProvider; 42 | reality: RealityServiceProvider; 43 | view: ViewServiceProvider; 44 | vuforia: VuforiaServiceProvider; 45 | permission: PermissionServiceProvider; 46 | constructor(entity: EntityServiceProvider, context: ContextServiceProvider, focus: FocusServiceProvider, device: DeviceServiceProvider, visibility: VisibilityServiceProvider, reality: RealityServiceProvider, view: ViewServiceProvider, vuforia: VuforiaServiceProvider, permission: PermissionServiceProvider); 47 | } 48 | /** 49 | * A composition root which instantiates the object graph based on a provided configuration. 50 | * You generally want to create a new ArgonSystem via the provided [[init]] or [[initReality]] functions: 51 | * ```ts 52 | * var app = Argon.init(); // app is an instance of ArgonSystem 53 | * ``` 54 | */ 55 | export declare class ArgonSystem { 56 | container: DI.Container; 57 | entity: EntityService; 58 | context: ContextService; 59 | device: DeviceService; 60 | focus: FocusService; 61 | reality: RealityService; 62 | session: SessionService; 63 | view: ViewService; 64 | visibility: VisibilityService; 65 | vuforia: VuforiaService; 66 | permission: PermissionService; 67 | /** 68 | * The ArgonSystem instance which shares a view provided by a manager 69 | */ 70 | static instance?: ArgonSystem; 71 | constructor(container: DI.Container, entity: EntityService, context: ContextService, device: DeviceService, focus: FocusService, reality: RealityService, session: SessionService, view: ViewService, visibility: VisibilityService, vuforia: VuforiaService, permission: PermissionService); 72 | private _setupDOM(); 73 | readonly suggestedPixelRatio: number; 74 | _provider: ArgonSystemProvider; 75 | readonly provider: ArgonSystemProvider; 76 | readonly updateEvent: Event; 77 | readonly renderEvent: Event; 78 | readonly focusEvent: Event; 79 | readonly blurEvent: Event; 80 | destroy(): void; 81 | } 82 | export declare class ArgonConfigurationManager { 83 | configuration: Configuration; 84 | container: DI.Container; 85 | elementOrSelector: HTMLElement | string | null; 86 | static configure(configurationManager: ArgonConfigurationManager): void; 87 | constructor(configuration: Configuration, container?: DI.Container, elementOrSelector?: HTMLElement | string | null); 88 | standardConfiguration(): void; 89 | defaultConnect(): void; 90 | defaultUI(): void; 91 | } 92 | /** 93 | * Create an ArgonSystem instance. 94 | * If we are running within a [[REALITY_MANAGER]], 95 | * this function will create an ArgonSystem which has the [[REALITY_AUGMENTOR]] role. 96 | * If we are not running within a [[REALITY_MANAGER]], 97 | * this function will create an ArgonSystem which has the [[REALITY_MANAGER]] role. 98 | */ 99 | export declare function init(configuration?: Configuration, dependencyInjectionContainer?: DI.Container): ArgonSystem; 100 | export declare function init(element?: string | HTMLDivElement | null, configuration?: Configuration, dependencyInjectionContainer?: DI.Container): ArgonSystem; 101 | /** 102 | * Initialize an [[ArgonSystem]] with the [[REALITY_VIEWER]] role 103 | */ 104 | export declare function initRealityViewer(configuration?: Configuration, dependencyInjectionContainer?: DI.Container): ArgonSystem; 105 | /** 106 | * @private 107 | */ 108 | export declare const initReality: typeof initRealityViewer; 109 | -------------------------------------------------------------------------------- /src/cesium/MapzenTerrariumTerrainProvider.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A {@link TerrainProvider} that produces terrain geometry by tessellating height maps 3 | * retrieved from Mapzen (which are publicly hosted on S3). 4 | * 5 | * @alias MapzenTerrariumTerrainProvider 6 | * @constructor 7 | * 8 | * @param {Object} options Object with the following properties: 9 | * @param {String} options.url The base url, e.g.: https://s3.amazonaws.com/elevation-tiles-prod/terrarium/ . 10 | * @param {Object} [options.proxy] A proxy to use for requests. This object is expected to have a getURL function which returns the proxied URL, if needed. 11 | * @param {TilingScheme} [options.tilingScheme] The tiling scheme specifying how the terrain 12 | * is broken into tiles. If this parameter is not provided, a {@link GeographicTilingScheme} 13 | * is used. 14 | * @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If the tilingScheme is specified, 15 | * this parameter is ignored and the tiling scheme's ellipsoid is used instead. 16 | * If neither parameter is specified, the WGS84 ellipsoid is used. 17 | * @param {Credit|String} [options.credit] The credit, which will is displayed on the canvas. 18 | * 19 | * 20 | * @example 21 | * var terrainProvider = new Cesium.MapzenTerrariumTerrainProvider({ 22 | * url : 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/', 23 | * }); 24 | * viewer.terrainProvider = terrainProvider; 25 | * 26 | * @see TerrainProvider 27 | */ 28 | export declare function MapzenTerrariumTerrainProvider(options: any): void; 29 | -------------------------------------------------------------------------------- /src/cesium/MapzenTerrariumTerrainProvider.ts: -------------------------------------------------------------------------------- 1 | // @author: YousefED 2 | // From https://github.com/YousefED/cesium/commit/3791582640b12753c7ebd09efe4d7a032fcbfeca 3 | 4 | import { 5 | Credit, 6 | defaultValue, 7 | defined, 8 | Ellipsoid, 9 | Event, 10 | WebMercatorTilingScheme, 11 | getImagePixels, 12 | HeightmapTerrainData, 13 | loadImage, 14 | TerrainProvider, 15 | throttleRequestByServer 16 | } from './cesium-imports' 17 | 18 | 19 | /** 20 | * A {@link TerrainProvider} that produces terrain geometry by tessellating height maps 21 | * retrieved from Mapzen (which are publicly hosted on S3). 22 | * 23 | * @alias MapzenTerrariumTerrainProvider 24 | * @constructor 25 | * 26 | * @param {Object} options Object with the following properties: 27 | * @param {String} options.url The base url, e.g.: https://s3.amazonaws.com/elevation-tiles-prod/terrarium/ . 28 | * @param {Object} [options.proxy] A proxy to use for requests. This object is expected to have a getURL function which returns the proxied URL, if needed. 29 | * @param {TilingScheme} [options.tilingScheme] The tiling scheme specifying how the terrain 30 | * is broken into tiles. If this parameter is not provided, a {@link GeographicTilingScheme} 31 | * is used. 32 | * @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If the tilingScheme is specified, 33 | * this parameter is ignored and the tiling scheme's ellipsoid is used instead. 34 | * If neither parameter is specified, the WGS84 ellipsoid is used. 35 | * @param {Credit|String} [options.credit] The credit, which will is displayed on the canvas. 36 | * 37 | * 38 | * @example 39 | * var terrainProvider = new Cesium.MapzenTerrariumTerrainProvider({ 40 | * url : 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/', 41 | * }); 42 | * viewer.terrainProvider = terrainProvider; 43 | * 44 | * @see TerrainProvider 45 | */ 46 | export function MapzenTerrariumTerrainProvider(options) { 47 | //>>includeStart('debug', pragmas.debug); 48 | 49 | this._token = options.token; 50 | this._url = options.url; 51 | this._tilingScheme = options.tilingScheme; 52 | if (!defined(this._tilingScheme)) { 53 | /*this._tilingScheme = new GeographicTilingScheme({ 54 | ellipsoid : defaultValue(options.ellipsoid, Ellipsoid.WGS84) 55 | });*/ 56 | this._tilingScheme = new WebMercatorTilingScheme({ 57 | numberOfLevelZeroTilesX:1, 58 | numberOfLevelZeroTilesY:1, 59 | ellipsoid : defaultValue(options.ellipsoid, Ellipsoid.WGS84) 60 | }); 61 | } 62 | 63 | this._heightmapWidth = 64; 64 | this._levelZeroMaximumGeometricError = TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(this._tilingScheme.ellipsoid, this._heightmapWidth, this._tilingScheme.getNumberOfXTilesAtLevel(0)); 65 | 66 | this._proxy = options.proxy; 67 | 68 | this._terrainDataStructure = { 69 | heightScale : 1.0 / 256.0, 70 | heightOffset : -32768.0, 71 | elementsPerHeight : 3, 72 | stride : 4, 73 | elementMultiplier : 256.0, 74 | isBigEndian : true, 75 | lowestEncodedHeight : 0, 76 | highestEncodedHeight : 256 * 256 * 256 - 1 77 | }; 78 | 79 | this._errorEvent = new Event(); 80 | 81 | var credit = options.credit; 82 | if (typeof credit === 'string') { 83 | credit = new Credit(credit); 84 | } 85 | this._credit = credit; 86 | this._readyPromise = Promise.resolve(true); 87 | 88 | this._terrainPromises = {}; 89 | } 90 | 91 | Object.defineProperties(MapzenTerrariumTerrainProvider.prototype, { 92 | /** 93 | * Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing 94 | * to the event, you will be notified of the error and can potentially recover from it. Event listeners 95 | * are passed an instance of {@link TileProviderError}. 96 | * @memberof ArcGisImageServerTerrainProvider.prototype 97 | * @type {Event} 98 | */ 99 | errorEvent : { 100 | get : function() { 101 | return this._errorEvent; 102 | } 103 | }, 104 | 105 | /** 106 | * Gets the credit to display when this terrain provider is active. Typically this is used to credit 107 | * the source of the terrain. This function should not be called before {@link MapzenTerrariumTerrainProvider#ready} returns true. 108 | * @memberof MapzenTerrariumTerrainProvider.prototype 109 | * @type {Credit} 110 | */ 111 | credit : { 112 | get : function() { 113 | return this._credit; 114 | } 115 | }, 116 | 117 | /** 118 | * Gets the tiling scheme used by this provider. This function should 119 | * not be called before {@link MapzenTerrariumTerrainProvider#ready} returns true. 120 | * @memberof MapzenTerrariumTerrainProvider.prototype 121 | * @type {GeographicTilingScheme} 122 | */ 123 | tilingScheme : { 124 | get : function() { 125 | return this._tilingScheme; 126 | } 127 | }, 128 | 129 | /** 130 | * Gets a value indicating whether or not the provider is ready for use. 131 | * @memberof MapzenTerrariumTerrainProvider.prototype 132 | * @type {Boolean} 133 | */ 134 | ready : { 135 | get : function() { 136 | return true; 137 | } 138 | }, 139 | 140 | /** 141 | * Gets a promise that resolves to true when the provider is ready for use. 142 | * @memberof MapzenTerrariumTerrainProvider.prototype 143 | * @type {Promise.} 144 | * @readonly 145 | */ 146 | readyPromise : { 147 | get : function() { 148 | return this._readyPromise; 149 | } 150 | }, 151 | 152 | /** 153 | * Gets a value indicating whether or not the provider includes a water mask. The water mask 154 | * indicates which areas of the globe are water rather than land, so they can be rendered 155 | * as a reflective surface with animated waves. This function should not be 156 | * called before {@link MapzenTerrariumTerrainProvider#ready} returns true. 157 | * @memberof MapzenTerrariumTerrainProvider.prototype 158 | * @type {Boolean} 159 | */ 160 | hasWaterMask : { 161 | get : function() { 162 | return false; 163 | } 164 | }, 165 | 166 | /** 167 | * Gets a value indicating whether or not the requested tiles include vertex normals. 168 | * This function should not be called before {@link MapzenTerrariumTerrainProvider#ready} returns true. 169 | * @memberof MapzenTerrariumTerrainProvider.prototype 170 | * @type {Boolean} 171 | */ 172 | hasVertexNormals : { 173 | get : function() { 174 | return false; 175 | } 176 | } 177 | }); 178 | 179 | /** 180 | * Requests the geometry for a given tile. This function should not be called before 181 | * {@link MapzenTerrariumTerrainProvider#ready} returns true. The result includes terrain 182 | * data and indicates that all child tiles are available. 183 | * 184 | * @param {Number} x The X coordinate of the tile for which to request geometry. 185 | * @param {Number} y The Y coordinate of the tile for which to request geometry. 186 | * @param {Number} level The level of the tile for which to request geometry. 187 | * @returns {Promise.|undefined} A promise for the requested geometry. If this method 188 | * returns undefined instead of a promise, it is an indication that too many requests are already 189 | * pending and the request will be retried later. 190 | */ 191 | MapzenTerrariumTerrainProvider.prototype.requestTileGeometry = function(x, y, level, throttleRequests) { 192 | var url = this._url+level+'/'+x+'/'+y+'.png'; 193 | 194 | var proxy = this._proxy; 195 | if (defined(proxy)) { 196 | url = proxy.getURL(url); 197 | } 198 | 199 | var promise = this._terrainPromises[url]; 200 | 201 | if (!promise) { 202 | throttleRequests = defaultValue(throttleRequests, true); 203 | if (throttleRequests) { 204 | promise = throttleRequestByServer(url, loadImage); 205 | if (!defined(promise)) { 206 | return undefined; 207 | } 208 | } else { 209 | promise = loadImage(url); 210 | } 211 | this._terrainPromises[url] = promise; 212 | } 213 | 214 | var that = this; 215 | return promise.then(function(image) { 216 | return new HeightmapTerrainData({ 217 | buffer : getImagePixels(image, that._heightmapWidth, that._heightmapWidth), 218 | width : that._heightmapWidth, 219 | height : that._heightmapWidth, 220 | childTileMask : level < 16 ? 0 : 15, 221 | structure : that._terrainDataStructure 222 | }); 223 | }); 224 | }; 225 | 226 | /** 227 | * Gets the maximum geometric error allowed in a tile at a given level. 228 | * 229 | * @param {Number} level The tile level for which to get the maximum geometric error. 230 | * @returns {Number} The maximum geometric error. 231 | */ 232 | MapzenTerrariumTerrainProvider.prototype.getLevelMaximumGeometricError = function(level) { 233 | return this._levelZeroMaximumGeometricError / (1 << level); 234 | }; 235 | 236 | /** 237 | * Determines whether data for a tile is available to be loaded. 238 | * 239 | * @param {Number} x The X coordinate of the tile for which to request geometry. 240 | * @param {Number} y The Y coordinate of the tile for which to request geometry. 241 | * @param {Number} level The level of the tile for which to request geometry. 242 | * @returns {Boolean} Undefined if not supported, otherwise true or false. 243 | */ 244 | MapzenTerrariumTerrainProvider.prototype.getTileDataAvailable = function(x, y, level) { 245 | return level < 16 ? true : undefined; 246 | }; 247 | -------------------------------------------------------------------------------- /src/cesium/cesium-extensions.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'cesium' { 2 | interface SampledProperty { 3 | maxNumSamples: number; 4 | } 5 | interface SampledPositionProperty { 6 | maxNumSamples: number; 7 | } 8 | } 9 | export {}; 10 | -------------------------------------------------------------------------------- /src/cesium/cesium-extensions.ts: -------------------------------------------------------------------------------- 1 | // Add functionality for keeping a moving window of samples per SampledProperty, 2 | // so that the data doesn't accumulate indefinitely 3 | 4 | import { 5 | SampledProperty, 6 | SampledPositionProperty, 7 | binarySearch, 8 | JulianDate 9 | } from './cesium-imports' 10 | 11 | declare module 'cesium' { 12 | interface SampledProperty { 13 | maxNumSamples: number; 14 | } 15 | interface SampledPositionProperty { 16 | maxNumSamples: number; 17 | } 18 | } 19 | 20 | var after = function (fn: T, after: Function): T { 21 | return function() { 22 | var result = fn.apply(this, arguments) 23 | after.call(this, result) 24 | return result 25 | } 26 | } 27 | 28 | function removeBeforeDate(property: any, time: JulianDate) { 29 | var times = property._times 30 | var index = ~binarySearch(times, time, JulianDate.compare) 31 | if (index > 0) { 32 | times.splice(0, index) 33 | property._values.splice(0, index * property._innerType.packedLength) 34 | property._updateTableLength = true 35 | property._definitionChanged.raiseEvent(property) 36 | } 37 | } 38 | 39 | SampledProperty.prototype.removeSamplesBeforeDate = function(time) { 40 | removeBeforeDate(this, time) 41 | } 42 | 43 | SampledPositionProperty.prototype.removeSamplesBeforeDate = function(time) { 44 | removeBeforeDate(this._property, time) 45 | } 46 | 47 | function removeOldSamples(property: any, maxNumSamples: number) { 48 | if (maxNumSamples === undefined) return; 49 | var removeCount = property._times.length - maxNumSamples 50 | if (removeCount > 0) { 51 | property._times.splice(0, removeCount) 52 | property._values.splice(0, removeCount * property._innerType.packedLength) 53 | property._updateTableLength = true 54 | } 55 | } 56 | 57 | SampledProperty.prototype.addSample = after( 58 | SampledProperty.prototype.addSample, 59 | function() { 60 | removeOldSamples(this, this.maxNumSamples) 61 | } 62 | ) 63 | 64 | SampledProperty.prototype.addSamples = after( 65 | SampledProperty.prototype.addSamples, 66 | function() { 67 | removeOldSamples(this, this.maxNumSamples) 68 | } 69 | ) 70 | 71 | SampledProperty.prototype.addSamplesPackedArray = after( 72 | SampledProperty.prototype.addSamplesPackedArray, 73 | function() { 74 | removeOldSamples(this, this.maxNumSamples) 75 | } 76 | ) 77 | 78 | SampledPositionProperty.prototype.addSample = after( 79 | SampledPositionProperty.prototype.addSample, 80 | function() { 81 | removeOldSamples(this._property, this.maxNumSamples) 82 | } 83 | ) 84 | 85 | SampledPositionProperty.prototype.addSamples = after( 86 | SampledPositionProperty.prototype.addSamples, 87 | function() { 88 | removeOldSamples(this._property, this.maxNumSamples) 89 | } 90 | ) 91 | 92 | SampledPositionProperty.prototype.addSamplesPackedArray = after( 93 | SampledPositionProperty.prototype.addSamplesPackedArray, 94 | function() { 95 | removeOldSamples(this._property, this.maxNumSamples) 96 | } 97 | ) -------------------------------------------------------------------------------- /src/cesium/cesium-imports.d.ts: -------------------------------------------------------------------------------- 1 | export { default as binarySearch } from 'cesium/Source/Core/binarySearch'; 2 | export { default as CallbackProperty } from 'cesium/Source/DataSources/CallbackProperty'; 3 | export { default as CameraEventAggregator } from 'cesium/Source/Scene/CameraEventAggregator'; 4 | export { default as CameraEventType } from 'cesium/Source/Scene/CameraEventType'; 5 | export { default as Cartesian2 } from 'cesium/Source/Core/Cartesian2'; 6 | export { default as Cartesian3 } from 'cesium/Source/Core/Cartesian3'; 7 | export { default as Cartesian4 } from 'cesium/Source/Core/Cartesian4'; 8 | export { default as Cartographic } from 'cesium/Source/Core/Cartographic'; 9 | export { default as Clock } from 'cesium/Source/Core/Clock'; 10 | export { default as ClockStep } from 'cesium/Source/Core/ClockStep'; 11 | export { default as CompositeEntityCollection } from 'cesium/Source/DataSources/CompositeEntityCollection'; 12 | export { default as ConstantPositionProperty } from 'cesium/Source/DataSources/ConstantPositionProperty'; 13 | export { default as ConstantProperty } from 'cesium/Source/DataSources/ConstantProperty'; 14 | export { default as defaultValue } from 'cesium/Source/Core/defaultValue'; 15 | export { default as defined } from 'cesium/Source/Core/defined'; 16 | export { default as DeveloperError } from 'cesium/Source/Core/DeveloperError'; 17 | export { default as Ellipsoid } from 'cesium/Source/Core/Ellipsoid'; 18 | export { default as Entity } from 'cesium/Source/DataSources/Entity'; 19 | export { default as EntityCollection } from 'cesium/Source/DataSources/EntityCollection'; 20 | export { default as Event } from 'cesium/Source/Core/Event'; 21 | export { default as ExtrapolationType } from 'cesium/Source/Core/ExtrapolationType'; 22 | export { default as FeatureDetection } from 'cesium/Source/Core/FeatureDetection'; 23 | export { default as GeographicProjection } from 'cesium/Source/Core/GeographicProjection'; 24 | export { default as HeadingPitchRoll } from 'cesium/Source/Core/HeadingPitchRoll'; 25 | export { default as HermitePolynomialApproximation } from 'cesium/Source/Core/HermitePolynomialApproximation'; 26 | export { default as JulianDate } from 'cesium/Source/Core/JulianDate'; 27 | export { default as CesiumMath } from 'cesium/Source/Core/Math'; 28 | export { default as Matrix3 } from 'cesium/Source/Core/Matrix3'; 29 | export { default as Matrix4 } from 'cesium/Source/Core/Matrix4'; 30 | export { default as OrientationProperty } from 'cesium/Source/DataSources/OrientationProperty'; 31 | export { default as PerspectiveFrustum } from 'cesium/Source/Scene/PerspectiveFrustum'; 32 | export { default as PerspectiveOffCenterFrustum } from 'cesium/Source/Scene/PerspectiveOffCenterFrustum'; 33 | export { default as PositionProperty } from 'cesium/Source/DataSources/PositionProperty'; 34 | export { default as Property } from 'cesium/Source/DataSources/Property'; 35 | export { default as Quaternion } from 'cesium/Source/Core/Quaternion'; 36 | export { default as ReferenceEntity } from 'cesium/Source/DataSources/ReferenceEntity'; 37 | export { default as ReferenceFrame } from 'cesium/Source/Core/ReferenceFrame'; 38 | export { default as ReferenceProperty } from 'cesium/Source/DataSources/ReferenceProperty'; 39 | export { default as SampledPositionProperty } from 'cesium/Source/DataSources/SampledPositionProperty'; 40 | export { default as SampledProperty } from 'cesium/Source/DataSources/SampledProperty'; 41 | export { default as ScreenSpaceEventHandler } from 'cesium/Source/Core/ScreenSpaceEventHandler'; 42 | export { default as ScreenSpaceEventType } from 'cesium/Source/Core/ScreenSpaceEventType'; 43 | export { default as Transforms } from 'cesium/Source/Core/Transforms'; 44 | export { default as Simon1994PlanetaryPositions } from 'cesium/Source/Core/Simon1994PlanetaryPositions'; 45 | export { default as PolylinePipeline } from 'cesium/Source/Core/PolylinePipeline'; 46 | export { default as TerrainProvider } from 'cesium/Source/Core/TerrainProvider'; 47 | export { default as throttleRequestByServer } from 'cesium/Source/Core/throttleRequestByServer'; 48 | export { default as loadImage } from 'cesium/Source/Core/loadImage'; 49 | export { default as WebMercatorTilingScheme } from 'cesium/Source/Core/WebMercatorTilingScheme'; 50 | export { default as getImagePixels } from 'cesium/Source/Core/getImagePixels'; 51 | export { default as HeightmapTerrainData } from 'cesium/Source/Core/HeightmapTerrainData'; 52 | export { default as Credit } from 'cesium/Source/Core/Credit'; 53 | export { default as sampleTerrain } from 'cesium/Source/Core/sampleTerrain'; 54 | export declare function createGuid(): string; 55 | import './cesium-extensions'; 56 | -------------------------------------------------------------------------------- /src/cesium/cesium-imports.ts: -------------------------------------------------------------------------------- 1 | export { default as binarySearch } from 'cesium/Source/Core/binarySearch' 2 | export { default as CallbackProperty } from 'cesium/Source/DataSources/CallbackProperty' 3 | export { default as CameraEventAggregator } from 'cesium/Source/Scene/CameraEventAggregator' 4 | export { default as CameraEventType } from 'cesium/Source/Scene/CameraEventType' 5 | export { default as Cartesian2 } from 'cesium/Source/Core/Cartesian2' 6 | export { default as Cartesian3 } from 'cesium/Source/Core/Cartesian3' 7 | export { default as Cartesian4 } from 'cesium/Source/Core/Cartesian4' 8 | export { default as Cartographic } from 'cesium/Source/Core/Cartographic' 9 | export { default as Clock } from 'cesium/Source/Core/Clock' 10 | export { default as ClockStep } from 'cesium/Source/Core/ClockStep' 11 | // export {default as Color} from 'cesium/Source/Core/Color' 12 | export { default as CompositeEntityCollection } from 'cesium/Source/DataSources/CompositeEntityCollection' 13 | export { default as ConstantPositionProperty } from 'cesium/Source/DataSources/ConstantPositionProperty' 14 | export { default as ConstantProperty } from 'cesium/Source/DataSources/ConstantProperty' 15 | // export {default as CzmlDataSource} from 'cesium/Source/DataSources/CzmlDataSource' 16 | export { default as defaultValue } from 'cesium/Source/Core/defaultValue' 17 | export { default as defined } from 'cesium/Source/Core/defined' 18 | // export {default as DataSource} from 'cesium/Source/DataSources/DataSource' 19 | export { default as DeveloperError } from 'cesium/Source/Core/DeveloperError' 20 | export { default as Ellipsoid } from 'cesium/Source/Core/Ellipsoid' 21 | export { default as Entity } from 'cesium/Source/DataSources/Entity' 22 | export { default as EntityCollection } from 'cesium/Source/DataSources/EntityCollection' 23 | export { default as Event } from 'cesium/Source/Core/Event' 24 | export { default as ExtrapolationType } from 'cesium/Source/Core/ExtrapolationType' 25 | export { default as FeatureDetection } from 'cesium/Source/Core/FeatureDetection' 26 | export { default as GeographicProjection } from 'cesium/Source/Core/GeographicProjection' 27 | export { default as HeadingPitchRoll } from 'cesium/Source/Core/HeadingPitchRoll' 28 | export { default as HermitePolynomialApproximation } from 'cesium/Source/Core/HermitePolynomialApproximation' 29 | export { default as JulianDate } from 'cesium/Source/Core/JulianDate' 30 | export { default as CesiumMath } from 'cesium/Source/Core/Math' 31 | export { default as Matrix3 } from 'cesium/Source/Core/Matrix3' 32 | export { default as Matrix4 } from 'cesium/Source/Core/Matrix4' 33 | export { default as OrientationProperty } from 'cesium/Source/DataSources/OrientationProperty' 34 | export { default as PerspectiveFrustum } from 'cesium/Source/Scene/PerspectiveFrustum' 35 | export { default as PerspectiveOffCenterFrustum } from 'cesium/Source/Scene/PerspectiveOffCenterFrustum' 36 | export { default as PositionProperty } from 'cesium/Source/DataSources/PositionProperty' 37 | export { default as Property } from 'cesium/Source/DataSources/Property' 38 | export { default as Quaternion } from 'cesium/Source/Core/Quaternion' 39 | export { default as ReferenceEntity } from 'cesium/Source/DataSources/ReferenceEntity' 40 | export { default as ReferenceFrame } from 'cesium/Source/Core/ReferenceFrame' 41 | export { default as ReferenceProperty } from 'cesium/Source/DataSources/ReferenceProperty' 42 | export { default as SampledPositionProperty } from 'cesium/Source/DataSources/SampledPositionProperty' 43 | export { default as SampledProperty } from 'cesium/Source/DataSources/SampledProperty' 44 | export { default as ScreenSpaceEventHandler } from 'cesium/Source/Core/ScreenSpaceEventHandler' 45 | export { default as ScreenSpaceEventType } from 'cesium/Source/Core/ScreenSpaceEventType' 46 | export { default as Transforms } from 'cesium/Source/Core/Transforms' 47 | 48 | export { default as Simon1994PlanetaryPositions } from 'cesium/Source/Core/Simon1994PlanetaryPositions' 49 | export { default as PolylinePipeline } from 'cesium/Source/Core/PolylinePipeline' 50 | 51 | //Terrain Tiles 52 | export { default as TerrainProvider } from 'cesium/Source/Core/TerrainProvider' 53 | export { default as throttleRequestByServer } from 'cesium/Source/Core/throttleRequestByServer' 54 | export { default as loadImage } from 'cesium/Source/Core/loadImage' 55 | 56 | export { default as WebMercatorTilingScheme } from 'cesium/Source/Core/WebMercatorTilingScheme' 57 | export { default as getImagePixels } from 'cesium/Source/Core/getImagePixels' 58 | export { default as HeightmapTerrainData } from 'cesium/Source/Core/HeightmapTerrainData' 59 | export { default as Credit } from 'cesium/Source/Core/Credit' 60 | export { default as sampleTerrain } from 'cesium/Source/Core/sampleTerrain' 61 | 62 | 63 | const lut:string[] = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); } 64 | 65 | export function createGuid() { // from http://www.chengxuyuans.com/qa/javascript/88231.html 66 | var d0 = Math.random()*0xffffffff|0; 67 | var d1 = Math.random()*0xffffffff|0; 68 | var d2 = Math.random()*0xffffffff|0; 69 | var d3 = Math.random()*0xffffffff|0; 70 | return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+ 71 | lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+ 72 | lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+ 73 | lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff]; 74 | } 75 | 76 | import './cesium-extensions' 77 | -------------------------------------------------------------------------------- /src/common.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Matrix4, JulianDate, Cartesian3, Cartographic, Quaternion } from './cesium/cesium-imports'; 3 | /** 4 | * Default distance from a user's eyes to the floor 5 | */ 6 | export declare const AVERAGE_EYE_HEIGHT = 1.6; 7 | /** 8 | * Default near plane 9 | */ 10 | export declare const DEFAULT_NEAR_PLANE = 0.01; 11 | /** 12 | * Default far plane 13 | */ 14 | export declare const DEFAULT_FAR_PLANE = 10000; 15 | /** 16 | * Describes the role of an [[ArgonSystem]] 17 | */ 18 | export declare enum Role { 19 | /** 20 | * A system with this role is responsible for augmenting an arbitrary view of reality, 21 | * generally by overlaying computer generated graphics. A reality augmentor may also, 22 | * if appropriate, be elevated to the role of a [[REALITY_MANAGER]]. 23 | */ 24 | REALITY_AUGMENTER, 25 | /** 26 | * A system with this role is responsible for (at minimum) describing (and providing, 27 | * if necessary) a visual representation of the world and the 3D eye pose of the viewer. 28 | */ 29 | REALITY_VIEWER, 30 | /** 31 | * A system with this role is responsible for mediating access to sensors/trackers 32 | * and pose data for known entities in the world, selecting/configuring/loading 33 | * [[REALITY_VIEWER]]s, and providing the mechanism by which any given [[REALITY_AUGMENTER]] 34 | * can augment any given [[REALITY_VIEWER]]. 35 | */ 36 | REALITY_MANAGER, 37 | /** 38 | * Deprecated. Use [[REALITY_AUGMENTER]]. 39 | * @private 40 | */ 41 | APPLICATION, 42 | /** 43 | * Deprecated. Use [[REALITY_MANAGER]]. 44 | * @private 45 | */ 46 | MANAGER, 47 | /** 48 | * Deprecated. Use [[REALITY_VIEWER]] 49 | * @private 50 | */ 51 | REALITY_VIEW, 52 | } 53 | export declare namespace Role { 54 | function isRealityViewer(r?: Role): boolean; 55 | function isRealityAugmenter(r?: Role): boolean; 56 | function isRealityManager(r?: Role): boolean; 57 | } 58 | /** 59 | * Configuration options for an [[ArgonSystem]] 60 | */ 61 | export declare abstract class Configuration { 62 | version?: number[]; 63 | uri?: string; 64 | title?: string; 65 | role?: Role; 66 | protocols?: string[]; 67 | userData?: any; 68 | defaultUI?: { 69 | disable?: boolean; 70 | }; 71 | 'supportsCustomProtocols'?: boolean; 72 | } 73 | export declare class Viewport { 74 | x: number; 75 | y: number; 76 | width: number; 77 | height: number; 78 | static clone(viewport?: Viewport, result?: Viewport): Viewport | undefined; 79 | static equals(viewportA?: Viewport, viewportB?: Viewport): boolean | undefined; 80 | } 81 | /** 82 | * Viewport values are expressed using a right-handed coordinate system with the origin 83 | * at the bottom left corner. 84 | */ 85 | export declare class CanvasViewport extends Viewport { 86 | pixelRatio: number; 87 | renderWidthScaleFactor: number; 88 | renderHeightScaleFactor: number; 89 | static clone(viewport?: CanvasViewport, result?: CanvasViewport): CanvasViewport | undefined; 90 | static equals(viewportA?: CanvasViewport, viewportB?: CanvasViewport): boolean | undefined; 91 | } 92 | /** 93 | * Identifies a subview in a [[SerializedSubview]] 94 | */ 95 | export declare enum SubviewType { 96 | SINGULAR, 97 | LEFTEYE, 98 | RIGHTEYE, 99 | OTHER, 100 | } 101 | /** 102 | * A serialized notation for the position, orientation, and referenceFrame of an entity. 103 | */ 104 | export interface SerializedEntityState { 105 | p: Cartesian3; 106 | o: Quaternion; 107 | r: number | string; 108 | meta?: any; 109 | } 110 | export declare namespace SerializedEntityState { 111 | function clone(state?: SerializedEntityState, result?: SerializedEntityState | null): SerializedEntityState | null; 112 | } 113 | /** 114 | * A map of entity ids and their associated poses. 115 | */ 116 | export interface SerializedEntityStateMap { 117 | [id: string]: SerializedEntityState | null; 118 | } 119 | /** 120 | * The serialized rendering parameters for a particular subview 121 | */ 122 | export interface SerializedSubview { 123 | type: SubviewType; 124 | /** 125 | * The projection matrix for this subview 126 | */ 127 | projectionMatrix: Matrix4; 128 | /** 129 | * The viewport for this subview (relative to the primary viewport) 130 | */ 131 | viewport: Viewport; 132 | } 133 | /** 134 | * The serialized rendering parameters for a particular subview 135 | */ 136 | export interface ReadonlySerializedSubview { 137 | readonly type: SubviewType; 138 | /** 139 | * The projection matrix for this subview 140 | */ 141 | readonly projectionMatrix: Readonly; 142 | /** 143 | * The viewport for this subview (relative to the primary viewport) 144 | */ 145 | readonly viewport: Readonly; 146 | } 147 | export declare namespace SerializedSubview { 148 | function clone(subview: SerializedSubview, result?: SerializedSubview): SerializedSubview; 149 | function equals(left?: SerializedSubview, right?: SerializedSubview): boolean | undefined; 150 | } 151 | export interface SerializedDeviceState { 152 | currentFov: number; 153 | eyeCartographicPosition: Cartographic | undefined; 154 | eyeHorizontalAccuracy: number | undefined; 155 | eyeVerticalAccuracy: number | undefined; 156 | viewport: CanvasViewport; 157 | subviews: SerializedSubview[]; 158 | strictSubviews: boolean; 159 | isPresentingHMD: boolean; 160 | } 161 | export declare class SerializedSubviewList extends Array { 162 | constructor(); 163 | static clone(subviews?: SerializedSubviewList, result?: SerializedSubviewList): SerializedSubviewList | undefined; 164 | } 165 | /** 166 | * Describes the pose of a reality view and how it is able to render 167 | */ 168 | export interface DeprecatedEyeParameters { 169 | viewport?: CanvasViewport; 170 | pose?: SerializedEntityState; 171 | stereoMultiplier?: number; 172 | fov?: number; 173 | aspect?: number; 174 | } 175 | /** 176 | * Deprecated. See [[ViewSpec]] 177 | * Describes the partial frame state reported by reality viewers before v1.1 178 | * @deprecated 179 | */ 180 | export interface DeprecatedPartialFrameState { 181 | index: number; 182 | time: { 183 | dayNumber: number; 184 | secondsOfDay: number; 185 | }; 186 | view?: any; 187 | eye?: DeprecatedEyeParameters; 188 | entities?: SerializedEntityStateMap; 189 | } 190 | /** 191 | * Describes a complete frame state which is sent to child sessions 192 | */ 193 | export interface ContextFrameState { 194 | time: JulianDate; 195 | viewport: CanvasViewport; 196 | subviews: SerializedSubviewList; 197 | reality?: string; 198 | index?: number; 199 | entities: SerializedEntityStateMap; 200 | sendTime?: JulianDate; 201 | } 202 | export interface GeolocationOptions { 203 | enableHighAccuracy?: boolean; 204 | } 205 | -------------------------------------------------------------------------------- /src/device.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Entity, Cartesian3, JulianDate, PerspectiveFrustum, Cartographic } from './cesium/cesium-imports'; 3 | import { EntityService, EntityServiceProvider } from './entity'; 4 | import { SessionService, SessionPort } from './session'; 5 | import { CanvasViewport, SerializedSubviewList, SerializedEntityStateMap, GeolocationOptions } from './common'; 6 | import { Event } from './utils'; 7 | import { ViewService } from './view'; 8 | import { VisibilityService } from './visibility'; 9 | export declare class DeviceStableState { 10 | viewport?: CanvasViewport; 11 | subviews?: SerializedSubviewList; 12 | entities: SerializedEntityStateMap; 13 | suggestedGeolocationSubscription?: { 14 | enableHighAccuracy?: boolean; 15 | }; 16 | suggestedUserHeight: number; 17 | geolocationDesired: boolean; 18 | geolocationOptions?: GeolocationOptions; 19 | isPresentingHMD: boolean; 20 | isPresentingRealityHMD: boolean; 21 | strict: boolean; 22 | } 23 | export declare class DeviceFrameState { 24 | private _scratchFrustum; 25 | time: JulianDate; 26 | viewport: CanvasViewport; 27 | subviews: SerializedSubviewList; 28 | } 29 | /** 30 | * The DeviceService provides the current device state 31 | */ 32 | export declare class DeviceService { 33 | protected sessionService: SessionService; 34 | protected entityService: EntityService; 35 | protected viewService: ViewService; 36 | protected visibilityService: VisibilityService; 37 | /** 38 | * If this is true (and we are presenting via webvr api), then 39 | * vrDisplay.submitFrame is called after the frameState event 40 | */ 41 | autoSubmitFrame: boolean; 42 | /** 43 | * Device state for the current frame. This 44 | * is not updated unless the view is visible. 45 | */ 46 | frameState: DeviceFrameState; 47 | /** 48 | * An event that fires every time the device frameState is updated. 49 | */ 50 | frameStateEvent: Event; 51 | /** 52 | * An even that fires when the view starts or stops presenting to an HMD 53 | */ 54 | presentHMDChangeEvent: Event; 55 | screenOrientationChangeEvent: Event; 56 | suggestedGeolocationSubscriptionChangeEvent: Event; 57 | /** 58 | * A coordinate system representing the physical space in which the user is free to 59 | * move around, positioned on the surface the user is standing on, 60 | * where +X is east, +Y is up, and +Z is south (East-Up-South), if geolocation is known. 61 | * If the stage is not geolocated, then the +X and +Z directions are arbitrary. 62 | */ 63 | stage: Entity; 64 | /** 65 | * An entity representing the origin of the device coordinate system, +Y up. 66 | */ 67 | origin: Entity; 68 | /** 69 | * An entity representing the physical pose of the user, 70 | * where +X is right, +Y is up, and -Z is forward 71 | */ 72 | user: Entity; 73 | readonly geoHeadingAccuracy: number | undefined; 74 | readonly geoHorizontalAccuracy: number | undefined; 75 | readonly geoVerticalAccuracy: number | undefined; 76 | _geolocationDesired: boolean; 77 | readonly geolocationDesired: { 78 | enableHighAccuracy?: boolean | undefined; 79 | }; 80 | _geolocationOptions: GeolocationOptions | undefined; 81 | readonly geolocationOptions: GeolocationOptions | undefined; 82 | private _suggestedGeolocationSubscription; 83 | private _setSuggestedGeolocationSubscription(options?); 84 | readonly suggestedGeolocationSubscription: { 85 | enableHighAccuracy?: boolean | undefined; 86 | } | undefined; 87 | defaultUserHeight: number; 88 | readonly suggestedUserHeight: number; 89 | readonly strict: boolean; 90 | protected _scratchCartesian: Cartesian3; 91 | protected _scratchFrustum: PerspectiveFrustum; 92 | private _vrDisplays; 93 | private _vrDisplay; 94 | readonly vrDisplay: any; 95 | constructor(sessionService: SessionService, entityService: EntityService, viewService: ViewService, visibilityService: VisibilityService); 96 | protected _parentState: DeviceStableState | undefined; 97 | private _updatingFrameState; 98 | private _updateFrameState; 99 | readonly screenOrientationDegrees: number; 100 | protected getScreenOrientationDegrees(): () => any; 101 | /** 102 | * Request an animation frame callback for the current view. 103 | */ 104 | requestAnimationFrame: (callback: (timestamp: number) => void) => number; 105 | /** 106 | * Cancel an animation frame callback for the current view. 107 | */ 108 | cancelAnimationFrame: (id: number) => void; 109 | /** 110 | * Start emmitting frameState events 111 | */ 112 | private _startUpdates(); 113 | /** 114 | * Stop emitting frameState events 115 | */ 116 | private _stopUpdates(); 117 | protected onUpdateFrameState(): void; 118 | private _updateViewport(); 119 | private _updateDefault(); 120 | private _stringIdentifierFromReferenceFrame; 121 | private _getReachableAncestorReferenceFrames; 122 | private _scratchArray; 123 | private _originPose; 124 | private _updateDefaultOrigin(); 125 | private _updateDefaultUser(); 126 | private _vrFrameData?; 127 | private _scratchQuaternion; 128 | private _scratchQuaternion2; 129 | private _scratchMatrix3; 130 | private _scratchMatrix4; 131 | private _defaultLeftBounds; 132 | private _defaultRightBounds; 133 | private _updateForWebVR(); 134 | private _hasPolyfillWebVRDisplay(); 135 | protected onRequestPresentHMD(): Promise; 136 | protected onExitPresentHMD(): Promise; 137 | createContextFrameState(time: JulianDate, viewport: CanvasViewport, subviewList: SerializedSubviewList, options?: { 138 | overrideStage?: boolean; 139 | overrideUser?: boolean; 140 | overrideView?: boolean; 141 | floorOffset?: number; 142 | }): any; 143 | getSubviewEntity(index: number): Entity; 144 | subscribeGeolocation(options?: GeolocationOptions, session?: SessionPort): Promise; 145 | unsubscribeGeolocation(session?: SessionPort): void; 146 | /** 147 | * Is the view presenting to an HMD 148 | */ 149 | readonly isPresentingHMD: boolean; 150 | /** 151 | * Is the current reality presenting to an HMD 152 | */ 153 | readonly isPresentingRealityHMD: boolean; 154 | requestPresentHMD(): Promise; 155 | exitPresentHMD(): Promise; 156 | private _deviceOrientationListener; 157 | private _deviceOrientation; 158 | private _deviceOrientationHeadingAccuracy; 159 | private _negX90; 160 | private _tryOrientationUpdates(); 161 | private _setupVRPresentChangeHandler(); 162 | } 163 | /** 164 | * 165 | */ 166 | export declare class DeviceServiceProvider { 167 | protected sessionService: SessionService; 168 | protected deviceService: DeviceService; 169 | protected viewService: ViewService; 170 | protected entityService: EntityService; 171 | protected entityServiceProvider: EntityServiceProvider; 172 | private _subscribers; 173 | constructor(sessionService: SessionService, deviceService: DeviceService, viewService: ViewService, entityService: EntityService, entityServiceProvider: EntityServiceProvider); 174 | protected handleRequestPresentHMD(session: SessionPort): Promise; 175 | protected handleExitPresentHMD(session: SessionPort): Promise; 176 | private _needsPublish; 177 | private _publishTime; 178 | private _stableState; 179 | publishStableState(): void; 180 | protected onUpdateStableState(stableState: DeviceStableState): void; 181 | private _currentGeolocationOptions?; 182 | private _targetGeolocationOptions; 183 | private _sessionGeolocationOptions; 184 | private _checkDeviceGeolocationSubscribers(); 185 | private _sctachStageCartesian; 186 | private _scatchStageMatrix4; 187 | private _scatchStageMatrix3; 188 | private _scatchStageQuaternion; 189 | private _eastUpSouthToFixedFrame; 190 | protected configureStage(cartographic: Cartographic, geoHorizontalAccuracy?: number, geoVerticalAccuracy?: number): void; 191 | private _geolocationWatchId?; 192 | private _scratchCartographic; 193 | /** 194 | * Overridable. Should call configureStage when new geolocation is available 195 | */ 196 | onStartGeolocationUpdates(options: GeolocationOptions): void; 197 | /** 198 | * Overridable. 199 | */ 200 | onStopGeolocationUpdates(): void; 201 | } 202 | -------------------------------------------------------------------------------- /src/entity.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { SessionService, SessionPort } from './session'; 3 | import { Event } from './utils'; 4 | import { SerializedEntityState, SerializedEntityStateMap } from './common'; 5 | import { PermissionServiceProvider } from './permission'; 6 | import { Cartesian3, Cartographic, Entity, EntityCollection, JulianDate, ReferenceFrame, Transforms, Quaternion } from './cesium/cesium-imports'; 7 | /** 8 | * Represents the pose of an entity relative to a particular reference frame. 9 | * 10 | * The `update` method must be called in order to update the position / orientation / poseStatus. 11 | */ 12 | export declare class EntityPose { 13 | private _collection; 14 | constructor(_collection: EntityCollection, entityOrId: Entity | string, referenceFrameId: Entity | ReferenceFrame | string); 15 | private _entity; 16 | private _referenceFrame; 17 | readonly entity: Entity; 18 | readonly referenceFrame: Entity | ReferenceFrame; 19 | /** 20 | * The status of this pose, as a bitmask. 21 | * 22 | * If the current pose is known, then the KNOWN bit is 1. 23 | * If the current pose is not known, then the KNOWN bit is 0. 24 | * 25 | * If the previous pose was known and the current pose is unknown, 26 | * then the LOST bit is 1. 27 | * If the previous pose was unknown and the current pose status is known, 28 | * then the FOUND bit is 1. 29 | * In all other cases, both the LOST bit and the FOUND bit are 0. 30 | */ 31 | status: PoseStatus; 32 | /** 33 | * alias for status 34 | */ 35 | readonly poseStatus: PoseStatus; 36 | position: Cartesian3; 37 | orientation: Quaternion; 38 | time: JulianDate; 39 | private _previousTime; 40 | private _previousStatus; 41 | private _getEntityPositionInReferenceFrame; 42 | private _getEntityOrientationInReferenceFrame; 43 | update(time: JulianDate): void; 44 | } 45 | /** 46 | * A bitmask that provides metadata about the pose of an EntityPose. 47 | * KNOWN - the pose of the entity state is defined. 48 | * KNOWN & FOUND - the pose was undefined when the entity state was last queried, and is now defined. 49 | * LOST - the pose was defined when the entity state was last queried, and is now undefined 50 | */ 51 | export declare enum PoseStatus { 52 | KNOWN = 1, 53 | FOUND = 2, 54 | LOST = 4, 55 | } 56 | /** 57 | * A service for subscribing/unsubscribing to entities 58 | */ 59 | export declare class EntityService { 60 | protected sessionService: SessionService; 61 | constructor(sessionService: SessionService); 62 | collection: EntityCollection; 63 | subscribedEvent: Event<{ 64 | id: string; 65 | options?: {} | undefined; 66 | }>; 67 | unsubscribedEvent: Event<{ 68 | id: string; 69 | }>; 70 | subscriptions: Map; 71 | private _handleSubscribed(evt); 72 | private _handleUnsubscribed(id); 73 | private _scratchCartesian; 74 | private _scratchQuaternion; 75 | private _scratchMatrix3; 76 | private _scratchMatrix4; 77 | private _getEntityPositionInReferenceFrame; 78 | /** 79 | * Get the cartographic position of an Entity at the given time 80 | */ 81 | getCartographic(entity: Entity, time: JulianDate, result?: Cartographic): Cartographic | undefined; 82 | /** 83 | * Create an entity that is positioned at the given cartographic location, 84 | * with an orientation computed according to the provided `localToFixed` transform function. 85 | * 86 | * For the `localToFixed` parameter, you can pass any of the following: 87 | * 88 | * ``` 89 | * Argon.Cesium.Transforms.eastNorthUpToFixedFrame 90 | * Argon.Cesium.Transforms.northEastDownToFixedFrame 91 | * Argon.Cesium.Transforms.northUpEastToFixedFrame 92 | * Argon.Cesium.Transforms.northWestUpToFixedFrame 93 | * ``` 94 | * 95 | * Additionally, argon.js provides: 96 | * 97 | * ``` 98 | * Argon.eastUpSouthToFixedFrame 99 | * ``` 100 | * 101 | * Alternative transform functions can be created with: 102 | * 103 | * ``` 104 | * Argon.Cesium.Transforms.localFrameToFixedFrameGenerator 105 | * ``` 106 | */ 107 | createFixed(cartographic: Cartographic, localToFixed: typeof Transforms.northUpEastToFixedFrame): Entity; 108 | /** 109 | * Subscribe to pose updates for the given entity id 110 | * @returns A Promise that resolves to a new or existing entity 111 | */ 112 | subscribe(idOrEntity: string | Entity): Promise; 113 | subscribe(idOrEntity: string | Entity, options?: {}, session?: SessionPort): Promise; 114 | /** 115 | * Unsubscribe from pose updates for the given entity id 116 | */ 117 | unsubscribe(idOrEntity: any): void; 118 | unsubscribe(idOrEntity: string | Entity, session?: SessionPort): void; 119 | /** 120 | * Create a new EntityPose instance to represent the pose of an entity 121 | * relative to a given reference frame. If no reference frame is specified, 122 | * then the pose is based on the context's defaultReferenceFrame. 123 | * 124 | * @param entity - the entity to track 125 | * @param referenceFrameOrId - the reference frame to use 126 | */ 127 | createEntityPose(entityOrId: Entity | string, referenceFrameOrId: string | ReferenceFrame | Entity): EntityPose; 128 | /** 129 | * 130 | * @param id 131 | * @param entityState 132 | */ 133 | updateEntityFromSerializedState(id: string, entityState: SerializedEntityState | null): Entity; 134 | } 135 | /** 136 | * A service for publishing entity states to managed sessions 137 | */ 138 | export declare class EntityServiceProvider { 139 | private sessionService; 140 | private entityService; 141 | private permissionServiceProvider; 142 | subscriptionsBySubscriber: WeakMap>; 143 | subscribersByEntity: Map>; 144 | sessionSubscribedEvent: Event<{ 145 | session: SessionPort; 146 | id: string; 147 | options: {}; 148 | }>; 149 | sessionUnsubscribedEvent: Event<{ 150 | session: SessionPort; 151 | id: string; 152 | }>; 153 | targetReferenceFrameMap: Map; 154 | constructor(sessionService: SessionService, entityService: EntityService, permissionServiceProvider: PermissionServiceProvider); 155 | fillEntityStateMapForSession(session: SessionPort, time: JulianDate, entities: SerializedEntityStateMap): void; 156 | private _cacheTime; 157 | private _entityPoseCache; 158 | private _getSerializedEntityState; 159 | getCachedSerializedEntityState(entity: Entity | undefined, time: JulianDate): SerializedEntityState | null; 160 | } 161 | -------------------------------------------------------------------------------- /src/focus.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService, SessionPort } from './session'; 2 | import { Event } from './utils'; 3 | /** 4 | * Access focus state 5 | */ 6 | export declare class FocusService { 7 | /** 8 | * An event that is raised when this app has gained focus 9 | */ 10 | focusEvent: Event; 11 | /** 12 | * An event that is raised when this app has lost focus 13 | */ 14 | blurEvent: Event; 15 | /** 16 | * True if this app has focus 17 | */ 18 | readonly hasFocus: boolean; 19 | private _hasFocus; 20 | constructor(sessionService: SessionService); 21 | } 22 | /** 23 | * Manage focus state 24 | */ 25 | export declare class FocusServiceProvider { 26 | private sessionService; 27 | sessionFocusEvent: Event<{ 28 | previous?: SessionPort | undefined; 29 | current?: SessionPort | undefined; 30 | }>; 31 | constructor(sessionService: SessionService); 32 | private _session?; 33 | session: SessionPort | undefined; 34 | } 35 | -------------------------------------------------------------------------------- /src/focus.ts: -------------------------------------------------------------------------------- 1 | import { inject } from 'aurelia-dependency-injection'; 2 | import { SessionService, SessionPort } from './session'; 3 | import { Event } from './utils'; 4 | 5 | /** 6 | * Access focus state 7 | */ 8 | @inject(SessionService) 9 | export class FocusService { 10 | 11 | /** 12 | * An event that is raised when this app has gained focus 13 | */ 14 | public focusEvent = new Event(); 15 | 16 | /** 17 | * An event that is raised when this app has lost focus 18 | */ 19 | public blurEvent = new Event(); 20 | 21 | /** 22 | * True if this app has focus 23 | */ 24 | public get hasFocus() { return this._hasFocus } 25 | private _hasFocus = false; 26 | 27 | constructor(sessionService: SessionService) { 28 | sessionService.manager.on['ar.focus.state'] = ({state}: { state: boolean }) => { 29 | if (this._hasFocus !== state) { 30 | this._hasFocus = state; 31 | if (state) { 32 | this.focusEvent.raiseEvent(undefined); 33 | } else { 34 | this.blurEvent.raiseEvent(undefined); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | 41 | 42 | /** 43 | * Manage focus state 44 | */ 45 | @inject(SessionService, FocusService) 46 | export class FocusServiceProvider { 47 | 48 | public sessionFocusEvent = new Event<{ previous?: SessionPort, current?: SessionPort }>(); 49 | 50 | constructor(private sessionService:SessionService) { 51 | sessionService.ensureIsRealityManager(); 52 | sessionService.manager.connectEvent.addEventListener(() => { 53 | setTimeout(() => { 54 | if (!this._session && this.sessionService.manager.isConnected) 55 | this.session = this.sessionService.manager; 56 | }) 57 | }); 58 | } 59 | 60 | private _session?:SessionPort; 61 | 62 | public get session() { return this._session }; 63 | public set session(session: SessionPort|undefined) { 64 | if (session && !session.isConnected) 65 | throw new Error('Only a connected session can be granted focus') 66 | const previousFocussedSession = this._session; 67 | if (previousFocussedSession !== session) { 68 | if (previousFocussedSession) 69 | previousFocussedSession.send('ar.focus.state', { state: false }); 70 | if (session) session.send('ar.focus.state', { state: true }); 71 | this._session = session; 72 | this.sessionFocusEvent.raiseEvent({ 73 | previous: previousFocussedSession, 74 | current: session 75 | }); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/permission.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService, SessionPort } from './session'; 2 | export declare type PermissionType = 'geolocation' | 'camera' | 'world-structure'; 3 | export declare class Permission { 4 | readonly type: PermissionType; 5 | readonly state: PermissionState; 6 | constructor(type: PermissionType, state?: PermissionState); 7 | } 8 | export declare enum PermissionState { 9 | NOT_REQUIRED, 10 | PROMPT, 11 | GRANTED, 12 | DENIED, 13 | } 14 | /** 15 | * Access permission states 16 | */ 17 | export declare class PermissionService { 18 | protected sessionService: SessionService; 19 | constructor(sessionService: SessionService); 20 | /** 21 | * Query current state of permission 22 | * 23 | * @returns A Promise that resolves to the current state of the permission 24 | */ 25 | query(type: PermissionType, session?: SessionPort): Promise; 26 | /** 27 | * Revoke permissions 28 | * 29 | * @returns A promise that resolves to the state of requested permission after revoking. 30 | * Should be PermissionState.Denied on success. 31 | */ 32 | revoke(type: PermissionType): Promise; 33 | } 34 | /** 35 | * Manage permissions 36 | */ 37 | export declare class PermissionServiceProvider { 38 | private sessionService; 39 | constructor(sessionService: SessionService); 40 | /** 41 | * Browsers should override this and ask the users via their own UI. 42 | * The permissions should be stored locally based on the host name and id(=type). 43 | * @param session Used to acquire hostname from the uri. 44 | * @param id Can be used as a type of permission. Also can be random id's on Vuforia requests. 45 | * @returns A resolved promise if subscription is permitted. 46 | * @returns A rejected promise if subscription is not permitted. 47 | */ 48 | handlePermissionRequest(session: SessionPort, id: string, options: any): Promise; 49 | /** 50 | * Browsers should override this to check their locally stored permissions. 51 | * @param type 52 | * @returns The current state of the permission 53 | */ 54 | getPermissionState(session: SessionPort, type: PermissionType): PermissionState; 55 | } 56 | -------------------------------------------------------------------------------- /src/permission.ts: -------------------------------------------------------------------------------- 1 | import { autoinject } from 'aurelia-dependency-injection'; 2 | import { SessionService, SessionPort } from './session'; 3 | 4 | export type PermissionType = 5 | 'geolocation' //Geolocation 6 | | 'camera' //Camera 7 | | 'world-structure'; //3D Structural mesh 8 | 9 | export class Permission { 10 | readonly type: PermissionType; 11 | readonly state: PermissionState; 12 | 13 | constructor(type: PermissionType, state?: PermissionState) { 14 | this.type = type; 15 | this.state = state || PermissionState.NOT_REQUIRED; 16 | } 17 | } 18 | 19 | export enum PermissionState { 20 | NOT_REQUIRED = 'not_required' as any, //Default state. Permission is not being used. 21 | PROMPT = 'prompt' as any, //Permission should be asked for from the user. 22 | GRANTED = 'granted' as any, //Permission has been granted. 23 | DENIED = 'denied' as any, //Permission has been denied. 24 | } 25 | 26 | /** 27 | * Access permission states 28 | */ 29 | @autoinject() 30 | export class PermissionService { 31 | constructor(protected sessionService: SessionService) { 32 | 33 | } 34 | 35 | /** 36 | * Query current state of permission 37 | * 38 | * @returns A Promise that resolves to the current state of the permission 39 | */ 40 | // public query() : Promise; 41 | public query(type: PermissionType, session = this.sessionService.manager) : Promise { 42 | // let permissionMaps: Permission[] = []; 43 | return session.request('ar.permission.query', {type}).then(({state}:{state: PermissionState}) => { 44 | return state || PermissionState.NOT_REQUIRED; 45 | }); 46 | } 47 | 48 | /** 49 | * Revoke permissions 50 | * 51 | * @returns A promise that resolves to the state of requested permission after revoking. 52 | * Should be PermissionState.Denied on success. 53 | */ 54 | public revoke(type: PermissionType) : Promise { 55 | const session = this.sessionService.manager; 56 | return session.request('ar.permission.revoke', {type}).then(({state}:{state: PermissionState}) => { 57 | return state; 58 | }); 59 | } 60 | 61 | } 62 | 63 | /** 64 | * Manage permissions 65 | */ 66 | @autoinject() 67 | export class PermissionServiceProvider { 68 | 69 | constructor(private sessionService:SessionService) { 70 | this.sessionService.ensureIsRealityManager(); 71 | this.sessionService.connectEvent.addEventListener((session: SessionPort) => { 72 | 73 | session.on['ar.permission.query'] = ({type}: {type: PermissionType}) => { 74 | return Promise.resolve({state: this.getPermissionState(session, type)}); 75 | } 76 | 77 | /** 78 | * Browswer should override this if they want to allow revoking permissions. 79 | * @param type 80 | * @returns A promise that resolves to the state of the permission after revoking 81 | */ 82 | session.on['ar.permission.revoke'] = ({type}: {type: PermissionType}) => { 83 | return Promise.reject(new Error("Revoking permission is not supported on this browser.")); 84 | } 85 | }); 86 | } 87 | 88 | /** 89 | * Browsers should override this and ask the users via their own UI. 90 | * The permissions should be stored locally based on the host name and id(=type). 91 | * @param session Used to acquire hostname from the uri. 92 | * @param id Can be used as a type of permission. Also can be random id's on Vuforia requests. 93 | * @returns A resolved promise if subscription is permitted. 94 | * @returns A rejected promise if subscription is not permitted. 95 | */ 96 | public handlePermissionRequest(session: SessionPort, id: string, options: any) { 97 | return Promise.resolve(); 98 | } 99 | 100 | /** 101 | * Browsers should override this to check their locally stored permissions. 102 | * @param type 103 | * @returns The current state of the permission 104 | */ 105 | public getPermissionState(session: SessionPort, type: PermissionType){ 106 | return PermissionState.GRANTED; 107 | } 108 | } -------------------------------------------------------------------------------- /src/reality-viewers/base.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { ReferenceFrame } from '../cesium/cesium-imports'; 3 | import { SessionPort } from '../session'; 4 | import { Event } from '../utils'; 5 | /** 6 | * Abstract class for a RealityViewer 7 | */ 8 | export declare abstract class RealityViewer { 9 | uri: string; 10 | providedReferenceFrames: Array; 11 | connectEvent: Event; 12 | presentChangeEvent: Event; 13 | private _isPresenting; 14 | readonly isPresenting: boolean; 15 | private _session?; 16 | readonly session: SessionPort | undefined; 17 | constructor(uri: string); 18 | destroy(): void; 19 | setPresenting(flag: boolean): void; 20 | abstract load(): any; 21 | static DEFAULT: string; 22 | static EMPTY: string; 23 | static LIVE: string; 24 | static getType(uri?: string): string | undefined; 25 | } 26 | -------------------------------------------------------------------------------- /src/reality-viewers/base.ts: -------------------------------------------------------------------------------- 1 | import {ReferenceFrame} from '../cesium/cesium-imports' 2 | import {SessionPort} from '../session' 3 | import {Event} from '../utils' 4 | 5 | /** 6 | * Abstract class for a RealityViewer 7 | */ 8 | export abstract class RealityViewer { 9 | 10 | public providedReferenceFrames:Array = []; 11 | 12 | public connectEvent = new Event(); 13 | public presentChangeEvent = new Event(); 14 | 15 | private _isPresenting = false; 16 | public get isPresenting() { 17 | return this._isPresenting; 18 | } 19 | 20 | private _session?:SessionPort; 21 | public get session() { 22 | return this._session; 23 | } 24 | 25 | constructor( 26 | public uri:string 27 | ){ 28 | this.connectEvent.addEventListener((session)=>{ 29 | if (this._session) this._session.close(); 30 | this._session = session; 31 | session.closeEvent.addEventListener(()=>{ 32 | if (this._session === session) this._session = undefined; 33 | }); 34 | }); 35 | } 36 | 37 | public destroy() { 38 | this.setPresenting(false); 39 | if (this.session) { 40 | this.session.close(); 41 | } 42 | }; 43 | 44 | public setPresenting(flag:boolean) { 45 | if (this._isPresenting !== flag) { 46 | this._isPresenting = flag; 47 | this.presentChangeEvent.raiseEvent(undefined); 48 | } 49 | } 50 | 51 | public abstract load(); 52 | 53 | static DEFAULT = 'reality:default'; 54 | static EMPTY = 'reality:empty'; 55 | static LIVE = 'reality:live'; 56 | 57 | static getType(uri?: string) { 58 | if (uri === undefined) return undefined; 59 | if (uri.split(':')[0] === 'reality') { 60 | return uri; 61 | } 62 | return 'hosted'; 63 | } 64 | } -------------------------------------------------------------------------------- /src/reality-viewers/empty.d.ts: -------------------------------------------------------------------------------- 1 | import { Container } from 'aurelia-dependency-injection'; 2 | import { SessionService } from '../session'; 3 | import { ViewService } from '../view'; 4 | import { RealityViewer } from './base'; 5 | export declare class EmptyRealityViewer extends RealityViewer { 6 | private sessionService; 7 | private viewService; 8 | private container; 9 | uri: string; 10 | type: string; 11 | private _aggregator; 12 | private _moveFlags; 13 | constructor(sessionService: SessionService, viewService: ViewService, container: Container, uri: string); 14 | private _scratchMatrix3; 15 | private _scratchMatrix4; 16 | load(): void; 17 | } 18 | -------------------------------------------------------------------------------- /src/reality-viewers/hosted.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService } from '../session'; 2 | import { ViewService } from '../view'; 3 | import { RealityViewer } from './base'; 4 | export declare class HostedRealityViewer extends RealityViewer { 5 | private sessionService; 6 | private viewService; 7 | uri: string; 8 | type: string; 9 | iframeElement: HTMLIFrameElement; 10 | constructor(sessionService: SessionService, viewService: ViewService, uri: string); 11 | destroy(): void; 12 | load(): void; 13 | } 14 | -------------------------------------------------------------------------------- /src/reality-viewers/hosted.ts: -------------------------------------------------------------------------------- 1 | 2 | import { inject } from 'aurelia-dependency-injection' 3 | import { createGuid } from '../cesium/cesium-imports' 4 | import { SessionService } from '../session' 5 | import { ViewService } from '../view' 6 | import { RealityViewer } from './base' 7 | 8 | @inject(SessionService, ViewService) 9 | export class HostedRealityViewer extends RealityViewer { 10 | 11 | public type = 'hosted'; 12 | 13 | public iframeElement:HTMLIFrameElement; 14 | 15 | constructor( 16 | private sessionService: SessionService, 17 | private viewService: ViewService, 18 | public uri:string) { 19 | super(uri); 20 | 21 | if (typeof document !== 'undefined' && document.createElement) { 22 | const iframeElement = this.iframeElement = document.createElement('iframe'); 23 | iframeElement.name = createGuid(); 24 | iframeElement.style.border = '0'; 25 | iframeElement.width = '100%'; 26 | iframeElement.height = '100%'; 27 | iframeElement.style.position = 'absolute'; 28 | iframeElement.style.opacity = '0'; 29 | iframeElement.style.pointerEvents = 'none'; 30 | iframeElement.style.zIndex = "-100"; 31 | const viewElement = this.viewService.element; 32 | viewElement.insertBefore(iframeElement!, viewElement.firstChild); 33 | 34 | this.presentChangeEvent.addEventListener(()=>{ 35 | this.iframeElement.style.opacity = this.isPresenting ? '1' : '0'; 36 | }); 37 | } 38 | } 39 | 40 | public destroy() { 41 | super.destroy(); 42 | if (this.iframeElement) { 43 | this.iframeElement.remove(); 44 | } 45 | } 46 | 47 | public load(): void { 48 | if (typeof document !== 'undefined' && document.createElement) { 49 | const session = this.sessionService.addManagedSessionPort(this.uri); 50 | session.connectEvent.addEventListener(()=>{ 51 | if (this.sessionService.manager.isClosed) return; 52 | this.connectEvent.raiseEvent(session); 53 | }); 54 | 55 | let handleConnectMessage = (ev:MessageEvent) => { 56 | if (ev.data.type !== 'ARGON_SESSION') return; 57 | const name = ev.data.name; 58 | const messagePort: MessagePort = ev.ports && ev.ports[0]; 59 | 60 | if (!messagePort) 61 | throw new Error('Received an ARGON_SESSION message without a MessagePort object'); 62 | 63 | if (name !== this.iframeElement.name) return; 64 | 65 | window.removeEventListener('message', handleConnectMessage); 66 | 67 | session.open(messagePort, this.sessionService.configuration); 68 | }; 69 | window.addEventListener('message', handleConnectMessage); 70 | 71 | this.iframeElement.src = ''; 72 | this.iframeElement.src = this.uri; 73 | } 74 | } 75 | } 76 | 77 | // @singleton() 78 | // @inject(SessionFactory) 79 | // export class DOMSessionListenerService { 80 | 81 | // public sessionEvent = new Event(); 82 | 83 | // constructor(sessionFactory:SessionFactory) { 84 | // window.addEventListener('message', ev => { 85 | // if (ev.data.type != 'ARGON_SESSION') return; 86 | 87 | // const messagePort:MessagePortLike = ev.ports && ev.ports[0]; 88 | // if (!messagePort) 89 | // throw new Error('Received an ARGON_SESSION message without a MessagePort object'); 90 | 91 | // // get the event.source iframe 92 | // let i = 0; 93 | // let frame:HTMLIFrameElement = null; 94 | // while (i < window.frames.length && frame != null) { 95 | // if (window.frames[i] == ev.source) 96 | // frame = document.getElementsByTagName( 'iframe' )[i]; 97 | // } 98 | 99 | // const session = sessionFactory.create(); 100 | // session.frame = frame; 101 | 102 | // if (frame) frame.addEventListener('load', function close() { 103 | // frame.removeEventListener('load', close); 104 | // console.log('IFrameSessionHandler: frame load detected, closing current session.', frame, session) 105 | // session.close() 106 | // }); 107 | 108 | // this.sessionEvent.raiseEvent(session); 109 | // }); 110 | // } 111 | // } 112 | -------------------------------------------------------------------------------- /src/reality-viewers/live.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService, SessionPort } from '../session'; 2 | import { ViewService } from '../view'; 3 | import { ContextService } from '../context'; 4 | import { DeviceService } from '../device'; 5 | import { RealityViewer } from './base'; 6 | export declare class LiveRealityViewer extends RealityViewer { 7 | private sessionService; 8 | private viewService; 9 | private contextService; 10 | private deviceService; 11 | uri: string; 12 | videoElement: HTMLVideoElement; 13 | private canvas; 14 | private context; 15 | private videoFov; 16 | private settingsIframe; 17 | constructor(sessionService: SessionService, viewService: ViewService, contextService: ContextService, deviceService: DeviceService, uri: string); 18 | destroy(): void; 19 | protected setupInternalSession(internalSession: SessionPort): void; 20 | load(): void; 21 | static isAvailable(): boolean; 22 | getVideoFrame(x: number, y: number, width: number, height: number): ImageData; 23 | } 24 | -------------------------------------------------------------------------------- /src/reality-viewers/live.ts: -------------------------------------------------------------------------------- 1 | import { inject } from 'aurelia-dependency-injection' 2 | import { Role } from '../common' 3 | import { SessionService, SessionPort } from '../session' 4 | import { ViewService } from '../view' 5 | import { ContextService } from '../context' 6 | import { DeviceService } from '../device' 7 | import { RealityViewer } from './base' 8 | 9 | @inject(SessionService, ViewService, ContextService, DeviceService) 10 | export class LiveRealityViewer extends RealityViewer { 11 | 12 | public videoElement: HTMLVideoElement; 13 | 14 | private canvas: HTMLCanvasElement; 15 | private context: CanvasRenderingContext2D; 16 | 17 | private videoFov: number; 18 | 19 | private settingsIframe: HTMLIFrameElement; 20 | 21 | constructor( 22 | private sessionService: SessionService, 23 | private viewService: ViewService, 24 | private contextService: ContextService, 25 | private deviceService: DeviceService, 26 | public uri:string) { 27 | super(uri); 28 | 29 | if (typeof document !== 'undefined') { 30 | this.settingsIframe = document.createElement('iframe'); 31 | this.settingsIframe.width = '0'; 32 | this.settingsIframe.height = '0'; 33 | this.settingsIframe.src = 'https://argonjs.io/tools.argonjs.io/'; 34 | this.settingsIframe.style.display = 'none'; 35 | 36 | this.videoFov = Math.PI / 2; 37 | 38 | this.videoElement = document.createElement('video'); 39 | this.videoElement.style.width = '100%'; 40 | this.videoElement.style.height = 'height:100%'; 41 | this.videoElement.controls = false; 42 | this.videoElement.autoplay = true; 43 | this.videoElement.style.display = 'none'; 44 | this.videoElement.style.zIndex = "-100"; 45 | 46 | const viewElement = this.viewService.element; 47 | viewElement.insertBefore(this.settingsIframe, viewElement.firstChild); 48 | viewElement.insertBefore(this.videoElement, viewElement.firstChild); 49 | 50 | this.canvas = document.createElement('canvas'); 51 | this.context = this.canvas.getContext('2d')!; 52 | 53 | window.addEventListener('message', (event) => { 54 | const origin = event.origin; 55 | if (origin === 'http://argonjs.io') { 56 | this.videoFov = event.data; // TODO: this is not flexible. Should be passing an object with message type and data 57 | } 58 | }); 59 | } 60 | 61 | this.presentChangeEvent.addEventListener(()=>{ 62 | if (typeof document !== 'undefined') { 63 | this.videoElement.style.display = this.isPresenting ? 'initial' : 'none'; 64 | } 65 | }) 66 | } 67 | 68 | public destroy() { 69 | super.destroy(); 70 | if (typeof document !== 'undefined') { 71 | this.settingsIframe.remove(); 72 | this.videoElement.remove(); 73 | this.canvas.remove(); 74 | } 75 | } 76 | 77 | protected setupInternalSession(internalSession:SessionPort) { 78 | 79 | internalSession.connectEvent.addEventListener(() => { 80 | 81 | if (this.videoElement) { 82 | const videoElement = this.videoElement!; 83 | const mediaDevices = navigator.mediaDevices; 84 | const getUserMedia = (mediaDevices.getUserMedia || mediaDevices['mozGetUserMedia'] || 85 | mediaDevices['msGetUserMedia'] || mediaDevices['webkitGetUserMedia']).bind(mediaDevices); 86 | 87 | getUserMedia({ audio: false, video: true }).then((videoStream: MediaStream) => { 88 | const stopVideoStream = () => { 89 | for (const t of videoStream.getTracks()) { 90 | t.stop(); 91 | } 92 | } 93 | if (internalSession.isConnected) { 94 | videoElement.src = window.URL.createObjectURL(videoStream); 95 | internalSession.closeEvent.addEventListener(stopVideoStream) 96 | } else { 97 | stopVideoStream(); 98 | } 99 | }).catch((error: DOMException) => { 100 | internalSession.errorEvent.raiseEvent(error); 101 | }); 102 | 103 | // const viewService = this.viewService; 104 | let lastFrameTime = -1; 105 | 106 | const remove1 = this.deviceService.suggestedGeolocationSubscriptionChangeEvent.addEventListener(()=>{ 107 | 108 | if (this.deviceService.suggestedGeolocationSubscription) { 109 | this.deviceService.subscribeGeolocation(this.deviceService.suggestedGeolocationSubscription, internalSession); 110 | } else { 111 | this.deviceService.unsubscribeGeolocation(); 112 | } 113 | 114 | }); 115 | 116 | const remove2 =this.deviceService.frameStateEvent.addEventListener((frameState)=>{ 117 | 118 | if (videoElement.currentTime != lastFrameTime) { 119 | lastFrameTime = videoElement.currentTime; 120 | 121 | // const videoWidth = videoElement.videoWidth; 122 | // const videoHeight = videoElement.videoHeight; 123 | 124 | const contextFrameState = this.contextService.createFrameState( 125 | frameState.time, 126 | frameState.viewport, 127 | frameState.subviews 128 | ); 129 | 130 | internalSession.send('ar.reality.frameState', contextFrameState); 131 | } 132 | 133 | }); 134 | 135 | internalSession.closeEvent.addEventListener(()=>{ 136 | remove1(); 137 | remove2(); 138 | }) 139 | } 140 | }); 141 | } 142 | 143 | public load(): void { 144 | const session = this.sessionService.addManagedSessionPort(this.uri); 145 | session.connectEvent.addEventListener(()=>{ 146 | this.connectEvent.raiseEvent(session); 147 | }); 148 | 149 | const internalSession = this.sessionService.createSessionPort(this.uri); 150 | internalSession.suppressErrorOnUnknownTopic = true; 151 | this.setupInternalSession(internalSession); 152 | 153 | // Only connect after the caller is able to attach connectEvent handlers 154 | Promise.resolve().then(()=>{ 155 | if (this.sessionService.manager.isClosed) return; 156 | const messageChannel = this.sessionService.createSynchronousMessageChannel(); 157 | session.open(messageChannel.port1, this.sessionService.configuration); 158 | internalSession.open(messageChannel.port2, { role: Role.REALITY_VIEWER, title: 'Live', uri: this.uri, version: this.sessionService.configuration.version }); 159 | }) 160 | } 161 | 162 | public static isAvailable(): boolean { 163 | if (typeof navigator !== 'undefined' && navigator.mediaDevices) { 164 | const mediaDevices = navigator.mediaDevices; 165 | return !!(mediaDevices.getUserMedia || mediaDevices['mozGetUserMedia'] || mediaDevices['msGetUserMedia'] || mediaDevices['webkitGetUserMedia']); 166 | } else { 167 | return false; 168 | } 169 | } 170 | 171 | public getVideoFrame(x: number, y: number, width: number, height: number): ImageData { 172 | this.canvas.width = this.videoElement.videoWidth; 173 | this.canvas.height = this.videoElement.videoHeight; 174 | this.context.drawImage(this.videoElement, 0, 0, this.canvas.width, this.canvas.height); 175 | return this.context.getImageData(x, y, width, height); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/reality.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Cartographic } from './cesium/cesium-imports'; 3 | import { SessionPort, SessionService } from './session'; 4 | import { Event } from './utils'; 5 | import { ContextService } from './context'; 6 | import { FocusServiceProvider } from './focus'; 7 | import { VisibilityServiceProvider } from './visibility'; 8 | import { RealityViewer } from './reality-viewers/base'; 9 | import { ViewServiceProvider } from './view'; 10 | import { DeviceService } from './device'; 11 | export declare abstract class RealityViewerFactory { 12 | private _createEmptyReality; 13 | private _createLiveReality; 14 | private _createHostedReality; 15 | constructor(_createEmptyReality: any, _createLiveReality: any, _createHostedReality: any); 16 | createRealityViewer(uri: string): RealityViewer; 17 | } 18 | /** 19 | * A service which makes requests to manage the reality viewer. 20 | */ 21 | export declare class RealityService { 22 | private sessionService; 23 | private contextService; 24 | /** 25 | * An event that provides a session for sending / receiving 26 | * commands to / from a reality. 27 | * 28 | * The session passed via this event can represent either endpoint of 29 | * a connection between RealityViewer <--> RealityAugmenter/RealityManager. 30 | * 31 | * If running in a RealityAugmenter, the session 32 | * represents a connection to a RealityViewer. 33 | * 34 | * If running in a RealityViewer, the session 35 | * represents a connection to a RealityAugmenter. 36 | */ 37 | readonly connectEvent: Event; 38 | private _connectEvent; 39 | /** 40 | * A collection of connected sessions. 41 | * 42 | * If running in a RealityAugmenter, this collection 43 | * represents connections to any loaded RealityViewers. 44 | * 45 | * If running in a RealityViewer, this collection 46 | * represents connections to any RealityAugmenters. 47 | */ 48 | readonly sessions: SessionPort[]; 49 | private _sessions; 50 | /** 51 | * An event that is raised when the presenting reality viewer is changed. 52 | */ 53 | readonly changeEvent: Event<{ 54 | previous?: string | undefined; 55 | current: string; 56 | }>; 57 | private _changeEvent; 58 | /** 59 | * The URI for the currently presenting Reality Viewer. 60 | */ 61 | readonly current: string | undefined; 62 | private _current?; 63 | /** 64 | * The default Reality Viewer. 65 | */ 66 | default: string; 67 | constructor(sessionService: SessionService, contextService: ContextService); 68 | /** 69 | * Install the specified reality viewer 70 | */ 71 | install(uri: string): Promise; 72 | /** 73 | * Uninstall the specified reality viewer 74 | */ 75 | uninstall(uri: string): Promise; 76 | /** 77 | * Request a reality viewer to be presented. 78 | * - Pass a url to request a (custum) hosted reality viewer 79 | * - [[RealityViewer.DEFAULT]] to request the system default reality viewer 80 | * - [[RealityViewer.LIVE]] to request a live reality viewer 81 | * - [[RealityViewer.EMPTY]] to request an empty reality viewer 82 | */ 83 | request(uri: string): Promise; 84 | /** 85 | * Deprecated. Use [[RealityService#request]] 86 | * @deprecated 87 | */ 88 | setDesired(reality: { 89 | uri: string; 90 | } | undefined): void; 91 | /** 92 | * Ask a reality to move the stage to the given geolocation 93 | */ 94 | setStageGeolocation(realitySession: SessionPort, geolocation: Cartographic): Promise; 95 | /** 96 | * Ask a reality to move the stage to the given geolocation 97 | */ 98 | resetStageGeolocation(realitySession: SessionPort): Promise; 99 | } 100 | export declare class RealityServiceProvider { 101 | private sessionService; 102 | private realityService; 103 | private contextService; 104 | private deviceService; 105 | private viewServiceProvider; 106 | private visibilityServiceProvider; 107 | private focusServiceProvider; 108 | private realityViewerFactory; 109 | /** 110 | * An event that is raised when a reality viewer is installed. 111 | */ 112 | installedEvent: Event<{ 113 | viewer: RealityViewer; 114 | }>; 115 | /** 116 | * An event that is raised when a reality viewer is uninstalled. 117 | */ 118 | uninstalledEvent: Event<{ 119 | viewer: RealityViewer; 120 | }>; 121 | readonly presentingRealityViewer: RealityViewer | undefined; 122 | private _presentingRealityViewer; 123 | private _viewerByURI; 124 | private _installersByURI; 125 | constructor(sessionService: SessionService, realityService: RealityService, contextService: ContextService, deviceService: DeviceService, viewServiceProvider: ViewServiceProvider, visibilityServiceProvider: VisibilityServiceProvider, focusServiceProvider: FocusServiceProvider, realityViewerFactory: RealityViewerFactory); 126 | private _scratchFrustum; 127 | private _handleInstall(session, uri); 128 | private _connectViewerWithSession(viewerSession, session); 129 | protected _handleUninstall(session: SessionPort, uri: string): Promise; 130 | protected _handleRequest(session: SessionPort, options: { 131 | uri: string; 132 | }): Promise; 133 | private _setPresentingRealityViewer(viewer); 134 | getViewerByURI(uri: string): RealityViewer | undefined; 135 | removeInstaller(installerSession: SessionPort): void; 136 | } 137 | -------------------------------------------------------------------------------- /src/ui.d.ts: -------------------------------------------------------------------------------- 1 | import { DeviceService } from './device'; 2 | import { SessionService } from './session'; 3 | import { ViewService } from './view'; 4 | import { RealityService, RealityServiceProvider } from './reality'; 5 | /** 6 | * Provides a default UI 7 | */ 8 | export declare class DefaultUIService { 9 | private sessionService; 10 | private viewService; 11 | private realityService; 12 | private realityServiceProvider; 13 | private deviceService; 14 | private element?; 15 | private realityViewerSelectorElement; 16 | private realityViewerListElement; 17 | private menuBackgroundElement; 18 | private realityViewerItemElements; 19 | private menuItems; 20 | private menuOpen; 21 | private openInArgonMenuItem; 22 | private hmdMenuItem; 23 | private realityMenuItem; 24 | private maximizeMenuItem; 25 | constructor(sessionService: SessionService, viewService: ViewService, realityService: RealityService, realityServiceProvider: RealityServiceProvider, deviceService: DeviceService); 26 | private _createMenuItem(icon, hint, onSelect?); 27 | private onSelect(element, cb); 28 | private toggleMenu(); 29 | private _hideMenuItem(e); 30 | updateMenu(): void; 31 | } 32 | -------------------------------------------------------------------------------- /src/utils.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { SerializedEntityState } from './common'; 3 | import { Entity, JulianDate, PerspectiveFrustum, PerspectiveOffCenterFrustum, Quaternion, Cartesian3, ReferenceFrame, Matrix4, Transforms, Cartographic } from './cesium/cesium-imports'; 4 | export * from './utils/command-queue'; 5 | export * from './utils/event'; 6 | export * from './utils/message-channel'; 7 | export { default as getEventSynthesizier } from './utils/ui-event-synthesizer'; 8 | export { default as createEventForwarder } from './utils/ui-event-forwarder'; 9 | export declare function isNativeFunction(f: Function): boolean; 10 | export declare const hasNativeWebVRImplementation: boolean; 11 | export declare const suggestedWebGLContextAntialiasAttribute: boolean; 12 | export declare function stringIdentifierFromReferenceFrame(referenceFrame: string | ReferenceFrame | Entity): string; 13 | export declare function jsonEquals(left?: {}, right?: {}): boolean; 14 | /** 15 | * Computes a 4x4 transformation matrix from a reference frame with an east-up-south axes centered at the provided origin to the provided ellipsoid's fixed reference frame. The local axes are defined as: 16 | * The x axis points in the local east direction. 17 | * The y axis points in the points in the direction of the ellipsoid surface normal which passes through the position.. 18 | * The z axis points in the local south direction. 19 | */ 20 | export declare const eastUpSouthToFixedFrame: Transforms.ConversionFunction; 21 | /** 22 | * Get array of ancestor reference frames of a Cesium Entity, ordered from 23 | * farthest ancestor to the passed frame, excluding the passed frame. 24 | * @param frame A Cesium Entity to get ancestor reference frames. 25 | * @param frames An array of reference frames of the Cesium Entity. 26 | */ 27 | export declare function getAncestorReferenceFrames(frame: Entity, result?: never[]): (Entity | ReferenceFrame)[]; 28 | /** 29 | * Get array of ancestor reference frames of a Cesium Entity, ordered from 30 | * farthest ancestor which has a valid pose to the passed frame, excluding the passed frame. 31 | * @param frame A Cesium Entity to get ancestor reference frames. 32 | * @param frames An array of reference frames of the Cesium Entity. 33 | */ 34 | export declare function getReachableAncestorReferenceFrames(frame: Entity, time: JulianDate, result?: never[]): (Entity | ReferenceFrame)[]; 35 | /** 36 | * Gets the value of the Position property at the provided time and in the provided reference frame. 37 | * @param entity The entity to get position. 38 | * @param time The time for which to retrieve the value. 39 | * @param referenceFrame The desired referenceFrame of the result. 40 | * @param result The object to store the value into. 41 | * @return The modified result parameter. 42 | */ 43 | export declare function getEntityPositionInReferenceFrame(entity: Entity, time: JulianDate, referenceFrame: Entity | ReferenceFrame, result: Cartesian3): Cartesian3 | undefined; 44 | /** 45 | * Alias of getEntityPositionInReferenceFrame 46 | */ 47 | export declare const getEntityPosition: typeof getEntityPositionInReferenceFrame; 48 | /** 49 | * Get the value of the Orientation property at the provided time and in the provided reference frame. 50 | * @param entity The entity to get position. 51 | * @param time The time for which to retrieve the value. 52 | * @param referenceFrame The desired referenceFrame of the result. 53 | * @param result The object to store the value into. 54 | * @return The modified result parameter. 55 | */ 56 | export declare function getEntityOrientationInReferenceFrame(entity: Entity, time: JulianDate, referenceFrame: ReferenceFrame | Entity, result: Quaternion): Quaternion | undefined; 57 | /** 58 | * Alias of getEntityOrientationInReferenceFrame 59 | */ 60 | export declare const getEntityOrientation: typeof getEntityOrientationInReferenceFrame; 61 | /** 62 | * Create a SerializedEntityPose from a source entity. 63 | * @param entity The entity which the serialized pose represents. 64 | * @param time The time which to retrieve the pose. 65 | * @param referenceFrame The reference frame to use for generating the pose. 66 | * If a target reference frame is not provided, the entity pose will be 67 | * serialized according to the furthest ancestor frame that resolves to a valid pose. 68 | * @return An EntityPose object with orientation, position and referenceFrame. 69 | */ 70 | export declare function getSerializedEntityState(entity: Entity, time: JulianDate, frame?: ReferenceFrame | Entity): SerializedEntityState | null; 71 | /** 72 | * If urlParser does not have a value, throw error message "resolveURL requires DOM api". 73 | * If inURL is undefined, throw error message "expected inURL". 74 | * Otherwise, assign value of inURL to urlParser.href. 75 | * @param inURL A URL needed to be resolved. 76 | * @returns A URL ready to be parsed. 77 | */ 78 | export declare function resolveURL(inURL: string): string; 79 | /** 80 | * Parse URL to an object describing details of the URL with href, protocol, 81 | * hostname, port, pathname, search, hash, host. 82 | * @param inURL A URL needed to be parsed. 83 | * @return An object showing parsed URL with href, protocol, 84 | * hostname, port, pathname, search, hash, host. 85 | */ 86 | export declare function parseURL(inURL: string): { 87 | href: string; 88 | protocol: string; 89 | hostname: string; 90 | port: string; 91 | pathname: string; 92 | search: string; 93 | hash: string; 94 | host: string; 95 | }; 96 | export declare function resolveElement(elementOrSelector: string | HTMLElement): Promise<{}>; 97 | export declare function decomposePerspectiveOffCenterProjectionMatrix(mat: Matrix4, result: PerspectiveOffCenterFrustum): PerspectiveOffCenterFrustum; 98 | export declare function decomposePerspectiveProjectionMatrix(mat: Matrix4, result: PerspectiveFrustum): PerspectiveFrustum; 99 | /** 100 | * Convert an Entity's position and orientation properties to a new reference frame. 101 | * The properties must be constant properties. 102 | * @param entity The entity to convert. 103 | * @param time The time which to retrieve the pose up the reference chain. 104 | * @param referenceFrame The reference frame to convert the position and oriention to. 105 | * @return a boolean indicating success or failure. Will be false if either property is 106 | * not constant, or if either property cannot be converted to the new frame. 107 | */ 108 | export declare function convertEntityReferenceFrame(entity: Entity, time: JulianDate, frame: ReferenceFrame | Entity): boolean; 109 | export declare const isIOS: boolean; 110 | export declare const isAndroid: boolean; 111 | export declare function installArgonApp(): void; 112 | export declare function openInArgonApp(): void; 113 | declare const rAF: any; 114 | declare const cAF: any; 115 | export { rAF as requestAnimationFrame, cAF as cancelAnimationFrame }; 116 | export declare function deprecated(alternative?: string): MethodDecorator; 117 | export declare const defaultTerrainProvider: any; 118 | export declare function updateHeightFromTerrain(cartographic: Cartographic): Promise; 119 | -------------------------------------------------------------------------------- /src/utils/command-queue.d.ts: -------------------------------------------------------------------------------- 1 | import { Event } from './event'; 2 | /** 3 | * TODO. 4 | */ 5 | export declare class CommandQueue { 6 | private _queue; 7 | private _currentCommand; 8 | private _currentCommandPending; 9 | private _paused; 10 | /** 11 | * An error event. 12 | */ 13 | errorEvent: Event; 14 | /** 15 | * If errorEvent has 1 listener, outputs the error message to the web console. 16 | */ 17 | constructor(); 18 | /** 19 | * Push a command to the command queue. 20 | * @param command Any command ready to be pushed into the command queue. 21 | */ 22 | push(command: () => Promise | TResult, execute?: boolean): Promise; 23 | /** 24 | * Execute the command queue 25 | */ 26 | execute(): void; 27 | /** 28 | * Puase the command queue (currently executing commands will still complete) 29 | */ 30 | pause(): void; 31 | /** 32 | * Clear commandQueue. 33 | */ 34 | clear(): void; 35 | private _executeNextCommand(); 36 | } 37 | -------------------------------------------------------------------------------- /src/utils/command-queue.ts: -------------------------------------------------------------------------------- 1 | import {Event} from './event' 2 | 3 | /** 4 | * TODO. 5 | */ 6 | export class CommandQueue { 7 | private _queue: Array<{ command: Function, execute: Function, reject: (reason: any) => void }> = []; 8 | private _currentCommand: Function | undefined; 9 | private _currentCommandPending: Promise | undefined; 10 | private _paused = true; 11 | 12 | /** 13 | * An error event. 14 | */ 15 | public errorEvent = new Event(); 16 | 17 | /** 18 | * If errorEvent has 1 listener, outputs the error message to the web console. 19 | */ 20 | constructor() { 21 | this.errorEvent.addEventListener((error) => { 22 | if (this.errorEvent.numberOfListeners === 1) console.error(error); 23 | }) 24 | } 25 | 26 | /** 27 | * Push a command to the command queue. 28 | * @param command Any command ready to be pushed into the command queue. 29 | */ 30 | public push(command: () => Promise|TResult, execute?: boolean): Promise { 31 | const result = new Promise((resolve, reject) => { 32 | this._queue.push({ 33 | command, 34 | reject, 35 | execute: () => { 36 | // console.log('CommandQueue: Executing command ' + command.toString()); 37 | const result = Promise.resolve().then(command); 38 | // result.then(() => { console.log('CommandQueue: DONE ' + command.toString()) }); 39 | resolve(result); 40 | return result; 41 | } 42 | }); 43 | }); 44 | if (execute || !this._paused) this.execute(); 45 | return result; 46 | } 47 | 48 | /** 49 | * Execute the command queue 50 | */ 51 | public execute() { 52 | this._paused = false; 53 | Promise.resolve().then(() => { 54 | if (this._queue.length > 0 && !this._currentCommandPending) { 55 | this._executeNextCommand(); 56 | } 57 | }); 58 | } 59 | 60 | /** 61 | * Puase the command queue (currently executing commands will still complete) 62 | */ 63 | public pause() { 64 | this._paused = true; 65 | } 66 | 67 | /** 68 | * Clear commandQueue. 69 | */ 70 | public clear() { 71 | this._queue.forEach((item) => { 72 | item.reject("Unable to execute.") 73 | }) 74 | this._queue = []; 75 | } 76 | 77 | private _executeNextCommand() { 78 | this._currentCommand = undefined; 79 | this._currentCommandPending = undefined; 80 | if (this._paused) return; 81 | const item = this._queue.shift(); 82 | if (!item) return; 83 | this._currentCommand = item.command; 84 | this._currentCommandPending = item.execute() 85 | .then(this._executeNextCommand.bind(this)) 86 | .catch((e) => { 87 | this.errorEvent.raiseEvent(e); 88 | this._executeNextCommand(); 89 | }); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/utils/event.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A callback for removing the event listener. 3 | */ 4 | export declare type RemoveCallback = () => void; 5 | /** 6 | * Provides the ability raise and subscribe to an event. 7 | */ 8 | export declare class Event { 9 | private _event; 10 | /** 11 | * Get the number of listeners currently subscribed to the event. 12 | * @return Number of listeners currently subscribed to the event. 13 | */ 14 | readonly numberOfListeners: number; 15 | /** 16 | * Add an event listener. 17 | * @param The function to be executed when the event is raised. 18 | * @return A convenience function which removes this event listener when called 19 | */ 20 | addEventListener: (listener: (data: T) => void) => RemoveCallback; 21 | /** 22 | * Remove an event listener. 23 | * @param The function to be unregistered. 24 | * @return True if the listener was removed; 25 | * false if the listener and scope are not registered with the event. 26 | */ 27 | removeEventListener: (listener: (data: T) => void) => boolean; 28 | /** 29 | * Raises the event by calling each registered listener with all supplied arguments. 30 | * @param This method takes any number of parameters and passes them through to the listener functions. 31 | */ 32 | raiseEvent: (data: T) => void; 33 | } 34 | -------------------------------------------------------------------------------- /src/utils/event.ts: -------------------------------------------------------------------------------- 1 | import CesiumEvent from 'cesium/Source/Core/Event'; 2 | 3 | /** 4 | * A callback for removing the event listener. 5 | */ 6 | export type RemoveCallback = () => void; 7 | 8 | /** 9 | * Provides the ability raise and subscribe to an event. 10 | */ 11 | export class Event { 12 | 13 | private _event = new CesiumEvent(); 14 | /** 15 | * Get the number of listeners currently subscribed to the event. 16 | * @return Number of listeners currently subscribed to the event. 17 | */ 18 | get numberOfListeners() { 19 | return this._event.numberOfListeners; 20 | } 21 | 22 | /** 23 | * Add an event listener. 24 | * @param The function to be executed when the event is raised. 25 | * @return A convenience function which removes this event listener when called 26 | */ 27 | addEventListener: (listener: (data: T) => void) => RemoveCallback = 28 | this._event.addEventListener.bind(this._event); 29 | 30 | /** 31 | * Remove an event listener. 32 | * @param The function to be unregistered. 33 | * @return True if the listener was removed; 34 | * false if the listener and scope are not registered with the event. 35 | */ 36 | removeEventListener: (listener: (data: T) => void) => boolean = 37 | this._event.removeEventListener.bind(this._event); 38 | 39 | /** 40 | * Raises the event by calling each registered listener with all supplied arguments. 41 | * @param This method takes any number of parameters and passes them through to the listener functions. 42 | */ 43 | raiseEvent: (data: T) => void = 44 | this._event.raiseEvent.bind(this._event); 45 | 46 | } -------------------------------------------------------------------------------- /src/utils/message-channel.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A minimal MessageEvent interface. 3 | */ 4 | export declare class MessageEventLike { 5 | constructor(data: any); 6 | data: any; 7 | } 8 | /** 9 | * A minimal MessagePort interface. 10 | */ 11 | export interface MessagePortLike { 12 | /** 13 | * A callback for handling incoming messages. 14 | */ 15 | onmessage?: (ev: MessageEventLike) => any; 16 | /** 17 | * Send a message through this message port. 18 | * @param message The message needed to be posted. 19 | */ 20 | postMessage(message: any): void; 21 | /** 22 | * Close this message port. 23 | */ 24 | close?: () => void; 25 | } 26 | /** 27 | * A MessageChannel pollyfill. 28 | */ 29 | export declare class MessageChannelLike { 30 | /** 31 | * The first port. 32 | */ 33 | port1: MessagePortLike; 34 | /** 35 | * The second port. 36 | */ 37 | port2: MessagePortLike; 38 | /** 39 | * Create a MessageChannelLike instance. 40 | */ 41 | constructor(); 42 | } 43 | /** 44 | * A synchronous MessageChannel. 45 | */ 46 | export declare class SynchronousMessageChannel { 47 | /** 48 | * The first port. 49 | */ 50 | port1: MessagePortLike; 51 | /** 52 | * The second port. 53 | */ 54 | port2: MessagePortLike; 55 | /** 56 | * Create a MessageChannelLike instance. 57 | */ 58 | constructor(); 59 | } 60 | /** 61 | * A factory which creates MessageChannel or MessageChannelLike instances, depending on 62 | * wheter or not MessageChannel is avaialble in the execution context. 63 | */ 64 | export declare class MessageChannelFactory { 65 | /** 66 | * Create a MessageChannel (or MessageChannelLike) instance. 67 | */ 68 | create(): MessageChannelLike; 69 | /** 70 | * Create a SynchronousMessageChannel instance. 71 | */ 72 | createSynchronous(): SynchronousMessageChannel; 73 | } 74 | -------------------------------------------------------------------------------- /src/utils/message-channel.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * A minimal MessageEvent interface. 4 | */ 5 | export declare class MessageEventLike { 6 | constructor(data: any); 7 | data: any; 8 | } 9 | 10 | /** 11 | * A minimal MessagePort interface. 12 | */ 13 | export interface MessagePortLike { 14 | 15 | /** 16 | * A callback for handling incoming messages. 17 | */ 18 | onmessage?: (ev: MessageEventLike) => any; 19 | 20 | /** 21 | * Send a message through this message port. 22 | * @param message The message needed to be posted. 23 | */ 24 | postMessage(message: any): void; 25 | 26 | /** 27 | * Close this message port. 28 | */ 29 | close?: () => void; 30 | } 31 | 32 | /** 33 | * A MessageChannel pollyfill. 34 | */ 35 | export class MessageChannelLike { 36 | 37 | /** 38 | * The first port. 39 | */ 40 | public port1: MessagePortLike; 41 | 42 | /** 43 | * The second port. 44 | */ 45 | public port2: MessagePortLike; 46 | 47 | /** 48 | * Create a MessageChannelLike instance. 49 | */ 50 | constructor() { 51 | const messageChannel = this; 52 | let _portsOpen = true; 53 | 54 | let _port1ready: Promise<{}>; 55 | let _port2ready: Promise<{}>; 56 | 57 | let _port1onmessage: (messageEvent: MessageEventLike) => void; 58 | _port1ready = new Promise((resolve) => { 59 | messageChannel.port1 = { 60 | set onmessage(func) { 61 | _port1onmessage = func; 62 | resolve(); 63 | }, 64 | get onmessage() { 65 | return _port1onmessage; 66 | }, 67 | postMessage(data: any) { 68 | if (_portsOpen) { 69 | _port2ready.then(() => { 70 | if (messageChannel.port2.onmessage) 71 | messageChannel.port2.onmessage({ data }); 72 | }) 73 | } 74 | }, 75 | close() { 76 | _portsOpen = false; 77 | } 78 | } 79 | }); 80 | 81 | let _port2onmessage: (messageEvent: MessageEventLike) => void; 82 | _port2ready = new Promise((resolve) => { 83 | messageChannel.port2 = { 84 | set onmessage(func) { 85 | _port2onmessage = func; 86 | resolve(); 87 | }, 88 | get onmessage() { 89 | return _port2onmessage; 90 | }, 91 | postMessage(data: any) { 92 | if (_portsOpen) { 93 | _port1ready.then(() => { 94 | if (messageChannel.port1.onmessage) 95 | messageChannel.port1.onmessage({ data }); 96 | }) 97 | } 98 | }, 99 | close() { 100 | _portsOpen = false; 101 | } 102 | } 103 | }); 104 | 105 | } 106 | } 107 | 108 | 109 | /** 110 | * A synchronous MessageChannel. 111 | */ 112 | export class SynchronousMessageChannel { 113 | 114 | /** 115 | * The first port. 116 | */ 117 | public port1: MessagePortLike; 118 | 119 | /** 120 | * The second port. 121 | */ 122 | public port2: MessagePortLike; 123 | 124 | /** 125 | * Create a MessageChannelLike instance. 126 | */ 127 | constructor() { 128 | const messageChannel = this; 129 | 130 | let pendingMessages1: any[] = [] 131 | let onmessage1 = function(message) { 132 | pendingMessages1.push(message); 133 | } 134 | messageChannel.port1 = { 135 | get onmessage() { return onmessage1 }, 136 | set onmessage(func) { 137 | setTimeout(()=>{ 138 | onmessage1 = func; 139 | pendingMessages1.forEach((data) => func(data)) 140 | pendingMessages1 = []; 141 | },0); 142 | }, 143 | postMessage(data: any) { 144 | if (messageChannel.port2.onmessage) 145 | messageChannel.port2.onmessage({ data }); 146 | }, 147 | close() { 148 | messageChannel.port1.onmessage = undefined; 149 | messageChannel.port2.onmessage = undefined; 150 | } 151 | } 152 | 153 | let pendingMessages2: any[] = [] 154 | let onmessage2 = function(message) { 155 | pendingMessages2.push(message); 156 | } 157 | messageChannel.port2 = { 158 | get onmessage() { return onmessage2 }, 159 | set onmessage(func) { 160 | onmessage2 = func; 161 | pendingMessages2.forEach((data) => func(data)) 162 | pendingMessages2 = []; 163 | }, 164 | postMessage(data: any) { 165 | if (messageChannel.port1.onmessage) 166 | messageChannel.port1.onmessage({ data }); 167 | }, 168 | close() { 169 | messageChannel.port1.onmessage = undefined; 170 | messageChannel.port2.onmessage = undefined; 171 | } 172 | } 173 | } 174 | } 175 | 176 | /** 177 | * A factory which creates MessageChannel or MessageChannelLike instances, depending on 178 | * wheter or not MessageChannel is avaialble in the execution context. 179 | */ 180 | export class MessageChannelFactory { 181 | 182 | /** 183 | * Create a MessageChannel (or MessageChannelLike) instance. 184 | */ 185 | public create(): MessageChannelLike { 186 | if (typeof MessageChannel !== 'undefined') return new MessageChannel() 187 | else return new MessageChannelLike(); 188 | } 189 | 190 | /** 191 | * Create a SynchronousMessageChannel instance. 192 | */ 193 | public createSynchronous(): SynchronousMessageChannel { 194 | return new SynchronousMessageChannel() 195 | } 196 | } -------------------------------------------------------------------------------- /src/utils/ui-event-forwarder.d.ts: -------------------------------------------------------------------------------- 1 | import { ViewService } from '../view'; 2 | export default function createEventForwarder(this: void, viewService: ViewService, callback: (uievent: UIEvent) => void): void; 3 | -------------------------------------------------------------------------------- /src/utils/ui-event-forwarder.ts: -------------------------------------------------------------------------------- 1 | // import { FeatureDetection } from '../cesium/cesium-imports' 2 | import { ViewService } from '../view' 3 | import { isIOS } from '../utils' 4 | 5 | const cloneTouch = (touch:Touch, boundingRect:ClientRect) => { 6 | return { 7 | identifier: touch.identifier, 8 | clientX: touch.clientX - boundingRect.left, 9 | clientY: touch.clientY - boundingRect.top, 10 | screenX: touch.screenX, 11 | screenY: touch.screenY 12 | }; 13 | } 14 | 15 | const cloneTouches = (touches:TouchList, boundingRect:ClientRect) => { 16 | if (!touches) return undefined; 17 | const touchList:any = []; 18 | for (var i = 0; i < touches.length; i++) { 19 | const touch = touches.item(i)!; 20 | touchList[i] = cloneTouch(touch, boundingRect); 21 | } 22 | return touchList; 23 | } 24 | 25 | export default function createEventForwarder(this:void, viewService:ViewService, callback:(uievent:UIEvent)=>void) { 26 | 27 | let forwardEvent = false; 28 | 29 | const eventData = { 30 | event:UIEvent = undefined, 31 | forwardEvent: () => { forwardEvent = true } 32 | } 33 | 34 | const uievent = {}; 35 | 36 | const handleEvent = (e:MouseEvent&WheelEvent&TouchEvent&PointerEvent)=>{ 37 | const target = e.target instanceof HTMLElement ? e.target : undefined; 38 | const width = target && target.clientWidth; 39 | const height = target && target.clientHeight; 40 | 41 | // prevent undesired default actions over the view element 42 | if (e.type === 'wheel' || 43 | isIOS && e.type === 'touchmove' && e.touches.length === 2) 44 | e.preventDefault(); 45 | 46 | // contain our events within the view element 47 | e.stopPropagation(); 48 | 49 | // if the target element is the view element or an element of similar size, 50 | // attempt to forward the event (webvr-polyfill makes the canvas 10px larger 51 | // in each dimension due to an issue with the iOS safari browser, which is why 52 | // we forward the event for any target that matches the viewport size up to 15px 53 | // larger in either dimension) 54 | if (e.target === viewService.element || 55 | (width && Math.abs(width - viewService.element.clientWidth) < 15 && 56 | height && Math.abs(height - viewService.element.clientHeight) < 15)) { 57 | 58 | // If we have a uievent listener attached, then make sure the 59 | // app explictily asks for events to be forwarded. Otherwise, 60 | // automatically forward the uievents 61 | if (viewService.uiEvent.numberOfListeners > 0) { 62 | forwardEvent = false; 63 | eventData.event = e; 64 | viewService.uiEvent.raiseEvent(eventData); 65 | if (!forwardEvent) { 66 | // if the app doesn't want to forward the event, 67 | // stop the event propogation immediately so that even a locally-running 68 | // reality viewer cannot process the event 69 | e.stopImmediatePropagation(); 70 | return; 71 | } 72 | } 73 | 74 | // prevent undesired synthetic click 75 | if (e.type === 'touchstart') 76 | e.preventDefault(); 77 | 78 | const boundingRect = viewService.element.getBoundingClientRect(); 79 | const touches = cloneTouches(e.touches, boundingRect); 80 | const changedTouches = cloneTouches(e.changedTouches, boundingRect); 81 | const targetTouches = cloneTouches(e.targetTouches, boundingRect); 82 | 83 | // Event / UI Event 84 | uievent.timeStamp = e.timeStamp; 85 | uievent.type = e.type; 86 | uievent.bubbles = e.bubbles; 87 | uievent.cancelable = e.cancelable; 88 | uievent.which = e.which; 89 | uievent.detail = e.detail; 90 | uievent.composed = e['composed']; 91 | uievent.timeStamp = e.timeStamp; 92 | 93 | // Mouse Event 94 | uievent.altKey = e.altKey; 95 | uievent.ctrlKey = e.ctrlKey; 96 | uievent.metaKey = e.metaKey; 97 | uievent.button = e.button; 98 | uievent.buttons = e.buttons; 99 | uievent.clientX = e.clientX - boundingRect.left; 100 | uievent.clientY = e.clientY - boundingRect.top; 101 | uievent.screenX = e.screenX; 102 | uievent.screenY = e.screenY; 103 | uievent.movementX = e.movementX; 104 | uievent.movementY = e.movementY; 105 | 106 | // Wheel Event 107 | uievent.deltaX = e.deltaX; 108 | uievent.deltaY = e.deltaY; 109 | uievent.deltaZ = e.deltaZ; 110 | uievent.deltaMode = e.deltaMode; 111 | uievent.wheelDelta = e.wheelDelta; 112 | uievent.wheelDeltaX = e.wheelDeltaX; 113 | uievent.wheelDeltaY = e.wheelDeltaY; 114 | 115 | // Touch Event 116 | uievent.touches = touches; 117 | uievent.changedTouches = changedTouches; 118 | uievent.targetTouches = targetTouches; 119 | 120 | // Pointer Events 121 | uievent.pointerId = e.pointerId; 122 | uievent.pointerType = e.pointerType; 123 | uievent.width = e.width; 124 | uievent.height = e.height; 125 | uievent.pressure = e.pressure; 126 | uievent.tiltX = e.tiltX; 127 | uievent.tiltY = e.tiltY; 128 | uievent.isPrimary = e.isPrimary; 129 | 130 | callback(uievent); 131 | } else { 132 | // if this event is not forwardable, stop propogation immediately 133 | e.stopImmediatePropagation(); 134 | } 135 | }; 136 | 137 | const forwardedEvent = [ 138 | 'wheel' 139 | ,'click' 140 | ,'dblclick' 141 | ,'contextmenu' 142 | ]; 143 | 144 | // if (FeatureDetection.supportsPointerEvents()) { 145 | forwardedEvent.push( 146 | 'pointerenter' 147 | ,'pointerleave' 148 | ,'pointerdown' 149 | ,'pointermove' 150 | ,'pointerup' 151 | ,'pointercancel' 152 | ); 153 | // } else { 154 | forwardedEvent.push( 155 | 'mouseenter' 156 | ,'mouseleave' 157 | ,'mousedown' 158 | ,'mousemove' 159 | ,'mouseup' 160 | ,'touchstart' 161 | ,'touchend' 162 | ,'touchmove' 163 | ,'touchcancel' 164 | ); 165 | // } 166 | 167 | forwardedEvent.forEach((type)=>{ 168 | viewService.element.addEventListener(type, handleEvent, false); 169 | }); 170 | } -------------------------------------------------------------------------------- /src/utils/ui-event-synthesizer.d.ts: -------------------------------------------------------------------------------- 1 | declare const _default: (() => (uievent: UIEvent) => void) | (() => undefined); 2 | export default _default; 3 | -------------------------------------------------------------------------------- /src/view.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { CanvasViewport, Viewport, ContextFrameState, SubviewType } from './common'; 3 | import { SessionService, SessionPort } from './session'; 4 | import { ContextService } from './context'; 5 | import { EntityPose } from './entity'; 6 | import { PerspectiveFrustum } from './cesium/cesium-imports'; 7 | import { Event } from './utils'; 8 | import { FocusService, FocusServiceProvider } from './focus'; 9 | import { VisibilityServiceProvider } from './visibility'; 10 | /** 11 | * The rendering paramters for a particular subview 12 | */ 13 | export declare class Subview { 14 | index: number; 15 | type: SubviewType; 16 | frustum: PerspectiveFrustum; 17 | pose: EntityPose; 18 | viewport: Viewport; 19 | renderViewport: Viewport; 20 | } 21 | export declare const enum ViewportMode { 22 | EMBEDDED = 0, 23 | PAGE = 0, 24 | IMMERSIVE = 1, 25 | } 26 | export declare class ViewItems { 27 | element?: HTMLElement; 28 | layers?: { 29 | source: HTMLElement; 30 | }[]; 31 | } 32 | /** 33 | * Manages the view state 34 | */ 35 | export declare class ViewService { 36 | private sessionService; 37 | private focusService; 38 | private viewItems; 39 | /** 40 | * UI events that occur within this view. To handle an event (and prevent it from 41 | * being forwarded to another layer) call event.stopImmediatePropagation(). 42 | */ 43 | uiEvent: Event<{ 44 | event: UIEvent | MouseEvent | PointerEvent | WheelEvent | TouchEvent; 45 | forwardEvent: () => void; 46 | }>; 47 | /** 48 | * An event that is raised when the viewport has changed 49 | */ 50 | viewportChangeEvent: Event; 51 | /** 52 | * An event that is raised when the viewport mode has changed 53 | */ 54 | viewportModeChangeEvent: Event; 55 | /** 56 | * The current viewport mode 57 | */ 58 | readonly viewportMode: ViewportMode; 59 | private _mode; 60 | protected readonly presentationMode: ViewportMode; 61 | /** 62 | * The current viewport 63 | */ 64 | readonly viewport: Viewport; 65 | private _viewport; 66 | /** 67 | * The width which should be used for the render buffer 68 | */ 69 | readonly renderWidth: number; 70 | private _renderWidth; 71 | /** 72 | * The height which should be used for the render buffer 73 | */ 74 | readonly renderHeight: number; 75 | private _renderHeight; 76 | getViewport(): Viewport; 77 | /** 78 | * Automatically layout the element to match the immersive viewport during PresentationMode.IMMERSIVE 79 | */ 80 | autoLayoutImmersiveMode: boolean; 81 | /** 82 | * Automatically style layer elements 83 | */ 84 | autoStyleLayerElements: boolean; 85 | /** 86 | * Automatically publish the viewport of the element during PresentationMode.EMBEDDED 87 | */ 88 | autoPublishEmbeddedMode: boolean; 89 | constructor(sessionService: SessionService, focusService: FocusService, viewItems: ViewItems); 90 | setLayers(layers: { 91 | source: HTMLElement; 92 | }[]): void; 93 | /** 94 | * The DOM element associated with this view 95 | */ 96 | readonly element: HTMLElement; 97 | /** 98 | * The layers composing this view. 99 | */ 100 | readonly layers: { 101 | source: HTMLElement; 102 | }[] | undefined; 103 | private _currentViewportJSON; 104 | private _subviews; 105 | private _subviewFrustum; 106 | readonly subviews: Subview[]; 107 | /** 108 | * @private 109 | */ 110 | protected getSubviews(): Subview[]; 111 | _processContextFrameState(state: ContextFrameState, contextService: ContextService): void; 112 | requestPresentationMode(mode: ViewportMode): Promise; 113 | private _desiredViewportMode; 114 | desiredViewportMode: ViewportMode; 115 | private _updateViewportMode(mode); 116 | /** 117 | * Publish the viewport being used in [[PresentationMode.EMBEDDED]] 118 | * so that the manager knows what our embedded viewport is 119 | */ 120 | publishEmbeddedViewport(viewport?: Viewport): void; 121 | private _updateViewport(viewport); 122 | sendUIEventToSession(uievent: UIEvent, session?: SessionPort): void; 123 | private _embeddedViewport; 124 | /** 125 | * @private 126 | */ 127 | _watchEmbeddedViewport(): void; 128 | } 129 | export declare class ViewServiceProvider { 130 | private sessionService; 131 | private viewService; 132 | private focusServiceProvider; 133 | sessionViewportMode: WeakMap; 134 | /** 135 | * The embedded viewports for each managed session. 136 | */ 137 | sessionEmbeddedViewport: WeakMap; 138 | /** 139 | * A UI event being forwarded from a managed session 140 | */ 141 | forwardedUIEvent: Event; 142 | constructor(sessionService: SessionService, viewService: ViewService, focusServiceProvider: FocusServiceProvider, visibilityServiceProvider: VisibilityServiceProvider); 143 | sendUIEventToSession(uievent: UIEvent, session: SessionPort): void; 144 | private _publishViewportModes(); 145 | } 146 | -------------------------------------------------------------------------------- /src/visibility.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService, SessionPort } from './session'; 2 | import { Event } from './utils'; 3 | /** 4 | * Access visibility state 5 | */ 6 | export declare class VisibilityService { 7 | /** 8 | * An event that is raised when the app becomes visible 9 | */ 10 | showEvent: Event; 11 | /** 12 | * An event that is raised when the app becomes hidden 13 | */ 14 | hideEvent: Event; 15 | /** 16 | * True if this app has focus 17 | */ 18 | readonly isVisible: boolean; 19 | private _isVisible; 20 | constructor(sessionService: SessionService); 21 | } 22 | /** 23 | * Manage visibility state 24 | */ 25 | export declare class VisibilityServiceProvider { 26 | visibleSessions: Set; 27 | sessionChangeEvent: Event; 28 | constructor(sessionService: SessionService); 29 | set(session: SessionPort, visibility: boolean): void; 30 | } 31 | -------------------------------------------------------------------------------- /src/visibility.ts: -------------------------------------------------------------------------------- 1 | import { inject } from 'aurelia-dependency-injection'; 2 | import { SessionService, SessionPort } from './session'; 3 | import { Event } from './utils'; 4 | 5 | /** 6 | * Access visibility state 7 | */ 8 | @inject(SessionService) 9 | export class VisibilityService { 10 | 11 | /** 12 | * An event that is raised when the app becomes visible 13 | */ 14 | public showEvent = new Event(); 15 | 16 | /** 17 | * An event that is raised when the app becomes hidden 18 | */ 19 | public hideEvent = new Event(); 20 | 21 | /** 22 | * True if this app has focus 23 | */ 24 | public get isVisible() { return this._isVisible } 25 | private _isVisible = false; 26 | 27 | constructor(sessionService: SessionService) { 28 | sessionService.manager.on['ar.visibility.state'] = ({state}: { state: boolean }) => { 29 | if (this._isVisible !== state) { 30 | this._isVisible = state; 31 | if (state) this.showEvent.raiseEvent(undefined); 32 | else this.hideEvent.raiseEvent(undefined) 33 | } 34 | } 35 | 36 | sessionService.manager.closeEvent.addEventListener(()=>{ 37 | if (this._isVisible) { 38 | this._isVisible = false; 39 | this.hideEvent.raiseEvent(undefined); 40 | } 41 | }) 42 | 43 | // if running in an old manager, assume we are visible 44 | sessionService.manager.connectEvent.addEventListener(()=>{ 45 | if (sessionService.manager.version[0] === 0) { 46 | this._isVisible = true; 47 | this.showEvent.raiseEvent(undefined); 48 | } 49 | }) 50 | } 51 | 52 | } 53 | 54 | 55 | /** 56 | * Manage visibility state 57 | */ 58 | @inject(SessionService, VisibilityService) 59 | export class VisibilityServiceProvider { 60 | 61 | public visibleSessions = new Set(); 62 | public sessionChangeEvent = new Event(); 63 | 64 | constructor(sessionService: SessionService) { 65 | sessionService.ensureIsRealityManager(); 66 | 67 | this.sessionChangeEvent.addEventListener((session)=>{ 68 | session.send('ar.visibility.state', {state: this.visibleSessions.has(session)}); 69 | }); 70 | 71 | sessionService.manager.connectEvent.addEventListener(()=>{ 72 | this.set(sessionService.manager, true); 73 | }); 74 | } 75 | 76 | set(session:SessionPort, visibility:boolean) { 77 | if (visibility) { 78 | if (!this.visibleSessions.has(session)) { 79 | this.visibleSessions.add(session); 80 | this.sessionChangeEvent.raiseEvent(session); 81 | } 82 | } else { 83 | if (this.visibleSessions.has(session)) { 84 | this.visibleSessions.delete(session); 85 | this.sessionChangeEvent.raiseEvent(session); 86 | } 87 | } 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /src/vuforia.d.ts: -------------------------------------------------------------------------------- 1 | import { SessionService, SessionPort } from './session'; 2 | import { Event } from './utils'; 3 | /** 4 | * A service which handles requests from a VuforiaService 5 | */ 6 | export declare abstract class VuforiaServiceProvider { 7 | constructor(sessionService: SessionService); 8 | } 9 | /** 10 | * Enum for the setHint function 11 | */ 12 | export declare enum VuforiaHint { 13 | MaxSimultaneousImageTargets = 0, 14 | MaxSimultaneousObjectTargets = 1, 15 | DelayedLoadingObjectDatasets = 2, 16 | } 17 | /** 18 | * A service for interacting with the Vuforia API 19 | */ 20 | export declare class VuforiaService { 21 | private sessionService; 22 | constructor(sessionService: SessionService); 23 | /** 24 | * Resolves to a boolean indicating whether or not the Vuforia API is available on this system 25 | */ 26 | isAvailable(): Promise; 27 | /** 28 | * Initialize vuforia using an encrypted license. 29 | * You can get a vuforia license key from https://developer.vuforia.com/ 30 | * You can encrypt your vuforia license with the tool at http://docs.argonjs.io/start/vuforia-pgp-encryptor 31 | */ 32 | init(options: string | { 33 | encryptedLicenseData: string; 34 | }): Promise; 35 | /** 36 | * Initialize vuforia with an unecrypted key. 37 | * It's a bad idea to publish your unencrypted vuforia key on the internet. 38 | * @private 39 | */ 40 | initWithUnencryptedKey(options: string | { 41 | key: string; 42 | }): Promise; 43 | } 44 | export declare class VuforiaAPI { 45 | private manager; 46 | constructor(manager: SessionPort); 47 | objectTracker: VuforiaObjectTracker; 48 | setHint(hint: VuforiaHint, value: number): Promise; 49 | } 50 | export declare abstract class VuforiaTracker { 51 | constructor(); 52 | } 53 | export declare type VuforiaDataSetId = string; 54 | export interface VuforiaDataSetEvent { 55 | id: VuforiaDataSetId; 56 | } 57 | export interface VuforiaDataSetLoadEvent extends VuforiaDataSetEvent { 58 | id: VuforiaDataSetId; 59 | trackables: VuforiaTrackables; 60 | } 61 | /** 62 | * Vuforia Object Tracker 63 | */ 64 | export declare class VuforiaObjectTracker extends VuforiaTracker { 65 | private managerSession; 66 | dataSetLoadEvent: Event; 67 | dataSetUnloadEvent: Event; 68 | dataSetActivateEvent: Event; 69 | dataSetDeactivateEvent: Event; 70 | constructor(managerSession: SessionPort); 71 | private _deprecatedDataSetInstanceMap; 72 | /** 73 | * Deprecated. Please use createDataSetFromURI instead. 74 | * @deprecated To be removed. 75 | */ 76 | createDataSet(url?: string): Promise; 77 | /** 78 | * Fetch a dataset from the provided url. 79 | * If successfull, resolves to an id which represents the dataset. 80 | */ 81 | createDataSetFromURL(url: string): Promise; 82 | readonly createDataSetFromURI: (url: string) => Promise; 83 | /** 84 | * Load the dataset into memory, and return a promise which 85 | * resolves to the contained trackables 86 | */ 87 | loadDataSet(id: VuforiaDataSetId): Promise; 88 | /** 89 | * Unload a dataset from memory (deactivating it if necessary) 90 | */ 91 | unloadDataSet(id: VuforiaDataSetId): Promise; 92 | /** 93 | * Load (if necessary) and activate a dataset to enable tracking of the contained trackables 94 | */ 95 | activateDataSet(id: VuforiaDataSetId | DeprecatedVuforiaDataSet): Promise; 96 | /** 97 | * Deactivate a loaded dataset to disable tracking of the contained trackables 98 | */ 99 | deactivateDataSet(id: VuforiaDataSetId | DeprecatedVuforiaDataSet): Promise; 100 | } 101 | /** 102 | * A map from names of trackable data sets to their ids, names, and sizes TODO 103 | */ 104 | export interface VuforiaTrackables { 105 | [name: string]: { 106 | id: string; 107 | size?: { 108 | x: number; 109 | y: number; 110 | z: number; 111 | }; 112 | }; 113 | } 114 | /** 115 | * @deprecated To be removed. 116 | */ 117 | export declare class DeprecatedVuforiaDataSet { 118 | id: string; 119 | private managerSession; 120 | private _isActive; 121 | private _trackables; 122 | constructor(id: string, managerSession: SessionPort); 123 | _onActivate(): void; 124 | _onDeactivate(): void; 125 | fetch(): Promise; 126 | load(): Promise; 127 | isActive(): boolean; 128 | getTrackables(): VuforiaTrackables; 129 | } 130 | -------------------------------------------------------------------------------- /src/webvr.d.ts: -------------------------------------------------------------------------------- 1 | import 'googlevr/webvr-polyfill/src/main'; 2 | -------------------------------------------------------------------------------- /src/webvr.ts: -------------------------------------------------------------------------------- 1 | import CardboardUI from 'googlevr/webvr-polyfill/src/cardboard-ui'; 2 | import 'googlevr/webvr-polyfill/src/main'; 3 | 4 | // fix cardboard ui to listen for touch or mouse events. 5 | // see https://github.com/googlevr/webvr-polyfill/issues/174 6 | var kButtonWidthDp = 28; 7 | var kTouchSlopFactor = 1.5; 8 | CardboardUI.prototype.listen = function(optionsCallback, backCallback) { 9 | var canvas = this.gl.canvas; 10 | var hasTouchEventClass = typeof TouchEvent !== 'undefined'; 11 | this.listener = function(event:MouseEvent|TouchEvent) { 12 | var midline = canvas.clientWidth / 2; 13 | var buttonSize = kButtonWidthDp * kTouchSlopFactor; 14 | var e:MouseEvent|Touch = hasTouchEventClass && event instanceof TouchEvent ? 15 | event.changedTouches[0] : 16 | event; 17 | // Check to see if the user clicked on (or around) the gear icon 18 | if (e.clientX > midline - buttonSize && 19 | e.clientX < midline + buttonSize && 20 | e.clientY > canvas.clientHeight - buttonSize) { 21 | event.preventDefault(); 22 | event.stopImmediatePropagation(); 23 | optionsCallback(event); 24 | } 25 | // Check to see if the user clicked on (or around) the back icon 26 | else if (e.clientX < buttonSize && e.clientY < buttonSize) { 27 | event.preventDefault(); 28 | event.stopImmediatePropagation(); 29 | backCallback(event); 30 | } 31 | }; 32 | canvas.addEventListener('click', this.listener, false); 33 | canvas.addEventListener('touchstart', this.listener, false); // for some reason, using `touchend` here breaks touch events in parent DOM elements, whereas touchstart works fine.... seems like a bug in WebKit 34 | }; -------------------------------------------------------------------------------- /test/app/custom_reality.d.ts: -------------------------------------------------------------------------------- 1 | import * as Argon from '../../src/argon'; 2 | export declare const app: Argon.ArgonSystem; 3 | export declare const scene: any; 4 | export declare const camera: any; 5 | export declare const user: any; 6 | export declare const userLocation: any; 7 | export declare const posXSphere: any; 8 | export declare const negXSphere: any; 9 | export declare const posYSphere: any; 10 | export declare const negYSphere: any; 11 | export declare const posZSphere: any; 12 | export declare const negZSphere: any; 13 | -------------------------------------------------------------------------------- /test/app/custom_reality.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 | 23 | 24 | -------------------------------------------------------------------------------- /test/app/custom_reality.js: -------------------------------------------------------------------------------- 1 | // import * as Argon from 'argon' 2 | import * as Argon from '../../src/argon'; 3 | window['Argon'] = Argon; 4 | export var app = Argon.initRealityViewer(); 5 | export var scene = new THREE.Scene(); 6 | export var camera = new THREE.PerspectiveCamera(); 7 | export var user = new THREE.Object3D(); 8 | export var userLocation = new THREE.Object3D; 9 | scene.add(camera); 10 | scene.add(user); 11 | scene.add(userLocation); 12 | var renderer = new THREE.WebGLRenderer({ 13 | alpha: true, 14 | logarithmicDepthBuffer: true, 15 | antialias: Argon.suggestedWebGLContextAntialiasAttribute 16 | }); 17 | renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); 18 | app.view.element.appendChild(renderer.domElement); 19 | // app.context.defaultReferenceFrame = app.context.localOriginEastUpSouth; 20 | app.context.defaultReferenceFrame = app.context.localOriginEastNorthUp; 21 | var geometry = new THREE.SphereGeometry(30, 32, 32); 22 | var mat = new THREE.MeshBasicMaterial({ color: 0xff0000 }); 23 | export var posXSphere = new THREE.Mesh(geometry, mat); 24 | posXSphere.position.x = 200; 25 | userLocation.add(posXSphere); 26 | mat = new THREE.MeshBasicMaterial({ color: 0xffaaaa }); 27 | export var negXSphere = new THREE.Mesh(geometry, mat); 28 | negXSphere.position.x = -200; 29 | userLocation.add(negXSphere); 30 | mat = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); 31 | export var posYSphere = new THREE.Mesh(geometry, mat); 32 | posYSphere.position.y = 200; 33 | userLocation.add(posYSphere); 34 | mat = new THREE.MeshBasicMaterial({ color: 0xaaffaa }); 35 | export var negYSphere = new THREE.Mesh(geometry, mat); 36 | negYSphere.position.y = -200; 37 | userLocation.add(negYSphere); 38 | mat = new THREE.MeshBasicMaterial({ color: 0x0000ff }); 39 | export var posZSphere = new THREE.Mesh(geometry, mat); 40 | posZSphere.position.z = 200; 41 | userLocation.add(posZSphere); 42 | mat = new THREE.MeshBasicMaterial({ color: 0xaaaaff }); 43 | export var negZSphere = new THREE.Mesh(geometry, mat); 44 | negZSphere.position.z = -200; 45 | userLocation.add(negZSphere); 46 | var axisHelper = new THREE.AxisHelper(10); 47 | userLocation.add(axisHelper); 48 | axisHelper.position.z = 50; 49 | var axisHelper = new THREE.AxisHelper(10); 50 | userLocation.add(axisHelper); 51 | axisHelper.position.y = -50; 52 | var perspectiveProjection = new Argon.Cesium.PerspectiveFrustum(); 53 | perspectiveProjection.fov = Math.PI / 2; 54 | var processFrameState = function (suggestedFrameState) { 55 | var frameState = app.device.createContextFrameState(suggestedFrameState.time, suggestedFrameState.viewport, suggestedFrameState.subviews, app.context.user); 56 | app.context.submitFrameState(frameState); 57 | }; 58 | app.device.frameStateEvent.addEventListener(processFrameState); 59 | app.updateEvent.addEventListener(function () { 60 | var userPose = app.context.getEntityPose(app.context.user); 61 | if (userPose.status & Argon.PoseStatus.KNOWN) { 62 | user.position.copy(userPose.position); 63 | user.quaternion.copy(userPose.orientation); 64 | userLocation.position.copy(userPose.position); 65 | } 66 | }); 67 | app.renderEvent.addEventListener(function () { 68 | var viewport = app.view.viewport; 69 | renderer.setSize(viewport.width, viewport.height); 70 | renderer.setPixelRatio(app.suggestedPixelRatio); 71 | for (var _i = 0, _a = app.view.subviews; _i < _a.length; _i++) { 72 | var subview = _a[_i]; 73 | camera.position.copy(subview.pose.position); 74 | camera.quaternion.copy(subview.pose.orientation); 75 | camera.projectionMatrix.fromArray(subview.frustum.projectionMatrix); 76 | var _b = subview.viewport, x = _b.x, y = _b.y, width = _b.width, height = _b.height; 77 | renderer.setViewport(x, y, width, height); 78 | renderer.setScissor(x, y, width, height); 79 | renderer.setScissorTest(true); 80 | renderer.render(scene, camera); 81 | } 82 | }); 83 | -------------------------------------------------------------------------------- /test/app/custom_reality.ts: -------------------------------------------------------------------------------- 1 | // import * as Argon from 'argon' 2 | import * as Argon from '../../src/argon' 3 | 4 | declare const THREE: any; 5 | 6 | window['Argon'] = Argon; 7 | 8 | export const app = Argon.initRealityViewer(); 9 | 10 | export const scene = new THREE.Scene(); 11 | export const camera = new THREE.PerspectiveCamera(); 12 | export const user = new THREE.Object3D(); 13 | export const userLocation = new THREE.Object3D; 14 | scene.add(camera); 15 | scene.add(user); 16 | scene.add(userLocation); 17 | 18 | const renderer = new THREE.WebGLRenderer({ 19 | alpha: true, 20 | logarithmicDepthBuffer: true, 21 | antialias: Argon.suggestedWebGLContextAntialiasAttribute 22 | }); 23 | renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); 24 | app.view.element.appendChild(renderer.domElement); 25 | 26 | // app.context.defaultReferenceFrame = app.context.localOriginEastUpSouth; 27 | app.context.defaultReferenceFrame = app.context.localOriginEastNorthUp; 28 | 29 | const geometry = new THREE.SphereGeometry( 30, 32, 32 ); 30 | 31 | let mat = new THREE.MeshBasicMaterial( {color: 0xff0000} ); 32 | 33 | export const posXSphere = new THREE.Mesh( geometry, mat ); 34 | posXSphere.position.x = 200; 35 | userLocation.add( posXSphere ); 36 | 37 | mat = new THREE.MeshBasicMaterial( {color: 0xffaaaa} ); 38 | 39 | export const negXSphere = new THREE.Mesh( geometry, mat ); 40 | negXSphere.position.x = -200; 41 | userLocation.add( negXSphere ); 42 | 43 | mat = new THREE.MeshBasicMaterial( {color: 0x00ff00} ); 44 | 45 | export const posYSphere = new THREE.Mesh( geometry, mat ); 46 | posYSphere.position.y = 200; 47 | userLocation.add( posYSphere ); 48 | 49 | mat = new THREE.MeshBasicMaterial( {color: 0xaaffaa} ); 50 | 51 | export const negYSphere = new THREE.Mesh( geometry, mat ); 52 | negYSphere.position.y = -200; 53 | userLocation.add( negYSphere ); 54 | 55 | mat = new THREE.MeshBasicMaterial( {color: 0x0000ff} ); 56 | 57 | export const posZSphere = new THREE.Mesh( geometry, mat ); 58 | posZSphere.position.z = 200; 59 | userLocation.add( posZSphere ); 60 | 61 | mat = new THREE.MeshBasicMaterial( {color: 0xaaaaff} ); 62 | 63 | export const negZSphere = new THREE.Mesh( geometry, mat ); 64 | negZSphere.position.z = -200; 65 | userLocation.add( negZSphere ); 66 | 67 | 68 | var axisHelper = new THREE.AxisHelper( 10 ); 69 | userLocation.add( axisHelper ); 70 | axisHelper.position.z = 50; 71 | 72 | var axisHelper = new THREE.AxisHelper( 10 ); 73 | userLocation.add( axisHelper ); 74 | axisHelper.position.y = -50; 75 | 76 | var perspectiveProjection = new Argon.Cesium.PerspectiveFrustum(); 77 | perspectiveProjection.fov = Math.PI / 2; 78 | 79 | const processFrameState = (suggestedFrameState:Argon.DeviceFrameState) => { 80 | const frameState = app.device.createContextFrameState( 81 | suggestedFrameState.time, 82 | suggestedFrameState.viewport, 83 | suggestedFrameState.subviews, 84 | app.context.user 85 | ); 86 | app.context.submitFrameState(frameState); 87 | } 88 | app.device.frameStateEvent.addEventListener(processFrameState); 89 | 90 | app.updateEvent.addEventListener(() => { 91 | const userPose = app.context.getEntityPose(app.context.user); 92 | if (userPose.status & Argon.PoseStatus.KNOWN) { 93 | user.position.copy(userPose.position); 94 | user.quaternion.copy(userPose.orientation); 95 | userLocation.position.copy(userPose.position); 96 | } 97 | }) 98 | 99 | app.renderEvent.addEventListener(() => { 100 | const viewport = app.view.viewport; 101 | renderer.setSize(viewport.width, viewport.height); 102 | renderer.setPixelRatio(app.suggestedPixelRatio); 103 | 104 | for (let subview of app.view.subviews) { 105 | camera.position.copy(subview.pose.position); 106 | camera.quaternion.copy(subview.pose.orientation); 107 | camera.projectionMatrix.fromArray(subview.frustum.projectionMatrix); 108 | let {x,y,width,height} = subview.viewport; 109 | renderer.setViewport(x,y,width,height); 110 | renderer.setScissor(x,y,width,height); 111 | renderer.setScissorTest(true); 112 | renderer.render(scene, camera); 113 | } 114 | }) -------------------------------------------------------------------------------- /test/app/dataset/StonesAndChips.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/test/app/dataset/StonesAndChips.dat -------------------------------------------------------------------------------- /test/app/dataset/StonesAndChips.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /test/app/example.d.ts: -------------------------------------------------------------------------------- 1 | import * as Argon from '../../src/argon'; 2 | export declare const app: Argon.ArgonSystem; 3 | export declare const scene: any; 4 | export declare const camera: any; 5 | export declare const user: any; 6 | export declare const userLocation: any; 7 | export declare const posXSphere: any; 8 | export declare const negXSphere: any; 9 | export declare const posYSphere: any; 10 | export declare const negYSphere: any; 11 | export declare const posZSphere: any; 12 | export declare const negZSphere: any; 13 | -------------------------------------------------------------------------------- /test/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 18 | 19 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Argon Tests 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 | 21 | 22 | -------------------------------------------------------------------------------- /test/runner.js: -------------------------------------------------------------------------------- 1 | var Mocha = require('mocha') 2 | 3 | var runner = new Mocha({ 4 | ui: 'bdd', 5 | // this line is what will allow this runner to work in both the browser and Node 6 | reporter: typeof window != 'undefined' ? 'html' : 'spec' 7 | }); 8 | 9 | // set up the global variables 10 | runner['suite'].emit('pre-require', typeof window != 'undefined' ? window : global, 'global-mocha-context', runner); 11 | 12 | SystemJS.config({ 13 | typescriptOptions: { 14 | module: "system", 15 | target: "es5" 16 | } 17 | }); 18 | 19 | SystemJS.import('./test/test.ts!').then(function(tests) { 20 | return new Promise((resolve, reject) => { 21 | runner.run((failures) => { 22 | if (failures) 23 | reject(failures); 24 | else 25 | resolve(); 26 | }); 27 | }); 28 | }).catch(console.error.bind(console)); -------------------------------------------------------------------------------- /test/test.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argonjs/argon/5ef5e9460accea5ce7973f9dcfc67b9ffb1f28d4/test/test.d.ts -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "es2015", 5 | "declaration": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "pretty": true, 10 | "sourceMap": true, 11 | "moduleResolution": "node" 12 | }, 13 | "include": [ 14 | "src/**/*.ts" 15 | ], 16 | "files": [ 17 | "types/declarations.d.ts" 18 | ] 19 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.build.json", 3 | "compilerOptions": { 4 | "lib": ["es2015", "dom"], 5 | "sourceMap": false, 6 | "moduleResolution": "node", 7 | "strictNullChecks": true, 8 | "noUnusedLocals": true, 9 | "traceResolution": false 10 | }, 11 | "include": [ 12 | "types/declarations.d.ts", 13 | "src/**/*.ts", 14 | "test/**/*.ts" 15 | ] 16 | } -------------------------------------------------------------------------------- /tsfmt.json: -------------------------------------------------------------------------------- 1 | { 2 | "indentSize": 4, 3 | "tabSize": 4, 4 | "newLineCharacter": "\n", 5 | "convertTabsToSpaces": true, 6 | "insertSpaceAfterCommaDelimiter": true, 7 | "insertSpaceAfterSemicolonInForStatements": true, 8 | "insertSpaceBeforeAndAfterBinaryOperators": true, 9 | "insertSpaceAfterKeywordsInControlFlowStatements": true, 10 | "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, 11 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, 12 | "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, 13 | "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, 14 | "placeOpenBraceOnNewLineForFunctions": false, 15 | "placeOpenBraceOnNewLineForControlBlocks": false 16 | } 17 | -------------------------------------------------------------------------------- /types/cesium/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@types/cesium", 3 | "version": "1.0.0" 4 | } -------------------------------------------------------------------------------- /types/declarations.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*package.json' { 2 | export const version : string; 3 | } 4 | 5 | declare module 'googlevr/webvr-polyfill/src/cardboard-ui'; -------------------------------------------------------------------------------- /types/mobile-detect/index.d.ts: -------------------------------------------------------------------------------- 1 | declare class MobileDetect { 2 | 3 | constructor(userAgent: string, maxPhoneWidth?: number); 4 | 5 | is(key: string): boolean; 6 | match(pattern: string | RegExp): boolean; 7 | mobile(): string; 8 | mobileGrade(): string; 9 | os(): string; 10 | phone(): string; 11 | tablet(): string; 12 | userAgent(): string; 13 | version(value: string): number; 14 | versionStr(value: string): string; 15 | } 16 | 17 | export default MobileDetect; 18 | -------------------------------------------------------------------------------- /types/mobile-detect/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@types/mobile-detect", 3 | "version": "1.3.2" 4 | } --------------------------------------------------------------------------------