Newer
Older
/**
* @author Xavier Gibert-González
*
* Creates a crossing arrow for visualizing momentum
*
* Parameters:
* dir - Vector3
* origin - Vector3
* length - Number
* hex - color in hex value
* headLength - Number
* headWidth - Number
*/
THREE.MomentumHelper = function ( dir, origin, length, hex, headLength, headWidth, segments ) {
// dir is assumed to be normalized
THREE.Object3D.call( this );
if ( hex === undefined ) hex = 0xffff00;
if ( length === undefined ) length = 1;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.position = origin;
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3( 0, -0.8, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3( 0, 0.90, 0 ) );
//lineGeometry.dynamic = true;
Xavier Gibert
committed
this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: hex, linewidth: 6 } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );
/*var materials = [
new THREE.MeshLambertMaterial( { color: hex, shading: THREE.SmoothShading, blending: THREE.AdditiveBlending, vertexColors: THREE.VertexColors } ),
new THREE.MeshBasicMaterial( { color: 0x000000, shading: THREE.SmoothShading, wireframe: true, transparent: true } )
];*/
var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, segments, 1 );
coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
//coneGeometry.dynamic = true;
if(!canvas_mode)
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshLambertMaterial( { color: hex, shading: THREE.SmoothShading, blending: THREE.AdditiveBlending, vertexColors: THREE.VertexColors } ) );
else
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: hex } ) );
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//this.cone = THREE.SceneUtils.createMultiMaterialObject( coneGeometry, materials );
this.cone.matrixAutoUpdate = false;
this.add( this.cone );
this.setDirection( dir );
this.setLength( length, headLength, headWidth );
};
THREE.MomentumHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE.MomentumHelper.prototype.setDirection = function () {
var axis = new THREE.Vector3();
var radians;
return function ( dir ) {
// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );
} else {
axis.set( dir.z, 0, - dir.x ).normalize();
radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( axis, radians );
}
};
}();
THREE.MomentumHelper.prototype.setLength = function ( length, headLength, headWidth ) {
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.line.scale.set( 1, length, 1 );
this.line.updateMatrix();
this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();
};
THREE.MomentumHelper.prototype.setColor = function ( hex ) {
this.line.material.color.setHex( hex );
this.cone.material.color.setHex( hex );
};
//************************************************************************************************
/**
* @author Xavier Gibert-González
*
* Creates a target in the sphere
*
* Parameters:
* dir - Vector3
* origin - Vector3
* length - Number
* hex - color in hex value
* headLength - Number
* headWidth - Number
*/
THREE.TargetHelper = function ( dir, origin, length, hex, headLength, headWidth, segments ) {
// dir is assumed to be normalized
THREE.Object3D.call( this );
if ( hex === undefined ) hex = 0xffff00;
if ( length === undefined ) length = 1;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.position = origin;
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3( 0, 1, 0 ) );
lineGeometry.dynamic = true;//xgg
lineGeometry.computeLineDistances();//xgg
this.line = new THREE.Line( lineGeometry, new THREE.LineDashedMaterial( { color: hex, linewidth: 2, dashSize: 2, gapSize: 2} ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//var coneGeometry = new THREE.CylinderGeometry( headLength, headLength, headWidth, segments, 1 );
//Cross shape for target
// points that define shape
var pts = [];
var cross_scale = 0.3;
pts.push( new THREE.Vector2 (0, 2*cross_scale));
pts.push( new THREE.Vector2 (-5*cross_scale, 7*cross_scale));
pts.push( new THREE.Vector2 (-7*cross_scale, 5*cross_scale));
pts.push( new THREE.Vector2 (-2*cross_scale, 0));
pts.push( new THREE.Vector2 (-7*cross_scale, -5*cross_scale));
pts.push( new THREE.Vector2 (-5*cross_scale, -7*cross_scale));
pts.push( new THREE.Vector2 (0, -2*cross_scale));
pts.push( new THREE.Vector2 (5*cross_scale, -7*cross_scale));
pts.push( new THREE.Vector2 (7*cross_scale, -5*cross_scale));
pts.push( new THREE.Vector2 (2*cross_scale, 0));
pts.push( new THREE.Vector2 (7*cross_scale, 5*cross_scale));
pts.push( new THREE.Vector2 (5*cross_scale, 7*cross_scale));
// shape to extrude
var shape = new THREE.Shape( pts );
// extrude options
var options = {
amount: headWidth, // default 100, only used when path is null
bevelEnabled: false,
bevelSegments: 2,
steps: 1, // default 1, try 3 if path defined
extrudePath: null // or path
};
// geometry
var coneGeometry = new THREE.ExtrudeGeometry( shape, options );
coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ).makeRotationX( Math.PI/2 ) );
//End of cross shape definition
//coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
if(!canvas_mode)
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshLambertMaterial( { color: hex, shading: THREE.SmoothShading, blending: THREE.AdditiveBlending, vertexColors: THREE.VertexColors } ) );
else
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: hex } ) );
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
this.cone.matrixAutoUpdate = false;
this.add( this.cone );
this.setDirection( dir );
this.setLength( length, headLength, headWidth );
};
THREE.TargetHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE.TargetHelper.prototype.setDirection = function () {
var axis = new THREE.Vector3();
var radians;
return function ( dir ) {
// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );
} else {
axis.set( dir.z, 0, - dir.x ).normalize();
radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( axis, radians );
}
};
}();
THREE.TargetHelper.prototype.setLength = function ( length, headLength, headWidth ) {
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.line.scale.set( 1, length, 1 );
this.line.updateMatrix();
this.cone.scale.set( headLength, headWidth, headLength );
this.cone.position.y = length;
this.cone.updateMatrix();
};
THREE.TargetHelper.prototype.setColor = function ( hex ) {
//this.line.material.color.setHex( hex );
this.cone.material.color.setHex( hex );
};
Xavier Gibert
committed
/**
* @author WestLangley / http://github.com/WestLangley
* @author zz85 / http://github.com/zz85
* @author bhouston / http://exocortex.com
*
* Creates an arrow for visualizing directions
*
* Parameters:
* dir - Vector3
* origin - Vector3
* length - Number
* color - color in hex value
* headLength - Number
* headWidth - Number
*/
THREE.VectorHelper = function ( dir, origin, length, color, headLength, headWidth, segments ) {
Xavier Gibert
committed
// dir is assumed to be normalized
THREE.Object3D.call( this );
if ( color === undefined ) color = 0xffff00;
if ( length === undefined ) length = 1;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.position = origin;
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3( 0, 1, 0 ) );
this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color, linewidth: 2 } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );
var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, segments, 1 );
Xavier Gibert
committed
coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
//this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
if(!canvas_mode)
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshLambertMaterial( { color: color, shading: THREE.SmoothShading, blending: THREE.AdditiveBlending, vertexColors: THREE.VertexColors } ) );
else
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
Xavier Gibert
committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
this.cone.matrixAutoUpdate = false;
this.add( this.cone );
this.setDirection( dir );
this.setLength( length, headLength, headWidth );
};
THREE.VectorHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE.VectorHelper.prototype.setDirection = function () {
var axis = new THREE.Vector3();
var radians;
return function ( dir ) {
// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );
} else {
axis.set( dir.z, 0, - dir.x ).normalize();
radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( axis, radians );
}
};
}();
THREE.VectorHelper.prototype.setLength = function ( length, headLength, headWidth ) {
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.line.scale.set( 1, length, 1 );
this.line.updateMatrix();
this.cone.scale.set( headWidth, headLength, headWidth );
this.cone.position.y = length;
this.cone.updateMatrix();
};
THREE.VectorHelper.prototype.setColor = function ( color ) {
this.line.material.color.set( color );
this.cone.material.color.set( color );
};