예제 #1
0
    // 增加线段
    public void AddLine(Vector3 start, Vector3 end, Color color, float radius = 0.1f)
    {
        int     num      = 6;
        int     angle    = 360 / num;
        Vector3 dir      = (end - start).normalized;
        var     vertical = GetVerticalDir(dir);

        for (int i = 1; i <= num; i++)
        {
            var r  = Quaternion.AngleAxis(i * angle, dir) * vertical;
            var r1 = Quaternion.AngleAxis((i + 1) * angle, dir) * vertical;

            var p1 = (r * radius) + start;
            var p2 = (r1 * radius) + start;
            var p3 = (r * radius) + end;
            var p4 = (r1 * radius) + end;
            segment_mesh.SegmentData.SetTriangleVertice(0, start, p2, p1);
            segment_mesh.SegmentData.SetColor(color);
            segment_mesh.AddSegmentData(flag);

            segment_mesh.SegmentData.SetTriangleVertice(0, end, p3, p4);
            segment_mesh.SegmentData.SetColor(color);
            segment_mesh.AddSegmentData(flag);

            segment_mesh.SegmentData.SetTriangleVertice(0, p1, p2, p4);
            segment_mesh.SegmentData.SetColor(color);
            segment_mesh.AddSegmentData(flag);

            segment_mesh.SegmentData.SetTriangleVertice(0, p3, p1, p4);
            segment_mesh.SegmentData.SetColor(color);
            segment_mesh.AddSegmentData(flag);
        }

        segment_mesh.CopyToMesh(render_object.mesh_filter.mesh, true);
        render_object.mesh_filter.mesh.RecalculateNormals();
    }
예제 #2
0
    // 创建建筑
    public void CreateBuild(BuildData build_data)
    {
        float   build_height = (float)(build_data.floor_height * build_data.floor_num);
        Vector3 h            = new Vector3(0, build_height, 0);
        // 绘制底面
        List <int> triangleindex = Triangulation.WidelyTriangleIndex(build_data.panel_pos);

        for (int i = 2; i < triangleindex.Count; i += 3)
        {
            Vector3 vv1 = build_data.panel_pos[triangleindex[i - 2]];
            Vector3 vv2 = build_data.panel_pos[triangleindex[i - 1]];
            Vector3 vv3 = build_data.panel_pos[triangleindex[i]];

            segment_mesh.SegmentData.SetTriangleVertice(0, vv3, vv2, vv1);
            segment_mesh.AddSegmentData(flag);
        }

        // 绘制柱子
        Vector3 v1 = Vector3.zero;
        Vector3 v2 = Vector3.zero;
        Vector3 v3 = Vector3.zero;
        Vector3 v4 = Vector3.zero;

        for (int i = 0; i < build_data.panel_pos.Count; i++)
        {
            if (i == 0)
            {
                v2 = build_data.panel_pos[i];
                v1 = build_data.panel_pos[build_data.panel_pos.Count - 1];
                v4 = build_data.panel_pos[i] + h;
                v3 = build_data.panel_pos[build_data.panel_pos.Count - 1] + h;
            }
            else
            {
                v1 = build_data.panel_pos[i - 1];
                v2 = build_data.panel_pos[i];
                v3 = build_data.panel_pos[i - 1] + h;
                v4 = build_data.panel_pos[i] + h;
            }
            segment_mesh.SegmentData.SetTriangleVertice(0, v3, v2, v1);
            segment_mesh.AddSegmentData(flag);
            segment_mesh.SegmentData.SetTriangleVertice(0, v2, v3, v4);
            segment_mesh.AddSegmentData(flag);

            segment_mesh.SegmentData.SetTriangleVertice(0, v1, v2, v3);
            segment_mesh.AddSegmentData(flag);
            segment_mesh.SegmentData.SetTriangleVertice(0, v4, v3, v2);
            segment_mesh.AddSegmentData(flag);
        }

        // 绘制顶面
        for (int i = 2; i < triangleindex.Count; i += 3)
        {
            Vector3 vv1 = build_data.panel_pos[triangleindex[i - 2]] + h;
            Vector3 vv2 = build_data.panel_pos[triangleindex[i - 1]] + h;
            Vector3 vv3 = build_data.panel_pos[triangleindex[i]] + h;

            segment_mesh.SegmentData.SetTriangleVertice(0, vv1, vv2, vv3);
            segment_mesh.AddSegmentData(flag);
        }

        segment_mesh.CopyToMesh(render_object.mesh_filter.mesh, true);
        render_object.mesh_filter.mesh.RecalculateNormals();

        CreateLayer(build_data);
    }