source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/helpers/EdgesHelper.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.8 KB
Line 
1/**
2 * @author WestLangley / http://github.com/WestLangley
3 */
4
5THREE.EdgesHelper = function ( object, hex ) {
6
7 var color = ( hex !== undefined ) ? hex : 0xffffff;
8
9 var edge = [ 0, 0 ], hash = {};
10 var sortFunction = function ( a, b ) { return a - b };
11
12 var keys = [ 'a', 'b', 'c' ];
13 var geometry = new THREE.BufferGeometry();
14
15 var geometry2 = object.geometry.clone();
16
17 geometry2.mergeVertices();
18 geometry2.computeFaceNormals();
19
20 var vertices = geometry2.vertices;
21 var faces = geometry2.faces;
22 var numEdges = 0;
23
24 for ( var i = 0, l = faces.length; i < l; i ++ ) {
25
26 var face = faces[ i ];
27
28 for ( var j = 0; j < 3; j ++ ) {
29
30 edge[ 0 ] = face[ keys[ j ] ];
31 edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
32 edge.sort( sortFunction );
33
34 var key = edge.toString();
35
36 if ( hash[ key ] === undefined ) {
37
38 hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
39 numEdges ++;
40
41 } else {
42
43 hash[ key ].face2 = i;
44
45 }
46
47 }
48
49 }
50
51 geometry.addAttribute( 'position', Float32Array, 2 * numEdges, 3 );
52
53 var coords = geometry.attributes.position.array;
54
55 var index = 0;
56
57 for ( var key in hash ) {
58
59 var h = hash[ key ];
60
61 if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) < 0.9999 ) { // hardwired const OK
62
63 var vertex = vertices[ h.vert1 ];
64 coords[ index ++ ] = vertex.x;
65 coords[ index ++ ] = vertex.y;
66 coords[ index ++ ] = vertex.z;
67
68 vertex = vertices[ h.vert2 ];
69 coords[ index ++ ] = vertex.x;
70 coords[ index ++ ] = vertex.y;
71 coords[ index ++ ] = vertex.z;
72
73 }
74
75 }
76
77 THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces );
78
79 this.matrixAutoUpdate = false;
80 this.matrixWorld = object.matrixWorld;
81
82};
83
84THREE.EdgesHelper.prototype = Object.create( THREE.Line.prototype );
Note: See TracBrowser for help on using the repository browser.