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


C# Mesh.RecalculateBounds方法代码示例

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


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

示例1: FileToMesh

        // Use this for initialization
        public static Mesh FileToMesh(string filePath)
        {
            meshStruct newMesh = createMeshStruct(filePath);
            populateMeshStruct(ref newMesh);

            Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
            Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
            Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
            int i = 0;
            /* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
             * for the appropriate Unity mesh array.
             */
            foreach (Vector3 v in newMesh.faceData)
            {
                newVerts[i] = newMesh.vertices[(int)v.x - 1];
                if (v.y >= 1)
                    newUVs[i] = newMesh.uv[(int)v.y - 1];

                if (v.z >= 1)
                    newNormals[i] = newMesh.normals[(int)v.z - 1];
                i++;
            }

            Mesh mesh = new Mesh();

            mesh.vertices = newVerts;
            mesh.uv = newUVs;
            mesh.normals = newNormals;
            mesh.triangles = newMesh.triangles;

            mesh.RecalculateBounds();
            mesh.Optimize();

            return mesh;
        }
开发者ID:tudela,项目名称:RealSolarSystem,代码行数:36,代码来源:ObjLib.cs

示例2: Start

    public void Start()
    {
        _mushroom = new GameObject("Mushroom");
        _mushroom.AddComponent<MeshFilter>();
        _mushroom.AddComponent<MeshRenderer>();

        _mesh = new Mesh();

        _vertices = new List<Vector3>();
        _indices = new List<int>();
        _uvs = new List<Vector2>();
        _mesh.Clear();

        GenerateVertices();
        GenerateIndices();
        GenerateUvs();
        //DrawVertices();

        _mesh.vertices = _vertices.ToArray();
        _mesh.triangles = _indices.ToArray();
        _mesh.uv = _uvs.ToArray();

        _mesh.RecalculateBounds();
        _mesh.RecalculateNormals();

        _mushroom.GetComponent<MeshFilter>().mesh = _mesh;
        _mushroom.renderer.material.color = Color.grey;
    }
开发者ID:WozStudios,项目名称:AVirtualWonderland,代码行数:28,代码来源:MushroomGenerator.cs

示例3: Start

    void Start()
    {
        // Create Vector2 vertices
        Vector3[] vertices3D = new Vector3[] {
            new Vector3(5, 10, 0),
            new Vector3(10, -5, 0),
            new Vector3(-7, -3, 0),
            new Vector3(-2, -8, 0),
            new Vector3(9, -10, 0),
        };

        // Use the triangulator to get indices for creating triangles
        MidpointTriangulator tr = new MidpointTriangulator(vertices3D);

        Vector3[] vertices = tr.Triangulate().ToArray();
        int[] indices = new int[vertices.Length];

        // Create the Vector3 vertices
        for (int i = 0; i < vertices.Length; i++)
        {
          indices[i] = i;
        }

        // Create the mesh
        Mesh msh = new Mesh();
        msh.vertices = vertices;
        msh.triangles = indices;
        msh.RecalculateNormals();
        msh.RecalculateBounds();

        // Set up game object with mesh;
        MeshFilter filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
        filter.mesh = msh;
    }
开发者ID:jonas-halbach,项目名称:DestructibleGeometry,代码行数:34,代码来源:TriangulatorTest.cs

示例4: AddLine

    void AddLine(Mesh m, Vector3[] quad, bool tmp)
    {
        int vl = m.vertices.Length;

            Vector3[] vs = m.vertices;
            if(!tmp || vl == 0) vs = resizeVertices(vs, 4);
            else vl -= 4;

            vs[vl] = quad[0];
            vs[vl+1] = quad[1];
            vs[vl+2] = quad[2];
            vs[vl+3] = quad[3];

            int tl = m.triangles.Length;

            int[] ts = m.triangles;
            if(!tmp || tl == 0) ts = resizeTraingles(ts, 6);
            else tl -= 6;
            ts[tl] = vl;
            ts[tl+1] = vl+1;
            ts[tl+2] = vl+2;
            ts[tl+3] = vl+1;
            ts[tl+4] = vl+3;
            ts[tl+5] = vl+2;

            m.vertices = vs;
            m.triangles = ts;
            m.RecalculateBounds();
    }
开发者ID:BiDuc,项目名称:Stereoscopic_Scatterplot,代码行数:29,代码来源:LinesAxes.cs

示例5: CreateConvexHull

        public static void CreateConvexHull(ConvexHullShape shape, Mesh mesh)
        {
            ShapeHull hull = new ShapeHull(shape);
            hull.BuildHull(shape.Margin);

            List<UnityEngine.Vector3> verts = new List<UnityEngine.Vector3>();
            List<int> tris = new List<int>();

            //int vertexCount = hull.NumVertices;
            UIntArray indices = hull.Indices;
            Vector3Array points = hull.Vertices;

            for (int i = 0; i < indices.Count; i+=3)
            {
                verts.Add(points[(int)indices[i]].ToUnity());
                verts.Add(points[(int)indices[i+1]].ToUnity());
                verts.Add(points[(int)indices[i+2]].ToUnity());
                tris.Add(i);
                tris.Add(i + 1);
                tris.Add(i + 2);
            }

            mesh.vertices = verts.ToArray();
            mesh.triangles = tris.ToArray();
            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
        }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:27,代码来源:MeshFactory2.cs

示例6: GenerateMesh

    public Mesh GenerateMesh(Map map, float squareSize)
    {
        vertices = new List<Vector3>();
        triangles = new List<int>();

        triangleDictionary = new Dictionary<int, List<Triangle>>();
        outlines = new List<List<int>>();
        checkedVertices = new HashSet<int>();

        squareGrid = new SquareGrid(map, squareSize);
        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        if(generateColliders) {
            Generate2DColliders();
        }

        return mesh;
    }
开发者ID:jondbridges,项目名称:ancillary,代码行数:29,代码来源:MapMeshGenerator.cs

示例7: CreateLattice

 private static Mesh CreateLattice(int meshDim)
 {
     Mesh m = new Mesh();
     ConstructMesh(m, meshDim);
     m.RecalculateBounds();
     return m;
 }
开发者ID:kristofe,项目名称:UnityGPUMarchingCubes,代码行数:7,代码来源:CreateLatticeMesh.cs

示例8: CloneMesh

    static Mesh CloneMesh(Mesh mesh)
    {
        Mesh clonemesh = new Mesh();
        clonemesh.vertices = mesh.vertices;
        clonemesh.uv1 = mesh.uv1;
        clonemesh.uv2 = mesh.uv2;
        clonemesh.uv = mesh.uv;
        clonemesh.normals = mesh.normals;
        clonemesh.tangents = mesh.tangents;
        clonemesh.colors = mesh.colors;

        clonemesh.subMeshCount = mesh.subMeshCount;

        for ( int s = 0; s < mesh.subMeshCount; s++ )
        {
            clonemesh.SetTriangles(mesh.GetTriangles(s), s);
        }

        //clonemesh.triangles = mesh.triangles;

        clonemesh.boneWeights = mesh.boneWeights;
        clonemesh.bindposes = mesh.bindposes;
        clonemesh.name = mesh.name + "_copy";
        clonemesh.RecalculateBounds();

        return clonemesh;
    }
开发者ID:jsr2k1,项目名称:videojocjj,代码行数:27,代码来源:MegaCopyObjects.cs

示例9: ratio

    float gr = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f; //golen ratio (a+b is to a as a is to b)

    #endregion Fields

    #region Methods

    void Start()
    {
        Nose = GameObject.Find("Nose");
        Nose.AddComponent<MeshFilter>();
        Nose.AddComponent<MeshRenderer>();
        noseMesh = GetComponent<MeshFilter>().mesh;//attach mesh to nose
        noseMesh.Clear();

        noseMesh.vertices = new Vector3[] {//construct pyramid for nose
            new Vector3( gr,   		     1,		  	0),
            new Vector3( gr-1,    -gr*0.6f, -gr*0.75f),
            new Vector3( gr-1, 	  -gr*0.6f,  gr*0.75f),
            new Vector3( gr*1.5f, -gr*0.6f,   		0)};

        List<int> noseTrianglesIndices = new List<int>() {//arrange triangles
            0,  1,  2,
            0,  3,  1,
            0,  2,  3,
            1,  3,  2};
        noseMesh.triangles = noseTrianglesIndices.ToArray();

        //Set Colour
        Material material = new Material(Shader.Find("Standard"));
        Color fleshtone = new Color(10, 205, 180);
        material.SetColor("fleshtone", fleshtone);

        Nose.GetComponent<Renderer>().material = material;

        noseMesh.RecalculateBounds();
        noseMesh.RecalculateNormals();
        noseMesh.Optimize();
    }
开发者ID:Bobnonymous,项目名称:Facemaker,代码行数:38,代码来源:GenerateNose.cs

示例10: JoinMeshes

        // todo : make extensdion method
        public static Mesh JoinMeshes( Mesh first, Mesh second )
        {
            int newVertLength = first.vertices.Length + second.vertices.Length;
            int newTriLength  = first.triangles.Length + second.triangles.Length;

            Vector3[] newVerts = new Vector3[ newVertLength ];
            Vector2[] newUVs = new Vector2[ newVertLength ];
            int[] newTris = new int[ newTriLength ];

            for ( int v=0; v<newVertLength; v++ )
            {
                if ( v == second.vertices.Length ) break;
                newVerts[ v ] = v >= first.vertices.Length ? second.vertices[ v ] : first.vertices[ v ];
                newUVs[ v ] = v >= first.vertices.Length ? second.uv[ v ] : first.uv[ v ];
            }

            for ( int t=0; t<newTriLength; t++ )
            {
                if ( t == second.triangles.Length ) break;
                newTris[ t ] = t >= first.triangles.Length ? second.triangles[ t ] : first.triangles[ t ];
            }

            Mesh newMesh = new Mesh();
            newMesh.vertices = newVerts;
            newMesh.uv = newUVs;
            newMesh.triangles = newTris;
            newMesh.RecalculateNormals();
            newMesh.RecalculateBounds();
            return newMesh;
        }
开发者ID:moto2002,项目名称:BaseFramework,代码行数:31,代码来源:MeshHelper.cs

示例11: Update

    // Update is called once per frame
    void Update()
    {
        if (!Application.isPlaying) {
            triangulator = new Triangulator ();
            Vector2[] vertex = polyCollider.points;
            triangulator.UpdatePoints (vertex);
            int[] index = triangulator.Triangulate ();

            Vector3[] vertex3D = new Vector3[vertex.Length];
            for (int i = 0; i < vertex.Length; i++) {
                vertex3D [i] = vertex [i];
            }
            Vector2[] uvs = new Vector2[vertex.Length];

            for (int i=0; i < uvs.Length; i++) {
                uvs [i] = new Vector2 (vertex [i].x, vertex [i].y);
            }

            Mesh msh = new Mesh ();
            msh.vertices = vertex3D;
            msh.triangles = index;
            msh.uv = uvs;
            msh.RecalculateBounds ();
            msh.RecalculateNormals ();

            mshFilter.mesh = msh;
        }
    }
开发者ID:Blinkq,项目名称:HellRuner,代码行数:29,代码来源:CustomPlatform.cs

示例12: MergeMeshes

        public static GameObject MergeMeshes(PaintJob[] jobs)
        {
            if (jobs.Length == 0)
            return null;
             List<CombineInstance> meshes = new List<CombineInstance>();
             for (int i = 0; i < jobs.Length; ++i)
             {
            Mesh m = BakeDownMesh(jobs[i].meshFilter.sharedMesh, jobs[i].stream);
            CombineInstance ci = new CombineInstance();
            ci.mesh = m;
            ci.transform = jobs[i].meshFilter.transform.localToWorldMatrix;
            meshes.Add(ci);
             }

             Mesh mesh = new Mesh();
             mesh.CombineMeshes(meshes.ToArray());
             GameObject go = new GameObject("Combined Mesh");
             go.AddComponent<MeshRenderer>();
             var mf = go.AddComponent<MeshFilter>();
             mesh.Optimize();
             mesh.RecalculateBounds();
             mesh.UploadMeshData(false);
             mf.sharedMesh = mesh;
             for (int i = 0; i < meshes.Count; ++i)
             {
            GameObject.DestroyImmediate(meshes[i].mesh);
             }
             return go;
        }
开发者ID:slipster216,项目名称:VertexPaint,代码行数:29,代码来源:VertexPainterUtilities.cs

示例13: CreateMesh

 public static void CreateMesh()
 {
     Mesh mesh = new Mesh();
     Vector3[] vertices = new Vector3[] {
         Vector3.zero, // lowerLeft
         new Vector3(0,0,1080), //upperLeft
         new Vector3(1920,0,1080), //upperRight
         new Vector3(1920,0,0), // lowerRight
     };
     Vector2[] uv = new Vector2[] {
         new Vector2(0,0),
         new Vector2(0,1),
         new Vector2(1,1),
         new Vector2(1,0)
     };
     mesh.vertices = vertices;
     mesh.uv = uv;
     mesh.triangles = new int[] {
         0,1,2,
         0,2,3,
     };
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     AssetDatabase.CreateAsset(mesh, "Assets/AntsVsMice/Levels/boardMesh.asset");
     AssetDatabase.SaveAssets ();
 }
开发者ID:splashdamage,项目名称:AntsVsMice,代码行数:26,代码来源:GenerateBoardMesh.cs

示例14: Go

    public static void Go()
    {
        Mesh mesh = new Mesh();

        mesh.vertices = new Vector3[]{
            new Vector3(-0.5f, -0.5f, 1),
            new Vector3(+0.5f, -0.5f, 1),
            new Vector3(-0.5f, +0.5f, 0),
            new Vector3(+0.5f, +0.5f, 0)
        };

        mesh.uv = new Vector2[]{
            new Vector2(0, 0),
            new Vector2(1, 0),
            new Vector2(0, 1),
            new Vector2(1, 1)
        };

        mesh.triangles = new int[]{
            0, 2, 1,
            2, 3, 1
        };

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        AssetDatabase.CreateAsset(mesh, "Assets/Angled Plane.asset");
    }
开发者ID:GabrielSibley,项目名称:games,代码行数:28,代码来源:CreateAngledPlaneMesh.cs

示例15: UpdateCollisionMesh

    /// <summary>
    /// Manually recalculates the collision mesh of the skinned mesh on this object.
    /// </summary>
    public void UpdateCollisionMesh()
    {
        Mesh mesh = new Mesh();

        Vector3[] newVert = new Vector3[skinnedMeshRenderer.sharedMesh.vertices.Length];

        // Now get the local positions of all weighted indices...
        foreach ( CWeightList wList in nodeWeights )
        {
            foreach ( CVertexWeight vw in wList.weights )
            {
                newVert[vw.index] += wList.transform.localToWorldMatrix.MultiplyPoint3x4( vw.localPosition ) * vw.weight;
            }
        }

        // Now convert each point into local coordinates of this object.
        for ( int i = 0 ; i < newVert.Length ; i++ )
        {
            newVert[i] = transform.InverseTransformPoint( newVert[i] );
        }

        // Update the mesh ( collider) with the updated vertices
        mesh.vertices = newVert;
        mesh.uv = skinnedMeshRenderer.sharedMesh.uv; // is this even needed here?
        mesh.triangles = skinnedMeshRenderer.sharedMesh.triangles;
        mesh.RecalculateBounds();
        mesh.MarkDynamic(); // says it should improve performance, but I couldn't see it happening
        meshCollider.sharedMesh = mesh;
    }
开发者ID:nanalucky,项目名称:Pet46,代码行数:32,代码来源:SkinnedCollisionHelper.cs


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