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


C# Mesh.RecalculateBounds方法代码示例

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


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

示例1: FillMesh

 /// <summary>
 ///   <para>Fill the given mesh with the stream data.</para>
 /// </summary>
 /// <param name="mesh"></param>
 public void FillMesh(Mesh mesh)
 {
   mesh.Clear();
   if (this.m_Positions.Count >= 65000)
     throw new ArgumentException("Mesh can not have more than 65000 vertices");
   mesh.SetVertices(this.m_Positions);
   mesh.SetColors(this.m_Colors);
   mesh.SetUVs(0, this.m_Uv0S);
   mesh.SetUVs(1, this.m_Uv1S);
   mesh.SetNormals(this.m_Normals);
   mesh.SetTangents(this.m_Tangents);
   mesh.SetTriangles(this.m_Indices, 0);
   mesh.RecalculateBounds();
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:18,代码来源:VertexHelper.cs

示例2: CreateLeafMesh2


//.........这里部分代码省略.........

                int leafletDetail = 1; // 1 or above
                int vertsPrLeaflet = leafletDetail + 2;
                int vertexCountPrSide = leaflets * vertsPrLeaflet;
                Vector3[] verts = new Vector3[vertexCountPrSide * 2];
                Debug.Log("||vertices|| " + verts.Length);

                // Build the first side of the leaf
                verts[0] = Vector3.zero;
                for (int l = 0; l < leaflets; ++l) {

                // Vertex on 'spine'
                float spineDelta = (l + 0.3f) / (float)leaflets;
                verts[1 + l * vertsPrLeaflet] = new Vector3(0.0f, 0.0f, spineDelta * length);

                // Outer vertex
                float outerDelta = (l + 1.0f) / (float)leaflets;
                Vector2 outerPos = outerBend.GetPosition(outerAngle * outerDelta);
                verts[1 + l * vertsPrLeaflet + 1] = new Vector3(outerPos.x, -0.4f * outerPos.x, outerPos.y);

                // Inner vertex if not last leaflet
                if (l < leaflets-1) {
                float innerDelta = (l + 0.9f) / (float)leaflets;
                Vector2 innerPos = innerBend.GetPosition(innerAngle * innerDelta);
                verts[1 + l * vertsPrLeaflet + 2] = new Vector3(innerPos.x, -0.4f * innerPos.x, innerPos.y);
                }
                }
                // Hard set last vertex to length away from origin to avoit precision errors
                verts[vertexCountPrSide-1] = new Vector3(0.0f, 0.0f, length);

                // Build the second side of the leaf
                for (int v = 0; v < vertexCountPrSide; ++v) {
                Vector3 vert = verts[v];
                vert.x *= -1.0f;
                verts[v + vertexCountPrSide] = vert;
                }

                string vertsStr = "";
                foreach (Vector3 v in verts)
                vertsStr += v.ToString("0.000");
                Debug.Log(vertsStr);

                // Index the first side of the leaf
                int trisPrSide = leaflets * leafletDetail + (leaflets - 1) * 2;
                int indicesPrSide = trisPrSide * 3;
                int[] indices = new int[indicesPrSide * 2];
                Debug.Log("||indices|| " + indices.Length);
                int prevSpineIndex = 1 - vertsPrLeaflet;
                int i = 0;
                while (i < indicesPrSide - 1) {
                int spineIndex = prevSpineIndex + vertsPrLeaflet;

                indices[i] = spineIndex-1;
                ++i;
                indices[i] = spineIndex+1;
                ++i;
                indices[i] = spineIndex;
                ++i;

                for (int l = 0; l < leafletDetail && i < indices.Length-1; ++l) {
                indices[i] = spineIndex;
                ++i;
                indices[i] = spineIndex + l + 1;
                ++i;
                indices[i] = spineIndex + l + 2;
                ++i;
                }

                if (i < indices.Length-1) {
                int nextSpineIndex = spineIndex + vertsPrLeaflet;
                indices[i] = spineIndex;
                ++i;
                indices[i] = nextSpineIndex - 1;
                ++i;
                indices[i] = nextSpineIndex;
                ++i;
                }

                prevSpineIndex = spineIndex;
                }

                // Index the second side of the leaf
                for (i = 0; i < indicesPrSide; ++i)
                indices[indicesPrSide + i] = indices[i] + vertexCountPrSide;

                string trisStr = "";
                for (i = 0; i < indices.Length / 3; ++i)
                trisStr += "[" + indices[i*3] + ", " + indices[i*3+1] + ", " + indices[i*3+2] + "], ";
                Debug.Log(trisStr);

                Mesh mesh = new Mesh();
                mesh.name = "PalmLeaf_" + seed;
                mesh.vertices = verts;
                mesh.triangles = indices;
                mesh.RecalculateNormals();
                mesh.RecalculateBounds();
                mesh.Optimize();

                return mesh;
            }
