Example #1
0
        public static FrameMeshSet GetFrameMeshSet(List <IPlaneMeshSet> planeMeshSets)
        {
            var positionList = new List <Vector3>();

            foreach (var obj in planeMeshSets)
            {
                positionList.AddRange(obj.GetPositionList());
            }

            var framePointsList = GetFrameScript.GetFramePoints(positionList.ConvertAll(GetVector2)).ToList();
            var yBuf            = GetYoffset(positionList.Count);

            positionList = framePointsList.ConvertAll((input) => new Vector3(input.x, positionList[0].y + yBuf, input.y));

            if (positionList.Count < 3)
            {
                return(null);
            }

            return(new FrameMeshSet(positionList));
        }
Example #2
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);
            }
        }