Skip to content

Commit 7c60d73

Browse files
committed
Version 1.9.1,
1 parent 1763883 commit 7c60d73

File tree

7 files changed

+50
-35
lines changed

7 files changed

+50
-35
lines changed

Runtime/Const/KinetixConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Kinetix.Internal
88
{
99
public static class KinetixConstants
1010
{
11-
public const string version = "1.8.1";
11+
public const string version = "1.9.1";
1212
public static bool C_ShouldUGCBeAvailable = true;
1313

1414
#if STAGING_KINETIX

Runtime/Operations/OperationRetargetEmote/EmoteRetargeting.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public EmoteRetargeting(EmoteRetargetingConfig _Config): base(_Config) {}
1313

1414
public override async Task Execute()
1515
{
16-
KinetixLogger.LogDebug("HELP," + Config.Emote.Ids.UUID, "EmoteRetargeting." + nameof(Execute) + " - 16", false);
17-
1816
if (CancellationTokenSource.IsCancellationRequested || Config.CancellationSequencer.canceled)
1917
{
2018
CurrentTaskCompletionSource.TrySetCanceled();

Samples~/IK_ContainmentZone/ARaycastObject.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Linq;
33
using UnityEngine;
44

5-
public abstract class ARaycastObject : MonoBehaviour
5+
public abstract class ARaycastObject : MonoBehaviour
66
{
77
/// <summary>
88
/// Max default raycast distance
@@ -59,6 +59,7 @@ public bool Raycast(Vector3 startPosition, Quaternion rotation, Vector3 directio
5959
return true;
6060

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

80-
protected bool WhereColliderFilter(RaycastHit raycastHit) => !ignoreColliders.Contains(raycastHit.collider.gameObject);
81+
82+
83+
private bool DistanceSecurity(RaycastHit hit)
84+
{
85+
return hit.distance > Mathf.Epsilon;
86+
}
87+
88+
protected bool WhereColliderFilter(RaycastHit raycastHit) => DistanceSecurity(raycastHit) && !ignoreColliders.Contains(raycastHit.collider.gameObject);
8189
protected bool WhereColliderFilter(Collider collider) => !ignoreColliders.Contains(collider.gameObject);
82-
90+
8391
protected Func<Collider, bool> WhereHasSpecificCollider(Collider colliderToFind)
8492
{
8593
return Where;
86-
bool Where (Collider other)
94+
bool Where(Collider other)
8795
{
8896
return other == colliderToFind;
8997
}
9098
}
9199
protected Func<RaycastHit, bool> WhereHasSpecificColliderRaycast(Collider colliderToFind)
92100
{
93101
return Where;
94-
bool Where(RaycastHit other)
102+
bool Where(RaycastHit raycastHit)
95103
{
96-
return other.collider == colliderToFind;
104+
return DistanceSecurity(raycastHit) && raycastHit.collider == colliderToFind;
97105
}
98106
}
99107
}

Samples~/IK_ContainmentZone/IK_ContainmentZone.cs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Kinetix;
22
using System;
3+
using System.Linq;
34
using System.Collections;
45
using TMPro;
56
using UnityEngine;
@@ -37,7 +38,7 @@ private void Awake()
3738
gizmo = GetComponent<GizmoUtils>() ?? gameObject.AddComponent<GizmoUtils>();
3839
}
3940

40-
public void OnValidateGameApiKey()
41+
public void OnValidateGameApiKey()
4142
{
4243
// Initialization is an async process,
4344
// We use a callback to tell when it's finished
@@ -88,9 +89,9 @@ public void OpenUGELink()
8889

8990
stepDisplayController.NextStep();
9091

91-
if (routine != null)
92+
if (routine != null)
9293
StopCoroutine(routine);
93-
94+
9495
routine = StartCoroutine(FetchEmotesAtInterval());
9596
});
9697
}
@@ -131,7 +132,7 @@ public void AssignEmoteToButton(AnimationMetadata _Metadata)
131132
KinetixCore.Metadata.LoadIconByAnimationId(_Metadata.Ids.UUID, (_Sprite) => {
132133
animationIcon.sprite = _Sprite;
133134
animationName.text = _Metadata.Name;
134-
animationID = _Metadata.Ids.UUID;
135+
animationID = _Metadata.Ids.UUID;
135136
});
136137
}
137138

@@ -151,23 +152,23 @@ private void OnBeforeIK(IKInfo currentPose)
151152
Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperLeg.globalPosition, Color.gray);
152153
Debug.DrawLine(currentPose.leftUpperLeg.globalPosition, currentPose.leftLowerLeg.globalPosition, Color.gray);
153154
Debug.DrawLine(currentPose.leftLowerLeg.globalPosition, currentPose.leftFoot.globalPosition, Color.gray);
154-
155+
155156
Debug.DrawLine(currentPose.hips.globalPosition, currentPose.leftUpperArm.globalPosition, Color.gray);
156157
Debug.DrawLine(currentPose.leftUpperArm.globalPosition, currentPose.leftLowerArm.globalPosition, Color.gray);
157158
Debug.DrawLine(currentPose.leftLowerArm.globalPosition, currentPose.leftHand.globalPosition, Color.gray);
158-
159+
159160
Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperLeg.globalPosition, Color.gray);
160161
Debug.DrawLine(currentPose.rightUpperLeg.globalPosition, currentPose.rightLowerLeg.globalPosition, Color.gray);
161162
Debug.DrawLine(currentPose.rightLowerLeg.globalPosition, currentPose.rightFoot.globalPosition, Color.gray);
162-
163+
163164
Debug.DrawLine(currentPose.hips.globalPosition, currentPose.rightUpperArm.globalPosition, Color.gray);
164165
Debug.DrawLine(currentPose.rightUpperArm.globalPosition, currentPose.rightLowerArm.globalPosition, Color.gray);
165166
Debug.DrawLine(currentPose.rightLowerArm.globalPosition, currentPose.rightHand.globalPosition, Color.gray);
166167
#endregion
167168

