@depasquale/three-immersive-controls

中文文档
0.0.17发布于 2024/09/28MITTypeScriptES Module近 30 天下载 3.9万

Immersive (VR) controls for Three.js

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Options
  4. Examples
  5. To do

Three.js Immersive Controls

  • Immersive (VR) functionality
    • Movement and rotation with VR controllers (move with left thumbstick, rotate with right thumbstick)
    • Object selection with VR controllers (A button or trigger)
  • Browser window functionality
    • Movement and rotation with keyboard (WASD and arrow keys)
    • Object selection with mouse

Installation

npm install @depasquale/three-immersive-controls

Usage

import ImmersiveControls from '@depasquale/three-immersive-controls';

// Create the `camera`, `renderer`, and `scene` instances with Three.js
// ...

const controls = new ImmersiveControls(camera, renderer, scene, { /* options */ });

Include this in the render loop:

controls.update();

Options

  • initialPosition: THREE.Vector3
    • The player's initial position in the scene. Default is new THREE.Vector3(0, 1.6, 4).
  • lookAt: THREE.Vector3
    • Point toward which the player is initially oriented. (Not yet implemented.)
  • floor: number | false
    • number (default is 0): Sets the y position of a floor below which the player cannot pass (simple solution for collision detection instead of navmeshes).
    • false: No limit to the player's movement along the y-axis is set.
  • gravity: true | false
    • true (default): The player's movement is restricted to the x- and z-axes, and the y position remains at the floor setting.
    • false: The player can also move vertically along the y-axis (flight mode).
  • moveSpeed: { keyboard: number, vr: number }
    • Speed at which the player moves through the scene when input is received from the keyboard or VR controllers. Default is { vr: 2.5, keyboard: 5 }.
  • rotateSpeed: number
    • Speed at which the player is rotated when input is received from the keyboard or VR controllers. Default is 1.
  • tumble: true | false
    • Allow the player to rotate on the x-axis in addition to the y-axis. Default is false.
  • showControllerModel: true | false
    • Show the VR controllers in immersive mode. Default is true.
  • showEnterVRButton: true | false
    • Add a button to the DOM to allow the user to enter immersive mode when this functionality is supported. Default is true.
  • showExitVRButton: true | false
    • Display a button in front of the player in the scene which allows the user to exit immersive mode. Default is true.
  • vrControls: true | false
    • Activate immersive (VR) controls. Default is true.
  • keyboardControls: true | false
    • Activate keyboard controls. Default is true.
  • mouseControls: true | false
    • Activate mouse controls. Default is true. (Movement with mouse input has not yet been implemented, but object selection with the mouse works.)
  • showFps: true | false
    • Display the Stats indicator in the DOM and in front of the player in the scene to monitor performance. Default is false.

Examples

Examples are provided in the examples directory. To try them locally in your browser, run:

npm run examples

Or try them here.

To do

  • Add collision detection with navmeshes
  • Test with a variety of VR devices (so far only tested with Oculus Quest 2)
  • Handle situations when only one VR controller is available
  • Add controls for touchscreen devices
  • Better repositioning of "Exit VR" button in scene
  • Possible additional features
    • Teleportation
    • Blinders during rotation and movement
    • Movement with mouse input
    • Hand tracking

版本与发布记录

@depasquale/three-immersive-controls 共发布 17 个版本,首次发布于 2022/03/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.17latest2024/09/282 年前
0.0.162024/09/272 年前
0.0.152023/11/063 年前
0.0.142022/09/224 年前
0.0.132022/09/214 年前
0.0.122022/08/034 年前

关于 @depasquale/three-immersive-controls 的常见问题

@depasquale/three-immersive-controls 是什么?

Immersive (VR) controls for Three.js

如何安装 @depasquale/three-immersive-controls?

在项目目录运行 npm install @depasquale/three-immersive-controls,或使用 pnpm add / yarn add / bun add。

@depasquale/three-immersive-controls 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@depasquale/three-immersive-controls 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@depasquale/three-immersive-controls 可以商用吗?

@depasquale/three-immersive-controls 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@depasquale/three-immersive-controls 的下载量有多少?

根据 npm 官方下载统计,@depasquale/three-immersive-controls 在 2026/10/12 – 2026/11/10 这 30 天内被下载 38,940 次,日均约 1,298 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@depasquale/three-immersive-controls 还在维护吗?

最新版本 0.0.17 发布于 2024/09/28(2 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/03/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。