vr_controls
v6.2.71
Published
This package utilize loading, selection gamepads models for current vr device, positioning them relative head. Typescript ready. ### Supported devices: 1. Lenovo DayDream 2. Oculus Rift 3. Oculus Go 4. Oculus Quest 5. Gear VR 6. HTC Vive 7. Win
Downloads
21
Maintainers
Readme
WebVR input utility
About
This package utilize loading, selection gamepads models for current vr device, positioning them relative head.
Typescript ready.
Supported devices:
- Lenovo DayDream
- Oculus Rift
- Oculus Go
- Oculus Quest
- Gear VR
- HTC Vive
- WinowsMixedReality(WIP)
Installation
Install package:
npm i vr_controls
Include models in your bundle:
- If you use
webpack
, you should copy models directory somewhere in your destination directory.
It is better to usecustom copy plugin
, instead ofCopyWebpackPlugin
, because, the 2nd one has some problems when copying gltf`s .bin file.
In this case, files from... plugins: [ ... { apply: (cmplr) => { cmplr.hooks.afterEmit.tap("MyCopyPlug", (cmpln) => { let from = path.join(__dirname, "node_modules", "vr_controls", "lib", "gamepad"); let to = path.join(__dirname, "dist", "models", "gamepad"); let files = fs.readdirSync(from); for (let i = 0; i < files.length; i++) { fs.copyFileSync( path.join(from, files[i]), path.join(to, files[i])); } console.log("custom copy applied"); }) } }, ... ]
gamepad
folder will be copied into__dirname/dist/models/gamepad
, wheredist
-- is my destination folder.
- If you use
Members
VRModelsLoader
-- Utility for vr models loading and parse them.VRControls
-- Gets native gamepads and serialzie its into handy wrappersVRGamepadData
-- Handy native gamepad data wrapper, serialize data into three.js typesVRManager
-- Utility for enter/exit vr events, detect current vr mode, current device detectionVRBodyDefault
-- basic implementation of vr body, that automatically handle 3dof and 6 dof gamepads. If there is 3dof gamepads -- Body will pose them with virtual arm. If 6dof - will pose them as it is.GamepadModelsNames
-- dictionary for gamepads models names.HMDsNames
-- dictionary for known head mounted devices.
Usage
You can use package in default
and custom
way.
In any case, first of all, you should initialize VRManager, and pass the gamepad model path (in dist folder) into VRModelsLoader
.
VRManager.Init(YourRenderer);
VRModelsLoader.ModelsGLTFUrl = "models/gamepad";
...
In the example above, this path specified, because webpack
will copy models in this(models/gamepad
) folder, and my dist looks like this:
Usage examples
Example of default way:
Body
will automatically pose gamepads, depends on their DOF.let body = new VRBodyDefault(); yourUpdateLoop(() => { body.UpdateGamepadsData(Renderer.vr.getStandingMatrix()); body.UpdatePose(MainScene, HeadObject); });
The
body.Hands[]
contains instances of Object3D, that used as posing points. Gamepads 3d models snaps on them.
It is safe, to replace them withbody.ReplaceHand(...)
, on your own objects at the run time.Hands[0]
- left hand;Hands[1]
- right handCustom way:
...description in progress