TransformExtensions.AbsoluteMaxValue

This commit is contained in:
ousttrue 2024-10-07 16:38:58 +09:00
parent 46e65700b2
commit ba4d66d146
8 changed files with 28 additions and 69 deletions

View File

@ -0,0 +1,21 @@
using UnityEngine;
namespace UniGLTF
{
public static class TransformExtensions
{
public static float UniformedLossyScale(this Transform transform)
{
var s = transform.lossyScale;
return AbsoluteMaxValue(s);
}
public static float AbsoluteMaxValue(in Vector3 s)
{
var x = Mathf.Abs(s.x);
var y = Mathf.Abs(s.y);
var z = Mathf.Abs(s.z);
return Mathf.Max(Mathf.Max(x, y), z);
}
}
}

View File

@ -1,7 +1,9 @@
{
"name": "SpringBoneJobs",
"rootNamespace": "",
"references": [],
"references": [
"GUID:8d76e605759c3f64a957d63ef96ada7c"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,

View File

@ -42,35 +42,6 @@ namespace UniGLTF.SpringBoneJobs
// System Level
public float DeltaTime;
static float MaxValue(Vector3 s)
{
var x = Mathf.Abs(s.x);
var y = Mathf.Abs(s.y);
var z = Mathf.Abs(s.z);
if (x < y)
{
if (y < z)
{
return z;
}
else
{
return y;
}
}
else
{
if (x < z)
{
return z;
}
else
{
return x;
}
}
}
/// <param name="index">房のindex</param>
public void Execute(int index)
{
@ -111,7 +82,7 @@ namespace UniGLTF.SpringBoneJobs
var parentRotation = parentTransform?.rotation ?? Quaternion.identity;
// scaling 対応
var scalingFactor = model.SupportsScalingAtRuntime ? MaxValue(headTransform.localToWorldMatrix.lossyScale) : 1.0f;
var scalingFactor = model.SupportsScalingAtRuntime ? TransformExtensions.AbsoluteMaxValue(headTransform.localToWorldMatrix.lossyScale) : 1.0f;
// verlet積分で次の位置を計算
var external = (joint.gravityDir * joint.gravityPower + model.ExternalForce) * DeltaTime;

View File

@ -1,38 +0,0 @@
using UnityEngine;
namespace VRM
{
public static class TransformExtensions
{
public static float UniformedLossyScale(this Transform transform)
{
// Mathf.Max(a, b, c) は GC どうなんだろう
var s = transform.lossyScale;
var x = Mathf.Abs(s.x);
var y = Mathf.Abs(s.y);
var z = Mathf.Abs(s.z);
if (x < y)
{
if (y < z)
{
return z;
}
else
{
return y;
}
}
else
{
if (x < z)
{
return z;
}
else
{
return x;
}
}
}
}
}

View File

@ -1,3 +1,4 @@
using UniGLTF;
using UnityEngine;
namespace VRM.SpringBone

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using UniGLTF;
using UnityEngine;
namespace VRM.SpringBone

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using UniGLTF;
using UnityEngine;
namespace VRM.SpringBone