コード例 #1
0
        public static void CreateRoadMeshFromNodeLine(Dictionary <string, NodeMap.NodeData> nodeData, string key, Dictionary <string, BeefMeshUtility.IPlaneMeshSet> registerHashtag, List <BeefMeshUtility.IPlaneMeshSet> roadMeshCallback)
        {
            var key1       = key;
            var centerNode = nodeData[key1];
            var graph      = centerNode.Graph;

            foreach (string key2 in graph)
            {
                var nextNode = nodeData[key2];
                var hashKey1 = key1 + ":" + key2;
                var hashKey2 = key2 + ":" + key1;

                // 同じノードをつないだメッシュを重複して生成しないようにハッシュで判定する。
                if (registerHashtag.ContainsKey(hashKey1) || registerHashtag.ContainsKey(hashKey2))
                {
                }
                else
                {
                    var list = BeefMeshUtility.CreateStraightRoad(centerNode.Position, nextNode.Position, RoadWidth);
                    registerHashtag[hashKey1] = list[0];
                    registerHashtag[hashKey2] = list[list.Count - 1];

                    for (int i = 1; i < list.Count - 1; i++)
                    {
                        roadMeshCallback.Add(list[i]);
                    }
                }
            }
        }
コード例 #2
0
        public static void CreateRoadByNodeMapNext(NodeMap nodeMap, Action <CreateRoadMeshScripts.MeshSet, string, string> createMeshGameObject)
        {
            var hash          = new Dictionary <string, BeefMeshUtility.IPlaneMeshSet>();
            var roadMeshSets  = new List <BeefMeshUtility.IPlaneMeshSet>();
            var curveMeshSets = new List <BeefMeshUtility.IPlaneMeshSet>();
            var areaMeshSets  = new List <BeefMeshUtility.IPlaneMeshSet>();
            var groupDict     = new NodeMap.GroupDict(nodeMap.nodeMap.Count);

            NodeMap.Group(nodeMap, out groupDict);

            foreach (var entry in groupDict)
            {
                // FIXME: 1つ以上のグループが存在する場合の暫定対処, 警告だけ出して処理続行する.
                if (entry.Value != 0)
                {
                    Debug.LogWarningFormat("More than one Node groups exist.");
                    continue;
                }

                CreateRoadMeshFromNodeLine(nodeMap.nodeMap, entry.Key, hash, roadMeshSets);
                var key1       = entry.Key;
                var centerNode = nodeMap.nodeMap[key1];

                if (1 < centerNode.Graph.Count)
                {
                    var connectedMeshSets = centerNode.Graph.ConvertAll((string key2) => key1 + ":" + key2).ConvertAll((string input) => hash[input]).ToList();
                    var meshSet           = BeefMeshUtility.GetFrameMeshSet(connectedMeshSets);

                    if (meshSet == null)
                    {
                        continue;
                    }

                    if (centerNode.Graph.Count == 2)
                    {
                        curveMeshSets.Add(meshSet);
                    }
                    else
                    {
                        areaMeshSets.Add(meshSet);
                    }
                }
            }

            var roadMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(roadMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < roadMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(roadMeshSetsNeo[i], "Road" + i, "TileMaterial");
            }

            var curveMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(curveMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < curveMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(curveMeshSetsNeo[i], "Curve" + i, "CurveTileMaterial");
            }

            var areaMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(areaMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < areaMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(areaMeshSetsNeo[i], "CrossRoad" + i, "CrossTileMaterial");
            }
        }