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