开发者ID:shadercoder,项目名称:Unity3D-experiments,代码行数:101,代码来源:PalmCreator.cs

示例3: CreateStemMesh

            public static Mesh CreateStemMesh(int seed)
            {
                Random.seed = seed;

                int sides = 7;
                int quads = sides * 2;
                float height = 0.25f;
                float bottomDiameter = 0.125f;
                float topDiameter = 0.2f;

                Vector3[] vertices = new Vector3[quads * 3 + 1];
                int lidOffset = quads * 2;
                int centerIndex = vertices.Length-1;
                float sideRotation = Random.Range(0.0f, 2.0f * Mathf.PI);
                for (int q = 0; q < quads; ++q) {
                float x = Mathf.Cos(sideRotation + q * 2.0f * Mathf.PI / quads);
                float z = Mathf.Sin(sideRotation + q * 2.0f * Mathf.PI / quads);

                Vector3 bottom = new Vector3(x * bottomDiameter, 0.0f, z * bottomDiameter);
                Vector3 top = new Vector3(x * topDiameter, height, z * topDiameter);

                float rand = q % 2 == 0 ? Random.Range(0.8f, 0.9f) : Random.Range(1.1f, 1.4f);
                top = bottom + (top - bottom) * rand;
                if ((q % 2) == 1)
                top += new Vector3(x, 0.0f, z) * topDiameter * 0.1f * rand;

                vertices[q * 2] = bottom;
                vertices[q * 2 + 1] = top;
                vertices[lidOffset + q] = top; // For the 'lid'
                }

                vertices[centerIndex] = new Vector3(0.0f, height * 0.5f, 0.0f);

                int[] indices = new int[quads * 6 + quads * 3]; // quads * 6 indices for the sides and quads * 3 for the top
                for (int s = 0; s < sides-1; ++s) {
                AddStemSideIndices(s * 4, s * 4 + 1, s * 4 + 2, s * 4 + 3, s * 4 + 4, s * 4 + 5,
                               lidOffset + s * 2, lidOffset + s * 2 + 1, lidOffset + s * 2 + 2, centerIndex,
                               indices, s * 18);
                }

                int lastSide = (sides - 1) * 4;
                int lastLid = lidOffset + (sides - 1) * 2;
                AddStemSideIndices(lastSide, lastSide + 1, lastSide + 2, lastSide + 3, 0, 1,
                           lastLid, lastLid + 1, lidOffset, centerIndex,
                           indices, (sides - 1) * 18);

                Mesh mesh = new Mesh();
                mesh.name = "PalmStem_" + seed;
                mesh.vertices = vertices;
                mesh.triangles = indices;
                mesh.RecalculateNormals();
                mesh.RecalculateBounds();
                mesh.Optimize();

                return mesh;
            }
开发者ID:shadercoder,项目名称:Unity3D-experiments,代码行数:56,代码来源:PalmCreator.cs

示例4: CreateLeafMesh

            public static Mesh CreateLeafMesh(int seed, float length)
            {
                Random.seed = seed;

                float outerAngle = 90.0f;
                Vector2 outerP0 = Vector2.zero;
                Vector2 outerP1 = new Vector2(0.0f, length);
                BenderRodriguez outerBend = new BenderRodriguez(outerP0, outerP1, outerAngle);

                int quads = 7;

                // TODO Add a 'spine'

                Vector3[] verts = new Vector3[(quads+1) * 2];
                for (int q = 0; q <= quads; ++q) {
                float delta = q / (float)quads;

                Vector2 outerPos = outerBend.GetPosition(outerAngle * delta * delta);
                verts[2*q  ] = outerPos;
                outerPos.x *= -1.0f;
                verts[2*q+1] = outerPos;
                }

                int[] indices = new int[quads * 6];
                for (int q = 0; q < quads; ++q) {
                indices[6*q  ] = 2*q;
                indices[6*q+1] = 2*q+2;
                indices[6*q+2] = 2*q+1;

                indices[6*q+3] = 2*q+1;
                indices[6*q+4] = 2*q+2;
                indices[6*q+5] = 2*q+3;
                }

                Mesh mesh = new Mesh();
                mesh.name = "PalmLeaf_" + seed;
                mesh.vertices = verts;
                mesh.triangles = indices;
                mesh.RecalculateNormals();
                mesh.RecalculateBounds();
                mesh.Optimize();

                return mesh;
            }
开发者ID:shadercoder,项目名称:Unity3D-experiments,代码行数:44,代码来源:PalmCreator.cs


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