fix: Erros in Unity 2022 due to GetBoneTransform (#550)

This commit is contained in:
anatawa12 2023-12-12 19:49:32 +09:00 committed by GitHub
parent 409501cb39
commit 0e243aa4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 127 additions and 81 deletions

View File

@ -331,7 +331,7 @@ namespace nadena.dev.modular_avatar.core.editor
return false;
}
avatarHips = avatarAnimator.GetBoneTransform(HumanBodyBones.Hips)?.gameObject;
avatarHips = avatarAnimator.isHuman ? avatarAnimator.GetBoneTransform(HumanBodyBones.Hips)?.gameObject : null;
if (avatarHips == null)
{
@ -345,7 +345,7 @@ namespace nadena.dev.modular_avatar.core.editor
var outfitAnimator = outfitRoot.GetComponent<Animator>();
if (outfitAnimator != null)
{
outfitHips = outfitAnimator.GetBoneTransform(HumanBodyBones.Hips)?.gameObject;
outfitHips = outfitAnimator.isHuman ? outfitAnimator.GetBoneTransform(HumanBodyBones.Hips)?.gameObject : null;
}
var hipsCandidates = new List<string>();

View File

@ -168,15 +168,18 @@ namespace nadena.dev.modular_avatar.core.editor
var rootAnimator = RuntimeUtil.FindAvatarTransformInParents(mergeTarget.transform)
.GetComponent<Animator>();
foreach (var bone in Enum.GetValues(typeof(HumanBodyBones)).Cast<HumanBodyBones>())
if (rootAnimator.isHuman)
{
if (bone != HumanBodyBones.LastBone)
foreach (var bone in Enum.GetValues(typeof(HumanBodyBones)).Cast<HumanBodyBones>())
{
var xform = rootAnimator.GetBoneTransform(bone);
if (xform != null)
if (bone != HumanBodyBones.LastBone)
{
xform_to_bone[xform] = bone;
bone_to_xform[bone] = xform;
var xform = rootAnimator.GetBoneTransform(bone);
if (xform != null)
{
xform_to_bone[xform] = bone;
bone_to_xform[bone] = xform;
}
}
}
}

View File

@ -62,7 +62,7 @@ namespace nadena.dev.modular_avatar.core.editor
this.context = context.Extension<ModularAvatarContext>().BuildContext;
this.physBones = avatarGameObject.transform.GetComponentsInChildren<VRCPhysBone>(true);
if (avatarGameObject.TryGetComponent<Animator>(out var animator))
if (avatarGameObject.TryGetComponent<Animator>(out var animator) && animator.isHuman)
{
this.humanoidBones = new HashSet<Transform>(Enum.GetValues(typeof(HumanBodyBones))
.Cast<HumanBodyBones>()

View File

@ -80,14 +80,13 @@ namespace nadena.dev.modular_avatar.core.editor
// Also retain humanoid bones
var animator = _root.GetComponent<Animator>();
if (animator != null)
if (animator != null && animator.isHuman)
{
foreach (var bone_ in Enum.GetValues(typeof(HumanBodyBones)))
foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones)))
{
var bone = (HumanBodyBones) bone_;
if (bone == HumanBodyBones.LastBone) continue;
var transform = animator.GetBoneTransform((HumanBodyBones) bone);
var transform = animator.GetBoneTransform(bone);
if (transform != null)
{
MarkObject(transform.gameObject);
@ -108,23 +107,26 @@ namespace nadena.dev.modular_avatar.core.editor
// https://github.com/bdunderscore/modular-avatar/issues/308
// If we have duplicate Armature bones, retain them all in order to deal with some horrible hacks that are
// in use in the wild.
try
if (animator.isHuman)
{
var trueArmature = animator?.GetBoneTransform(HumanBodyBones.Hips)?.parent;
if (trueArmature != null)
try
{
foreach (Transform t in _root.transform)
var trueArmature = animator?.GetBoneTransform(HumanBodyBones.Hips)?.parent;
if (trueArmature != null)
{
if (t.name == trueArmature.name)
foreach (Transform t in _root.transform)
{
MarkObject(t.gameObject);
if (t.name == trueArmature.name)
{
MarkObject(t.gameObject);
}
}
}
}
}
catch (MissingComponentException e)
{
// No animator? weird. Move on.
catch (MissingComponentException e)
{
// No animator? weird. Move on.
}
}
}

View File

@ -26,7 +26,7 @@ namespace nadena.dev.modular_avatar.core.editor
public VisibleHeadAccessoryValidation(GameObject avatarRoot)
{
var animator = avatarRoot.GetComponent<Animator>();
HeadBone = animator != null ? animator.GetBoneTransform(HumanBodyBones.Head) : null;
HeadBone = animator != null && animator.isHuman ? animator.GetBoneTransform(HumanBodyBones.Head) : null;
var activeBones = ImmutableHashSet.CreateBuilder<Transform>();
#if MA_VRCSDK3_AVATARS

View File

@ -175,7 +175,7 @@ namespace nadena.dev.modular_avatar.core
}
var animator = avatarTransform.GetComponent<Animator>();
if (animator == null) return null;
if (animator == null || !animator.isHuman) return null;
var bone = animator.GetBoneTransform(boneReference);
if (bone == null) return null;
if (string.IsNullOrWhiteSpace(subPath)) return bone;
@ -192,12 +192,15 @@ namespace nadena.dev.modular_avatar.core
return;
}
foreach (var boneTypeObj in Enum.GetValues(typeof(HumanBodyBones)))
if (animator.isHuman)
{
var boneType = (HumanBodyBones) boneTypeObj;
if (boneType == HumanBodyBones.LastBone) continue;
var bone = animator.GetBoneTransform(boneType);
if (bone != null) humanBones[bone] = boneType;
foreach (var boneTypeObj in Enum.GetValues(typeof(HumanBodyBones)))
{
var boneType = (HumanBodyBones)boneTypeObj;
if (boneType == HumanBodyBones.LastBone) continue;
var bone = animator.GetBoneTransform(boneType);
if (bone != null) humanBones[bone] = boneType;
}
}
Transform iter = newTarget;

View File

@ -175,7 +175,7 @@ namespace nadena.dev.modular_avatar.core
{
// We only infer if targeting the armature (below the Hips bone)
var rootAnimator = RuntimeUtil.FindAvatarTransformInParents(transform)?.GetComponent<Animator>();
if (rootAnimator == null) return;
if (rootAnimator == null || !rootAnimator.isHuman) return;
var hips = rootAnimator.GetBoneTransform(HumanBodyBones.Hips);
if (hips == null || hips.transform.parent != mergeTargetObject.transform) return;

View File

@ -26,18 +26,19 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3825275463613500755}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.023681391, y: 1.0559628, z: -0.6872994}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3646968714803193661}
- {fileID: 3646968713996568948}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!95 &3825275463613500750
Animator:
serializedVersion: 3
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@ -50,10 +51,12 @@ Animator:
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!114 &3825275463613500753
MonoBehaviour:
m_ObjectHideFlags: 0
@ -322,40 +325,12 @@ MonoBehaviour:
contentType: 0
assetBundleUnityVersion:
fallbackStatus: 0
--- !u!114 &3825275463971368602
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4167925416990528462}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6fd7cab7d93b403280f2f9da978d8a4f, type: 3}
m_Name:
m_EditorClassIdentifier:
Bindings:
- ReferenceMesh:
referencePath: BaseMesh
Blendshape: shape_0
LocalBlendshape: shape_0_local
- ReferenceMesh:
referencePath: BaseMesh
Blendshape: shape_1
LocalBlendshape: shape_1
- ReferenceMesh:
referencePath: MissingMesh
Blendshape: missing_mesh_shape
LocalBlendshape: missing_mesh_shape
- ReferenceMesh:
referencePath:
Blendshape: missing_mesh_shape_2
LocalBlendshape: missing_mesh_shape_2
--- !u!1001 &3825275463173128406
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 3825275463613500751}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
@ -454,6 +429,9 @@ PrefabInstance:
value: BaseMesh
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 14ac2ad30c5d3444ca37f76cea5a7047, type: 3}
--- !u!4 &3646968714803193661 stripped
Transform:
@ -466,6 +444,7 @@ PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 3825275463613500751}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
@ -569,16 +548,52 @@ PrefabInstance:
value: SyncedMesh
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
type: 3}
insertIndex: -1
addedObject: {fileID: 3825275463971368602}
m_SourcePrefab: {fileID: 100100000, guid: 14ac2ad30c5d3444ca37f76cea5a7047, type: 3}
--- !u!1 &4167925416990528462 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
type: 3}
m_PrefabInstance: {fileID: 3825275463971368607}
m_PrefabAsset: {fileID: 0}
--- !u!4 &3646968713996568948 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
type: 3}
m_PrefabInstance: {fileID: 3825275463971368607}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4167925416990528462 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 14ac2ad30c5d3444ca37f76cea5a7047,
type: 3}
m_PrefabInstance: {fileID: 3825275463971368607}
m_PrefabAsset: {fileID: 0}
--- !u!114 &3825275463971368602
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4167925416990528462}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6fd7cab7d93b403280f2f9da978d8a4f, type: 3}
m_Name:
m_EditorClassIdentifier:
Bindings:
- ReferenceMesh:
referencePath: BaseMesh
Blendshape: shape_0
LocalBlendshape: shape_0_local
- ReferenceMesh:
referencePath: BaseMesh
Blendshape: shape_1
LocalBlendshape: shape_1
- ReferenceMesh:
referencePath: MissingMesh
Blendshape: missing_mesh_shape
LocalBlendshape: missing_mesh_shape
- ReferenceMesh:
referencePath:
Blendshape: missing_mesh_shape_2
LocalBlendshape: missing_mesh_shape_2

