elation-engine 0.9.113 → 0.9.115
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/systems/render.css +5 -1
- package/package.json +1 -1
- package/scripts/assets.js +103 -20
- package/scripts/assetworker.js +18 -1
- package/scripts/external/holoplay.js +1494 -0
- package/scripts/external/octree.js +0 -0
- package/scripts/external/three/CSS3DRenderer.js +46 -43
- package/scripts/external/three/CubemapToEquirectangular.js +1 -1
- package/scripts/external/three/three-extras.js +1553 -392
- package/scripts/external/three/three-icosa.js +2575 -0
- package/scripts/external/three/three-loaders.js +925 -133
- package/scripts/external/three/three-postprocessing.js +3 -3
- package/scripts/external/three/three-r116dev.js +50930 -0
- package/scripts/external/three/three-spotlighttextures.js +50953 -0
- package/scripts/external/three/three-vrm.js +2 -2
- package/scripts/external/three/three-working.js +35968 -0
- package/scripts/external/three/three.js +38532 -24087
- package/scripts/external/three-mesh-bvh.js +5370 -0
- package/scripts/external/three-old/BVHLoader.js +406 -0
- package/scripts/external/three-old/ColladaLoader.js +5519 -0
- package/scripts/external/three-old/ColladaLoader2.js +1694 -0
- package/scripts/external/three-old/CubemapToEquirectangular.js +188 -0
- package/scripts/external/three-old/DDSLoader.js +269 -0
- package/scripts/external/three-old/FBXLoader-mine.js +5063 -0
- package/scripts/external/three-old/FBXLoader.js +5112 -0
- package/scripts/external/three-old/FlyControls.js +295 -0
- package/scripts/external/three-old/GLTF2Loader.js +2950 -0
- package/scripts/external/three-old/GLTFLoader.js +2213 -0
- package/scripts/external/three-old/JSONLoader.js +435 -0
- package/scripts/external/three-old/MTLLoader.js +533 -0
- package/scripts/external/three-old/OBJLoader-experimental.js +874 -0
- package/scripts/external/three-old/OBJLoader-working.js +727 -0
- package/scripts/external/three-old/OBJLoader.js +723 -0
- package/scripts/external/three-old/OBJMTLLoader.js +440 -0
- package/scripts/external/three-old/OrbitControls.js +592 -0
- package/scripts/external/three-old/PLYLoader.js +517 -0
- package/scripts/external/three-old/TransformControls.js +1100 -0
- package/scripts/external/three-old/VRMLLoader.js +1021 -0
- package/scripts/external/three-old/glTFLoader-combined.js +2513 -0
- package/scripts/external/three-old/nodethree.js +44018 -0
- package/scripts/external/three-old/render/BleachBypassShader.js +64 -0
- package/scripts/external/three-old/render/BloomPass.js +116 -0
- package/scripts/external/three-old/render/CSS3DRenderer.js +310 -0
- package/scripts/external/three-old/render/ClearPass.js +44 -0
- package/scripts/external/three-old/render/ConvolutionShader.js +101 -0
- package/scripts/external/three-old/render/CopyShader.js +46 -0
- package/scripts/external/three-old/render/EffectComposer.js +211 -0
- package/scripts/external/three-old/render/FXAAShader.js +88 -0
- package/scripts/external/three-old/render/FilmPass.js +60 -0
- package/scripts/external/three-old/render/FilmShader.js +104 -0
- package/scripts/external/three-old/render/ManualMSAARenderPass.js +168 -0
- package/scripts/external/three-old/render/MaskPass.js +97 -0
- package/scripts/external/three-old/render/OculusRenderPass.js +84 -0
- package/scripts/external/three-old/render/OculusRiftEffect.js +240 -0
- package/scripts/external/three-old/render/PortalRenderPass.js +166 -0
- package/scripts/external/three-old/render/RecordingPass.js +208 -0
- package/scripts/external/three-old/render/RenderPass.js +57 -0
- package/scripts/external/three-old/render/SSAOShader.js +259 -0
- package/scripts/external/three-old/render/SepiaShader.js +54 -0
- package/scripts/external/three-old/render/ShaderPass.js +66 -0
- package/scripts/external/three-old/render/VREffect.js +482 -0
- package/scripts/external/three-old/shimthree.js +23 -0
- package/scripts/external/three-old/stats.js +6 -0
- package/scripts/external/three-old/three-88dev.js +45004 -0
- package/scripts/external/three-old/three-backgroundoptimization.js +44432 -0
- package/scripts/external/three-old/three-updates.js +44735 -0
- package/scripts/external/three-old/three-working.js +44719 -0
- package/scripts/external/three-old/three.js +44431 -0
- package/scripts/external/three-old/threex.rendererstats.js +66 -0
- package/scripts/external/three-old/tween.js +13 -0
- package/scripts/external/webvr-polyfill-new.js +3497 -0
- package/scripts/external/webvr-polyfill-newest.js +3491 -0
- package/scripts/external/webvr-polyfill-old.js +6337 -0
- package/scripts/geometries.js +2 -2
- package/scripts/math.js +6 -6
- package/scripts/systems/admin.js +1 -1
- package/scripts/systems/controls.js +6 -4
- package/scripts/systems/physics.js +10 -10
- package/scripts/systems/render.js +58 -20
- package/scripts/systems/render2.js +38 -0
- package/scripts/things/camera.js +6 -1
- package/scripts/things/generic-trackedvectors.js +1875 -0
- package/scripts/things/generic.js +3 -4
- package/scripts/things/label2d.js +1 -1
- package/scripts/things/leapmotion.js +6 -6
- package/scripts/things/menu.js +1 -1
- package/scripts/things/player-bak.js +638 -0
- package/scripts/things/player.js +28 -10
- package/scripts/things/skysphere.js +1 -1
- package/scripts/things/terrain.js +1 -1
- package/scripts/things/text.js +1 -1
|
@@ -0,0 +1,1100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author arodic / https://github.com/arodic
|
|
3
|
+
*/
|
|
4
|
+
/*jshint sub:true*/
|
|
5
|
+
|
|
6
|
+
( function () {
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var GizmoMaterial = function ( parameters ) {
|
|
12
|
+
|
|
13
|
+
THREE.MeshBasicMaterial.call( this );
|
|
14
|
+
|
|
15
|
+
this.depthTest = false;
|
|
16
|
+
this.depthWrite = false;
|
|
17
|
+
this.side = THREE.DoubleSide;
|
|
18
|
+
this.transparent = true;
|
|
19
|
+
|
|
20
|
+
this.setValues( parameters );
|
|
21
|
+
|
|
22
|
+
this.oldColor = this.color.clone();
|
|
23
|
+
this.oldOpacity = this.opacity;
|
|
24
|
+
|
|
25
|
+
this.highlight = function( highlighted ) {
|
|
26
|
+
|
|
27
|
+
if ( highlighted ) {
|
|
28
|
+
|
|
29
|
+
this.color.setRGB( 1, 1, 0 );
|
|
30
|
+
this.opacity = 1;
|
|
31
|
+
|
|
32
|
+
} else {
|
|
33
|
+
|
|
34
|
+
this.color.copy( this.oldColor );
|
|
35
|
+
this.opacity = this.oldOpacity;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
GizmoMaterial.prototype = Object.create( THREE.MeshBasicMaterial.prototype );
|
|
44
|
+
GizmoMaterial.prototype.constructor = GizmoMaterial;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
var GizmoLineMaterial = function ( parameters ) {
|
|
48
|
+
|
|
49
|
+
THREE.LineBasicMaterial.call( this );
|
|
50
|
+
|
|
51
|
+
this.depthTest = false;
|
|
52
|
+
this.depthWrite = false;
|
|
53
|
+
this.transparent = true;
|
|
54
|
+
this.linewidth = 1;
|
|
55
|
+
|
|
56
|
+
this.setValues( parameters );
|
|
57
|
+
|
|
58
|
+
this.oldColor = this.color.clone();
|
|
59
|
+
this.oldOpacity = this.opacity;
|
|
60
|
+
|
|
61
|
+
this.highlight = function( highlighted ) {
|
|
62
|
+
|
|
63
|
+
if ( highlighted ) {
|
|
64
|
+
|
|
65
|
+
this.color.setRGB( 1, 1, 0 );
|
|
66
|
+
this.opacity = 1;
|
|
67
|
+
|
|
68
|
+
} else {
|
|
69
|
+
|
|
70
|
+
this.color.copy( this.oldColor );
|
|
71
|
+
this.opacity = this.oldOpacity;
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
GizmoLineMaterial.prototype = Object.create( THREE.LineBasicMaterial.prototype );
|
|
80
|
+
GizmoLineMaterial.prototype.constructor = GizmoLineMaterial;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
var pickerMaterial = new GizmoMaterial( { visible: false, transparent: false } );
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
THREE.TransformGizmo = function () {
|
|
87
|
+
|
|
88
|
+
var scope = this;
|
|
89
|
+
|
|
90
|
+
this.init = function () {
|
|
91
|
+
|
|
92
|
+
THREE.Object3D.call( this );
|
|
93
|
+
|
|
94
|
+
this.handles = new THREE.Object3D();
|
|
95
|
+
this.pickers = new THREE.Object3D();
|
|
96
|
+
this.planes = new THREE.Object3D();
|
|
97
|
+
|
|
98
|
+
this.add( this.handles );
|
|
99
|
+
this.add( this.pickers );
|
|
100
|
+
this.add( this.planes );
|
|
101
|
+
|
|
102
|
+
//// PLANES
|
|
103
|
+
|
|
104
|
+
var planeGeometry = new THREE.PlaneBufferGeometry( 50, 50, 2, 2 );
|
|
105
|
+
var planeMaterial = new THREE.MeshBasicMaterial( { visible: false, side: THREE.DoubleSide } );
|
|
106
|
+
|
|
107
|
+
var planes = {
|
|
108
|
+
"XY": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
109
|
+
"YZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
110
|
+
"XZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
111
|
+
"XYZE": new THREE.Mesh( planeGeometry, planeMaterial )
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
this.activePlane = planes[ "XYZE" ];
|
|
115
|
+
|
|
116
|
+
planes[ "YZ" ].rotation.set( 0, Math.PI / 2, 0 );
|
|
117
|
+
planes[ "XZ" ].rotation.set( - Math.PI / 2, 0, 0 );
|
|
118
|
+
|
|
119
|
+
for ( var i in planes ) {
|
|
120
|
+
|
|
121
|
+
planes[ i ].name = i;
|
|
122
|
+
this.planes.add( planes[ i ] );
|
|
123
|
+
this.planes[ i ] = planes[ i ];
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//// HANDLES AND PICKERS
|
|
128
|
+
|
|
129
|
+
var setupGizmos = function( gizmoMap, parent ) {
|
|
130
|
+
|
|
131
|
+
for ( var name in gizmoMap ) {
|
|
132
|
+
|
|
133
|
+
for ( i = gizmoMap[ name ].length; i --; ) {
|
|
134
|
+
|
|
135
|
+
var object = gizmoMap[ name ][ i ][ 0 ];
|
|
136
|
+
var position = gizmoMap[ name ][ i ][ 1 ];
|
|
137
|
+
var rotation = gizmoMap[ name ][ i ][ 2 ];
|
|
138
|
+
|
|
139
|
+
object.name = name;
|
|
140
|
+
|
|
141
|
+
if ( position ) object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
|
|
142
|
+
if ( rotation ) object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
|
|
143
|
+
|
|
144
|
+
parent.add( object );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
setupGizmos( this.handleGizmos, this.handles );
|
|
153
|
+
setupGizmos( this.pickerGizmos, this.pickers );
|
|
154
|
+
|
|
155
|
+
// reset Transformations
|
|
156
|
+
|
|
157
|
+
this.traverse( function ( child ) {
|
|
158
|
+
|
|
159
|
+
if ( child instanceof THREE.Mesh ) {
|
|
160
|
+
|
|
161
|
+
child.updateMatrix();
|
|
162
|
+
|
|
163
|
+
var tempGeometry = child.geometry.clone();
|
|
164
|
+
tempGeometry.applyMatrix( child.matrix );
|
|
165
|
+
child.geometry = tempGeometry;
|
|
166
|
+
|
|
167
|
+
child.position.set( 0, 0, 0 );
|
|
168
|
+
child.rotation.set( 0, 0, 0 );
|
|
169
|
+
child.scale.set( 1, 1, 1 );
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
} );
|
|
174
|
+
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
this.highlight = function ( axis ) {
|
|
178
|
+
|
|
179
|
+
this.traverse( function( child ) {
|
|
180
|
+
|
|
181
|
+
if ( child.material && child.material.highlight ) {
|
|
182
|
+
|
|
183
|
+
if ( child.name === axis ) {
|
|
184
|
+
|
|
185
|
+
child.material.highlight( true );
|
|
186
|
+
|
|
187
|
+
} else {
|
|
188
|
+
|
|
189
|
+
child.material.highlight( false );
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
} );
|
|
196
|
+
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
THREE.TransformGizmo.prototype = Object.create( THREE.Object3D.prototype );
|
|
202
|
+
THREE.TransformGizmo.prototype.constructor = THREE.TransformGizmo;
|
|
203
|
+
|
|
204
|
+
THREE.TransformGizmo.prototype.update = function ( rotation, eye ) {
|
|
205
|
+
|
|
206
|
+
var vec1 = new THREE.Vector3( 0, 0, 0 );
|
|
207
|
+
var vec2 = new THREE.Vector3( 0, 1, 0 );
|
|
208
|
+
var lookAtMatrix = new THREE.Matrix4();
|
|
209
|
+
|
|
210
|
+
this.traverse( function( child ) {
|
|
211
|
+
|
|
212
|
+
if ( child.name.search( "E" ) !== - 1 ) {
|
|
213
|
+
|
|
214
|
+
child.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, vec2 ) );
|
|
215
|
+
|
|
216
|
+
} else if ( child.name.search( "X" ) !== - 1 || child.name.search( "Y" ) !== - 1 || child.name.search( "Z" ) !== - 1 ) {
|
|
217
|
+
|
|
218
|
+
child.quaternion.setFromEuler( rotation );
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} );
|
|
223
|
+
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
THREE.TransformGizmoTranslate = function () {
|
|
227
|
+
|
|
228
|
+
THREE.TransformGizmo.call( this );
|
|
229
|
+
|
|
230
|
+
var arrowGeometry = new THREE.Geometry();
|
|
231
|
+
var mesh = new THREE.Mesh( new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false ) );
|
|
232
|
+
mesh.position.y = 0.5;
|
|
233
|
+
mesh.updateMatrix();
|
|
234
|
+
mesh.renderOrder = 10;
|
|
235
|
+
arrowGeometry.merge( mesh.geometry, mesh.matrix );
|
|
236
|
+
|
|
237
|
+
var lineXGeometry = new THREE.BufferGeometry();
|
|
238
|
+
lineXGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
|
|
239
|
+
|
|
240
|
+
var lineYGeometry = new THREE.BufferGeometry();
|
|
241
|
+
lineYGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
|
|
242
|
+
|
|
243
|
+
var lineZGeometry = new THREE.BufferGeometry();
|
|
244
|
+
lineZGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
|
|
245
|
+
|
|
246
|
+
this.handleGizmos = {
|
|
247
|
+
|
|
248
|
+
X: [
|
|
249
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
|
|
250
|
+
[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
251
|
+
],
|
|
252
|
+
|
|
253
|
+
Y: [
|
|
254
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
|
|
255
|
+
[ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
256
|
+
],
|
|
257
|
+
|
|
258
|
+
Z: [
|
|
259
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
|
|
260
|
+
[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
261
|
+
],
|
|
262
|
+
|
|
263
|
+
XYZ: [
|
|
264
|
+
[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, 0 ] ]
|
|
265
|
+
],
|
|
266
|
+
|
|
267
|
+
XY: [
|
|
268
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.15, 0.15, 0 ] ]
|
|
269
|
+
],
|
|
270
|
+
|
|
271
|
+
YZ: [
|
|
272
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ] ]
|
|
273
|
+
],
|
|
274
|
+
|
|
275
|
+
XZ: [
|
|
276
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ] ]
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
this.pickerGizmos = {
|
|
282
|
+
|
|
283
|
+
X: [
|
|
284
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
|
|
285
|
+
],
|
|
286
|
+
|
|
287
|
+
Y: [
|
|
288
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ]
|
|
289
|
+
],
|
|
290
|
+
|
|
291
|
+
Z: [
|
|
292
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
|
|
293
|
+
],
|
|
294
|
+
|
|
295
|
+
XYZ: [
|
|
296
|
+
[ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), pickerMaterial ) ]
|
|
297
|
+
],
|
|
298
|
+
|
|
299
|
+
XY: [
|
|
300
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0.2, 0 ] ]
|
|
301
|
+
],
|
|
302
|
+
|
|
303
|
+
YZ: [
|
|
304
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ] ]
|
|
305
|
+
],
|
|
306
|
+
|
|
307
|
+
XZ: [
|
|
308
|
+
[ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), pickerMaterial ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ] ]
|
|
309
|
+
]
|
|
310
|
+
|
|
311
|
+
};
|
|
312
|
+
this.handleGizmos.X[0][0].renderOrder = 10;
|
|
313
|
+
this.handleGizmos.X[1][0].renderOrder = 10;
|
|
314
|
+
this.handleGizmos.Y[0][0].renderOrder = 10;
|
|
315
|
+
this.handleGizmos.Y[1][0].renderOrder = 10;
|
|
316
|
+
this.handleGizmos.Z[0][0].renderOrder = 10;
|
|
317
|
+
this.handleGizmos.Z[1][0].renderOrder = 10;
|
|
318
|
+
this.handleGizmos.XY[0][0].renderOrder = 10;
|
|
319
|
+
this.handleGizmos.XZ[0][0].renderOrder = 10;
|
|
320
|
+
this.handleGizmos.YZ[0][0].renderOrder = 10;
|
|
321
|
+
this.handleGizmos.XYZ[0][0].renderOrder = 10;
|
|
322
|
+
|
|
323
|
+
this.setActivePlane = function ( axis, eye ) {
|
|
324
|
+
|
|
325
|
+
var tempMatrix = new THREE.Matrix4();
|
|
326
|
+
eye.applyMatrix4( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
327
|
+
|
|
328
|
+
if ( axis === "X" ) {
|
|
329
|
+
|
|
330
|
+
this.activePlane = this.planes[ "XY" ];
|
|
331
|
+
|
|
332
|
+
if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if ( axis === "Y" ) {
|
|
337
|
+
|
|
338
|
+
this.activePlane = this.planes[ "XY" ];
|
|
339
|
+
|
|
340
|
+
if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if ( axis === "Z" ) {
|
|
345
|
+
|
|
346
|
+
this.activePlane = this.planes[ "XZ" ];
|
|
347
|
+
|
|
348
|
+
if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if ( axis === "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
353
|
+
|
|
354
|
+
if ( axis === "XY" ) this.activePlane = this.planes[ "XY" ];
|
|
355
|
+
|
|
356
|
+
if ( axis === "YZ" ) this.activePlane = this.planes[ "YZ" ];
|
|
357
|
+
|
|
358
|
+
if ( axis === "XZ" ) this.activePlane = this.planes[ "XZ" ];
|
|
359
|
+
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
this.init();
|
|
363
|
+
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
THREE.TransformGizmoTranslate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
367
|
+
THREE.TransformGizmoTranslate.prototype.constructor = THREE.TransformGizmoTranslate;
|
|
368
|
+
|
|
369
|
+
THREE.TransformGizmoRotate = function () {
|
|
370
|
+
|
|
371
|
+
THREE.TransformGizmo.call( this );
|
|
372
|
+
|
|
373
|
+
var CircleGeometry = function ( radius, facing, arc ) {
|
|
374
|
+
|
|
375
|
+
var geometry = new THREE.BufferGeometry();
|
|
376
|
+
var vertices = [];
|
|
377
|
+
arc = arc ? arc : 1;
|
|
378
|
+
|
|
379
|
+
for ( var i = 0; i <= 64 * arc; ++ i ) {
|
|
380
|
+
|
|
381
|
+
if ( facing === 'x' ) vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
|
|
382
|
+
if ( facing === 'y' ) vertices.push( Math.cos( i / 32 * Math.PI ) * radius, 0, Math.sin( i / 32 * Math.PI ) * radius );
|
|
383
|
+
if ( facing === 'z' ) vertices.push( Math.sin( i / 32 * Math.PI ) * radius, Math.cos( i / 32 * Math.PI ) * radius, 0 );
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
|
|
388
|
+
return geometry;
|
|
389
|
+
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
this.handleGizmos = {
|
|
393
|
+
|
|
394
|
+
X: [
|
|
395
|
+
[ new THREE.Line( new CircleGeometry( 1, 'x', 0.5 ), new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
396
|
+
],
|
|
397
|
+
|
|
398
|
+
Y: [
|
|
399
|
+
[ new THREE.Line( new CircleGeometry( 1, 'y', 0.5 ), new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
400
|
+
],
|
|
401
|
+
|
|
402
|
+
Z: [
|
|
403
|
+
[ new THREE.Line( new CircleGeometry( 1, 'z', 0.5 ), new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
404
|
+
],
|
|
405
|
+
|
|
406
|
+
E: [
|
|
407
|
+
[ new THREE.Line( new CircleGeometry( 1.25, 'z', 1 ), new GizmoLineMaterial( { color: 0xcccc00 } ) ) ]
|
|
408
|
+
],
|
|
409
|
+
|
|
410
|
+
XYZE: [
|
|
411
|
+
[ new THREE.Line( new CircleGeometry( 1, 'z', 1 ), new GizmoLineMaterial( { color: 0x787878 } ) ) ]
|
|
412
|
+
]
|
|
413
|
+
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
this.pickerGizmos = {
|
|
417
|
+
|
|
418
|
+
X: [
|
|
419
|
+
[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ] ]
|
|
420
|
+
],
|
|
421
|
+
|
|
422
|
+
Y: [
|
|
423
|
+
[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ] ]
|
|
424
|
+
],
|
|
425
|
+
|
|
426
|
+
Z: [
|
|
427
|
+
[ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), pickerMaterial ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
|
|
428
|
+
],
|
|
429
|
+
|
|
430
|
+
E: [
|
|
431
|
+
[ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.12, 2, 24 ), pickerMaterial ) ]
|
|
432
|
+
],
|
|
433
|
+
|
|
434
|
+
XYZE: [
|
|
435
|
+
[ new THREE.Mesh( new THREE.Geometry() ) ]// TODO
|
|
436
|
+
]
|
|
437
|
+
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
this.setActivePlane = function ( axis ) {
|
|
441
|
+
|
|
442
|
+
if ( axis === "E" ) this.activePlane = this.planes[ "XYZE" ];
|
|
443
|
+
|
|
444
|
+
if ( axis === "X" ) this.activePlane = this.planes[ "YZ" ];
|
|
445
|
+
|
|
446
|
+
if ( axis === "Y" ) this.activePlane = this.planes[ "XZ" ];
|
|
447
|
+
|
|
448
|
+
if ( axis === "Z" ) this.activePlane = this.planes[ "XY" ];
|
|
449
|
+
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
this.update = function ( rotation, eye2 ) {
|
|
453
|
+
|
|
454
|
+
THREE.TransformGizmo.prototype.update.apply( this, arguments );
|
|
455
|
+
|
|
456
|
+
var group = {
|
|
457
|
+
|
|
458
|
+
handles: this[ "handles" ],
|
|
459
|
+
pickers: this[ "pickers" ],
|
|
460
|
+
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
var tempMatrix = new THREE.Matrix4();
|
|
464
|
+
var worldRotation = new THREE.Euler( 0, 0, 1 );
|
|
465
|
+
var tempQuaternion = new THREE.Quaternion();
|
|
466
|
+
var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
467
|
+
var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
468
|
+
var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
469
|
+
var quaternionX = new THREE.Quaternion();
|
|
470
|
+
var quaternionY = new THREE.Quaternion();
|
|
471
|
+
var quaternionZ = new THREE.Quaternion();
|
|
472
|
+
var eye = eye2.clone();
|
|
473
|
+
|
|
474
|
+
worldRotation.copy( this.planes[ "XY" ].rotation );
|
|
475
|
+
tempQuaternion.setFromEuler( worldRotation );
|
|
476
|
+
|
|
477
|
+
tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
|
|
478
|
+
eye.applyMatrix4( tempMatrix );
|
|
479
|
+
|
|
480
|
+
this.traverse( function( child ) {
|
|
481
|
+
|
|
482
|
+
tempQuaternion.setFromEuler( worldRotation );
|
|
483
|
+
|
|
484
|
+
if ( child.name === "X" ) {
|
|
485
|
+
|
|
486
|
+
quaternionX.setFromAxisAngle( unitX, Math.atan2( - eye.y, eye.z ) );
|
|
487
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
488
|
+
child.quaternion.copy( tempQuaternion );
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if ( child.name === "Y" ) {
|
|
493
|
+
|
|
494
|
+
quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
|
|
495
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
496
|
+
child.quaternion.copy( tempQuaternion );
|
|
497
|
+
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if ( child.name === "Z" ) {
|
|
501
|
+
|
|
502
|
+
quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
|
|
503
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
504
|
+
child.quaternion.copy( tempQuaternion );
|
|
505
|
+
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
} );
|
|
509
|
+
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
this.init();
|
|
513
|
+
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
THREE.TransformGizmoRotate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
517
|
+
THREE.TransformGizmoRotate.prototype.constructor = THREE.TransformGizmoRotate;
|
|
518
|
+
|
|
519
|
+
THREE.TransformGizmoScale = function () {
|
|
520
|
+
|
|
521
|
+
THREE.TransformGizmo.call( this );
|
|
522
|
+
|
|
523
|
+
var arrowGeometry = new THREE.Geometry();
|
|
524
|
+
var mesh = new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ) );
|
|
525
|
+
mesh.position.y = 0.5;
|
|
526
|
+
mesh.updateMatrix();
|
|
527
|
+
|
|
528
|
+
arrowGeometry.merge( mesh.geometry, mesh.matrix );
|
|
529
|
+
|
|
530
|
+
var lineXGeometry = new THREE.BufferGeometry();
|
|
531
|
+
lineXGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
|
|
532
|
+
|
|
533
|
+
var lineYGeometry = new THREE.BufferGeometry();
|
|
534
|
+
lineYGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
|
|
535
|
+
|
|
536
|
+
var lineZGeometry = new THREE.BufferGeometry();
|
|
537
|
+
lineZGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
|
|
538
|
+
|
|
539
|
+
this.handleGizmos = {
|
|
540
|
+
|
|
541
|
+
X: [
|
|
542
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ],
|
|
543
|
+
[ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
544
|
+
],
|
|
545
|
+
|
|
546
|
+
Y: [
|
|
547
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
|
|
548
|
+
[ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
549
|
+
],
|
|
550
|
+
|
|
551
|
+
Z: [
|
|
552
|
+
[ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ] ],
|
|
553
|
+
[ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
554
|
+
],
|
|
555
|
+
|
|
556
|
+
XYZ: [
|
|
557
|
+
[ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
|
|
558
|
+
]
|
|
559
|
+
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
this.pickerGizmos = {
|
|
563
|
+
|
|
564
|
+
X: [
|
|
565
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ] ]
|
|
566
|
+
],
|
|
567
|
+
|
|
568
|
+
Y: [
|
|
569
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0.6, 0 ] ]
|
|
570
|
+
],
|
|
571
|
+
|
|
572
|
+
Z: [
|
|
573
|
+
[ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), pickerMaterial ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ] ]
|
|
574
|
+
],
|
|
575
|
+
|
|
576
|
+
XYZ: [
|
|
577
|
+
[ new THREE.Mesh( new THREE.BoxGeometry( 0.4, 0.4, 0.4 ), pickerMaterial ) ]
|
|
578
|
+
]
|
|
579
|
+
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
this.setActivePlane = function ( axis, eye ) {
|
|
583
|
+
|
|
584
|
+
var tempMatrix = new THREE.Matrix4();
|
|
585
|
+
eye.applyMatrix4( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
586
|
+
|
|
587
|
+
if ( axis === "X" ) {
|
|
588
|
+
|
|
589
|
+
this.activePlane = this.planes[ "XY" ];
|
|
590
|
+
if ( Math.abs( eye.y ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "XZ" ];
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if ( axis === "Y" ) {
|
|
595
|
+
|
|
596
|
+
this.activePlane = this.planes[ "XY" ];
|
|
597
|
+
if ( Math.abs( eye.x ) > Math.abs( eye.z ) ) this.activePlane = this.planes[ "YZ" ];
|
|
598
|
+
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if ( axis === "Z" ) {
|
|
602
|
+
|
|
603
|
+
this.activePlane = this.planes[ "XZ" ];
|
|
604
|
+
if ( Math.abs( eye.x ) > Math.abs( eye.y ) ) this.activePlane = this.planes[ "YZ" ];
|
|
605
|
+
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if ( axis === "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
609
|
+
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
this.init();
|
|
613
|
+
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
THREE.TransformGizmoScale.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
617
|
+
THREE.TransformGizmoScale.prototype.constructor = THREE.TransformGizmoScale;
|
|
618
|
+
|
|
619
|
+
THREE.TransformControls = function ( camera, domElement ) {
|
|
620
|
+
|
|
621
|
+
// TODO: Make non-uniform scale and rotate play nice in hierarchies
|
|
622
|
+
// TODO: ADD RXYZ contol
|
|
623
|
+
|
|
624
|
+
THREE.Object3D.call( this );
|
|
625
|
+
|
|
626
|
+
domElement = ( domElement !== undefined ) ? domElement : document;
|
|
627
|
+
|
|
628
|
+
this.object = undefined;
|
|
629
|
+
this.visible = false;
|
|
630
|
+
this.snap = null;
|
|
631
|
+
this.space = "world";
|
|
632
|
+
this.size = 1;
|
|
633
|
+
this.axis = null;
|
|
634
|
+
|
|
635
|
+
var scope = this;
|
|
636
|
+
|
|
637
|
+
var _mode = "translate";
|
|
638
|
+
var _dragging = false;
|
|
639
|
+
var _plane = "XY";
|
|
640
|
+
var _gizmo = {
|
|
641
|
+
|
|
642
|
+
"translate": new THREE.TransformGizmoTranslate(),
|
|
643
|
+
"rotate": new THREE.TransformGizmoRotate(),
|
|
644
|
+
"scale": new THREE.TransformGizmoScale()
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
for ( var type in _gizmo ) {
|
|
648
|
+
|
|
649
|
+
var gizmoObj = _gizmo[ type ];
|
|
650
|
+
|
|
651
|
+
gizmoObj.visible = ( type === _mode );
|
|
652
|
+
this.add( gizmoObj );
|
|
653
|
+
gizmoObj.renderOrder = 10;
|
|
654
|
+
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
var changeEvent = { type: "change" };
|
|
658
|
+
var mouseDownEvent = { type: "mouseDown" };
|
|
659
|
+
var mouseUpEvent = { type: "mouseUp", mode: _mode };
|
|
660
|
+
var objectChangeEvent = { type: "objectChange" };
|
|
661
|
+
|
|
662
|
+
var ray = new THREE.Raycaster();
|
|
663
|
+
var pointerVector = new THREE.Vector2();
|
|
664
|
+
|
|
665
|
+
var point = new THREE.Vector3();
|
|
666
|
+
var offset = new THREE.Vector3();
|
|
667
|
+
|
|
668
|
+
var rotation = new THREE.Vector3();
|
|
669
|
+
var offsetRotation = new THREE.Vector3();
|
|
670
|
+
var scale = 1;
|
|
671
|
+
|
|
672
|
+
var lookAtMatrix = new THREE.Matrix4();
|
|
673
|
+
var eye = new THREE.Vector3();
|
|
674
|
+
|
|
675
|
+
var tempMatrix = new THREE.Matrix4();
|
|
676
|
+
var tempVector = new THREE.Vector3();
|
|
677
|
+
var tempQuaternion = new THREE.Quaternion();
|
|
678
|
+
var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
679
|
+
var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
680
|
+
var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
681
|
+
|
|
682
|
+
var quaternionXYZ = new THREE.Quaternion();
|
|
683
|
+
var quaternionX = new THREE.Quaternion();
|
|
684
|
+
var quaternionY = new THREE.Quaternion();
|
|
685
|
+
var quaternionZ = new THREE.Quaternion();
|
|
686
|
+
var quaternionE = new THREE.Quaternion();
|
|
687
|
+
|
|
688
|
+
var oldPosition = new THREE.Vector3();
|
|
689
|
+
var oldScale = new THREE.Vector3();
|
|
690
|
+
var oldRotationMatrix = new THREE.Matrix4();
|
|
691
|
+
|
|
692
|
+
var parentRotationMatrix = new THREE.Matrix4();
|
|
693
|
+
var parentScale = new THREE.Vector3();
|
|
694
|
+
|
|
695
|
+
var worldPosition = new THREE.Vector3();
|
|
696
|
+
var worldRotation = new THREE.Euler();
|
|
697
|
+
var worldRotationMatrix = new THREE.Matrix4();
|
|
698
|
+
var camPosition = new THREE.Vector3();
|
|
699
|
+
var camRotation = new THREE.Euler();
|
|
700
|
+
|
|
701
|
+
domElement.addEventListener( "mousedown", onPointerDown, false );
|
|
702
|
+
domElement.addEventListener( "touchstart", onPointerDown, false );
|
|
703
|
+
|
|
704
|
+
domElement.addEventListener( "mousemove", onPointerHover, false );
|
|
705
|
+
domElement.addEventListener( "touchmove", onPointerHover, false );
|
|
706
|
+
|
|
707
|
+
domElement.addEventListener( "mousemove", onPointerMove, false );
|
|
708
|
+
domElement.addEventListener( "touchmove", onPointerMove, false );
|
|
709
|
+
|
|
710
|
+
domElement.addEventListener( "mouseup", onPointerUp, false );
|
|
711
|
+
domElement.addEventListener( "mouseout", onPointerUp, false );
|
|
712
|
+
domElement.addEventListener( "touchend", onPointerUp, false );
|
|
713
|
+
domElement.addEventListener( "touchcancel", onPointerUp, false );
|
|
714
|
+
domElement.addEventListener( "touchleave", onPointerUp, false );
|
|
715
|
+
|
|
716
|
+
this.dispose = function () {
|
|
717
|
+
|
|
718
|
+
domElement.removeEventListener( "mousedown", onPointerDown );
|
|
719
|
+
domElement.removeEventListener( "touchstart", onPointerDown );
|
|
720
|
+
|
|
721
|
+
domElement.removeEventListener( "mousemove", onPointerHover );
|
|
722
|
+
domElement.removeEventListener( "touchmove", onPointerHover );
|
|
723
|
+
|
|
724
|
+
domElement.removeEventListener( "mousemove", onPointerMove );
|
|
725
|
+
domElement.removeEventListener( "touchmove", onPointerMove );
|
|
726
|
+
|
|
727
|
+
domElement.removeEventListener( "mouseup", onPointerUp );
|
|
728
|
+
domElement.removeEventListener( "mouseout", onPointerUp );
|
|
729
|
+
domElement.removeEventListener( "touchend", onPointerUp );
|
|
730
|
+
domElement.removeEventListener( "touchcancel", onPointerUp );
|
|
731
|
+
domElement.removeEventListener( "touchleave", onPointerUp );
|
|
732
|
+
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
this.attach = function ( object ) {
|
|
736
|
+
|
|
737
|
+
this.object = object;
|
|
738
|
+
this.visible = true;
|
|
739
|
+
this.update();
|
|
740
|
+
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
this.detach = function () {
|
|
744
|
+
|
|
745
|
+
this.object = undefined;
|
|
746
|
+
this.visible = false;
|
|
747
|
+
this.axis = null;
|
|
748
|
+
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
this.setMode = function ( mode ) {
|
|
752
|
+
|
|
753
|
+
_mode = mode ? mode : _mode;
|
|
754
|
+
|
|
755
|
+
if ( _mode === "scale" ) scope.space = "local";
|
|
756
|
+
|
|
757
|
+
for ( var type in _gizmo ) _gizmo[ type ].visible = ( type === _mode );
|
|
758
|
+
|
|
759
|
+
this.update();
|
|
760
|
+
scope.dispatchEvent( changeEvent );
|
|
761
|
+
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
this.setSnap = function ( snap ) {
|
|
765
|
+
|
|
766
|
+
scope.snap = snap;
|
|
767
|
+
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
this.setSize = function ( size ) {
|
|
771
|
+
|
|
772
|
+
scope.size = size;
|
|
773
|
+
this.update();
|
|
774
|
+
scope.dispatchEvent( changeEvent );
|
|
775
|
+
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
this.setSpace = function ( space ) {
|
|
779
|
+
|
|
780
|
+
scope.space = space;
|
|
781
|
+
this.update();
|
|
782
|
+
scope.dispatchEvent( changeEvent );
|
|
783
|
+
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
this.update = function () {
|
|
787
|
+
|
|
788
|
+
if ( scope.object === undefined ) return;
|
|
789
|
+
|
|
790
|
+
scope.object.updateMatrixWorld();
|
|
791
|
+
worldPosition.setFromMatrixPosition( scope.object.matrixWorld );
|
|
792
|
+
worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) );
|
|
793
|
+
|
|
794
|
+
camera.updateMatrixWorld();
|
|
795
|
+
camPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
796
|
+
camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) );
|
|
797
|
+
|
|
798
|
+
scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size;
|
|
799
|
+
this.position.copy( worldPosition );
|
|
800
|
+
this.scale.set( scale, scale, scale );
|
|
801
|
+
|
|
802
|
+
eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
803
|
+
|
|
804
|
+
if ( scope.space === "local" ) {
|
|
805
|
+
|
|
806
|
+
_gizmo[ _mode ].update( worldRotation, eye );
|
|
807
|
+
|
|
808
|
+
} else if ( scope.space === "world" ) {
|
|
809
|
+
|
|
810
|
+
_gizmo[ _mode ].update( new THREE.Euler(), eye );
|
|
811
|
+
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
_gizmo[ _mode ].highlight( scope.axis );
|
|
815
|
+
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
function onPointerHover( event ) {
|
|
819
|
+
|
|
820
|
+
if ( scope.object === undefined || _dragging === true ) return;
|
|
821
|
+
|
|
822
|
+
var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
|
|
823
|
+
|
|
824
|
+
var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
|
|
825
|
+
|
|
826
|
+
var axis = null;
|
|
827
|
+
|
|
828
|
+
if ( intersect ) {
|
|
829
|
+
|
|
830
|
+
axis = intersect.object.name;
|
|
831
|
+
|
|
832
|
+
event.preventDefault();
|
|
833
|
+
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
if ( scope.axis !== axis ) {
|
|
837
|
+
|
|
838
|
+
scope.axis = axis;
|
|
839
|
+
scope.update();
|
|
840
|
+
scope.dispatchEvent( changeEvent );
|
|
841
|
+
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function onPointerDown( event ) {
|
|
847
|
+
|
|
848
|
+
if ( scope.object === undefined || _dragging === true ) return;
|
|
849
|
+
|
|
850
|
+
var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
|
|
851
|
+
|
|
852
|
+
if ( pointer.button === 0 || pointer.button === undefined ) {
|
|
853
|
+
|
|
854
|
+
var intersect = intersectObjects( pointer, _gizmo[ _mode ].pickers.children );
|
|
855
|
+
|
|
856
|
+
if ( intersect ) {
|
|
857
|
+
|
|
858
|
+
event.preventDefault();
|
|
859
|
+
event.stopPropagation();
|
|
860
|
+
|
|
861
|
+
scope.dispatchEvent( mouseDownEvent );
|
|
862
|
+
|
|
863
|
+
scope.axis = intersect.object.name;
|
|
864
|
+
|
|
865
|
+
scope.update();
|
|
866
|
+
|
|
867
|
+
eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
868
|
+
|
|
869
|
+
_gizmo[ _mode ].setActivePlane( scope.axis, eye );
|
|
870
|
+
|
|
871
|
+
var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
|
|
872
|
+
|
|
873
|
+
if ( planeIntersect ) {
|
|
874
|
+
|
|
875
|
+
oldPosition.copy( scope.object.position );
|
|
876
|
+
oldScale.copy( scope.object.scale );
|
|
877
|
+
|
|
878
|
+
oldRotationMatrix.extractRotation( scope.object.matrix );
|
|
879
|
+
worldRotationMatrix.extractRotation( scope.object.matrixWorld );
|
|
880
|
+
|
|
881
|
+
parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
|
|
882
|
+
parentScale.setFromMatrixScale( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
|
|
883
|
+
|
|
884
|
+
offset.copy( planeIntersect.point );
|
|
885
|
+
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
_dragging = true;
|
|
893
|
+
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function onPointerMove( event ) {
|
|
897
|
+
|
|
898
|
+
if ( scope.object === undefined || scope.axis === null || _dragging === false ) return;
|
|
899
|
+
|
|
900
|
+
var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
|
|
901
|
+
|
|
902
|
+
var planeIntersect = intersectObjects( pointer, [ _gizmo[ _mode ].activePlane ] );
|
|
903
|
+
|
|
904
|
+
if ( planeIntersect === false ) return;
|
|
905
|
+
|
|
906
|
+
event.preventDefault();
|
|
907
|
+
event.stopPropagation();
|
|
908
|
+
|
|
909
|
+
point.copy( planeIntersect.point );
|
|
910
|
+
|
|
911
|
+
if ( _mode === "translate" ) {
|
|
912
|
+
|
|
913
|
+
point.sub( offset );
|
|
914
|
+
point.multiply( parentScale );
|
|
915
|
+
|
|
916
|
+
if ( scope.space === "local" ) {
|
|
917
|
+
|
|
918
|
+
point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
919
|
+
|
|
920
|
+
if ( scope.axis.search( "X" ) === - 1 ) point.x = 0;
|
|
921
|
+
if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0;
|
|
922
|
+
if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0;
|
|
923
|
+
|
|
924
|
+
point.applyMatrix4( oldRotationMatrix );
|
|
925
|
+
|
|
926
|
+
scope.object.position.copy( oldPosition );
|
|
927
|
+
scope.object.position.add( point );
|
|
928
|
+
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if ( scope.space === "world" || scope.axis.search( "XYZ" ) !== - 1 ) {
|
|
932
|
+
|
|
933
|
+
if ( scope.axis.search( "X" ) === - 1 ) point.x = 0;
|
|
934
|
+
if ( scope.axis.search( "Y" ) === - 1 ) point.y = 0;
|
|
935
|
+
if ( scope.axis.search( "Z" ) === - 1 ) point.z = 0;
|
|
936
|
+
|
|
937
|
+
point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
938
|
+
|
|
939
|
+
scope.object.position.copy( oldPosition );
|
|
940
|
+
scope.object.position.add( point );
|
|
941
|
+
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
if ( scope.snap !== null ) {
|
|
945
|
+
|
|
946
|
+
if ( scope.axis.search( "X" ) !== - 1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
|
|
947
|
+
if ( scope.axis.search( "Y" ) !== - 1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
|
|
948
|
+
if ( scope.axis.search( "Z" ) !== - 1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
|
|
949
|
+
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
} else if ( _mode === "scale" ) {
|
|
953
|
+
|
|
954
|
+
point.sub( offset );
|
|
955
|
+
point.multiply( parentScale );
|
|
956
|
+
|
|
957
|
+
if ( scope.space === "local" ) {
|
|
958
|
+
|
|
959
|
+
if ( scope.axis === "XYZ" ) {
|
|
960
|
+
|
|
961
|
+
scale = 1 + ( ( point.y ) / 50 );
|
|
962
|
+
|
|
963
|
+
scope.object.scale.x = oldScale.x * scale;
|
|
964
|
+
scope.object.scale.y = oldScale.y * scale;
|
|
965
|
+
scope.object.scale.z = oldScale.z * scale;
|
|
966
|
+
|
|
967
|
+
} else {
|
|
968
|
+
|
|
969
|
+
point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
970
|
+
|
|
971
|
+
if ( scope.axis === "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 );
|
|
972
|
+
if ( scope.axis === "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 );
|
|
973
|
+
if ( scope.axis === "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 );
|
|
974
|
+
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
} else if ( _mode === "rotate" ) {
|
|
980
|
+
|
|
981
|
+
point.sub( worldPosition );
|
|
982
|
+
point.multiply( parentScale );
|
|
983
|
+
tempVector.copy( offset ).sub( worldPosition );
|
|
984
|
+
tempVector.multiply( parentScale );
|
|
985
|
+
|
|
986
|
+
if ( scope.axis === "E" ) {
|
|
987
|
+
|
|
988
|
+
point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
989
|
+
tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
990
|
+
|
|
991
|
+
rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
992
|
+
offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
993
|
+
|
|
994
|
+
tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
995
|
+
|
|
996
|
+
quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
|
|
997
|
+
quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
998
|
+
|
|
999
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
|
|
1000
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
1001
|
+
|
|
1002
|
+
scope.object.quaternion.copy( tempQuaternion );
|
|
1003
|
+
|
|
1004
|
+
} else if ( scope.axis === "XYZE" ) {
|
|
1005
|
+
|
|
1006
|
+
quaternionE.setFromEuler( point.clone().cross( tempVector ).normalize() ); // rotation axis
|
|
1007
|
+
|
|
1008
|
+
tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
1009
|
+
quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo( tempVector ) );
|
|
1010
|
+
quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
1011
|
+
|
|
1012
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
1013
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
1014
|
+
|
|
1015
|
+
scope.object.quaternion.copy( tempQuaternion );
|
|
1016
|
+
|
|
1017
|
+
} else if ( scope.space === "local" ) {
|
|
1018
|
+
|
|
1019
|
+
point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
1020
|
+
|
|
1021
|
+
tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
1022
|
+
|
|
1023
|
+
rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
1024
|
+
offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
1025
|
+
|
|
1026
|
+
quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
|
|
1027
|
+
quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
1028
|
+
quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
1029
|
+
quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
1030
|
+
|
|
1031
|
+
if ( scope.axis === "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
|
|
1032
|
+
if ( scope.axis === "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
|
|
1033
|
+
if ( scope.axis === "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
|
|
1034
|
+
|
|
1035
|
+
scope.object.quaternion.copy( quaternionXYZ );
|
|
1036
|
+
|
|
1037
|
+
} else if ( scope.space === "world" ) {
|
|
1038
|
+
|
|
1039
|
+
rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
1040
|
+
offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
1041
|
+
|
|
1042
|
+
tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
1043
|
+
|
|
1044
|
+
quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
1045
|
+
quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
1046
|
+
quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
1047
|
+
quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
1048
|
+
|
|
1049
|
+
if ( scope.axis === "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
1050
|
+
if ( scope.axis === "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
1051
|
+
if ( scope.axis === "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
1052
|
+
|
|
1053
|
+
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
1054
|
+
|
|
1055
|
+
scope.object.quaternion.copy( tempQuaternion );
|
|
1056
|
+
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
scope.update();
|
|
1062
|
+
scope.dispatchEvent( changeEvent );
|
|
1063
|
+
scope.dispatchEvent( objectChangeEvent );
|
|
1064
|
+
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function onPointerUp( event ) {
|
|
1068
|
+
|
|
1069
|
+
if ( _dragging && ( scope.axis !== null ) ) {
|
|
1070
|
+
|
|
1071
|
+
mouseUpEvent.mode = _mode;
|
|
1072
|
+
scope.dispatchEvent( mouseUpEvent )
|
|
1073
|
+
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
_dragging = false;
|
|
1077
|
+
onPointerHover( event );
|
|
1078
|
+
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function intersectObjects( pointer, objects ) {
|
|
1082
|
+
|
|
1083
|
+
var rect = domElement.getBoundingClientRect();
|
|
1084
|
+
var x = ( pointer.clientX - rect.left ) / rect.width;
|
|
1085
|
+
var y = ( pointer.clientY - rect.top ) / rect.height;
|
|
1086
|
+
|
|
1087
|
+
pointerVector.set( ( x * 2 ) - 1, - ( y * 2 ) + 1 );
|
|
1088
|
+
ray.setFromCamera( pointerVector, camera );
|
|
1089
|
+
|
|
1090
|
+
var intersections = ray.intersectObjects( objects, true );
|
|
1091
|
+
return intersections[ 0 ] ? intersections[ 0 ] : false;
|
|
1092
|
+
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
THREE.TransformControls.prototype = Object.create( THREE.Object3D.prototype );
|
|
1098
|
+
THREE.TransformControls.prototype.constructor = THREE.TransformControls;
|
|
1099
|
+
|
|
1100
|
+
}() );
|