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

Feature/visualizing snapzone content in editor trng 1047 #47

Merged

Conversation

SimonTheSourcerer
Copy link
Contributor

@SimonTheSourcerer SimonTheSourcerer commented Aug 31, 2020

Description

  • Added Preview where and how the object will be snapped
  • Normal created snapzones only allow to snap a specific TrainingSceneObject
  • Fixed snapzone snapping position by adjusting the center of mass (always put it to 0,0,0 which).

Fixes: # (issue)

  • TRNG-1047
  • TRNG-1044

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

by hand

Test Configuration:
To get this working you also have to checkout Basic interaction: Feature/validation for snapzones

Copy link
Contributor

@Gusinuhe Gusinuhe left a comment

Choose a reason for hiding this comment

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

I know it is already messed up, but maybe some new public elements from the SnapZone (like the PreviewMesh) can be internals.


private void Update()
{
bool isPreviewing = gameObject.GetComponent<MeshFilter>() != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the MeshFilter can be cached and just check if it is null or not.

if (Parent.ShowHighlightInEditor && Parent.PreviewMesh && isPreviewing == false)
{
MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
meshFilter.sharedMesh = Parent.PreviewMesh;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work if the parent has a SkinnedMeshRenderer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dont know :x

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should, I'll test it

Copy link
Contributor

Choose a reason for hiding this comment

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

It does work

Runtime/Interaction/SnapZonePreviewDrawer.cs Show resolved Hide resolved
Editor/Properties/SnappablePropertyEditor.cs Show resolved Hide resolved
Editor/Properties/SnappablePropertyEditor.cs Show resolved Hide resolved
Editor/SnapZone/SnapZoneSettings.cs Outdated Show resolved Hide resolved
Runtime/Interaction/SnapZone.cs Outdated Show resolved Hide resolved
Runtime/Interaction/SnapZone.cs Outdated Show resolved Hide resolved
Runtime/Interaction/SnapZone.cs Outdated Show resolved Hide resolved
Runtime/Interaction/SnapZonePreviewDrawer.cs Show resolved Hide resolved
@SimonTheSourcerer SimonTheSourcerer changed the title Feature/visualizing snapzone conten in editor trng 1047 Feature/visualizing snapzone content in editor trng 1047 Aug 31, 2020
Copy link
Contributor

@Gusinuhe Gusinuhe left a comment

Choose a reason for hiding this comment

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

The snap zone generator does not consider submeshes for the highlight object.
image

Editor/SnapZone/SnapZoneSettings.cs Outdated Show resolved Hide resolved
Runtime/Interaction/SnapZone.cs Outdated Show resolved Hide resolved
@SimonTheSourcerer
Copy link
Contributor Author

Also fixed the highlight during runtime.


private Material highlightMeshMaterial;
[SerializeField]
Copy link
Contributor

Choose a reason for hiding this comment

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

publics are already serialized 😇

@@ -318,6 +384,14 @@ public override bool CanSelect(XRBaseInteractable interactable)
return true;
}

foreach (Validator validator in validators)
Copy link
Contributor

Choose a reason for hiding this comment

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

if (validators.All(validator => validator.Validate(interactable.gameObject)) == false)
{
    return false;
}

@aleksei-korolev
Copy link
Contributor

I didn't test it yet, but the code looks OK

@Gusinuhe
Copy link
Contributor

Gusinuhe commented Aug 31, 2020

When ShowHighlightInEditor is disabled, the highlight object is disabled as expected, but if it is enabled again the highlight object never gets enabled (and actually SnapZonePreviewDrawer is gone forever).

@Gusinuhe
Copy link
Contributor

SnapZonePreviewDrawer does not render sub meshes.

image

  • Object in the left: Snap Zone
  • Object in the right: Highlight object from the same Snap Zone

Editor/Interaction/SnapZoneEditor.cs Outdated Show resolved Hide resolved
@@ -54,8 +55,25 @@ private void CreateSnapZone(SnappableProperty snappable)
// Adds a Snap Zone component to our new object.
SnapZone snapZone = snapObject.AddComponent<SnapZoneProperty>().SnapZone;
snapZone.ShownHighlightObject = snapZonePrefab;
IsTrainingSceneObjectValidation validation =
snapZone.gameObject.AddComponent<IsTrainingSceneObjectValidation>();
Copy link
Contributor

Choose a reason for hiding this comment

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

linebreak. maybe you dont want that

@@ -31,24 +31,39 @@ public class SnapZoneSettings : ScriptableObject
private Material highlightMaterial;

/// <summary>
/// This color is used when an <see cref="InteractableObject"/> is hovering a <see cref="SnapZone"/>.
/// This color is used when a valid <see cref="InteractableObject"/> is hovering a <see cref="SnapZone"/>.
Copy link
Contributor

Choose a reason for hiding this comment

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

ValidationColor probably should be ValidColor since it is also InvalidColor.
Validation is the process and therefore could also be invalid in the end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should probably be that, but this is an api break :|

/// <summary>
/// The material used for drawing when an <see cref="InteractableObject"/> is hovering a <see cref="SnapZone"/>. Should be transparent.
/// </summary>
public Material HighlightMaterial => SetupHighlightMaterial();

/// <summary>
/// The material used for the highlight object. Should be transparent.
/// The material used for the highlight object, when a valid object is hovering. Should be transparent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as with the color -> ValidMaterial or IsValidMaterial

Runtime/Interaction/SnapZone.cs Outdated Show resolved Hide resolved
@SimonTheSourcerer SimonTheSourcerer force-pushed the feature/visualizing-snapzone-conten-in-editor-trng-1047 branch from e4c6613 to ca164d2 Compare September 1, 2020 08:36
feat(snapzones): added gizmo to snapzones
feat(snapzones): automatically created snapzones only snap the correct object

fix(snapzones): snapping not working correctly with offset items
fix(snapzones): improved rendering of highlights for snapzones
fix(snapzones): fast forward snappables now snap immediately (#44)
@SimonTheSourcerer SimonTheSourcerer force-pushed the feature/visualizing-snapzone-conten-in-editor-trng-1047 branch from ca164d2 to 1e5d783 Compare September 1, 2020 08:57
Copy link
Contributor

@Gusinuhe Gusinuhe left a comment

Choose a reason for hiding this comment

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

By the power vested in me, I now pronounce this PR, approved!

You may now merge the branch.

@Gusinuhe Gusinuhe merged commit 054f2d6 into develop Sep 1, 2020
@Gusinuhe Gusinuhe deleted the feature/visualizing-snapzone-conten-in-editor-trng-1047 branch September 1, 2020 16:17
@ci-innoactive
Copy link
Collaborator

🎉 This PR is included in version 1.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants