public void LoadVolumetricData() { if (!layers.All(x => x.GetComponent <ModelLayer>().DataType == DataType.Volumetric)) { Debug.LogWarning("Missing volumetric data in AssetBundle during LoadVolumetricData call."); return; } Color ch1 = new Color(1, 0, 0); Color ch2 = new Color(0, 1, 0); Color ch3 = new Color(0, 0, 1); Color ch4 = new Color(1, 0, 1); foreach (ModelLayer l in layers) { l.gameObject.GetComponent <MeshRenderer>().sharedMaterial = VolumetricMaterial; string budleName = l.name + "_data.bytes"; TextAsset bytesAsset = assetBundle.LoadAsset(budleName) as TextAsset; VolumetricModelLayer volumetricLayer = l.gameObject.GetComponent <VolumetricModelLayer>(); VolumetricLoader loader = l.gameObject.AddComponent <VolumetricLoader>(); loader.Width = volumetricLayer.Width; loader.Height = volumetricLayer.Height; loader.Depth = volumetricLayer.Depth; loader.Channels = volumetricLayer.Channels; // Calculate scale ratios. Bases: w - 512, h - 512, d - 20 float w_ratio = (float)loader.Width / 512.0f; float h_ratio = (float)loader.Height / 512.0f; float d_ratio = (float)loader.Depth / 20.0f; // Set rescalled "canvas". Bases: x - 0.9, y - 0.9, z - 0.1 l.gameObject.transform.localScale = new Vector3((0.9f * w_ratio), (0.9f * h_ratio), (0.1f * d_ratio)); if (loader.Channels > 0) { loader.channel1 = ch1; } if (loader.Channels > 1) { loader.channel2 = ch2; } if (loader.Channels > 2) { loader.channel3 = ch3; } if (loader.Channels > 3) { loader.channel4 = ch4; } if (!loader.IsModelTextureCalculated()) { Debug.Log("Loading Volumetric - bytes size: " + bytesAsset.bytes.Length.ToString()); loader.SetRawBytes(bytesAsset.bytes); } } }
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; }