three-render-objects 1.27.3 → 1.27.5

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.
@@ -1,4 +1,4 @@
1
- // Version 1.27.3 three-render-objects - https://github.com/vasturiano/three-render-objects
1
+ // Version 1.27.5 three-render-objects - https://github.com/vasturiano/three-render-objects
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :
4
4
  typeof define === 'function' && define.amd ? define(['three'], factory) :
@@ -46,44 +46,33 @@
46
46
  } else {
47
47
  obj[key] = value;
48
48
  }
49
-
50
49
  return obj;
51
50
  }
52
-
53
51
  function _slicedToArray$1(arr, i) {
54
52
  return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1();
55
53
  }
56
-
57
54
  function _toConsumableArray(arr) {
58
55
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
59
56
  }
60
-
61
57
  function _arrayWithoutHoles(arr) {
62
58
  if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
63
59
  }
64
-
65
60
  function _arrayWithHoles$1(arr) {
66
61
  if (Array.isArray(arr)) return arr;
67
62
  }
68
-
69
63
  function _iterableToArray(iter) {
70
64
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
71
65
  }
72
-
73
66
  function _iterableToArrayLimit$1(arr, i) {
74
67
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
75
-
76
68
  if (_i == null) return;
77
69
  var _arr = [];
78
70
  var _n = true;
79
71
  var _d = false;
80
-
81
72
  var _s, _e;
82
-
83
73
  try {
84
74
  for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
85
75
  _arr.push(_s.value);
86
-
87
76
  if (i && _arr.length === i) break;
88
77
  }
89
78
  } catch (err) {
@@ -96,10 +85,8 @@
96
85
  if (_d) throw _e;
97
86
  }
98
87
  }
99
-
100
88
  return _arr;
101
89
  }
102
-
103
90
  function _unsupportedIterableToArray$1(o, minLen) {
104
91
  if (!o) return;
105
92
  if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
@@ -108,19 +95,14 @@
108
95
  if (n === "Map" || n === "Set") return Array.from(o);
109
96
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
110
97
  }
111
-
112
98
  function _arrayLikeToArray$1(arr, len) {
113
99
  if (len == null || len > arr.length) len = arr.length;
114
-
115
100
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
116
-
117
101
  return arr2;
118
102
  }
119
-
120
103
  function _nonIterableSpread() {
121
104
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
122
105
  }
123
-
124
106
  function _nonIterableRest$1() {
125
107
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
126
108
  }
@@ -135,9 +117,6 @@
135
117
 
136
118
  super();
137
119
 
138
- if ( domElement === undefined ) console.warn( 'THREE.TrackballControls: The second parameter "domElement" is now mandatory.' );
139
- if ( domElement === document ) console.error( 'THREE.TrackballControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.' );
140
-
141
120
  const scope = this;
142
121
  const STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
143
122
 
@@ -822,8 +801,20 @@
822
801
 
823
802
  case 2:
824
803
  _state = STATE.TOUCH_ZOOM_PAN;
825
- _moveCurr.copy( getMouseOnCircle( event.pageX - _movePrev.x, event.pageY - _movePrev.y ) );
826
- _movePrev.copy( _moveCurr );
804
+
805
+ for ( let i = 0; i < _pointers.length; i ++ ) {
806
+
807
+ if ( _pointers[ i ].pointerId !== event.pointerId ) {
808
+
809
+ const position = _pointerPositions[ _pointers[ i ].pointerId ];
810
+ _moveCurr.copy( getMouseOnCircle( position.x, position.y ) );
811
+ _movePrev.copy( _moveCurr );
812
+ break;
813
+
814
+ }
815
+
816
+ }
817
+
827
818
  break;
828
819
 
829
820
  }
@@ -938,9 +929,6 @@
938
929
 
939
930
  super();
940
931
 
941
- if ( domElement === undefined ) console.warn( 'THREE.OrbitControls: The second parameter "domElement" is now mandatory.' );
942
- if ( domElement === document ) console.error( 'THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.' );
943
-
944
932
  this.object = object;
945
933
  this.domElement = domElement;
946
934
  this.domElement.style.touchAction = 'none'; // disable touch scroll
@@ -2141,13 +2129,6 @@
2141
2129
 
2142
2130
  super();
2143
2131
 
2144
- if ( domElement === undefined ) {
2145
-
2146
- console.warn( 'THREE.FlyControls: The second parameter "domElement" is now mandatory.' );
2147
- domElement = document;
2148
-
2149
- }
2150
-
2151
2132
  this.object = object;
2152
2133
  this.domElement = domElement;
2153
2134
 
@@ -2172,7 +2153,7 @@
2172
2153
 
2173
2154
  this.tmpQuaternion = new three$1.Quaternion();
2174
2155
 
2175
- this.mouseStatus = 0;
2156
+ this.status = 0;
2176
2157
 
2177
2158
  this.moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 };
2178
2159
  this.moveVector = new three$1.Vector3( 0, 0, 0 );
@@ -2248,11 +2229,11 @@
2248
2229
 
2249
2230
  };
2250
2231
 
2251
- this.mousedown = function ( event ) {
2232
+ this.pointerdown = function ( event ) {
2252
2233
 
2253
2234
  if ( this.dragToLook ) {
2254
2235
 
2255
- this.mouseStatus ++;
2236
+ this.status ++;
2256
2237
 
2257
2238
  } else {
2258
2239
 
@@ -2269,9 +2250,9 @@
2269
2250
 
2270
2251
  };
2271
2252
 
2272
- this.mousemove = function ( event ) {
2253
+ this.pointermove = function ( event ) {
2273
2254
 
2274
- if ( ! this.dragToLook || this.mouseStatus > 0 ) {
2255
+ if ( ! this.dragToLook || this.status > 0 ) {
2275
2256
 
2276
2257
  const container = this.getContainerDimensions();
2277
2258
  const halfWidth = container.size[ 0 ] / 2;
@@ -2286,11 +2267,11 @@
2286
2267
 
2287
2268
  };
2288
2269
 
2289
- this.mouseup = function ( event ) {
2270
+ this.pointerup = function ( event ) {
2290
2271
 
2291
2272
  if ( this.dragToLook ) {
2292
2273
 
2293
- this.mouseStatus --;
2274
+ this.status --;
2294
2275
 
2295
2276
  this.moveState.yawLeft = this.moveState.pitchDown = 0;
2296
2277
 
@@ -2381,26 +2362,25 @@
2381
2362
  this.dispose = function () {
2382
2363
 
2383
2364
  this.domElement.removeEventListener( 'contextmenu', contextmenu );
2384
- this.domElement.removeEventListener( 'mousedown', _mousedown );
2385
- this.domElement.removeEventListener( 'mousemove', _mousemove );
2386
- this.domElement.removeEventListener( 'mouseup', _mouseup );
2365
+ this.domElement.removeEventListener( 'pointerdown', _pointerdown );
2366
+ this.domElement.removeEventListener( 'pointermove', _pointermove );
2367
+ this.domElement.removeEventListener( 'pointerup', _pointerup );
2387
2368
 
2388
2369
  window.removeEventListener( 'keydown', _keydown );
2389
2370
  window.removeEventListener( 'keyup', _keyup );
2390
2371
 
2391
2372
  };
2392
2373
 
2393
- const _mousemove = this.mousemove.bind( this );
2394
- const _mousedown = this.mousedown.bind( this );
2395
- const _mouseup = this.mouseup.bind( this );
2374
+ const _pointermove = this.pointermove.bind( this );
2375
+ const _pointerdown = this.pointerdown.bind( this );
2376
+ const _pointerup = this.pointerup.bind( this );
2396
2377
  const _keydown = this.keydown.bind( this );
2397
2378
  const _keyup = this.keyup.bind( this );
2398
2379
 
2399
2380
  this.domElement.addEventListener( 'contextmenu', contextmenu );
2400
-
2401
- this.domElement.addEventListener( 'mousemove', _mousemove );
2402
- this.domElement.addEventListener( 'mousedown', _mousedown );
2403
- this.domElement.addEventListener( 'mouseup', _mouseup );
2381
+ this.domElement.addEventListener( 'pointerdown', _pointerdown );
2382
+ this.domElement.addEventListener( 'pointermove', _pointermove );
2383
+ this.domElement.addEventListener( 'pointerup', _pointerup );
2404
2384
 
2405
2385
  window.addEventListener( 'keydown', _keydown );
2406
2386
  window.addEventListener( 'keyup', _keyup );
@@ -2486,6 +2466,8 @@
2486
2466
 
2487
2467
  }
2488
2468
 
2469
+ dispose() {}
2470
+
2489
2471
  }
2490
2472
 
2491
2473
  // Helper for passes that need to fill the viewport with a single quad.
@@ -2591,6 +2573,14 @@
2591
2573
 
2592
2574
  }
2593
2575
 
2576
+ dispose() {
2577
+
2578
+ this.material.dispose();
2579
+
2580
+ this.fsQuad.dispose();
2581
+
2582
+ }
2583
+
2594
2584
  }
2595
2585
 
2596
2586
  class MaskPass extends Pass {
@@ -2911,6 +2901,15 @@
2911
2901
 
2912
2902
  }
2913
2903
 
2904
+ dispose() {
2905
+
2906
+ this.renderTarget1.dispose();
2907
+ this.renderTarget2.dispose();
2908
+
2909
+ this.copyPass.dispose();
2910
+
2911
+ }
2912
+
2914
2913
  }
2915
2914
 
2916
2915
  // Helper for passes that need to fill the viewport with a single quad.
@@ -3002,14 +3001,12 @@
3002
3001
  _extends = Object.assign ? Object.assign.bind() : function (target) {
3003
3002
  for (var i = 1; i < arguments.length; i++) {
3004
3003
  var source = arguments[i];
3005
-
3006
3004
  for (var key in source) {
3007
3005
  if (Object.prototype.hasOwnProperty.call(source, key)) {
3008
3006
  target[key] = source[key];
3009
3007
  }
3010
3008
  }
3011
3009
  }
3012
-
3013
3010
  return target;
3014
3011
  };
3015
3012
  return _extends.apply(this, arguments);
@@ -3019,7 +3016,6 @@
3019
3016
  if (self === void 0) {
3020
3017
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3021
3018
  }
3022
-
3023
3019
  return self;
3024
3020
  }
3025
3021
 
@@ -3052,7 +3048,6 @@
3052
3048
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
3053
3049
  if (Reflect.construct.sham) return false;
3054
3050
  if (typeof Proxy === "function") return true;
3055
-
3056
3051
  try {
3057
3052
  Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
3058
3053
  return true;
@@ -3074,30 +3069,23 @@
3074
3069
  return instance;
3075
3070
  };
3076
3071
  }
3077
-
3078
3072
  return _construct.apply(null, arguments);
3079
3073
  }
