hilo3d 1.19.1 → 2.0.0-alpha.2

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 +0,0 @@
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
- })();
@@ -1,128 +0,0 @@
1
- var camera, stage, renderer, gl, directionLight, ambientLight, ticker, stats, orbitControls;
2
- if (!window.notInit) {
3
- camera = new Hilo3d.PerspectiveCamera({
4
- aspect: innerWidth / innerHeight,
5
- far: 100,
6
- near: 0.1,
7
- z: 3
8
- });
9
-
10
- stage = new Hilo3d.Stage({
11
- container: document.getElementById('container'),
12
- camera: camera,
13
- clearColor: new Hilo3d.Color(0.3, 0.35, 0.35),
14
- width: innerWidth,
15
- height: innerHeight,
16
- preferWebGL2: location.search.indexOf('webgl2') > -1,
17
- antialias: false,
18
- alpha: false,
19
- useLogDepth: false,
20
- });
21
-
22
- window.onresize = function(){
23
- camera.aspect = innerWidth / innerHeight;
24
- stage.resize(innerWidth, innerHeight);
25
- }
26
-
27
- renderer = stage.renderer;
28
- gl;
29
-
30
- directionLight = new Hilo3d.DirectionalLight({
31
- color: new Hilo3d.Color(1, 1, 1),
32
- direction: new Hilo3d.Vector3(0, -1, 0)
33
- }).addTo(stage);
34
-
35
- ambientLight = new Hilo3d.AmbientLight({
36
- color: new Hilo3d.Color(1, 1, 1),
37
- amount: .5
38
- }).addTo(stage);
39
-
40
- ticker = new Hilo3d.Ticker(60);
41
- ticker.addTick(stage);
42
- ticker.addTick(Hilo3d.Tween);
43
- ticker.addTick(Hilo3d.Animation);
44
- stats = new Stats(ticker, stage.renderer.renderInfo);
45
- orbitControls = new OrbitControls(stage, {
46
- isLockMove: true,
47
- isLockZ: true
48
- });
49
-
50
- ['init', 'initFailed'].forEach(function(eventName){
51
- stage.renderer.on(eventName, function(e){
52
- console.log(e.type, e);
53
- console.log('Stage use ' + (renderer.isWebGL2 ? 'WebGL2' : 'WebGL1'));
54
- });
55
- });
56
-
57
- setTimeout(function() {
58
- ticker.start(true);
59
- gl = renderer.gl;
60
- }, 10);
61
- }
62
-
63
- var utils = {
64
- keys: {},
65
- parseQuery(url) {
66
- var reg = /([^?#&=]+)=([^#&]*)/g;
67
- var params = {};
68
- var result;
69
- while ((result = reg.exec(url))) {
70
- params[result[1]] = decodeURIComponent(result[2]);
71
- }
72
- return params;
73
- },
74
- buildUrl(url, params) {
75
- if (url === undefined) {
76
- url = '';
77
- }
78
-
79
- if (params === undefined) {
80
- params = {};
81
- }
82
-
83
- var originParams = this.parseQuery(url);
84
- var newParams = Object.assign(originParams, params);
85
- var qs = Object.keys(newParams).map(function(key) {
86
- return key + '=' + encodeURIComponent(newParams[key])
87
- }).join('&');
88
- return url.replace(/(\?.*)?$/, '?' + qs);
89
- },
90
- loadEnvMap(callback) {
91
- var loadQueue = new Hilo3d.LoadQueue([{
92
- type: 'CubeTexture',
93
- images: [
94
- '//gw.alicdn.com/tfs/TB1i.dWr9cqBKNjSZFgXXX_kXXa-128-128.jpg',
95
- '//gw.alicdn.com/tfs/TB1ozYarJcnBKNjSZR0XXcFqFXa-128-128.jpg',
96
- '//gw.alicdn.com/tfs/TB11Nc_rRsmBKNjSZFFXXcT9VXa-128-128.jpg',
97
- '//gw.alicdn.com/tfs/TB13ldPr_mWBKNjSZFBXXXxUFXa-128-128.jpg',
98
- '//gw.alicdn.com/tfs/TB1RmQ6rTqWBKNjSZFAXXanSpXa-128-128.jpg',
99
- '//gw.alicdn.com/tfs/TB13j8frYZnBKNjSZFKXXcGOVXa-128-128.jpg'
100
- ]
101
- }, {
102
- type: 'CubeTexture',
103
- right: '//gw.alicdn.com/tfs/TB1EJJYr9cqBKNjSZFgXXX_kXXa-1024-1024.jpg',
104
- left: '//gw.alicdn.com/tfs/TB1xXKFrSYTBKNjSZKbXXXJ8pXa-1024-1024.jpg',
105
- top: '//gw.alicdn.com/tfs/TB1U7Fmr7UmBKNjSZFOXXab2XXa-1024-1024.jpg',
106
- bottom: '//gw.alicdn.com/tfs/TB1zJRdr8jTBKNjSZFDXXbVgVXa-1024-1024.jpg',
107
- front: '//gw.alicdn.com/tfs/TB1SkFLrQZmBKNjSZPiXXXFNVXa-1024-1024.jpg',
108
- back: '//gw.alicdn.com/tfs/TB1z9F2h4tnkeRjSZSgXXXAuXXa-1024-1024.jpg',
109
- magFilter: Hilo3d.constants.LINEAR,
110
- minFilter: Hilo3d.constants.LINEAR_MIPMAP_LINEAR
111
- }, {
112
- src: '//gw.alicdn.com/tfs/TB1.K0CrYZnBKNjSZFhXXc.oXXa-256-256.png',
113
- wrapS: Hilo3d.constants.CLAMP_TO_EDGE,
114
- wrapT: Hilo3d.constants.CLAMP_TO_EDGE,
115
- type: 'Texture'
116
- }]).start().on('complete', function() {
117
- var result = loadQueue.getAllContent();
118
-
119
- callback({
120
- diffuseEnvMap: result[0],
121
- specularEnvMap: result[1],
122
- brdfLUT: result[2],
123
- });
124
- });
125
- }
126
- };
127
-
128
- utils.keys = utils.parseQuery(location.href);