Skip to content

Commit 2c3c66a

Browse files
authored
Merge pull request #379 from matthewturk/picker_points
Extend Picker to pick individual Points objects.
2 parents a78cb57 + db78616 commit 2c3c66a

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

js/scripts/three-class-config.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ module.exports = {
266266
event: new Types.String('click', {
267267
help: 'The DOM MouseEvent type to trigger the pick',
268268
}),
269+
lineThreshold: new Types.Float(1.0, {
270+
nullable: false,
271+
help: 'The threshold value for line picking',
272+
}),
273+
pointThreshold: new Types.Float(1.0, {
274+
nullable: false,
275+
help: 'The threshold value for point picking',
276+
}),
269277
all: new Types.Bool(false, {
270278
help: 'Wether to send info on all object intersections beneath the picked point, or only the first one. See ``picked``.',
271279
}),
@@ -276,6 +284,10 @@ module.exports = {
276284
point: new Types.Vector3(0, 0, 0, {
277285
help: 'The coordinates of the picked point (all zero if no object picked)',
278286
}),
287+
instanceId: new Types.Int(null, {
288+
nullable: true,
289+
help: 'The InstanceID if picking a multi-instanced object',
290+
}),
279291
face: new Types.Vector3(0, 0, 0, {
280292
help: 'The vertex indices of the picked face (all zero if no face picked)',
281293
}),
@@ -285,6 +297,10 @@ module.exports = {
285297
faceVertices: new Types.VectorArray({
286298
help: 'The three vertices that make up the picked face, as vectors (empty if no face picked)',
287299
}),
300+
index: new Types.Int(null, {
301+
nullable: true,
302+
help: 'The index of a picked Points instance',
303+
}),
288304
faceIndex: new Types.Int(null, {
289305
nullable: true,
290306
help: 'The index of the face picked (null if no face picked)',
@@ -310,7 +326,8 @@ module.exports = {
310326
},
311327
propsDefinedByThree: [
312328
'distance', 'point', 'face', 'faceNormal', 'faceVertices',
313-
'faceIndex', 'object', 'picked', 'uv', 'indices'],
329+
'faceIndex', 'object', 'picked', 'uv', 'indices', 'instanceId',
330+
'index'],
314331
constructorArgs: ['controlling'],
315332
},
316333

js/src/controls/Picker.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ var PickerModel = PickerAutogen.PickerModel.extend({
3535

3636
onPick: function() {
3737
var mouse = this.obj.pickCoordinates;
38-
var objects = pick(mouse, this.camera, this.get('controlling').obj);
38+
var objects = pick(mouse, this.camera, this.get('controlling').obj,
39+
this.get('lineThreshold'), this.get('pointThreshold')
40+
);
3941

4042
var info = getinfo(objects.length > 0 ? objects[0] : null);
4143

@@ -102,8 +104,12 @@ PickerControls.prototype = Object.create( THREE.EventDispatcher.prototype );
102104
PickerControls.prototype.constructor = PickerControls;
103105

104106

105-
function pick(mouse, camera, root) {
107+
function pick(mouse, camera, root, lineThreshold, pointThreshold) {
106108
var raycaster = new THREE.Raycaster();
109+
raycaster.params = {
110+
'Points': { 'threshold': pointThreshold },
111+
'Line': { 'threshold': lineThreshold }
112+
};
107113
raycaster.setFromCamera( mouse, camera );
108114
return raycaster.intersectObject(root, true);
109115
}
@@ -134,6 +140,8 @@ function getinfo(o) {
134140
faceIndex: o.faceIndex !== undefined && o.faceIndex !== null ? o.faceIndex : null,
135141
object: o.object.ipymodel,
136142
uv: o.uv ? [o.uv.x, o.uv.y] : [0, 0],
143+
instanceId: o.instanceId !== undefined ? o.instanceId : null,
144+
index: o.index !== undefined ? o.index : null,
137145
};
138146
}
139147
return {
@@ -146,6 +154,8 @@ function getinfo(o) {
146154
faceIndex: null,
147155
object: null,
148156
uv: [0, 0],
157+
instanceId: null,
158+
index: null,
149159
};
150160
}
151161

0 commit comments

Comments
 (0)