LightProbeVolumeGizmo.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2017 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using BansheeEngine;
  6. using BansheeEditor;
  7. namespace BansheeEditor
  8. {
  9. /** @addtogroup Scene-Editor
  10. * @{
  11. */
  12. /// <summary>
  13. /// Render individual nodes of a light probe volume and allows the user to select and move them.
  14. /// </summary>
  15. [CustomHandle(typeof(LightProbeVolume))]
  16. internal class LightProbeVolumeNodeHandles : Handle
  17. {
  18. /// <summary>
  19. /// Returns the handle of the currently selected node in the light probe volume. Is set to uint.MaxValue if no
  20. /// node is selected.
  21. /// </summary>
  22. internal static uint SelectedNode
  23. {
  24. get { return selectedNode; }
  25. }
  26. private LightProbeVolume volume;
  27. private List<HandleSliderSphere> nodeColliders = new List<HandleSliderSphere>();
  28. private LightProbeInfo[] probeInfos;
  29. private MoveHandle moveHandle;
  30. private static uint selectedNode = uint.MaxValue;
  31. /// <summary>
  32. /// Creates a new instance of the object.
  33. /// </summary>
  34. public LightProbeVolumeNodeHandles(LightProbeVolume volume)
  35. {
  36. this.volume = volume;
  37. selectedNode = uint.MaxValue;
  38. }
  39. /// <inheritdoc/>
  40. protected internal override void PreInput()
  41. {
  42. Matrix4 transform = volume.SceneObject.WorldTransform;
  43. probeInfos = volume.GetProbes();
  44. for (int i = 0; i < probeInfos.Length; i++)
  45. {
  46. if(i == nodeColliders.Count)
  47. nodeColliders.Add(new HandleSliderSphere(this, 1.0f, false));
  48. Vector3 position = probeInfos[i].position;
  49. position = transform.MultiplyAffine(position);
  50. nodeColliders[i].Position = position;
  51. }
  52. while (nodeColliders.Count > probeInfos.Length)
  53. {
  54. nodeColliders[nodeColliders.Count - 1].Destroy();
  55. nodeColliders.RemoveAt(nodeColliders.Count - 1);
  56. }
  57. if (selectedNode != uint.MaxValue)
  58. {
  59. if(moveHandle == null)
  60. moveHandle = new MoveHandle();
  61. Vector3 position = Vector3.Zero;
  62. for (int i = 0; i < probeInfos.Length; i++)
  63. {
  64. if (probeInfos[i].handle == selectedNode)
  65. {
  66. position = transform.MultiplyAffine(probeInfos[i].position);
  67. break;
  68. }
  69. }
  70. moveHandle.Position = position;
  71. moveHandle.PreInput();
  72. }
  73. }
  74. /// <inheritdoc/>
  75. protected internal override void PostInput()
  76. {
  77. for(int i = 0; i < nodeColliders.Count; i++)
  78. {
  79. if (nodeColliders[i].State == HandleSlider.StateType.Active)
  80. {
  81. selectedNode = probeInfos[i].handle;
  82. break;
  83. }
  84. }
  85. if (selectedNode != uint.MaxValue && moveHandle != null)
  86. {
  87. moveHandle.PostInput();
  88. if (moveHandle.IsDragged())
  89. volume.SetProbePosition(selectedNode, moveHandle.Position + moveHandle.Delta);
  90. }
  91. }
  92. /// <inheritdoc/>
  93. protected internal override void Draw()
  94. {
  95. HandleDrawing.Transform = Matrix4.TRS(volume.SceneObject.Position, volume.SceneObject.Rotation, Vector3.One);
  96. HandleDrawing.Color = Color.White;
  97. foreach (var entry in probeInfos)
  98. HandleDrawing.DrawSphere(entry.position, 1.0f);
  99. }
  100. }
  101. /** @} */
  102. }