devwiki:vr

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

VR quick setup

initial setup

  1. new project: build settings - android
  2. player settings: input: new inputs
  3. [add] package manager: install (alt+_)
    • XR plugin management 4.2.1
    • XR interactive toolkit 2.0.2 + import Starter Asset
    • oculus XR plugin: 1.12
  4. player setting:
    • xr plugin management: check oculus for both pc and android
  5. [add] import external package:
    • Oculus Hands.unitypackage
    • VR Tunnelling Pro.unitypackage

input tweak

  1. go Assets / Samples / XR Interaction toolkit / 2.0.2/ Starter
  2. [add] select XRI default left+right controller: (top button in inspector) “add to ActionBasedController default”
  3. [set] Project setting > Preset Manager:
    • filter “Right”/“Left” for “XRI Default Right/Left Controller”

Settings

  1. Build settings: Android
    • texture compression: ASTC
  2. Project setting:
    • Quality: go option Medium:
      • anistropic texture = disable
      • anti alias = 4x
      • shadow = disable
  3. Player setting:
    • other : Dynamic Batching = true
    • other : mini API = 23
    • prebake collision mesh = true
  4. audio setting:
    • DSP buffet size = best latency
  5. Time setting:
    • fixed timestep = 0.0138889 (1/72)

MainScene

  1. Name MainScene
  2. delete default cameras
  3. First directional light
    • mode = realtime
    • shadow = no shadow
  4. Second directional light
    • mode = baked
    • shadow = soft shadows
  5. layer: Teleport / Grab / Player
    • project setting : physics : layer collision matrix > player not X grab

XR Rig

  1. [add] XR origin (action based)
    • to layer “Player” (no, this object only) « this is for VR, not XR origin without hand one.
    • tracking origin mode = “Floor”
  2. inside XR origin:
    • duplicate L/R controllers 2 times
    • 0 = RightHand Direct Controller
      • remove Ray interactor
      • remove interactor line visual
      • remove Line renderer
      • [add] “XR Director Interactor”
        • hide controller on select = true
      • [add] “Sphere collider”
        • is trigger = true
        • radius = 0.1
    • 1 = RightHand Ray Controller (L)
      • enable interaction with UI = true
      • Raycast config > Raycast mask = UI
      • interactor line isual > invalid color gradient all alpha = 0 (???)
    • 2 = RightHand Teleport Controller (L)
      • active = disabled
      • XR controller : selection action = XRI RightHand Locomotion / Teleport select
      • Ray interactor : enable interaction with UI = false
      • Ray interactor : line type = projectile curve
      • Ray interactor : velocity = 8
      • Ray interactor : Raycast mast = Teleport
      • interactor line visual : override line length = false

Blink effect

  • XR origin > Camera offset > Main camera
    • clipping planes : near = 0.01
    • [add] as its child, add UI > RAW Image (as BlinkCanvas)
    • rename auto created Canvas as “BlinkCanvas”
  • BlinkCanvas
    • Canvas : render mode = world space, position = [0,0,.02], wh=[0,0]
    • [add] script “Blink.cs”
    • its child: RAWImage: position =[0,0,0], w=2, h=2, color=black
    • select BlinkCanvas, create animation
      • rawImage: f0: active=true, alpha=0
      • rawImage: f2: alpha=1; event: DoAction
      • rawImage: f15: active=false; alpha=0; event: TunnelingOn
      • BlinkAnimation (triangle shape icon): loop time = false
    • Panel > Animator
      • select BlinkCanvas animation controller (box with 2 dot shape icon)
      • [add] trigger “blink”
      • [add] empty state, and set as default
      • [connect] BlinkEmptyState > BlinkAnimation: has exit time = false, condition : blink
      • [connect] BlinkAnimation > BlinkEmptyState: has exit time = true
    • hide RAWImage by default

tunneling effect

  • Main camera
    • [add] Tunneling mobile
      • motion target = XR Origin (??? XR Rig)
      • effect coverage = 0.5
      • angular velocity = falsse
      • linear velocity = true; max = 1.5

Locomotion system

  • [add] XR > LocomotionSystem
    • remove Snap Turn Provider (action-based)
    • [add] [custom script: SnapTurn folder] Snap Turn Provider Blink Action-based (ActionBasedSnapTurnProviderBlink.cs)
      • system = locomotion system
      • enable turn around = false (???)
      • blink = BlinkCanvas
      • Right Hand Snap turn - use reference = true
      • reference = XRI RightHand Locomotion/Turn
    • remove Teleportation Provider
    • [add] [custom script: Teleportation folder] Teleportation Blink Provider
      • system = locomotion system
      • blink = BlinkCanvas
    • [add] [custom script: Continous ] Continous Move Provider blink (ActionBasedConituousMoveProviderBlink)
      • system = locomotion system
      • move speed = 2
      • Left hand move action - use reference = true
      • reference = XRI LeftHand Locomotion/Move
      • forward source = LeftHand Direct Controller (???? doc=RightHand Direct, or you mean right is always for move direction??)
    • [add][custom] Character controller Driver 2.cs
      • locomotion provvider = its Continous move provider (??? doc=locomotion system)

Rig component

  • XR Origin
    • [add] Input Action Manager
      • action sets size = 1
      • element0 = XRI Default Input action
    • [add] Character controller
      • radius = 0.3
    • [add] [custom] ControllerModeSwap.cs
      • interactor controller = “RightHand Direct controller”
      • teleport controller = “RightHand Teleport controller”
      • teleport activation button - use refernece = true
      • reference = XRI RightHand Locomotion/Teleport mode activate
  • BlinkCavans > Blink.cs (uncomment that 2 lines)
    • animator = BlinkCanvas
    • tunneling = Main Camera
    • movement provider = locomotion system (contious move)

Hand Presenece Prefab

  • [create] empty LeftHand (pos=0,0,0)
    • [add] HandPresence.cs
    • [add] child: Oculus Hands\Prefabs\Left Hand Model
      • pos= 0,0,0; rot = 0,0,120
      • hand material: hands_solid = standard shader
      • [option] create transparent hand material: HandMat
        • albedo = transparent green, render mode = transparent
    • [add][custom: Controllers folder] child: Controllers\quest2_controllers_div0
    • hide Right parts
    • create controllerMat, standard, albedo = nextControllerBoth_color1k texture
    • assign that material to mesh
    • ———-
    • LeftHand > HandPresence
      • controller = quest2_controllers_div0
      • hand model = Left Hand Model
      • grip button - use reference = true
      • reference = XRI LeftHand interaction/ Select (??? last time we create custom input)
      • trigger button - use reference = true
      • reference = XRI LeftHand interaction/ Activate
    • LeftHand = Prefab; delete from scene
    • ———–
    • duplicate LeftHand prefab as RightHand
    • remove “Left Hand model”
    • [add] Oculus Hands\Prefabs\Right Hand, pos=0,0,0, rot=0,0,-120
    • assign handMaterial (optional)
    • assign controller material
    • RightHand > HandPresence
      • controller = quest2_controllers_div0
      • hand model = Right Hand Model
      • grip reference = XRI RightHand interaction/ Select
      • trigger reference = XRI RightHand interaction / activate
    • ————
    • Back to Scene
    • LeftHand Direct Controller > XR controller
      • model prefab = LeftHand prefab
    • RightHand Direct controller > XR controller
      • model prefab = RightHand prefab

Hand animation

  • select hand prefab, right click
  • [create] animation controller for right hand
    • [add] parameter float: Grip + Trigger
    • create state > from New Blend Tree, double click to edit
      • blend type= 2D freeform cartesian
      • parameter = grip + trigger
      • + x 4 = 4 motion fields, 00, 01,10,11
      • go Oculus Hands / animations
        • R_hand_default_anim, r_hand_pinch_anim, r_hand_fist_anim, r_hand_fist_anim
        • expand to see the triangle icon, and drag to the Blend Tree
  • [duplicate] right hand animation controller as LeftHandAnimationController
    • swap the blend tree animation
  • ——
  • inside “LeftHand” and “RightHand” prefab
    • select “Left Hand Model” and “Right Hand Model”
    • assign the animation controller accordingly
  • ——
  • go Sample »> Starter Assets - XRI Default Input Action
    • edit button to open
    • XRI RightHand > Actions > +
      • Grip (type = value; type=axis;
      • binding.path = XR controller \ XR controller (Right Hand) \ optional controls \ grip)
      • generic XR controller = true
    • XRI RightHand > Actions > +
      • Trigger (type = value; type = axis)
      • binding.path = XR Controller\XR Controller (Right Hand)\Optional Controls\trigger
      • generic XR controller = true
    • same Grip + Trigger for XRI Left Hand
    • click “save asset button”
    • ~~~~~~~
    • RightHand/LeftHand Prefab > HandPresence
      • update reference of Grip and Trigger

Teleport reticle

  • [drag] [custom Teleport folder] in
  • create “TeleportMat” with AlphaRamp (unlit/alpha ramp)
  • [Teleport] teleportHightLight : scale factor = 0.01; (apply)
  • [add] teleportHightLight to scene, scale = 0.5,1,0.5
  • assign TeleportMaterial
  • make it prefab = original prefab; remove from scene
  • name as TeleportReticle

Teleport Anchor

  • create cylinder, scale 1,0.1,1
  • remove collider
  • add mesh collider (convex = true)
  • [layer] = Teleport
  • [add] [teleportation] TeleportationBlinkAnchor.cs
  • [add as child] TeleportReticle (scale=0.5,5,0.5) under cylinder
  • teleportationBlinkAncor: onFirstHoverEnter:
    • teleport reticle: active = true
  • teleportationBlinkAncor: onLastHoverEnter:
    • teleport reticle: active = false
  • hide teleport reticle

Teleport Area

  • add floor
  • [add] [teleporation] TeleportationBlinkArea.cs
    • custom reticle = teleportReticle prefab
    • teleport provider = locomotion system
  • floor [layer] = Teleport

Grabbable

  • add cube
  • [layer] = “Grab”
  • add collider
  • add rigidbody
  • [add] XR Grab Interactable
    • or XROffsetGrabInteractable.cs (assign attach transform)
    • move type=velocity

Highlighting for grabable

  • [custom: outlinedDiffuse ]create highlightMaterial (outlined/diffuse) with main color + outliner color + optional texture
  • assign that material to object to highlight
  • assign [custom] Highligher.cs to object to highlight
  • [drag] itself to both interactor and mesh render

Socket for grabbable

  • ceate empty game object
  • add sphere collider (is trigger = true)
  • add “XR Socket interactor”
    • [add] new SocketMaterial (transparent, green alpha 150, smooth 0)
    • to Hover Mesh Material
    • (optional) attach point
    • (optional) put a vis sphere under it

other tag socket

  • ??? (wip)

UI

  • [add]XR > UI Canvas (not the UI one) as XRUICanvas
  • scale = .002, .002, .002
  • add RAWImage alpha 0 to show ray
  • add rest text mesh pro ui
  • set canvas and all children [layer] = UI

BigButton

  • create base
  • create top (+rigidbody = is kinematic)
  • [add] [custom: things] HandButton.cs

Leveler

  • [layer] = grab
  • add collider
  • add rigidbody; gavity = false
  • [add] XR Grab interactor
    • move type = velocity tracking
  • [add] Hinge joint
    • use visualizer to set Anchor (if pivot is correct, should be 000) and Axis
    • use limit = true
    • use spring = true (damper = 1, spring=1)

Finalize

  • create light > Light Probes Group
  • optional blob shadow for character and dynamic objects
  • unmoveable object set = static
  • Bake lightmaps: window > Rendering > Light setting > Generate lighting
  • build
  • devwiki/vr.txt
  • Last modified: 2022/07/02 03:57
  • by ying