devwiki:vr

This is an old revision of the document!


Hardware

Oculus Quest 2 pack

Install All Apps first:

Enable Developer mode for your account

Oculus Casting and Screen Sharing

  • in headset, click Share button > Casting > choose TV or your computer
  • if you choose computer, go computer browser, go link : https://www.oculus.com/casting, you need to login same account as headset

Start VR in Unity

  • platform : android
  • package:
    • XR plugin management 4.2.1
    • XR interactive toolkit 2.0.2 (new input and yes)
    • oculus XR plugin: 1.12
  • player setting:
    • xr plugin management: check oculus for both pc and android
  • package manage:
    • XR interaction toolkit > sample > add asset and simulator
  • assets
    • starter assets : XRI default left+right controller: click add to ActionBasedController default
    • now in Player setting: preset manager, the XRI left right controller should be there, and type Right/Left for the filter
  • checklist
    • android: texture compression : ASTC
    • player setting:
      • quality: choose medium setting preset
        • anisotropic texture: disable
        • anti alias: 4x multi sample
        • shadow : disable
      • player: other setting:
        • dynamic batching: on
        • minimum api: 23
        • optimize: prebake collision mesh: on
      • audio:
        • dsp buffer size: good latency
  • scene
    • add XR origin (action based)
      • tracking mode: floor
    • XR origin: add component
      • Input action manager: action asset: element0: » search XRI default input action
    • add empty game object, name “LocomotionSystem”
      • add component: “Locomotion System”, drag in XR Origin object
      • add component: “Teleportation provider”, drag itself into it
      • add component: “Snap Turn provider”, drag itself into system, check “Right Hand Snap Turn”, reference as search “XRI RightHand Locomotion/Turn (Input Action Reference)”
    • Teleport Method 1: add cylinder obj, add teleportation Anchor
      • object under layer “Teleport”
      • match orientation: target up and forward
      • events > First Hover Enter, drag highlight indicator geo group there, function as setActive, tick box
      • events > Last Hover Exited, drag highlight indicator geo group there, function as setActive, not tick box
    • Teleport Method 2: teleport area
      • select floor object, add component: “Teleportation Area”
        • set teleport highlight object to custom reticle
        • drag locomotionSystem into teleportation provider
    • Customize lazer pointer
      • XR origin > LeftHand Controller
        • xr ray interactor:
          • Raycast Mask : (optionally) uncheck Teleport layer (so left hand cant teleport)
      • XR origin > RightHand Controller
        • xr ray interactor:
          • velocity : 8 (how far it projects)
          • Raycast Mask : (optional) Teleport layer
        • line visual :
          • Override line length: uncheck, so it can be infinite
          • color: (optional)
    • character
      • XR origin: add component: “Character controller”
      • Locomotion system:
        • add “Character controller driver”
          • provider: link to below
        • add “Continuous move provider (action based)”: (has gravity)
          • link system,
          • gravity application mode (attempt move: only when move / immediate: realtime)
          • forward source: ( LeftHand controller (your hand )/ Main Camera (your eye) )
          • left hand move action: checked : search “XRI LeftHand Locmotion/Move - input action”
    • (optional) VR tunneling pro:
      • main camera: add component “tunneling mobile”
        • motion target: xr origin
        • effect coverage: 0.5
        • uncheck angular velocity
        • check linear velocity: max 1.5
    • (optional) tunneling blink (turn will blink)
      • under main camera, create a RAWImage. which auto create canvas object,
      • name canvas object, BlinkCanvas, and choose as world space
      • RAWImage, width height: 2, color : black
      • drag Blink.cs to BlinkCanvas
      • select BlinkCanvas, create animation
        1. first frame: RawImage color alpha 0, RAWImage enabled
        2. second frame: RAWImage color alpha 1, RAWImage enabled, Event: DoAction()
        3. third frame: RAWImage color alpha 0, RAWImage disable, event: TunnelingOn()
      • drag BlinkCanvas into Blink.cs as animator
      • drag Main camera, as tunneling mobile
      • RightHand Controller > Interactor Events > Select Exited > BlinkCanvas : PlayAnim()
      • (optional: if you want left hand teleport also has blink) LeftHand Controller > Interactor Events > Select Exited > BlinkCanvas : PlayAnim()
      • In BlinkCanvas > Animator panel, create trigger called “Blink”
        • entry > empty state > BlinkAnimation (no exit time, condition: blink) > empty state (has exit time)
      • uncheck RAWImage, now, (as animation will check it)
      • (updated turn aciton)
        • Locomotion system: uncheck old snap turn provider
        • add new ActionBasedSnapTurnProviderBlink.cs to it as Snap Turn Provider
        • link locomotionSystem, and drag BlinkCanvas to the blink.
        • check RightHand Snap turn, use reference, XRI RightHand Locomotion/Turn
    • (extra) add blink to teleport
      • use modified ActionBased CountinuousMoveProvider, “ActionBasedContinuousMoveProviderBlink.cs”, it will track moving status
      • drag it to LocomotionSystem, (set system to “LocomotionSystem”, speed to 2, use Left Hand move action, LeftHand/Move, forward source: LeftHand Controller, reference LeftHand locomotion/move)
      • uncheck old Counitouse Move Provider component
      • update “blink.cs”, to support this
      • drag LocomotionSystem to BlinkCanvas's Blink component: Movement provider.
      • ———– optional: delay teleport after blink
      • go LocomotionSystem, uncheck old TeleportationProvider component
      • drag new custom TeleportationBlinkProvider to it
        • locomotion > system
        • BlinkCanvas > blink
      • remove manual blink call from RightHand Controller interactor, since we bake it into new script
      • remove Teleportation Area we on floor with new “TeleportationBlinkArea.cs”
      • do same for teleportation anchor
    • (extra) add toggle for teleport controller
      • rename RightHand Controller as RightHand Teleport controller, duplicate as left and use left hand control copy control component and paste input value there
      • duplicate LeftHand controller as RightHand controller, and copy over input value as well
      • so that, you have 2 set of controller for hands, one set for interact, one set for teleport
      • turn off LeftHand and RightHand line visualizer for those straight line.
      • drag custom “Controller Mode Swap.cs ” script to XR origin, then put those 4 controllers there.
      • and check user reference: XRI RightHand Locomotion/Teleport mode activate
      • then, hide teleport set first.
      • — make right jobstick forward as activate teleport, while old left right to turn
      • RightHand teleport Controller > XR controller : selection action: changed to RightHand Locomotion/Teleport select
        • also, remove the select exited event for previous manual blink (if you keep it there, and turn it from runtime to off, it will make you need to press grip select button to be able to teleport)
        • to cancel teleport, you cant basically, or point to a place where teleport cant go to cancel
    • (extra) add Oculus Hands.unitypackage
      • go oculus hands / material, change material to standard
      • set the prefab to LeftHand controler / RightHand controler prefab model
    • (optional) offset teleport ray
      • create empty gameobject under teleport controller, name as “RayOriginTransform”
      • then, in Teleport controller > XR ray interactor : Ray original transform (drag the “RayOriginTransform” there)
      • then offset “RayOriginTransform”, so that the ray is at correct position you want
      • use XR device simulator, and play game, enable controller to see, and in Scene mode to move the transform
      • then disable game and disable XR device simulator
  • — Physical interaction
    • create game object sphere with collider + XR grab interactable / (optional: XROffsetGrabInteractor.cs)
      • XR grab interactable:
        • movement type:
          • velocity tracking (more calculation, cant penetrate into other objects)
          • kinematic (ok calculation, can into other objects)
          • instantaneous (just follow)
        • (optional) custom Attach Transform to the center to grab, + attach point compatible mode:legacy
        • (optional) grab interatable: event on select point to it: first select / last exit
    • so you can grab
      • (optional custom grab) Controller: XR ray interactor
        • anchor control: off
        • force grab: thing will fly to your hand
        • hit closest only: yes
        • hover to select: (off) auto grab
        • hide controller on select: on
    • for physical calculation: player setting: time : fixed timestep 0.0138889 for 72hz physicals, instead of 0.02
  • (extra) direct controller
    • duplicate RightHand control (rename old as ray controller), as RightHand direct controller
      • add component: XR direct interactor: hide controller on select ON
      • add component: sphere collider: 0.1 and is Trigger
  • (extra) object grab interactable script
    • highlighter.cs:
      • hide and show optional select indicator geo
      • control outline width of outliner material assigned to the object
    • colorChanger.cs for index button press trigger effect
      • it take original material + new material for trigger switch
    • (no script method): index finger trigger is at grab interactable event : Activate/Deactivate

