@vitrosoftware/common-ui-ts 1.1.121 → 1.1.123
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/css/std/controls/checkbox/checkbox.css +4 -0
- package/css/std/controls/checkbox/img/checkbox-indeterminate.svg +4 -0
- package/css/std/controls/date-picker/date-picker.css +1 -25
- package/css/std/controls/dxf-viewer/annotation.css +85 -0
- package/css/std/controls/dxf-viewer/common.css +24 -0
- package/css/std/controls/dxf-viewer/dxf-viewer-index.css +14081 -0
- package/css/std/controls/dxf-viewer/dxf-viewer.css +194 -0
- package/css/std/controls/dxf-viewer/img/cancel-dark-grey.svg +5 -0
- package/css/std/controls/dxf-viewer/img/collapse-bottom.svg +5 -0
- package/css/std/controls/dxf-viewer/img/collapse-up-blue.svg +5 -0
- package/css/std/controls/dxf-viewer/img/delete-active.svg +11 -0
- package/css/std/controls/dxf-viewer/img/delete.svg +11 -0
- package/css/std/controls/dxf-viewer/img/draw-annotation.svg +3 -0
- package/css/std/controls/dxf-viewer/img/invisible-eye.svg +4 -0
- package/css/std/controls/dxf-viewer/img/show-annotation.svg +3 -0
- package/css/std/controls/dxf-viewer/img/sidebar-layers-toggle.svg +6 -0
- package/css/std/controls/dxf-viewer/img/sidebar-notes-toggle.svg +5 -0
- package/css/std/controls/dxf-viewer/img/sidebar-resizer.svg +6 -0
- package/css/std/controls/dxf-viewer/img/sidebar-toggle.svg +7 -0
- package/css/std/controls/dxf-viewer/img/visible-eye.svg +4 -0
- package/css/std/controls/dxf-viewer/img/zoom-in.svg +6 -0
- package/css/std/controls/dxf-viewer/img/zoom-out.svg +5 -0
- package/css/std/controls/dxf-viewer/layer-list.css +104 -0
- package/css/std/controls/dxf-viewer/panel.css +34 -0
- package/css/std/controls/dxf-viewer/prop-inspector.css +102 -0
- package/css/std/controls/dxf-viewer/select.css +111 -0
- package/css/std/controls/dxf-viewer/sidebar.css +190 -0
- package/css/std/controls/dxf-viewer/thumbnail-list.css +65 -0
- package/css/std/controls/dxf-viewer/toolbar.css +117 -0
- package/css/std/controls/dxf-viewer/treeview.css +3 -0
- package/css/std/controls/dxf-viewer/treeview.panel.css +108 -0
- package/css/std/controls/error-message/error-message.css +22 -0
- package/css/std/controls/image-picker/image-picker.css +0 -26
- package/css/std/controls/input/input.css +1 -24
- package/css/std/controls/issue-tile/issue-tile-header.css +1 -0
- package/css/std/controls/login/ntlm-authentication-form.css +9 -12
- package/css/std/controls/lookup-picker/lookup-picker-value-list.css +38 -2
- package/css/std/controls/lookup-picker/lookup-picker.css +1 -25
- package/css/std/controls/table-view/treegrid-context-menu.css +44 -18
- package/css/std/controls/table-view/treegrid-message.css +4 -4
- package/css/std/controls/time-picker/time-picker.css +1 -25
- package/dist/index.css +81 -143
- package/dist/index.js +15137 -489
- package/dist/index.js.map +1 -1
- package/dist/src/controls/Checkbox/Checkbox.d.ts +1 -0
- package/dist/src/controls/DxfViewer/DxfViewer.d.ts +6 -0
- package/dist/src/controls/DxfViewer/DxfViewerContext.d.ts +31 -0
- package/dist/src/controls/DxfViewer/Layer.d.ts +9 -0
- package/dist/src/controls/DxfViewer/LayerList.d.ts +11 -0
- package/dist/src/controls/DxfViewer/Thumbnail.d.ts +7 -0
- package/dist/src/controls/DxfViewer/ThumbnailList.d.ts +6 -0
- package/dist/src/controls/DxfViewer/Viewer.d.ts +6 -0
- package/dist/src/controls/ErrorMessage/ErrorMessage.d.ts +6 -0
- package/dist/src/controls/Login/FormRef.d.ts +3 -0
- package/dist/src/controls/Login/LoginConstants.d.ts +2 -1
- package/dist/src/controls/Login/LoginFormRef.d.ts +2 -2
- package/dist/src/controls/Login/NTLMAuthenticationForm.d.ts +5 -2
- package/dist/src/controls/LookupPicker/LookupPicker.d.ts +2 -0
- package/dist/src/controls/LookupPicker/ValueList.d.ts +2 -0
- package/dist/src/controls/TableView/TableViewConstants.d.ts +11 -0
- package/dist/src/controls/TableView/TreeGridTableViewContextImpl.d.ts +1 -0
- package/dist/src/controls/TreeView/TreeView.d.ts +4 -0
- package/dist/src/controls/TreeView/TreeViewConfig.d.ts +3 -0
- package/dist/src/controls/TreeView/TreeViewConstants.d.ts +2 -1
- package/dist/src/index.d.ts +7 -1
- package/lib/dxf-viewer/BatchingKey.js +91 -0
- package/lib/dxf-viewer/DxfFetcher.js +39 -0
- package/lib/dxf-viewer/DxfScene.js +2695 -0
- package/lib/dxf-viewer/DxfViewer.js +1056 -0
- package/lib/dxf-viewer/DxfWorker.js +229 -0
- package/lib/dxf-viewer/DynamicBuffer.js +100 -0
- package/lib/dxf-viewer/HatchCalculator.js +345 -0
- package/lib/dxf-viewer/LinearDimension.js +323 -0
- package/lib/dxf-viewer/MTextFormatParser.js +211 -0
- package/lib/dxf-viewer/MaterialKey.js +37 -0
- package/lib/dxf-viewer/OrbitControls.js +1253 -0
- package/lib/dxf-viewer/Pattern.js +94 -0
- package/lib/dxf-viewer/RBTree.js +471 -0
- package/lib/dxf-viewer/TextRenderer.js +1038 -0
- package/lib/dxf-viewer/index.js +42 -0
- package/lib/dxf-viewer/math/Matrix2.js +77 -0
- package/lib/dxf-viewer/math/utils.js +59 -0
- package/lib/dxf-viewer/parser/AutoCadColorIndex.js +265 -0
- package/lib/dxf-viewer/parser/DimStyleCodes.js +33 -0
- package/lib/dxf-viewer/parser/DxfArrayScanner.js +143 -0
- package/lib/dxf-viewer/parser/DxfParser.js +980 -0
- package/lib/dxf-viewer/parser/ExtendedDataParse-My.js +91 -0
- package/lib/dxf-viewer/parser/ExtendedDataParser.js +123 -0
- package/lib/dxf-viewer/parser/ParseHelpers.js +142 -0
- package/lib/dxf-viewer/parser/entities/3dface.js +83 -0
- package/lib/dxf-viewer/parser/entities/arc.js +38 -0
- package/lib/dxf-viewer/parser/entities/attdef.js +89 -0
- package/lib/dxf-viewer/parser/entities/attrib.js +34 -0
- package/lib/dxf-viewer/parser/entities/attribute.js +109 -0
- package/lib/dxf-viewer/parser/entities/circle.js +43 -0
- package/lib/dxf-viewer/parser/entities/dimension.js +72 -0
- package/lib/dxf-viewer/parser/entities/ellipse.js +46 -0
- package/lib/dxf-viewer/parser/entities/hatch.js +343 -0
- package/lib/dxf-viewer/parser/entities/insert.js +62 -0
- package/lib/dxf-viewer/parser/entities/leader.js +84 -0
- package/lib/dxf-viewer/parser/entities/line.js +34 -0
- package/lib/dxf-viewer/parser/entities/lwpolyline.js +100 -0
- package/lib/dxf-viewer/parser/entities/mtext.js +54 -0
- package/lib/dxf-viewer/parser/entities/point.js +35 -0
- package/lib/dxf-viewer/parser/entities/polyline.js +92 -0
- package/lib/dxf-viewer/parser/entities/solid.js +40 -0
- package/lib/dxf-viewer/parser/entities/spline.js +70 -0
- package/lib/dxf-viewer/parser/entities/text.js +47 -0
- package/lib/dxf-viewer/parser/entities/vertex.js +62 -0
- package/lib/dxf-viewer/parser/entities/viewport.js +56 -0
- package/lib/dxf-viewer/parser/objects/dictionary.js +29 -0
- package/lib/dxf-viewer/parser/objects/layout.js +35 -0
- package/lib/dxf-viewer/parser/objects/xrecord.js +29 -0
- package/lib/opentype/opentype.module.js +14571 -0
- package/lib/three/CSS2DRenderer.js +235 -0
- package/lib/three/three.module.js +49912 -0
- package/lib/xeokit/xeokit-sdk-2.6.10.es.js +136629 -0
- package/lib/xeokit/xeokit-sdk-2.6.10.min.es.js +299 -0
- package/package.json +12 -10
- package/src/controls/BimViewer/js/bim-viewer-models.js +93 -0
- package/src/controls/BimViewer/js/bim-viewer.js +194 -5
- package/src/controls/DxfViewer/js/dxf-viewer.js +3541 -0
- package/src/controls/PdfViewer/js/pdf-viewer.js +1 -1
- package/css/std/controls/input/img/error-message.svg +0 -6
- package/css/std/controls/lookup-picker/img/error-message.svg +0 -6
- package/css/std/controls/time-picker/img/error-message.svg +0 -6
- package/dist/src/controls/ActionHandler/ActionInfo.d.ts +0 -12
- package/dist/src/controls/ActionHandler/ActionInfoItem.d.ts +0 -13
- package/dist/src/controls/ActionHandler/UpdatingPopover.d.ts +0 -2
- package/dist/src/controls/Dialog/DialogButton.d.ts +0 -8
- package/dist/src/controls/Dialog/DialogCloseButton.d.ts +0 -8
- package/dist/src/controls/Icon/Icon.d.ts +0 -11
- package/dist/src/controls/Search/Input.d.ts +0 -21
- package/dist/src/controls/Search/SearchConstants.d.ts +0 -4
- /package/css/std/controls/{date-picker → error-message}/img/error-message.svg +0 -0
|
@@ -0,0 +1,1253 @@
|
|
|
1
|
+
// Forked from three/examples/js/controls/OrbitControls.js to implement additional features (e.g.
|
|
2
|
+
// zooming on cursor).
|
|
3
|
+
|
|
4
|
+
import * as THREE from "/resource/dxfViewer/js/three/three.module.js"
|
|
5
|
+
|
|
6
|
+
// This set of controls performs orbiting, dollying (zooming), and panning.
|
|
7
|
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
|
8
|
+
//
|
|
9
|
+
// Orbit - left mouse / touch: one-finger move
|
|
10
|
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
|
11
|
+
// Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
|
|
12
|
+
|
|
13
|
+
export const OrbitControls = function ( object, domElement ) {
|
|
14
|
+
|
|
15
|
+
if ( domElement === undefined ) console.warn( 'THREE.OrbitControls: The second parameter "domElement" is now mandatory.' );
|
|
16
|
+
if ( domElement === document ) console.error( 'THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.' );
|
|
17
|
+
|
|
18
|
+
this.object = object;
|
|
19
|
+
this.domElement = domElement;
|
|
20
|
+
|
|
21
|
+
// Set to false to disable this control
|
|
22
|
+
this.enabled = true;
|
|
23
|
+
|
|
24
|
+
// "target" sets the location of focus, where the object orbits around
|
|
25
|
+
this.target = new THREE.Vector3();
|
|
26
|
+
|
|
27
|
+
// How far you can dolly in and out ( PerspectiveCamera only )
|
|
28
|
+
this.minDistance = 0;
|
|
29
|
+
this.maxDistance = Infinity;
|
|
30
|
+
|
|
31
|
+
// How far you can zoom in and out ( OrthographicCamera only )
|
|
32
|
+
this.minZoom = 0;
|
|
33
|
+
this.maxZoom = Infinity;
|
|
34
|
+
|
|
35
|
+
// How far you can orbit vertically, upper and lower limits.
|
|
36
|
+
// Range is 0 to Math.PI radians.
|
|
37
|
+
this.minPolarAngle = 0; // radians
|
|
38
|
+
this.maxPolarAngle = Math.PI; // radians
|
|
39
|
+
|
|
40
|
+
// How far you can orbit horizontally, upper and lower limits.
|
|
41
|
+
// If set, the interval [ min, max ] must be a sub-interval of [ - 2 PI, 2 PI ], with ( max - min < 2 PI )
|
|
42
|
+
this.minAzimuthAngle = - Infinity; // radians
|
|
43
|
+
this.maxAzimuthAngle = Infinity; // radians
|
|
44
|
+
|
|
45
|
+
// Set to true to enable damping (inertia)
|
|
46
|
+
// If damping is enabled, you must call controls.update() in your animation loop
|
|
47
|
+
this.enableDamping = false;
|
|
48
|
+
this.dampingFactor = 0.05;
|
|
49
|
+
|
|
50
|
+
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
|
|
51
|
+
// Set to false to disable zooming
|
|
52
|
+
this.enableZoom = true;
|
|
53
|
+
this.zoomSpeed = 1.0;
|
|
54
|
+
this.mouseZoomSpeedFactor = 1;
|
|
55
|
+
|
|
56
|
+
// Set to false to disable rotating
|
|
57
|
+
this.enableRotate = true;
|
|
58
|
+
this.rotateSpeed = 1.0;
|
|
59
|
+
|
|
60
|
+
// Set to false to disable panning
|
|
61
|
+
this.enablePan = true;
|
|
62
|
+
this.panSpeed = 1.0;
|
|
63
|
+
this.screenSpacePanning = true; // if false, pan orthogonal to world-space direction camera.up
|
|
64
|
+
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
|
65
|
+
|
|
66
|
+
// Set to true to automatically rotate around the target
|
|
67
|
+
// If auto-rotate is enabled, you must call controls.update() in your animation loop
|
|
68
|
+
this.autoRotate = false;
|
|
69
|
+
this.autoRotateSpeed = 2.0; // 30 seconds per orbit when fps is 60
|
|
70
|
+
|
|
71
|
+
// The four arrow keys
|
|
72
|
+
this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
|
|
73
|
+
|
|
74
|
+
// Mouse buttons
|
|
75
|
+
this.mouseButtons = { LEFT: THREE.MOUSE.ROTATE, MIDDLE: THREE.MOUSE.DOLLY, RIGHT: THREE.MOUSE.PAN };
|
|
76
|
+
|
|
77
|
+
// Touch fingers
|
|
78
|
+
this.touches = { ONE: THREE.TOUCH.ROTATE, TWO: THREE.TOUCH.DOLLY_PAN };
|
|
79
|
+
|
|
80
|
+
// for reset
|
|
81
|
+
this.target0 = this.target.clone();
|
|
82
|
+
this.position0 = this.object.position.clone();
|
|
83
|
+
this.zoom0 = this.object.zoom;
|
|
84
|
+
|
|
85
|
+
// the target DOM element for key events
|
|
86
|
+
this._domElementKeyEvents = null;
|
|
87
|
+
|
|
88
|
+
//
|
|
89
|
+
// public methods
|
|
90
|
+
//
|
|
91
|
+
this.zoomIn = dollyIn;
|
|
92
|
+
this.zoomOut = dollyOut;
|
|
93
|
+
|
|
94
|
+
this.getPolarAngle = function () {
|
|
95
|
+
|
|
96
|
+
return spherical.phi;
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
this.getAzimuthalAngle = function () {
|
|
101
|
+
|
|
102
|
+
return spherical.theta;
|
|
103
|
+
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
this.listenToKeyEvents = function ( domElement ) {
|
|
107
|
+
|
|
108
|
+
domElement.addEventListener( 'keydown', onKeyDown );
|
|
109
|
+
this._domElementKeyEvents = domElement;
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
this.saveState = function () {
|
|
114
|
+
|
|
115
|
+
scope.target0.copy( scope.target );
|
|
116
|
+
scope.position0.copy( scope.object.position );
|
|
117
|
+
scope.zoom0 = scope.object.zoom;
|
|
118
|
+
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
this.reset = function () {
|
|
122
|
+
|
|
123
|
+
scope.target.copy( scope.target0 );
|
|
124
|
+
scope.object.position.copy( scope.position0 );
|
|
125
|
+
scope.object.zoom = scope.zoom0;
|
|
126
|
+
|
|
127
|
+
scope.object.updateProjectionMatrix();
|
|
128
|
+
scope.dispatchEvent( changeEvent );
|
|
129
|
+
|
|
130
|
+
scope.update();
|
|
131
|
+
|
|
132
|
+
state = STATE.NONE;
|
|
133
|
+
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// this method is exposed, but perhaps it would be better if we can make it private...
|
|
137
|
+
this.update = function () {
|
|
138
|
+
|
|
139
|
+
var offset = new THREE.Vector3();
|
|
140
|
+
|
|
141
|
+
// so camera.up is the orbit axis
|
|
142
|
+
var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
|
|
143
|
+
var quatInverse = quat.clone().invert();
|
|
144
|
+
|
|
145
|
+
var lastPosition = new THREE.Vector3();
|
|
146
|
+
var lastQuaternion = new THREE.Quaternion();
|
|
147
|
+
|
|
148
|
+
var twoPI = 2 * Math.PI;
|
|
149
|
+
|
|
150
|
+
return function update() {
|
|
151
|
+
|
|
152
|
+
var position = scope.object.position;
|
|
153
|
+
|
|
154
|
+
offset.copy( position ).sub( scope.target );
|
|
155
|
+
|
|
156
|
+
// rotate offset to "y-axis-is-up" space
|
|
157
|
+
offset.applyQuaternion( quat );
|
|
158
|
+
|
|
159
|
+
// angle from z-axis around y-axis
|
|
160
|
+
spherical.setFromVector3( offset );
|
|
161
|
+
|
|
162
|
+
if ( scope.autoRotate && state === STATE.NONE ) {
|
|
163
|
+
|
|
164
|
+
rotateLeft( getAutoRotationAngle() );
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if ( scope.enableDamping ) {
|
|
169
|
+
|
|
170
|
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
171
|
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
172
|
+
|
|
173
|
+
} else {
|
|
174
|
+
|
|
175
|
+
spherical.theta += sphericalDelta.theta;
|
|
176
|
+
spherical.phi += sphericalDelta.phi;
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// restrict theta to be between desired limits
|
|
181
|
+
|
|
182
|
+
var min = scope.minAzimuthAngle;
|
|
183
|
+
var max = scope.maxAzimuthAngle;
|
|
184
|
+
|
|
185
|
+
if ( isFinite( min ) && isFinite( max ) ) {
|
|
186
|
+
|
|
187
|
+
if ( min < - Math.PI ) min += twoPI; else if ( min > Math.PI ) min -= twoPI;
|
|
188
|
+
|
|
189
|
+
if ( max < - Math.PI ) max += twoPI; else if ( max > Math.PI ) max -= twoPI;
|
|
190
|
+
|
|
191
|
+
if ( min <= max ) {
|
|
192
|
+
|
|
193
|
+
spherical.theta = Math.max( min, Math.min( max, spherical.theta ) );
|
|
194
|
+
|
|
195
|
+
} else {
|
|
196
|
+
|
|
197
|
+
spherical.theta = ( spherical.theta > ( min + max ) / 2 ) ?
|
|
198
|
+
Math.max( min, spherical.theta ) :
|
|
199
|
+
Math.min( max, spherical.theta );
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// restrict phi to be between desired limits
|
|
206
|
+
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
|
207
|
+
|
|
208
|
+
spherical.makeSafe();
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
spherical.radius *= scale;
|
|
212
|
+
|
|
213
|
+
// restrict radius to be between desired limits
|
|
214
|
+
spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
|
|
215
|
+
|
|
216
|
+
// move target to panned location
|
|
217
|
+
|
|
218
|
+
if ( scope.enableDamping === true ) {
|
|
219
|
+
|
|
220
|
+
scope.target.addScaledVector( panOffset, scope.dampingFactor );
|
|
221
|
+
|
|
222
|
+
} else {
|
|
223
|
+
|
|
224
|
+
scope.target.add( panOffset );
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
offset.setFromSpherical( spherical );
|
|
229
|
+
|
|
230
|
+
// rotate offset back to "camera-up-vector-is-up" space
|
|
231
|
+
offset.applyQuaternion( quatInverse );
|
|
232
|
+
|
|
233
|
+
position.copy( scope.target ).add( offset );
|
|
234
|
+
|
|
235
|
+
scope.object.lookAt( scope.target );
|
|
236
|
+
|
|
237
|
+
if ( scope.enableDamping === true ) {
|
|
238
|
+
|
|
239
|
+
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
|
|
240
|
+
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
|
|
241
|
+
|
|
242
|
+
panOffset.multiplyScalar( 1 - scope.dampingFactor );
|
|
243
|
+
|
|
244
|
+
} else {
|
|
245
|
+
|
|
246
|
+
sphericalDelta.set( 0, 0, 0 );
|
|
247
|
+
|
|
248
|
+
panOffset.set( 0, 0, 0 );
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
scale = 1;
|
|
253
|
+
|
|
254
|
+
// update condition is:
|
|
255
|
+
// min(camera displacement, camera rotation in radians)^2 > EPS
|
|
256
|
+
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
|
257
|
+
|
|
258
|
+
if ( zoomChanged ||
|
|
259
|
+
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
|
260
|
+
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
|
|
261
|
+
|
|
262
|
+
scope.dispatchEvent( changeEvent );
|
|
263
|
+
|
|
264
|
+
lastPosition.copy( scope.object.position );
|
|
265
|
+
lastQuaternion.copy( scope.object.quaternion );
|
|
266
|
+
zoomChanged = false;
|
|
267
|
+
|
|
268
|
+
return true;
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return false;
|
|
273
|
+
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
}();
|
|
277
|
+
|
|
278
|
+
this.dispose = function () {
|
|
279
|
+
|
|
280
|
+
scope.domElement.removeEventListener( 'contextmenu', onContextMenu );
|
|
281
|
+
|
|
282
|
+
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
|
283
|
+
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
|
284
|
+
|
|
285
|
+
scope.domElement.removeEventListener( 'touchstart', onTouchStart );
|
|
286
|
+
scope.domElement.removeEventListener( 'touchend', onTouchEnd );
|
|
287
|
+
scope.domElement.removeEventListener( 'touchmove', onTouchMove );
|
|
288
|
+
|
|
289
|
+
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
|
290
|
+
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
if ( scope._domElementKeyEvents !== null ) {
|
|
294
|
+
|
|
295
|
+
scope._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
//scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
|
|
300
|
+
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
//
|
|
304
|
+
// internals
|
|
305
|
+
//
|
|
306
|
+
|
|
307
|
+
var scope = this;
|
|
308
|
+
|
|
309
|
+
var changeEvent = { type: 'change' };
|
|
310
|
+
var startEvent = { type: 'start' };
|
|
311
|
+
var endEvent = { type: 'end' };
|
|
312
|
+
|
|
313
|
+
var STATE = {
|
|
314
|
+
NONE: - 1,
|
|
315
|
+
ROTATE: 0,
|
|
316
|
+
DOLLY: 1,
|
|
317
|
+
PAN: 2,
|
|
318
|
+
TOUCH_ROTATE: 3,
|
|
319
|
+
TOUCH_PAN: 4,
|
|
320
|
+
TOUCH_DOLLY_PAN: 5,
|
|
321
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
var state = STATE.NONE;
|
|
325
|
+
|
|
326
|
+
var EPS = 0.000001;
|
|
327
|
+
|
|
328
|
+
// current position in spherical coordinates
|
|
329
|
+
var spherical = new THREE.Spherical();
|
|
330
|
+
var sphericalDelta = new THREE.Spherical();
|
|
331
|
+
|
|
332
|
+
var scale = 1;
|
|
333
|
+
var panOffset = new THREE.Vector3();
|
|
334
|
+
var zoomChanged = false;
|
|
335
|
+
|
|
336
|
+
var rotateStart = new THREE.Vector2();
|
|
337
|
+
var rotateEnd = new THREE.Vector2();
|
|
338
|
+
var rotateDelta = new THREE.Vector2();
|
|
339
|
+
|
|
340
|
+
var panStart = new THREE.Vector2();
|
|
341
|
+
var panEnd = new THREE.Vector2();
|
|
342
|
+
var panDelta = new THREE.Vector2();
|
|
343
|
+
|
|
344
|
+
var dollyCenter = new THREE.Vector2();
|
|
345
|
+
var dollyStart = new THREE.Vector2();
|
|
346
|
+
var dollyEnd = new THREE.Vector2();
|
|
347
|
+
var dollyDelta = new THREE.Vector2();
|
|
348
|
+
|
|
349
|
+
function getAutoRotationAngle() {
|
|
350
|
+
|
|
351
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function getZoomScale( isMouseMovement ) {
|
|
356
|
+
|
|
357
|
+
return Math.pow( 0.95, scope.zoomSpeed * ( isMouseMovement ? scope.mouseZoomSpeedFactor : 1 ));
|
|
358
|
+
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function rotateLeft( angle ) {
|
|
362
|
+
|
|
363
|
+
sphericalDelta.theta -= angle;
|
|
364
|
+
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function rotateUp( angle ) {
|
|
368
|
+
|
|
369
|
+
sphericalDelta.phi -= angle;
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
var panLeft = function () {
|
|
374
|
+
|
|
375
|
+
var v = new THREE.Vector3();
|
|
376
|
+
|
|
377
|
+
return function panLeft( distance, objectMatrix ) {
|
|
378
|
+
|
|
379
|
+
v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
|
|
380
|
+
v.multiplyScalar( - distance );
|
|
381
|
+
|
|
382
|
+
panOffset.add( v );
|
|
383
|
+
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
}();
|
|
387
|
+
|
|
388
|
+
var panUp = function () {
|
|
389
|
+
|
|
390
|
+
var v = new THREE.Vector3();
|
|
391
|
+
|
|
392
|
+
return function panUp( distance, objectMatrix ) {
|
|
393
|
+
|
|
394
|
+
if ( scope.screenSpacePanning === true ) {
|
|
395
|
+
|
|
396
|
+
v.setFromMatrixColumn( objectMatrix, 1 );
|
|
397
|
+
|
|
398
|
+
} else {
|
|
399
|
+
|
|
400
|
+
v.setFromMatrixColumn( objectMatrix, 0 );
|
|
401
|
+
v.crossVectors( scope.object.up, v );
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
v.multiplyScalar( distance );
|
|
406
|
+
|
|
407
|
+
panOffset.add( v );
|
|
408
|
+
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
}();
|
|
412
|
+
|
|
413
|
+
// deltaX and deltaY are in pixels; right and down are positive
|
|
414
|
+
var pan = function () {
|
|
415
|
+
|
|
416
|
+
var offset = new THREE.Vector3();
|
|
417
|
+
|
|
418
|
+
return function pan( deltaX, deltaY ) {
|
|
419
|
+
|
|
420
|
+
var element = scope.domElement;
|
|
421
|
+
|
|
422
|
+
if ( scope.object.isPerspectiveCamera ) {
|
|
423
|
+
|
|
424
|
+
// perspective
|
|
425
|
+
var position = scope.object.position;
|
|
426
|
+
offset.copy( position ).sub( scope.target );
|
|
427
|
+
var targetDistance = offset.length();
|
|
428
|
+
|
|
429
|
+
// half of the fov is center to top of screen
|
|
430
|
+
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
|
431
|
+
|
|
432
|
+
// we use only clientHeight here so aspect ratio does not distort speed
|
|
433
|
+
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
|
|
434
|
+
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
|
|
435
|
+
|
|
436
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
|
437
|
+
|
|
438
|
+
// orthographic
|
|
439
|
+
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom /
|
|
440
|
+
element.clientWidth / window.devicePixelRatio, scope.object.matrix );
|
|
441
|
+
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom /
|
|
442
|
+
element.clientHeight / window.devicePixelRatio, scope.object.matrix );
|
|
443
|
+
|
|
444
|
+
} else {
|
|
445
|
+
|
|
446
|
+
// camera neither orthographic nor perspective
|
|
447
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
|
448
|
+
scope.enablePan = false;
|
|
449
|
+
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
}();
|
|
455
|
+
|
|
456
|
+
function zoomPan( zoomRatio, zoomCenter) {
|
|
457
|
+
const panX = (zoomCenter.x - scope.domElement.width / 2) * (zoomRatio - 1) / zoomRatio
|
|
458
|
+
const panY = (zoomCenter.y - scope.domElement.height / 2) * (zoomRatio - 1) / zoomRatio
|
|
459
|
+
pan(-panX, -panY)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function dollyOut( dollyScale, zoomCenter ) {
|
|
463
|
+
|
|
464
|
+
if ( scope.object.isPerspectiveCamera ) {
|
|
465
|
+
|
|
466
|
+
scale /= dollyScale;
|
|
467
|
+
|
|
468
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
|
469
|
+
|
|
470
|
+
const newZoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
|
|
471
|
+
zoomPan(newZoom / scope.object.zoom, zoomCenter)
|
|
472
|
+
scope.object.zoom = newZoom
|
|
473
|
+
scope.object.updateProjectionMatrix();
|
|
474
|
+
zoomChanged = true;
|
|
475
|
+
|
|
476
|
+
} else {
|
|
477
|
+
|
|
478
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
479
|
+
scope.enableZoom = false;
|
|
480
|
+
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function dollyIn( dollyScale, zoomCenter ) {
|
|
486
|
+
|
|
487
|
+
if ( scope.object.isPerspectiveCamera ) {
|
|
488
|
+
|
|
489
|
+
scale *= dollyScale;
|
|
490
|
+
|
|
491
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
|
492
|
+
|
|
493
|
+
const newZoom =
|
|
494
|
+
Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
|
|
495
|
+
zoomPan(newZoom / scope.object.zoom, zoomCenter)
|
|
496
|
+
scope.object.zoom = newZoom;
|
|
497
|
+
scope.object.updateProjectionMatrix();
|
|
498
|
+
zoomChanged = true;
|
|
499
|
+
|
|
500
|
+
} else {
|
|
501
|
+
|
|
502
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
503
|
+
scope.enableZoom = false;
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
//
|
|
510
|
+
// event callbacks - update the object state
|
|
511
|
+
//
|
|
512
|
+
|
|
513
|
+
function handleMouseDownRotate( event ) {
|
|
514
|
+
|
|
515
|
+
rotateStart.set( event.clientX, event.clientY );
|
|
516
|
+
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function handleMouseDownDolly( event ) {
|
|
520
|
+
|
|
521
|
+
const canvasRect = scope.domElement.getBoundingClientRect();
|
|
522
|
+
dollyCenter.set( event.clientX - canvasRect.left, event.clientY - canvasRect.top );
|
|
523
|
+
dollyStart.set( event.clientX, event.clientY );
|
|
524
|
+
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function handleMouseDownPan( event ) {
|
|
528
|
+
|
|
529
|
+
panStart.set( event.clientX, event.clientY );
|
|
530
|
+
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function handleMouseMoveRotate( event ) {
|
|
534
|
+
|
|
535
|
+
rotateEnd.set( event.clientX, event.clientY );
|
|
536
|
+
|
|
537
|
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
|
538
|
+
|
|
539
|
+
var element = scope.domElement;
|
|
540
|
+
|
|
541
|
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
|
542
|
+
|
|
543
|
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
|
544
|
+
|
|
545
|
+
rotateStart.copy( rotateEnd );
|
|
546
|
+
|
|
547
|
+
scope.update();
|
|
548
|
+
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function handleMouseMoveDolly( event ) {
|
|
552
|
+
|
|
553
|
+
dollyEnd.set( event.clientX, event.clientY );
|
|
554
|
+
|
|
555
|
+
dollyDelta.subVectors( dollyEnd, dollyStart );
|
|
556
|
+
|
|
557
|
+
if ( dollyDelta.y > 0 ) {
|
|
558
|
+
|
|
559
|
+
dollyOut( getZoomScale(true), dollyCenter );
|
|
560
|
+
|
|
561
|
+
} else if ( dollyDelta.y < 0 ) {
|
|
562
|
+
|
|
563
|
+
dollyIn( getZoomScale(true), dollyCenter );
|
|
564
|
+
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
dollyStart.copy( dollyEnd );
|
|
568
|
+
|
|
569
|
+
scope.update();
|
|
570
|
+
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function handleMouseMovePan( event ) {
|
|
574
|
+
|
|
575
|
+
panEnd.set( event.clientX, event.clientY );
|
|
576
|
+
|
|
577
|
+
panDelta.subVectors( panEnd, panStart )
|
|
578
|
+
.multiplyScalar( scope.panSpeed * window.devicePixelRatio );
|
|
579
|
+
|
|
580
|
+
pan( panDelta.x, panDelta.y );
|
|
581
|
+
|
|
582
|
+
panStart.copy( panEnd );
|
|
583
|
+
|
|
584
|
+
scope.update();
|
|
585
|
+
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function handleMouseUp( /*event*/ ) {
|
|
589
|
+
|
|
590
|
+
// no-op
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function handleMouseWheel( event ) {
|
|
595
|
+
|
|
596
|
+
const canvasRect = scope.domElement.getBoundingClientRect()
|
|
597
|
+
const zoomCenter = new THREE.Vector2(
|
|
598
|
+
(event.clientX - canvasRect.left) * window.devicePixelRatio,
|
|
599
|
+
(event.clientY - canvasRect.top) * window.devicePixelRatio)
|
|
600
|
+
|
|
601
|
+
if ( event.deltaY < 0 ) {
|
|
602
|
+
|
|
603
|
+
dollyIn( getZoomScale(), zoomCenter );
|
|
604
|
+
|
|
605
|
+
} else if ( event.deltaY > 0 ) {
|
|
606
|
+
|
|
607
|
+
dollyOut( getZoomScale(), zoomCenter );
|
|
608
|
+
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
scope.update();
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function handleKeyDown( event ) {
|
|
616
|
+
|
|
617
|
+
var needsUpdate = false;
|
|
618
|
+
|
|
619
|
+
switch ( event.keyCode ) {
|
|
620
|
+
|
|
621
|
+
case scope.keys.UP:
|
|
622
|
+
pan( 0, scope.keyPanSpeed );
|
|
623
|
+
needsUpdate = true;
|
|
624
|
+
break;
|
|
625
|
+
|
|
626
|
+
case scope.keys.BOTTOM:
|
|
627
|
+
pan( 0, - scope.keyPanSpeed );
|
|
628
|
+
needsUpdate = true;
|
|
629
|
+
break;
|
|
630
|
+
|
|
631
|
+
case scope.keys.LEFT:
|
|
632
|
+
pan( scope.keyPanSpeed, 0 );
|
|
633
|
+
needsUpdate = true;
|
|
634
|
+
break;
|
|
635
|
+
|
|
636
|
+
case scope.keys.RIGHT:
|
|
637
|
+
pan( - scope.keyPanSpeed, 0 );
|
|
638
|
+
needsUpdate = true;
|
|
639
|
+
break;
|
|
640
|
+
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
if ( needsUpdate ) {
|
|
644
|
+
|
|
645
|
+
// prevent the browser from scrolling on cursor keys
|
|
646
|
+
event.preventDefault();
|
|
647
|
+
|
|
648
|
+
scope.update();
|
|
649
|
+
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function handleTouchStartRotate( event ) {
|
|
656
|
+
|
|
657
|
+
if ( event.touches.length == 1 ) {
|
|
658
|
+
|
|
659
|
+
rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
|
660
|
+
|
|
661
|
+
} else {
|
|
662
|
+
|
|
663
|
+
var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
|
|
664
|
+
var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
|
|
665
|
+
|
|
666
|
+
rotateStart.set( x, y );
|
|
667
|
+
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
function handleTouchStartPan( event ) {
|
|
673
|
+
|
|
674
|
+
if ( event.touches.length == 1 ) {
|
|
675
|
+
|
|
676
|
+
panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
|
677
|
+
|
|
678
|
+
} else {
|
|
679
|
+
|
|
680
|
+
var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
|
|
681
|
+
var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
|
|
682
|
+
|
|
683
|
+
panStart.set( x, y );
|
|
684
|
+
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function handleTouchStartDolly( event ) {
|
|
690
|
+
const canvasRect = scope.domElement.getBoundingClientRect();
|
|
691
|
+
dollyCenter.set(
|
|
692
|
+
(event.touches[0].clientX + event.touches[1].clientX) / 2 - canvasRect.left,
|
|
693
|
+
(event.touches[0].clientY + event.touches[1].clientY) / 2 - canvasRect.top )
|
|
694
|
+
.multiplyScalar(window.devicePixelRatio);
|
|
695
|
+
|
|
696
|
+
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
|
697
|
+
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
|
698
|
+
|
|
699
|
+
var distance = Math.sqrt( dx * dx + dy * dy );
|
|
700
|
+
|
|
701
|
+
dollyStart.set( 0, distance );
|
|
702
|
+
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function handleTouchStartDollyPan( event ) {
|
|
706
|
+
|
|
707
|
+
if ( scope.enableZoom ) handleTouchStartDolly( event );
|
|
708
|
+
|
|
709
|
+
if ( scope.enablePan ) handleTouchStartPan( event );
|
|
710
|
+
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function handleTouchStartDollyRotate( event ) {
|
|
714
|
+
|
|
715
|
+
if ( scope.enableZoom ) handleTouchStartDolly( event );
|
|
716
|
+
|
|
717
|
+
if ( scope.enableRotate ) handleTouchStartRotate( event );
|
|
718
|
+
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function handleTouchMoveRotate( event ) {
|
|
722
|
+
|
|
723
|
+
if ( event.touches.length == 1 ) {
|
|
724
|
+
|
|
725
|
+
rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
|
726
|
+
|
|
727
|
+
} else {
|
|
728
|
+
|
|
729
|
+
var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
|
|
730
|
+
var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
|
|
731
|
+
|
|
732
|
+
rotateEnd.set( x, y );
|
|
733
|
+
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
|
737
|
+
|
|
738
|
+
var element = scope.domElement;
|
|
739
|
+
|
|
740
|
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
|
741
|
+
|
|
742
|
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
|
743
|
+
|
|
744
|
+
rotateStart.copy( rotateEnd );
|
|
745
|
+
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function handleTouchMovePan( event ) {
|
|
749
|
+
|
|
750
|
+
if ( event.touches.length == 1 ) {
|
|
751
|
+
|
|
752
|
+
panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
|
|
753
|
+
|
|
754
|
+
} else {
|
|
755
|
+
|
|
756
|
+
var x = 0.5 * ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX );
|
|
757
|
+
var y = 0.5 * ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY );
|
|
758
|
+
|
|
759
|
+
panEnd.set( x, y );
|
|
760
|
+
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
panDelta.subVectors( panEnd, panStart )
|
|
764
|
+
.multiplyScalar( scope.panSpeed * window.devicePixelRatio );
|
|
765
|
+
|
|
766
|
+
pan( panDelta.x, panDelta.y );
|
|
767
|
+
|
|
768
|
+
panStart.copy( panEnd );
|
|
769
|
+
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function handleTouchMoveDolly( event ) {
|
|
773
|
+
|
|
774
|
+
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
|
775
|
+
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
|
776
|
+
|
|
777
|
+
var distance = Math.sqrt( dx * dx + dy * dy );
|
|
778
|
+
|
|
779
|
+
dollyEnd.set( 0, distance );
|
|
780
|
+
|
|
781
|
+
dollyDelta.set( 0, dollyEnd.y / dollyStart.y );
|
|
782
|
+
|
|
783
|
+
dollyOut( dollyDelta.y, dollyCenter );
|
|
784
|
+
|
|
785
|
+
dollyStart.copy( dollyEnd );
|
|
786
|
+
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function handleTouchMoveDollyPan( event ) {
|
|
790
|
+
|
|
791
|
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
|
792
|
+
|
|
793
|
+
if ( scope.enablePan ) handleTouchMovePan( event );
|
|
794
|
+
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function handleTouchMoveDollyRotate( event ) {
|
|
798
|
+
|
|
799
|
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
|
800
|
+
|
|
801
|
+
if ( scope.enableRotate ) handleTouchMoveRotate( event );
|
|
802
|
+
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function handleTouchEnd( /*event*/ ) {
|
|
806
|
+
|
|
807
|
+
// no-op
|
|
808
|
+
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
//
|
|
812
|
+
// event handlers - FSM: listen for events and reset state
|
|
813
|
+
//
|
|
814
|
+
|
|
815
|
+
function onPointerDown( event ) {
|
|
816
|
+
|
|
817
|
+
if ( scope.enabled === false ) return;
|
|
818
|
+
|
|
819
|
+
switch ( event.pointerType ) {
|
|
820
|
+
|
|
821
|
+
case 'mouse':
|
|
822
|
+
case 'pen':
|
|
823
|
+
onMouseDown( event );
|
|
824
|
+
break;
|
|
825
|
+
|
|
826
|
+
// TODO touch
|
|
827
|
+
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function onPointerMove( event ) {
|
|
833
|
+
|
|
834
|
+
if ( scope.enabled === false ) return;
|
|
835
|
+
|
|
836
|
+
switch ( event.pointerType ) {
|
|
837
|
+
|
|
838
|
+
case 'mouse':
|
|
839
|
+
case 'pen':
|
|
840
|
+
onMouseMove( event );
|
|
841
|
+
break;
|
|
842
|
+
|
|
843
|
+
// TODO touch
|
|
844
|
+
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function onPointerUp( event ) {
|
|
850
|
+
|
|
851
|
+
switch ( event.pointerType ) {
|
|
852
|
+
|
|
853
|
+
case 'mouse':
|
|
854
|
+
case 'pen':
|
|
855
|
+
onMouseUp( event );
|
|
856
|
+
break;
|
|
857
|
+
|
|
858
|
+
// TODO touch
|
|
859
|
+
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function onMouseDown( event ) {
|
|
865
|
+
|
|
866
|
+
// Prevent the browser from scrolling.
|
|
867
|
+
event.preventDefault();
|
|
868
|
+
|
|
869
|
+
// Manually set the focus since calling preventDefault above
|
|
870
|
+
// prevents the browser from setting it automatically.
|
|
871
|
+
|
|
872
|
+
scope.domElement.focus ? scope.domElement.focus() : window.focus();
|
|
873
|
+
|
|
874
|
+
var mouseAction;
|
|
875
|
+
|
|
876
|
+
switch ( event.button ) {
|
|
877
|
+
|
|
878
|
+
case 0:
|
|
879
|
+
|
|
880
|
+
mouseAction = scope.mouseButtons.LEFT;
|
|
881
|
+
break;
|
|
882
|
+
|
|
883
|
+
case 1:
|
|
884
|
+
|
|
885
|
+
mouseAction = scope.mouseButtons.MIDDLE;
|
|
886
|
+
break;
|
|
887
|
+
|
|
888
|
+
case 2:
|
|
889
|
+
|
|
890
|
+
mouseAction = scope.mouseButtons.RIGHT;
|
|
891
|
+
break;
|
|
892
|
+
|
|
893
|
+
default:
|
|
894
|
+
|
|
895
|
+
mouseAction = - 1;
|
|
896
|
+
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
switch ( mouseAction ) {
|
|
900
|
+
|
|
901
|
+
case THREE.MOUSE.DOLLY:
|
|
902
|
+
|
|
903
|
+
if ( scope.enableZoom === false ) return;
|
|
904
|
+
|
|
905
|
+
handleMouseDownDolly( event );
|
|
906
|
+
|
|
907
|
+
state = STATE.DOLLY;
|
|
908
|
+
|
|
909
|
+
break;
|
|
910
|
+
|
|
911
|
+
case THREE.MOUSE.ROTATE:
|
|
912
|
+
|
|
913
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
914
|
+
|
|
915
|
+
if ( scope.enablePan === false ) return;
|
|
916
|
+
|
|
917
|
+
handleMouseDownPan( event );
|
|
918
|
+
|
|
919
|
+
state = STATE.PAN;
|
|
920
|
+
|
|
921
|
+
} else {
|
|
922
|
+
|
|
923
|
+
if ( scope.enableRotate === false ) return;
|
|
924
|
+
|
|
925
|
+
handleMouseDownRotate( event );
|
|
926
|
+
|
|
927
|
+
state = STATE.ROTATE;
|
|
928
|
+
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
break;
|
|
932
|
+
|
|
933
|
+
case THREE.MOUSE.PAN:
|
|
934
|
+
|
|
935
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
936
|
+
|
|
937
|
+
if ( scope.enableRotate === false ) return;
|
|
938
|
+
|
|
939
|
+
handleMouseDownRotate( event );
|
|
940
|
+
|
|
941
|
+
state = STATE.ROTATE;
|
|
942
|
+
|
|
943
|
+
} else {
|
|
944
|
+
|
|
945
|
+
if ( scope.enablePan === false ) return;
|
|
946
|
+
|
|
947
|
+
handleMouseDownPan( event );
|
|
948
|
+
|
|
949
|
+
state = STATE.PAN;
|
|
950
|
+
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
break;
|
|
954
|
+
|
|
955
|
+
default:
|
|
956
|
+
|
|
957
|
+
state = STATE.NONE;
|
|
958
|
+
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if ( state !== STATE.NONE ) {
|
|
962
|
+
|
|
963
|
+
scope.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove );
|
|
964
|
+
scope.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp );
|
|
965
|
+
|
|
966
|
+
scope.dispatchEvent( startEvent );
|
|
967
|
+
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function onMouseMove( event ) {
|
|
973
|
+
|
|
974
|
+
if ( scope.enabled === false ) return;
|
|
975
|
+
|
|
976
|
+
event.preventDefault();
|
|
977
|
+
|
|
978
|
+
switch ( state ) {
|
|
979
|
+
|
|
980
|
+
case STATE.ROTATE:
|
|
981
|
+
|
|
982
|
+
if ( scope.enableRotate === false ) return;
|
|
983
|
+
|
|
984
|
+
handleMouseMoveRotate( event );
|
|
985
|
+
|
|
986
|
+
break;
|
|
987
|
+
|
|
988
|
+
case STATE.DOLLY:
|
|
989
|
+
|
|
990
|
+
if ( scope.enableZoom === false ) return;
|
|
991
|
+
|
|
992
|
+
handleMouseMoveDolly( event );
|
|
993
|
+
|
|
994
|
+
break;
|
|
995
|
+
|
|
996
|
+
case STATE.PAN:
|
|
997
|
+
|
|
998
|
+
if ( scope.enablePan === false ) return;
|
|
999
|
+
|
|
1000
|
+
handleMouseMovePan( event );
|
|
1001
|
+
|
|
1002
|
+
break;
|
|
1003
|
+
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function onMouseUp( event ) {
|
|
1009
|
+
|
|
1010
|
+
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
|
1011
|
+
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
|
|
1012
|
+
|
|
1013
|
+
if ( scope.enabled === false ) return;
|
|
1014
|
+
|
|
1015
|
+
handleMouseUp( event );
|
|
1016
|
+
|
|
1017
|
+
scope.dispatchEvent( endEvent );
|
|
1018
|
+
|
|
1019
|
+
state = STATE.NONE;
|
|
1020
|
+
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function onMouseWheel( event ) {
|
|
1024
|
+
|
|
1025
|
+
if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
|
|
1026
|
+
|
|
1027
|
+
event.preventDefault();
|
|
1028
|
+
event.stopPropagation();
|
|
1029
|
+
|
|
1030
|
+
scope.dispatchEvent( startEvent );
|
|
1031
|
+
|
|
1032
|
+
handleMouseWheel( event );
|
|
1033
|
+
|
|
1034
|
+
scope.dispatchEvent( endEvent );
|
|
1035
|
+
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function onKeyDown( event ) {
|
|
1039
|
+
|
|
1040
|
+
if ( scope.enabled === false || scope.enablePan === false ) return;
|
|
1041
|
+
|
|
1042
|
+
handleKeyDown( event );
|
|
1043
|
+
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function onTouchStart( event ) {
|
|
1047
|
+
|
|
1048
|
+
if ( scope.enabled === false ) return;
|
|
1049
|
+
|
|
1050
|
+
event.preventDefault(); // prevent scrolling
|
|
1051
|
+
|
|
1052
|
+
switch ( event.touches.length ) {
|
|
1053
|
+
|
|
1054
|
+
case 1:
|
|
1055
|
+
|
|
1056
|
+
switch ( scope.touches.ONE ) {
|
|
1057
|
+
|
|
1058
|
+
case THREE.TOUCH.ROTATE:
|
|
1059
|
+
|
|
1060
|
+
if ( scope.enableRotate === false ) return;
|
|
1061
|
+
|
|
1062
|
+
handleTouchStartRotate( event );
|
|
1063
|
+
|
|
1064
|
+
state = STATE.TOUCH_ROTATE;
|
|
1065
|
+
|
|
1066
|
+
break;
|
|
1067
|
+
|
|
1068
|
+
case THREE.TOUCH.PAN:
|
|
1069
|
+
|
|
1070
|
+
if ( scope.enablePan === false ) return;
|
|
1071
|
+
|
|
1072
|
+
handleTouchStartPan( event );
|
|
1073
|
+
|
|
1074
|
+
state = STATE.TOUCH_PAN;
|
|
1075
|
+
|
|
1076
|
+
break;
|
|
1077
|
+
|
|
1078
|
+
default:
|
|
1079
|
+
|
|
1080
|
+
state = STATE.NONE;
|
|
1081
|
+
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
break;
|
|
1085
|
+
|
|
1086
|
+
case 2:
|
|
1087
|
+
|
|
1088
|
+
switch ( scope.touches.TWO ) {
|
|
1089
|
+
|
|
1090
|
+
case THREE.TOUCH.DOLLY_PAN:
|
|
1091
|
+
|
|
1092
|
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
|
1093
|
+
|
|
1094
|
+
handleTouchStartDollyPan( event );
|
|
1095
|
+
|
|
1096
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
|
1097
|
+
|
|
1098
|
+
break;
|
|
1099
|
+
|
|
1100
|
+
case THREE.TOUCH.DOLLY_ROTATE:
|
|
1101
|
+
|
|
1102
|
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
|
1103
|
+
|
|
1104
|
+
handleTouchStartDollyRotate( event );
|
|
1105
|
+
|
|
1106
|
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
1107
|
+
|
|
1108
|
+
break;
|
|
1109
|
+
|
|
1110
|
+
default:
|
|
1111
|
+
|
|
1112
|
+
state = STATE.NONE;
|
|
1113
|
+
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
break;
|
|
1117
|
+
|
|
1118
|
+
default:
|
|
1119
|
+
|
|
1120
|
+
state = STATE.NONE;
|
|
1121
|
+
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
if ( state !== STATE.NONE ) {
|
|
1125
|
+
|
|
1126
|
+
scope.dispatchEvent( startEvent );
|
|
1127
|
+
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function onTouchMove( event ) {
|
|
1133
|
+
|
|
1134
|
+
if ( scope.enabled === false ) return;
|
|
1135
|
+
|
|
1136
|
+
event.preventDefault(); // prevent scrolling
|
|
1137
|
+
event.stopPropagation();
|
|
1138
|
+
|
|
1139
|
+
switch ( state ) {
|
|
1140
|
+
|
|
1141
|
+
case STATE.TOUCH_ROTATE:
|
|
1142
|
+
|
|
1143
|
+
if ( scope.enableRotate === false ) return;
|
|
1144
|
+
|
|
1145
|
+
handleTouchMoveRotate( event );
|
|
1146
|
+
|
|
1147
|
+
scope.update();
|
|
1148
|
+
|
|
1149
|
+
break;
|
|
1150
|
+
|
|
1151
|
+
case STATE.TOUCH_PAN:
|
|
1152
|
+
|
|
1153
|
+
if ( scope.enablePan === false ) return;
|
|
1154
|
+
|
|
1155
|
+
handleTouchMovePan( event );
|
|
1156
|
+
|
|
1157
|
+
scope.update();
|
|
1158
|
+
|
|
1159
|
+
break;
|
|
1160
|
+
|
|
1161
|
+
case STATE.TOUCH_DOLLY_PAN:
|
|
1162
|
+
|
|
1163
|
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
|
1164
|
+
|
|
1165
|
+
handleTouchMoveDollyPan( event );
|
|
1166
|
+
|
|
1167
|
+
scope.update();
|
|
1168
|
+
|
|
1169
|
+
break;
|
|
1170
|
+
|
|
1171
|
+
case STATE.TOUCH_DOLLY_ROTATE:
|
|
1172
|
+
|
|
1173
|
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
|
1174
|
+
|
|
1175
|
+
handleTouchMoveDollyRotate( event );
|
|
1176
|
+
|
|
1177
|
+
scope.update();
|
|
1178
|
+
|
|
1179
|
+
break;
|
|
1180
|
+
|
|
1181
|
+
default:
|
|
1182
|
+
|
|
1183
|
+
state = STATE.NONE;
|
|
1184
|
+
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function onTouchEnd( event ) {
|
|
1190
|
+
|
|
1191
|
+
if ( scope.enabled === false ) return;
|
|
1192
|
+
|
|
1193
|
+
handleTouchEnd( event );
|
|
1194
|
+
|
|
1195
|
+
scope.dispatchEvent( endEvent );
|
|
1196
|
+
|
|
1197
|
+
state = STATE.NONE;
|
|
1198
|
+
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function onContextMenu( event ) {
|
|
1202
|
+
|
|
1203
|
+
if ( scope.enabled === false ) return;
|
|
1204
|
+
|
|
1205
|
+
event.preventDefault();
|
|
1206
|
+
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
//
|
|
1210
|
+
|
|
1211
|
+
scope.domElement.addEventListener( 'contextmenu', onContextMenu );
|
|
1212
|
+
|
|
1213
|
+
scope.domElement.addEventListener( 'pointerdown', onPointerDown );
|
|
1214
|
+
scope.domElement.addEventListener( 'wheel', onMouseWheel );
|
|
1215
|
+
|
|
1216
|
+
scope.domElement.addEventListener( 'touchstart', onTouchStart );
|
|
1217
|
+
scope.domElement.addEventListener( 'touchend', onTouchEnd );
|
|
1218
|
+
scope.domElement.addEventListener( 'touchmove', onTouchMove );
|
|
1219
|
+
|
|
1220
|
+
// force an update at start
|
|
1221
|
+
|
|
1222
|
+
this.update();
|
|
1223
|
+
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
|
1227
|
+
OrbitControls.prototype.constructor = OrbitControls;
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
// This set of controls performs orbiting, dollying (zooming), and panning.
|
|
1231
|
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
|
1232
|
+
// This is very similar to OrbitControls, another set of touch behavior
|
|
1233
|
+
//
|
|
1234
|
+
// Orbit - right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger rotate
|
|
1235
|
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
|
1236
|
+
// Pan - left mouse, or arrow keys / touch: one-finger move
|
|
1237
|
+
|
|
1238
|
+
export const MapControls = function ( object, domElement ) {
|
|
1239
|
+
|
|
1240
|
+
OrbitControls.call( this, object, domElement );
|
|
1241
|
+
|
|
1242
|
+
this.screenSpacePanning = false; // pan orthogonal to world-space direction camera.up
|
|
1243
|
+
|
|
1244
|
+
this.mouseButtons.LEFT = THREE.MOUSE.PAN;
|
|
1245
|
+
this.mouseButtons.RIGHT = THREE.MOUSE.ROTATE;
|
|
1246
|
+
|
|
1247
|
+
this.touches.ONE = THREE.TOUCH.PAN;
|
|
1248
|
+
this.touches.TWO = THREE.TOUCH.DOLLY_ROTATE;
|
|
1249
|
+
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
MapControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
|
1253
|
+
MapControls.prototype.constructor = MapControls;
|