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


C# Mesh.Optimize方法代码示例

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


在下文中一共展示了Mesh.Optimize方法的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: Render

    public void Render(BuildingsRender buildingsRender)
    {
        var meshFilter = gameObject.AddComponent<MeshFilter>();
        var meshRenderer = gameObject.AddComponent<MeshRenderer>();

        Material material;
        if (buildingsRender.MaterialMap.TryGetValue(Building.Type, out material))
        {
            meshRenderer.material = material;
        }
        
        var verticies = new List<Vector3>();
        var triangles = new List<int>();

        foreach (var position in Building.Positions)
        {
            var tile = Map.TerrainData.GetTile(position.x, position.y);

            verticies.Add(tile.Corner1 + Offset);
            verticies.Add(tile.Corner2 + Offset);
            verticies.Add(tile.Corner3 + Offset);

            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
            triangles.Add(triangles.Count);
        }
        var mesh = new Mesh();
        meshFilter.mesh = mesh;
        mesh.vertices = verticies.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.Optimize();
        mesh.RecalculateNormals();
    }
开发者ID:astrellon,项目名称:cbt,代码行数:33,代码来源:BuildingRoadRender.cs

示例3: BuildBorderMesh

        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public static void BuildBorderMesh(Mesh pMesh, float pWidth, float pHeight, float pThickness)
        {
            float innerW = pWidth/2-pThickness;
            float innerH = pHeight/2-pThickness;
            float outerW = pWidth/2;
            float outerH = pHeight/2;

            pMesh.vertices = new[] {
                new Vector3( outerW,  outerH, 0),
                new Vector3( outerW, -outerH, 0),
                new Vector3(-outerW, -outerH, 0),
                new Vector3(-outerW,  outerH, 0),
                new Vector3( innerW,  innerH, 0),
                new Vector3( innerW, -innerH, 0),
                new Vector3(-innerW, -innerH, 0),
                new Vector3(-innerW,  innerH, 0)
            };

            pMesh.triangles = new[] {
                0, 1, 4,
                1, 5, 4,
                1, 2, 5,
                2, 6, 5,
                2, 3, 6,
                3, 7, 6,
                3, 4, 7,
                3, 0, 4
            };

            pMesh.uv = new Vector2[8];
            pMesh.RecalculateBounds();
            pMesh.RecalculateNormals();
            pMesh.Optimize();
        }
开发者ID:changjiashuai,项目名称:Hover-VR-Interface-Kit,代码行数:36,代码来源:MeshUtil.cs

示例4: Build

    public void Build()
    {
        float[,,] voxels = new float[size+1,size+1,size+1];
        int height;
        float hFactor;
        for(int z = 0; z < size+1; z++){
        for(int y = 0; y < size+1; y++){
           height = yi + y;
           hFactor = (float)(maxHeight - 2*height) / (float)maxHeight;
        for(int x = 0; x < size+1; x++){
           voxels[x,y,z] = -hFactor + m_perlin.FractalNoise3D((float)(xi+x), (float)(yi+y), (float)(zi+z), 3, freq, 1.0f);
        }}}

        mesh = MarchingCubes.CreateMesh(voxels);

        //UV MAPPING
        Vector3[] vertices = mesh.vertices;
        Vector2[] uvs = new Vector2[mesh.vertices.Length];
        for(int i = 0; i < uvs.Length;i++){
            uvs[i] = new Vector2(vertices[i].x,vertices[i].z);
        }
        mesh.uv = uvs;
        //NORMALS
        mesh.RecalculateNormals();
        //TANGENTS
        TangentSolver.Solve(mesh);
        mesh.Optimize();
        AssetDatabase.CreateAsset(mesh, "Assets/Resources/meshes/mesh" + xi + yi + zi + ".asset");
        //GAMEOBJECT SETUP
        m_mesh.GetComponent<MeshFilter>().mesh = mesh;
        m_mesh.transform.localPosition = gPos;
        m_mesh.AddComponent<MeshCollider>();
    }
开发者ID:victorbstan,项目名称:marchingCubes,代码行数:33,代码来源:VolMesh.cs

示例5: CreateMesh

        public Mesh CreateMesh()
        {
            Mesh m = new Mesh
            {
                vertices = Vertices.ToArray(),
                uv = UV1.ToArray(),
                uv2 = UV2.ToArray(),
                triangles = Triangles.ToArray(),
                colors = Colors.ToArray()
            };

            if(Submeshes.Count > 0)
            {
                CombineInstance[] instances = new CombineInstance[Submeshes.Count];
                for(int i = 0; i < Submeshes.Count; i++)
                {
                    CombineInstance ins = new CombineInstance
                    {
                        mesh = Submeshes[i].CreateMesh(),
                        transform = Matrix4x4.identity
                    };

                    instances[i] = ins;

                }
                m.CombineMeshes(instances, false);
            }

            m.RecalculateNormals();
            m.RecalculateBounds();
            m.Optimize();

            return m;
        }
开发者ID:Arcanum2010,项目名称:UnityVoxelTest,代码行数:34,代码来源:IMesher.cs

示例6: Start

    // Use this for initialization
    void Start()
    {
        mesh = GetComponent<MeshFilter> ().mesh;

        float x = transform.position.x;
        float y = transform.position.y;
        float z = transform.position.z;

        newVertices.Add( new Vector3 (x  , y  , z ));
        newVertices.Add( new Vector3 (x + 1 , y  , z ));
        newVertices.Add( new Vector3 (x + 1 , y-1  , z ));
        newVertices.Add( new Vector3 (x  , y-1  , z ));

        newTriangles.Add(0);
        newTriangles.Add(1);
        newTriangles.Add(3);
        newTriangles.Add(1);
        newTriangles.Add(2);
        newTriangles.Add(3);

        mesh.Clear ();
        mesh.vertices = newVertices.ToArray();
        mesh.triangles = newTriangles.ToArray();
        mesh.Optimize ();
        mesh.RecalculateNormals ();
    }
开发者ID:vtloc,项目名称:glass-earth,代码行数:27,代码来源:Test.cs

示例7: 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

示例8: 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

示例9: ComputeMesh

    public override Mesh ComputeMesh()
    {
        Vector3 p0 = new Vector3(0, 0, 0);
        Vector3 p1 = new Vector3(0, 0.66f, 0);
        Vector3 p2 = new Vector3(0.33f, 1, 0);
        Vector3 p3 = new Vector3(1, 1, 0);
        Vector3 p4 = new Vector3(0.4f, 0.6f, 0);

        Vector3 anchor = new Vector3(0.25f, 0.75f, 0);

        var vertices = new Vector3[] { p0, p1, p2, p3, p4 };
        for(int i = 0; i < vertices.Length; i++)
        {
            vertices[i].Set(vertices[i].x - anchor.x, vertices[i].y - anchor.y, vertices[i].z - anchor.z);
        }

        var mesh = new Mesh();

        mesh.Clear();
        mesh.vertices = vertices;

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

        mesh.colors = new Color[] { new Color(0, 0, 0, 0), new Color(255, 255, 255, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0) };

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

        return mesh;
    }
开发者ID:AnjrilStudio,项目名称:Pokemon-World-Game,代码行数:35,代码来源:TestParticleMesh.cs

示例10: CreateUnitSquare

    public static Mesh CreateUnitSquare()
    {
        var mesh = new Mesh();
        var verts = new Vector3[] {
            new Vector3(-0.5f,  0.5f, 0.0f),
            new Vector3( 0.5f,  0.5f, 0.0f),
            new Vector3(-0.5f, -0.5f, 0.0f),
            new Vector3( 0.5f, -0.5f, 0.0f)
        };
        var uvs = new Vector2[] {
            new Vector2(0.0f, 1.0f),
            new Vector2(1.0f, 1.0f),
            new Vector2(0.0f, 0.0f),
            new Vector2(1.0f, 0.0f)
        };
        var normals = new Vector3[] {
            new Vector3(0, 1, 0),
            new Vector3(0, 1, 0),
            new Vector3(0, 1, 0),
            new Vector3(0, 1, 0)
        };
        var idx = new int[] { 0, 1, 2, 3, 2, 1 };
        mesh.vertices = verts;
        mesh.uv = uvs;
        mesh.normals = normals;
        mesh.triangles = idx;
        mesh.RecalculateBounds();
        mesh.Optimize();

        return mesh;
    }
开发者ID:rje,项目名称:rubbertron,代码行数:31,代码来源:ProceduralGeometry.cs

示例11: deformCell

    void deformCell(GameObject cell)
    {
        Mesh cellMesh = new Mesh();//Instantiate (cell.GetComponent<MeshFilter>().sharedMesh) as Mesh;
        //cellMesh = cell.GetComponent<MeshFilter>().sharedMesh;
        Vector3[] vertices = new Vector3[cell.GetComponent<MeshFilter>().sharedMesh.vertexCount];
        cell.GetComponent<MeshFilter>().sharedMesh.vertices.CopyTo(vertices, 0);
        cellMesh.vertices = vertices;
        Vector3[] normals = new Vector3[cell.GetComponent<MeshFilter>().sharedMesh.vertexCount];
        cell.GetComponent<MeshFilter>().sharedMesh.normals.CopyTo(normals, 0);
        for(int i = 0; i < cellMesh.vertexCount; ++i){
            Vector3 newPos = cell.transform.position + vertices[i];
            vertices[i].y = geo.terrainData.GetInterpolatedHeight(newPos.x, newPos.z);//SampleHeight(cell.transform.position + vertices[i]);
            Debug.Log("vertice: " + i + ": " + vertices[i]);
        }

        cellMesh.name = cell.name;

        cellMesh.vertices = vertices;
        cellMesh.normals = normals;
        cellMesh.triangles = cell.GetComponent<MeshFilter>().sharedMesh.triangles;
        cellMesh.uv = cell.GetComponent<MeshFilter>().sharedMesh.uv;
        cellMesh.uv1 = cell.GetComponent<MeshFilter>().sharedMesh.uv1;
        cellMesh.uv2 = cell.GetComponent<MeshFilter>().sharedMesh.uv2;
        cellMesh.Optimize();
        cellMesh.RecalculateBounds();

        cell.GetComponent<MeshFilter>().sharedMesh = cellMesh;
        cell.GetComponent<MeshCollider>().sharedMesh = cellMesh;
    }