3080
3074
 
3081
3075
  function _wrapNativeSuper(Class) {
3082
3076
  var _cache = typeof Map === "function" ? new Map() : undefined;
3083
-
3084
3077
  _wrapNativeSuper = function _wrapNativeSuper(Class) {
3085
3078
  if (Class === null || !_isNativeFunction(Class)) return Class;
3086
-
3087
3079
  if (typeof Class !== "function") {
3088
3080
  throw new TypeError("Super expression must either be null or a function");
3089
3081
  }
3090
-
3091
3082
  if (typeof _cache !== "undefined") {
3092
3083
  if (_cache.has(Class)) return _cache.get(Class);
3093
-
3094
3084
  _cache.set(Class, Wrapper);
3095
3085
  }
3096
-
3097
3086
  function Wrapper() {
3098
3087
  return _construct(Class, arguments, _getPrototypeOf(this).constructor);
3099
3088
  }
3100
-
3101
3089
  Wrapper.prototype = Object.create(Class.prototype, {
3102
3090
  constructor: {
3103
3091
  value: Wrapper,
@@ -3108,7 +3096,6 @@
3108
3096
  });
3109
3097
  return _setPrototypeOf(Wrapper, Class);
3110
3098
  };
3111
-
3112
3099
  return _wrapNativeSuper(Class);
3113
3100
  }
3114
3101
 
@@ -4974,11 +4961,9 @@
4974
4961
  state.extraRenderers.forEach(function (r) {
4975
4962
  return r.render(state.scene, state.camera);
4976
4963
  });
4977
-
4978
4964
  if (state.enablePointerInteraction) {
4979
4965
  // Update tooltip and trigger onHover events
4980
4966
  var topObject = null;
4981
-
4982
4967
  if (state.hoverDuringDrag || !state.isPointerDragging) {
4983
4968
  var intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y).filter(function (d) {
4984
4969
  return state.hoverFilter(d.object);
@@ -4989,14 +4974,12 @@
4989
4974
  topObject = topIntersect ? topIntersect.object : null;
4990
4975
  state.intersectionPoint = topIntersect ? topIntersect.point : null;
4991
4976
  }
4992
-
4993
4977
  if (topObject !== state.hoverObj) {
4994
4978
  state.onHover(topObject, state.hoverObj);
4995
4979
  state.toolTipElem.innerHTML = topObject ? index$1(state.tooltipContent)(topObject) || '' : '';
4996
4980
  state.hoverObj = topObject;
4997
4981
  }
4998
4982
  }
4999
-
5000
4983
  exports$1.update(); // update camera animation tweens
5001
4984
  }
5002
4985
 
@@ -5004,16 +4987,17 @@
5004
4987
  },
