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

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

GUI front-end to server base plus web page content

File size: 2.1 KB
Line 
1/**
2 * @author mrdoob / http://mrdoob.com/
3 * @author WestLangley / http://github.com/WestLangley
4*/
5
6THREE.VertexNormalsHelper = 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 : 0xff0000;
13
14 var width = ( linewidth !== undefined ) ? linewidth : 1;
15
16 var geometry = new THREE.Geometry();
17
18 var vertices = object.geometry.vertices;
19
20 var faces = object.geometry.faces;
21
22 for ( var i = 0, l = faces.length; i < l; i ++ ) {
23
24 var face = faces[ i ];
25
26 for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
27
28 geometry.vertices.push( new THREE.Vector3() );
29 geometry.vertices.push( new THREE.Vector3() );
30
31 }
32
33 }
34
35 THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces );
36
37 this.matrixAutoUpdate = false;
38
39 this.normalMatrix = new THREE.Matrix3();
40
41 this.update();
42
43};
44
45THREE.VertexNormalsHelper.prototype = Object.create( THREE.Line.prototype );
46
47THREE.VertexNormalsHelper.prototype.update = ( function ( object ) {
48
49 var v1 = new THREE.Vector3();
50
51 return function( object ) {
52
53 var keys = [ 'a', 'b', 'c', 'd' ];
54
55 this.object.updateMatrixWorld( true );
56
57 this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
58
59 var vertices = this.geometry.vertices;
60
61 var verts = this.object.geometry.vertices;
62
63 var faces = this.object.geometry.faces;
64
65 var worldMatrix = this.object.matrixWorld;
66
67 var idx = 0;
68
69 for ( var i = 0, l = faces.length; i < l; i ++ ) {
70
71 var face = faces[ i ];
72
73 for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
74
75 var vertexId = face[ keys[ j ] ];
76 var vertex = verts[ vertexId ];
77
78 var normal = face.vertexNormals[ j ];
79
80 vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix );
81
82 v1.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size );
83
84 v1.add( vertices[ idx ] );
85 idx = idx + 1;
86
87 vertices[ idx ].copy( v1 );
88 idx = idx + 1;
89
90 }
91
92 }
93
94 this.geometry.verticesNeedUpdate = true;
95
96 return this;
97
98 }
99
100}());
Note: See TracBrowser for help on using the repository browser.