@@ -4,10 +4,11 @@ var Drawing = Drawing || {};
4
4
Drawing . SimpleGraph = function ( options ) {
5
5
var options = options || { } ;
6
6
var layout = options . layout || "2d" ;
7
+ var selection = options . selection || false ;
7
8
var nodes_count = options . nodes || 20 ;
8
9
var edges_count = options . edges || 10 ;
9
10
10
- var camera , scene , renderer , interaction , stats ;
11
+ var camera , scene , renderer , interaction , stats , geometry , object_selection ;
11
12
var graph = new Graph ( { limit : options . limit } ) ;
12
13
13
14
var geometries = [ ] ;
@@ -41,8 +42,20 @@ Drawing.SimpleGraph = function(options) {
41
42
42
43
scene = new THREE . Scene ( ) ;
43
44
44
- renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
45
+ // Node geometry
46
+ if ( layout === "3d" ) {
47
+ geometry = new THREE . SphereGeometry ( 50 , 50 , 50 ) ;
48
+ } else {
49
+ geometry = new THREE . SphereGeometry ( 50 , 50 , 0 ) ;
50
+ }
51
+
52
+ if ( selection ) {
53
+ object_selection = new THREE . ObjectSelection ( { selected : function ( obj ) {
54
+ // display info
55
+ } } ) ;
56
+ }
45
57
58
+ renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
46
59
renderer . setSize ( window . innerWidth , window . innerHeight ) ;
47
60
48
61
document . body . appendChild ( renderer . domElement ) ;
@@ -61,7 +74,6 @@ Drawing.SimpleGraph = function(options) {
61
74
document . body . appendChild ( info ) ;
62
75
}
63
76
64
-
65
77
function createGraph ( ) {
66
78
var node = new Node ( 0 ) ;
67
79
graph . addNode ( node ) ;
@@ -99,13 +111,9 @@ Drawing.SimpleGraph = function(options) {
99
111
100
112
101
113
function drawNode ( node ) {
102
- var geometry ;
103
- if ( layout === "3d" ) {
104
- geometry = new THREE . CubeGeometry ( 50 , 50 , 50 ) ;
105
- } else {
106
- geometry = new THREE . CubeGeometry ( 50 , 50 , 0 ) ;
107
- }
108
- var draw_object = new THREE . Mesh ( geometry , [ new THREE . MeshBasicMaterial ( { color : Math . random ( ) * 0xffffff } ) , new THREE . MeshBasicMaterial ( { color : 0xffffff , opacity : 0.5 , wireframe : true } ) ] ) ;
114
+
115
+ var draw_object = new THREE . Mesh ( geometry , [ new THREE . MeshBasicMaterial ( { color : Math . random ( ) * 0xffffff , opacity : 0.5 } ) ] ) ;
116
+
109
117
110
118
// label
111
119
// var labelCanvas = document.createElement( "canvas" );
@@ -178,6 +186,7 @@ Drawing.SimpleGraph = function(options) {
178
186
geometries [ i ] . __dirtyVertices = true ;
179
187
}
180
188
189
+
181
190
// scene.objects.forEach(function(obj) {
182
191
// if(obj.type === "label") {
183
192
// var delta_x = obj.position.x - obj.draw_object.position.x;
@@ -191,7 +200,10 @@ Drawing.SimpleGraph = function(options) {
191
200
// drawText(obj, obj.draw_object.position.y);
192
201
// }
193
202
// });
194
-
203
+
204
+ if ( selection ) {
205
+ object_selection . render ( scene , camera ) ;
206
+ }
195
207
renderer . render ( scene , camera ) ;
196
208
// interaction.update();
197
209
stats . update ( ) ;
0 commit comments