mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-21 17:50:57 -05:00
RuntimeGltfInstance が無い場合に NullReferenceException を修正
This commit is contained in:
parent
11e79263ce
commit
7e819b8019
|
|
@ -139,7 +139,18 @@ namespace UniVRM10
|
|||
{
|
||||
// importer 内で InitializeAsync が呼び出し済み
|
||||
}
|
||||
return new Vrm10Runtime(this, useControlRig, m_springBoneRuntime);
|
||||
|
||||
var runtime = GetComponent<RuntimeGltfInstance>();
|
||||
|
||||
// Vrm10Runtimeが使う初期姿勢を固定する。SpringBone や Constraint の初期姿勢になる。
|
||||
var initPose = runtime != null
|
||||
// RuntimeGltfInstance があるとき => RuntimeLoad => 初期姿勢は glTF の node に由来する
|
||||
? runtime.InitialTransformStates.ToDictionary((kv) => kv.Key, (kv) => kv.Value)
|
||||
// RuntimeGltfInstance が無いとき => Scene 配置の prefab など。シーンの現状を代用する。既に T-Pose でないかもしれない。
|
||||
: GetComponentsInChildren<Transform>().ToDictionary(x => x, x => new TransformState(x))
|
||||
;
|
||||
|
||||
return new Vrm10Runtime(this, useControlRig, m_springBoneRuntime, initPose);
|
||||
}
|
||||
|
||||
public Vrm10Runtime Runtime
|
||||
|
|
|
|||
|
|
@ -49,25 +49,21 @@ namespace UniVRM10
|
|||
}
|
||||
}
|
||||
|
||||
Dictionary<Transform, TransformState> _initPose;
|
||||
IReadOnlyDictionary<Transform, TransformState> _initPose;
|
||||
|
||||
public Vrm10Runtime(Vrm10Instance instance, bool useControlRig, IVrm10SpringBoneRuntime springBoneRuntime)
|
||||
public Vrm10Runtime(Vrm10Instance instance, bool useControlRig, IVrm10SpringBoneRuntime springBoneRuntime,
|
||||
IReadOnlyDictionary<Transform, TransformState> initPose)
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
UniGLTFLogger.Warning($"{nameof(Vrm10Runtime)} expects runtime behaviour.");
|
||||
}
|
||||
if (instance == null)
|
||||
{
|
||||
m_instance = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_instance != instance)
|
||||
_initPose = initPose;
|
||||
m_instance = instance;
|
||||
if (m_instance == null)
|
||||
{
|
||||
m_instance = instance;
|
||||
var runtime = m_instance.GetComponent<RuntimeGltfInstance>();
|
||||
_initPose = runtime.InitialTransformStates.ToDictionary((kv) => kv.Key, (kv) => kv.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!instance.TryGetBoneTransform(HumanBodyBones.Head, out m_head))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user