VR开发教程:Leap Motion官网文档HandController(手部控制器)

发表于2018-01-06
评论0 4.9k浏览
前言:
本系列译文是为迎合Unity VR的热潮与大家的学习需要,推出的针对Unity方向的Leap Motion官方文档中英对照翻译。 本篇第五篇 《HandController(手部控制器)》 介绍了HandController(手部控制器)预设体与HandController脚本组件使用,以及HandController类中定义的各个公共属性与方法。

HandController  手部控制器
The HandController script is attached to the HandController prefab. The prefab serves as the anchor point for drawing hands. You can set the HandController properties, such as which hand prefabs to use, in the Inspector panel.
HandController脚本组件添加在HandController(手部控制器)预设体上。该预设体是用来绘制手型的锚点。你可以在检视面板中设置HandController的属性,例如使用哪种手型预设体等。

When you play the scene, any hands detected by the Leap Motion controller are drawn relative to the position and orientation of the prefab.
当你运行场景之后,Leap Motion 控制器检测到的所有手型都将相对于该预设体的位置和方向进行绘制。

If your hand is 20cm above the Leap Motion device, the virtual hand is drawn 20cm above the prefab position (if the HandController transform scale is set to 1.0). Do note that the default scale is 20:1, so hands are drawn much larger than real-size. In the Unity Scene view, the approximate field of view of the Leap Motion sensors are shown.
如果手在Leap Motion设备上方20厘米,虚拟手讲被绘制在预设体上方20厘米(前提是HandController对象的Transfom组件的scale值为1)。需要注意的是,默认情况下缩放比例为20:1,因而场景中绘制出来的手型要比实际大得多。在Unity场景视图中我们可以看到Leap Motion传感器的近似视野区域。

class HandController   HandController 类
The Controller object that instantiates hands and tools to represent the hands and tools tracked by the Leap Motion device. 
该控制器对象用于实例化Leap Motion设备追踪的手部和工具。

HandController is a Unity MonoBehavior instance that serves as the interface between your Unity application and the Leap Motion service.
HandController类是Unity MonoBehavior类的子类,是Unity应用程序和Leap Motion服务的接口。

The HandController script is attached to the HandController prefab. Drop a HandController prefab into a scene to add 3D, motion-controlled hands. The hands are placed above the prefab at their real-world relationship to the physical Leap device. You can change the transform of the prefab to adjust the orientation and the size of the hands in the scene. You can change the HandController.handMovementScale property to change the range of motion of the hands without changing the apparent model size.
HandController脚本添加在HandController预设体上。将HandController预设体拖拽到场景中可以添加3D的动作控制手型。手型会根据真实世界的物理Leap设备感知出现在预设体上方。你可以通过改变该预设体Transform组件的属性值来调整场景中手型的方向和大小。改变HandController.handMovementScale属性可以在不改变手型大小的前提下改变手部运动的范围。

When the HandController is active in a scene, it adds the specified 3D models for the hands to the scene whenever physical hands are tracked by the Leap Motion hardware. By default, these objects are destroyed when the physical hands are lost and recreated when tracking resumes. The asset package provides a variety of hands that you can use in conjunction with the hand controller. 
若手部控制器在场景中处于激活状态,就会在Leap Motion硬件设备追踪到手部时,在场景中添加指定的3D手型。默认情况下,这些对象会在追踪不到时销毁,再次追踪到时重新创建。资源包提供了多种手型,与手部控制器结合使用。

Public Functions  公共函数

void DestroyAllHands()  
销毁所有手型

Destroys all hands owned by this HandController instance. 
销毁当前HandController类实例化的所有手型。

string FinishAndSaveRecording()
完成并保存记录
Saves the current recording to a new file, returns the path, and starts playback. 
保存当前记录到一个新的文件中,返回路径,并播放

Return  返回值
string The path to the saved recording.   字符串类型  记录所保存的路径。

HandModel [] GetAllGraphicsHands()  获取所有图形手型
Returns a copy of the hand model list.  返回手部模型列表的拷贝


HandModel [] GetAllPhysicsHands() 获取所有物理手型
Returns a copy of the physics model list.  返回物理模型列表的拷贝


