Added support for spawning and editing multiple datasets in the same scene. Also fixed the initial size of the TF GUIs.
This commit is contained in:
Родитель
6369c346d5
Коммит
6a76a748bf
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class SelectionHelper
|
||||
{
|
||||
public static VolumeRenderedObject GetSelectedVolumeObject()
|
||||
{
|
||||
foreach (GameObject obj in Selection.gameObjects)
|
||||
{
|
||||
VolumeRenderedObject volrendobj = obj.GetComponent<VolumeRenderedObject>();
|
||||
if (volrendobj != null)
|
||||
return volrendobj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0fe93c0b29b1f474ebcfd15be9ef1c9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -10,6 +10,8 @@ public class TransferFunction2DEditorWindow : EditorWindow
|
|||
private Material tfGUIMat = null;
|
||||
private int selectedBoxIndex = -1;
|
||||
|
||||
private VolumeRenderedObject volRendObject = null;
|
||||
|
||||
[MenuItem("Volume Rendering/2D Transfer Function")]
|
||||
static void ShowWindow()
|
||||
{
|
||||
|
@ -19,23 +21,43 @@ public class TransferFunction2DEditorWindow : EditorWindow
|
|||
|
||||
TransferFunction2DEditorWindow tf2dWnd = (TransferFunction2DEditorWindow)EditorWindow.GetWindow(typeof(TransferFunction2DEditorWindow));
|
||||
tf2dWnd.Show();
|
||||
tf2dWnd.SetInitialPosition();
|
||||
}
|
||||
|
||||
private void SetInitialPosition()
|
||||
{
|
||||
Rect rect = this.position;
|
||||
rect.width = 800.0f;
|
||||
rect.height = 500.0f;
|
||||
this.position = rect;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
tfGUIMat = Resources.Load<Material>("TransferFunction2DGUIMat");
|
||||
|
||||
volRendObject = SelectionHelper.GetSelectedVolumeObject();
|
||||
if (volRendObject == null)
|
||||
{
|
||||
volRendObject = GameObject.FindObjectOfType<VolumeRenderedObject>();
|
||||
if (volRendObject != null)
|
||||
Selection.objects = new Object[] { volRendObject.gameObject };
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
VolumeRenderedObject volRend = FindObjectOfType<VolumeRenderedObject>();
|
||||
if (volRend == null)
|
||||
// Update selected object
|
||||
if (volRendObject == null)
|
||||
volRendObject = SelectionHelper.GetSelectedVolumeObject();
|
||||
|
||||
if (volRendObject == null)
|
||||
return;
|
||||
|
||||
if (hist2DTex == null)
|
||||
hist2DTex = HistogramTextureGenerator.Generate2DHistogramTexture(volRend.dataset);
|
||||
hist2DTex = HistogramTextureGenerator.Generate2DHistogramTexture(volRendObject.dataset);
|
||||
|
||||
TransferFunction2D tf2d = volRend.transferFunction2D;
|
||||
TransferFunction2D tf2d = volRendObject.transferFunction2D;
|
||||
|
||||
// Calculate GUI width (minimum of window width and window height * 2)
|
||||
float bgWidth = Mathf.Min(this.position.width - 20.0f, (this.position.height - 250.0f) * 2.0f);
|
||||
|
@ -104,12 +126,20 @@ public class TransferFunction2DEditorWindow : EditorWindow
|
|||
tf2d.GenerateTexture();
|
||||
needsRegenTexture = false;
|
||||
}
|
||||
volRend.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tf2d.GetTexture());
|
||||
volRend.GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("TF2D_ON");
|
||||
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tf2d.GetTexture());
|
||||
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("TF2D_ON");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void OnSelectionChange()
|
||||
{
|
||||
VolumeRenderedObject newVolRendObj = Selection.activeGameObject?.GetComponent<VolumeRenderedObject>();
|
||||
// If we selected another volume object than the one previously edited in this GUI
|
||||
if (volRendObject != null && newVolRendObj != null && newVolRendObj != volRendObject)
|
||||
this.Close();
|
||||
}
|
||||
|
||||
public void OnInspectorUpdate()
|
||||
{
|
||||
Repaint();
|
||||
|
|
|
@ -10,6 +10,8 @@ public class TransferFunctionEditorWindow : EditorWindow
|
|||
|
||||
private int selectedColPointIndex = -1;
|
||||
|
||||
private VolumeRenderedObject volRendObject = null;
|
||||
|
||||
[MenuItem("Volume Rendering/1D Transfer Function")]
|
||||
static void ShowWindow()
|
||||
{
|
||||
|
@ -19,6 +21,15 @@ public class TransferFunctionEditorWindow : EditorWindow
|
|||
|
||||
TransferFunctionEditorWindow wnd = (TransferFunctionEditorWindow)EditorWindow.GetWindow(typeof(TransferFunctionEditorWindow));
|
||||
wnd.Show();
|
||||
wnd.SetInitialPosition();
|
||||
}
|
||||
|
||||
private void SetInitialPosition()
|
||||
{
|
||||
Rect rect = this.position;
|
||||
rect.width = 800.0f;
|
||||
rect.height = 500.0f;
|
||||
this.position = rect;
|
||||
}
|
||||
|
||||
private Material tfGUIMat = null;
|
||||
|
@ -28,14 +39,25 @@ public class TransferFunctionEditorWindow : EditorWindow
|
|||
{
|
||||
tfGUIMat = Resources.Load<Material>("TransferFunctionGUIMat");
|
||||
tfPaletteGUIMat = Resources.Load<Material>("TransferFunctionPaletteGUIMat");
|
||||
|
||||
volRendObject = SelectionHelper.GetSelectedVolumeObject();
|
||||
if (volRendObject == null)
|
||||
{
|
||||
volRendObject = GameObject.FindObjectOfType<VolumeRenderedObject>();
|
||||
if(volRendObject != null)
|
||||
Selection.objects = new Object[] { volRendObject.gameObject };
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
VolumeRenderedObject volRend = FindObjectOfType<VolumeRenderedObject>();
|
||||
if (volRend == null)
|
||||
// Update selected object
|
||||
if (volRendObject == null)
|
||||
volRendObject = SelectionHelper.GetSelectedVolumeObject();
|
||||
|
||||
if (volRendObject == null)
|
||||
return;
|
||||
tf = volRend.transferFunction;
|
||||
tf = volRendObject.transferFunction;
|
||||
|
||||
Color oldColour = GUI.color;
|
||||
float bgWidth = Mathf.Min(this.position.width - 20.0f, (this.position.height - 50.0f) * 2.0f);
|
||||
|
@ -115,12 +137,20 @@ public class TransferFunctionEditorWindow : EditorWindow
|
|||
}
|
||||
|
||||
// TEST!!! TODO
|
||||
volRend.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tfTexture);
|
||||
volRend.GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("TF2D_ON");
|
||||
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tfTexture);
|
||||
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("TF2D_ON");
|
||||
|
||||
GUI.color = oldColour;
|
||||
}
|
||||
|
||||
private void OnSelectionChange()
|
||||
{
|
||||
VolumeRenderedObject newVolRendObj = Selection.activeGameObject?.GetComponent<VolumeRenderedObject>();
|
||||
// If we selected another volume object than the one previously edited in this GUI
|
||||
if (volRendObject != null && newVolRendObj != null && newVolRendObj != volRendObject)
|
||||
this.Close();
|
||||
}
|
||||
|
||||
public void OnInspectorUpdate()
|
||||
{
|
||||
Repaint();
|
||||
|
|
|
@ -8,6 +8,7 @@ public class VolumeObjectFactory
|
|||
GameObject obj = GameObject.Instantiate((GameObject)Resources.Load("VolumeRenderedObject"));
|
||||
VolumeRenderedObject volObj = obj.GetComponent<VolumeRenderedObject>();
|
||||
MeshRenderer meshRenderer = obj.GetComponent<MeshRenderer>();
|
||||
meshRenderer.material = new Material(meshRenderer.sharedMaterial);
|
||||
|
||||
volObj.dataset = dataset;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче