@ohuoy/easymap 1.0.19 → 1.0.21

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.
Files changed (57) hide show
  1. package/dist/bundle.js +318 -290
  2. package/dist/example - /345/211/257/346/234/254/bundle.js" +318 -290
  3. package/dist/example - /345/211/257/346/234/254/index.html" +11 -11
  4. package/index.js +4 -0
  5. package/lib/threebox-plugin/CHANGELOG.md +665 -0
  6. package/lib/threebox-plugin/LICENSE.txt +97 -0
  7. package/lib/threebox-plugin/README.md +199 -0
  8. package/lib/threebox-plugin/exports.js +2 -0
  9. package/lib/threebox-plugin/main.js +8 -0
  10. package/lib/threebox-plugin/package.json +44 -0
  11. package/lib/threebox-plugin/server.stop.js +13 -0
  12. package/lib/threebox-plugin/src/Threebox.js +1216 -0
  13. package/lib/threebox-plugin/src/animation/AnimationManager.js +483 -0
  14. package/lib/threebox-plugin/src/camera/CameraSync.js +302 -0
  15. package/lib/threebox-plugin/src/objects/CSS2DRenderer.js +245 -0
  16. package/lib/threebox-plugin/src/objects/LabelRenderer.js +71 -0
  17. package/lib/threebox-plugin/src/objects/Object3D.js +34 -0
  18. package/lib/threebox-plugin/src/objects/effects/BuildingShadows.js +115 -0
  19. package/lib/threebox-plugin/src/objects/extrusion.js +61 -0
  20. package/lib/threebox-plugin/src/objects/fflate.min.js +15 -0
  21. package/lib/threebox-plugin/src/objects/label.js +29 -0
  22. package/lib/threebox-plugin/src/objects/line.js +1386 -0
  23. package/lib/threebox-plugin/src/objects/loadObj.js +142 -0
  24. package/lib/threebox-plugin/src/objects/loaders/ColladaLoader.js +3751 -0
  25. package/lib/threebox-plugin/src/objects/loaders/FBXLoader.js +3864 -0
  26. package/lib/threebox-plugin/src/objects/loaders/GLTFLoader.js +3857 -0
  27. package/lib/threebox-plugin/src/objects/loaders/MTLLoader.js +498 -0
  28. package/lib/threebox-plugin/src/objects/loaders/OBJLoader.js +818 -0
  29. package/lib/threebox-plugin/src/objects/objects.js +1113 -0
  30. package/lib/threebox-plugin/src/objects/sphere.js +28 -0
  31. package/lib/threebox-plugin/src/objects/tooltip.js +27 -0
  32. package/lib/threebox-plugin/src/objects/tube.js +35 -0
  33. package/lib/threebox-plugin/src/three.js +6 -0
  34. package/lib/threebox-plugin/src/three.module.js +54571 -0
  35. package/lib/threebox-plugin/src/utils/ValueGenerator.js +11 -0
  36. package/lib/threebox-plugin/src/utils/constants.js +21 -0
  37. package/lib/threebox-plugin/src/utils/material.js +52 -0
  38. package/lib/threebox-plugin/src/utils/suncalc.js +322 -0
  39. package/lib/threebox-plugin/src/utils/utils.js +424 -0
  40. package/lib/threebox-plugin/src/utils/validate.js +115 -0
  41. package/package.json +18 -18
  42. package/src/components/EasyMapMarker.js +8 -0
  43. package/src/components/control/DrawBar.js +5 -0
  44. package/src/components/control/TilesBar.js +116 -27
  45. package/src/components/control/Toobars.js +20 -1
  46. package/src/components/layer/AlarmLayer.js +4 -1
  47. package/src/components/layer/AnimationBarbsLayer.js +1 -1
  48. package/src/components/layer/AnimationLayer copy.js +1 -1
  49. package/src/components/layer/AnimationLayer.js +11 -3
  50. package/src/components/layer/CustomIconLayer.js +1 -1
  51. package/src/components/layer/ExtrusionLayer.js +1 -1
  52. package/src/components/layer/ExtrusionLayerold.js +2 -1
  53. package/src/components/layer/MarkerAreaLayer.js +1 -1
  54. package/src/components/layer/PathLineLayer.js +1 -1
  55. package/src/components/layer/ThreeScanLayer.js +51 -14
  56. package/src/components/layer/ThreeWallLayer.js +1 -1
  57. package/webpack.config.js +2 -1