5005
4988
  getPointerPos: function getPointerPos(state) {
5006
4989
  var _state$pointerPos = state.pointerPos,
5007
- x = _state$pointerPos.x,
5008
- y = _state$pointerPos.y;
4990
+ x = _state$pointerPos.x,
4991
+ y = _state$pointerPos.y;
5009
4992
  return {
5010
4993
  x: x,
5011
4994
  y: y
5012
4995
  };
5013
4996
  },
5014
4997
  cameraPosition: function cameraPosition(state, position, lookAt, transitionDuration) {
5015
- var camera = state.camera; // Setter
4998
+ var camera = state.camera;
5016
4999
 
5000
+ // Setter
5017
5001
  if (position && state.initialised) {
5018
5002
  var finalPos = position;
5019
5003
  var finalLookAt = lookAt || {
@@ -5021,7 +5005,6 @@
5021
5005
  y: 0,
5022
5006
  z: 0
5023
5007
  };
5024
-
5025
5008
  if (!transitionDuration) {
5026
5009
  // no animation
5027
5010
  setCameraPos(finalPos);
@@ -5029,31 +5012,31 @@
5029
5012
  } else {
5030
5013
  var camPos = Object.assign({}, camera.position);
5031
5014
  var camLookAt = getLookAt();
5032
- new exports$1.Tween(camPos).to(finalPos, transitionDuration).easing(exports$1.Easing.Quadratic.Out).onUpdate(setCameraPos).start(); // Face direction in 1/3rd of time
5015
+ new exports$1.Tween(camPos).to(finalPos, transitionDuration).easing(exports$1.Easing.Quadratic.Out).onUpdate(setCameraPos).start();
5033
5016
 
5017
+ // Face direction in 1/3rd of time
5034
5018
  new exports$1.Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(exports$1.Easing.Quadratic.Out).onUpdate(setLookAt).start();
5035
5019
  }
5036
-
5037
5020
  return this;
5038
- } // Getter
5039
-
5021
+ }
5040
5022
 
5023
+ // Getter
5041
5024
  return Object.assign({}, camera.position, {
5042
5025
  lookAt: getLookAt()
5043
- }); //
5026
+ });
5027
+
5028
+ //
5044
5029
 
5045
5030
  function setCameraPos(pos) {
5046
5031
  var x = pos.x,
5047
- y = pos.y,
5048
- z = pos.z;
5032
+ y = pos.y,
5033
+ z = pos.z;
5049
5034
  if (x !== undefined) camera.position.x = x;
5050
5035
  if (y !== undefined) camera.position.y = y;
5051
5036
  if (z !== undefined) camera.position.z = z;
5052
5037
  }
