Skip to content

Commit 6d71090

Browse files
author
medihack
committed
Implement pickable feature for renderer3D. Fixes xtk#107.
1 parent 67fcb7c commit 6d71090

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

injects/displayable.js

100644100755
+42
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ X.displayable = function() {
175175
* @protected
176176
*/
177177
this._distance = 0;
178+
179+
/**
180+
* The flag if this object is pickable.
181+
*
182+
* @type {!boolean}
183+
* @protected
184+
*/
185+
this._pickable = true;
178186

179187
};
180188

@@ -594,3 +602,37 @@ X.displayable.prototype.__defineSetter__('linewidth', function(width) {
594602
// no modified event since the rendering loop always checks it
595603

596604
});
605+
606+
607+
/**
608+
* Get the pickable flag.
609+
*
610+
* @return {!boolean} The pickable flag.
611+
*/
612+
X.displayable.prototype.__defineGetter__('pickable', function() {
613+
614+
return this._pickable;
615+
616+
});
617+
618+
619+
/**
620+
* Set the pickable flag.
621+
*
622+
* @param {!boolean} pickable The pickable flag.
623+
*/
624+
X.displayable.prototype.__defineSetter__('pickable', function(pickable) {
625+
626+
if (!goog.isBoolean(pickable)) {
627+
628+
throw new Error('Invalid pickable setting.');
629+
630+
}
631+
632+
this._pickable = pickable;
633+
634+
this._dirty = true;
635+
636+
// no modified event since the rendering loop always checks it
637+
638+
});

objects/object.js

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ X.object.prototype.copy_ = function(object) {
171171

172172
this._magicmode = object._magicmode;
173173

174+
this._pickable = object._pickable;
175+
174176
this._pointIndices = object._pointIndices.slice();
175177

176178
this._dirty = true;

objects/testing/object_test.js

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function testXobjectCopy() {
2929
o.linewidth = 3;
3030
o.caption = 'testing';
3131
o.magicmode = true;
32+
o.pickable = false;
3233

3334
// now we want to copy the object
3435
var o2 = new X.object(o);
@@ -64,5 +65,6 @@ function testXobjectCopy() {
6465
assertEquals(o.linewidth, o2.linewidth);
6566
assertEquals(o.caption, o2.caption);
6667
assertEquals(o.magicmode, o2.magicmode);
68+
assertEquals(o.pickable, o2.pickable);
6769

6870
}

visualization/renderer3D.js

100644100755
+7
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,13 @@ X.renderer3D.prototype.render_ = function(picking, invoked) {
15991599

16001600
}
16011601

1602+
// check picking mode and object pickable
1603+
if (picking && !object._pickable) {
1604+
1605+
// object not pickable, continue to next one
1606+
continue;
1607+
}
1608+
16021609
var id = object._id;
16031610

16041611
var magicMode = object._magicmode;

0 commit comments

Comments
 (0)