// Converts data.Set_deprecated[] to data.ModelIndex[].InSet static void Upgrade_Set_ModelIndexInSet(SketchMetadata data) { if (data.Set_deprecated == null) { return; } TiltModels75[] index = data.ModelIndex; string[] set = data.Set_deprecated; if (index == null) { index = new TiltModels75[] { }; } List <string> setOnly = new List <string>(set); foreach (TiltModels75 m in index) { if (set.Contains(m.FilePath)) { m.InSet_deprecated = true; setOnly.Remove(m.FilePath); } } index = index.Concat(setOnly.Select(s => new TiltModels75 { FilePath = s, InSet_deprecated = true })).ToArray(); data.ModelIndex = index; data.Set_deprecated = null; }
/// I believe (but am not sure) that Media Library content loads synchronously, /// and PAC content loads asynchronously. public static void CreateFromSaveData(TiltModels75 modelDatas) { Debug.AssertFormat(modelDatas.AssetId == null || modelDatas.FilePath == null, "Model Data should not have an AssetID *and* a File Path"); Debug.AssertFormat(!modelDatas.InSet_deprecated, "InSet should have been removed at load time"); bool ok; if (modelDatas.FilePath != null) { ok = CreateModelsFromRelativePath( modelDatas.FilePath, modelDatas.Transforms, modelDatas.RawTransforms, modelDatas.PinStates, modelDatas.GroupIds); } else if (modelDatas.AssetId != null) { CreateModelsFromAssetId( modelDatas.AssetId, modelDatas.RawTransforms, modelDatas.PinStates, modelDatas.GroupIds); ok = true; } else { Debug.LogError("Model Data doesn't contain an AssetID or File Path."); ok = false; } if (!ok) { ModelCatalog.m_Instance.AddMissingModel( modelDatas.FilePath, modelDatas.Transforms, modelDatas.RawTransforms); } }
public static TiltModels75[] GetTiltModels(GroupIdMapping groupIdMapping) { var widgets = WidgetManager.m_Instance.ModelWidgets.Where(w => w.gameObject.activeSelf).ToArray(); if (widgets.Length == 0 && !ModelCatalog.m_Instance.MissingModels.Any()) { return(null); } var widgetModels = widgets.Select(w => w.Model).Distinct(); Dictionary <Model.Location, List <WidgetMetadata> > modelLocationMap = new Dictionary <Model.Location, List <WidgetMetadata> >(); foreach (var model in widgetModels) { modelLocationMap[model.GetLocation()] = new List <WidgetMetadata>(); } foreach (var widget in widgets) { WidgetMetadata newEntry = new WidgetMetadata(); newEntry.xf = widget.GetSaveTransform(); newEntry.pinned = widget.Pinned; newEntry.groupId = groupIdMapping.GetId(widget.Group); modelLocationMap[widget.Model.GetLocation()].Add(newEntry); } List <TiltModels75> models = new List <TiltModels75>(); foreach (var elem in modelLocationMap) { var val = new TiltModels75 { Location = elem.Key, }; // Order and align the metadata. WidgetMetadata[] ordered = elem.Value.OrderBy(ByTranslation).ToArray(); val.PinStates = new bool[ordered.Length]; val.RawTransforms = new TrTransform[ordered.Length]; val.GroupIds = new uint[ordered.Length]; for (int i = 0; i < ordered.Length; ++i) { val.PinStates[i] = ordered[i].pinned; val.RawTransforms[i] = ordered[i].xf; val.GroupIds[i] = ordered[i].groupId; } models.Add(val); } return(models .Concat(ModelCatalog.m_Instance.MissingModels) .OrderBy(ByModelLocation).ToArray()); }
private static string ByModelLocation(TiltModels75 models) { if (models.AssetId != null) { return("AssetId:" + models.AssetId); } else if (models.FilePath != null) { return("FilePath:" + models.FilePath); } Debug.LogWarning("Attempted to save model without asset id or filepath"); return(""); }