mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 07:00:10 -05:00
Merge pull request #1712 from amamagi/fix/vrm10-spring-bone-buffer-disposed-check
SpringBoneの剛性が意図しない方向に働くことがある問題を修正
This commit is contained in:
commit
927116a127
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
using UniVRM10.FastSpringBones.Blittables;
|
||||
using UniVRM10.FastSpringBones.System;
|
||||
|
|
@ -15,6 +17,7 @@ namespace UniVRM10
|
|||
private readonly IVrm10Constraint[] m_constraints;
|
||||
private readonly Transform m_head;
|
||||
private readonly FastSpringBoneService m_fastSpringBoneService;
|
||||
private readonly Dictionary<Transform, (Vector3 position, Quaternion rotation)> m_defaultTransformStates;
|
||||
|
||||
private FastSpringBoneBuffer m_fastSpringBoneBuffer;
|
||||
|
||||
|
|
@ -47,6 +50,18 @@ namespace UniVRM10
|
|||
// for UnitTest
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = target.GetComponent<RuntimeGltfInstance>();
|
||||
if (instance != null)
|
||||
{
|
||||
// ランタイムインポートならここに到達してほぼゼロコストになる
|
||||
m_defaultTransformStates = instance.Nodes.ToDictionary(tf=> tf, tf=>(tf.position, tf.rotation));
|
||||
}
|
||||
else
|
||||
{
|
||||
// エディタでプレハブ配置してる奴ならこっちに到達して収集する
|
||||
m_defaultTransformStates = target.GetComponentsInChildren<Transform>().ToDictionary(tf=> tf, tf=>(tf.position, tf.rotation));
|
||||
}
|
||||
|
||||
m_fastSpringBoneService = FastSpringBoneService.Instance;
|
||||
m_fastSpringBoneBuffer = CreateFastSpringBoneBuffer(m_target.SpringBone);
|
||||
|
|
@ -97,11 +112,21 @@ namespace UniVRM10
|
|||
gravityDir = joint.m_gravityDir,
|
||||
gravityPower = joint.m_gravityPower,
|
||||
stiffnessForce = joint.m_stiffnessForce
|
||||
}
|
||||
},
|
||||
DefaultLocalRotation = GetOrAddDefaultTransformState(joint.transform).rotation
|
||||
}).ToArray(),
|
||||
}).ToArray());
|
||||
}
|
||||
|
||||
private (Vector3 position, Quaternion rotation) GetOrAddDefaultTransformState(Transform tf)
|
||||
{
|
||||
if (m_defaultTransformStates.TryGetValue(tf, out var defaultTransformState))
|
||||
{
|
||||
return defaultTransformState;
|
||||
}
|
||||
return m_defaultTransformStates[tf] = (tf.position, tf.rotation);
|
||||
}
|
||||
|
||||
private static BlittableColliderType TranslateColliderType(VRM10SpringBoneColliderTypes colliderType)
|
||||
{
|
||||
switch (colliderType)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
parentTransformIndex = parent != null ? transformIndexDictionary[parent] : -1,
|
||||
currentTail = currentTail,
|
||||
prevTail = currentTail,
|
||||
localRotation = joint.Transform.localRotation,
|
||||
localRotation = joint.DefaultLocalRotation,
|
||||
boneAxis = localChildPosition.normalized,
|
||||
length = localChildPosition.magnitude
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ namespace UniVRM10.FastSpringBones.System
|
|||
{
|
||||
public Transform Transform;
|
||||
public BlittableJoint Joint;
|
||||
public Quaternion DefaultLocalRotation;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user