initial upload

This commit is contained in:
tom.hempel
2025-09-21 22:42:26 +02:00
commit d03bcd4ba5
6231 changed files with 351582 additions and 0 deletions

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9f8504c17081a0a44ac16c48a54aa8bb
folderAsset: yes
timeCreated: 1483525185
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using UnityEngine;
using System.Collections;
using RootMotion.FinalIK;
namespace RootMotion.Demos {
/// <summary>
/// Triggering Hit Reactions on mouse button.
/// </summary>
public class HitReactionVRIKTrigger: MonoBehaviour {
public HitReactionVRIK hitReaction;
public float hitForce = 1f;
private string colliderName;
void Update() {
// On left mouse button...
if (Input.GetMouseButtonDown(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Raycast to find a ragdoll collider
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 100f)) {
// Use the HitReaction
hitReaction.Hit(hit.collider, ray.direction * hitForce, hit.point);
// Just for GUI
colliderName = hit.collider.name;
}
}
}
void OnGUI() {
GUILayout.Label("LMB to shoot the Dummy, RMB to rotate the camera.");
if (colliderName != string.Empty) GUILayout.Label("Last Bone Hit: " + colliderName);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4306e26e5aa733b4884914d17211dac5
timeCreated: 1514033475
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,82 @@
using UnityEngine;
using RootMotion.FinalIK;
namespace RootMotion.Demos
{
// Moving the demo VR character controller.
public class VRController : MonoBehaviour
{
[System.Serializable]
public enum InputMode
{
Input = 0,
WASDOnly = 1,
}
public InputMode inputMode;
public VRIK ik;
public Transform centerEyeAnchor;
// Match these values to velocities in the locomotion animation blend tree for better looking results (avoids half-blends)
public float walkSpeed = 1f;
public float runSpeed = 3f;
public float walkForwardSpeedMlp = 1f;
public float runForwardSpeedMlp = 1f;
private Vector3 smoothInput, smoothInputV;
private void Update()
{
// Get input
Vector3 input = GetInput();
input *= ik.solver.scale;
float fDot = Vector3.Dot(input, Vector3.forward);
bool f = fDot > 0f;
// Locomotion speed
float s = walkSpeed;
if (Input.GetKey(KeyCode.LeftShift))
{
s = runSpeed;
if (f) s *= runForwardSpeedMlp; // Walk faster/slower when moving forward
} else
{
if (f) s *= walkForwardSpeedMlp; // Run faster/slower when moving forward
}
// Input smoothing
smoothInput = Vector3.SmoothDamp(smoothInput, input * s, ref smoothInputV, 0.1f);
// Rotate input to avatar space
Vector3 forward = centerEyeAnchor.forward;
forward.y = 0f;
Quaternion avatarSpace = Quaternion.LookRotation(forward);
// Apply
transform.position += avatarSpace * smoothInput * Time.deltaTime;
}
// Returns keyboard/thumbstick input vector
private Vector3 GetInput()
{
switch (inputMode)
{
case InputMode.Input:
Vector3 v = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
if (v.sqrMagnitude < 0.3f) return Vector3.zero;
return v.normalized;
case InputMode.WASDOnly:
Vector3 input = Vector3.zero;
if (Input.GetKey(KeyCode.W)) input += Vector3.forward;
if (Input.GetKey(KeyCode.S)) input += Vector3.back;
if (Input.GetKey(KeyCode.A)) input += Vector3.left;
if (Input.GetKey(KeyCode.D)) input += Vector3.right;
return input.normalized;
default: return Vector3.zero;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 477067c91bad4404790bb7ed5ce59601
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,47 @@
using UnityEngine;
using RootMotion.FinalIK;
namespace RootMotion.Demos
{
/// <summary>
/// Makes VRIK work with elbow targets at a cost of reduced hand accuracy.
/// </summary>
public class VRIKArmMocap : MonoBehaviour
{
public VRIK ik;
public Transform leftElbowTarget;
public Transform rightElbowTarget;
void Start()
{
// Register to get a call from VRIK after it updates
ik.solver.OnPostUpdate += AfterVRIK;
}
void AfterVRIK()
{
// This is called by VRIK each time it is done updating for the frame
UpdateArm(ik.references.leftUpperArm, ik.references.leftForearm, ik.references.leftHand, leftElbowTarget, ik.solver.leftArm.target);
UpdateArm(ik.references.rightUpperArm, ik.references.rightForearm, ik.references.rightHand, rightElbowTarget, ik.solver.rightArm.target);
}
private static void UpdateArm(Transform upperArm, Transform forearm, Transform hand, Transform elbowTarget, Transform handTarget)
{
if (elbowTarget == null) return;
if (handTarget == null) return;
// Rotate the upper arm towards the elbow target.
upperArm.rotation = Quaternion.FromToRotation(forearm.position - upperArm.position, elbowTarget.position - upperArm.position) * upperArm.rotation;
// Rotate the forearm towards the hand target
forearm.rotation = Quaternion.FromToRotation(hand.position - forearm.position, handTarget.position - forearm.position) * forearm.rotation;
}
void OnDestroy()
{
// Clean up
if (ik != null) ik.solver.OnPostUpdate -= AfterVRIK;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6dd78a58cae96804baf3bbd2bd73caf1
timeCreated: 1542280405
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RootMotion.FinalIK;
namespace RootMotion.Demos
{
public class VRIKCalibrationBasic : MonoBehaviour
{
[Tooltip("The VRIK component.")] public VRIK ik;
[Header("Head")]
[Tooltip("HMD.")] public Transform centerEyeAnchor;
[Tooltip("Position offset of the camera from the head bone (root space).")] public Vector3 headAnchorPositionOffset;
[Tooltip("Rotation offset of the camera from the head bone (root space).")] public Vector3 headAnchorRotationOffset;
[Header("Hands")]
[Tooltip("Left Hand Controller")] public Transform leftHandAnchor;
[Tooltip("Right Hand Controller")] public Transform rightHandAnchor;
[Tooltip("Position offset of the hand controller from the hand bone (controller space).")] public Vector3 handAnchorPositionOffset;
[Tooltip("Rotation offset of the hand controller from the hand bone (controller space).")] public Vector3 handAnchorRotationOffset;
[Header("Scale")]
[Tooltip("Multiplies the scale of the root.")] public float scaleMlp = 1f;
[Header("Data stored by Calibration")]
public VRIKCalibrator.CalibrationData data = new VRIKCalibrator.CalibrationData();
private void LateUpdate()
{
if (Input.GetKeyDown(KeyCode.C))
{
// Calibrate the character, store data of the calibration
data = VRIKCalibrator.Calibrate(ik, centerEyeAnchor, leftHandAnchor, rightHandAnchor, headAnchorPositionOffset, headAnchorRotationOffset, handAnchorPositionOffset, handAnchorRotationOffset, scaleMlp);
}
/*
* calling Calibrate with settings will return a VRIKCalibrator.CalibrationData, which can be used to calibrate that same character again exactly the same in another scene (just pass data instead of settings),
* without being dependent on the pose of the player at calibration time.
* Calibration data still depends on bone orientations though, so the data is valid only for the character that it was calibrated to or characters with identical bone structures.
* If you wish to use more than one character, it would be best to calibrate them all at once and store the CalibrationData for each one.
* */
if (Input.GetKeyDown(KeyCode.D))
{
if (data.scale == 0f)
{
Debug.LogError("No Calibration Data to calibrate to, please calibrate with 'C' first.");
}
else
{
VRIKCalibrator.Calibrate(ik, data, centerEyeAnchor, null, leftHandAnchor, rightHandAnchor);
}
}
// Recalibrates avatar scale only. Can be called only if the avatar has been calibrated already.
if (Input.GetKeyDown(KeyCode.S))
{
if (data.scale == 0f)
{
Debug.LogError("Avatar needs to be calibrated before RecalibrateScale is called.");
}
VRIKCalibrator.RecalibrateScale(ik, data, scaleMlp);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1885d47f6086b6640ac7f1e1d1137642
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using UnityEngine;
using System.Collections;
using RootMotion.FinalIK;
namespace RootMotion.Demos
{
public class VRIKCalibrationController : MonoBehaviour
{
[Tooltip("Reference to the VRIK component on the avatar.")] public VRIK ik;
[Tooltip("The settings for VRIK calibration.")] public VRIKCalibrator.Settings settings;
[Tooltip("The HMD.")] public Transform headTracker;
[Tooltip("(Optional) A tracker placed anywhere on the body of the player, preferrably close to the pelvis, on the belt area.")] public Transform bodyTracker;
[Tooltip("(Optional) A tracker or hand controller device placed anywhere on or in the player's left hand.")] public Transform leftHandTracker;
[Tooltip("(Optional) A tracker or hand controller device placed anywhere on or in the player's right hand.")] public Transform rightHandTracker;
[Tooltip("(Optional) A tracker placed anywhere on the ankle or toes of the player's left leg.")] public Transform leftFootTracker;
[Tooltip("(Optional) A tracker placed anywhere on the ankle or toes of the player's right leg.")] public Transform rightFootTracker;
[Header("Data stored by Calibration")]
public VRIKCalibrator.CalibrationData data = new VRIKCalibrator.CalibrationData();
void LateUpdate()
{
if (Input.GetKeyDown(KeyCode.C))
{
// Calibrate the character, store data of the calibration
data = VRIKCalibrator.Calibrate(ik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
}
/*
* calling Calibrate with settings will return a VRIKCalibrator.CalibrationData, which can be used to calibrate that same character again exactly the same in another scene (just pass data instead of settings),
* without being dependent on the pose of the player at calibration time.
* Calibration data still depends on bone orientations though, so the data is valid only for the character that it was calibrated to or characters with identical bone structures.
* If you wish to use more than one character, it would be best to calibrate them all at once and store the CalibrationData for each one.
* */
if (Input.GetKeyDown(KeyCode.D))
{
if (data.scale == 0f)
{
Debug.LogError("No Calibration Data to calibrate to, please calibrate with settings first.");
}
else
{
// Use data from a previous calibration to calibrate that same character again.
VRIKCalibrator.Calibrate(ik, data, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
}
}
// Recalibrates avatar scale only. Can be called only if the avatar has been calibrated already.
if (Input.GetKeyDown(KeyCode.S))
{
if (data.scale == 0f)
{
Debug.LogError("Avatar needs to be calibrated before RecalibrateScale is called.");
}
VRIKCalibrator.RecalibrateScale(ik, data, settings);
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4513e09e0185b9749bc91a9d562d73ff
timeCreated: 1499778808
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
using UnityEngine;
using System.Collections;
using RootMotion.FinalIK;
namespace RootMotion.Demos {
public class VRIKPlatform : MonoBehaviour {
public VRIK ik;
private Vector3 lastPosition;
private Quaternion lastRotation = Quaternion.identity;
void OnEnable() {
lastPosition = transform.position;
lastRotation = transform.rotation;
}
void LateUpdate () {
// Adding the motion of this Transform to VRIK
ik.solver.AddPlatformMotion (transform.position - lastPosition, transform.rotation * Quaternion.Inverse(lastRotation), transform.position);
lastRotation = transform.rotation;
lastPosition = transform.position;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0a74728623a249645880c78a0ec69030
timeCreated: 1476949826
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,58 @@
using UnityEngine;
using System.Collections;
using RootMotion.FinalIK;
namespace RootMotion.Demos
{
public class VRIKPlatformController : MonoBehaviour
{
public VRIK ik;
public Transform trackingSpace;
public Transform platform;
public bool moveToPlatform = true;
private Transform lastPlatform;
private Vector3 lastPosition;
private Quaternion lastRotation = Quaternion.identity;
void LateUpdate()
{
if (platform != lastPlatform)
{
if (platform != null)
{
// Moves the character to the position/rotation of the new platform
if (moveToPlatform)
{
lastPosition = ik.transform.position;
lastRotation = ik.transform.rotation;
ik.transform.position = platform.position;
ik.transform.rotation = platform.rotation;
trackingSpace.position = platform.position;
trackingSpace.rotation = platform.rotation;
ik.solver.AddPlatformMotion(platform.position - lastPosition, platform.rotation * Quaternion.Inverse(lastRotation), platform.position);
}
lastPosition = platform.position;
lastRotation = platform.rotation;
}
ik.transform.parent = platform;
trackingSpace.parent = platform;
lastPlatform = platform;
}
if (platform != null)
{
// Adding the motion of this Transform to VRIK
ik.solver.AddPlatformMotion(platform.position - lastPosition, platform.rotation * Quaternion.Inverse(lastRotation), platform.position);
lastRotation = platform.rotation;
lastPosition = platform.position;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf54ecb66e03c1c44873ff9fc6922213
timeCreated: 1530269426
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20e7a82a9c260894cab875fd831bd5a7
timeCreated: 1512734385
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 514dd711a487d2d47a1f009108e1c04a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 79f672ccc196fa143882bcb5e333cdcf
timeCreated: 1475148932
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e3b3977f14c1e92489be1774a9df3113
timeCreated: 1499777558
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61eee84f62d48a04bb3fdf1427bce05f
timeCreated: 1485861210
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fffb16a3dd355504f8eba21f3b455737
timeCreated: 1514033411
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 33de6a5fcc199c045b748ef01d1fd174
timeCreated: 1530270222
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dc412329386244249a719a00b7632e14
timeCreated: 1476949872
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f667b39ffe0bdfd4b948ee5001b31562
timeCreated: 1476688159
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fff4c7d58b7625d4a8aa18aa0081d80b
timeCreated: 1542280112
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant: