jonlo-threejs-selection

1.0.0 • Public • Published

threejs-raycast-selection

Very simple package to get a threejs element from a raycast

Quick Start

import { Selection } from 'threejs-raycast-selection';

let selection = new Selection(camera);

selection.addSelectableObject(object);

let selectedElementData = selection.selectElement(mousePosNormalized);
let selectedMesh = selectedElementData.selectedElement;
let selectedMeshParent = selectedElementData.parent;
let raycastHitPoint = selectedElementData.intersectionPoint;

//Or

selection.subscribe('elementSelected', (params) => { this.elementSelected(params); });

params

{
	selectedElement,
	parent,
	intersectionPoint
}

Classes

Selection

Functions

constructor(camera)

Creates an instance of Selection.

selectElement(mousePosNormalized)Object

Returns the element with the lowest userData.selectionIndex value in the intersections from a raycast

addSelectableObject(object)

Adds an Object3d to the selection system, including all its children meshes

removeSelectableObject(object)

Removes an Object3d from the selection system

Selection

Kind: global class Version: 1 Author: jon

constructor(camera)

Creates an instance of Selection.

Kind: global function Access: public

Param Type
camera Camera

selectElement(mousePosNormalized) ⇒ Object

Returns the element with the lowest userData.selectionIndex value in the intersections from a raycast

Kind: global function Returns: Object - The selected mesh, it's parent and the raycastHit point Access: public

Param Type
mousePosNormalized Vector2

addSelectableObject(object)

Adds an Object3d to the selection system, including all its children meshes

Kind: global function Access: public

Param Type
object Object3d

removeSelectableObject(object)

Removes an Object3d from the selection system

Kind: global function Access: public

Param Type
object Object3d

Package Sidebar

Install

npm i jonlo-threejs-selection

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

8.33 kB

Total Files

6

Last publish

Collaborators

  • jonlo