three-render-objects 1.27.4 → 1.27.6
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/three-render-objects.common.js +65 -105
- package/dist/three-render-objects.d.ts +4 -1
- package/dist/three-render-objects.js +111 -123
- package/dist/three-render-objects.js.map +1 -1
- package/dist/three-render-objects.min.js +2 -2
- package/dist/three-render-objects.module.js +61 -95
- package/package.json +13 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Version 1.27.
|
|
1
|
+
// Version 1.27.6 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
|
}
|
|
@@ -819,8 +801,20 @@
|
|
|
819
801
|
|
|
820
802
|
case 2:
|
|
821
803
|
_state = STATE.TOUCH_ZOOM_PAN;
|
|
822
|
-
|
|
823
|
-
|
|
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
|
+
|
|
824
818
|
break;
|
|
825
819
|
|
|
826
820
|
}
|
|
@@ -2159,7 +2153,7 @@
|
|
|
2159
2153
|
|
|
2160
2154
|
this.tmpQuaternion = new three$1.Quaternion();
|
|
2161
2155
|
|
|
2162
|
-
this.
|
|
2156
|
+
this.status = 0;
|
|
2163
2157
|
|
|
2164
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 };
|
|
2165
2159
|
this.moveVector = new three$1.Vector3( 0, 0, 0 );
|
|
@@ -2235,11 +2229,11 @@
|
|
|
2235
2229
|
|
|
2236
2230
|
};
|
|
2237
2231
|
|
|
2238
|
-
this.
|
|
2232
|
+
this.pointerdown = function ( event ) {
|
|
2239
2233
|
|
|
2240
2234
|
if ( this.dragToLook ) {
|
|
2241
2235
|
|
|
2242
|
-
this.
|
|
2236
|
+
this.status ++;
|
|
2243
2237
|
|
|
2244
2238
|
} else {
|
|
2245
2239
|
|
|
@@ -2256,9 +2250,9 @@
|
|
|
2256
2250
|
|
|
2257
2251
|
};
|
|
2258
2252
|
|
|
2259
|
-
this.
|
|
2253
|
+
this.pointermove = function ( event ) {
|
|
2260
2254
|
|
|
2261
|
-
if ( ! this.dragToLook || this.
|
|
2255
|
+
if ( ! this.dragToLook || this.status > 0 ) {
|
|
2262
2256
|
|
|
2263
2257
|
const container = this.getContainerDimensions();
|
|
2264
2258
|
const halfWidth = container.size[ 0 ] / 2;
|
|
@@ -2273,11 +2267,11 @@
|
|
|
2273
2267
|
|
|
2274
2268
|
};
|
|
2275
2269
|
|
|
2276
|
-
this.
|
|
2270
|
+
this.pointerup = function ( event ) {
|
|
2277
2271
|
|
|
2278
2272
|
if ( this.dragToLook ) {
|
|
2279
2273
|
|
|
2280
|
-
this.
|
|
2274
|
+
this.status --;
|
|
2281
2275
|
|
|
2282
2276
|
this.moveState.yawLeft = this.moveState.pitchDown = 0;
|
|
2283
2277
|
|
|
@@ -2368,26 +2362,25 @@
|
|
|
2368
2362
|
this.dispose = function () {
|
|
2369
2363
|
|
|
2370
2364
|
this.domElement.removeEventListener( 'contextmenu', contextmenu );
|
|
2371
|
-
this.domElement.removeEventListener( '
|
|
2372
|
-
this.domElement.removeEventListener( '
|
|
2373
|
-
this.domElement.removeEventListener( '
|
|
2365
|
+
this.domElement.removeEventListener( 'pointerdown', _pointerdown );
|
|
2366
|
+
this.domElement.removeEventListener( 'pointermove', _pointermove );
|
|
2367
|
+
this.domElement.removeEventListener( 'pointerup', _pointerup );
|
|
2374
2368
|
|
|
2375
2369
|
window.removeEventListener( 'keydown', _keydown );
|
|
2376
2370
|
window.removeEventListener( 'keyup', _keyup );
|
|
2377
2371
|
|
|
2378
2372
|
};
|
|
2379
2373
|
|
|
2380
|
-
const
|
|
2381
|
-
const
|
|
2382
|
-
const
|
|
2374
|
+
const _pointermove = this.pointermove.bind( this );
|
|
2375
|
+
const _pointerdown = this.pointerdown.bind( this );
|
|
2376
|
+
const _pointerup = this.pointerup.bind( this );
|
|
2383
2377
|
const _keydown = this.keydown.bind( this );
|
|
2384
2378
|
const _keyup = this.keyup.bind( this );
|
|
2385
2379
|
|
|
2386
2380
|
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
|
2387
|
-
|
|
2388
|
-
this.domElement.addEventListener( '
|
|
2389
|
-
this.domElement.addEventListener( '
|
|
2390
|
-
this.domElement.addEventListener( 'mouseup', _mouseup );
|
|
2381
|
+
this.domElement.addEventListener( 'pointerdown', _pointerdown );
|
|
2382
|
+
this.domElement.addEventListener( 'pointermove', _pointermove );
|
|
2383
|
+
this.domElement.addEventListener( 'pointerup', _pointerup );
|
|
2391
2384
|
|
|
2392
2385
|
window.addEventListener( 'keydown', _keydown );
|
|
2393
2386
|
window.addEventListener( 'keyup', _keyup );
|
|
@@ -2473,6 +2466,8 @@
|
|
|
2473
2466
|
|
|
2474
2467
|
}
|
|
2475
2468
|
|
|
2469
|
+
dispose() {}
|
|
2470
|
+
|
|
2476
2471
|
}
|
|
2477
2472
|
|
|
2478
2473
|
// Helper for passes that need to fill the viewport with a single quad.
|
|
@@ -2578,6 +2573,14 @@
|
|
|
2578
2573
|
|
|
2579
2574
|
}
|
|
2580
2575
|
|
|
2576
|
+
dispose() {
|
|
2577
|
+
|
|
2578
|
+
this.material.dispose();
|
|
2579
|
+
|
|
2580
|
+
this.fsQuad.dispose();
|
|
2581
|
+
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2581
2584
|
}
|
|
2582
2585
|
|
|
2583
2586
|
class MaskPass extends Pass {
|
|
@@ -2898,6 +2901,15 @@
|
|
|
2898
2901
|
|
|
2899
2902
|
}
|
|
2900
2903
|
|
|
2904
|
+
dispose() {
|
|
2905
|
+
|
|
2906
|
+
this.renderTarget1.dispose();
|
|
2907
|
+
this.renderTarget2.dispose();
|
|
2908
|
+
|
|
2909
|
+
this.copyPass.dispose();
|
|
2910
|
+
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2901
2913
|
}
|
|
2902
2914
|
|
|
2903
2915
|
// Helper for passes that need to fill the viewport with a single quad.
|
|
@@ -2989,14 +3001,12 @@
|
|
|
2989
3001
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
2990
3002
|
for (var i = 1; i < arguments.length; i++) {
|
|
2991
3003
|
var source = arguments[i];
|
|
2992
|
-
|
|
2993
3004
|
for (var key in source) {
|
|
2994
3005
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2995
3006
|
target[key] = source[key];
|
|
2996
3007
|
}
|
|
2997
3008
|
}
|
|
2998
3009
|
}
|
|
2999
|
-
|
|
3000
3010
|
return target;
|
|
3001
3011
|
};
|
|
3002
3012
|
return _extends.apply(this, arguments);
|
|
@@ -3006,7 +3016,6 @@
|
|
|
3006
3016
|
if (self === void 0) {
|
|
3007
3017
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
3008
3018
|
}
|
|
3009
|
-
|
|
3010
3019
|
return self;
|
|
3011
3020
|
}
|
|
3012
3021
|
|
|
@@ -3039,7 +3048,6 @@
|
|
|
3039
3048
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
3040
3049
|
if (Reflect.construct.sham) return false;
|
|
3041
3050
|
if (typeof Proxy === "function") return true;
|
|
3042
|
-
|
|
3043
3051
|
try {
|
|
3044
3052
|
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
3045
3053
|
return true;
|
|
@@ -3061,30 +3069,23 @@
|
|
|
3061
3069
|
return instance;
|
|
3062
3070
|
};
|
|
3063
3071
|
}
|
|
3064
|
-
|
|
3065
3072
|
return _construct.apply(null, arguments);
|
|
3066
3073
|
}
|
|
3067
3074
|
|
|
3068
3075
|
function _wrapNativeSuper(Class) {
|
|
3069
3076
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
3070
|
-
|
|
3071
3077
|
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
3072
3078
|
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
3073
|
-
|
|
3074
3079
|
if (typeof Class !== "function") {
|
|
3075
3080
|
throw new TypeError("Super expression must either be null or a function");
|
|
3076
3081
|
}
|
|
3077
|
-
|
|
3078
3082
|
if (typeof _cache !== "undefined") {
|
|
3079
3083
|
if (_cache.has(Class)) return _cache.get(Class);
|
|
3080
|
-
|
|
3081
3084
|
_cache.set(Class, Wrapper);
|
|
3082
3085
|
}
|
|
3083
|
-
|
|
3084
3086
|
function Wrapper() {
|
|
3085
3087
|
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
3086
3088
|
}
|
|
3087
|
-
|
|
3088
3089
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
3089
3090
|
constructor: {
|
|
3090
3091
|
value: Wrapper,
|
|
@@ -3095,7 +3096,6 @@
|
|
|
3095
3096
|
});
|
|
3096
3097
|
return _setPrototypeOf(Wrapper, Class);
|
|
3097
3098
|
};
|
|
3098
|
-
|
|
3099
3099
|
return _wrapNativeSuper(Class);
|
|
3100
3100
|
}
|
|
3101
3101
|
|
|
@@ -4961,11 +4961,9 @@
|
|
|
4961
4961
|
state.extraRenderers.forEach(function (r) {
|
|
4962
4962
|
return r.render(state.scene, state.camera);
|
|
4963
4963
|
});
|
|
4964
|
-
|
|
4965
4964
|
if (state.enablePointerInteraction) {
|
|
4966
4965
|
// Update tooltip and trigger onHover events
|
|
4967
4966
|
var topObject = null;
|
|
4968
|
-
|
|
4969
4967
|
if (state.hoverDuringDrag || !state.isPointerDragging) {
|
|
4970
4968
|
var intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y).filter(function (d) {
|
|
4971
4969
|
return state.hoverFilter(d.object);
|
|
@@ -4976,14 +4974,12 @@
|
|
|
4976
4974
|
topObject = topIntersect ? topIntersect.object : null;
|
|
4977
4975
|
state.intersectionPoint = topIntersect ? topIntersect.point : null;
|
|
4978
4976
|
}
|
|
4979
|
-
|
|
4980
4977
|
if (topObject !== state.hoverObj) {
|
|
4981
4978
|
state.onHover(topObject, state.hoverObj);
|
|
4982
4979
|
state.toolTipElem.innerHTML = topObject ? index$1(state.tooltipContent)(topObject) || '' : '';
|
|
4983
4980
|
state.hoverObj = topObject;
|
|
4984
4981
|
}
|
|
4985
4982
|
}
|
|
4986
|
-
|
|
4987
4983
|
exports$1.update(); // update camera animation tweens
|
|
4988
4984
|
}
|
|
4989
4985
|
|
|
@@ -4991,16 +4987,17 @@
|
|
|
4991
4987
|
},
|
|
4992
4988
|
getPointerPos: function getPointerPos(state) {
|
|
4993
4989
|
var _state$pointerPos = state.pointerPos,
|
|
4994
|
-
|
|
4995
|
-
|
|
4990
|
+
x = _state$pointerPos.x,
|
|
4991
|
+
y = _state$pointerPos.y;
|
|
4996
4992
|
return {
|
|
4997
4993
|
x: x,
|
|
4998
4994
|
y: y
|
|
4999
4995
|
};
|
|
5000
4996
|
},
|
|
5001
4997
|
cameraPosition: function cameraPosition(state, position, lookAt, transitionDuration) {
|
|
5002
|
-
var camera = state.camera;
|
|
4998
|
+
var camera = state.camera;
|
|
5003
4999
|
|
|
5000
|
+
// Setter
|
|
5004
5001
|
if (position && state.initialised) {
|
|
5005
5002
|
var finalPos = position;
|
|
5006
5003
|
var finalLookAt = lookAt || {
|
|
@@ -5008,7 +5005,6 @@
|
|
|
5008
5005
|
y: 0,
|
|
5009
5006
|
z: 0
|
|
5010
5007
|
};
|
|
5011
|
-
|
|
5012
5008
|
if (!transitionDuration) {
|
|
5013
5009
|
// no animation
|
|
5014
5010
|
setCameraPos(finalPos);
|
|
@@ -5016,31 +5012,31 @@
|
|
|
5016
5012
|
} else {
|
|
5017
5013
|
var camPos = Object.assign({}, camera.position);
|
|
5018
5014
|
var camLookAt = getLookAt();
|
|
5019
|
-
new exports$1.Tween(camPos).to(finalPos, transitionDuration).easing(exports$1.Easing.Quadratic.Out).onUpdate(setCameraPos).start();
|
|
5015
|
+
new exports$1.Tween(camPos).to(finalPos, transitionDuration).easing(exports$1.Easing.Quadratic.Out).onUpdate(setCameraPos).start();
|
|
5020
5016
|
|
|
5017
|
+
// Face direction in 1/3rd of time
|
|
5021
5018
|
new exports$1.Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(exports$1.Easing.Quadratic.Out).onUpdate(setLookAt).start();
|
|
5022
5019
|
}
|
|
5023
|
-
|
|
5024
5020
|
return this;
|
|
5025
|
-
}
|
|
5026
|
-
|
|
5021
|
+
}
|
|
5027
5022
|
|
|
5023
|
+
// Getter
|
|
5028
5024
|
return Object.assign({}, camera.position, {
|
|
5029
5025
|
lookAt: getLookAt()
|
|
5030
|
-
});
|
|
5026
|
+
});
|
|
5027
|
+
|
|
5028
|
+
//
|
|
5031
5029
|
|
|
5032
5030
|
function setCameraPos(pos) {
|
|
5033
5031
|
var x = pos.x,
|
|
5034
|
-
|
|
5035
|
-
|
|
5032
|
+
y = pos.y,
|
|
5033
|
+
z = pos.z;
|
|
5036
5034
|
if (x !== undefined) camera.position.x = x;
|
|
5037
5035
|
if (y !== undefined) camera.position.y = y;
|
|
5038
5036
|
if (z !== undefined) camera.position.z = z;
|
|
5039
5037
|
}
|
|
5040
|
-
|
|
5041
5038
|
function setLookAt(lookAt) {
|
|
5042
5039
|
var lookAtVect = new three.Vector3(lookAt.x, lookAt.y, lookAt.z);
|
|
5043
|
-
|
|
5044
5040
|
if (state.controls.target) {
|
|
5045
5041
|
state.controls.target = lookAtVect;
|
|
5046
5042
|
} else {
|
|
@@ -5056,11 +5052,9 @@
|
|
|
5056
5052
|
zoomToFit: function zoomToFit(state) {
|
|
5057
5053
|
var transitionDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
5058
5054
|
var padding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
5059
|
-
|
|
5060
5055
|
for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
5061
5056
|
bboxArgs[_key - 3] = arguments[_key];
|
|
5062
5057
|
}
|
|
5063
|
-
|
|
5064
5058
|
return this.fitToBbox(this.getBbox.apply(this, bboxArgs), transitionDuration, padding);
|
|
5065
5059
|
},
|
|
5066
5060
|
fitToBbox: function fitToBbox(state, bbox) {
|
|
@@ -5068,31 +5062,27 @@
|
|
|
5068
5062
|
var padding = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
|
|
5069
5063
|
// based on https://discourse.threejs.org/t/camera-zoom-to-fit-object/936/24
|
|
5070
5064
|
var camera = state.camera;
|
|
5071
|
-
|
|
5072
5065
|
if (bbox) {
|
|
5073
5066
|
var center = new three.Vector3(0, 0, 0); // reset camera aim to center
|
|
5074
|
-
|
|
5075
5067
|
var maxBoxSide = Math.max.apply(Math, _toConsumableArray(Object.entries(bbox).map(function (_ref) {
|
|
5076
5068
|
var _ref2 = _slicedToArray$1(_ref, 2),
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5069
|
+
coordType = _ref2[0],
|
|
5070
|
+
coords = _ref2[1];
|
|
5080
5071
|
return Math.max.apply(Math, _toConsumableArray(coords.map(function (c) {
|
|
5081
5072
|
return Math.abs(center[coordType] - c);
|
|
5082
5073
|
})));
|
|
5083
|
-
}))) * 2;
|
|
5074
|
+
}))) * 2;
|
|
5084
5075
|
|
|
5076
|
+
// find distance that fits whole bbox within padded fov
|
|
5085
5077
|
var paddedFov = (1 - padding * 2 / state.height) * camera.fov;
|
|
5086
5078
|
var fitHeightDistance = maxBoxSide / Math.atan(paddedFov * Math.PI / 180);
|
|
5087
5079
|
var fitWidthDistance = fitHeightDistance / camera.aspect;
|
|
5088
5080
|
var distance = Math.max(fitHeightDistance, fitWidthDistance);
|
|
5089
|
-
|
|
5090
5081
|
if (distance > 0) {
|
|
5091
5082
|
var newCameraPosition = center.clone().sub(camera.position).normalize().multiplyScalar(-distance);
|
|
5092
5083
|
this.cameraPosition(newCameraPosition, center, transitionDuration);
|
|
5093
5084
|
}
|
|
5094
5085
|
}
|
|
5095
|
-
|
|
5096
5086
|
return this;
|
|
5097
5087
|
},
|
|
5098
5088
|
getBbox: function getBbox(state) {
|
|
@@ -5104,8 +5094,9 @@
|
|
|
5104
5094
|
if (!objs.length) return null;
|
|
5105
5095
|
objs.forEach(function (obj) {
|
|
5106
5096
|
return box.expandByObject(obj);
|
|
5107
|
-
});
|
|
5097
|
+
});
|
|
5108
5098
|
|
|
5099
|
+
// extract global x,y,z min/max
|
|
5109
5100
|
return Object.assign.apply(Object, _toConsumableArray(['x', 'y', 'z'].map(function (c) {
|
|
5110
5101
|
return _defineProperty({}, c, [box.min[c], box.max[c]]);
|
|
5111
5102
|
})));
|
|
@@ -5113,7 +5104,6 @@
|
|
|
5113
5104
|
getScreenCoords: function getScreenCoords(state, x, y, z) {
|
|
5114
5105
|
var vec = new three.Vector3(x, y, z);
|
|
5115
5106
|
vec.project(this.camera()); // project to the camera plane
|
|
5116
|
-
|
|
5117
5107
|
return {
|
|
5118
5108
|
// align relative pos to canvas dimensions
|
|
5119
5109
|
x: (vec.x + 1) * state.width / 2,
|
|
@@ -5131,7 +5121,6 @@
|
|
|
5131
5121
|
var relCoords = new three.Vector2(x / state.width * 2 - 1, -(y / state.height) * 2 + 1);
|
|
5132
5122
|
var raycaster = new three.Raycaster();
|
|
5133
5123
|
raycaster.params.Line.threshold = state.lineHoverPrecision; // set linePrecision
|
|
5134
|
-
|
|
5135
5124
|
raycaster.setFromCamera(relCoords, state.camera);
|
|
5136
5125
|
return raycaster.intersectObjects(state.objects, true);
|
|
5137
5126
|
},
|
|
@@ -5153,8 +5142,8 @@
|
|
|
5153
5142
|
tbControls: function tbControls(state) {
|
|
5154
5143
|
return state.controls;
|
|
5155
5144
|
} // to be deprecated
|
|
5156
|
-
|
|
5157
5145
|
},
|
|
5146
|
+
|
|
5158
5147
|
stateInit: function stateInit() {
|
|
5159
5148
|
return {
|
|
5160
5149
|
scene: new three.Scene(),
|
|
@@ -5164,22 +5153,23 @@
|
|
|
5164
5153
|
},
|
|
5165
5154
|
init: function init(domNode, state) {
|
|
5166
5155
|
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
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;
|
|
5176
5164
|
// Wipe DOM
|
|
5177
|
-
domNode.innerHTML = '';
|
|
5165
|
+
domNode.innerHTML = '';
|
|
5178
5166
|
|
|
5167
|
+
// Add relative container
|
|
5179
5168
|
domNode.appendChild(state.container = document.createElement('div'));
|
|
5180
5169
|
state.container.className = 'scene-container';
|
|
5181
|
-
state.container.style.position = 'relative';
|
|
5170
|
+
state.container.style.position = 'relative';
|
|
5182
5171
|
|
|
5172
|
+
// Add nav info section
|
|
5183
5173
|
state.container.appendChild(state.navInfo = document.createElement('div'));
|
|
5184
5174
|
state.navInfo.className = 'scene-nav-info';
|
|
5185
5175
|
state.navInfo.textContent = {
|
|
@@ -5187,44 +5177,46 @@
|
|
|
5187
5177
|
trackball: 'Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan',
|
|
5188
5178
|
fly: 'WASD: move, R|F: up | down, Q|E: roll, up|down: pitch, left|right: yaw'
|
|
5189
5179
|
}[controlType] || '';
|
|
5190
|
-
state.navInfo.style.display = state.showNavInfo ? null : 'none';
|
|
5180
|
+
state.navInfo.style.display = state.showNavInfo ? null : 'none';
|
|
5191
5181
|
|
|
5182
|
+
// Setup tooltip
|
|
5192
5183
|
state.toolTipElem = document.createElement('div');
|
|
5193
5184
|
state.toolTipElem.classList.add('scene-tooltip');
|
|
5194
|
-
state.container.appendChild(state.toolTipElem);
|
|
5185
|
+
state.container.appendChild(state.toolTipElem);
|
|
5195
5186
|
|
|
5187
|
+
// Capture pointer coords on move or touchstart
|
|
5196
5188
|
state.pointerPos = new three.Vector2();
|
|
5197
5189
|
state.pointerPos.x = -2; // Initialize off canvas
|
|
5198
|
-
|
|
5199
5190
|
state.pointerPos.y = -2;
|
|
5200
5191
|
['pointermove', 'pointerdown'].forEach(function (evType) {
|
|
5201
5192
|
return state.container.addEventListener(evType, function (ev) {
|
|
5202
5193
|
// track click state
|
|
5203
|
-
evType === 'pointerdown' && (state.isPointerPressed = true);
|
|
5194
|
+
evType === 'pointerdown' && (state.isPointerPressed = true);
|
|
5204
5195
|
|
|
5196
|
+
// detect point drag
|
|
5205
5197
|
!state.isPointerDragging && ev.type === 'pointermove' && (ev.pressure > 0 || state.isPointerPressed) // ev.pressure always 0 on Safari, so we used the isPointerPressed tracker
|
|
5206
5198
|
&& (ev.pointerType !== 'touch' || ev.movementX === undefined || [ev.movementX, ev.movementY].some(function (m) {
|
|
5207
5199
|
return Math.abs(m) > 1;
|
|
5208
5200
|
})) // relax drag trigger sensitivity on touch events
|
|
5209
5201
|
&& (state.isPointerDragging = true);
|
|
5210
|
-
|
|
5211
5202
|
if (state.enablePointerInteraction) {
|
|
5212
5203
|
// update the pointer pos
|
|
5213
5204
|
var offset = getOffset(state.container);
|
|
5214
5205
|
state.pointerPos.x = ev.pageX - offset.left;
|
|
5215
|
-
state.pointerPos.y = ev.pageY - offset.top;
|
|
5206
|
+
state.pointerPos.y = ev.pageY - offset.top;
|
|
5216
5207
|
|
|
5208
|
+
// Move tooltip
|
|
5217
5209
|
state.toolTipElem.style.top = "".concat(state.pointerPos.y, "px");
|
|
5218
|
-
state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px");
|
|
5219
|
-
|
|
5220
|
-
state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat(
|
|
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
|
|
5221
5214
|
state.height - state.pointerPos.y < 100 ? 'calc(-100% - 8px)' : '21px', ")");
|
|
5222
5215
|
}
|
|
5223
|
-
|
|
5224
5216
|
function getOffset(el) {
|
|
5225
5217
|
var rect = el.getBoundingClientRect(),
|
|
5226
|
-
|
|
5227
|
-
|
|
5218
|
+
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
|
|
5219
|
+
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
5228
5220
|
return {
|
|
5229
5221
|
top: rect.top + scrollTop,
|
|
5230
5222
|
left: rect.left + scrollLeft
|
|
@@ -5233,11 +5225,11 @@
|
|
|
5233
5225
|
}, {
|
|
5234
5226
|
passive: true
|
|
5235
5227
|
});
|
|
5236
|
-
});
|
|
5228
|
+
});
|
|
5237
5229
|
|
|
5230
|
+
// Handle click events on objs
|
|
5238
5231
|
state.container.addEventListener('pointerup', function (ev) {
|
|
5239
5232
|
state.isPointerPressed = false;
|
|
5240
|
-
|
|
5241
5233
|
if (state.isPointerDragging) {
|
|
5242
5234
|
state.isPointerDragging = false;
|
|
5243
5235
|
if (!state.clickAfterDrag) return; // don't trigger onClick after pointer drag (camera motion via controls)
|
|
@@ -5262,16 +5254,17 @@
|
|
|
5262
5254
|
|
|
5263
5255
|
state.container.addEventListener('contextmenu', function (ev) {
|
|
5264
5256
|
if (state.onRightClick) ev.preventDefault(); // prevent default contextmenu behavior and allow pointerup to fire instead
|
|
5265
|
-
});
|
|
5257
|
+
});
|
|
5266
5258
|
|
|
5259
|
+
// Setup renderer, camera and controls
|
|
5267
5260
|
state.renderer = new three.WebGLRenderer(Object.assign({
|
|
5268
5261
|
antialias: true,
|
|
5269
5262
|
alpha: true
|
|
5270
5263
|
}, rendererConfig));
|
|
5271
5264
|
state.renderer.setPixelRatio(Math.min(2, window.devicePixelRatio)); // clamp device pixel ratio
|
|
5265
|
+
state.container.appendChild(state.renderer.domElement);
|
|
5272
5266
|
|
|
5273
|
-
|
|
5274
|
-
|
|
5267
|
+
// Setup extra renderers
|
|
5275
5268
|
state.extraRenderers = extraRenderers;
|
|
5276
5269
|
state.extraRenderers.forEach(function (r) {
|
|
5277
5270
|
// overlay them on top of main renderer
|
|
@@ -5279,24 +5272,23 @@
|
|
|
5279
5272
|
r.domElement.style.top = '0px';
|
|
5280
5273
|
r.domElement.style.pointerEvents = 'none';
|
|
5281
5274
|
state.container.appendChild(r.domElement);
|
|
5282
|
-
});
|
|
5275
|
+
});
|
|
5283
5276
|
|
|
5277
|
+
// configure post-processing composer
|
|
5284
5278
|
state.postProcessingComposer = new EffectComposer(state.renderer);
|
|
5285
5279
|
state.postProcessingComposer.addPass(new RenderPass(state.scene, state.camera)); // render scene as first pass
|
|
5286
|
-
// configure controls
|
|
5287
5280
|
|
|
5281
|
+
// configure controls
|
|
5288
5282
|
state.controls = new {
|
|
5289
5283
|
trackball: TrackballControls,
|
|
5290
5284
|
orbit: OrbitControls,
|
|
5291
5285
|
fly: FlyControls
|
|
5292
5286
|
}[controlType](state.camera, state.renderer.domElement);
|
|
5293
|
-
|
|
5294
5287
|
if (controlType === 'fly') {
|
|
5295
5288
|
state.controls.movementSpeed = 300;
|
|
5296
5289
|
state.controls.rollSpeed = Math.PI / 6;
|
|
5297
5290
|
state.controls.dragToLook = true;
|
|
5298
5291
|
}
|
|
5299
|
-
|
|
5300
5292
|
if (controlType === 'trackball' || controlType === 'orbit') {
|
|
5301
5293
|
state.controls.minDistance = 0.1;
|
|
5302
5294
|
state.controls.maxDistance = state.skyRadius;
|
|
@@ -5313,14 +5305,14 @@
|
|
|
5313
5305
|
state.controlsDragging = false;
|
|
5314
5306
|
});
|
|
5315
5307
|
}
|
|
5316
|
-
|
|
5317
5308
|
[state.renderer, state.postProcessingComposer].concat(_toConsumableArray(state.extraRenderers)).forEach(function (r) {
|
|
5318
5309
|
return r.setSize(state.width, state.height);
|
|
5319
5310
|
});
|
|
5320
5311
|
state.camera.aspect = state.width / state.height;
|
|
5321
5312
|
state.camera.updateProjectionMatrix();
|
|
5322
|
-
state.camera.position.z = 1000;
|
|
5313
|
+
state.camera.position.z = 1000;
|
|
5323
5314
|
|
|
5315
|
+
// add sky
|
|
5324
5316
|
state.scene.add(state.skysphere = new three.Mesh());
|
|
5325
5317
|
state.skysphere.visible = false;
|
|
5326
5318
|
state.loadComplete = state.scene.visible = !waitForLoadComplete;
|
|
@@ -5337,20 +5329,17 @@
|
|
|
5337
5329
|
state.camera.aspect = state.width / state.height;
|
|
5338
5330
|
state.camera.updateProjectionMatrix();
|
|
5339
5331
|
}
|
|
5340
|
-
|
|
5341
5332
|
if (changedProps.hasOwnProperty('skyRadius') && state.skyRadius) {
|
|
5342
5333
|
state.controls.hasOwnProperty('maxDistance') && changedProps.skyRadius && (state.controls.maxDistance = Math.min(state.controls.maxDistance, state.skyRadius));
|
|
5343
5334
|
state.camera.far = state.skyRadius * 2.5;
|
|
5344
5335
|
state.camera.updateProjectionMatrix();
|
|
5345
5336
|
state.skysphere.geometry = new three.SphereGeometry(state.skyRadius);
|
|
5346
5337
|
}
|
|
5347
|
-
|
|
5348
5338
|
if (changedProps.hasOwnProperty('backgroundColor')) {
|
|
5349
5339
|
var alpha = parseToRgb(state.backgroundColor).alpha;
|
|
5350
5340
|
if (alpha === undefined) alpha = 1;
|
|
5351
5341
|
state.renderer.setClearColor(new three.Color(curriedOpacify$1(1, state.backgroundColor)), alpha);
|
|
5352
5342
|
}
|
|
5353
|
-
|
|
5354
5343
|
if (changedProps.hasOwnProperty('backgroundImageUrl')) {
|
|
5355
5344
|
if (!state.backgroundImageUrl) {
|
|
5356
5345
|
state.skysphere.visible = false;
|
|
@@ -5362,26 +5351,25 @@
|
|
|
5362
5351
|
map: texture,
|
|
5363
5352
|
side: three.BackSide
|
|
5364
5353
|
});
|
|
5365
|
-
state.skysphere.visible = true;
|
|
5354
|
+
state.skysphere.visible = true;
|
|
5366
5355
|
|
|
5356
|
+
// triggered when background image finishes loading (asynchronously to allow 1 frame to load texture)
|
|
5367
5357
|
state.onBackgroundImageLoaded && setTimeout(state.onBackgroundImageLoaded);
|
|
5368
5358
|
!state.loadComplete && finishLoad();
|
|
5369
5359
|
});
|
|
5370
5360
|
}
|
|
5371
5361
|
}
|
|
5372
|
-
|
|
5373
5362
|
changedProps.hasOwnProperty('showNavInfo') && (state.navInfo.style.display = state.showNavInfo ? null : 'none');
|
|
5374
|
-
|
|
5375
5363
|
if (changedProps.hasOwnProperty('objects')) {
|
|
5376
5364
|
(changedProps.objects || []).forEach(function (obj) {
|
|
5377
5365
|
return state.scene.remove(obj);
|
|
5378
5366
|
}); // Clear the place
|
|
5379
|
-
|
|
5380
5367
|
state.objects.forEach(function (obj) {
|
|
5381
5368
|
return state.scene.add(obj);
|
|
5382
5369
|
}); // Add to scene
|
|
5383
|
-
}
|
|
5370
|
+
}
|
|
5384
5371
|
|
|
5372
|
+
//
|
|
5385
5373
|
|
|
5386
5374
|
function finishLoad() {
|
|
5387
5375
|
state.loadComplete = state.scene.visible = true;
|