@@ -0,0 +1,483 @@
1
+
2
+ /**
3
+ * @author peterqliu / https://github.com/peterqliu
4
+ * @author jscastro / https://github.com/jscastro76
5
+ */
6
+ // const THREE = require('../three.js');
7
+ import * as THREE from '../three.module.js'
8
+ import utils from '../utils/utils.js';
9
+ //const utils = require("../utils/utils.js");
10
+
11
+ function AnimationManager(map) {
12
+ this.map = map
13
+ this.enrolledObjects = [];
14
+ this.previousFrameTime;
15
+
16
+ };
17
+
18
+ AnimationManager.prototype = {
19
+
20
+ unenroll: function (obj) {
21
+ this.enrolledObjects.splice(this.enrolledObjects.indexOf(obj), 1);
22
+ },
23
+
24
+ enroll: function (obj) {
25
+
26
+ //[jscastro] add the object default animations
27
+ obj.clock = new THREE.Clock();
28
+ obj.hasDefaultAnimation = false;
29
+ obj.defaultAction;
30
+ obj.actions = [];
31
+ obj.mixer;
32
+ let map = this.map;
33
+
34
+ //[jscastro] if the object includes animations
35
+ if (obj.animations && obj.animations.length > 0) {
36
+
37
+ obj.hasDefaultAnimation = true;
38
+
39
+ //check first if a defaultAnimation is defined by options
40
+ let daIndex = (obj.userData.defaultAnimation ? obj.userData.defaultAnimation : 0);
41
+ obj.mixer = new THREE.AnimationMixer(obj);
42
+
43
+ setAction(daIndex);
44
+ }
45
+
46
+ //[jscastro] set the action to play
47
+ function setAction(animationIndex) {
48
+ for (let i = 0; i < obj.animations.length; i++) {
49
+ if (animationIndex > obj.animations.length)
50
+ console.log("The animation index " + animationIndex + " doesn't exist for this object");
51
+ let animation = obj.animations[i];
52
+ let action = obj.mixer.clipAction(animation);
53
+ obj.actions.push(action);
54
+ console.log(action,obj)
55
+ //select the default animation and set the weight to 1
56
+ if (animationIndex === i) {
57
+ obj.defaultAction = action;
58
+ action.setEffectiveWeight(1);
59
+ }
60
+ else {
61
+ action.setEffectiveWeight(0);
62
+ }
63
+ action.play();
64
+
65
+ }
66
+ }
67
+
68
+ let _isPlaying = false;
69
+ //[jscastro] added property for isPlaying state
70
+ Object.defineProperty(obj, 'isPlaying', {
71
+ get() { return _isPlaying; },
72
+ set(value) {
73
+ if (_isPlaying != value) {
74
+ _isPlaying = value;
75
+ // Dispatch new event IsPlayingChanged
76
+ obj.dispatchEvent({ type: 'IsPlayingChanged', detail: obj});
77
+ }
78
+ }
79
+ })
80
+
81
+ /* Extend the provided object with animation-specific properties and track in the animation manager */
82
+ this.enrolledObjects.push(obj);
83
+
84
+ // Give this object its own internal animation queue
85
+ obj.animationQueue = [];
86
+
87
+ obj.set = function (options) {
88
+
89
+ //if duration is set, animate to the new state
90
+ if (options.duration > 0) {
91
+
92
+ let newParams = {
93
+ start: Date.now(),
94
+ expiration: Date.now() + options.duration,
95
+ endState: {}
96
+ }
97
+
98
+ utils.extend(options, newParams);
99
+
100
+ let translating = options.coords;
101
+ let rotating = options.rotation;
102
+ let scaling = options.scale || options.scaleX || options.scaleY || options.scaleZ;
103
+
104
+ if (rotating) {
105
+
106
+ let r = obj.rotation;
107
+ options.startRotation = [r.x, r.y, r.z];
108
+
109
+
110
+ options.endState.rotation = utils.types.rotation(options.rotation, options.startRotation);
111
+ options.rotationPerMs = options.endState.rotation
112
+ .map(function (angle, index) {
113
+ return (angle - options.startRotation[index]) / options.duration;
114
+ })
115
+ }
116
+
117
+ if (scaling) {
118
+ let s = obj.scale;
119
+ options.startScale = [s.x, s.y, s.z];
120
+ options.endState.scale = utils.types.scale(options.scale, options.startScale);
121
+
122
+ options.scalePerMs = options.endState.scale
123
+ .map(function (scale, index) {
124
+ return (scale - options.startScale[index]) / options.duration;
125
+ })
126
+ }
127
+
128
+ if (translating) options.pathCurve = new THREE.CatmullRomCurve3(utils.lnglatsToWorld([obj.coordinates, options.coords]));
129
+
130
+ let entry = {
131
+ type: 'set',
132
+ parameters: options
133
+ }
134
+
135
+ this.animationQueue
136
+ .push(entry);
137
+ map.repaint = true;
138
+ }
139
+
140
+ //if no duration set, stop object's existing animations and go to that state immediately
141
+ else {
142
+ this.stop();
143
+ options.rotation = utils.radify(options.rotation);
144
+ this._setObject(options);
145
+ }
146
+
147
+ return this
148
+
149
+ };
150
+
151
+ //[jscastro] animation method, is set by update method
152
+ obj.animationMethod = null;
153
+
154
+ //[jscastro] stop animation and the queue
155
+ obj.stop = function (index) {
156
+ if (obj.mixer) {
157
+ obj.isPlaying = false;
158
+ cancelAnimationFrame(obj.animationMethod);
159
+ }
160
+ //TODO: if this is removed, it produces an error in
161
+ this.animationQueue = [];
162
+ return this;
163
+ }
164
+
165
+ obj.followPath = function (options, cb) {
166
+
167
+ let entry = {
168
+ type: 'followPath',
169
+ parameters: utils._validate(options, defaults.followPath)
170
+ };
171
+
172
+ utils.extend(
173
+ entry.parameters,
174
+ {
175
+ pathCurve: new THREE.CatmullRomCurve3(
176
+ utils.lnglatsToWorld(options.path)
177
+ ),
178
+ start: Date.now(),
179
+ expiration: Date.now() + entry.parameters.duration,
180
+ cb: cb
181
+ }
182
+ );
183
+
184
+ this.animationQueue
185
+ .push(entry);
186
+
187
+ map.repaint = true;
188
+
189
+ return this;
190
+ };
191
+
192
+ obj._setObject = function (options) {
193
+
194
+ //default scale always
195
+ obj.setScale();
196
+
197
+ let p = options.position; // lnglat
198
+ let r = options.rotation; // radians
199
+ let s = options.scale; // custom scale
200
+ let w = options.worldCoordinates; //Vector3
201
+ let q = options.quaternion; // [axis, angle in rads]
202
+ let t = options.translate; // [jscastro] lnglat + height for 3D objects
203
+ let wt = options.worldTranslate; // [jscastro] Vector3 translation
204
+
205
+ if (p) {
206
+ this.coordinates = p;
207
+ let c = utils.projectToWorld(p);
208
+ this.position.copy(c)
209
+ }
210
+
211
+ if (t) {
212
+ this.coordinates = [this.coordinates[0] + t[0], this.coordinates[1] + t[1], this.coordinates[2] + t[2]];
213
+ let c = utils.projectToWorld(t);
214
+ this.position.copy(c)
215
+ //this.translateX(c.x);
216
+ //this.translateY(c.y);
217
+ //this.translateZ(c.z);
218
+ options.position = this.coordinates;
219
+ }
220
+
221
+ if (wt) {
222
+ this.translateX(wt.x);
223
+ this.translateY(wt.y);
224
+ this.translateZ(wt.z);
225
+ let p = utils.unprojectFromWorld(this.position);
226
+ this.coordinates = options.position = p;
227
+ }
228
+
229
+ if (r) {
230
+ this.rotation.set(r[0], r[1], r[2]);
231
+ options.rotation = new THREE.Vector3(r[0], r[1], r[2]);
232
+ }
233
+
234
+ if (s) {
235
+ this.scale.set(s[0], s[1], s[2]);
236
+ options.scale = this.scale;
237
+ }
238
+
239
+ if (q) {
240
+ this.quaternion.setFromAxisAngle(q[0], q[1]);
241
+ options.rotation = q[0].multiplyScalar(q[1]);
242
+ }
243
+
244
+ if (w) {
245
+ this.position.copy(w);
246
+ let p = utils.unprojectFromWorld(w);
247
+ this.coordinates = options.position = p;
248
+ }
249
+
250
+ //Each time the object is positioned, project the floor and correct shadow plane
251
+ this.setBoundingBoxShadowFloor();
252
+ this.setReceiveShadowFloor();
253
+
254
+ this.updateMatrixWorld();
255
+ map.repaint = true;
256
+
257
+ //const threeTarget = new THREE.EventDispatcher();
258
+ //threeTarget.dispatchEvent({ type: 'event', detail: { object: this, action: { position: options.position, rotation: options.rotation, scale: options.scale } } });
259
+ // fire the ObjectChanged event to notify UI object change
260
+ let e = { type: 'ObjectChanged', detail: { object: this, action: { position: options.position, rotation: options.rotation, scale: options.scale } } };
261
+ this.dispatchEvent(e);
262
+
263
+ };
264
+
265
+ //[jscastro] play default animation
266
+ obj.playDefault = function (options) {
267
+ if (obj.mixer && obj.hasDefaultAnimation) {
268
+
269
+ let newParams = {
270
+ start: Date.now(),
271
+ expiration: Date.now() + options.duration,
272
+ endState: {}
273
+ }
274
+
275
+ utils.extend(options, newParams);
276
+
277
+ obj.mixer.timeScale = options.speed || 1;
278
+
279
+ let entry = {
280
+ type: 'playDefault',
281
+ parameters: options
282
+ };
283
+
284
+ this.animationQueue
285
+ .push(entry);
286
+
287
+ map.repaint = true
288
+ return this;
289
+ }
290
+ }
291
+
292
+ //[jscastro] play an animation, requires options.animation as an index, if not it will play the default one
293
+ obj.playAnimation = function (options) {
294
+ if (obj.mixer) {
295
+
296
+ if (options.animation) {
297
+ setAction(options.animation)
298
+ }
299
+ obj.playDefault(options);
300
+
301
+ }
302
+ }
303
+
304
+ //[jscastro] pause all actions animation
305
+ obj.pauseAllActions = function () {
306
+ if (obj.mixer) {
307
+ obj.actions.forEach(function (action) {
308
+ action.paused = true;
309
+ });
310
+ }
311
+ }
312
+
313
+ //[jscastro] unpause all actions
314
+ obj.unPauseAllActions = function () {
315
+ if (obj.mixer) {
316
+ obj.actions.forEach(function (action) {
317
+ action.paused = false;
318
+ });
319
+ }
320
+
321
+ }
322
+
323
+ //[jscastro] stop all actions
324
+ obj.deactivateAllActions = function () {
325
+ if (obj.mixer) {
326
+ obj.actions.forEach(function (action) {
327
+ action.stop();
328
+ });
329
+ }
330
+ }
331
+
332
+ //[jscastro] play all actions
333
+ obj.activateAllActions = function () {
334
+ if (obj.mixer) {
335
+ obj.actions.forEach(function (action) {
336
+ action.play();
337
+ });
338
+ }
339
+ }
340
+
341
+ //[jscastro] move the model action one tick just to avoid issues with initial position
342
+ obj.idle = function () {
343
+ if (obj.mixer) {
344
+ // Update the animation mixer and render this frame
345
+ obj.mixer.update(0.01);
346
+ }
347
+ map.repaint = true;
348
+ return this;
349
+ }
350
+
351
+ },
352
+
353
+ update: function (now) {
354
+ if (!this.previousFrameTime) this.previousFrameTime = now;
355
+ let map = this.map;
356
+ let dimensions = ['X', 'Y', 'Z'];
357
+
358
+ //[jscastro] when function expires this produces an error
359
+ if (!this.enrolledObjects) return false;
360
+
361
+ //iterate through objects in queue. count in reverse so we can cull objects without frame shifting
362
+ for (let a = this.enrolledObjects.length - 1; a >= 0; a--) {
363
+
364
+ let object = this.enrolledObjects[a];
365
+
366
+ if (!object.animationQueue || object.animationQueue.length === 0) continue;
367
+
368
+ //[jscastro] now multiple animations on a single object is possible
369
+ for (let i = object.animationQueue.length - 1; i >= 0; i--) {
370
+
371
+ //focus on first item in queue
372
+ let item = object.animationQueue[i];
373
+ if (!item) continue;
374
+ let options = item.parameters;
375
+
376
+ // if an animation is past its expiration date, cull it
377
+ if (!options.expiration) {
378
+ // console.log('culled')
379
+
380
+ object.animationQueue.splice(i, 1);
381
+
382
+ // set the start time of the next animation
383
+ if (object.animationQueue[i]) object.animationQueue[i].parameters.start = now;
384
+
385
+ return
386
+ }
387
+
388
+ //if finished, jump to end state and flag animation entry for removal next time around. Execute callback if there is one
389
+ let expiring = now >= options.expiration;
390
+
391
+ if (expiring) {
392
+ options.expiration = false;
393
+ if (item.type === 'playDefault') {
394
+ object.stop();
395
+ } else {
396
+ if (options.endState) object._setObject(options.endState);
397
+ if (typeof (options.cb) != 'undefined') options.cb();
398
+ }
399
+ }
400
+
401
+ else {
402
+ let timeProgress = (now - options.start) / options.duration;
403
+
404
+ if (item.type === 'set') {
405
+
406
+ let objectState = {};
407
+
408
+ if (options.pathCurve) objectState.worldCoordinates = options.pathCurve.getPoint(timeProgress);
409
+
410
+ if (options.rotationPerMs) {
411
+ objectState.rotation = options.startRotation.map(function (rad, index) {
412
+ return rad + options.rotationPerMs[index] * timeProgress * options.duration
413
+ })
414
+ }
415
+
416
+ if (options.scalePerMs) {
417
+ objectState.scale = options.startScale.map(function (scale, index) {
418
+ return scale + options.scalePerMs[index] * timeProgress * options.duration
419
+ })
420
+ }
421
+
422
+ object._setObject(objectState);
423
+ }
424
+
425
+ if (item.type === 'followPath') {
426
+
427
+ let position = options.pathCurve.getPointAt(timeProgress);
428
+ let objectState = { worldCoordinates: position };
429
+
430
+ // if we need to track heading
431
+ if (options.trackHeading) {
432
+
433
+ let tangent = options.pathCurve
434
+ .getTangentAt(timeProgress)
435
+ .normalize();
436
+
437
+ let axis = new THREE.Vector3(0, 0, 0);
438
+ let up = new THREE.Vector3(0, 1, 0);
439
+
440
+ axis
441
+ .crossVectors(up, tangent)
442
+ .normalize();
443
+
444
+ let radians = Math.acos(up.dot(tangent));
445
+
446
+ objectState.quaternion = [axis, radians];
447
+
448
+ }
449
+
450
+ object._setObject(objectState);
451
+
452
+ }
453
+
454
+ //[jscastro] play default animation
455
+ if (item.type === 'playDefault') {
456
+
457
+ object.activateAllActions();
458
+ object.isPlaying = true;
459
+ object.animationMethod = requestAnimationFrame(this.update);
460
+ object.mixer.update(object.clock.getDelta());
461
+ map.repaint = true;
462
+ }
463
+
464
+ }
465
+ }
466
+
467
+ }
468
+
469
+ this.previousFrameTime = now;
470
+ }
471
+
472
+ }
473
+
474
+ const defaults = {
475
+ followPath: {
476
+ path: null,
477
+ duration: 1000,
478
+ trackHeading: true
479
+ }
480
+ }
481
+
482
+ export default AnimationManager
483
+ //module.exports = exports = AnimationManager;