Skip to content

Commit

Permalink
Merge pull request #55 from MicroscopeIT/marekz/rebase-integration-vo…
Browse files Browse the repository at this point in the history
…lumetric-data

Integration of volumetric data visualization and conversion
  • Loading branch information
ellendil authored Mar 3, 2020
2 parents d6b8f4c + c020e30 commit dc0d42b
Show file tree
Hide file tree
Showing 36 changed files with 6,525 additions and 38,398 deletions.
9 changes: 9 additions & 0 deletions unity/EVPreprocessing/Assets/Editor/DataPreparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public static void ImportWithConversion()
importDispatcher.PrepareData("ConversionRequired");
}

[MenuItem("EVPreprocessing/Create an AssetBundle from volumetric data")]
public static void ImportVolumetric()
{
var importDispatcher = new DataPreparator();
importDispatcher.PrepareData("VolumetricModel");
}

[MenuItem("EVPreprocessing/Create an AssetBundle from converted data")]
public static void ImportConvertedModel()
{
Expand Down Expand Up @@ -79,6 +86,8 @@ private ModelImport.ModelImporter InitializeModelImporter(string modelType, Mode
return new ConvertedModel(modelConverter.OutputRootDir);
case "ConvertedModel":
return new ConvertedModel(rootDirectory);
case "VolumetricModel":
return new VolumetricModel(rootDirectory);
default:
throw Log.ThrowError("Incorrect ModelImporter type declared!", new IOException());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ protected void AddLayerComponent(GameObject go, ModelLayerInfo layerInfo)
ModelLayer layer = go.AddComponent<ModelLayer>();
layer.Caption = layerInfo.Caption;
layer.Simulation = CheckIfSimulation(layerInfo.DataType);
layer.DataType = GetDataType(layerInfo.DataType);
}

private DataType GetDataType(string layerDataType)
{
return layerDataType == "volumetric" ? DataType.Volumetric : DataType.Mesh;
}

private bool CheckIfSimulation(string simulationFlag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public class ModelLayerInfo
public string AssetFileName;
public bool UseAsIcon;
}

public class VolumetricMedata
{
public int width;
public int height;
public int depth;
public int channels;
}
}
97 changes: 97 additions & 0 deletions unity/EVPreprocessing/Assets/Editor/ModelImport/VolumetricModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using ModelImport;
using Newtonsoft.Json;

namespace ModelImport
{
public class VolumetricModel : ModelImporter
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public VolumetricModel(string rootDirectory) : base(rootDirectory) { }

protected override void ImportLayer(ModelLayerInfo layerInfo)
{
string objectName = Info.Caption + "_" + Path.GetFileName(layerInfo.Directory);
GameObject modelGameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
ImportData(modelGameObject, layerInfo);
AddLayerComponent(modelGameObject, layerInfo);
SaveFilesForExport(modelGameObject, layerInfo, objectName);
}

private void ImportData(GameObject modelGameObject, ModelLayerInfo layerInfo)
{
// FIXME: Scale of display cube should depend on scale of data and should be set at load !!!
modelGameObject.transform.localScale = new Vector3(0.9f, 0.9f, 0.1f);
VolumetricMedata metadata;
using (StreamReader r = new StreamReader(layerInfo.Directory + @"\" + "metadata.json"))
{
string json = r.ReadToEnd();
metadata = JsonConvert.DeserializeObject<VolumetricMedata>(json);
}

VolumetricModelLayer modelLayer = modelGameObject.AddComponent<VolumetricModelLayer>();
modelLayer.Width = metadata.width;
modelLayer.Height = metadata.height;
modelLayer.Depth = metadata.depth;
modelLayer.Channels = metadata.channels;
}

// Prepare the go for taking preview icon.
// We need to configure blend shapes state, material -- otherwise icon would look bad.
private void PrepareForPreview(GameObject go)
{
// FIXME: Preview icon generation !!!
//MeshRenderer renderer = go.GetComponent<MeshRenderer>();
//if (renderer != null &&
// renderer.sharedMesh != null &&
// renderer.sharedMesh.blendShapeCount != 0)
//{
// renderer.SetBlendShapeWeight(0, 100f);
// Material defaultMaterial = AssetDatabase.LoadAssetAtPath<Material>(DefaultMaterialAsset);
// if (defaultMaterial == null)
// {
// throw new Exception("Cannot read default material asset from " + DefaultMaterialAsset);
// }
// renderer.material = defaultMaterial;
//}
}

// Saves imported model to a Unity-friendly files, to be put in AssetBundles.
private void SaveFilesForExport(GameObject modelGameObject, ModelLayerInfo layerInfo, string objectName)
{
string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;
AssetDirs.CreateAssetDirectory(rootAssetsDir);

Mesh modelMesh = modelGameObject.GetComponent<MeshFilter>().mesh;
string meshPath = rootAssetsDir + "/" + objectName + ".asset";
AssetPaths.Add(meshPath);
AssetDatabase.CreateAsset(modelMesh, meshPath);

string rawDataPath = layerInfo.Directory + @"\" + "data.raw";
// This is strange to copy data first as Asset then copy asset to build dir
string tmpDataPath = rootAssetsDir + "/tmp_data.bytes";
string dataPath = rootAssetsDir + "/" + objectName + "_data.bytes";

if (File.Exists(tmpDataPath))
FileUtil.DeleteFileOrDirectory(tmpDataPath);
FileUtil.CopyFileOrDirectory(rawDataPath, tmpDataPath);
AssetPaths.Add(dataPath);
AssetDatabase.Refresh();
AssetDatabase.CopyAsset(tmpDataPath, dataPath);


string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab";
AssetPaths.Add(gameObjectPath);
PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath);

if (layerInfo.UseAsIcon) {
PrepareForPreview(modelGameObject);
LayerAutomaticIconGenerate(modelGameObject);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions unity/EVPreprocessing/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ LightmapSettings:
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
Expand Down Expand Up @@ -117,7 +116,8 @@ NavMeshSettings:
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 170076735}
Expand All @@ -133,7 +133,8 @@ GameObject:
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 170076733}
m_Enabled: 1
serializedVersion: 8
Expand Down Expand Up @@ -170,7 +171,8 @@ Light:
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 170076733}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
Expand All @@ -183,7 +185,8 @@ Transform:
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 534669905}
Expand All @@ -200,14 +203,16 @@ GameObject:
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 534669902}
m_Enabled: 1
--- !u!20 &534669904
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 534669902}
m_Enabled: 1
serializedVersion: 2
Expand Down Expand Up @@ -248,7 +253,8 @@ Camera:
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 534669902}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
/* Information about layer.
* It should be present in asset bundle for each GameObject representing a layer.
*/

public enum DataType
{
Mesh,
Volumetric
}

public class ModelLayer : MonoBehaviour
{
// Nice name to show to user.
public string Caption;

// Type of data to be visualized
public DataType DataType;

// Is this a simulation layer (using simulation shader etc.)
public bool Simulation;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;

/* Information about layer.
* It should be present in asset bundle for each GameObject representing a layer.
*/
public class VolumetricModelLayer : MonoBehaviour
{
// Data width
public int Width;

// Data height
public int Height;

// Data depth
public int Depth;

// Number of channles in data
public int Channels;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

8 changes: 0 additions & 8 deletions unity/Holo/Assets/GFX/Left and Right Epicardium.meta

This file was deleted.

Loading

0 comments on commit dc0d42b

Please sign in to comment.