示例#1
0
 private GridMap(VertexMap vertexMap)
 {
     VertexMap = vertexMap;
     GridSizeX = VertexMap.SizeX - 1;
     GridSizeZ = VertexMap.SizeZ - 1;
     Cells     = new Cell[GridSizeX, GridSizeZ];
 }
示例#2
0
    public static GridMap GenerateGrid(VertexMap vertexMap)
    {
        var gridMap = new GridMap(vertexMap);

        for (var x = 0; x < gridMap.GridSizeX; x++)
        {
            for (var z = 0; z < gridMap.GridSizeZ; z++)
            {
                var i = x * gridMap.VertexMap.SizeX + z;

                if (x < gridMap.GridSizeX && z < gridMap.GridSizeZ)
                {
                    gridMap.Cells[x, z] = new Cell(
                        gridMap,
                        new [] {
                        i,
                        i + 1,
                        i + gridMap.VertexMap.SizeX + 1,
                        i + gridMap.VertexMap.SizeX
                    }
                        );
                }
            }
        }

        return(gridMap);
    }
示例#3
0
    public MeshData(VertexMap vertexMap)
    {
        m_VertexMap = vertexMap;
        m_Triangles = GenerateTriangles(m_VertexMap);

        m_Mesh = new Mesh {
            vertices = m_VertexMap.Vertices, triangles = m_Triangles
        };
        m_Mesh.RecalculateNormals();
    }
示例#4
0
    private int[] GenerateTriangles(VertexMap vertexMap)
    {
        var cellCount = (vertexMap.SizeX - 1) * (vertexMap.SizeZ - 1);
        var triangles = new int[cellCount * 6];

        for (var i = 0; i < cellCount; i++)
        {
            //var vertexIndex = cell.VertexIndex;
            //AddTriangle(vertexIndex[0], vertexIndex[2], vertexIndex[3]);
            //AddTriangle(vertexIndex[0], vertexIndex[1], vertexIndex[2]);
        }

        return(triangles);
    }
示例#5
0
    public static VertexMap GenerateVertexMap(int sizeX, int sizeZ)
    {
        var vertexMap = new VertexMap(sizeX, sizeZ);

        for (var x = 0; x < vertexMap.SizeX; x++)
        {
            for (var z = 0; z < vertexMap.SizeZ; z++)
            {
                vertexMap.Vertices[x * sizeX + z] = new Vector3(x, 0, z);
            }
        }

        return(vertexMap);
    }
示例#6
0
        /// <summary>
        /// Extract vertex maps for all MCS conten, or only selected folders if useSelection == true.
        /// </summary>
        public static void ExtractVertexMaps(bool useSelection)
        {
            List <GameObject> content = GetContent(useSelection);

            if (content.Count == 0)
            {
                return;
            }

            _activeProcess         = new ContentProcessor("Extract", content, true);
            _activeProcess.Process = delegate() {
                GameObject obj = _activeProcess.GetObject();
                if (obj == null)
                {
                    return;
                }

                CoreMesh[] meshes = obj.GetComponentsInChildren <CoreMesh>();
                foreach (CoreMesh mesh in meshes)
                {
                    string collection = GetCollectionName(mesh.runtimeMorphPath);

                    //_activeProcess.status = collection + ":" + mesh.name;

                    SkinnedMeshRenderer smr = mesh.GetComponent <SkinnedMeshRenderer>();
                    if (smr != null)
                    {
                        string collectionConversionMapPath = _conversionMapPath + ((string.IsNullOrEmpty(collection) ? "" : "/" + collection));
                        Directory.CreateDirectory(collectionConversionMapPath);

                        VertexMap vertexMap = new VertexMap(smr.sharedMesh.vertices);
                        vertexMap.WriteToDisk(collectionConversionMapPath + "/" + mesh.name + ".json");
                    }
                }

                if (_activeProcess.isLast)
                {
                    if (EditorUtility.DisplayDialog("Complete!", "Extracted vertex maps were saved in Assets/MCS/ConversionMaps.\nYou can copy the files to your new Unity project.", "Show in Explorer", "Close"))
                    {
                        EditorUtility.RevealInFinder(_conversionMapPath);
                    }
                }
            };
        }
示例#7
0
        public List <T> BellmanFord(T startValue, T endValue)
        {
            Vertex <T> startingVertex = Find(startValue);
            Vertex <T> endingVertex   = Find(endValue);
            List <T>   returnList     = new List <T>();

            if (startingVertex == null || endingVertex == null)
            {
                return(returnList);
            }

            Dictionary <Vertex <T>, (int distance, Vertex <T> parent, bool wasVisited)> VertexMap = new Dictionary <Vertex <T>, (int distance, Vertex <T> parent, bool wasVisited)>();

            foreach (Vertex <T> vertex in vertices)
            {
                VertexMap.Add(vertex, (int.MaxValue, null, false));
            }
            ChangeMap(VertexMap, startingVertex, 0);

            HeapTree <Vertex <T> > PriorityQueue = new HeapTree <Vertex <T> >(Comparer <Vertex <T> > .Create((a, b) => VertexMap[a].distance.CompareTo(VertexMap[b].distance)));

            PriorityQueue.Add(startingVertex);

            Dijkstra(PriorityQueue, VertexMap, endingVertex);

            Vertex <T> currentVertex = endingVertex;

            while (VertexMap[currentVertex].parent != null)
            {
                returnList.Add(currentVertex.Value);
                currentVertex = VertexMap[currentVertex].parent;
            }
            if (returnList.Count != 0)
            {
                returnList.Add(startingVertex.Value);
            }


            return(returnList);
        }
示例#8
0
        public List <T> Dijkstra(T startValue, T endValue)
        {
            Vertex <T> startingVertex = Find(startValue);
            Vertex <T> endingVertex   = Find(endValue);

            List <T> returnList = new List <T>();

            if (startingVertex == null || endingVertex == null)
            {
                return(returnList);
            }

            Dictionary <Vertex <T>, (int distance, Vertex <T> parentVertex, bool wasVisited)> VertexMap = new Dictionary <Vertex <T>, (int, Vertex <T>, bool)>();


            foreach (Vertex <T> vertex in Vertices)
            {
                VertexMap.Add(vertex, (int.MaxValue, null, false));
            }
            VertexMap[startingVertex] = (0, null, false);

            var PriorityQueue = new HeapTree <Vertex <T> >(Comparer <Vertex <T> > .Create((a, b) => VertexMap[a].distance.CompareTo(VertexMap[b].distance)));

            PriorityQueue.Add(startingVertex);
            Dijkstra(PriorityQueue, VertexMap, endingVertex);

            Vertex <T> currentVertex = endingVertex;

            while (VertexMap[currentVertex].Item2 != null)
            {
                returnList.Add(currentVertex.Value);
                currentVertex = VertexMap[currentVertex].Item2;
            }
            returnList.Add(startingVertex.Value);
            return(returnList);
        }
示例#9
0
        public VertexMap Cut(double move)
        {
            this.vertexMap = new VertexMap(this.mesh);
            this.edgeQueue = new Queue<VertexPair>();
            this.move = move;
            
            foreach (var edge in this.mesh.Edges)
            {
                if (edge.Traits.SelectedFlag != 0)
                {
                    this.edgeQueue.Enqueue(new VertexPair(edge.Vertex0, edge.Vertex1));
                }
            }

            bool boundary = false;
            foreach (var edge in this.edgeQueue)
            {
                if (edge.Src.OnBoundary || edge.Dst.OnBoundary)
                {
                    boundary = true;
                    break;
                }
            }

            if (!boundary)
            {
                this.CutStart();
            }

            int count = 1;
            while (this.edgeQueue.Count != 0 && count < this.edgeQueue.Count)
            {
                VertexPair pair = this.edgeQueue.Dequeue();
                TriMesh.Edge edge = pair.Src.FindEdgeTo(pair.Dst);
                if (edge != null)
                {
                    if (this.Cut(edge))
                    {
                        count = 0;
                    }
                    else
                    {
                        this.edgeQueue.Enqueue(pair);
                        count++;
                    }
                }
                else
                {
                    TriMesh.Vertex[] map1 = this.vertexMap.GetOther(pair.Src, false);
                    TriMesh.Vertex[] map2 = this.vertexMap.GetOther(pair.Dst, false);

                    for (int m = 0; m < map1.Length; m++)
                    {
                        this.edgeQueue.Enqueue(new VertexPair(map1[m], pair.Dst));
                    }

                    for (int n = 0; n < map2.Length; n++)
                    {
                        this.edgeQueue.Enqueue(new VertexPair(pair.Src, map2[n]));
                    }

                    for (int m = 0; m < map1.Length; m++)
                    {
                        for (int n = 0; n < map2.Length; n++)
                        {
                            this.edgeQueue.Enqueue(new VertexPair(map1[m], map2[n]));
                        }
                    }
                    count = 0;
                }
            }
            TriMeshUtil.FixIndex(mesh);
          
            return this.vertexMap;
        }
