Ejemplo n.º 1
0
 static void ProcessAfterImport(PolyGraph graph)
 {
     using (TimeCount.Start("Resolve Regions"))
         RegionResolver.Resolve(graph);
     using (TimeCount.Start("Create Wireframe"))
         WireframeCreator.Create(graph);
     using (TimeCount.Start("Saving initial snapshot"))
         Others.SaveInitialSnapshot(graph);
 }
Ejemplo n.º 2
0
    static bool ConnectedCheck(PolyGraph graph, List <GameObject> gameObjects)
    {
        var xforms   = gameObjects.ConvertAll(v => v.transform).ToArray();
        var resolver = new RegionResolver(graph);

        resolver.Collect(xforms);
        resolver.CalculateTriangleAdjacents();
        resolver.CalculateRegionAdjacents();

        List <int>            regionIndexs     = Enumerable.Range(0, resolver.regions.Count).ToList();
        List <List <string> > connectedRegions = new List <List <string> >();

        while (regionIndexs.Count > 0)
        {
            List <string> connected = new List <string>();
            Queue <int>   queue     = new Queue <int>();
            queue.Enqueue(regionIndexs[0]);
            while (queue.Count > 0)
            {
                int i = queue.Dequeue();
                regionIndexs.Remove(i);
                var region = resolver.regions[i];
                connected.Add(region.name);
                foreach (int adj in region.adjacents)
                {
                    if (regionIndexs.Contains(adj) && !queue.Contains(adj))
                    {
                        queue.Enqueue(adj);
                    }
                }
            }
            connectedRegions.Add(connected);
        }

        if (connectedRegions.Count > 1)
        {
            var log = new StringBuilder("Selected regions are not all connected, connected regions are:\n");
            foreach (var names in connectedRegions)
            {
                log.AppendFormat("{{ {0} }}\n", string.Join(", ", names));
            }
            Debug.LogError(log);
            return(false);
        }
        else
        {
            return(true);
        }
    }
Ejemplo n.º 3
0
    public static void Resolve(PolyGraph graph)
    {
        Transform[] xforms = new Transform[graph.transform.childCount];
        for (int i = 0; i < graph.transform.childCount; ++i)
        {
            xforms[i] = graph.transform.GetChild(i);
        }

        var resolver = new RegionResolver(graph);

        resolver.Collect(xforms);
        resolver.CalculateTriangleAdjacents();
        resolver.CalculateRegionAdjacents();
        resolver.CalculateRegionBorderEdges();
        resolver.Apply();
    }
Ejemplo n.º 4
0
    void Save()
    {
        if (!IsEditing)
        {
            return;
        }

        try
        {
            using (TimeCount.Start("Saving " + info.editObj.name))
            {
                EditorUtility.DisplayProgressBar("Saving " + info.editObj.name, "Copying instance", 0f);
                GameObject copy = null;
                using (TimeCount.Start("Copying instance"))
                {
                    copy      = GameObject.Instantiate <GameObject>(info.editObj);
                    copy.name = info.editObj.name;
                }

                EditorUtility.DisplayProgressBar("Saving " + info.editObj.name, "Destroying inactive meshes", 0.25f);
                using (TimeCount.Start("Destroying inactive meshes"))
                {
                    GameObject.DestroyImmediate(copy.GetComponent <MeshPicker>());
                    var inactiveMeshes = copy.GetComponentsInChildren <MeshFilter>(true).Where(v => !v.gameObject.activeSelf);
                    foreach (var m in inactiveMeshes)
                    {
                        GameObject.DestroyImmediate(m.gameObject);
                    }
                }

                EditorUtility.DisplayProgressBar("Saving " + info.editObj.name, "Resolving regions & create wireframe", 0.5f);
                var polyGraph = copy.GetComponent <PolyGraph>();
                using (TimeCount.Start("Recenter Graph"))
                    RecenterGraph(polyGraph);
                using (TimeCount.Start("Resolve Regions"))
                    RegionResolver.Resolve(polyGraph);
                using (TimeCount.Start("Create Wireframe"))
                    WireframeCreator.Create(polyGraph);
                using (TimeCount.Start("Saving initial snapshot"))
                    Others.SaveInitialSnapshot(polyGraph);

                EditorUtility.DisplayProgressBar("Saving " + info.editObj.name, "Saving prefab", 0.75f);
                using (TimeCount.Start("Saving prefab"))
                {
                    string             path   = string.Format("{0}/{1}/{1}.prefab", Paths.AssetResArtworks, copy.name);
                    UnityEngine.Object prefab = PrefabUtility.CreatePrefab(path, copy);
                    PrefabUtility.ReplacePrefab(copy, prefab, ReplacePrefabOptions.ConnectToPrefab);
                }

                using (TimeCount.Start("Saving assets"))
                {
                    GameObject.DestroyImmediate(copy);
                    AssetDatabase.SaveAssets();
                }
                unsavedModification = false;
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
    }
Ejemplo n.º 5
0
 protected override void Context()
 {
     _container = A.Fake <IContainer>();
     sut        = new RegionResolver(_container);
 }