Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use VRCParentConstraint instead of constraint hack for world fixed objects when available #1326

Merged
merged 11 commits into from
Nov 17, 2024

Conversation

JLChnToZ
Copy link
Contributor

As title indicates, this patches WorldFixedObjectProcessor to use VRCParentConstraint instead of old-fashioned Unity constraint hack for world fixed objects, only when such components are available and we're working on VRChat avatars.

Comment on lines 89 to 108
#if MA_VRCSDK3_AVATARS_3_7_0_OR_NEWER
var isVrcAvatar = avatarRoot.TryGetComponent(out VRC.SDKBase.VRC_AvatarDescriptor _);

if (isVrcAvatar)
{
var constraint = obj.AddComponent(
System.Type.GetType("VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint, VRC.SDK3.Dynamics.Constraint")
) as VRC.Dynamics.ManagedTypes.VRCParentConstraintBase;
constraint.IsActive = true;
constraint.Locked = true;
constraint.AffectsPositionX = true;
constraint.AffectsPositionY = true;
constraint.AffectsPositionZ = true;
constraint.AffectsRotationX = true;
constraint.AffectsRotationY = true;
constraint.AffectsRotationZ = true;
constraint.FreezeToWorld = true;
}
else
#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer here to extract this logic to a method and swap out the method as a whole, rather than having an else block spanning an #endif like this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK if the committed change is OK, it is hard to extract as a method because the case is "when VRCSDK with constraints is imported" (only can be filtered with #if preprocessor) and "we are working on a VRChat avatar" (only can be checked with if (...) ... else block)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking something like:

if (!TryGenerateVRChatConstraint(obj)) GenerateGenericConstraint(obj);

// ...
#if MA_VRCSDK3_AVATARS_3_7_0_OR_NEWER
bool TryGenerateVRChatConstraint(GameObject obj) { ... }
#else
bool TryGenerateVRChatConstraint(GameObject obj) { return false; }
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@bdunderscore
Copy link
Owner

It looks like the unit tests are broken now...

@JLChnToZ
Copy link
Contributor Author

JLChnToZ commented Nov 4, 2024

@bdunderscore bdunderscore merged commit a984cf8 into bdunderscore:main Nov 17, 2024
5 checks passed
bdunderscore added a commit that referenced this pull request Nov 20, 2024
…fixed objects when available (#1326)"

This reverts commit a984cf8. The prior
behavior was to lock world fixed objects at their offset from the
origin; however with this change we ended up locking them at a location
relative to the avatar spawn location, breaking some gimmicks.

I tried experimenting a bit with VRCConstraint to try to replicate this
behavior, but it seems a bit non-trivial, so we'll revert this as a
hotfix for now.
bdunderscore added a commit that referenced this pull request Nov 20, 2024
…fixed objects when available (#1326)" (#1363)

This reverts commit a984cf8. The prior
behavior was to lock world fixed objects at their offset from the
origin; however with this change we ended up locking them at a location
relative to the avatar spawn location, breaking some gimmicks.

I tried experimenting a bit with VRCConstraint to try to replicate this
behavior, but it seems a bit non-trivial, so we'll revert this as a
hotfix for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants