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


C# Mesh.RecalculateNormals方法代码示例

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


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

示例1: create

    public static void create(string name, List<Vector2> verticesList)
    {
        GameObject obstacle = new GameObject (name, typeof(MeshFilter), typeof(MeshRenderer));
        MeshFilter mesh_filter = obstacle.GetComponent<MeshFilter> ();

        obstacle.transform.position = new Vector3 (0, 0.01f, 0);

        var renderer = obstacle.GetComponent<Renderer>();
        renderer.sharedMaterial = new Material (Shader.Find ("Transparent/Diffuse"));
        renderer.sharedMaterial.color = new Color (1, 0, 0, .3f);

        Vector2[] vertices2D = verticesList.ToArray();

        // Use the triangulator to get indices for creating triangles
        Triangulator tr = new Triangulator(vertices2D);
        int[] indicesArray = tr.Triangulate();
        List<int> indices = new List<int>();
        for (int i = 0;i<indicesArray.Length;i++) {
            indices.Add (indicesArray[i]);
        }

        // Create the Vector3 vertices
        List<Vector3> vertices = new List<Vector3>();

        for (int i=0; i<vertices2D.Length; i++) {
            vertices.Add (new Vector3(vertices2D[i].x, 0, vertices2D[i].y));
        }

        // Create the mesh
        Mesh mesh = new Mesh();

        mesh.vertices = vertices.ToArray();
        mesh.uv = verticesList.ToArray();
        mesh.triangles = indices.ToArray();
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        //flip if needed
        if (mesh.normals [0].y == -1) {
            indices.Reverse ();
            mesh.triangles = indices.ToArray ();
            mesh.RecalculateNormals();
        }

        mesh_filter.mesh = mesh;
        GeometryLoader gl = GameObject.Find ("GeometryLoader").GetComponent<GeometryLoader> ();
        gl.setWorldAsParent (obstacle);
    }
开发者ID:benjaminaaron,项目名称:SumoVizUnity_ModSem,代码行数:48,代码来源:AreaGeometry.cs

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

示例3: MakeQuad

    public static Mesh MakeQuad(Vector3 a, Vector3 b)
    {
        Vector3[] vertices = new Vector3[4];
        vertices [0] = Vector3.zero;
        vertices [1] = a;
        vertices [2] = a + b;
        vertices [3] = b;

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

        // right side up
        Vector2[] uvs = new Vector2[] {
            new Vector2(0, 0),
            new Vector2(0, 1),
            new Vector2(1, 1),
            new Vector2(1, 0)
        };

        Mesh mesh = new Mesh ();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uvs;
        mesh.RecalculateNormals ();
        return mesh;
    }
开发者ID:julenka,项目名称:unity-meshes-class,代码行数:25,代码来源:QuadGenerator.cs

示例4: Start

    void Start()
    {
        plane = new Mesh();
        Vector3[] vertices = new Vector3[] {
            new Vector3(-0.5f, 0.5f, 0),
            new Vector3(0.5f, 0.5f, 0),
            new Vector3(-0.5f, -0.5f, 0),
            new Vector3(0.5f, -0.5f, 0)
        };
        Vector2[] uvs = new Vector2[] {
            new Vector2(0f, 1f),
            new Vector2(1f, 1f),
            new Vector2(0f, 0f),
            new Vector2(1f, 0f)
        };
        int[] triangles = new int[] {
            0, 2, 1, 1, 2, 3
        };
        Color[] colors = new Color[] {
            vertexColor, vertexColor, vertexColor, vertexColor
        };

        plane.vertices = vertices;
        plane.uv = uvs;
        plane.triangles = triangles;
        plane.colors = colors;
        plane.RecalculateNormals();

        MeshFilter filter = GetComponent<MeshFilter>();
        if (!filter)
            filter = gameObject.AddComponent<MeshFilter>();
        filter.mesh = plane;
    }
开发者ID:EmergentRealityLab,项目名称:BasicCAVETest,代码行数:33,代码来源:SpritesheetPlane.cs

示例5: CreatePlane

    public static GameObject CreatePlane(Vector2 size)
    {
        size *= 0.5f;
        Mesh planeMesh = new Mesh();
        planeMesh.name = "CustomPlane";

        //set vertices
        Vector3[] vertices = {
            new Vector3(-size.x, -size.y, 0f),
            new Vector3(size.x, -size.y, 0f),
            new Vector3(size.x, size.y, 0f),
            new Vector3(-size.x, size.y, 0f)};
        planeMesh.vertices = vertices;
        //set uvs
        Vector2[] uvs = {Vector2.zero, Vector2.up, Vector2.one, Vector2.right};
        planeMesh.uv = uvs;
        //set triangles
        int[] triangles = {0, 1, 2, 0, 2, 3};
        planeMesh.triangles = triangles;
        planeMesh.RecalculateNormals();

        //Create gameobject
        GameObject plane = new GameObject("CustomPlane");
        MeshFilter _meshFilter = plane.AddComponent<MeshFilter>();
        _meshFilter.mesh = planeMesh;
        plane.AddComponent<MeshRenderer>();
        plane.AddComponent<MeshCollider>();
        plane.transform.position = Vector3.zero;

        return plane;
    }
开发者ID:ullizei,项目名称:pirates,代码行数:31,代码来源:MeshCreator.cs

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

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

示例8: CreateSplitMesh

	public static void CreateSplitMesh (Mesh mesh, List<Slice2D> slices)
	{
		var sliceCount = slices.Count;

		if (sliceCount < 2)
			return;
		// Eg.: | | | | | => 5 slices = 8 tris (5 - 1 => 4quads * 2tris/quad = 8), times 3 idx / tri
		var triIdx = new int[(sliceCount - 1) * 6];
		// Eg.: 1 3  5 7
		//      0 2  4 6 ... => 0,1,3, 0,3,2, 4,5,7, 4,7,6
		int i = 0;
		// "j" is the Triangle Index
		// Will repeat the number of quads (slices/2) * 6 (# of "j"s per quad)
		for (int j = 0; j < (sliceCount * 3); j = j + 6) {
			triIdx[j] = i;
			triIdx[j + 1] = i + 1;
			triIdx[j + 2] = i + 3;
			triIdx[j + 3] = i;
			triIdx[j + 4] = i + 3;
			triIdx[j + 5] = i + 2;
			//Debug.Log(" j:" + j+" "+(j+1)+" "+(j+2)+" "+(j+3)+" "+(j+4)+" "+(j+5));
			//Debug.Log(" i:" + i + " " + (i + 1) + " " + (i + 3) + " " + (i) + " " + (i + 3) + " " + (i + 2));
			i += 4;
		}
		mesh.SetTriangles (triIdx, 0);
		mesh.RecalculateNormals ();
	}
开发者ID:MaDDoXbr,项目名称:https---github.com-magneticservices-Palomar,代码行数:27,代码来源:MeshTools.cs

示例9: Init

    public void Init(BareerAreaParameters parameters)
    {
        xCoord=parameters.xCoord;
          yCoord=parameters.yCoord;

          parent=parameters.parent;
        //Debug.Log(parent);
        //      Debug.Log(parent);
          Mesh newMesh=new Mesh();
          newMesh.vertices=parameters.basicMesh.vertices;
          newMesh.triangles=parameters.basicMesh.triangles;
          newMesh.uv=parameters.basicMesh.uv;
          newMesh.RecalculateNormals();
          GetComponent<MeshFilter>().sharedMesh=newMesh;

        mesh=GetComponent<MeshFilter>().sharedMesh;

        //	  byte[] bareers = parent.Bareers;
          uvs=mesh.uv;
          for(int i=0; i<areaSize; i++)
        for(int j=0; j<areaSize; j++)
        {
          InitTriangle(j, i);
        }
        gameObject.hideFlags = 0;//HideFlags.HideInInspector|HideFlags.HideInHierarchy;
    }
开发者ID:crassus0,项目名称:Edge-drivers,代码行数:26,代码来源:BareerAreaControls.cs

示例10: GenerateMesh

    public void GenerateMesh(int[,] map, float squareSize)
    {
        if(wallCollider == null)
        {
            wallCollider = walls.gameObject.AddComponent<MeshCollider> ();
        }
        outlines.Clear();
        checkedVertices.Clear ();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        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();
        cave.mesh = mesh;
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        if(!is2D) {
            CreateWallMesh();
        }
    }
开发者ID:AshKatchem,项目名称:GameTest,代码行数:33,代码来源:MeshGen.cs