开发者ID:TacticsMMO,项目名称:Tactics,代码行数:29,代码来源:testMatch.cs

示例12: Start

    void Start () {
        RotationController.CalibratedRotation().Add(this);

        scoreTextObject.transform.position = new Vector3(0, lvlGenerationTunnelHeight, 10);

        lvlGenerationGameObjects = new List<GameObject>();
        lvlGenerationCurrent = -lvlGenerationBackwards;
        transform.position = new Vector3(0.0f, 2.0f, 0.0f);
        transform.eulerAngles = Vector3.up;
        move = true;
        score = 0;
        UpdateScoreDisplay();
        Mesh mesh = new Mesh();
        {
            mesh.vertices = new Vector3[]{
                new Vector3(-lvlGenerationTunnelWidth, 0, 0),
                new Vector3(-lvlGenerationTunnelWidth, 0, lvlGenerationMeshDistance),
                new Vector3(lvlGenerationTunnelWidth, 0, lvlGenerationMeshDistance),
                new Vector3(lvlGenerationTunnelWidth, 0, 0)
            };
            mesh.triangles = new int[]{
                0,1,2,
                0,2,3
            };
            mesh.RecalculateNormals();
            mesh.RecalculateBounds();
            mesh.Optimize();
        }
        lvlGenerationTestMesh = mesh;
    }
开发者ID:michel-zimmer,项目名称:sw-minigame-unity,代码行数:30,代码来源:FlightBoardController.cs

示例13: InitializeSharedMesh

    static void InitializeSharedMesh()
    {
        sharedMesh = new Mesh ();
        sharedMesh.subMeshCount = 2;

        var vertices = new Vector3 [4 * 6];

        vertices [0] = new Vector3 (-1, +1, -1);
        vertices [1] = new Vector3 (+1, +1, -1);
        vertices [2] = new Vector3 (+1, -1, -1);
        vertices [3] = new Vector3 (-1, -1, -1);

        vertices [4] = new Vector3 (+1, +1, -1);
        vertices [5] = new Vector3 (+1, +1, +1);
        vertices [6] = new Vector3 (+1, -1, +1);
        vertices [7] = new Vector3 (+1, -1, -1);

        vertices [8] = new Vector3 (+1, +1, +1);
        vertices [9] = new Vector3 (-1, +1, +1);
        vertices [10] = new Vector3 (-1, -1, +1);
        vertices [11] = new Vector3 (+1, -1, +1);

        vertices [12] = new Vector3 (-1, +1, +1);
        vertices [13] = new Vector3 (-1, +1, -1);
        vertices [14] = new Vector3 (-1, -1, -1);
        vertices [15] = new Vector3 (-1, -1, +1);

        vertices [16] = new Vector3 (-1, +1, +1);
        vertices [17] = new Vector3 (+1, +1, +1);
        vertices [18] = new Vector3 (+1, +1, -1);
        vertices [19] = new Vector3 (-1, +1, -1);

        vertices [20] = new Vector3 (-1, -1, -1);
        vertices [21] = new Vector3 (+1, -1, -1);
        vertices [22] = new Vector3 (+1, -1, +1);
        vertices [23] = new Vector3 (-1, -1, +1);

        sharedMesh.vertices = vertices;

        var indices = new int[vertices.Length];
        for (var i = 0; i < indices.Length; i++) {
            indices [i] = i;
        }
        sharedMesh.SetIndices (indices, MeshTopology.Quads, 0);

        sharedMesh.Optimize ();
        sharedMesh.RecalculateNormals ();

        indices = new int[4 * 3 * 2];
        var offs = 0;
        for (var i1 = 0; i1 < 16; i1 += 4) {
            for (var i2 = i1; i2 < i1 + 3; i2++) {
                indices [offs++] = i2;
                indices [offs++] = i2 + 1;
            }
        }
        sharedMesh.SetIndices (indices, MeshTopology.Lines, 1);
    }
开发者ID:keijiro,项目名称:VJ01,代码行数:58,代码来源:WireSolidMeshBuilder.cs

示例14: ApplyToMesh

 public static void ApplyToMesh(Mesh mesh, MeshDesc desc)
 {
     mesh.Clear();
     mesh.vertices = desc.positions.ToArray();
     mesh.normals = desc.normals.ToArray();
     mesh.triangles = desc.indices.ToArray();
     mesh.Optimize();
     mesh.RecalculateBounds();
 }
开发者ID:smogpill,项目名称:transit,代码行数:9,代码来源:MeshUtils.cs

示例15: Compile

 public void Compile()
 {
     mesh = new Mesh();
     mesh.vertices = vertices;
     mesh.triangles = triangles;
     mesh.Optimize();
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }
开发者ID:snarf95,项目名称:DungeonRun,代码行数:9,代码来源:ProceduralMesh.cs


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