当前位置: 首页>>代码示例>>C#>>正文


C# Geometry.CalculateBounds方法代码示例

本文整理汇总了C#中Geometry.CalculateBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Geometry.CalculateBounds方法的具体用法?C# Geometry.CalculateBounds怎么用?C# Geometry.CalculateBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Geometry的用法示例。


在下文中一共展示了Geometry.CalculateBounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildGeometry

    /// <summary>
    /// This takes the current geometry and builds the data to go into Recast
    /// It needs to be updated to take into account scale, position, and rotation
    /// It needs to be updated to look for specific tags
    /// </summary>
    /// <param name="geom"></param>
    private static void BuildGeometry(NavMeshSettings settings, Config config, Geometry geom)
    {
        for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++)
        {
            if ((settings.Tags & (1 << i)) != 0)
            {
                foreach (var gameObject in GameObject.FindGameObjectsWithTag(UnityEditorInternal.InternalEditorUtility.tags[i]))
                {
                    foreach (var terrainObj in gameObject.GetComponentsInChildren<Terrain>())
                    {
                        var terrain = terrainObj.terrainData;
                        var w = terrain.heightmapWidth;
                        var h = terrain.heightmapHeight;
                        var meshScale = terrain.size;
                        var tRes = 1;
                        meshScale = new Vector3(meshScale.x / (w - 1) * tRes, meshScale.y, meshScale.z / (h - 1) * tRes);
                        var tData = terrain.GetHeights(0, 0, w, h);

                        w = (w - 1) / tRes + 1;
                        h = (h - 1) / tRes + 1;
                        var tVertices = new Vector3[w * h];
                        var tPolys = new int[(w - 1) * (h - 1) * 6];

                        // Build vertices and UVs
                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                tVertices[y * w + x] = Vector3.Scale(meshScale, new Vector3(x, tData[y * tRes, x * tRes], y)) + terrainObj.transform.position;
                            }
                        }

                        var index = 0;
                        // Build triangle indices: 3 indices into vertex array for each triangle
                        for (int y = 0; y < h - 1; y++)
                        {
                            for (int x = 0; x < w - 1; x++)
                            {
                                // For each grid cell output two triangles
                                tPolys[index++] = (y * w) + x;
                                tPolys[index++] = ((y + 1) * w) + x;
                                tPolys[index++] = (y * w) + x + 1;

                                tPolys[index++] = ((y + 1) * w) + x;
                                tPolys[index++] = ((y + 1) * w) + x + 1;
                                tPolys[index++] = (y * w) + x + 1;
                            }
                        }
                        int subTotalVerts = geom.NumVertexes;
                        foreach (var tVertex in tVertices)
                        {
                            geom.Vertexes.Add(new RecastVertex(tVertex.x, tVertex.y, tVertex.z));
                            geom.NumVertexes++;
                        }
                        for (int j = 0; j < tPolys.Length; j += 3)
                        {
                            geom.Triangles.Add(tPolys[j] + subTotalVerts);
                            geom.Triangles.Add(tPolys[j + 1] + subTotalVerts);
                            geom.Triangles.Add(tPolys[j + 2] + subTotalVerts);
                            geom.NumTriangles++;
                        }
                    }
                    foreach (var componentsInChild in gameObject.GetComponentsInChildren<MeshFilter>())
                    {
                        int subTotalVerts = geom.NumVertexes;
                        foreach (Vector3 vector3 in componentsInChild.sharedMesh.vertices)
                        {
                            Vector3 vec = gameObject.transform.TransformPoint(vector3);
                            geom.Vertexes.Add(new RecastVertex(vec.x, vec.y, vec.z));
                            geom.NumVertexes++;
                        }
                        for (int j = 0; j < componentsInChild.sharedMesh.triangles.Length; j += 3)
                        {
                            geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j] + subTotalVerts);
                            geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j + 1] + subTotalVerts);
                            geom.Triangles.Add(componentsInChild.sharedMesh.triangles[j + 2] + subTotalVerts);
                            geom.NumTriangles++;
                        }
                    }
                    foreach (var offMeshConnector in gameObject.GetComponentsInChildren<OffMeshConnector>())
                    {
                        RecastVertex start = new RecastVertex(offMeshConnector.StartPosition.x, offMeshConnector.StartPosition.y, offMeshConnector.StartPosition.z);
                        RecastVertex end = new RecastVertex(offMeshConnector.EndPosition.x, offMeshConnector.EndPosition.y, offMeshConnector.EndPosition.z);
                        geom.AddOffMeshConnection(start, end, offMeshConnector.Radius, offMeshConnector.Bidirectional, 5, 8);
                    }
                }
            }
        }

        if (geom.NumVertexes != 0)
        {
            geom.CalculateBounds();
            config.CalculateGridSize(geom);
            geom.CreateChunkyTriMesh();
//.........这里部分代码省略.........
开发者ID:zukeru,项目名称:ageofasura,代码行数:101,代码来源:ServerNavMesh.cs


注:本文中的Geometry.CalculateBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。