Skip to content

Version 1.9.1, #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Runtime/Const/KinetixConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Kinetix.Internal
{
public static class KinetixConstants
{
public const string version = "1.8.1";
public const string version = "1.9.1";
public static bool C_ShouldUGCBeAvailable = true;

#if STAGING_KINETIX
Expand Down
2 changes: 0 additions & 2 deletions Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public EmoteRetargeting(EmoteRetargetingConfig _Config): base(_Config) {}

public override async Task Execute()
{
KinetixLogger.LogDebug("HELP," + Config.Emote.Ids.UUID, "EmoteRetargeting." + nameof(Execute) + " - 16", false);

if (CancellationTokenSource.IsCancellationRequested || Config.CancellationSequencer.canceled)
{
CurrentTaskCompletionSource.TrySetCanceled();
Expand Down
20 changes: 14 additions & 6 deletions Samples~/IK_ContainmentZone/ARaycastObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using UnityEngine;

public abstract class ARaycastObject : MonoBehaviour
public abstract class ARaycastObject : MonoBehaviour
{
/// <summary>
/// Max default raycast distance
Expand Down Expand Up @@ -59,6 +59,7 @@ public bool Raycast(Vector3 startPosition, Quaternion rotation, Vector3 directio
return true;

}

abstract public RaycastHit[] Raycast(Vector3 startPosition, Quaternion rotation, Vector3 direction, int layerMask, float distance = RAYCAST_DISTANCE);
/// <summary>
/// Get the farthest point (in global context) along the requested direction
Expand All @@ -77,23 +78,30 @@ public bool Raycast(Vector3 startPosition, Quaternion rotation, Vector3 directio
/// <param name="rotation">Global rotation of the transform</param>
public abstract void DrawGizmo(Vector3 startPosition, Quaternion rotation);

protected bool WhereColliderFilter(RaycastHit raycastHit) => !ignoreColliders.Contains(raycastHit.collider.gameObject);


private bool DistanceSecurity(RaycastHit hit)
{
return hit.distance > Mathf.Epsilon;
}

protected bool WhereColliderFilter(RaycastHit raycastHit) => DistanceSecurity(raycastHit) && !ignoreColliders.Contains(raycastHit.collider.gameObject);
protected bool WhereColliderFilter(Collider collider) => !ignoreColliders.Contains(collider.gameObject);

protected Func<Collider, bool> WhereHasSpecificCollider(Collider colliderToFind)
{
return Where;
bool Where (Collider other)
bool Where(Collider other)
{
return other == colliderToFind;
}
}
protected Func<RaycastHit, bool> WhereHasSpecificColliderRaycast(Collider colliderToFind)
{
return Where;
bool Where(RaycastHit other)
bool Where(RaycastHit raycastHit)
{
return other.collider == colliderToFind;
return DistanceSecurity(raycastHit) && raycastHit.collider == colliderToFind;
}
}
}
55 changes: 31 additions & 24 deletions Samples~/IK_ContainmentZone/IK_ContainmentZone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Kinetix;
using System;
using System.Linq;
using System.Collections;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -37,7 +38,7 @@ private void Awake()
gizmo = GetComponent<GizmoUtils>() ?? gameObject.AddComponent<GizmoUtils>();
}

public void OnValidateGameApiKey()
public void OnValidateGameApiKey()
{
// Initialization is an async process,
// We use a callback to tell when it's finished
Expand Down Expand Up @@ -88,9 +89,9 @@ public void OpenUGELink()

stepDisplayController.NextStep();

if (routine != null)
if (routine != null)
StopCoroutine(routine);

routine = StartCoroutine(FetchEmotesAtInterval());
});
}
Expand Down Expand Up @@ -131,7 +132,7 @@ public void AssignEmoteToButton(AnimationMetadata _Metadata)
KinetixCore.Metadata.LoadIconByAnimationId(_Metadata.Ids.UUID, (_Sprite) => {
animationIcon.sprite = _Sprite;
animationName.text = _Metadata.Name;
animationID = _Metadata.Ids.UUID;
animationID = _Metadata.Ids.UUID;
});
}

Expand All @@ -151,23 +152,23 @@ private void OnBeforeIK(IKInfo currentPose)
Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperLeg.globalPosition, Color.gray);
Debug.DrawLine(currentPose.leftUpperLeg.globalPosition, currentPose.leftLowerLeg.globalPosition, Color.gray);
Debug.DrawLine(currentPose.leftLowerLeg.globalPosition, currentPose.leftFoot.globalPosition, Color.gray);

Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperArm.globalPosition, Color.gray);
Debug.DrawLine(currentPose.leftUpperArm.globalPosition, currentPose.leftLowerArm.globalPosition, Color.gray);
Debug.DrawLine(currentPose.leftLowerArm.globalPosition, currentPose.leftHand.globalPosition, Color.gray);

Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperLeg.globalPosition, Color.gray);
Debug.DrawLine(currentPose.rightUpperLeg.globalPosition, currentPose.rightLowerLeg.globalPosition, Color.gray);
Debug.DrawLine(currentPose.rightLowerLeg.globalPosition, currentPose.rightFoot.globalPosition, Color.gray);

Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperArm.globalPosition, Color.gray);
Debug.DrawLine(currentPose.rightUpperArm.globalPosition, currentPose.rightLowerArm.globalPosition, Color.gray);
Debug.DrawLine(currentPose.rightLowerArm.globalPosition, currentPose.rightHand.globalPosition, Color.gray);
#endregion

ApplyIK(currentPose, leftHandCollider, currentPose.leftHand, currentPose.leftLowerArm, AvatarIKGoal.LeftHand, AvatarIKHint.LeftElbow);
ApplyIK(currentPose, leftFootCollider, currentPose.leftFoot, currentPose.leftLowerLeg, AvatarIKGoal.LeftFoot, AvatarIKHint.LeftKnee);

ApplyIK(currentPose, rightHandCollider, currentPose.rightHand, currentPose.rightLowerArm, AvatarIKGoal.RightHand, AvatarIKHint.RightElbow);
ApplyIK(currentPose, rightFootCollider, currentPose.rightFoot, currentPose.rightLowerLeg, AvatarIKGoal.RightFoot, AvatarIKHint.RightKnee);
}
Expand All @@ -179,15 +180,15 @@ private void OnBeforeIK(IKInfo currentPose)
private void ApplyIK(IKInfo currentPose, ARaycastObject raycast, IKTransformInfo transformGoal, IKTransformInfo transformHint, AvatarIKGoal goal, AvatarIKHint hint)
{
bool isFoot = goal.ToString().EndsWith("Foot");

//Check collision for goals (hands / foot)
PhysicCast(currentPose, raycast, transformGoal, transformHint, (v) =>
{
if (v != null)
{
KinetixCore.Animation.SetIKPositionAndWeightOnLocalPlayer(goal, v.Value, 1);
KinetixCore.Animation.SetIKHintPositionOnLocalPlayer(hint, transformGoal.globalPosition + (transformHint.globalPosition - transformGoal.globalPosition) * 2);

if (isFoot)
KinetixCore.Animation.SetIKRotationAndWeightOnLocalPlayer(goal, transformGoal.globalRotation, 1);

Expand Down Expand Up @@ -234,7 +235,7 @@ Green line (near yellow sphere) : Previous position to corrected position
gizmo.Color(GIZMO_COLOR);

//Check for colliders
Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask);
Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask).Distinct().ToArray();
int collidersLenght = colliders.Length;

bool defaultQuery = Physics.queriesHitBackfaces; //We need to restore physics after we're done computing the physic
Expand All @@ -246,39 +247,45 @@ Green line (near yellow sphere) : Previous position to corrected position
Vector3 hipsToGoal = transformGoal.globalPosition - currentPose.hips.globalPosition;
//Compute hint -> goal (+offset)
Vector3 fromHintToGoal = (transformGoal.globalPosition + offset) - transformHint.globalPosition;

//If an overlap has been detected
if (collidersLenght > 0)
{
Physics.queriesHitBackfaces = true; //enable back faces
Physics.queriesHitBackfaces = false; //disable back faces

Vector3 point, fromTo, hitPosition, hitNormal;
Vector3 moveDirection = Vector3.zero;//To be computed
for (int i = collidersLenght - 1; i >= 0; i--)
{
Collider collider = colliders[i];
point = collider.ClosestPointOnBounds(transformGoal.globalPosition);
fromTo = point - transformGoal.globalPosition;
bool colliderIsSelf = collider.GetComponentInParent<Animator>() == myAnimator;

Vector3 rayOrigin = colliderIsSelf ? transformGoal.globalPosition : currentPose.hips.globalPosition;

point = collider.ClosestPointOnBounds(transformGoal.globalPosition + offset);
fromTo = point - rayOrigin;

//If it's not interpenetrating, make the raycast point in the direction of the leg/arm.
//This is to fix backface normal that are on the opposite side
bool colliderIsSelf = collider.GetComponentInParent<Animator>() == myAnimator;
if (!colliderIsSelf)
fromTo *= Mathf.Sign(Vector3.Dot(hipsToGoal, fromTo));

if (fromTo == Vector3.zero) //Security
fromTo = offset;

#region GIZMO
//Nearest point on collider's bounding box
Debug.DrawLine(transformGoal.globalPosition, point, new Color(1, 0, 0, 0.2f));
Debug.DrawLine(transformGoal.globalPosition + offset, point, new Color(1, 0, 0, 0.2f));
gizmo.Color(GIZMO_COLOR_HIT);
gizmo.DrawSphere(point, 0.005f);

//Raycast
Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white);
Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta);
Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white);
Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta);
#endregion

