@galacean/engine-toolkit-framebuffer-picker
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Framebuffer Picker

The Framebuffer Picker tool using GPU frame picking technology, it can judge whether a certain model is clicked at the pixel level, and return information such as the material and mesh of the picked entity.

frame picker

npm

The Outline is published on npm with full typing support. To install, use:

$ npm install @galacean/engine-toolkit-framebuffer-picker

This will allow you to import package entirely using:

import * as TOOLKIT from "@galacean/engine-toolkit-framebuffer-picker";

or individual classes using:

import { FramebufferPicker } from "@galacean/engine-toolkit-framebuffer-picker";

Usage

class ClickScript extends Script {
  onUpdate(): void {
    const inputManager = this.engine.inputManager;
    const { pointers } = inputManager;
    if (pointers && inputManager.isPointerDown(PointerButton.Primary)) {
      if (pointers.length > 0) {
        const pointerPosition = pointers[0].position;
        framebufferPicker.pick(pointerPosition.x, pointerPosition.y).then((renderElement) => {
          if (renderElement) {
            // ... picked element
          } else {
            // ... no picked element
          }
        });
      }
    }
  }
}

cameraEntity.addComponent(ClickScript);

const framebufferPicker = rootNode.addComponent(FramebufferPicker);
framebufferPicker.camera = camera;

Links

License

The engine is released under the MIT license. See LICENSE file.

Readme

Keywords

none

Package Sidebar

Install

npm i @galacean/engine-toolkit-framebuffer-picker

Weekly Downloads

46

Version

1.1.0

License

MIT

Unpacked Size

115 kB

Total Files

12

Last publish

Collaborators

  • chengkong.zxx
  • imchenjian
  • ruimeng.su
  • yinjie
  • yiqi
  • jujie
  • luzhuang
  • husong
  • mrkou47
  • johanzhu
  • zhuxudong
  • zhanyingwei
  • gl3336563
  • eyworldwide