Revanth Alampally
Revanth Alampally

Reputation: 75

Can we remove Arrow Helper object by clicking on it?

I know we can remove any object by scene.__removeObject() So I am removing any object in the screen by using raycaster. When I click on a object intersects.length becomes >0 and scene.__removeObject(SELECTED) gets executed. But if click on an Arrowhelper object (say ARROW) intersects.length is still zero.

So how I remove the Arrow helper from GUI. In code I know scene.__removeObject(ARROW) works

function onDocumentMouseDown( event ) {

        event.preventDefault();

        var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
        projector.unprojectVector( vector, camera );

        var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );

        var intersects = raycaster.intersectObjects( objects );

        if ( intersects.length > 0 ) {

            controls.enabled = false;

            SELECTED = intersects[ 0 ].object;
           scene.__removeObject(SELECTED)
           // scene.__removeObject(ARROW)


        }

    }

Upvotes: 1

Views: 760

Answers (1)

vincent
vincent

Reputation: 1533

Your problem is in fact about intersections, correct ?

The ArrowHelper is made of two meshes .cone and .line so it should be intersectable just like other objects.

Remember the Raycaster will only intersect objects that are in your objects variable.

I see two solutions for your problem:

  • make sure the objects variable contains the helper's .cone or .line or both.
  • add the whole helper in objects (objects.push(ARROW)) but then you have to call intersectObjects recursively

    raycaster.intersectObjects( objects, true );

Upvotes: 1

Related Questions