Skip to content

Commit

Permalink
Add vertical displacement slider to lift objects off the ground
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-vr committed May 16, 2022
1 parent a01198f commit dcc8e4b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LightboxViewerEditorWindow : EditorWindow
public bool counterRotate = true;
public bool postProcessing = true;
public bool advanced;
public float verticalDisplacement;
private Vector2 _scrollPos;
private int _generatedSize;

Expand Down Expand Up @@ -162,13 +163,24 @@ private void OnGUI()
advanced = EditorGUILayout.Foldout(advanced, "Advanced");
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(postProcessing)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(referenceCamera)));

EditorGUILayout.BeginHorizontal();
EditorGUILayout.Slider(serializedObject.FindProperty(nameof(verticalDisplacement)), 0, 2f);
EditorGUI.BeginDisabledGroup(verticalDisplacement == 0);
if (ColoredBgButton(verticalDisplacement != 0, Color.green, () => GUILayout.Button("Reset", GUILayout.Width(150))))
{
serializedObject.FindProperty(nameof(verticalDisplacement)).floatValue = 0;
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();

EditorGUI.BeginDisabledGroup(!_enabled);
if (GUILayout.Button("Realign"))
{
Realign();
}
EditorGUI.EndDisabledGroup();
headerLines += 4;
headerLines += 5;
}
else
{
Expand Down Expand Up @@ -204,6 +216,7 @@ private void OnGUI()
ProjectRenderQueue.CounterRotate(counterRotate);
ProjectRenderQueue.Camera(referenceCamera);
ProjectRenderQueue.PostProcessing(postProcessing);
ProjectRenderQueue.VerticalDisplacement(verticalDisplacement);
}

var att = ProjectRenderQueue.Textures().ToArray();
Expand Down Expand Up @@ -387,6 +400,7 @@ public class LightboxViewerRenderQueue
private Quaternion _referentialQuaternion;
private Camera _cameraOptional;
private bool _postProcessing;
private float _verticalDisplacement;

public LightboxViewerRenderQueue()
{
Expand Down Expand Up @@ -525,7 +539,7 @@ private void TrueRender(GameObject copy)
var lightboxIndex = _queue.Dequeue();
var currentLightbox = allApplicableLightboxes[lightboxIndex];
currentLightbox.SetActive(true);
viewer.RenderNoAnimator(_lightboxIndexToTexture[lightboxIndex], currentLightbox, renderTexture, _referentialVector, _referentialQuaternion);
viewer.RenderNoAnimator(_lightboxIndexToTexture[lightboxIndex], currentLightbox, renderTexture, _referentialVector, _referentialQuaternion, _verticalDisplacement);
currentLightbox.SetActive(false);

itemCount++;
Expand Down Expand Up @@ -654,5 +668,10 @@ private GameObject[] AllApplicableLightboxes()
.Where(lightbox => !lightbox.CompareTag("EditorOnly"))
.ToArray();
}

public void VerticalDisplacement(float verticalDisplacement)
{
_verticalDisplacement = verticalDisplacement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Terminate()
Object.DestroyImmediate(_camera.gameObject);
}

public void RenderNoAnimator(Texture2D element, GameObject currentLightbox, RenderTexture renderTexture, Vector3 referentialVector, Quaternion referentialQuaternion)
public void RenderNoAnimator(Texture2D element, GameObject currentLightbox, RenderTexture renderTexture, Vector3 referentialVector, Quaternion referentialQuaternion, float verticalDisplacement)
{
var rootTransform = _animatedRoot.transform;
var camTransform = _camera.transform;
Expand All @@ -66,7 +66,7 @@ public void RenderNoAnimator(Texture2D element, GameObject currentLightbox, Rend
var camRot = camTransform.rotation;
try
{
var targetPos = currentLightbox.transform.position;
var targetPos = currentLightbox.transform.position + Vector3.up * verticalDisplacement;
rootTransform.position = targetPos + (initPos - referentialVector);
var relativeVector = camPos - referentialVector;
camTransform.position = currentLightbox.transform.rotation * referentialQuaternion * relativeVector + targetPos;
Expand Down

0 comments on commit dcc8e4b

Please sign in to comment.