Objective:
This series is intended to cater to the upsurge of unity VR and the learning needs of everyone, the launch of the unity-oriented leap motion official document in English-Chinese translation. This fifth article "Handcontroller (Hand Controller)" describes the Handcontroller (hand controller) preset and Handcontroller Script component use, and The various public properties and methods defined in the Handcontroller class .
Handcontroller Hand Controller
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.
The Handcontroller Script component is added to the Handcontroller (hand controller) preset body. This preset is used to draw the anchor point of the hand type. You can set handcontroller properties in the inspector, such as which hand presets to use.
When your play the scene, any hands detected by the Leap Motion controller is drawn relative to the position and Orientati On the prefab.
When you run the scene, all the hand patterns detected by the LEAP Motion controller will be drawn relative to the position and orientation of the preset body.
If your hand is 20cm above the Leap Motion device, the virtual hand is drawn 20cm above the prefab position (if the Handco Ntroller transform scale are set to 1.0). Do note and the default scale is 20:1, so hands be drawn much larger than real-size. In the Unity Scene view, the approximate field of view of the Leap Motion sensors is shown.
If the hand is 20 cm above the leap motion device, the virtual hand is drawn at 20 centimeters above the preset (provided the scale value of the TRANSFOM component of the Handcontroller object is 1). It is important to note that by default the scale is 20:1, so the hand shape drawn in the scene is much larger than it actually is. In the Unity scene view we can see the approximate field of view of the leap motion sensor.
class
Handcontroller Handcontroller class
The Controller object, instantiates hands and tools to represent, the hands and tools tracked by the Leap Motion device .
The controller object is used to instantiate the hands and tools tracked by the leap motion device.
Handcontroller is a unity Monobehavior instance that serves as the interface between your Unity application and T He Leap Motion service.
The Handcontroller class is a subclass of the Unity Monobehavior class and is the interface for unity applications and leap motion services.
The handcontroller script is attached to the handcontroller prefab. Drop a handcontroller prefab into a scene to add the motion-controlled hands. The hands is 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 the range of motion of the hands without C Hanging the apparent model size.
The Handcontroller script is added to the Handcontroller preset body. Drag the Handcontroller preset to the scene to add a 3D motion Control hand shape. The hand type will appear above the preset based on the real-world physical leap device perception. You can adjust the orientation and size of the hand shape in the scene by changing the property values of the transform component of the preset. Changing the Handcontroller.handmovementscale property can change the range of hand motions without changing the size of the hand.
When the Handcontroller was active in a scene, it adds the specified 3D models for the hands to the scene whenever Physical hands is tracked by the Leap Motion hardware. By default, these objects is destroyed when the physical hands is lost and recreated when tracking resumes. The asset package provides a variety of hands so can use in conjunction with the hand controller.
If the hand controller is active in the scene, the specified 3D hand shape is added to the scene when the leap motion hardware device tracks the hands. By default, these objects are destroyed when they are not tracked and re-created when they are traced again. The resource bundle is available in a variety of hand types and is used in combination with a hand controller.
public Functions Common functions
void
Destroyallhands() Destroy all hand types
Destroys all hands owned by this Handcontroller instance.
Destroys all hand types instantiated by the current Handcontroller class.
String
finishandsaverecording() Complete and save the record
Saves the recording to a new file, returns the path, and starts playback.
Saves the current record to a new file, returns the path, and plays
-
return value
-
String the path to the saved recording. The string type records the saved path.
Handmodel[]
Getallgraphicshands() Get all graphic hand shapes
Returns a copy of the hand model list. Returns a copy of the hand model list
Handmodel[]
Getallphysicshands() Get all physical hand types
Returns a copy of the Physics model list. Returns a copy of the physical model list
Frame
GetFrame() Get Frame
Returns the latest Frame object. Returns the last frame of an object.
If the Recorder object is playing a recording and then the frame is taken from the recording. Otherwise, the frame comes from the Leap Motion Controller itself.
If the Logger object is playing a record, the frame is fetched from the record. Otherwise it will be obtained from the Leap motion controller itself.
Controller
Getleapcontroller() Get Leap controller
Returns the Leap Controller instance. Returns a Leap controller instance.
Float
getrecordingprogress() Get Record progress
The current frame position divided by the total number of frames in the recording.
Records the progress scale of the current frame. [Translator Note: The value range is 0 ~ 1]
void
Ignorecollisionswithhands(Gameobject to_ignore, bool ignore = true) ignore hand collisions
Turns off collisions between the specified Gameobject and all hands.
Closes the collision of the specified game object with the hand.
Subject to the limitations of Unity physics.ignorecollisions (). See.
See Unity physics.ignorecollisions ().
bool
isconnected() whether to connect
True if the leap motion hardware is plugged on and this application are connected to the Leap Motion service.
The return value is true, indicating that the leap motion hardware is plugged in and the current application is connected to the Leap Motion service.
bool
isembedded() is embedded
True if the active Leap Motion device is embedded in a laptop or keyboard.
The return value is true, which means that the currently enabled Leap motion device is embedded in a laptop or keyboard.
void
pauserecording() Pause record
Stops playback or recording without resetting the frame counter.
Pauses playback or recording.
void
playrecording() Play record
Start getting frames from the leaprecorder object rather than the Leap service.
Gets the frame from the Leaprecorder object, not the leap service.
void
Record() recording
Starts saving frames.
Start saving frames.
void
resetrecording() Reset Record
Discards any frames recorded so far.
Discard the previously recorded frames.
void
stoprecording() Stop Recording
Stops recording or playback and resets the frame counter to the beginning.
Stops recording or playback, and sets the current frame to its initial position.
Public Members
BOOL destroyhands Whether hand type can be manually destroyed
If hands is in charge of destroying themselves, make this false.
If the hand type is destroyed autonomously, it needs to be set to false.
BOOL Enablerecordplayback Recording playback is active
Set true to enable recording.
Set to true to make the record play valid.
Vector3 Handmovementscale Hand Movement range
The scale factors for hand movement.
The zoom ratio of the hand movement.
Set greater than 1 to give the hands a greater range of motion.
A value greater than 1 o'clock enlarges the hand movement range.
Whether the bool isheadmounted is used in a head-mounted device
Set true if the Leap Motion hardware is mounted in an HMD; Otherwise, leave false.
Set to True when the leap motion hardware is used for the headset device, otherwise false.
Handmodel Leftgraphicsmodel left graphic model
The gameobject containing graphics to use for the left hand or both hands if Separateleftright is false.
The drawing object used by the left hand, when Separateleftright is false, for both hands.
Handmodel Leftphysicsmodel left physical model
The gameobject containing colliders to use for the left hand or both hands if Separateleftright is false.
The physical collider object used by the left hand for both hands when Separateleftright is false.
BOOL Mirrorzaxis Mirror z-Axis
Reverses the z axis.
Reverse the z-axis direction.
BOOL Recorderloop Logger cycle
Whether to loop the playback.
Controls whether the loop plays.
Float recorderspeed Recorder speed
Playback speed. Playback speed.
Set to 1.0 for normal speed. 1 for normal speed.
Textasset recordingasset log file resource
The file to record or playback from.
Files that are recorded or played.
Handmodel Rightgraphicsmodel right side graphic model
The graphics hand model to use for the right hand.
Graphic hand type for right hand use.
Handmodel Rightphysicsmodel Right Physical model
The physics hand model is the right hand.
The right hand uses the physical hand type.
BOOL separateleftright Split-handedness
Whether to use a separate model for left and right hands (true); or mirror the same model for both hands (false).
Used to control the use of different models (when true) or using the same model (when false) through mirroring.
Toolmodel Toolmodel Tool Model
The gameobject containing both graphics and colliders for tools.
Change the game object to include the tool's graphics and collider.
————————————————————————————————
For more information:
"VR" Leap Motion Official Document Script reference (directory)
(Copyright notice: This is a translation of the Leap Motion website document, all rights reserved by the Leap Motion website, and the text content is for learning only.) )
"VR" Leap Motion Official document Handcontroller (hand Controller)