Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device Input System - Step 1 #7920

Merged
merged 20 commits into from
Apr 8, 2020
Merged

Device Input System - Step 1 #7920

merged 20 commits into from
Apr 8, 2020

Conversation

PolygonalSun
Copy link
Contributor

@PolygonalSun PolygonalSun commented Mar 26, 2020

This PR contains the web implementation for the DeviceInputSystem class. This class will take input from gamepads, mice, and keyboards and allow someone to access (via pollInput) their input values in the same manner.

While it isn't the full version of this system, it's the first step. I'd like to get it checked in so that I can get feedback to create a solid foundation for the next level up on this system.

To use:

Create a variable to hold the device input system and use onDeviceConnected and onDeviceDisconnected to provide custom behavior.

Example:

var dis = new BABYLON.DeviceInputSystem(canvas); // Canvas object needed to attach pointer
dis.onDeviceConnected((deviceName) => {
     if (deviceName == BABYLON.DeviceInputSystem.POINTER_DEVICE)
     {
          scene.onBeforeRenderObservable.add(() => {
               if (deviceName == BABYLON.DeviceInputSystem.POINTER_DEVICE &&
                    dis.pollInput(deviceName, 2))
                    {
                         console.log("Left Click");
                    }
          });
});

Note: This code is not expected to be used by end user but by another system.

@PolygonalSun PolygonalSun marked this pull request as ready for review March 27, 2020 16:43
Copy link
Contributor

@deltakosh deltakosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool so far!

Copy link
Contributor

@syntheticmagus syntheticmagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Playground or something that consumes and tests this? Seems fine enough as an intermediate step, but having some end-to-end, even a hacked-up one, would provide good validation that this does everything it intends to.

src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/index.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Show resolved Hide resolved
Copy link
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, otherwise looks good.

src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
src/DeviceInput/deviceInputSystem.ts Outdated Show resolved Hide resolved
@deltakosh deltakosh merged commit 5af096e into BabylonJS:master Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants