<commit_before>#if UNITY_2017_1_OR_NEWER

using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine.Formats.Alembic.Importer;
using UnityEngine.Formats.Alembic.Sdk;
using Object = UnityEngine.Object;

namespace UnityEditor.Formats.Alembic.Importer
{
    internal class AlembicAssetModificationProcessor : UnityEditor.AssetModificationProcessor
    {
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return AssetDeleteResult.DidNotDelete;
            }

            if (Path.GetExtension(assetPath.ToLower()) != ".abc")
                return AssetDeleteResult.DidNotDelete;

            AlembicStream.DisconnectStreamsWithPath(Path.GetFullPath(assetPath));

            return AssetDeleteResult.DidNotDelete;
        }

        public static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (string.IsNullOrEmpty(from))
            {
                return AssetMoveResult.DidNotMove;
            }

            if (Path.GetExtension(from.ToLower()) != ".abc")
                return AssetMoveResult.DidNotMove;
            var streamDstPath = Path.GetFullPath(to);
            var streamSrcPath = Path.GetFullPath(from);
            AlembicStream.DisconnectStreamsWithPath(streamSrcPath);
            AlembicStream.RemapStreamsWithPath(streamSrcPath,streamDstPath);
            
            AssetDatabase.Refresh(ImportAssetOptions.Default);
    		AlembicStream.ReconnectStreamsWithPath(streamDstPath);
 
            return AssetMoveResult.DidNotMove;
        } 
    }

    [ScriptedImporter(3, "abc")]
    internal class AlembicImporter : ScriptedImporter
    {
        [SerializeField]
        private AlembicStreamSettings streamSettings = new AlembicStreamSettings();
        public AlembicStreamSettings StreamSettings
        {
            get { return streamSettings; }
            set { streamSettings = value; }
        }
        [SerializeField]
        private double abcStartTime; // read only
        public double AbcStartTime
        {
            get { return abcStartTime; }
        }
        [SerializeField]
        private double abcEndTime; // read only
        public double AbcEndTime
        {
            get { return abcEndTime; }
        }
        [SerializeField]
        private double startTime = double.MinValue;
        public double StartTime
        {
            get { return startTime; }
            set { startTime = value; }
        }
        [SerializeField]
        private double endTime = double.MaxValue;
        public double EndTime
        {
            get { return endTime; }
            set { endTime = value; }
        }
        [SerializeField]
        private string importWarning;
        public string ImportWarning
        {
            get { return importWarning; }
            set { importWarning = value; }
        }
        [SerializeField]
        private List<string> varyingTopologyMeshNames = new List<string>();
        public List<string> VaryingTopologyMeshNames
        {
            get { return varyingTopologyMeshNames; }
        }
        [SerializeField]
        private List<string> splittingMeshNames = new List<string>();
        public List<string> SplittingMeshNames
        {
            get { return splittingMeshNames; }
        }
        [SerializeField] bool firstImport = true;

        void OnValidate()
        {
            if (!firstImport)
            {
                if (startTime < abcStartTime)
                    startTime = abcStartTime;
                if (endTime > abcEndTime)
                    endTime = abcStartTime;
            }
        }

        public override void OnImportAsset(AssetImportContext ctx)
        {
            if(ctx == null)
            {
                return;
            }
            
            var fullPath = Path.GetFullPath(ctx.assetPath);
            AlembicStream.DisconnectStreamsWithPath(fullPath);

            var fileName = Path.GetFileNameWithoutExtension(fullPath);
            var go = new GameObject(fileName);
            
            var streamDescriptor = ScriptableObject.CreateInstance<AlembicStreamDescriptor>();
            streamDescriptor.name = go.name + "_ABCDesc";
            streamDescriptor.PathToAbc = fullPath;
            streamDescriptor.Settings = StreamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad(true, true);

                abcStream.GetTimeRange(ref abcStartTime, ref abcEndTime);
                if (firstImport)
                {
                    startTime = abcStartTime;
                    endTime = abcEndTime;
                }
                streamDescriptor.abcStartTime = abcStartTime;
                streamDescriptor.abcEndTime = abcEndTime;

                var streamPlayer = go.AddComponent<AlembicStreamPlayer>();
                streamPlayer.StreamDescriptor = streamDescriptor;
                streamPlayer.StartTime = StartTime;
                streamPlayer.EndTime = EndTime;

                var subassets = new Subassets(ctx);
                subassets.Add(streamDescriptor.name, streamDescriptor);
                GenerateSubAssets(subassets, abcStream.abcTreeRoot, streamDescriptor);

                AlembicStream.ReconnectStreamsWithPath(fullPath);

#if UNITY_2017_3_OR_NEWER
                ctx.AddObjectToAsset(go.name, go);
                ctx.SetMainObject(go);
#else
                ctx.SetMainAsset(go.name, go);
#endif
            }

            firstImport = false;
        }

        class Subassets
        {
            AssetImportContext m_ctx;
            Material m_defaultMaterial;
            Material m_defaultPointsMaterial;
            Material m_defaultPointsMotionVectorMaterial;

            public Subassets(AssetImportContext ctx)
            {
                m_ctx = ctx;
            }

            public Material defaultMaterial
            {
                get<commit_msg>The object id's need to be predictable within the prefab.<commit_after>#if UNITY_2017_1_OR_NEWER

using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine.Formats.Alembic.Importer;
using UnityEngine.Formats.Alembic.Sdk;
using Object = UnityEngine.Object;

namespace UnityEditor.Formats.Alembic.Importer
{
    internal class AlembicAssetModificationProcessor : UnityEditor.AssetModificationProcessor
    {
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return AssetDeleteResult.DidNotDelete;
            }

            if (Path.GetExtension(assetPath.ToLower()) != ".abc")
                return AssetDeleteResult.DidNotDelete;

            AlembicStream.DisconnectStreamsWithPath(Path.GetFullPath(assetPath));

            return AssetDeleteResult.DidNotDelete;
        }

        public static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (string.IsNullOrEmpty(from))
            {
                return AssetMoveResult.DidNotMove;
            }

            if (Path.GetExtension(from.ToLower()) != ".abc")
                return AssetMoveResult.DidNotMove;
            var streamDstPath = Path.GetFullPath(to);
            var streamSrcPath = Path.GetFullPath(from);
            AlembicStream.DisconnectStreamsWithPath(streamSrcPath);
            AlembicStream.RemapStreamsWithPath(streamSrcPath,streamDstPath);
            
            AssetDatabase.Refresh(ImportAssetOptions.Default);
    		AlembicStream.ReconnectStreamsWithPath(streamDstPath);
 
            return AssetMoveResult.DidNotMove;
        } 
    }

    [ScriptedImporter(3, "abc")]
    internal class AlembicImporter : ScriptedImporter
    {
        [SerializeField]
        private AlembicStreamSettings streamSettings = new AlembicStreamSettings();
        public AlembicStreamSettings StreamSettings
        {
            get { return streamSettings; }
            set { streamSettings = value; }
        }
        [SerializeField]
        private double abcStartTime; // read only
        public double AbcStartTime
        {
            get { return abcStartTime; }
        }
        [SerializeField]
        private double abcEndTime; // read only
        public double AbcEndTime
        {
            get { return abcEndTime; }
        }
        [SerializeField]
        private double startTime = double.MinValue;
        public double StartTime
        {
            get { return startTime; }
            set { startTime = value; }
        }
        [SerializeField]
        private double endTime = double.MaxValue;
        public double EndTime
        {
            get { return endTime; }
            set { endTime = value; }
        }
        [SerializeField]
        private string importWarning;
        public string ImportWarning
        {
            get { return importWarning; }
            set { importWarning = value; }
        }
        [SerializeField]
        private List<string> varyingTopologyMeshNames = new List<string>();
        public List<string> VaryingTopologyMeshNames
        {
            get { return varyingTopologyMeshNames; }
        }
        [SerializeField]
        private List<string> splittingMeshNames = new List<string>();
        public List<string> SplittingMeshNames
        {
            get { return splittingMeshNames; }
        }
        [SerializeField] bool firstImport = true;

        void OnValidate()
        {
            if (!firstImport)
            {
                if (startTime < abcStartTime)
                    startTime = abcStartTime;
                if (endTime > abcEndTime)
                    endTime = abcStartTime;
            }
        }

        public override void OnImportAsset(AssetImportContext ctx)
        {
            if(ctx == null)
            {
                return;
            }
            
            var fullPath = Path.GetFullPath(ctx.assetPath);
            AlembicStream.DisconnectStreamsWithPath(fullPath);

            var fileName = Path.GetFileNameWithoutExtension(fullPath);
            var go = new GameObject(fileName);
            
            var streamDescriptor = ScriptableObject.CreateInstance<AlembicStreamDescriptor>();
            streamDescriptor.name = go.name + "_ABCDesc";
            streamDescriptor.PathToAbc = fullPath;
            streamDescriptor.Settings = StreamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad(true, true);

                abcStream.GetTimeRange(ref abcStartTime, ref abcEndTime);
                if (firstImport)
                {
                    startTime = abcStartTime;
                    endTime = abcEndTime;
                }
                streamDescriptor.abcStartTime = abcStartTime;
                streamDescriptor.abcEndTime = abcEndTime;

                var streamPlayer = go.AddComponent<AlembicStreamPlayer>();
                streamPlayer.StreamDescriptor = streamDescriptor;
                streamPlayer.StartTime = StartTime;
                streamPlayer.EndTime = EndTime;

                var subassets = new Subassets(ctx);
                subassets.Add(streamDescriptor.name, streamDescriptor);
                GenerateSubAssets(subassets, abcStream.abcTreeRoot, streamDescriptor);

                AlembicStream.ReconnectStreamsWithPath(fullPath);

#if UNITY_2017_3_OR_NEWER
                ctx.AddObjectToAsset("AbcRoot", go);
                ctx.SetMainObject(go);
#else
                ctx.SetMainAsset(go.name, go);
#endif
            }

            firstImport = false;
        }

        class Subassets
        {
            AssetImportContext m_ctx;
            Material m_defaultMaterial;
            Material m_defaultPointsMaterial;
            Material m_defaultPointsMotionVectorMaterial;

            public Subassets(AssetImportContext ctx)
            {
                m_ctx = ctx;
            }

            public Material defaultMaterial
            {
                get
{'fraction_non_alphanumeric': 0.06852506426735218, 'fraction_numerical': 0.0017673521850899742, 'mean_word_length': 1.834471766848816, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507494', 'n_tokens_mistral': 3164, 'n_tokens_neox': 3077, 'n_words': 612}