AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
VolumeInformationEditor.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEditor;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity
9 {
14  [CustomEditor(typeof(VolumeInformation))]
15  public class VolumeInformationEditor : Editor
16  {
17  public override void OnInspectorGUI()
18  {
19  var volInfo = this.target as VolumeInformation;
20 
21  base.OnInspectorGUI();
22 
23  if (GUILayout.Button("Bake"))
24  {
25  if (volInfo == null)
26  {
27  throw new ArgumentNullException();
28  }
29 
30  var texPath = EditorUtility.SaveFilePanel("Save volume", Application.dataPath, "volume", "asset");
31  texPath = texPath.Replace(Application.dataPath, "Assets");
32 
33  AssetDatabase.DeleteAsset(texPath);
34  AssetDatabase.SaveAssets();
35  AssetDatabase.Refresh();
36 
37  var size = Int3.zero;
38  var bakedSliceData = VolumeImportImages.ConvertFolderToVolume(Application.dataPath + volInfo.ImageSourceFolder,
39  volInfo.InferAlpha, out size);
40 
41  if (volInfo.AutoSizeOnBake)
42  {
43  volInfo.Size = size;
44  }
45 
46  var volumeSizePow2 = MathExtensions.PowerOfTwoGreaterThanOrEqualTo(volInfo.Size);
47  var tex3D = VolumeTextureUtils.BuildTexture(bakedSliceData, volInfo.Size, volumeSizePow2);
48 
49  AssetDatabase.CreateAsset(tex3D, texPath);
50  AssetDatabase.SaveAssets();
51 
52  volInfo.BakedTexture = AssetDatabase.LoadAssetAtPath<Texture3D>(texPath);
53 
54  Debug.Log("Baked volume to: " + texPath);
55 
56  EditorUtility.SetDirty(volInfo);
57  }
58  }
59  }
60 }
Holds data about a volume asset
Editor script for editor configuration of volume files Conversion of stacked images to volumes happen...
static readonly Int3 zero
Definition: Int3.cs:18
static Texture3D BuildTexture(byte[] data, Int3 volumeSize, Int3 volumeSizePow2)
static int PowerOfTwoGreaterThanOrEqualTo(this int v)
Extension methods and helper functions for various math data
3D integer class - operates similarly to Unity&#39;s Vector3D
Definition: Int3.cs:16
Helper functions for dealing with volume data