View File

@ -24,13 +24,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 142902026228790743}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1307626480854022291}
m_Father: {fileID: 7771643381241638341}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5142289987402199566
MonoBehaviour:
@ -48,7 +49,9 @@ MonoBehaviour:
referencePath: TargetArmature
prefix:
suffix:
locked: 0
legacyLocked: 0
LockMode: 2
mangleNames: 1
--- !u!1 &3939344753650647844
GameObject:
m_ObjectHideFlags: 0
@ -73,12 +76,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3939344753650647844}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3765950332587949126}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!108 &3850036455643109928
Light:
@ -139,6 +143,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &4272806970656211122
@ -167,14 +172,15 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4272806970656211122}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 775848723175009863}
- {fileID: 8324490609108703234}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7530346862543086688
MonoBehaviour:
@ -445,7 +451,7 @@ MonoBehaviour:
fallbackStatus: 0
--- !u!95 &8663814280084774636
Animator:
serializedVersion: 3
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@ -458,10 +464,12 @@ Animator:
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!1 &4555019349048654422
GameObject:
m_ObjectHideFlags: 0
@ -485,13 +493,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4555019349048654422}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 300981552980829197}
m_Father: {fileID: 1307626480854022291}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5003352987953611839
GameObject:
@ -517,13 +526,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5003352987953611839}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7163609193256089593}
m_Father: {fileID: 775848723175009863}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!108 &6458914482149713719
Light:
@ -584,6 +594,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &5211409391945350230
@ -609,13 +620,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5211409391945350230}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3765950332587949126}
m_Father: {fileID: 7771643381241638341}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6351904685015466854
GameObject:
@ -641,13 +653,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6351904685015466854}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2316703114878169859}
m_Father: {fileID: 8324490609108703234}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &6449816858013762983
BoxCollider:
@ -657,9 +670,17 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6351904685015466854}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &7929145021863230782
@ -686,12 +707,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7929145021863230782}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2316703114878169859}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!108 &1489850514334368640
Light:
@ -752,5 +774,6 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0