XR socket interactor: for take object into place

  • create empty object with sphere collider (as trigger),
  • add componenent: XR socket Interactor: (with your valid indicating material in Hover Mesh Material)
  • create a attachPoint empty object under it for it attach, then put it into “Attach Transform”
  • object with Grab Interactor will auto be put there once it touches its collider
  • use mask layer to filter out interaction

VR UI Canvas

  • create > XR > UI Canvas

XR Interaction Toolkit > XR Device Simulator, (disable it before export to device, this is for on screen testing w.o device)

  • drag it to scene
  • right click drag to move camera
  • hold shift + move left mouse to move left hand
  • hold space + move left mouse to move right hand
  • wasd key + shift/space to turn
  • g + shift/space to select

VR Framework setup

  • import vr framework
  • android ATSC
  • uncheck all scene
  • install oculus XR plugin : 1.12.1
  • install vrTunnelingPro
  • Project setting: XR plugin management
    • check “Oculus” on for both pc and android
  • ~~~~~
  • setup
  • drag XR rig (BNG/Prefabs/Player) to scene (1 in Y)
  • create floor (convex)
  • delete default camera
  • on XR Rig/PlayerController/CameraRig/TrackingSpace/CenterEyeAnchor > add component: Tunnelling Mobile
    • drag PlayerController to Motion Target
    • motion detection: change to Linear Velocity (0, 1.5)
    • replace edited motion stuffs script in (BNG Framework/Script/Core)
    • modify PlayerControl componets
      • Locomotion manager: default locomotion both; uncheck from preference; none for toggle action
      • player teleport: control type : x button
      • player teleport: initiate teleport action: none
      • player teleport: uncheck for allow teleport rotation
      • smooth locomotion: speed 2: sprint speed: 4; strafe speed: 2; strafe sprint speed: 4; sprint input: left thumbstick; jump input: A button;
      • player teleport: tunneling → CenterEyeAnchor; smooth locomotion → PlayerController
      • player rotation: fader → CenterEyeAnchor
    • modify CenterEyeAnchor:
      • Screen Fader: change fade in/out speed to adjust screen fade

