threebox
threebox copied to clipboard
return the right object level in queryrenderedfeatures
Hi,
Firstly - this is a really great library! Thank you.
I want to use setCoords() on an object returned from QueryRenderedFeatures(). However, the object returned from QueryRenderedFeatures() doesn't contain this function/property.
The use case is for the user to drag/move a feature...so I want to use QueryRenderedFeatures to get the feature under the mouse, then setCoords to change it's position.
Thanks! Joe
hi @joedjc, can you provide a test case of how you're trying to implement this?
Hi @peterqliu thanks for the reply.
Here's the test case. I use the on click event to get a Threebox feature under the mouse. I then try to set new coords on mouse move.
I actually got it to work using a box geometry created with a 'Object3D', but it doesn't seem to work with the feature created via the loadObj method.
`var selected_feature
map.on('style.load', function() {
map
.addLayer( {
id: 'custom_layer',
type: 'custom',
renderingMode: '3d',
onAdd: function(map, mbxContext){
window.tb = new Threebox(
map,
mbxContext,
{defaultLights: true}
);
// import truck from an external obj file, scaling up its size 10x
var options = {
obj: 'models/Truck.obj',
mtl: 'models/Truck.mtl',
scale: 1,
rotation: 180
}
tb.loadObj(options, function(model) {
truck = model.setCoords(origin);
tb.add(truck);
})
},
render: function(gl, matrix){
tb.update();
}
});
}) .on('click', function(e){ selected_feature = tb.queryRenderedFeatures(e.point)[0] }) .on('mousemove', function(e){ if ( selected_feature ) { selected_feature.object.setCoords([e.lngLat.lng, e.lngLat.lat]) } });`
@peterqliu Here's an example of what i'm trying to do. This one works with the cube geometry. Click the cube once then drag and mouse to move it:
https://www.iventis.co.uk/test/Object3D.html
Having dug into this I discovered I can access threebox object as it appears to be the second parent of the object returned by QueryRenderedFeatures (i.e. obj.object.parent.parent)
Ah perfect. I can see how that was confusing -- will look into tweaking qRF to return the proper parent with the methods attached