Sei sulla pagina 1di 4

08/09/2016 TheFundamentalStepsofLeapMotionCombinationinYourUnity3DProject126Kr

TheFundamentalStepsofLeapMotionCombinationinYour
Unity3DProject
Datetime:2016082307:06:12Topic:Unity3DShare

LeapMotionhasbeentryingtomakevirtualrealitymoreimmersivethaneverwithanewhandtrackingsystem.
Thefutureofhumancomputerinteractionisabouttoundergoastandardsshift.Eversincethestartofcomputing,
scientistsandappdevelopershavebeenworkingtowardcreating3Denvironments.

Weliveinveryinterestingtimes.Wearegrowingclosertomakingthesesciencefictionideasintosciencefacts.In
reality,wehavealreadydonesotosomeextent.Virtualrealityisagreattopic.OneofthemajortopicswithinVRis
theabilitytointeractwiththedigitalworld.Thisarticlewillconcentrateonthecommunicationoftheuserwiththe
digitalworld,applyingahardwaresensordevelopedbyLeapMotion.

Here,Iwillbeincludinghowtocombine&useLeapMotionhandmotionsensorwithUnity3D.

WhatistheLeapMotionController?
TheLeapMotionControllerfunctionsjustlikemovingyourhand.Itfollowsall10fingersuptoone100thofa
millimeter.It'sdramaticallymoredelicatethanexistingmotioncontroltechnology.Thatishowyoucandrawor
paintminimasterpiecesinsideaoneinchcube.

LeapMotionSetupandUnity3DIntegration
First,youwillneedtodownloadtheSDKforLeapMotion.AfteryoudownloadtheSDK,installtheruntime.The
SDKsupportsavarietyofplatformsandlanguagesthatyoucanlookinto.

AssumingyouhavealreadydownloadedandinstalledUnity5onyourmachine,thenextthingyouwillneedtodo
isgettheLeapMotionUnityCoreAssetsfromtheassetstore.

AfterdownloadingandinstallingtheLeapMotionCorecapitals,wecanbeginwithdevelopingoursimplescene
andlearninghowtocommunicatewiththeassets,extendingthemforourownpurposes.Goaheadandcreatea
newemptyprojectandimporttheLeapMotionCoreAssetsintoyourproject.

LeapMotionCoreAssets
Intheprojectwindow,yourmainfocusshouldbetheLeapMotionfolder.ThefoldersthatincludeOVRarefor
applyingLeapMotionwithaVRheadset.Wewillincludethisinafuturearticle.

Youshouldtaketimeandstudythestructuremoreimportantly,studythecontentofeachfolder.Oneofthe
maincoreassetsthatyouwillwanttobecomefamiliarwithistheHandController.Thisisthecentralbuildingblock
thatenablesyoutocommunicatewiththeLeapMotiondeviceinyourview.Itservesasthesupportpointfor
renderingyourhandsinthescene.

TheHandControllerprefabhastheHandControllerscriptconnected,whichenablesyoutocommunicatewiththe
device.Theadvantageofthisdesignisthatyoucanbuildyourownhandmodelsandusethemwiththecontroller
forvisualdesign,aswellascustomgesturesandmore.

AnotherkeypropertyistheHandMovementsystemvector.Awordofwarninghere,youwillneedtoreadthe
documentationandspecificationsforusingtheproperadjustmentsfortheparticularapplicationthatyouare
workingon.

http://126kr.com/article/5q5nbnu7lg9 1/4
08/09/2016 TheFundamentalStepsofLeapMotionCombinationinYourUnity3DProject126Kr

TheHandMovementsystemvectorisusedtoimprovetherangeofmotionofthehandswithoutincreasingthe
possiblemodelsize.PlacingtheHandControllerobjectisessential.Asstated,thisistheanchorpointforyour
camera,andyourcamerashouldbeinthesameareaastheHandController.

Thefactthatyoucanreallyseeyourhandmovementinthepicturebyitselfisahugeundertakingwiththeassets
thathavebeengiven.Tomakeeverythingmoreinteresting,youwillneedtobeabletocommunicatewiththe
environmentandmodifyandmanipulatestuffwithinthescene.

Forsimplicity,wewillsetthreecubesservingasourcolorpallet.Thefirstwillbered,thesecondwillbeblue,and
thethirdonewillbeorange.(Youcanpickanycolorsyouwant,bytheway.)Weneedtoplacethecubesinaway
thatinteractingwiththemiseasyfortheuser.

Wecanputthecubesinthefollowingorder:

TheCube (0,1,3)
RedCube (3,1,3)
BlueCube (0,1,3)
OrangeCube (3,1,3)
ThenextstepistogeneratethescriptthatwillhelpuscommunicatewiththeCubeGameObjects:

Asyoucansee,thecodeisnotverycomplex,butitdoeshelpusgetwhatwewant.Therearethreepublic
variablesthatareapplied:toidentifywhethertheobjectisselectable,thecolorthattheobjectuses,andthe
selectedcolor.

ThecoreofthelogichappensintheOnTriggerEnterfunction.Wechecktoseeiftheobjectthatinteractedwiththe
Cubeistheindexfinger,thenwechecktonoticeiftheobjectisselectable.Iftheobjectisselectable,wesetthe
selectablecolortothepredefinedcolorcodeandexitthefunction.

ThissamefunctionisalsousedtoimplementtheselectedcolorwiththeCubeGameObject.Forthisspecialcase,
wegettheRendererobjectfromtheCubeandsetthematerialcolortotheselectedcolor.

HowAboutMovinganObject?

http://126kr.com/article/5q5nbnu7lg9 2/4
08/09/2016 TheFundamentalStepsofLeapMotionCombinationinYourUnity3DProject126Kr

Thisisgreat,butwhatifyouwantedtobeabletohavemorecommunicationwithyour3Denvironment.Let'slook
atasimpleexampleyouneedtopickupobjectsandmovethemaroundinthescene.

Inorderforustomakeithappen,weneedtowritemorecode!Extendingourexample,wewillimplementthe
codethatwillenableyoutopickuptheCubeobjectandmoveitaroundintheenvironment.

http://126kr.com/article/5q5nbnu7lg9 3/4
08/09/2016 TheFundamentalStepsofLeapMotionCombinationinYourUnity3DProject126Kr

Virtualrealityhasalwaysbeenoneofthosetopicsintheindustrythatgetsalotofexposureatonce,thencools
down.Thistimearound,thingsareabitdifferent.ThehardwareandsoftwareecosystemthatenablesVRis
becomingmoredemocratized.Thecostofthehardware,eventhoughit'snotcheap,isatapointthatmost
developerscanafford.

ThisallowsthedevelopmentcommunitytoprovidebetterVRexperiencesandentertainment.Theideaof
integratinghandmotionandgestureswithVRappsisamust.

http://126kr.com/article/5q5nbnu7lg9 4/4

Potrebbero piacerti anche