物体事件管理器插件。
安装此插件可以为场景中的物体增加鼠标事件。
目前支持的事件枚举。
export enum EVENTNAME {
POINTERDOWN = "pointerdown",
POINTERUP = "pointerup",
POINTERMOVE = "pointermove",
POINTERENTER = "pointerenter",
POINTERLEAVE = "pointerleave",
CLICK = "click",
DBLCLICK = "dblclick",
CONTEXTMENU = "contextmenu",
}
使用案例。
import * as THREE from "three";
import { EventManagerPlugin } from "@vis-three/plugin-event-manager";
engine.install(EventManagerPlugin());
const box = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 5));
box.addEventListener("click", (event) => {
console.log(event);
});
EventManagerPlugin
:::tip
可以使用枚举:EVENT_MANAGER_PLUGIN
:::
- PointerManagerPlugin: @vis-three/plugin-pointer-manager
export interface EventManagerParameters {
/**指定事件触发场景 */
scene: Scene;
/**指定事件触发相机 */
camera: Camera;
/**是否递归场景物体子集 */
recursive?: boolean;
/**是否穿透触发事件,比如2个物体即使重叠都会触发 */
penetrate?: boolean;
// support?: boolean;
/**射线设置 参考three.js的射线设置*/
raycaster?: {
params: {
Line?: { threshold: number };
Points?: { threshold: number };
};
};
}
export interface EventManagerEngine extends PointerManagerEngine {
eventManager: EventManager;
}
此类继承@vis-three/core
的EventDispatcher
。
• Private
camera: Camera
目标相机
• delegation: boolean
= false
Todo
以事件委托的形式触发事件
• Private
filter: Set
<Object3D
<Event
>>
不会触发事件的过滤器
• penetrate: boolean
= false
事件穿透
• propagation: boolean
= false
Todo
以事件冒泡的形式触发事件
• raycaster: Raycaster
射线发射器
• recursive: boolean
= false
递归子物体
• Private
scene: Scene
目标场景
▸ addFilterObject(object
): EventManager
添加不会触发事件的场景中的物体
Name | Type | Description |
---|---|---|
object |
Object3D <Event > |
Object3D |
EventManager
▸ Private
intersectObject(mouse
): Intersection
<Object3D
<Event
>>[]
Name | Type |
---|---|
mouse |
Vector2 |
Intersection
<Object3D
<Event
>>[]
▸ removeFilterObject(object
): EventManager
移除过滤器中的物体
Name | Type | Description |
---|---|---|
object |
Object3D <Event > |
Object3D |
this
▸ setCamera(camera
): EventManager
设置当前相机
Name | Type |
---|---|
camera |
Camera |
this
▸ setScene(scene
): EventManager
设置当前场景
Name | Type |
---|---|
scene |
Scene |
this
▸ use(pointerManager
): EventManager
使用 pointerManger
Name | Type |
---|---|
pointerManager |
PointerManager |
EventManager