示例#10
0
            private static ImportedMesh ImportMeshList(List <MqoObject> mqoObjects, List <string> mqoMaterials)
            {
                ImportedMesh meshList = new ImportedMesh();

                meshList.Name = mqoObjects[0].name;
                float scale = 1f;

                if (!mqoObjects[0].worldCoords)
                {
                    int startPos = meshList.Name.IndexOf("(Scale=");
                    if (startPos > 0)
                    {
                        int endPos = meshList.Name.IndexOf(')');
                        scale = 1f / Single.Parse(meshList.Name.Substring(startPos + 7, endPos - startPos - 7));
                    }
                }
                meshList.BoneList    = new List <ImportedBone>(0);
                meshList.SubmeshList = new List <ImportedSubmesh>(mqoObjects.Count);

                int vertIdx = 0;

                foreach (MqoObject mqoObject in mqoObjects)
                {
                    List <VertexMap>[]            vertexMapList = new List <VertexMap> [mqoMaterials.Count + 1];
                    Dictionary <int, VertexMap>[] vertexMapDic  = new Dictionary <int, VertexMap> [mqoMaterials.Count + 1];
                    List <VertexMap[]>[]          faceMap       = new List <VertexMap[]> [mqoMaterials.Count + 1];
                    foreach (MqoFace mqoFace in mqoObject.faces)
                    {
                        int mqoFaceMatIdxOffset = mqoFace.materialIndex + 1;
                        if (vertexMapList[mqoFaceMatIdxOffset] == null)
                        {
                            vertexMapList[mqoFaceMatIdxOffset] = new List <VertexMap>(mqoObject.vertices.Length);
                            vertexMapDic[mqoFaceMatIdxOffset]  = new Dictionary <int, VertexMap>();
                            faceMap[mqoFaceMatIdxOffset]       = new List <VertexMap[]>(mqoObject.faces.Length);
                        }

                        VertexMap[] faceMapArray = new VertexMap[mqoFace.vertexIndices.Length];
                        faceMap[mqoFaceMatIdxOffset].Add(faceMapArray);
                        for (int i = 0; i < mqoFace.vertexIndices.Length; i++)
                        {
                            VertexMap vertMap;
                            if (!vertexMapDic[mqoFaceMatIdxOffset].TryGetValue(mqoFace.vertexIndices[i], out vertMap))
                            {
                                ImportedVertex vert;
                                MqoVertex      mqoVert = mqoObject.vertices[mqoFace.vertexIndices[i]];
                                if (mqoVert is MqoVertexWithColour)
                                {
                                    vert = new ImportedVertexWithColour();
                                    ((ImportedVertexWithColour)vert).Colour = ((MqoVertexWithColour)mqoVert).colour;
                                }
                                else
                                {
                                    vert = new ImportedVertex();
                                }
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoVert.coords * scale;

                                vertMap = new VertexMap {
                                    mqoIdx = mqoFace.vertexIndices[i], vert = vert
                                };
                                vertexMapDic[mqoFaceMatIdxOffset].Add(mqoFace.vertexIndices[i], vertMap);
                                vertMap.uvDic.Add(mqoFace.UVs[i], vertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(vertMap);
                            }

                            VertexMap uvVertMap;
                            if (!vertMap.uvDic.TryGetValue(mqoFace.UVs[i], out uvVertMap))
                            {
                                ImportedVertex vert = new ImportedVertex();
                                vert.BoneIndices = new byte[4];
                                vert.Weights     = new float[4];
                                vert.Normal      = new Vector3();
                                vert.UV          = mqoFace.UVs[i];
                                vert.Position    = mqoObject.vertices[mqoFace.vertexIndices[i]].coords;

                                uvVertMap = new VertexMap {
                                    mqoIdx = Int32.MaxValue, vert = vert
                                };
                                vertMap.uvDic.Add(mqoFace.UVs[i], uvVertMap);
                                vertexMapList[mqoFaceMatIdxOffset].Add(uvVertMap);
                            }

                            faceMapArray[i] = uvVertMap;
                        }
                    }

                    for (int i = 0; i < vertexMapList.Length; i++)
                    {
                        if (vertexMapList[i] != null)
                        {
                            ImportedSubmesh mesh = new ImportedSubmesh();
                            mesh.VertexList  = new List <ImportedVertex>(vertexMapList[i].Count);
                            mesh.FaceList    = new List <ImportedFace>(faceMap[i].Count);
                            mesh.Index       = mqoObject.baseIdx;
                            mesh.WorldCoords = mqoObject.worldCoords;
                            mesh.Visible     = mqoObject.visible;
                            int matIdx = i - 1;
                            if ((matIdx >= 0) && (matIdx < mqoMaterials.Count))
                            {
                                mesh.Material = mqoMaterials[matIdx];
                            }
                            meshList.SubmeshList.Add(mesh);

                            vertexMapList[i].Sort();
                            for (int j = 0; j < vertexMapList[i].Count; j++)
                            {
                                vertexMapList[i][j].wsMeshIdx = j;
                                mesh.VertexList.Add(vertexMapList[i][j].vert);
                                vertIdx++;
                            }

                            for (int j = 0; j < faceMap[i].Count; j++)
                            {
                                ImportedFace face = new ImportedFace();
                                face.VertexIndices = new int[] { faceMap[i][j][0].wsMeshIdx, faceMap[i][j][2].wsMeshIdx, faceMap[i][j][1].wsMeshIdx };
                                mesh.FaceList.Add(face);
                            }
                        }
                    }
                }

                return(meshList);
            }
示例#11
0
 private void Start()
 {
     vertexMap = VertexMap.GenerateVertexMap(width, length);
     gridMap   = GridMap.GenerateGrid(vertexMap);
     meshData  = new MeshData(vertexMap);
 }
示例#12
0
        /// <summary>
        /// Remaps morph data for all MCS content, or only selected folders if useSelection == true.
        /// </summary>
        public static void ConvertMorphData(bool useSelection)
        {
            if (!useSelection)
            {
                if (!EditorUtility.DisplayDialog("Warning", "This will attempt to convert all MCS morph data in your project. This process is nonreversible.\nAre you sure?", "Yes", "Cancel"))
                {
                    return;
                }
            }

            List <GameObject> content = GetContent(useSelection);

            if (content.Count == 0)
            {
                return;
            }

            // Load common conversion tools and data
            _conversionData = new ConversionData();

            _activeProcess         = new ContentProcessor("Convert", content, true);
            _activeProcess.Process = delegate() {
                GameObject obj = _activeProcess.GetObject();
                if (obj == null)
                {
                    return;
                }

                CoreMesh[] meshes = obj.GetComponentsInChildren <CoreMesh>();
                foreach (CoreMesh mesh in meshes)
                {
                    //_activeProcess.status = mesh.name + " : Checking...";
                    _conversionData.CreateReport(mesh.name);

                    // Check if already converted
                    if (_conversionData.GetMorphData(mesh.runtimeMorphPath, "_2019compatible") != null)
                    {
                        _conversionData.CloseReport("Skipped (already converted)");
                        continue;
                    }

                    // Check smr
                    SkinnedMeshRenderer smr = mesh.GetComponent <SkinnedMeshRenderer>();
                    if (smr == null)
                    {
                        _conversionData.CloseReport("Skipped (no SkinnedMeshRenderer found)");
                        continue;
                    }

                    // Check for original vertex map
                    string vmPath = "";
                    foreach (string path in _conversionData.vertexMaps)
                    {
                        if (path.Contains(mesh.name + ".json"))
                        {
                            vmPath = path;
                            break;
                        }
                    }
                    if (vmPath == "")
                    {
                        _conversionData.CloseReport("Skipped (no vertex map found)");
                        continue;
                    }

                    // Create temp directory for generated .morph files
                    string morphPath = Path.Combine(Application.streamingAssetsPath, mesh.runtimeMorphPath);
                    Directory.CreateDirectory(morphPath);

                    // Run process
                    try {
                        // Read vertex map
                        string    mapData   = File.ReadAllText(vmPath);
                        VertexMap vertexMap = JsonUtility.FromJson <VertexMap>(mapData);

                        // Generate retarget map
                        //_activeProcess.status = mesh.name + " : Generating Target Map...";
                        Dictionary <int, int> ttsMap = _conversionData.projectionMeshMap.GenerateTargetToSourceMap(vertexMap.vertices, smr.sharedMesh.vertices);

                        // Get manifest
                        var manifest = _conversionData.GetManifestForCoreMesh(mesh, _manifestSelectionMethod);

                        // Process morphs
                        int           n          = 0;
                        int           total      = manifest.names.Length;
                        List <string> morphNames = new List <string>(manifest.names);
                        morphNames.Add("base"); // Add "base" morph that's not in the manifest but is required for clothing and hair

                        foreach (string morph in morphNames)
                        {
                            //_activeProcess.status = string.Format("{0} : Processing Morph {1}/{2}", mesh.name, n, total);
                            n++;

                            MorphData source = _conversionData.GetMorphData(morphPath, morph); // Not all assets will have all morphs
                            if (source != null)
                            {
                                // Retarget morphs
                                MorphData target = RemapMorphData(smr, source, ttsMap);
                                // Save new .morph file
                                MCS_Utilities.MorphExtraction.MorphExtraction.WriteMorphDataToFile(target, morphPath + "/" + target.name + ".morph", false, false);
                            }
                        }

                        // Inject evidence of conversion so we don't accidentally remap again.
                        MorphData note = new MorphData();
                        note.name = "_2019compatible";
                        MCS_Utilities.MorphExtraction.MorphExtraction.WriteMorphDataToFile(note, morphPath + "/" + note.name + ".morph", false, false);

                        // Repack morphs into .morph.mr file
                        _activeProcess.status = mesh.name + " : Repacking Morphs...";
                        RepackMorphs(morphPath);

                        _conversionData.CloseReport("Success");
                    } catch {
                        _conversionData.CloseReport("Failed");
                    } finally {
                        MCS_Utilities.Paths.TryDirectoryDelete(morphPath);
                    }
                }

                if (_activeProcess.isLast)
                {
                    _conversionData.PrintSummary();
                }
            };
        }
 public PartialRelationGraph()
 {
     prMap  = new VertexMap <TValue>();
     pprMap = new EdgeMap();
 }
 public EdgeMap()
 {
     map = new VertexMap <object>();
 }