Geometric Information Mapping with the userpick Event
You can use the eventData argument of the userpick event to obtain the geometric information of a 3D model. This information can then be used for creating waypoints or points of interest (POIs).
|
This features is only available for Models; Area Targets, Image Targets, and 3D Images are not supported.
|
The userpick event includes the geometric data in the form of a 3D position vector consisting of the x, y, and z coordinates of the picked point and its 3D surface normal vector; these are called the position and normal. For example:
{
"position": [
100.987,
-200.654,
300.321
],
"normal": [
0.6,
-0.8,
0.0
]
}
The position coordinates and the surface normal of the contact (tap) point are reported in the eventData argument as an array (x, y, z) so that it can be picked up by the event listener:
$scope.$on('userpick', function(event, targetName, targetType, eventData)
If the geometric information is not available for a userpick event, then the position and normal arrays will be empty:
{
"position": [],
"normal": []
}
Example
The following is an example code snippet that could be added to Home.js:
|
• userpick events are only available for world coordinates; they are not available for relative coordinates.
• userpick events will only be sent for the model.
|
$scope.$on('userpick', function (event, targetName, targetType, eventData) {
// event data will be empty for 3D images
//
if (eventData == []) {
console.error('Pick on unsupported object: No event data')
return
}
// the pick event gives us the item id, position and normal
//
let position = JSON.parse(eventData).position
// geometric information will not be available
// for unsupported objects
if (position.length != 3) {
console.error('Pick on unsupported object: No position data')
return
}
// put a "ball" at the point the user just touched
//
$scope.setWidgetProp("ball", "x", position[0]);
$scope.setWidgetProp("ball", "y", position[1]);
$scope.setWidgetProp("ball", "z", position[2]);
})