5053
-
5054
5038
  function setLookAt(lookAt) {
5055
5039
  var lookAtVect = new three.Vector3(lookAt.x, lookAt.y, lookAt.z);
5056
-
5057
5040
  if (state.controls.target) {
5058
5041
  state.controls.target = lookAtVect;
5059
5042
  } else {
@@ -5069,11 +5052,9 @@
5069
5052
  zoomToFit: function zoomToFit(state) {
5070
5053
  var transitionDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
5071
5054
  var padding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
5072
-
5073
5055
  for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
5074
5056
  bboxArgs[_key - 3] = arguments[_key];
5075
5057
  }
5076
-
5077
5058
  return this.fitToBbox(this.getBbox.apply(this, bboxArgs), transitionDuration, padding);
5078
5059
  },
5079
5060
  fitToBbox: function fitToBbox(state, bbox) {
@@ -5081,31 +5062,27 @@
5081
5062
  var padding = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
5082
5063
  // based on https://discourse.threejs.org/t/camera-zoom-to-fit-object/936/24
5083
5064
  var camera = state.camera;
5084
-
5085
5065
  if (bbox) {
5086
5066
  var center = new three.Vector3(0, 0, 0); // reset camera aim to center
5087
-
5088
5067
  var maxBoxSide = Math.max.apply(Math, _toConsumableArray(Object.entries(bbox).map(function (_ref) {
5089
5068
  var _ref2 = _slicedToArray$1(_ref, 2),
5090
- coordType = _ref2[0],
5091
- coords = _ref2[1];
5092
-
5069
+ coordType = _ref2[0],
5070
+ coords = _ref2[1];
5093
5071
  return Math.max.apply(Math, _toConsumableArray(coords.map(function (c) {
5094
5072
  return Math.abs(center[coordType] - c);
5095
5073
  })));
5096
- }))) * 2; // find distance that fits whole bbox within padded fov
5074
+ }))) * 2;
5097
5075
 
5076
+ // find distance that fits whole bbox within padded fov
5098
5077
  var paddedFov = (1 - padding * 2 / state.height) * camera.fov;
5099
5078
  var fitHeightDistance = maxBoxSide / Math.atan(paddedFov * Math.PI / 180);
5100
5079
  var fitWidthDistance = fitHeightDistance / camera.aspect;
5101
5080
  var distance = Math.max(fitHeightDistance, fitWidthDistance);
5102
-
5103
5081
  if (distance > 0) {
5104
5082
  var newCameraPosition = center.clone().sub(camera.position).normalize().multiplyScalar(-distance);
5105
5083
  this.cameraPosition(newCameraPosition, center, transitionDuration);
5106
5084
  }
5107
5085
  }
5108
-
5109
5086
  return this;
5110
5087
  },
5111
5088
  getBbox: function getBbox(state) {
@@ -5117,8 +5094,9 @@
5117
5094
  if (!objs.length) return null;
5118
5095
  objs.forEach(function (obj) {
5119
5096
  return box.expandByObject(obj);
5120
- }); // extract global x,y,z min/max
5097
+ });
5121
5098
 
5099
+ // extract global x,y,z min/max
5122
5100
  return Object.assign.apply(Object, _toConsumableArray(['x', 'y', 'z'].map(function (c) {
5123
5101
  return _defineProperty({}, c, [box.min[c], box.max[c]]);
5124
5102
  })));
@@ -5126,7 +5104,6 @@
5126
5104
  getScreenCoords: function getScreenCoords(state, x, y, z) {
5127
5105
  var vec = new three.Vector3(x, y, z);
5128
5106
  vec.project(this.camera()); // project to the camera plane
5129
-
5130
5107
  return {
5131
5108
  // align relative pos to canvas dimensions
5132
5109
  x: (vec.x + 1) * state.width / 2,
@@ -5144,7 +5121,6 @@
5144
5121
  var relCoords = new three.Vector2(x / state.width * 2 - 1, -(y / state.height) * 2 + 1);
5145
5122
  var raycaster = new three.Raycaster();
5146
5123
  raycaster.params.Line.threshold = state.lineHoverPrecision; // set linePrecision
5147
-
5148
5124
  raycaster.setFromCamera(relCoords, state.camera);
5149
5125
  return raycaster.intersectObjects(state.objects, true);
5150
5126
  },
@@ -5166,8 +5142,8 @@
5166
5142
  tbControls: function tbControls(state) {
5167
5143
  return state.controls;
5168
5144
  } // to be deprecated
5169
-
5170
5145
  },
