locar 0.0.2 → 0.0.3

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
@@ -24,9 +24,9 @@ For this reason, the focus at present will be on developing a **pure three.js ve
24
24
 
25
25
  ## Using the library
26
26
 
27
- The library will eventually be published to `npm`. For now, you should build a library tarball locally with
27
+ The library has been published to `npm` so you can install with:
28
28
  ```
29
- npm run build
29
+ npm install locar
30
30
  ```
31
31
 
32
32
  Then you can use the library in your projects with:
@@ -35,16 +35,20 @@ Then you can use the library in your projects with:
35
35
  import * as LocAR from 'locar';
36
36
  ```
37
37
 
38
- as long as you install the tarball locally into your projects, e.g. in your `package.json`:
38
+ as long as you include `locar` as a dependency, e.g. in your `package.json`:
39
39
  ```
40
40
  "dependencies": {
41
- "locar" : "file:location-of-the-tarball.tgz",
41
+ "locar" : "^0.0.3",
42
42
  "three" : "^0.169.0"
43
43
  }
44
44
  ```
45
45
 
46
46
  Including the library bundle directly as an import has issues with duplicate three.js imports which we have not resolved, so we recommend the approach above.
47
47
 
48
+ ## Tutorial
49
+
50
+ Please see [here](https://github.com/AR-js-org/locar.js/blob/master/docs/tutorial/index.md) for a tutorial introducing LocAR.js.
51
+
48
52
  ## Disclaimer
49
53
 
50
54
  This is an open-source project licensed under the [MIT License](LICENSE) and thus comes with no warranty. Also it is a volunteer-led project; work on the project by AR.js maintainers or any other contributor will be undertaken *time-permitting* only. For this reason we welcome contributors! The more people working on the project, the more likely it is that it will become full-featured and issues will be resolved.
package/dist/locar.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as n from "three";
2
- class p {
1
+ import * as s from "three";
2
+ class v {
3
3
  constructor() {
4
4
  this.EARTH = 4007501668e-2, this.HALF_EARTH = 2003750834e-2;
5
5
  }
@@ -27,9 +27,9 @@ class p {
27
27
  return "epsg:3857";
28
28
  }
29
29
  }
30
- class E {
30
+ class w {
31
31
  constructor(e, t, i = {}) {
32
- this._scene = e, this._camera = t, this._proj = new p(), this._eventHandlers = {}, this._lastCoords = null, this._gpsMinDistance = 0, this._gpsMinAccuracy = 100, this._watchPositionId = null, this.setGpsOptions(i), this.initialPosition = null;
32
+ this._scene = e, this._camera = t, this._proj = new v(), this._eventHandlers = {}, this._lastCoords = null, this._gpsMinDistance = 0, this._gpsMinAccuracy = 100, this._watchPositionId = null, this.setGpsOptions(i), this.initialPosition = null;
33
33
  }
34
34
  setProjection(e) {
35
35
  this._proj = e;
@@ -53,12 +53,12 @@ class E {
53
53
  stopGps() {
54
54
  return this._watchPositionId !== null ? (navigator.geolocation.clearWatch(this._watchPositionId), this._watchPositionId = null, !0) : !1;
55
55
  }
56
- fakeGps(e, t, i = null, s = 0) {
56
+ fakeGps(e, t, i = null, n = 0) {
57
57
  i !== null && this.setElevation(i), this._gpsReceived({
58
58
  coords: {
59
59
  longitude: e,
60
60
  latitude: t,
61
- accuracy: s
61
+ accuracy: n
62
62
  }
63
63
  });
64
64
  }
@@ -70,12 +70,12 @@ class E {
70
70
  throw "No initial position determined";
71
71
  return [i[0], -i[1]];
72
72
  }
73
- add(e, t, i, s, a = {}) {
74
- e.properties = a, this.setWorldPosition(e, t, i, s), this._scene.add(e);
73
+ add(e, t, i, n, a = {}) {
74
+ e.properties = a, this.setWorldPosition(e, t, i, n), this._scene.add(e);
75
75
  }
76
- setWorldPosition(e, t, i, s) {
76
+ setWorldPosition(e, t, i, n) {
77
77
  const a = this.lonLatToWorldCoords(t, i);
78
- s !== void 0 && (e.position.y = s), [e.position.x, e.position.z] = a;
78
+ n !== void 0 && (e.position.y = n), [e.position.x, e.position.z] = a;
79
79
  }
80
80
  setElevation(e) {
81
81
  this._camera.position.y = e;
@@ -88,7 +88,7 @@ class E {
88
88
  }
89
89
  _gpsReceived(e) {
90
90
  let t = Number.MAX_VALUE;
91
- e.coords.accuracy <= this._gpsMinAccuracy && (this._lastCoords === null ? this._lastCoords = {
91
+ console.log(`_gpsReceived(): position ${e.coords.latitude},${e.coords.longitude}, accuracy ${e.coords.accuracy}, accuracy limit ${this._gpsMinAccuracy}`), e.coords.accuracy <= this._gpsMinAccuracy && (this._lastCoords === null ? this._lastCoords = {
92
92
  latitude: e.coords.latitude,
93
93
  longitude: e.coords.longitude
94
94
  } : t = this._haversineDist(this._lastCoords, e.coords), t >= this._gpsMinDistance && (this._lastCoords.longitude = e.coords.longitude, this._lastCoords.latitude = e.coords.latitude, this.initialPosition || this.setWorldOrigin(
@@ -106,17 +106,17 @@ class E {
106
106
  * Taken from original A-Frame AR.js location-based components
107
107
  */
108
108
  _haversineDist(e, t) {
109
- const i = n.MathUtils.degToRad(t.longitude - e.longitude), s = n.MathUtils.degToRad(t.latitude - e.latitude), a = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(n.MathUtils.degToRad(e.latitude)) * Math.cos(n.MathUtils.degToRad(t.latitude)) * (Math.sin(i / 2) * Math.sin(i / 2));
109
+ const i = s.MathUtils.degToRad(t.longitude - e.longitude), n = s.MathUtils.degToRad(t.latitude - e.latitude), a = Math.sin(n / 2) * Math.sin(n / 2) + Math.cos(s.MathUtils.degToRad(e.latitude)) * Math.cos(s.MathUtils.degToRad(t.latitude)) * (Math.sin(i / 2) * Math.sin(i / 2));
110
110
  return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) * 6371e3;
111
111
  }
112
112
  }
113
- class _ {
113
+ class E {
114
114
  constructor(e, t, i) {
115
- this.renderer = e, this.renderer.autoClear = !1, this.sceneWebcam = new n.Scene();
116
- let s;
117
- t === void 0 ? (s = document.createElement("video"), s.setAttribute("autoplay", !0), s.setAttribute("playsinline", !0), s.style.display = "none", document.body.appendChild(s)) : s = document.querySelector(t), this.geom = new n.PlaneGeometry(), this.texture = new n.VideoTexture(s), this.material = new n.MeshBasicMaterial({ map: this.texture });
118
- const a = new n.Mesh(this.geom, this.material);
119
- if (this.sceneWebcam.add(a), this.cameraWebcam = new n.OrthographicCamera(
115
+ this.renderer = e, this.renderer.autoClear = !1, this.sceneWebcam = new s.Scene();
116
+ let n;
117
+ t === void 0 ? (n = document.createElement("video"), n.setAttribute("autoplay", !0), n.setAttribute("playsinline", !0), n.style.display = "none", document.body.appendChild(n)) : n = document.querySelector(t), this.geom = new s.PlaneGeometry(), this.texture = new s.VideoTexture(n), this.material = new s.MeshBasicMaterial({ map: this.texture });
118
+ const a = new s.Mesh(this.geom, this.material);
119
+ if (this.sceneWebcam.add(a), this.cameraWebcam = new s.OrthographicCamera(
120
120
  -0.5,
121
121
  0.5,
122
122
  0.5,
@@ -124,27 +124,27 @@ class _ {
124
124
  0,
125
125
  10
126
126
  ), navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
127
- const c = {
127
+ const r = {
128
128
  video: {
129
129
  width: (i == null ? void 0 : i.width) || 1280,
130
130
  height: (i == null ? void 0 : i.height) || 720,
131
131
  facingMode: "environment"
132
132
  }
133
133
  };
134
- navigator.mediaDevices.getUserMedia(c).then((d) => {
135
- console.log("using the webcam successfully..."), s.srcObject = d, s.play();
136
- }).catch((d) => {
134
+ navigator.mediaDevices.getUserMedia(r).then((c) => {
135
+ console.log("using the webcam successfully..."), n.srcObject = c, n.play();
136
+ }).catch((c) => {
137
137
  setTimeout(() => {
138
- this.createErrorPopup(
138
+ alert(
139
139
  `Webcam Error