Frame GetFrame()  获取帧
Returns the latest frame object.  返回对象的最后一帧。

If the recorder object is playing a recording, then the frame is taken from the recording. Otherwise, the frame comes from the Leap Motion Controller itself. 
如果记录器对象正在播放记录,那么该帧将从记录中获取。否则将从Leap Motion控制器本身获取。


Controller GetLeapController() 获取Leap控制器
Returns the Leap Controller instance. 返回Leap控制器实例。

float GetRecordingProgress() 获取记录进度
The current frame position divided by the total number of frames in the recording. 
记录当前帧的进度比例。[译者注:取值范围为 0 ~ 1]

void IgnoreCollisionsWithHands(GameObject to_ignore, bool ignore = true) 忽略手部碰撞

Turns off collisions between the specified GameObject and all hands. 
关闭指定游戏对象与手部的碰撞。

Subject to the limitations of Unity Physics.IgnoreCollisions(). See . 
参见Unity Physics.IgnoreCollisions()。


bool IsConnected() 是否连接
True, if the Leap Motion hardware is plugged in and this application is connected to the Leap Motion service. 
返回值为真,表示Leap Motion硬件已插入,且当前应用程序连接到Leap Motion服务。


bool IsEmbedded() 是否嵌入
True, if the active Leap Motion device is embedded in a laptop or keyboard. 
返回值为真,表示当前启用的Leap Motion设备嵌入在笔记本电脑或键盘中。


void PauseRecording() 暂停记录
Stops playback or recording without resetting the frame counter. 
暂停播放或记录。


void PlayRecording() 播放记录
Start getting frames from the LeapRecorder object rather than the Leap service. 
从LeapRecorder对象中获取帧,而非Leap服务。


void Record() 录制
Starts saving frames. 
开始保存帧。


void ResetRecording() 重设记录
Discards any frames recorded so far. 
舍弃之前已录制的帧。

void StopRecording() 停止记录
Stops recording or playback and resets the frame counter to the beginning. 

停止录制或播放,并将当前帧设置到初始位置。

Public Members  公共成员
bool destroyHands  是否可以手动销毁手型

If hands are in charge of Destroying themselves, make this false. 

如果手型自主销毁,需要将其设置为false。

bool enableRecordPlayback 记录播放有效化

Set true to enable recording. 

设置为true 使记录播放有效。

Vector3 handMovementScale 手部移动范围

The scale factors for hand movement. 

手部移动的缩放比例。

Set greater than 1 to give the hands a greater range of motion. 

该值大于1时将放大手部移动范围。

bool isHeadMounted 是否用于头戴设备

Set true if the Leap Motion hardware is mounted on an HMD; otherwise, leave false. 

当Leap Motion硬件被用于头戴设备时,设置为true;否则为false。

HandModel leftGraphicsModel 左侧图形模型

The GameObject containing graphics to use for the left hand or both hands if separateLeftRight is false. 

左手所使用的图形对象,当separateLeftRight为false时用于双手。

HandModel leftPhysicsModel 左侧物理模型

The GameObject containing colliders to use for the left hand or both hands if separateLeftRight is false. 

左手所使用的物理碰撞器对象,当separateLeftRight为false时用于双手。

bool mirrorZAxis 镜像Z轴

Reverses the z axis. 

对Z轴方向取反。

bool recorderLoop 记录器循环

Whether to loop the playback. 

控制是否循环播放。

float recorderSpeed 记录器速度

Playback speed. 播放速度。

Set to 1.0 for normal speed.  1为正常速度。

TextAsset recordingAsset 记录文件资源

The file to record or playback from. 

记录或播放的文件。

HandModel rightGraphicsModel 右侧图形模型

The graphics hand model to use for the right hand. 

右手使用的图形手型。

HandModel rightPhysicsModel 右侧物理模型

The physics hand model to use for the right hand. 

右手使用物理手型。

bool separateLeftRight 分离左右手

Whether to use a separate model for left and right hands (true); or mirror the same model for both hands (false). 

用于控制左右手使用不同模型(为true时)或通过镜像使用相同模型(为false时)。

ToolModel toolModel 工具模型

The GameObject containing both graphics and colliders for tools.

改游戏对象包含工具的图形和碰撞器。

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引