Skip to content

⬅️ Back to Table of Contents

📄 Selector.js

📊 Analysis Summary

Metric Count
🔧 Functions 4
🧱 Classes 1
📊 Variables & Constants 6

📚 Table of Contents

🛠️ File Location:

📂 editor/js/Selector.js

Variables & Constants

Name Type Kind Value Exported
mouse any let/var new THREE.Vector2()
raycaster any let/var new THREE.Raycaster()
signals any let/var editor.signals
object any let/var intersects[ 0 ].object
objects any[] let/var []
uuid any let/var null

Functions

Selector.getIntersects(raycaster: any): any

Parameters:

  • raycaster any

Returns: any

Calls:

  • this.editor.scene.traverseVisible
  • objects.push
  • this.editor.sceneHelpers.traverseVisible
  • raycaster.intersectObjects
Code
getIntersects( raycaster ) {

        const objects = [];

        this.editor.scene.traverseVisible( function ( child ) {

            objects.push( child );

        } );

        this.editor.sceneHelpers.traverseVisible( function ( child ) {

            if ( child.name === 'picker' ) objects.push( child );

        } );

        return raycaster.intersectObjects( objects, false );

    }

Selector.getPointerIntersects(point: any, camera: any): any

Parameters:

  • point any
  • camera any

Returns: any

Calls:

  • mouse.set
  • raycaster.setFromCamera
  • this.getIntersects
Code
getPointerIntersects( point, camera ) {

        mouse.set( ( point.x * 2 ) - 1, - ( point.y * 2 ) + 1 );

        raycaster.setFromCamera( mouse, camera );

        return this.getIntersects( raycaster );

    }

Selector.select(object: any): void

Parameters:

  • object any

Returns: void

Calls:

  • this.editor.config.setKey
  • this.signals.objectSelected.dispatch
Code
select( object ) {

        if ( this.editor.selected === object ) return;

        let uuid = null;

        if ( object !== null ) {

            uuid = object.uuid;

        }

        this.editor.selected = object;
        this.editor.config.setKey( 'selected', uuid );

        this.signals.objectSelected.dispatch( object );

    }

Selector.deselect(): void

Returns: void

Calls:

  • this.select
Code
deselect() {

        this.select( null );

    }

Classes

Selector

Class Code
class Selector {

    constructor( editor ) {

        const signals = editor.signals;

        this.editor = editor;
        this.signals = signals;

        // signals

        signals.intersectionsDetected.add( ( intersects ) => {

            if ( intersects.length > 0 ) {

                const object = intersects[ 0 ].object;

                if ( object.userData.object !== undefined ) {

                    // helper

                    this.select( object.userData.object );

                } else {

                    this.select( object );

                }

            } else {

                this.select( null );

            }

        } );

    }

    getIntersects( raycaster ) {

        const objects = [];

        this.editor.scene.traverseVisible( function ( child ) {

            objects.push( child );

        } );

        this.editor.sceneHelpers.traverseVisible( function ( child ) {

            if ( child.name === 'picker' ) objects.push( child );

        } );

        return raycaster.intersectObjects( objects, false );

    }

    getPointerIntersects( point, camera ) {

        mouse.set( ( point.x * 2 ) - 1, - ( point.y * 2 ) + 1 );

        raycaster.setFromCamera( mouse, camera );

        return this.getIntersects( raycaster );

    }

    select( object ) {

        if ( this.editor.selected === object ) return;

        let uuid = null;

        if ( object !== null ) {

            uuid = object.uuid;

        }

        this.editor.selected = object;
        this.editor.config.setKey( 'selected', uuid );

        this.signals.objectSelected.dispatch( object );

    }

    deselect() {

        this.select( null );

    }

}

Methods

getIntersects(raycaster: any): any
Code
getIntersects( raycaster ) {

        const objects = [];

        this.editor.scene.traverseVisible( function ( child ) {

            objects.push( child );

        } );

        this.editor.sceneHelpers.traverseVisible( function ( child ) {

            if ( child.name === 'picker' ) objects.push( child );

        } );

        return raycaster.intersectObjects( objects, false );

    }
getPointerIntersects(point: any, camera: any): any
Code
getPointerIntersects( point, camera ) {

        mouse.set( ( point.x * 2 ) - 1, - ( point.y * 2 ) + 1 );

        raycaster.setFromCamera( mouse, camera );

        return this.getIntersects( raycaster );

    }
select(object: any): void
Code
select( object ) {

        if ( this.editor.selected === object ) return;

        let uuid = null;

        if ( object !== null ) {

            uuid = object.uuid;

        }

        this.editor.selected = object;
        this.editor.config.setKey( 'selected', uuid );

        this.signals.objectSelected.dispatch( object );

    }
deselect(): void
Code
deselect() {

        this.select( null );

    }