locar 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,7 +42,7 @@ import * as LocAR from 'locar';
42
42
  as long as you include `locar` as a dependency, e.g. in your `package.json`:
43
43
  ```
44
44
  "dependencies": {
45
- "locar" : "^0.1.2",
45
+ "locar" : "^0.1.8",
46
46
  "three" : "^0.175.0"
47
47
  }
48
48
  ```
@@ -0,0 +1,280 @@
1
+ import { EventDispatcher } from 'three';
2
+ import { Object3D } from 'three';
3
+ import { Quaternion } from 'three';
4
+ import * as THREE from 'three';
5
+
6
+ /**
7
+ * Class to handle object detection via mouse clicks/touch events
8
+ * and raycasting.
9
+ */
10
+ export declare class ClickHandler {
11
+ raycaster: THREE.Raycaster;
12
+ normalisedMousePosition: THREE.Vector2 | null;
13
+ /**
14
+ * Create a ClickHandler.
15
+ * @param {THREE.WebGLRenderer} - The Three.js renderer on which the click
16
+ * events will be handled.
17
+ */
18
+ constructor(renderer: THREE.WebGLRenderer);
19
+ /**
20
+ * Cast a ray into the scene to detect objects.
21
+ * @param {THREE.Camera} - The active Three.js camera, from which the ray
22
+ * will be cast.
23
+ * @param {THREE.Scene} - The active Three.js scene, which the ray will be
24
+ * cast into.
25
+ * @return {Array} - array of all intersected objects.
26
+ */
27
+ raycast(camera: THREE.Camera, scene: THREE.Scene): THREE.Intersection[];
28
+ }
29
+
30
+ export declare class DeviceOrientationControls extends EventDispatcher {
31
+ eventEmitter: EventEmitter;
32
+ object: Object3D;
33
+ enabled: boolean;
34
+ deviceOrientation: {
35
+ alpha?: number;
36
+ beta?: number;
37
+ gamma?: number;
38
+ webkitCompassHeading?: number;
39
+ absolute?: boolean;
40
+ } | null;
41
+ screenOrientation: number;
42
+ alphaOffset: number;
43
+ orientationOffset: number;
44
+ initialOffset: boolean | null;
45
+ lastQuaternion: Quaternion | null;
46
+ orientationChangeEventName: "deviceorientation" | "deviceorientationabsolute";
47
+ smoothingFactor: number;
48
+ enablePermissionDialog: boolean;
49
+ enableInlineStyling: boolean;
50
+ preferConfirmDialog: boolean;
51
+ orientationChangeThreshold: number;
52
+ connect: () => void;
53
+ disconnect: () => void;
54
+ requestOrientationPermissions: () => void;
55
+ update: () => void;
56
+ getCorrectedHeading: () => number;
57
+ updateAlphaOffset: () => void;
58
+ dispose: () => void;
59
+ getAlpha: () => number;
60
+ getBeta: () => number;
61
+ getGamma: () => number;
62
+ createObtainPermissionGestureDialog: () => void;
63
+ obtainPermissionGesture: () => void;
64
+ /**
65
+ * Create an instance of DeviceOrientationControls.
66
+ * @param {Object} object - the object to attach the controls to
67
+ * (usually your Three.js camera)
68
+ * @param {Object} options - options for DeviceOrientationControls:
69
+ * currently accepts smoothingFactor (< 1), enablePermissionDialog, orientationChangeThreshold (radians)
70
+ */
71
+ constructor(object: Object3D, options?: DeviceOrientationControlsOptions);
72
+ on(eventName: string, eventHandler: (event: any) => void): void;
73
+ /**
74
+ * Initialise device orientation controls.
75
+ * Should be called after you have created the DeviceOrientationControls
76
+ * object and set up the deviceorientationgranted and deviceorientationerror
77
+ * event handlers.
78
+ */
79
+ init: () => void;
80
+ }
81
+
82
+ declare type DeviceOrientationControlsOptions = {
83
+ smoothingFactor?: number;
84
+ orientationChangeThreshold?: number;
85
+ enablePermissionDialog?: boolean;
86
+ enableStyling?: boolean;
87
+ preferConfirmDialog?: boolean;
88
+ };
89
+
90
+ /** Event emitter class to handle events. */
91
+ export declare class EventEmitter {
92
+ eventHandlers: Record<string, ((...args: any[]) => void)[]>;
93
+ constructor();
94
+ /**
95
+ * Add an event handler.
96
+ * @param {string} eventName - the event to handle.
97
+ * @param {Function} eventHandler - the event handler function.
98
+ */
99
+ on: (eventName: string, eventHandler: (...args: any[]) => void) => void;
100
+ /**
101
+ * Emit an event.
102
+ * @param {string} eventName - the event to emit.
103
+ * @param ...params - parameters to pass to the event handlers.
104
+ */
105
+ emit: (eventName: string, ...params: any[]) => void;
106
+ /**
107
+ * Remove an event handler.
108
+ * @param {string} eventName - the event to remove a handler from.
109
+ * @param {Function} eventHandler - the event handler function to remove.
110
+ */
111
+ off: (eventName: string, eventHandler: (...args: any[]) => void) => void;
112
+ }
113
+
114
+ declare interface GpsOptions {
115
+ gpsMinDistance?: number;
116
+ gpsMinAccuracy?: number;
117
+ }
118
+
119
+ /** The main class for the LocAR.js system. */
120
+ export declare class LocationBased extends EventEmitter {
121
+ #private;
122
+ scene: THREE.Scene;
123
+ camera: THREE.Camera;
124
+ /**
125
+ * @param {THREE.Scene} scene - The Three.js scene to use.
126
+ * @param {THREE.Camera} camera - The Three.js camera to use. Should usually
127
+ * be a THREE.PerspectiveCamera.
128
+ * @param {Object} options - Initialisation options for the GPS; see
129
+ * setGpsOptions() below.
130
+ * @param {Object} serverLogger - an object which can optionally log GPS position to a server for debugging. null by default, so no logging will be done. This object should implement a sendData() method to send data (2nd arg) to a given endpoint (1st arg). Please see source code for details. Ensure you comply with privacy laws (GDPR or equivalent) if implementing this.
131
+ */
132
+ constructor(scene: THREE.Scene, camera: THREE.Camera, options?: GpsOptions, serverLogger?: ServerLogger | null);
133
+ /**
134
+ * Set the projection to use.
135
+ * @param {Object} any object which includes a project() method
136
+ * taking longitude and latitude as arguments and returning an array
137
+ * containing easting and northing.
138
+ */
139
+ setProjection(proj: SphMercProjection): void;
140
+ /**
141
+ * Set the GPS options.
142
+ * @param {Object} object containing gpsMinDistance and/or gpsMinAccuracy
143
+ * properties. The former specifies the number of metres which the device
144
+ * must move to process a new GPS reading, and the latter specifies the
145
+ * minimum accuracy, in metres, for a GPS reading to be counted.
146
+ */
147
+ setGpsOptions(options?: GpsOptions): void;
148
+ /**
149
+ * Start the GPS on a real device
150
+ * @return {boolean} code indicating whether the GPS was started successfully.
151
+ * GPS errors can be handled by handling the gpserror event.
152
+ */
153
+ startGps(): Promise<boolean>;
154
+ /**
155
+ * Stop the GPS on a real device
156
+ * @return {boolean} true if the GPS was stopped, false if it could not be
157
+ * stopped (i.e. it was never started).
158
+ */
159
+ stopGps(): boolean;
160
+ /**
161
+ * Send a fake GPS signal. Useful for testing on a desktop or laptop.
162
+ * @param {number} lon - The longitude.
163
+ * @param {number} lat - The latitude.
164
+ * @param {number} elev - The elevation in metres. (optional, set to null
165
+ * for no elevation).
166
+ * @param {number} acc - The accuracy of the GPS reading in metres. May be
167
+ * ignored if lower than the specified minimum accuracy.
168
+ */
169
+ fakeGps(lon: number, lat: number, elev?: number | null, acc?: number): void;
170
+ /**
171
+ * Convert longitude and latitude to three.js/WebGL world coordinates.
172
+ * Uses the specified projection, and negates the northing (in typical
173
+ * projections, northings increase northwards, but in the WebGL coordinate
174
+ * system, we face negative z if the camera is at the origin with default
175
+ * rotation).
176
+ * Must not be called until an initial position is determined.
177
+ * @param {number} lon - The longitude.
178
+ * @param {number} lat - The latitude.
179
+ * @return {Array} a two member array containing the WebGL x and z coordinates
180
+ */
181
+ lonLatToWorldCoords(lon: number, lat: number): number[];
182
+ /**
183
+ * Add a new AR object at a given latitude, longitude and elevation.
184
+ * @param {THREE.Mesh} object the object
185
+ * @param {number} lon - the longitude.
186
+ * @param {number} lat - the latitude.
187
+ * @param {number} elev - the elevation in metres
188
+ * (if not specified, 0 is assigned)
189
+ * @param {Object} properties - properties describing the object (for example,
190
+ * the contents of the GeoJSON properties field).
191
+ */
192
+ add(object: THREE.Object3D, lon: number, lat: number, elev: number | undefined, properties?: Record<string, any>): void;
193
+ /**
194
+ * Set the elevation (y coordinate) of the camera.
195
+ * @param {number} elev - the elevation in metres.
196
+ */
197
+ setElevation(elev: number): void;
198
+ /**
199
+ * Obtain the last known GPS location.
200
+ *
201
+ * @return {Object} object containing latitude and longitude fields, or null if no previous GPS location.
202
+ */
203
+ getLastKnownLocation(): LonLat | null;
204
+ }
205
+
206
+ declare interface LonLat {
207
+ longitude: number;
208
+ latitude: number;
209
+ }
210
+
211
+ declare interface ServerLogger {
212
+ sendData(endpoint: string, data: any): Promise<Response> | Response;
213
+ }
214
+
215
+ /** Class representing a Spherical Mercator projection. */
216
+ export declare class SphMercProjection {
217
+ #private;
218
+ EARTH: number;
219
+ HALF_EARTH: number;
220
+ /**
221
+ * Create a SphMercProjection.
222
+ */
223
+ constructor();
224
+ /**
225
+ * Project a longitude and latitude into Spherical Mercator.
226
+ * @param {number} lon - the longitude.
227
+ * @param {number} lat - the latitude.
228
+ * @return {Array} Two-member array containing easting and northing.
229
+ */
230
+ project: (lon: number, lat: number) => [number, number];
231
+ /**
232
+ * Unproject a Spherical Mercator easting and northing.
233
+ * @param {Array} projected - Two-member array containing easting and northing
234
+ * @return {Array} Two-member array containing longitude and latitude
235
+ */
236
+ unproject: (projected: [number, number]) => number[];
237
+ /**
238
+ * Return the projection's ID.
239
+ * @return {string} The value "epsg:3857".
240
+ */
241
+ getID: () => string;
242
+ }
243
+
244
+ export declare const version = "0.1.8";
245
+
246
+ /** Class to setup the webcam. */
247
+ export declare class Webcam extends EventEmitter {
248
+ #private;
249
+ sceneWebcam: THREE.Scene;
250
+ texture: THREE.VideoTexture | null;
251
+ /**
252
+ * Create a Webcam.
253
+ * @param constraints {Object} - options to use for initialising the camera.
254
+ * This is the same constraints object as used by standard MediaDevices API.
255
+ * @param {string} videoElementSelector - selector to obtain the HTML video
256
+ * element to render the webcam feed. If a falsy value (e.g. null or
257
+ * undefined), a video element will be created.
258
+ */
259
+ constructor(constraints?: {
260
+ video: {
261
+ facingMode: string;
262
+ };
263
+ }, videoElementSelector?: string);
264
+ /**
265
+ * Free up the memory associated with the webcam.
266
+ * Should be called when your application closes.
267
+ */
268
+ dispose(): void;
269
+ }
270
+
271
+ export declare interface WebcamErrorEvent {
272
+ code: string;
273
+ message: string;
274
+ }
275
+
276
+ export declare interface WebcamStartedEvent {
277
+ texture: THREE.VideoTexture;
278
+ }
279
+
280
+ export { }