140
- Name: ` + d.name + `
141
- Message: ` + d.message
140
+ Name: ` + c.name + `
141
+ Message: ` + c.message
142
142
  );
143
143
  }, 1e3);
144
144
  });
145
145
  } else
146
146
  setTimeout(() => {
147
- this.createErrorPopup("sorry - media devices API not supported");
147
+ alert("sorry - media devices API not supported");
148
148
  }, 1e3);
149
149
  }
150
150
  update() {
@@ -153,49 +153,43 @@ Message: ` + d.message
153
153
  dispose() {
154
154
  this.material.dispose(), this.texture.dispose(), this.geom.dispose();
155
155
  }
156
- createErrorPopup(e) {
157
- if (!document.getElementById("error-popup")) {
158
- var t = document.createElement("div");
159
- t.innerHTML = e, t.setAttribute("id", "error-popup"), document.body.appendChild(t);
160
- }
161
- }
162
156
  }
163
- const v = new n.Vector3(0, 0, 1), g = new n.Euler(), w = new n.Quaternion(), M = new n.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), f = { type: "change" };
164
- class P extends n.EventDispatcher {
157
+ const p = new s.Vector3(0, 0, 1), m = new s.Euler(), M = new s.Quaternion(), f = new s.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)), _ = { type: "change" };
158
+ class y extends s.EventDispatcher {
165
159
  constructor(e) {
166
160
  super(), window.isSecureContext === !1 && console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");
167
- const t = this, i = 1e-6, s = new n.Quaternion();
161
+ const t = this, i = 1e-6, n = new s.Quaternion();
168
162
  this.object = e, this.object.rotation.reorder("YXZ"), this.enabled = !0, this.deviceOrientation = {}, this.screenOrientation = 0, this.alphaOffset = 0, this.deviceOrientationEventName = "ondeviceorientationabsolute" in window ? "deviceorientationabsolute" : "deviceorientation";
169
163
  const a = function(o) {
170
164
  t.deviceOrientation = o;
171
- }, c = function() {
165
+ }, r = function() {
172
166
  t.screenOrientation = window.orientation || 0;
173
- }, d = function(o, h, l, u, m) {
174
- g.set(l, h, -u, "YXZ"), o.setFromEuler(g), o.multiply(M), o.multiply(w.setFromAxisAngle(v, -m));
167
+ }, c = function(o, l, h, u, g) {
168
+ m.set(h, l, -u, "YXZ"), o.setFromEuler(m), o.multiply(f), o.multiply(M.setFromAxisAngle(p, -g));
175
169
  };
176
170
  this.connect = function() {
177
- c(), window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then(function(o) {
178
- o == "granted" && (window.addEventListener("orientationchange", c), window.addEventListener(t.deviceOrientationEventName, a));
171
+ r(), window.DeviceOrientationEvent !== void 0 && typeof window.DeviceOrientationEvent.requestPermission == "function" ? window.DeviceOrientationEvent.requestPermission().then(function(o) {
172
+ o == "granted" && (window.addEventListener("orientationchange", r), window.addEventListener(t.deviceOrientationEventName, a));
179
173
  }).catch(function(o) {
180
174
  console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:", o);
181
- }) : (window.addEventListener("orientationchange", c), window.addEventListener(t.deviceOrientationEventName, a)), t.enabled = !0;
175
+ }) : (window.addEventListener("orientationchange", r), window.addEventListener(t.deviceOrientationEventName, a)), t.enabled = !0;
182
176
  }, this.disconnect = function() {
183
- window.removeEventListener("orientationchange", c), window.removeEventListener(t.deviceOrientationEventName, a), t.enabled = !1;
177
+ window.removeEventListener("orientationchange", r), window.removeEventListener(t.deviceOrientationEventName, a), t.enabled = !1;
184
178
  }, this.update = function() {
185
179
  if (t.enabled === !1) return;
186
180
  const o = t.deviceOrientation;
187
181
  if (o) {
188
- const h = o.alpha ? n.MathUtils.degToRad(o.alpha) + t.alphaOffset : 0, l = o.beta ? n.MathUtils.degToRad(o.beta) : 0, u = o.gamma ? n.MathUtils.degToRad(o.gamma) : 0, m = t.screenOrientation ? n.MathUtils.degToRad(t.screenOrientation) : 0;
189
- d(t.object.quaternion, h, l, u, m), 8 * (1 - s.dot(t.object.quaternion)) > i && (s.copy(t.object.quaternion), t.dispatchEvent(f));
182
+ const l = o.alpha ? s.MathUtils.degToRad(o.alpha) + t.alphaOffset : 0, h = o.beta ? s.MathUtils.degToRad(o.beta) : 0, u = o.gamma ? s.MathUtils.degToRad(o.gamma) : 0, g = t.screenOrientation ? s.MathUtils.degToRad(t.screenOrientation) : 0;
183
+ c(t.object.quaternion, l, h, u, g), 8 * (1 - n.dot(t.object.quaternion)) > i && (n.copy(t.object.quaternion), t.dispatchEvent(_));
190
184
  }
191
185
  }, this.dispose = function() {
192
186
  t.disconnect();
193
187
  }, this.connect();
194
188
  }
195
189
  }
196
- class y {
190
+ class P {
197
191
  constructor(e) {
198
- this.raycaster = new n.Raycaster(), this.normalisedMousePosition = new n.Vector2(null, null), e.domElement.addEventListener("click", (t) => {
192
+ this.raycaster = new s.Raycaster(), this.normalisedMousePosition = new s.Vector2(null, null), e.domElement.addEventListener("click", (t) => {
199
193
  this.normalisedMousePosition.set(
200
194
  t.clientX / e.domElement.clientWidth * 2 - 1,
201
195
  -(t.clientY / e.domElement.clientHeight * 2) + 1
@@ -211,23 +205,9 @@ class y {
211
205
  return [];
212
206
  }
213
207
  }
214
- function b(r = {}) {
215
- const e = new n.Scene(), t = new n.PerspectiveCamera(
216
- r.fov || 60,
217
- window.innerWidth / window.innerHeight,
218
- r.near || 1e-3,
219
- r.far || 100
220
- ), i = new n.WebGLRenderer();
221
- return i.setSize(window.innerWidth, window.innerHeight), document.body.appendChild(i.domElement), window.addEventListener("resize", (s) => {
222
- i.setSize(window.innerWidth, window.innerHeight), t.aspect = window.innerWidth / window.innerHeight, t.updateProjectionMatrix();
223
- }), i.setAnimationLoop(r.animate || function() {
224
- i.render(e, t);
225
- }), { scene: e, camera: t, renderer: i };
226
- }
227
208
  export {
228
- y as ClickHandler,
229
- P as DeviceOrientationControls,
230
- E as LocationBased,
231
- _ as WebcamRenderer,
232
- b as init3d
209
+ P as ClickHandler,
210
+ y as DeviceOrientationControls,
211
+ w as LocationBased,
212
+ E as WebcamRenderer
233
213
  };
package/dist/locar.umd.js CHANGED
@@ -1,3 +1,3 @@
1
- (function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.locar={},c.THREE))})(this,function(c,h){"use strict";function v(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const n=v(h);class w{constructor(){this.EARTH=4007501668e-2,this.HALF_EARTH=2003750834e-2}project(e,t){return[this.lonToSphMerc(e),this.latToSphMerc(t)]}unproject(e){return[this.sphMercToLon(e[0]),this.sphMercToLat(e[1])]}lonToSphMerc(e){return e/180*this.HALF_EARTH}latToSphMerc(e){var t=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return t*this.HALF_EARTH/180}sphMercToLon(e){return e/this.HALF_EARTH*180}sphMercToLat(e){var t=e/this.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t}getID(){return"epsg:3857"}}class M{constructor(e,t,i={}){this._scene=e,this._camera=t,this._proj=new w,this._eventHandlers={},this._lastCoords=null,this._gpsMinDistance=0,this._gpsMinAccuracy=100,this._watchPositionId=null,this.setGpsOptions(i),this.initialPosition=null}setProjection(e){this._proj=e}setGpsOptions(e={}){e.gpsMinDistance!==void 0&&(this._gpsMinDistance=e.gpsMinDistance),e.gpsMinAccuracy!==void 0&&(this._gpsMinAccuracy=e.gpsMinAccuracy)}startGps(){return this._watchPositionId===null?(this._watchPositionId=navigator.geolocation.watchPosition(e=>{this._gpsReceived(e)},e=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(e.code):alert(`GPS error: code ${e.code}`)},{enableHighAccuracy:!0}),!0):!1}stopGps(){return this._watchPositionId!==null?(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0):!1}fakeGps(e,t,i=null,s=0){i!==null&&this.setElevation(i),this._gpsReceived({coords:{longitude:e,latitude:t,accuracy:s}})}lonLatToWorldCoords(e,t){const i=this._proj.project(e,t);if(this.initialPosition)i[0]-=this.initialPosition[0],i[1]-=this.initialPosition[1];else throw"No initial position determined";return[i[0],-i[1]]}add(e,t,i,s,a={}){e.properties=a,this.setWorldPosition(e,t,i,s),this._scene.add(e)}setWorldPosition(e,t,i,s){const a=this.lonLatToWorldCoords(t,i);s!==void 0&&(e.position.y=s),[e.position.x,e.position.z]=a}setElevation(e){this._camera.position.y=e}on(e,t){this._eventHandlers[e]=t}setWorldOrigin(e,t){this.initialPosition=this._proj.project(e,t)}_gpsReceived(e){let t=Number.MAX_VALUE;e.coords.accuracy<=this._gpsMinAccuracy&&(this._lastCoords===null?this._lastCoords={latitude:e.coords.latitude,longitude:e.coords.longitude}:t=this._haversineDist(this._lastCoords,e.coords),t>=this._gpsMinDistance&&(this._lastCoords.longitude=e.coords.longitude,this._lastCoords.latitude=e.coords.latitude,this.initialPosition||this.setWorldOrigin(e.coords.longitude,e.coords.latitude),this.setWorldPosition(this._camera,e.coords.longitude,e.coords.latitude),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(e,t)))}_haversineDist(e,t){const i=n.MathUtils.degToRad(t.longitude-e.longitude),s=n.MathUtils.degToRad(t.latitude-e.latitude),a=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n.MathUtils.degToRad(e.latitude))*Math.cos(n.MathUtils.degToRad(t.latitude))*(Math.sin(i/2)*Math.sin(i/2));return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}}class _{constructor(e,t,i){this.renderer=e,this.renderer.autoClear=!1,this.sceneWebcam=new n.Scene;let s;t===void 0?(s=document.createElement("video"),s.setAttribute("autoplay",!0),s.setAttribute("playsinline",!0),s.style.display="none",document.body.appendChild(s)):s=document.querySelector(t),this.geom=new n.PlaneGeometry,this.texture=new n.VideoTexture(s),this.material=new n.MeshBasicMaterial({map:this.texture});const a=new n.Mesh(this.geom,this.material);if(this.sceneWebcam.add(a),this.cameraWebcam=new n.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const d={video:{width:(i==null?void 0:i.width)||1280,height:(i==null?void 0:i.height)||720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(d).then(l=>{console.log("using the webcam successfully..."),s.srcObject=l,s.play()}).catch(l=>{setTimeout(()=>{this.createErrorPopup(`Webcam Error
1
+ (function(r,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],h):(r=typeof globalThis<"u"?globalThis:r||self,h(r.locar={},r.THREE))})(this,function(r,h){"use strict";function v(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const n=v(h);class M{constructor(){this.EARTH=4007501668e-2,this.HALF_EARTH=2003750834e-2}project(e,t){return[this.lonToSphMerc(e),this.latToSphMerc(t)]}unproject(e){return[this.sphMercToLon(e[0]),this.sphMercToLat(e[1])]}lonToSphMerc(e){return e/180*this.HALF_EARTH}latToSphMerc(e){var t=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return t*this.HALF_EARTH/180}sphMercToLon(e){return e/this.HALF_EARTH*180}sphMercToLat(e){var t=e/this.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t}getID(){return"epsg:3857"}}class _{constructor(e,t,i={}){this._scene=e,this._camera=t,this._proj=new M,this._eventHandlers={},this._lastCoords=null,this._gpsMinDistance=0,this._gpsMinAccuracy=100,this._watchPositionId=null,this.setGpsOptions(i),this.initialPosition=null}setProjection(e){this._proj=e}setGpsOptions(e={}){e.gpsMinDistance!==void 0&&(this._gpsMinDistance=e.gpsMinDistance),e.gpsMinAccuracy!==void 0&&(this._gpsMinAccuracy=e.gpsMinAccuracy)}startGps(){return this._watchPositionId===null?(this._watchPositionId=navigator.geolocation.watchPosition(e=>{this._gpsReceived(e)},e=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(e.code):alert(`GPS error: code ${e.code}`)},{enableHighAccuracy:!0}),!0):!1}stopGps(){return this._watchPositionId!==null?(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0):!1}fakeGps(e,t,i=null,s=0){i!==null&&this.setElevation(i),this._gpsReceived({coords:{longitude:e,latitude:t,accuracy:s}})}lonLatToWorldCoords(e,t){const i=this._proj.project(e,t);if(this.initialPosition)i[0]-=this.initialPosition[0],i[1]-=this.initialPosition[1];else throw"No initial position determined";return[i[0],-i[1]]}add(e,t,i,s,a={}){e.properties=a,this.setWorldPosition(e,t,i,s),this._scene.add(e)}setWorldPosition(e,t,i,s){const a=this.lonLatToWorldCoords(t,i);s!==void 0&&(e.position.y=s),[e.position.x,e.position.z]=a}setElevation(e){this._camera.position.y=e}on(e,t){this._eventHandlers[e]=t}setWorldOrigin(e,t){this.initialPosition=this._proj.project(e,t)}_gpsReceived(e){let t=Number.MAX_VALUE;console.log(`_gpsReceived(): position ${e.coords.latitude},${e.coords.longitude}, accuracy ${e.coords.accuracy}, accuracy limit ${this._gpsMinAccuracy}`),e.coords.accuracy<=this._gpsMinAccuracy&&(this._lastCoords===null?this._lastCoords={latitude:e.coords.latitude,longitude:e.coords.longitude}:t=this._haversineDist(this._lastCoords,e.coords),t>=this._gpsMinDistance&&(this._lastCoords.longitude=e.coords.longitude,this._lastCoords.latitude=e.coords.latitude,this.initialPosition||this.setWorldOrigin(e.coords.longitude,e.coords.latitude),this.setWorldPosition(this._camera,e.coords.longitude,e.coords.latitude),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(e,t)))}_haversineDist(e,t){const i=n.MathUtils.degToRad(t.longitude-e.longitude),s=n.MathUtils.degToRad(t.latitude-e.latitude),a=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n.MathUtils.degToRad(e.latitude))*Math.cos(n.MathUtils.degToRad(t.latitude))*(Math.sin(i/2)*Math.sin(i/2));return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}}class w{constructor(e,t,i){this.renderer=e,this.renderer.autoClear=!1,this.sceneWebcam=new n.Scene;let s;t===void 0?(s=document.createElement("video"),s.setAttribute("autoplay",!0),s.setAttribute("playsinline",!0),s.style.display="none",document.body.appendChild(s)):s=document.querySelector(t),this.geom=new n.PlaneGeometry,this.texture=new n.VideoTexture(s),this.material=new n.MeshBasicMaterial({map:this.texture});const a=new n.Mesh(this.geom,this.material);if(this.sceneWebcam.add(a),this.cameraWebcam=new n.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const d={video:{width:(i==null?void 0:i.width)||1280,height:(i==null?void 0:i.height)||720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(d).then(l=>{console.log("using the webcam successfully..."),s.srcObject=l,s.play()}).catch(l=>{setTimeout(()=>{alert(`Webcam Error
2
2
  Name: `+l.name+`
3
- Message: `+l.message)},1e3)})}else setTimeout(()=>{this.createErrorPopup("sorry - media devices API not supported")},1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}createErrorPopup(e){if(!document.getElementById("error-popup")){var t=document.createElement("div");t.innerHTML=e,t.setAttribute("id","error-popup"),document.body.appendChild(t)}}}const E=new n.Vector3(0,0,1),f=new n.Euler,y=new n.Quaternion,P=new n.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),b={type:"change"};class O extends n.EventDispatcher{constructor(e){super(),window.isSecureContext===!1&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const t=this,i=1e-6,s=new n.Quaternion;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0,this.deviceOrientationEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation";const a=function(o){t.deviceOrientation=o},d=function(){t.screenOrientation=window.orientation||0},l=function(o,u,m,g,p){f.set(m,u,-g,"YXZ"),o.setFromEuler(f),o.multiply(P),o.multiply(y.setFromAxisAngle(E,-p))};this.connect=function(){d(),window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?window.DeviceOrientationEvent.requestPermission().then(function(o){o=="granted"&&(window.addEventListener("orientationchange",d),window.addEventListener(t.deviceOrientationEventName,a))}).catch(function(o){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",o)}):(window.addEventListener("orientationchange",d),window.addEventListener(t.deviceOrientationEventName,a)),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",d),window.removeEventListener(t.deviceOrientationEventName,a),t.enabled=!1},this.update=function(){if(t.enabled===!1)return;const o=t.deviceOrientation;if(o){const u=o.alpha?n.MathUtils.degToRad(o.alpha)+t.alphaOffset:0,m=o.beta?n.MathUtils.degToRad(o.beta):0,g=o.gamma?n.MathUtils.degToRad(o.gamma):0,p=t.screenOrientation?n.MathUtils.degToRad(t.screenOrientation):0;l(t.object.quaternion,u,m,g,p),8*(1-s.dot(t.object.quaternion))>i&&(s.copy(t.object.quaternion),t.dispatchEvent(b))}},this.dispose=function(){t.disconnect()},this.connect()}}class T{constructor(e){this.raycaster=new n.Raycaster,this.normalisedMousePosition=new n.Vector2(null,null),e.domElement.addEventListener("click",t=>{this.normalisedMousePosition.set(t.clientX/e.domElement.clientWidth*2-1,-(t.clientY/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition.x!==null&&this.normalisedMousePosition.y!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);const i=this.raycaster.intersectObjects(t.children,!1);return this.normalisedMousePosition.set(null,null),i}return[]}}function H(r={}){const e=new n.Scene,t=new n.PerspectiveCamera(r.fov||60,window.innerWidth/window.innerHeight,r.near||.001,r.far||100),i=new n.WebGLRenderer;return i.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(i.domElement),window.addEventListener("resize",s=>{i.setSize(window.innerWidth,window.innerHeight),t.aspect=window.innerWidth/window.innerHeight,t.updateProjectionMatrix()}),i.setAnimationLoop(r.animate||function(){i.render(e,t)}),{scene:e,camera:t,renderer:i}}c.ClickHandler=T,c.DeviceOrientationControls=O,c.LocationBased=M,c.WebcamRenderer=_,c.init3d=H,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
3
+ Message: `+l.message)},1e3)})}else setTimeout(()=>{alert("sorry - media devices API not supported")},1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}}const y=new n.Vector3(0,0,1),f=new n.Euler,E=new n.Quaternion,P=new n.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),b={type:"change"};class O extends n.EventDispatcher{constructor(e){super(),window.isSecureContext===!1&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const t=this,i=1e-6,s=new n.Quaternion;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0,this.deviceOrientationEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation";const a=function(o){t.deviceOrientation=o},d=function(){t.screenOrientation=window.orientation||0},l=function(o,u,g,m,p){f.set(g,u,-m,"YXZ"),o.setFromEuler(f),o.multiply(P),o.multiply(E.setFromAxisAngle(y,-p))};this.connect=function(){d(),window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?window.DeviceOrientationEvent.requestPermission().then(function(o){o=="granted"&&(window.addEventListener("orientationchange",d),window.addEventListener(t.deviceOrientationEventName,a))}).catch(function(o){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",o)}):(window.addEventListener("orientationchange",d),window.addEventListener(t.deviceOrientationEventName,a)),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",d),window.removeEventListener(t.deviceOrientationEventName,a),t.enabled=!1},this.update=function(){if(t.enabled===!1)return;const o=t.deviceOrientation;if(o){const u=o.alpha?n.MathUtils.degToRad(o.alpha)+t.alphaOffset:0,g=o.beta?n.MathUtils.degToRad(o.beta):0,m=o.gamma?n.MathUtils.degToRad(o.gamma):0,p=t.screenOrientation?n.MathUtils.degToRad(t.screenOrientation):0;l(t.object.quaternion,u,g,m,p),8*(1-s.dot(t.object.quaternion))>i&&(s.copy(t.object.quaternion),t.dispatchEvent(b))}},this.dispose=function(){t.disconnect()},this.connect()}}class T{constructor(e){this.raycaster=new n.Raycaster,this.normalisedMousePosition=new n.Vector2(null,null),e.domElement.addEventListener("click",t=>{this.normalisedMousePosition.set(t.clientX/e.domElement.clientWidth*2-1,-(t.clientY/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition.x!==null&&this.normalisedMousePosition.y!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);const i=this.raycaster.intersectObjects(t.children,!1);return this.normalisedMousePosition.set(null,null),i}return[]}}r.ClickHandler=T,r.DeviceOrientationControls=O,r.LocationBased=_,r.WebcamRenderer=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locar",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Location-based AR from AR.js.",
5
5
  "files": [
6
6
  "dist"