For putting on a clone of the head bone and using it as an IK target in VRIK.

This commit is contained in:
Emiliana 2020-02-08 23:41:56 +01:00
parent 4fa2471b9c
commit 0e38bb035f
2 changed files with 57 additions and 0 deletions

46
Unity/OpenSeeIKTarget.cs Normal file
View file

@ -0,0 +1,46 @@
using UnityEngine;
public class OpenSeeIKTarget : MonoBehaviour
{
public OpenSee.OpenSee openSee;
public bool calibrate = true;
public int faceId = 0;
public float translationScale = 0.3f;
public float smooth = 0.2f;
double updated = 0.0f;
Quaternion dR;
Vector3 dT;
void Update()
{
var openSeeData = openSee.trackingData;
if (openSeeData == null || openSeeData.Length < 1)
return;
int idx = -1;
int i = 0;
foreach (var item in openSeeData) {
if (item.id == faceId)
idx = i;
i++;
}
if (idx < 0)
return;
if (openSeeData[idx].time > updated) {
updated = openSeeData[idx].time;
} else {
return;
}
if (calibrate) {
calibrate = false;
dR = Quaternion.Euler(-openSeeData[idx].rotation.x, openSeeData[idx].rotation.y, -openSeeData[0].rotation.z);
dR = Quaternion.Inverse(dR);
dT = openSeeData[idx].translation;
}
Vector3 v = openSeeData[idx].translation - dT;
v.z = -v.z;
transform.localPosition = Vector3.Lerp(transform.localPosition, v * translationScale, 1f - smooth);
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(-openSeeData[idx].rotation.x, openSeeData[idx].rotation.y, -openSeeData[idx].rotation.z) * dR, 1f - smooth);
}
}

View file

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