Skip to content

Commit e290bb5

Browse files
committed
Added object selection.
1 parent 01d9c61 commit e290bb5

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

drawings/simple_graph.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ var Drawing = Drawing || {};
44
Drawing.SimpleGraph = function(options) {
55
var options = options || {};
66
var layout = options.layout || "2d";
7+
var selection = options.selection || false;
78
var nodes_count = options.nodes || 20;
89
var edges_count = options.edges || 10;
910

10-
var camera, scene, renderer, interaction, stats;
11+
var camera, scene, renderer, interaction, stats, geometry, object_selection;
1112
var graph = new Graph({limit: options.limit});
1213

1314
var geometries = [];
@@ -41,8 +42,20 @@ Drawing.SimpleGraph = function(options) {
4142

4243
scene = new THREE.Scene();
4344

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+
}
4557

58+
renderer = new THREE.WebGLRenderer({antialias: true});
4659
renderer.setSize( window.innerWidth, window.innerHeight );
4760

4861
document.body.appendChild( renderer.domElement );
@@ -61,7 +74,6 @@ Drawing.SimpleGraph = function(options) {
6174
document.body.appendChild( info );
6275
}
6376

64-
6577
function createGraph() {
6678
var node = new Node(0);
6779
graph.addNode(node);
@@ -99,13 +111,9 @@ Drawing.SimpleGraph = function(options) {
99111

100112

101113
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+
109117

110118
// label
111119
// var labelCanvas = document.createElement( "canvas" );
@@ -178,6 +186,7 @@ Drawing.SimpleGraph = function(options) {
178186
geometries[i].__dirtyVertices = true;
179187
}
180188

189+
181190
// scene.objects.forEach(function(obj) {
182191
// if(obj.type === "label") {
183192
// var delta_x = obj.position.x - obj.draw_object.position.x;
@@ -191,7 +200,10 @@ Drawing.SimpleGraph = function(options) {
191200
// drawText(obj, obj.draw_object.position.y);
192201
// }
193202
// });
194-
203+
204+
if(selection) {
205+
object_selection.render(scene, camera);
206+
}
195207
renderer.render( scene, camera );
196208
// interaction.update();
197209
stats.update();

0 commit comments

Comments
 (0)