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

Fixing a bug the causes FaceOrigin collections to face the wrong direction when collections are rotated (and some bonuses) #2229

Closed
wants to merge 30 commits into from

Conversation

Ecnassianer
Copy link
Contributor

This is a pull request for the completion of my proposal:
#2227

Eric Carter and others added 8 commits May 30, 2018 19:11
…face the wrong direction when collecitons are rotated. Incidentally adds Radial collections.

Previously collections with FaceOrigin selected as their Orientation Type which were not perfectly vertical would align their elements in crazy ways. This commit fixes this, but slightly changes the meaning of FaceOrigin so elements always face the origin, even if that means angling the element up or down to face the origin. This could be considered a breaking change, since all existing FaceOrigin object collections will change behavior. This is particularly true of Cylinder collections which are FaceOrigin orientation.  They can be returned to the old behavior by switching to FaceCenterAxis, which keeps elements aligned with the collection's up vector. FaceCenterAxis also works well with spheres.

In the process I also consolidated all the orientation switch statements into a single function that handles the orientation on all objection collections.

Bringing these changes over also necessitated bringing in @paseb 's addition of Radial collections, that make cool fan-like things. Bonus feature!

Co-Authored-By: Patrick Sebring <[email protected]>
getting master June18 dev into this fork
Proposal:
#2228

In the process, I fixed a few bugs, particularly with the custom inspectors. Solvers can now be switched to other tracked objects while playing in editor or at runtime via script. It also adds an offset and rotation to solver handlers so you can track a virtual point near by/rotated around an actual tracked object.
Update from upstream repo microsoft/MixedRealityToolkit-Unity@june18_dev
@msftclas
Copy link

msftclas commented Jun 1, 2018

CLA assistant check
All CLA requirements met.

@Ecnassianer
Copy link
Contributor Author

That's strange. I've linked my Github account to my corporate account, and msftclas was cool with me yesterday.

@keveleigh keveleigh requested a review from paseb June 1, 2018 20:38
FaceForwardReversed, // Zero rotation + 180 degrees
FaceParentFoward, // Parent Relative Forwards
FaceParentBack, // Parent Relative Backwards
FaceParentUp, // Parent Relative Up
Copy link
Contributor

Choose a reason for hiding this comment

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

strange formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This extra tab doesn't show up in my local copy. Is this a merge artifact that I can fix on github?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it's because FaceParentUp is preceded with tabs, while the others are spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha! Thank you!

Radius = radius >= 0 ? Radius : radius;

Vector3 newPos = new Vector3(0f, 0f, (Radius/Rows) * row);
float yAngle = _radialCellAngle * (column - (_columns / 2f)) + (_radialCellAngle*.5f);
Copy link
Contributor

Choose a reason for hiding this comment

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

(_columns * 0.5f)

@@ -0,0 +1,134 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we replace the white space with an underscore for the name of this asset?

@@ -0,0 +1,134 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
Copy link
Contributor

Choose a reason for hiding this comment

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

same for the name here as well, please.

FaceParentBack, // Parent Relative Backwards
FaceParentUp, // Parent Relative Up
FaceParentDown, // Parent Relative Down
FaceCenterAxis, // Lay flat on the surface, facing in
Copy link
Contributor

Choose a reason for hiding this comment

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

bad formatting

/// </summary>
[Range(5f, 360f)]
[Tooltip("Radial range for radial layout")]
public float RadialRange = 180f;
Copy link
Contributor

Choose a reason for hiding this comment

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

should be private and serialized, if access outside this class is required, then add a public property

Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing for the rest of the fields below.

/// <param name="node"></param>
/// <param name="orientType"></param>
/// <param name="newPos"></param>
private void UpdateNodeFacing(CollectionNode node, OrientTypeEnum orientType, Vector3 newPos = new Vector3())
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of creating a new vector3, let's use Vector3.zero

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vector3.zero isn't a compile-time constant, so it can't be used as a default value. How about:

UpdateNodeFacing(CollectionNode node, OrientTypeEnum orientType, Vector3 newPos = default(Vector3))

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't think it would be, but it was worth a shot.

/// <param name="row">This is a <see cref="int"/> for the radius of the cylinder</param>
/// <param name="column">This is a <see cref="int"/> for the radius of the cylinder</param>
/// <returns></returns>
private Vector3 RadialMapping(Vector3 source, float radius, int row, int column)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not use the source?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just update source with new values instead of creating a new vector3 each time?

            Radius = radius >= 0 ? Radius : radius;
       
            source.x = 0f;
            source.y = 0f;
            source.z = (Radius/Rows) * row;

            float yAngle = _radialCellAngle * (column - (_columns * 0.5f)) + (_radialCellAngle * .5f);

            Quaternion rot = Quaternion.Euler(0.0f, yAngle, 0.0f);
            source = rot * source;

            return source;

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why not just do pure Quaternion math so we get better results without gimbal lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paseb Can you weigh in on this one? I'm not sure what your intention was here.