168169
ApplyIK(currentPose, leftHandCollider, currentPose.leftHand, currentPose.leftLowerArm, AvatarIKGoal.LeftHand, AvatarIKHint.LeftElbow);
169170
ApplyIK(currentPose, leftFootCollider, currentPose.leftFoot, currentPose.leftLowerLeg, AvatarIKGoal.LeftFoot, AvatarIKHint.LeftKnee);
170-
171+
171172
ApplyIK(currentPose, rightHandCollider, currentPose.rightHand, currentPose.rightLowerArm, AvatarIKGoal.RightHand, AvatarIKHint.RightElbow);
172173
ApplyIK(currentPose, rightFootCollider, currentPose.rightFoot, currentPose.rightLowerLeg, AvatarIKGoal.RightFoot, AvatarIKHint.RightKnee);
173174
}
@@ -179,15 +180,15 @@ private void OnBeforeIK(IKInfo currentPose)
179180
private void ApplyIK(IKInfo currentPose, ARaycastObject raycast, IKTransformInfo transformGoal, IKTransformInfo transformHint, AvatarIKGoal goal, AvatarIKHint hint)
180181
{
181182
bool isFoot = goal.ToString().EndsWith("Foot");
182-
183+
183184
//Check collision for goals (hands / foot)
184185
PhysicCast(currentPose, raycast, transformGoal, transformHint, (v) =>
185186
{
186187
if (v != null)
187188
{
188189
KinetixCore.Animation.SetIKPositionAndWeightOnLocalPlayer(goal, v.Value, 1);
189190
KinetixCore.Animation.SetIKHintPositionOnLocalPlayer(hint, transformGoal.globalPosition + (transformHint.globalPosition - transformGoal.globalPosition) * 2);
190-
191+
191192
if (isFoot)
192193
KinetixCore.Animation.SetIKRotationAndWeightOnLocalPlayer(goal, transformGoal.globalRotation, 1);
193194

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

236237
//Check for colliders
237-
Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask);
238+
Collider[] colliders = raycast.Overlap(transformGoal.globalPosition, transformGoal.globalRotation, overlapLayerMask).Distinct().ToArray();
238239
int collidersLenght = colliders.Length;
239240

240241
bool defaultQuery = Physics.queriesHitBackfaces; //We need to restore physics after we're done computing the physic
@@ -246,39 +247,45 @@ Green line (near yellow sphere) : Previous position to corrected position
246247
Vector3 hipsToGoal = transformGoal.globalPosition - currentPose.hips.globalPosition;
247248
//Compute hint -> goal (+offset)
248249
Vector3 fromHintToGoal = (transformGoal.globalPosition + offset) - transformHint.globalPosition;
249-
250+
250251
//If an overlap has been detected
251252
if (collidersLenght > 0)
252253
{
253-
Physics.queriesHitBackfaces = true; //enable back faces
254+
Physics.queriesHitBackfaces = false; //disable back faces
254255

255256
Vector3 point, fromTo, hitPosition, hitNormal;
256257
Vector3 moveDirection = Vector3.zero;//To be computed
257258
for (int i = collidersLenght - 1; i >= 0; i--)
258259
{
259260
Collider collider = colliders[i];
260-
point = collider.ClosestPointOnBounds(transformGoal.globalPosition);
261-
fromTo = point - transformGoal.globalPosition;
261+
bool colliderIsSelf = collider.GetComponentInParent<Animator>() == myAnimator;
262+
263+
Vector3 rayOrigin = colliderIsSelf ? transformGoal.globalPosition : currentPose.hips.globalPosition;
264+
265+
point = collider.ClosestPointOnBounds(transformGoal.globalPosition + offset);
266+
fromTo = point - rayOrigin;
262267

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

273+
if (fromTo == Vector3.zero) //Security
274+
fromTo = offset;
275+
269276
#region GIZMO
270277
//Nearest point on collider's bounding box
271-
Debug.DrawLine(transformGoal.globalPosition, point, new Color(1, 0, 0, 0.2f));
278+
Debug.DrawLine(transformGoal.globalPosition + offset, point, new Color(1, 0, 0, 0.2f));
272279
gizmo.Color(GIZMO_COLOR_HIT);
273280
gizmo.DrawSphere(point, 0.005f);
274281

275282
//Raycast
276-
Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white);
277-
Debug.DrawRay(offset + transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta);
283+
Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET), Color.white);
284+
Debug.DrawRay(offset + rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, fromTo.normalized * (fromTo.magnitude + RAY_COLISION_OFFSET) * 0.2f, Color.magenta);
278285
#endregion
279286

280287
//Do a raycast to get the actual position of the hit
281-
if (!raycast.Raycast(transformGoal.globalPosition - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider))
288+
if (!raycast.Raycast(rayOrigin - fromTo.normalized * RAY_COLISION_OFFSET, transformGoal.globalRotation, fromTo, overlapLayerMask, out RaycastHit hit, fromTo.magnitude + RAY_COLISION_OFFSET, collider))
282289
{
283290
--collidersLenght;
284291
continue;
@@ -297,7 +304,7 @@ Green line (near yellow sphere) : Previous position to corrected position
297304
//Add a 'velocity' to correct the position in the direction of the normal
298305
Vector3 moveVelocity = Vector3.Dot(hitNormal, hitPosition - pointOnCollider) * hitNormal;
299306
moveDirection += moveVelocity;
300-
307+
301308
#region GIZMO
302309
//Normal
303310
gizmo.Color(Color.cyan);
@@ -316,7 +323,7 @@ Green line (near yellow sphere) : Previous position to corrected position
316323
if (collidersLenght > 0)
317324
{
318325
toReturn = transformGoal.globalPosition + moveDirection;
319-
326+
320327
//Reset color to "color hit" (for the raycastObject's gizmo)
321328
gizmo.Color(GIZMO_COLOR_HIT);
322329
}
@@ -329,7 +336,7 @@ Green line (near yellow sphere) : Previous position to corrected position
329336
{
330337
//Draw the raycast
331338
Debug.DrawRay(transformHint.globalPosition - fromHintToGoal, fromHintToGoal * 2, Color.blue);
332-
339+
333340
//Init some variables
334341
Vector3 hitPosition = hit.point;
335342
Vector3 hitNormal = hit.normal;
@@ -347,7 +354,7 @@ Green line (near yellow sphere) : Previous position to corrected position
347354
//Point on collider
348355
gizmo.Color(Color.green);
349356
gizmo.DrawSphere(pointOnCollider, 0.01f);
350-
357+
351358
//Hit
352359
gizmo.Color(GIZMO_COLOR_HIT);
353360
gizmo.DrawSphere(hitPosition, 0.01f);

Samples~/IK_ContainmentZone/RaycastBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override void DrawGizmo(Vector3 startPosition, Quaternion rotation)
4040

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

Samples~/Validation_Retake/Scripts/ValidationDemoImplementation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ private void RefreshProcessList(SdkApiProcess[] _Processes)
6767
KinetixCore.Metadata.GetAnimationMetadataByAnimationIds(apiProcess.Emote.ToString(), (_AnimationMetadata) => {
6868
StopCoroutine(processCoroutine);
6969

70+
AssignEmoteToButton(_AnimationMetadata);
71+
7072
stepDisplayController.NextStep();
7173
});
7274
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.kinetix.coreweb2",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"displayName": "Kinetix Core",
55
"description": "Kinetix Core SDK",
66
"samples": [

0 commit comments

Comments
 (0)