5146
+
5171
5147
  stateInit: function stateInit() {
5172
5148
  return {
5173
5149
  scene: new three.Scene(),
@@ -5177,22 +5153,23 @@
5177
5153
  },
5178
5154
  init: function init(domNode, state) {
5179
5155
  var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
5180
- _ref4$controlType = _ref4.controlType,
5181
- controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType,
5182
- _ref4$rendererConfig = _ref4.rendererConfig,
5183
- rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig,
5184
- _ref4$extraRenderers = _ref4.extraRenderers,
5185
- extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers,
5186
- _ref4$waitForLoadComp = _ref4.waitForLoadComplete,
5187
- waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp;
5188
-
5156
+ _ref4$controlType = _ref4.controlType,
5157
+ controlType = _ref4$controlType === void 0 ? 'trackball' : _ref4$controlType,
5158
+ _ref4$rendererConfig = _ref4.rendererConfig,
5159
+ rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig,
5160
+ _ref4$extraRenderers = _ref4.extraRenderers,
5161
+ extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers,
5162
+ _ref4$waitForLoadComp = _ref4.waitForLoadComplete,
5163
+ waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp;
5189
5164
  // Wipe DOM
5190
- domNode.innerHTML = ''; // Add relative container
5165
+ domNode.innerHTML = '';
5191
5166
 
5167
+ // Add relative container
5192
5168
  domNode.appendChild(state.container = document.createElement('div'));
5193
5169
  state.container.className = 'scene-container';
5194
- state.container.style.position = 'relative'; // Add nav info section
5170
+ state.container.style.position = 'relative';
5195
5171
 
5172
+ // Add nav info section
5196
5173
  state.container.appendChild(state.navInfo = document.createElement('div'));
5197
5174
  state.navInfo.className = 'scene-nav-info';
5198
5175
  state.navInfo.textContent = {
@@ -5200,44 +5177,46 @@
5200
5177
  trackball: 'Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan',
5201
5178
  fly: 'WASD: move, R|F: up | down, Q|E: roll, up|down: pitch, left|right: yaw'
5202
5179
  }[controlType] || '';
5203
- state.navInfo.style.display = state.showNavInfo ? null : 'none'; // Setup tooltip
5180
+ state.navInfo.style.display = state.showNavInfo ? null : 'none';
5204
5181
 
5182
+ // Setup tooltip
5205
5183
  state.toolTipElem = document.createElement('div');
5206
5184
  state.toolTipElem.classList.add('scene-tooltip');
5207
- state.container.appendChild(state.toolTipElem); // Capture pointer coords on move or touchstart
5185
+ state.container.appendChild(state.toolTipElem);
5208
5186
 
5187
+ // Capture pointer coords on move or touchstart
5209
5188
  state.pointerPos = new three.Vector2();
5210
5189
  state.pointerPos.x = -2; // Initialize off canvas
5211
-
5212
5190
  state.pointerPos.y = -2;
5213
5191
  ['pointermove', 'pointerdown'].forEach(function (evType) {
5214
5192
  return state.container.addEventListener(evType, function (ev) {
5215
5193
  // track click state
5216
- evType === 'pointerdown' && (state.isPointerPressed = true); // detect point drag
5194
+ evType === 'pointerdown' && (state.isPointerPressed = true);
5217
5195
 
5196
+ // detect point drag
5218
5197
  !state.isPointerDragging && ev.type === 'pointermove' && (ev.pressure > 0 || state.isPointerPressed) // ev.pressure always 0 on Safari, so we used the isPointerPressed tracker
5219
5198
  && (ev.pointerType !== 'touch' || ev.movementX === undefined || [ev.movementX, ev.movementY].some(function (m) {
5220
5199
  return Math.abs(m) > 1;
5221
5200
  })) // relax drag trigger sensitivity on touch events
5222
5201
  && (state.isPointerDragging = true);
5223
-
5224
5202
  if (state.enablePointerInteraction) {
5225
5203
  // update the pointer pos
5226
5204
  var offset = getOffset(state.container);
5227
5205
  state.pointerPos.x = ev.pageX - offset.left;
5228
- state.pointerPos.y = ev.pageY - offset.top; // Move tooltip
5206
+ state.pointerPos.y = ev.pageY - offset.top;
5229
5207
 
5208
+ // Move tooltip
5230
5209
  state.toolTipElem.style.top = "".concat(state.pointerPos.y, "px");
5231
- state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); // adjust horizontal position to not exceed canvas boundaries
5232
-
5233
- state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( // flip to above if near bottom
5210
+ state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px");
5211
+ // adjust horizontal position to not exceed canvas boundaries
5212
+ state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat(
5213
+ // flip to above if near bottom
5234
5214
  state.height - state.pointerPos.y < 100 ? 'calc(-100% - 8px)' : '21px', ")");
5235
5215
  }
5236
-
5237
5216
  function getOffset(el) {
5238
5217
  var rect = el.getBoundingClientRect(),
5239
- scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
5240
- scrollTop = window.pageYOffset || document.documentElement.scrollTop;
5218
+ scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
5219
+ scrollTop = window.pageYOffset || document.documentElement.scrollTop;
5241
5220
  return {
5242
5221
  top: rect.top + scrollTop,
5243
5222
  left: rect.left + scrollLeft
@@ -5246,11 +5225,11 @@
5246
5225
  }, {
5247
5226
  passive: true
5248
5227
  });
5249
- }); // Handle click events on objs
5228
+ });
5250
5229
 
5230
+ // Handle click events on objs
5251
5231
  state.container.addEventListener('pointerup', function (ev) {
5252
5232
  state.isPointerPressed = false;
5253
-
5254
5233
  if (state.isPointerDragging) {
5255
5234
  state.isPointerDragging = false;
5256
5235
  if (!state.clickAfterDrag) return; // don't trigger onClick after pointer drag (camera motion via controls)
@@ -5275,16 +5254,17 @@
5275
5254
 
5276
5255
  state.container.addEventListener('contextmenu', function (ev) {
5277
5256
  if (state.onRightClick) ev.preventDefault(); // prevent default contextmenu behavior and allow pointerup to fire instead
5278
- }); // Setup renderer, camera and controls
5257
+ });
5279
5258
 
5259
+ // Setup renderer, camera and controls
5280
5260
  state.renderer = new three.WebGLRenderer(Object.assign({
5281
5261
  antialias: true,
5282
5262
  alpha: true
5283
5263
  }, rendererConfig));
5284
5264
  state.renderer.setPixelRatio(Math.min(2, window.devicePixelRatio)); // clamp device pixel ratio
5265
+ state.container.appendChild(state.renderer.domElement);
5285
5266
 
5286
- state.container.appendChild(state.renderer.domElement); // Setup extra renderers
5287
-
5267
+ // Setup extra renderers
5288
5268
  state.extraRenderers = extraRenderers;
5289
5269
  state.extraRenderers.forEach(function (r) {
5290
5270
  // overlay them on top of main renderer
@@ -5292,24 +5272,23 @@
5292
5272
  r.domElement.style.top = '0px';
5293
5273
  r.domElement.style.pointerEvents = 'none';
5294
5274
  state.container.appendChild(r.domElement);
5295
- }); // configure post-processing composer
5275
+ });
5296
5276
 
5277
+ // configure post-processing composer
5297
5278
  state.postProcessingComposer = new EffectComposer(state.renderer);
5298
5279
  state.postProcessingComposer.addPass(new RenderPass(state.scene, state.camera)); // render scene as first pass
5299
- // configure controls
5300
5280
 
5281
+ // configure controls
5301
5282
  state.controls = new {
5302
5283
  trackball: TrackballControls,
5303
5284
  orbit: OrbitControls,
5304
5285
  fly: FlyControls
5305
5286
  }[controlType](state.camera, state.renderer.domElement);
5306
-
5307
5287
  if (controlType === 'fly') {
5308
5288
  state.controls.movementSpeed = 300;
5309
5289
  state.controls.rollSpeed = Math.PI / 6;
5310
5290
  state.controls.dragToLook = true;
5311
5291
  }
5312
-
5313
5292
  if (controlType === 'trackball' || controlType === 'orbit') {
5314
5293
  state.controls.minDistance = 0.1;
5315
5294
  state.controls.maxDistance = state.skyRadius;
@@ -5326,14 +5305,14 @@
5326
5305
  state.controlsDragging = false;
5327
5306
  });
5328
5307
  }
5329
-
5330
5308
  [state.renderer, state.postProcessingComposer].concat(_toConsumableArray(state.extraRenderers)).forEach(function (r) {
5331
5309
  return r.setSize(state.width, state.height);
5332
5310
  });
5333
5311
  state.camera.aspect = state.width / state.height;
5334
5312
  state.camera.updateProjectionMatrix();
5335
- state.camera.position.z = 1000; // add sky
5313
+ state.camera.position.z = 1000;
5336
5314
 
5315
+ // add sky
5337
5316
  state.scene.add(state.skysphere = new three.Mesh());
5338
5317
  state.skysphere.visible = false;
5339
5318
  state.loadComplete = state.scene.visible = !waitForLoadComplete;
@@ -5350,20 +5329,17 @@
5350
5329
  state.camera.aspect = state.width / state.height;
5351
5330
  state.camera.updateProjectionMatrix();
5352
5331
  }
5353
-
5354
5332
  if (changedProps.hasOwnProperty('skyRadius') && state.skyRadius) {
5355
5333
  state.controls.hasOwnProperty('maxDistance') && changedProps.skyRadius && (state.controls.maxDistance = Math.min(state.controls.maxDistance, state.skyRadius));
5356
5334
  state.camera.far = state.skyRadius * 2.5;
5357
5335
  state.camera.updateProjectionMatrix();
5358
5336
  state.skysphere.geometry = new three.SphereGeometry(state.skyRadius);
5359
5337
  }
5360
-
5361
5338
  if (changedProps.hasOwnProperty('backgroundColor')) {
5362
5339
  var alpha = parseToRgb(state.backgroundColor).alpha;
5363
5340
  if (alpha === undefined) alpha = 1;
5364
5341
  state.renderer.setClearColor(new three.Color(curriedOpacify$1(1, state.backgroundColor)), alpha);
5365
5342
  }
5366
-
5367
5343
  if (changedProps.hasOwnProperty('backgroundImageUrl')) {
5368
5344
  if (!state.backgroundImageUrl) {
5369
5345
  state.skysphere.visible = false;
@@ -5375,26 +5351,25 @@
5375
5351
  map: texture,
5376
5352
  side: three.BackSide
5377
5353
  });
5378
- state.skysphere.visible = true; // triggered when background image finishes loading (asynchronously to allow 1 frame to load texture)
5354
+ state.skysphere.visible = true;
5379
5355
 
5356
+ // triggered when background image finishes loading (asynchronously to allow 1 frame to load texture)
5380
5357
  state.onBackgroundImageLoaded && setTimeout(state.onBackgroundImageLoaded);
5381
5358
  !state.loadComplete && finishLoad();
5382
5359
  });
5383
5360
  }
5384
5361
  }
5385
-
5386
5362
  changedProps.hasOwnProperty('showNavInfo') && (state.navInfo.style.display = state.showNavInfo ? null : 'none');
5387
-
5388
5363
  if (changedProps.hasOwnProperty('objects')) {
5389
5364
  (changedProps.objects || []).forEach(function (obj) {
5390
5365
  return state.scene.remove(obj);
5391
5366
  }); // Clear the place
5392
-
5393
5367
  state.objects.forEach(function (obj) {
5394
5368
  return state.scene.add(obj);
5395
5369
  }); // Add to scene
5396
- } //
5370
+ }
5397
5371
 
5372
+ //
5398
5373
 
5399
5374
  function finishLoad() {
5400
5375
  state.loadComplete = state.scene.visible = true;