I have a terrain which was generated using the THREE.Terrain library. I'd like to be able to click and drag out a marquee and select objects that are on the surface of the Terrain Mesh.
Currently I am detecting the start and end of the drag, and drawing out a rectangle in the global XZ plane, but I'd prefer it to be flush with the surface.
Currently it looks like this;
However what I am aiming for is something more like this;
I am wondering if I have missed some obvious way of doing that with the Core three.js features.
There is always the brute force method of casting rays at intervals around the perimeter of the rectangle, and creating a series of line segments to approximate the projected rectangle, but I was wondering if there was a native method.
(I only just started looking at three.js this week, so I might have missed something obvious... though I've spent the last day experimenting, and haven't had much luck)
Update
Based on @prisoner849's suggestion, I mashed up his code with the Terrain demo and that seems to be working pretty well.
varying vec2 vPos;
void main() {
vec2 Ro = size * .5;
vec2 Uo = abs( vPos - center.xz ) - Ro;
vec3 c = mix(vec3(1.), vec3(1.,0.,0.), float(enabled && (abs(max(Uo.x,Uo.y)) < lineHalfWidth) ));
gl_FragColor = vec4(c, float(enabled && (abs(max(Uo.x,Uo.y)) < lineHalfWidth) ));
}
`;
The code needs a massive clean up, and the marquees need to be rotated to match the camera perspective, and it would be nice to have ctrl-click to add to selection set, etc, etc.
But in principle the fragment shader worked well...