示例11: ModifyMesh

    public override void ModifyMesh(Mesh mesh)
    {
        if (!IsActive())
            return;
        if (ForceNewMesh || _m == null)
        {
            _m = CreateMesh(mesh, 30, 30, IsFront);
            _verts = _m.vertices;
        }
        var modifiedVerticies = new Vector3[_verts.Length];
        float R, r, beta;

        for (int i = 0; i < _verts.Length; i++)
        {
            var vi = _verts[i];
            R = Mathf.Sqrt(vi.x * vi.x + Mathf.Pow(vi.y - A, 2));
            r = R * Mathf.Sin(Theta);
            beta = Mathf.Asin(vi.x / R) / Mathf.Sin(Theta);

            var v1 = new Vector3(r * Mathf.Sin(beta),
                R + A - r * (1 - Mathf.Cos(beta)) * Mathf.Sin(Theta),
                r * (1 - Mathf.Cos(beta)) * Mathf.Cos(Theta));

            var vert = new Vector3(v1.x * Mathf.Cos(Rho) - v1.z * Mathf.Sin(Rho),
                v1.y,
                (v1.x * Mathf.Sin(Rho) + v1.z * Mathf.Cos(Rho))
                );
            modifiedVerticies[i] = vert;
        }
        mesh.vertices = modifiedVerticies;      
        mesh.uv = _m.uv;
        mesh.triangles = _m.triangles;
        mesh.tangents = _m.tangents;
        mesh.RecalculateNormals();
    }
开发者ID:antonlicht,项目名称:unity.prototype.pageflip,代码行数:35,代码来源:PageCurlModifier.cs

示例12: meshInit

	public void meshInit() {
		Vector2[] vertices = new Vector2[points.Count + 4];
		int j = 0;
		for (; j < points.Count; j++) {
			Point p = points[j];
			double x = centre - Math.Cos (p.getTheta()) * p.getRad();
			double y = -Camera.main.orthographicSize - Camera.main.orthographicSize * 0.05d + (Math.Sin (p.getTheta()) * p.getRad());
			vertices[j] = new Vector2((float)x,(float) y);
		}
		vertices [j++] = new Vector2 ((float)+ size,(float) -size);
		vertices [j++] = new Vector2 ((float)size, (float)size);
		vertices [j++] = new Vector2 ((float)- size, (float)size);
		vertices [j++] = new Vector2 ((float)- size, (float)- size);

		Triangulator t = new Triangulator (vertices);
		int[] indices = t.Triangulate ();
		Vector3[] v3 = new Vector3[vertices.Length];
		for (int i = 0; i < v3.Length; i++) {
			v3[i] = new Vector3(vertices[i].x, vertices[i].y, 0);
		}


		Mesh m = new Mesh ();
		m.vertices = v3;
		m.triangles = indices;
		m.RecalculateNormals ();
		m.RecalculateBounds ();

		
		//Add to stuff
		this.GetComponent<MeshFilter> ().mesh = m;
	}
开发者ID:superdyoll,项目名称:GameJam2016,代码行数:32,代码来源:Shadow.cs

示例13: connectAll

    protected Mesh connectAll()
    {
        Mesh myMesh = new Mesh ();
        List<Vector3> verts = new List<Vector3>(degPerVert * degPerVert);
        List<int> tris = new List<int> (degPerVert * degPerVert);
        int currentTri = 0;
        for (int x =0; x < 360; x += degPerVert)
        {
            for (int y =0; y < 360; y += degPerVert)
            {

                    verts.Add(getPolar(x				,y					,0));
                    verts.Add(getPolar(x				,y + degPerVert		,0));
                    verts.Add(getPolar(x + degPerVert	,y 					,0));
                    verts.Add(getPolar(x + degPerVert	,y + degPerVert		,0));
                    tris.Add(currentTri		);
                    tris.Add(currentTri + 1	);
                    tris.Add(currentTri + 2	);

                    tris.Add(currentTri	+3	);
                    tris.Add(currentTri +2	);
                    tris.Add(currentTri +1 );
                    currentTri += 4;
            }
        }
        myMesh.vertices = verts.ToArray ();
        myMesh.triangles = tris.ToArray ();
        myMesh.RecalculateNormals ();
        return myMesh;
    }
开发者ID:billy1234,项目名称:TerrainGenMaster,代码行数:30,代码来源:Plannet.cs

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

示例15: CreateMesh

    public Mesh CreateMesh()
    {
        Mesh mesh = new Mesh ();

        mesh.vertices = m_Vertices.ToArray ();
        mesh.triangles = m_Indices.ToArray ();

        // Normals sao opcionais
        if (m_Normals.Count == m_Vertices.Count) {
            mesh.normals = m_Normals.ToArray ();
        } else {
            mesh.RecalculateNormals();
        }

        // UVs sao opcionais
        if (m_UVs.Count == m_Vertices.Count) {
            mesh.uv = m_UVs.ToArray();
        }

        // Tangents sao opcionais
        if (m_Tangents.Count == m_Vertices.Count) {
            mesh.tangents = m_Tangents.ToArray();
        }

        mesh.RecalculateBounds ();

        return mesh;
    }
开发者ID:adrianogil,项目名称:ProceduralRace,代码行数:28,代码来源:MeshBuilder.cs


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