Esempio n. 1
0
 // SchemaVersion 2: M19
 // Converts data.ModelIndex[].InSet to data.ModelIndex[].RawTransforms[]
 // This changes the behavior slightly: sets are immovable, but RawTransforms[] can be unpinned.
 // This essentially removes the experimental Set feature.
 static void UpgradeSchema_1to2(SketchMetadata data)
 {
     Debug.Assert(data.SchemaVersion == 1);
     if (data.ModelIndex == null)
     {
         return;
     }
     foreach (TiltModels75 tm75 in data.ModelIndex)
     {
         if (!tm75.InSet_deprecated)
         {
             continue;
         }
         // Only one of Transforms[] or RawTransforms[] can be non-null.
         // Therefore, we can only append to RawTransforms[] if Transforms[] is null.
         if (tm75.Transforms != null)
         {
             Debug.LogError("Cannot upgrade InSet if Transforms[] is non-null");
             continue;
         }
         tm75.InSet_deprecated = false;
         tm75.m_rawTransforms  = SafeAppend(tm75.m_rawTransforms, TrTransform.identity);
         tm75.PinStates        = SafeAppend(tm75.PinStates, true);
     }
     data.SchemaVersion = 2;
 }
Esempio n. 2
0
        // 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;
        }
Esempio n. 3
0
        public static void VerifyMetadataVersion(SketchMetadata data)
        {
            Upgrade_Set_ModelIndexInSet(data);

            if (data.SchemaVersion < 1)
            {
                UpgradeSchema_0to1(data);
            }
            if (data.SchemaVersion < 2)
            {
                UpgradeSchema_1to2(data);
            }
        }
Esempio n. 4
0
        /// SchemaVersion 1 was released in M15.
        /// It adds bool[] TiltModels75.PinStates, bool[] TiltModels75.TintStates, bool Guides.State.Pinned
        static void UpgradeSchema_0to1(SketchMetadata data)
        {
            // Pin flags were not written out previous to v15, so default guides to pinned.
            if (data.GuideIndex != null)
            {
                for (int i = 0; i < data.GuideIndex.Length; ++i)
                {
                    for (int j = 0; j < data.GuideIndex[i].States.Length; ++j)
                    {
                        data.GuideIndex[i].States[j].Pinned = true;
                    }
                }
            }

            // Default images to pinned, tinted, and not grouped.
            if (data.ImageIndex != null)
            {
                for (int i = 0; i < data.ImageIndex.Length; ++i)
                {
                    int numXfs = data.ImageIndex[i].Transforms.Length;
                    data.ImageIndex[i].PinStates  = Enumerable.Repeat(true, numXfs).ToArray();
                    data.ImageIndex[i].TintStates = Enumerable.Repeat(true, numXfs).ToArray();
                    data.ImageIndex[i].GroupIds   = Enumerable.Repeat(0u, numXfs).ToArray();
                }
            }

            // Default models to pinned, if they're local.  Poly assets are unpinned.
            if (data.ModelIndex != null)
            {
                for (int i = 0; i < data.ModelIndex.Length; ++i)
                {
                    if (data.ModelIndex[i].PinStates == null)
                    {
                        int numXfs = (data.ModelIndex[i].Transforms != null) ?
                                     data.ModelIndex[i].Transforms.Length :
                                     data.ModelIndex[i].RawTransforms.Length;
                        data.ModelIndex[i].PinStates = new bool[numXfs];
                    }

                    for (int j = 0; j < data.ModelIndex[i].PinStates.Length; ++j)
                    {
                        data.ModelIndex[i].PinStates[j] = (data.ModelIndex[i].Location.GetLocationType() !=
                                                           Model.Location.Type.PolyAssetId);
                    }
                }
            }

            data.SchemaVersion = 1;
        }
        public SketchMetadata ReadMetadata()
        {
            SketchMetadata metadata = null;
            var            stream   = SaveLoadScript.GetMetadataReadStream(this);

            if (stream != null)
            {
                using (var jsonReader = new JsonTextReader(new StreamReader(stream))) {
                    metadata   = SaveLoadScript.m_Instance.DeserializeMetadata(jsonReader);
                    m_SourceId = metadata.SourceId;
                    m_AssetId  = metadata.AssetId;
                }
            }
            return(metadata);
        }