hilo3d 1.19.0 → 1.19.1

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,292 +1,292 @@
1
- (function () {
2
- var PI2 = Math.PI / 2;
3
- var tempEuler = new Hilo3d.Euler();
4
- tempEuler.order = 'XYZ';
5
- var tempQuat = new Hilo3d.Quaternion();
6
- var tempMatrix = new Hilo3d.Matrix4();
7
- var tempVector = new Hilo3d.Vector3();
8
- var MOUSE = {
9
- LEFT: 0,
10
- MID: 1,
11
- RIGHT: 2
12
- };
13
- var STATE = {
14
- NONE: -1,
15
- MOVE: 0,
16
- ZOOM: 1,
17
- PAN: 2
18
- }
19
-
20
- function OrbitControls(stage, opt) {
21
- if (opt instanceof Hilo3d.Node) {
22
- opt = {
23
- model: opt
24
- };
25
- } else if (!opt) {
26
- opt = {};
27
- }
28
- this.model = opt.model || stage;
29
- this.stage = stage;
30
- this.canvas = stage.canvas;
31
- this.isLockZ = !!opt.isLockZ;
32
- this.rotationXLimit = opt.rotationXLimit;
33
- this.isLockScale = !!opt.isLockScale;
34
- this.isLockRotate = !!opt.isLockRotate;
35
- this.isLockMove = !!opt.isLockMove;
36
- if (opt.eulerOrder) {
37
- tempEuler.order = opt.eulerOrder;
38
- }
39
-
40
- if (this.isLockZ) {
41
- tempEuler.x = this.model.rotationX * Math.PI / 180;
42
- tempEuler.y = this.model.rotationY * Math.PI / 180;
43
- }
44
-
45
- this.mouseInfo = {
46
- startX: 0,
47
- startY: 0,
48
- isDown: false
49
- };
50
-
51
- this.onWheel = this.onWheel.bind(this);
52
- this.onMouseDown = this.onMouseDown.bind(this);
53
- this.onMouseMove = this.onMouseMove.bind(this);
54
- this.onMouseUp = this.onMouseUp.bind(this);
55
-
56
- this.isEnabled = false;
57
- this.enable();
58
- }
59
-
60
- OrbitControls.prototype.enable = function(){
61
- if(!this.isEnabled){
62
- this.isEnabled = true;
63
- var canvas = this.canvas;
64
- canvas.addEventListener('wheel', this.onWheel, false);
65
-
66
- if ('ontouchmove' in window) {
67
- canvas.addEventListener('touchstart', this.onMouseDown, false);
68
- canvas.addEventListener('touchmove', this.onMouseMove, false);
69
- canvas.addEventListener('touchend', this.onMouseUp, false);
70
- } else {
71
- document.addEventListener('contextmenu', function (evt) {
72
- //禁掉鼠标右键菜单
73
- evt.preventDefault()
74
- });
75
- canvas.addEventListener('mousedown', this.onMouseDown, false);
76
- canvas.addEventListener('mousemove', this.onMouseMove, false);
77
- canvas.addEventListener('mouseup', this.onMouseUp, false);
78
- }
79
- }
80
- };
81
-
82
- OrbitControls.prototype.disable = function(){
83
- if(this.isEnabled){
84
- this.isEnabled = false;
85
- this.mouseInfo.isDown = false;
86
- this.mouseInfo.state = STATE.NONE;
87
-
88
- var canvas = this.canvas;
89
- canvas.removeEventListener('wheel', this.onWheel, false);
90
-
91
- if ('ontouchmove' in window) {
92
- canvas.removeEventListener('touchstart', this.onMouseDown, false);
93
- canvas.removeEventListener('touchmove', this.onMouseMove, false);
94
- canvas.removeEventListener('touchend', this.onMouseUp, false);
95
- } else {
96
- document.removeEventListener('contextmenu', function (evt) {
97
- //禁掉鼠标右键菜单
98
- evt.preventDefault()
99
- });
100
- canvas.removeEventListener('mousedown', this.onMouseDown, false);
101
- canvas.removeEventListener('mousemove', this.onMouseMove, false);
102
- canvas.removeEventListener('mouseup', this.onMouseUp, false);
103
- }
104
- }
105
- }
106
-
107
- OrbitControls.prototype.rotate = function(distanceX, distanceY) {
108
- if (this.isLockRotate) {
109
- return;
110
- }
111
- var x = distanceY / 200;
112
- var y = distanceX / 200;
113
- if (this.isLockZ) {
114
- tempEuler.x += x;
115
- tempEuler.y += y;
116
- if (this.rotationXLimit) {
117
- if (tempEuler.x > this.rotationXLimit) {
118
- tempEuler.x = this.rotationXLimit;
119
- } else if (tempEuler.x < -this.rotationXLimit) {
120
- tempEuler.x = -this.rotationXLimit;
121
- }
122
- }
123
- this.model.quaternion.fromEuler(tempEuler);
124
- } else {
125
- tempEuler.set(x, y, 0);
126
- tempQuat.fromEuler(tempEuler);
127
- this.model.quaternion.premultiply(tempQuat);
128
- }
129
- };
130
-
131
- OrbitControls.prototype.scale = function(s) {
132
- if (this.isLockScale) {
133
- return;
134
- }
135
- this.model.scaleX *= s;
136
- this.model.scaleY *= s;
137
- this.model.scaleZ *= s;
138
-
139
- this.onScale && this.onScale(s);
140
- };
141
-
142
- OrbitControls.prototype.move = function(x, y) {
143
- if(this.isLockMove){
144
- return;
145
- }
146
- this.model.x += x;
147
- this.model.y += y;
148
- };
149
-
150
- OrbitControls.prototype.onMouseDown = function (evt) {
151
- this.mouseInfo.isDown = true;
152
- if (evt.type === 'touchstart') {
153
-
154
- this.mouseInfo.startX = evt.touches[0].pageX;
155
- this.mouseInfo.startY = evt.touches[0].pageY;
156
-
157
- switch (evt.touches.length) {
158
- case 1:
159
- this.mouseInfo.state = STATE.MOVE;
160
- break;
161
- case 2:
162
- var x = evt.touches[1].pageX - evt.touches[0].pageX;
163
- var y = evt.touches[1].pageY - evt.touches[0].pageY;
164
- this.mouseInfo.startPointerDistance = Math.sqrt(x * x + y * y);
165
- this.mouseInfo.state = STATE.ZOOM;
166
- break;
167
- case 3:
168
- this.mouseInfo.state = STATE.PAN;
169
- break;
170
- }
171
- } else {
172
- switch (evt.button) {
173
- case MOUSE.LEFT:
174
- this.mouseInfo.startX = evt.pageX;
175
- this.mouseInfo.startY = evt.pageY;
176
- this.mouseInfo.state = STATE.MOVE;
177
- break;
178
- case MOUSE.RIGHT:
179
- this.mouseInfo.startX = evt.pageX;
180
- this.mouseInfo.startY = evt.pageY;
181
- this.mouseInfo.state = STATE.PAN;
182
- break;
183
- }
184
- }
185
- }
186
-
187
- OrbitControls.prototype.onMouseMove = function (evt) {
188
- if (!this.mouseInfo.isDown) {
189
- return;
190
- }
191
- evt.preventDefault();
192
- evt.stopPropagation();
193
- var scope = this;
194
- if (evt.type === 'touchmove') {
195
- switch (this.mouseInfo.state) {
196
- case STATE.MOVE:
197
- scope.handlerToucheMove(evt);
198
- break;
199
- case STATE.ZOOM:
200
- scope.handlerToucheZoom(evt);
201
- break;
202
- case STATE.PAN:
203
- scope.handlerTouchePan(evt);
204
- break;
205
- }
206
- } else {
207
- switch (this.mouseInfo.state) {
208
- case STATE.MOVE:
209
- scope.handlerMouseMove(evt);
210
- break;
211
- case STATE.PAN:
212
- scope.handlerMousePan(evt);
213
- break;
214
- }
215
- }
216
-
217
- }
218
-
219
- OrbitControls.prototype.handlerMousePan = function (evt) {
220
- var distanceX = evt.pageX - this.mouseInfo.startX;
221
- var distanceY = evt.pageY - this.mouseInfo.startY;
222
- this.mouseInfo.startX = evt.pageX;
223
- this.mouseInfo.startY = evt.pageY;
224
- this.model.worldMatrix.getScaling(tempVector);
225
- this.move(distanceX * 2 * tempVector.x, distanceY * 2 * tempVector.y);
226
- }
227
-
228
- OrbitControls.prototype.handlerMouseMove = function (evt) {
229
- var distanceX = evt.pageX - this.mouseInfo.startX;
230
- var distanceY = evt.pageY - this.mouseInfo.startY;
231
- this.mouseInfo.startX = evt.pageX;
232
- this.mouseInfo.startY = evt.pageY;
233
-
234
- this.rotate(distanceX, distanceY);
235
- }
236
-
237
- OrbitControls.prototype.handlerToucheZoom = function (evt) {
238
- var x = evt.touches[1].pageX - evt.touches[0].pageX;
239
- var y = evt.touches[1].pageY - evt.touches[0].pageY;
240
- var pointerDistance = Math.sqrt(x * x + y * y);
241
- var scale = 1
242
- scale = pointerDistance / this.mouseInfo.startPointerDistance;
243
- this.mouseInfo.startPointerDistance = pointerDistance;
244
- if (scale != 1) {
245
- this.scale(scale);
246
- }
247
- }
248
-
249
- OrbitControls.prototype.handlerTouchePan = function (evt) {
250
- evt = evt.touches[0];
251
- var distanceX = evt.pageX - this.mouseInfo.startX;
252
- var distanceY = evt.pageY - this.mouseInfo.startY;
253
- this.mouseInfo.startX = evt.pageX;
254
- this.mouseInfo.startY = evt.pageY;
255
- this.move(distanceX * .01, -distanceY * .01);
256
- }
257
-
258
- OrbitControls.prototype.handlerToucheMove = function (evt) {
259
- var model = this.model;
260
- evt = evt.touches[0];
261
- this.handlerMouseMove(evt);
262
- }
263
-
264
- OrbitControls.prototype.onMouseUp = function (evt) {
265
- this.mouseInfo.isDown = false;
266
- this.mouseInfo.state = STATE.NONE;
267
- }
268
-
269
- OrbitControls.prototype.onWheel = function (evt) {
270
- evt.preventDefault();
271
- var _deltaY = evt.deltaY;
272
- if (_deltaY < -100) {
273
- _deltaY = -90
274
- } else if (_deltaY > 100) {
275
- _deltaY = 90
276
- }
277
- var s = 1 + _deltaY * 0.001;
278
- this.scale(1 / s);
279
- }
280
-
281
- OrbitControls.prototype.bindEvent = function () {
282
-
283
- }
284
-
285
- if(typeof module !== 'undefined'){
286
- module.exports = OrbitControls;
287
- }
288
-
289
- if(typeof window !== 'undefined'){
290
- window.OrbitControls = OrbitControls;
291
- }
1
+ (function () {
2
+ var PI2 = Math.PI / 2;
3
+ var tempEuler = new Hilo3d.Euler();
4
+ tempEuler.order = 'XYZ';
5
+ var tempQuat = new Hilo3d.Quaternion();
6
+ var tempMatrix = new Hilo3d.Matrix4();
7
+ var tempVector = new Hilo3d.Vector3();
8
+ var MOUSE = {
9
+ LEFT: 0,
10
+ MID: 1,
11
+ RIGHT: 2
12
+ };
13
+ var STATE = {
14
+ NONE: -1,
15
+ MOVE: 0,
16
+ ZOOM: 1,
17
+ PAN: 2
18
+ }
19
+
20
+ function OrbitControls(stage, opt) {
21
+ if (opt instanceof Hilo3d.Node) {
22
+ opt = {
23
+ model: opt
24
+ };
25
+ } else if (!opt) {
26
+ opt = {};
27
+ }
28
+ this.model = opt.model || stage;
29
+ this.stage = stage;
30
+ this.canvas = stage.canvas;
31
+ this.isLockZ = !!opt.isLockZ;
32
+ this.rotationXLimit = opt.rotationXLimit;
33
+ this.isLockScale = !!opt.isLockScale;
34
+ this.isLockRotate = !!opt.isLockRotate;
35
+ this.isLockMove = !!opt.isLockMove;
36
+ if (opt.eulerOrder) {
37
+ tempEuler.order = opt.eulerOrder;
38
+ }
39
+
40
+ if (this.isLockZ) {
41
+ tempEuler.x = this.model.rotationX * Math.PI / 180;
42
+ tempEuler.y = this.model.rotationY * Math.PI / 180;
43
+ }
44
+
45
+ this.mouseInfo = {
46
+ startX: 0,
47
+ startY: 0,
48
+ isDown: false
49
+ };
50
+
51
+ this.onWheel = this.onWheel.bind(this);
52
+ this.onMouseDown = this.onMouseDown.bind(this);
53
+ this.onMouseMove = this.onMouseMove.bind(this);
54
+ this.onMouseUp = this.onMouseUp.bind(this);
55
+
56
+ this.isEnabled = false;
57
+ this.enable();
58
+ }
59
+
60
+ OrbitControls.prototype.enable = function(){
61
+ if(!this.isEnabled){
62
+ this.isEnabled = true;
63
+ var canvas = this.canvas;
64
+ canvas.addEventListener('wheel', this.onWheel, false);
65
+
66
+ if ('ontouchmove' in window) {
67
+ canvas.addEventListener('touchstart', this.onMouseDown, false);
68
+ canvas.addEventListener('touchmove', this.onMouseMove, false);
69
+ canvas.addEventListener('touchend', this.onMouseUp, false);
70
+ } else {
71
+ document.addEventListener('contextmenu', function (evt) {
72
+ //禁掉鼠标右键菜单
73
+ evt.preventDefault()
74
+ });
75
+ canvas.addEventListener('mousedown', this.onMouseDown, false);
76
+ canvas.addEventListener('mousemove', this.onMouseMove, false);
77
+ canvas.addEventListener('mouseup', this.onMouseUp, false);
78
+ }
79
+ }
80
+ };
81
+
82
+ OrbitControls.prototype.disable = function(){
83
+ if(this.isEnabled){
84
+ this.isEnabled = false;
85
+ this.mouseInfo.isDown = false;
86
+ this.mouseInfo.state = STATE.NONE;
87
+
88
+ var canvas = this.canvas;
89
+ canvas.removeEventListener('wheel', this.onWheel, false);
90
+
91
+ if ('ontouchmove' in window) {
92
+ canvas.removeEventListener('touchstart', this.onMouseDown, false);
93
+ canvas.removeEventListener('touchmove', this.onMouseMove, false);
94
+ canvas.removeEventListener('touchend', this.onMouseUp, false);
95
+ } else {
96
+ document.removeEventListener('contextmenu', function (evt) {
97
+ //禁掉鼠标右键菜单
98
+ evt.preventDefault()
99
+ });
100
+ canvas.removeEventListener('mousedown', this.onMouseDown, false);
101
+ canvas.removeEventListener('mousemove', this.onMouseMove, false);
102
+ canvas.removeEventListener('mouseup', this.onMouseUp, false);
103
+ }
104
+ }
105
+ }
106
+
107
+ OrbitControls.prototype.rotate = function(distanceX, distanceY) {
108
+ if (this.isLockRotate) {
109
+ return;
110
+ }
111
+ var x = distanceY / 200;
112
+ var y = distanceX / 200;
113
+ if (this.isLockZ) {
114
+ tempEuler.x += x;
115
+ tempEuler.y += y;
116
+ if (this.rotationXLimit) {
117
+ if (tempEuler.x > this.rotationXLimit) {
118
+ tempEuler.x = this.rotationXLimit;
119
+ } else if (tempEuler.x < -this.rotationXLimit) {
120
+ tempEuler.x = -this.rotationXLimit;
121
+ }
122
+ }
123
+ this.model.quaternion.fromEuler(tempEuler);
124
+ } else {
125
+ tempEuler.set(x, y, 0);
126
+ tempQuat.fromEuler(tempEuler);
127
+ this.model.quaternion.premultiply(tempQuat);
128
+ }
129
+ };
130
+
131
+ OrbitControls.prototype.scale = function(s) {
132
+ if (this.isLockScale) {
133
+ return;
134
+ }
135
+ this.model.scaleX *= s;
136
+ this.model.scaleY *= s;
137
+ this.model.scaleZ *= s;
138
+
139
+ this.onScale && this.onScale(s);
140
+ };
141
+
142
+ OrbitControls.prototype.move = function(x, y) {
143
+ if(this.isLockMove){
144
+ return;
145
+ }
146
+ this.model.x += x;
147
+ this.model.y += y;
148
+ };
149
+
150
+ OrbitControls.prototype.onMouseDown = function (evt) {
151
+ this.mouseInfo.isDown = true;
152
+ if (evt.type === 'touchstart') {
153
+
154
+ this.mouseInfo.startX = evt.touches[0].pageX;
155
+ this.mouseInfo.startY = evt.touches[0].pageY;
156
+
157
+ switch (evt.touches.length) {
158
+ case 1:
159
+ this.mouseInfo.state = STATE.MOVE;
160
+ break;
161
+ case 2:
162
+ var x = evt.touches[1].pageX - evt.touches[0].pageX;
163
+ var y = evt.touches[1].pageY - evt.touches[0].pageY;
164
+ this.mouseInfo.startPointerDistance = Math.sqrt(x * x + y * y);
165
+ this.mouseInfo.state = STATE.ZOOM;
166
+ break;
167
+ case 3:
168
+ this.mouseInfo.state = STATE.PAN;
169
+ break;
170
+ }
171
+ } else {
172
+ switch (evt.button) {
173
+ case MOUSE.LEFT:
174
+ this.mouseInfo.startX = evt.pageX;
175
+ this.mouseInfo.startY = evt.pageY;
176
+ this.mouseInfo.state = STATE.MOVE;
177
+ break;
178
+ case MOUSE.RIGHT:
179
+ this.mouseInfo.startX = evt.pageX;
180
+ this.mouseInfo.startY = evt.pageY;
181
+ this.mouseInfo.state = STATE.PAN;
182
+ break;
183
+ }
184
+ }
185
+ }
186
+
187
+ OrbitControls.prototype.onMouseMove = function (evt) {
188
+ if (!this.mouseInfo.isDown) {
189
+ return;
190
+ }
191
+ evt.preventDefault();
192
+ evt.stopPropagation();
193
+ var scope = this;
194
+ if (evt.type === 'touchmove') {
195
+ switch (this.mouseInfo.state) {
196
+ case STATE.MOVE:
197
+ scope.handlerToucheMove(evt);
198
+ break;
199
+ case STATE.ZOOM:
200
+ scope.handlerToucheZoom(evt);
201
+ break;
202
+ case STATE.PAN:
203
+ scope.handlerTouchePan(evt);
204
+ break;
205
+ }
206
+ } else {
207
+ switch (this.mouseInfo.state) {
208
+ case STATE.MOVE:
209
+ scope.handlerMouseMove(evt);
210
+ break;
211
+ case STATE.PAN:
212
+ scope.handlerMousePan(evt);
213
+ break;
214
+ }
215
+ }
216
+
217
+ }
218
+
219
+ OrbitControls.prototype.handlerMousePan = function (evt) {
220
+ var distanceX = evt.pageX - this.mouseInfo.startX;
221
+ var distanceY = evt.pageY - this.mouseInfo.startY;
222
+ this.mouseInfo.startX = evt.pageX;
223
+ this.mouseInfo.startY = evt.pageY;
224
+ this.model.worldMatrix.getScaling(tempVector);
225
+ this.move(distanceX * 2 * tempVector.x, distanceY * 2 * tempVector.y);
226
+ }
227
+
228
+ OrbitControls.prototype.handlerMouseMove = function (evt) {
229
+ var distanceX = evt.pageX - this.mouseInfo.startX;
230
+ var distanceY = evt.pageY - this.mouseInfo.startY;
231
+ this.mouseInfo.startX = evt.pageX;
232
+ this.mouseInfo.startY = evt.pageY;
233
+
234
+ this.rotate(distanceX, distanceY);
235
+ }
236
+
237
+ OrbitControls.prototype.handlerToucheZoom = function (evt) {
238
+ var x = evt.touches[1].pageX - evt.touches[0].pageX;
239
+ var y = evt.touches[1].pageY - evt.touches[0].pageY;
240
+ var pointerDistance = Math.sqrt(x * x + y * y);
241
+ var scale = 1
242
+ scale = pointerDistance / this.mouseInfo.startPointerDistance;
243
+ this.mouseInfo.startPointerDistance = pointerDistance;
244
+ if (scale != 1) {
245
+ this.scale(scale);
246
+ }
247
+ }
248
+
249
+ OrbitControls.prototype.handlerTouchePan = function (evt) {
250
+ evt = evt.touches[0];
251
+ var distanceX = evt.pageX - this.mouseInfo.startX;
252
+ var distanceY = evt.pageY - this.mouseInfo.startY;
253
+ this.mouseInfo.startX = evt.pageX;
254
+ this.mouseInfo.startY = evt.pageY;
255
+ this.move(distanceX * .01, -distanceY * .01);
256
+ }
257
+
258
+ OrbitControls.prototype.handlerToucheMove = function (evt) {
259
+ var model = this.model;
260
+ evt = evt.touches[0];
261
+ this.handlerMouseMove(evt);
262
+ }
263
+
264
+ OrbitControls.prototype.onMouseUp = function (evt) {
265
+ this.mouseInfo.isDown = false;
266
+ this.mouseInfo.state = STATE.NONE;
267
+ }
268
+
269
+ OrbitControls.prototype.onWheel = function (evt) {
270
+ evt.preventDefault();
271
+ var _deltaY = evt.deltaY;
272
+ if (_deltaY < -100) {
273
+ _deltaY = -90
274
+ } else if (_deltaY > 100) {
275
+ _deltaY = 90
276
+ }
277
+ var s = 1 + _deltaY * 0.001;
278
+ this.scale(1 / s);
279
+ }
280
+
281
+ OrbitControls.prototype.bindEvent = function () {
282
+
283
+ }
284
+
285
+ if(typeof module !== 'undefined'){
286
+ module.exports = OrbitControls;
287
+ }
288
+
289
+ if(typeof window !== 'undefined'){
290
+ window.OrbitControls = OrbitControls;
291
+ }
292
292
  })();