Make Object Grabbale

  • object + rigidbody + Grabbale script + grabbale layer (so no push with your body)
    • grab button: use Grabber button
    • grab mechanic: (precise = grab offset; snap = in pivot position)
    • grab physics: (none=cant grab; physicivelocity=ok; kinematic=laggy)
    • remote grab: aimming with auto grab (linear, velocity, flick == how it fly to you)
    • hand options (hide hand, parent to hand = fast calculation; snap hand = hand pose)
    • can be dropped / snap to snap zone / force disable kinematic on drop
    • break distance= release on hand drag gap when fighting with physics
    • hand pose=grab pose
    • secondary grab behavior (change hands or holds both hands)
    • grab point (a transform like cup handle for grab point; require: snap hand model + grab snap)
      • create null object + Grab Point script
  • extra sound = Grabbable Haptics script + audio source + Collision sound script
  • (How it works: under
  • XR Rig/PlayerController/CameraRig/TrackingSpace/RightHandAnchor/RightControllerAnchor/RightController/Grabber;

Make Object highlight

  • replace BNG Framework/scripts/component, GrabbableHighlight.cs + OutlineEffect folder add
  • outline effect component into CenterEyeAnchor
  • object + GrabbableHighlight

others:

  • + grabbable highligh material script
  • + rigt helper

VR quick workflow

wip

  • devwiki/vr.1656523444.txt.gz
  • Last modified: 2022/06/29 17:24
  • by ying