Esempio n. 1
0
            public CreateRoadMeshScripts.MeshSet GetMeshSet()
            {
                var yBuf         = GetYoffset(0);
                var verticesList = new List <Vector3>();

                verticesList.Add(positionList[0] + Vector3.up * yBuf);
                verticesList.Add(positionList[1] + Vector3.up * yBuf);
                verticesList.Add(positionList[2] + Vector3.up * yBuf);
                verticesList.Add(positionList[3] + Vector3.up * yBuf);
                var trianglesList = new List <int>();
                var index         = 0;

                CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 0, index + 1, index + 2, Vector3.up);
                CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 1, index + 2, index + 3, Vector3.up);
                var uvList   = new List <Vector2>();
                var leftdown = new Vector2(1f / 8, 0f);
                var rightup  = new Vector2(1f - 1f / 8, 1f * num);

                uvList.Add(new Vector2(leftdown.x, leftdown.y));
                uvList.Add(new Vector2(rightup.x, leftdown.y));
                uvList.Add(new Vector2(leftdown.x, rightup.y));
                uvList.Add(new Vector2(rightup.x, rightup.y));
                var meshSet = new CreateRoadMeshScripts.MeshSet();

                meshSet.VerticesList  = verticesList;
                meshSet.TrianglesList = trianglesList;
                meshSet.UvList        = uvList;
                {
                    {
                        verticesList.Add(verticesList[index + 0] + Vector3.down);
                        verticesList.Add(verticesList[index + 2] + Vector3.down);
                        uvList.Add(new Vector2(0, leftdown.y));
                        uvList.Add(new Vector2(0, rightup.y));
                        var nextIndex = index + 4;
                        var left      = Quaternion.AngleAxis(-90, Vector3.up) * direction;
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 0, index + 2, nextIndex + 0, left);
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 2, nextIndex + 0, nextIndex + 1, left);
                    }
                    {
                        verticesList.Add(verticesList[index + 1] + Vector3.down);
                        verticesList.Add(verticesList[index + 3] + Vector3.down);
                        uvList.Add(new Vector2(1, leftdown.y));
                        uvList.Add(new Vector2(1, rightup.y));
                        var nextIndex = index + 4 + 2;
                        var right     = Quaternion.AngleAxis(90, Vector3.up) * direction;
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 1, index + 3, nextIndex + 0, right);
                        CreateRoadMeshScripts.AddTrianglesList(verticesList, trianglesList, index + 3, nextIndex + 0, nextIndex + 1, right);
                    }
                }
                return(meshSet);
            }
Esempio n. 2
0
            public CreateRoadMeshScripts.MeshSet GetMeshSet()
            {
                var meshSet = new List <CreateRoadMeshScripts.MeshSet>();

                CreateRoadMeshScripts.CreateArea(positionList, (obj) => meshSet.Add(obj));
                var unitMeshSet = CreateRoadMeshScripts.GetCombinedMesh(meshSet)[0];

                unitMeshSet = BeefMain.Runtime.CreateNodeRoad.ConvertUvSetting(unitMeshSet);
                var addDesign = new List <CreateRoadMeshScripts.MeshSet>();

                addDesign.Add(unitMeshSet);
                addDesign.Add(CreateDesign(positionList));
                return(CreateRoadMeshScripts.GetCombinedMesh(addDesign)[0]);
            }
Esempio n. 3
0
        /// <summary>
        /// 接続している道それぞれのメッシュを生成する。
        /// </summary>
        /// <param name="nodeData">Node data.</param>
        /// <param name="key">Key.</param>
        /// <param name="registerHashtag">Hash.</param>
        /// <param name="roadMeshCallback">Road mesh callback.</param>
        public static void CreateRoadMeshFromNode(Dictionary <string, NodeMap.NodeData> nodeData, string key, HashSet <string> registerHashtag, Action <CreateRoadMeshScripts.MeshSet> roadMeshCallback)
        {
            var key1       = key;
            var centerNode = nodeData[key1];

            foreach (var key2 in centerNode.Graph)
            {
                var nextNode = nodeData[key2];
                var hashKey  = GetUniqueHash(key1, key2);

                // 同じノードをつないだメッシュを重複して生成しないようにハッシュで判定する。
                if (!registerHashtag.Contains(hashKey))
                {
                    CreateRoadMeshScripts.CreateStraightRoad(centerNode.Position, nextNode.Position, RoadWidth, roadMeshCallback);
                    registerHashtag.Add(hashKey);
                }
            }
        }
Esempio n. 4
0
        public static void CreateRoadByNodeMap(NodeMap nodeMap, Action <CreateRoadMeshScripts.MeshSet, string, string> createMeshGameObject)
        {
            var hash         = new HashSet <string>();
            var roadMeshSets = new List <CreateRoadMeshScripts.MeshSet>();
            var areaMeshSets = new List <CreateRoadMeshScripts.MeshSet>();
            var groupDict    = new NodeMap.GroupDict();

            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;
                }

                CreateRoadMeshFromNode(nodeMap.nodeMap, entry.Key, hash,
                                       CreateRoadMeshScripts.CreateAddToMeshSetListCallback(roadMeshSets)
                                       );
                CreateCrossRoadMeshFromNode(nodeMap.nodeMap, entry.Key,
                                            CreateRoadMeshScripts.CreateAddToMeshSetListCallback(areaMeshSets)
                                            );
            }

            roadMeshSets = CreateRoadMeshScripts.GetCombinedMesh(roadMeshSets);

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

            areaMeshSets = CreateRoadMeshScripts.GetCombinedMesh(areaMeshSets.ConvertAll(ConvertUvSetting));

            for (int i = 0; i < areaMeshSets.Count; i++)
            {
                createMeshGameObject(areaMeshSets[i], "CrossRoad" + i, "CrossTileMaterial");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 交差点のメッシュを生成する。
        /// </summary>
        /// <param name="nodeData">Node data.</param>
        /// <param name="key">Key.</param>
        /// <param name="areaMeshCallback">Area mesh callback.</param>
        public static void CreateCrossRoadMeshFromNode(Dictionary <string, NodeMap.NodeData> nodeData, string key, Action <CreateRoadMeshScripts.MeshSet> areaMeshCallback)
        {
            var key1         = key;
            var centerNode   = nodeData[key1];
            var connectCount = centerNode.Graph.Count;

            if (connectCount < 3)
            {
                return;
            }

            var positionList = new List <Vector3>();

            foreach (var key2 in centerNode.Graph)
            {
                var nextNode = nodeData[key2];
                var vector   = (nextNode.Position - centerNode.Position);
                var left     = centerNode.Position + vector.normalized * RoadWidth + Quaternion.AngleAxis(-90, Vector3.up) * vector.normalized * RoadWidth * 0.5f;
                var right    = centerNode.Position + vector.normalized * RoadWidth + Quaternion.AngleAxis(90, Vector3.up) * vector.normalized * RoadWidth * 0.5f;
                positionList.Add(left);
                positionList.Add(right);
            }

            try
            {
                var framePointsList = GetFrameScript.GetFramePoints(positionList.ConvertAll((input) => new Vector2(input.x, input.z))).ToList();
                // Zファイティングを防ぐため 道路より上に配置している。
                var yBuf = (1f / 16) * connectCount;
                positionList = framePointsList.ConvertAll((input) => new Vector3(input.x, centerNode.Position.y + yBuf, input.y));
                CreateRoadMeshScripts.CreateArea(positionList, areaMeshCallback);
            }
            catch (Exception e)
            {
                // Debug.LogException(e);
            }
        }
Esempio n. 6
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");
            }
        }