-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from MicroscopeIT/marekz/rebase-integration-vo…
…lumetric-data Integration of volumetric data visualization and conversion
- Loading branch information
Showing
36 changed files
with
6,525 additions
and
38,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...processing/Assets/Editor/InputConfiguration.cs~HOL-44 Added argument parsing and log.meta
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
unity/EVPreprocessing/Assets/Editor/ModelImport/VolumetricModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...etBundles/AssetBundleEditorLoader.cs.meta → ...ditor/ModelImport/VolumetricModel.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
unity/EVPreprocessing/Assets/Scripts/models_collection/VolumetricModelLayer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
11 changes: 11 additions & 0 deletions
11
unity/EVPreprocessing/Assets/Scripts/models_collection/VolumetricModelLayer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
unity/EVPreprocessing/Assets/StreamingAssets/AssetBundlesFromVTK.meta
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.