//Do a raycast to get the actual position of the hit
if (!raycast.Raycast(transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider))
if (!raycast.Raycast(rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider))
{
--collidersLenght;
continue;
Expand All @@ -297,7 +304,7 @@ Green line (near yellow sphere) : Previous position to corrected position
//Add a 'velocity' to correct the position in the direction of the normal
Vector3 moveVelocity = Vector3.Dot(hitNormal, hitPosition - pointOnCollider) * hitNormal;
moveDirection += moveVelocity;

#region GIZMO
//Normal
gizmo.Color(Color.cyan);
Expand All @@ -316,7 +323,7 @@ Green line (near yellow sphere) : Previous position to corrected position
if (collidersLenght > 0)
{
toReturn = transformGoal.globalPosition + moveDirection;

//Reset color to "color hit" (for the raycastObject's gizmo)
gizmo.Color(GIZMO_COLOR_HIT);
}
Expand All @@ -329,7 +336,7 @@ Green line (near yellow sphere) : Previous position to corrected position
{
//Draw the raycast
Debug.DrawRay(transformHint.globalPosition - fromHintToGoal, fromHintToGoal * 2, Color.blue);

//Init some variables
Vector3 hitPosition = hit.point;
Vector3 hitNormal = hit.normal;
Expand All @@ -347,7 +354,7 @@ Green line (near yellow sphere) : Previous position to corrected position
//Point on collider
gizmo.Color(Color.green);
gizmo.DrawSphere(pointOnCollider, 0.01f);

//Hit
gizmo.Color(GIZMO_COLOR_HIT);
gizmo.DrawSphere(hitPosition, 0.01f);
Expand Down
2 changes: 1 addition & 1 deletion Samples~/IK_ContainmentZone/RaycastBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void DrawGizmo(Vector3 startPosition, Quaternion rotation)

public override Collider[] Overlap(Vector3 startPosition, Quaternion rotation, int layerMask)
{
return Physics.OverlapBox(startPosition + rotation * offset, size/2, rotation)
return Physics.OverlapBox(startPosition + rotation * offset, size/2, rotation, layerMask)
.Where(WhereColliderFilter).ToArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private void RefreshProcessList(SdkApiProcess[] _Processes)
KinetixCore.Metadata.GetAnimationMetadataByAnimationIds(apiProcess.Emote.ToString(), (_AnimationMetadata) => {
StopCoroutine(processCoroutine);

AssignEmoteToButton(_AnimationMetadata);

stepDisplayController.NextStep();
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.kinetix.coreweb2",
"version": "1.9.0",
"version": "1.9.1",
"displayName": "Kinetix Core",
"description": "Kinetix Core SDK",
"samples": [
Expand Down
Loading