source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/helpers/FaceNormalsHelper.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 1.6 KB
Line 
1/**
2 * @author mrdoob / http://mrdoob.com/
3 * @author WestLangley / http://github.com/WestLangley
4*/
5
6THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
7
8 this.object = object;
9
10 this.size = ( size !== undefined ) ? size : 1;
11
12 var color = ( hex !== undefined ) ? hex : 0xffff00;
13
14 var width = ( linewidth !== undefined ) ? linewidth : 1;
15
16 var geometry = new THREE.Geometry();
17
18 var faces = this.object.geometry.faces;
19
20 for ( var i = 0, l = faces.length; i < l; i ++ ) {
21
22 geometry.vertices.push( new THREE.Vector3() );
23 geometry.vertices.push( new THREE.Vector3() );
24
25 }
26
27 THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
28
29 this.matrixAutoUpdate = false;
30
31 this.normalMatrix = new THREE.Matrix3();
32
33 this.update();
34
35};
36
37THREE.FaceNormalsHelper.prototype = Object.create( THREE.Line.prototype );
38
39THREE.FaceNormalsHelper.prototype.update = ( function ( object ) {
40
41 var v1 = new THREE.Vector3();
42
43 return function ( object ) {
44
45 this.object.updateMatrixWorld( true );
46
47 this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
48
49 var vertices = this.geometry.vertices;
50
51 var faces = this.object.geometry.faces;
52
53 var worldMatrix = this.object.matrixWorld;
54
55 for ( var i = 0, l = faces.length; i < l; i ++ ) {
56
57 var face = faces[ i ];
58
59 v1.copy( face.normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size );
60
61 var idx = 2 * i;
62
63 vertices[ idx ].copy( face.centroid ).applyMatrix4( worldMatrix );
64
65 vertices[ idx + 1 ].addVectors( vertices[ idx ], v1 );
66
67 }
68
69 this.geometry.verticesNeedUpdate = true;
70
71 return this;
72
73 }
74
75}());
76
Note: See TracBrowser for help on using the repository browser.