@@ -11,7 +11,11 @@ public enum OrientTypeEnum
None, // Don't rotate at all
FaceOrigin, // Rotate towards the origin
FaceOriginReversed, // Rotate towards the origin + 180 degrees
FaceFoward, // Zero rotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to keep these but mark them obsolete to prevent breaking changes.

Be sure to point people to which enum they should be using.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unity serializes enums as integers, so as long as they're in the same position in the enum, the existing data reflects the rename. FaceForward and FaceForwardReversed will transition automatically to FaceParentForward and FaceParentBack.

As for references in code, they will be a compile error, but I hope these are easy enough to find and replace. I think this is a fair trade for getting it out of the inspector. I'll add a comment to the new value explaining its old name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this change:

        [Obsolete("Please use FaceParentFoward")]
        FaceFoward = FaceParentFoward,             // Zero rotation
        [Obsolete("Please use FaceParentBack")]
        FaceForwardReversed = FaceParentBack,    // Zero rotation + 180 degrees
        FaceParentFoward,       // Parent Relative Forwards
        FaceParentBack,         // Parent Relative Backwards
        FaceParentUp,           // Parent Relative Up
        FaceParentDown,         // Parent Relative Down
        FaceCenterAxis,         // Lay flat on the surface, facing in
        FaceCenterAxisReversed // Lay flat on the surface, facing out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I'm not familiar with setting an enum to another value in the enum, and your sample doesn't compile. Can you elaborate on what you're suggesting?

The compile error I'm getting is:
The evaluation of the constant value for 'OrientTypeEnum.FaceForwardReversed' involves a circular definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, this is because FaceParentBack is defined after FaceForwardReversed. Hold on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works:

        FaceParentFoward,       // Parent Relative Forwards, this used to be called FaceForward
        FaceParentBack,         // Parent Relative Backwards, this used to be called FaceForwardReversed
        [Obsolete("Please use FaceParentFoward")]
        FaceFoward = FaceParentFoward,             // Zero rotation
        [Obsolete("Please use FaceParentBack")]
        FaceForwardReversed = FaceParentBack,    // Zero rotation + 180 degrees
        FaceParentUp,           // Parent Relative Up
        FaceParentDown,         // Parent Relative Down

But I almost think it's not worth the rename, since it replaces a confusing name in the inspector with an invalid confusing name and a clear name. Unless there's a way to fix that, I'll just put the names back to the old ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just wrote it real quick, but I think you get the idea.

@@ -91,5 +91,11 @@ private void SetChildrenActive(bool isActive)
}
}
}
void Reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

missing private access modifier.

{
// We want the default value of Handedness of Controller finders to be Unknown so it doesn't attach to random object.
// But we also want the Editor to start with a useful default, so we set a Left handedness on inspector reset.
Handedness = UnityEngine.XR.WSA.Input.InteractionSourceHandedness.Left;
Copy link
Contributor

Choose a reason for hiding this comment

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

breaks cross platform support.

Copy link
Contributor Author

@Ecnassianer Ecnassianer Jun 4, 2018

Choose a reason for hiding this comment

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

I haven't dealt with that yet. Do you mean to use an ifdef like this?

#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR.WSA.Input;
#else
using UnityEngine.VR.WSA.Input;
#endif

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, But I believe there's already a platform agnostic handedness enum you can use instead.

Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

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

See comments

@Ecnassianer
Copy link
Contributor Author

Ecnassianer commented Jun 4, 2018

My work in another PR accidentally got merged into this branch. I'm taking all the ControllerFinder stuff out because it didn't belong here.

Eric Carter added 2 commits June 4, 2018 16:20
…assianer/MixedRealityToolkit-Unity into SolverExampleUpdates" because it never belonged here

This reverts commit 9a2bef8, reversing
changes made to 7cf6e78.
…ver belonged here

This reverts commit 6aac3a8, reversing
changes made to cba36c7.
@keveleigh
Copy link
Contributor

keveleigh commented Jun 4, 2018

Something somewhere has gone wrong:
image

@Ecnassianer
Copy link
Contributor Author

Yes, you can ignore this until I learn enough about git to rescue myself. XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants