• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# UnityEngine.Mesh类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Mesh类属于UnityEngine命名空间,在下文中一共展示了Mesh类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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: WriteChunk

        protected override void WriteChunk(out byte[] chunkData, Mesh mesh)
        {
            //mesh.uv1 and mesh.uv2 are the second uv set
            var uv1 = mesh.uv;
            var uv2 = mesh.uv1;
            var chunkLength = uv1.Length*UV_SIZE + uv2.Length*UV_SIZE + HEADER_SIZE;
            chunkData = new byte[chunkLength];

            var uv1Floats = new float[uv1.Length*2];
            var uv2Floats = new float[uv2.Length*2];
            for (var i = 0; i < uv1Floats.Length; i += 2)
            {
                var vert = uv1[i / 2];
                uv1Floats[i] = vert.x;
                uv1Floats[i + 1] = vert.y;
            }
            for (var i = 0; i < uv2Floats.Length; i += 2)
            {
                var vert = uv2[i / 2];
                uv2Floats[i] = vert.x;
                uv2Floats[i + 1] = vert.y;
            }

            //do actual writing
            //byte counts
            var uv1Count = uv1Floats.Length*sizeof (float);
            var uv2Count = uv2Floats.Length*sizeof (float);
            //header
            CopyBytes(uv1Count, chunkData, 0);
            CopyBytes(uv2Count, chunkData, sizeof(int));
            //data
            Buffer.BlockCopy(uv1Floats, 0, chunkData, HEADER_SIZE, uv1Count);
            Buffer.BlockCopy(uv2Floats, 0, chunkData, HEADER_SIZE + uv1Count, uv2Count);
        }
开发者ID:babon,项目名称:UnityMesh,代码行数:34,代码来源:UVsChunk.cs


示例4: ModifyMesh

		public override void ModifyMesh(Mesh mesh) {

			if (this.IsActive() == false) {

				return;

			}
			
			var list = new List<UIVertex>();
			using (var vertexHelper = new VertexHelper(mesh)) {

				vertexHelper.GetUIVertexStream(list);

			}
			
			this.ModifyVertices(list);  // calls the old ModifyVertices which was used on pre 5.2
			
			using (var vertexHelper = new VertexHelper()) {

				vertexHelper.AddUIVertexTriangleStream(list);
				vertexHelper.FillMesh(mesh);

			}

		}
开发者ID:RuFengLau,项目名称:Unity3d.UI.Windows,代码行数:25,代码来源:BaseVertexEffect.cs


示例5: Cut

 /// <summary>
 /// cut mesh by plane
 /// </summary>
 /// <param name="mesh">mesh to cut</param>
 /// <param name="meshTransform">transformation of the mesh</param>
 /// <param name="plane">cutting plane</param>
 /// <param name="triangulateHoles">flag for triangulation of holes</param>
 /// <param name="crossSectionVertexColor">this color will be assigned to cross section, valid only for vertex color shaders</param>
 /// <param name="crossUV">uv mapping area for cross section</param>
 /// <param name="allowOpenMesh">allow cutting of open mesh</param>
 /// <returns>processing time</returns>
 public float Cut(Mesh mesh, Transform meshTransform, Math.Plane plane, bool triangulateHoles, bool allowOpenMesh, ref List<CutterMesh> meshes,
                  Color crossSectionVertexColor, Vector4 crossUV)
 {
     this.crossSectionVertexColour = crossSectionVertexColor;
     this.crossSectionUV = crossUV;
     return Cut(mesh, meshTransform, plane, triangulateHoles, allowOpenMesh, ref meshes);
 }
开发者ID:seonwifi,项目名称:bongbong,代码行数:18,代码来源:MeshCutter.cs


示例6: ExportToString

		public static string ExportToString (Mesh mesh, Renderer renderer, bool uselhcoords = true, bool separateSubmeshes = true){
			Material[] mats = renderer.sharedMaterials;
			// Initiation
			StringBuilder sb = new StringBuilder();
			//Header
			sb.Append("o ").Append("Plane").Append("\n");
			foreach(Vector3 v in mesh.vertices) {
				sb.Append(string.Format("v {0:0.000000} {1:0.000000} {2:0.000000}\n",(uselhcoords?-v.x:v.x),v.y,v.z));
			}
			sb.Append("\n");
			foreach(Vector3 v in mesh.normals) {
				sb.Append(string.Format("vn {0:0.000000} {1:0.000000} {2:0.000000}\n",v.x,v.y,v.z));
			}
			sb.Append("\n");
			foreach(Vector3 v in mesh.uv) {
				sb.Append(string.Format("vt {0:0.000000} {1:0.000000}\n",v.x,v.y));
			}
			for (int material=0; material < mesh.subMeshCount; material ++) {
				sb.Append("\n");
				if (separateSubmeshes){
					sb.Append("g ").Append(mats[material].name).Append("\n");
				}
				sb.Append("usemtl ").Append(mats[material].name).Append("\n");
				sb.Append("usemap ").Append(mats[material].name).Append("\n");
				
				int[] triangles = mesh.GetTriangles(material);
				for (int i=0;i<triangles.Length;i+=3) {
					sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", 
					                        triangles[(uselhcoords?i+1:i)]+1, triangles[(uselhcoords?i:i+1)]+1, triangles[i+2]+1));
				}
			}
			return sb.ToString();
		}
开发者ID:anteaterho,项目名称:SpoutTestTemp,代码行数:33,代码来源:ObjTools.cs


示例7: CombineMeshes

        public static void CombineMeshes(Queue<CombineInstance> items
            , byte area
            , InputGeometryCompiler compiler)
        {
            const int MaxTris = 65000;

            List<CombineInstance> combineInstancesPart = new List<CombineInstance>();
            byte[] areas = NMGen.CreateAreaBuffer(MaxTris, area);

            while (items.Count != 0)
            {
                int vertCount = 0;

                while (items.Count > 0
                    && (vertCount + items.Peek().mesh.vertexCount < MaxTris))
                {
                    vertCount += items.Peek().mesh.vertexCount;
                    combineInstancesPart.Add(items.Dequeue());
                }

                Mesh meshPart = new Mesh();

                meshPart.CombineMeshes(combineInstancesPart.ToArray(), true, true);

                compiler.AddTriangles(meshPart.vertices, meshPart.vertexCount
                    , meshPart.triangles, areas, meshPart.triangles.Length / 3);

                Object.DestroyImmediate(meshPart);

                combineInstancesPart.Clear();
            }
        }
开发者ID:kbengine,项目名称:unity3d_nav_critterai,代码行数:32,代码来源:MeshUtil.cs


示例8: Set

		/// <summary>
		/// Sets the pivot to a given Vector3 offset from the center of the Mesh bounds.
		/// </summary>
		public static Vector3 Set (Mesh mesh, Vector3 offset)
		{
			mesh.RecalculateBounds ();
			Vector3 diff = mesh.bounds.center - offset;
			PivotTools.Move (mesh, diff);
			return diff;
		}
开发者ID:anteaterho,项目名称:SpoutTestTemp,代码行数:10,代码来源:PivotTools.cs


示例9: OnPopulateMesh

 protected override void OnPopulateMesh(Mesh toFill)
 {
     Texture mainTexture = this.mainTexture;
     if (mainTexture != null)
     {
         Vector4 zero = Vector4.zero;
         int num = Mathf.RoundToInt(mainTexture.width * this.uvRect.width);
         int num2 = Mathf.RoundToInt(mainTexture.height * this.uvRect.height);
         float num3 = ((num & 1) != 0) ? ((float) (num + 1)) : ((float) num);
         float num4 = ((num2 & 1) != 0) ? ((float) (num2 + 1)) : ((float) num2);
         zero.x = 0f;
         zero.y = 0f;
         zero.z = ((float) num) / num3;
         zero.w = ((float) num2) / num4;
         zero.x -= base.rectTransform.pivot.x;
         zero.y -= base.rectTransform.pivot.y;
         zero.z -= base.rectTransform.pivot.x;
         zero.w -= base.rectTransform.pivot.y;
         zero.x *= base.rectTransform.rect.width;
         zero.y *= base.rectTransform.rect.height;
         zero.z *= base.rectTransform.rect.width;
         zero.w *= base.rectTransform.rect.height;
         using (VertexHelper helper = new VertexHelper())
         {
             Color color = base.color;
             helper.AddVert(new Vector3(zero.x, zero.y), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
             helper.AddVert(new Vector3(zero.x, zero.w), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.w), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.y), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
             helper.AddTriangle(0, 1, 2);
             helper.AddTriangle(2, 3, 0);
             helper.FillMesh(toFill);
         }
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:35,代码来源:RawImage.cs


示例10: ModifyMesh

 public override void ModifyMesh(Mesh mesh)
 {
     if (this.IsActive())
     {
         List<UIVertex> stream = new List<UIVertex>();
         using (VertexHelper helper = new VertexHelper(mesh))
         {
             helper.GetUIVertexStream(stream);
         }
         int num = stream.Count * 5;
         if (stream.Capacity < num)
         {
             stream.Capacity = num;
         }
         int start = 0;
         int count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, -base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, -base.effectDistance.y);
         using (VertexHelper helper2 = new VertexHelper())
         {
             helper2.AddUIVertexTriangleStream(stream);
             helper2.FillMesh(mesh);
         }
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:33,代码来源:Outline.cs


示例11: Center

		/// <summary>
		/// Centers the pivot of the mesh
		/// </summary>
		/// <returns>
		/// The offset the geometry was moved by to center the pivot.
		/// </returns>
		/// <param name='mesh'>
		/// Mesh
		/// </param>
		public static Vector3 Center (Mesh mesh)
		{
			mesh.RecalculateBounds ();
			Vector3 diff = mesh.bounds.center;
			PivotTools.Move (mesh, diff);
			return diff;
		}
开发者ID:anteaterho,项目名称:SpoutTestTemp,代码行数:16,代码来源:PivotTools.cs


示例12: CreateMesh

        public static Mesh CreateMesh(Vector2 dimensions)
        {
            Mesh mesh = new Mesh();

            Vector3[] vertices = new Vector3[] {
                new Vector3(dimensions.x, dimensions.y,  0),
                new Vector3(dimensions.x, -dimensions.y, 0),
                new Vector3(-dimensions.x, dimensions.y, 0),
                new Vector3(-dimensions.x, -dimensions.y, 0),
            };

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

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

            mesh.vertices = vertices;
            mesh.uv = uv;
            mesh.triangles = triangles;
            mesh.RecalculateNormals();

            return mesh;
        }
开发者ID:pjohalloran,项目名称:balloonbasket_unity,代码行数:30,代码来源:Utils.cs


示例13: Export

        public static bool Export(string folder, string filename, Mesh mesh, ExportMaterial[] textures, bool copyTextures)
        {
		
            exportMesh = mesh;
            exportTextures = textures;
            targetFolder = folder;
            targetName = filename;
            _copyTextures = copyTextures;
		
            if(folder.Contains(" "))
            {
                EditorUtility.DisplayDialog("Filename Error","The filename can't contain spaces","I'm sorry");
                return false;
            }
		
            if(filename.Contains(" "))
            {
                EditorUtility.DisplayDialog("Filename Error","The filename can't contain spaces","I'm sorry");
                return false;
            }
		
            /*if (!CreateTargetFolder())
		{
			Debug.LogError("There was a problem with the destination folder");
    		return false;
		}*/
		
            MeshToFile(targetFolder, targetName);
		
            exportMesh = null;
            exportTextures = null;
		
            return  true;
        }
开发者ID:Alx666,项目名称:ProjectPhoenix,代码行数:34,代码来源:OBJExporter.cs


示例14: GenerateProportionalUVs

        static Vector2[] GenerateProportionalUVs( Vector3[] vertices, Mesh original )
        {
            Vector2[] result = new Vector2[ vertices.Length ];

            int vertexIndexToCalculateDiff = 0;
            for ( int i = 1; i < original.vertexCount; i++ ) {
                if ( original.vertices[ 0 ].x != original.vertices[ i ].x &&
                     original.vertices[ 0 ].y != original.vertices[ i ].y ) {
                    vertexIndexToCalculateDiff = i;
                    break;
                }
            }
            if ( vertexIndexToCalculateDiff == 0 ) {
                throw new System.Exception( "Couldn't find vertexes with different x and y coordinates!" );
            }

            Vector3 twoFirstVerticesDiff = original.vertices[ vertexIndexToCalculateDiff ] - original.vertices[ 0 ];
            Vector2 twoFirstUVsDiff = original.uv[ vertexIndexToCalculateDiff ] - original.uv[ 0 ];
            Vector2 distanceToUVMap = new Vector2();
            distanceToUVMap.x = twoFirstUVsDiff.x / twoFirstVerticesDiff.x;
            distanceToUVMap.y = twoFirstUVsDiff.y / twoFirstVerticesDiff.y;

            for ( int i = 0; i < vertices.Length; i++ ) {
                result[ i ] = ( vertices[ i ] - original.vertices[ 0 ] );
                result[ i ] = new Vector2( result[ i ].x * distanceToUVMap.x,
                                           result[ i ].y * distanceToUVMap.y );
                result[ i ] += original.uv[ 0 ];
            }

            return result;
        }
开发者ID:sabikku,项目名称:unity-sprite-cutter,代码行数:31,代码来源:FlatConvexPolygonMeshCutter.cs


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


示例16: Construct

        /// <summary>
        /// construct a new bsp tree from unity mesh
        /// </summary>
        /// <param name="mesh">unity mesh</param>
        /// <param name="meshTransform">transformation</param>
        /// <param name="id">id of the mesh</param>
        public void Construct(Mesh mesh, Transform meshTransform, int id)
        {
            // cache mesh data
            var trianglesNum = mesh.triangles.Length;
            var meshTriangles = mesh.triangles;
            var meshVertices = mesh.vertices;
            var meshNormals = mesh.normals;
            var meshUV = mesh.uv;

            Polygons = new List<CSGPolygon>(trianglesNum/3);

            for (int i = 0; i < trianglesNum; i+=3)
            {
                var id0 = meshTriangles[i];
                var id1 = meshTriangles[i + 1];
                var id2 = meshTriangles[i + 2];

                Polygons.Add(new CSGPolygon(id, new CSGVertex(meshTransform.TransformPoint(meshVertices[id0]), meshTransform.TransformDirection(meshNormals[id0]), meshUV[id0]),
                                             new CSGVertex(meshTransform.TransformPoint(meshVertices[id1]), meshTransform.TransformDirection(meshNormals[id1]), meshUV[id1]),
                                             new CSGVertex(meshTransform.TransformPoint(meshVertices[id2]), meshTransform.TransformDirection(meshNormals[id2]), meshUV[id2])));
            }

            root = new CSGNode();
            root.Build(Polygons);
        }
开发者ID:jaroosh,项目名称:Habitat,代码行数:31,代码来源:CSG.cs


示例17: GetSmoothVersionOf

 public static Mesh GetSmoothVersionOf(Mesh sourceMesh, int iterations = 1, float alpha = 0, float beta = .5f)
 {
     var workingMesh = sourceMesh.Clone();
     for (int i = 0; i < iterations; i++)
         workingMesh.vertices = HCFilter(sourceMesh.vertices, workingMesh.vertices, workingMesh.triangles, alpha, beta);
     return workingMesh;
 }
开发者ID:NoxCaos,项目名称:dotoriko-unity,代码行数:7,代码来源:SmoothFilter.cs


示例18: Dispose

        public void Dispose()
        {
            if (snapShotMesh != null)
                UnityEngine.Object.DestroyImmediate(snapShotMesh);

            snapShotMesh = null;
        }
开发者ID:WhiteRavensGame,项目名称:JRPGTownPrototype,代码行数:7,代码来源:SkinnedMeshProvider.cs


示例19: CreateInstance

		public static pb_Renderable CreateInstance(Mesh InMesh, Material InMaterial)
		{
			pb_Renderable ren = ScriptableObject.CreateInstance<pb_Renderable>();
			ren.mesh = InMesh;
			ren.materials = new Material[] { InMaterial };
			return ren;
		}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:7,代码来源:pb_Renderable.cs


示例20: Initialize

        public void Initialize(List<Vector3> verts, bool ocean)
        {
            // initialize
            tileObject = new GameObject("TileObject", typeof(MeshRenderer));
            tileMesh = new Mesh();
            vertices = verts;
            plate = -1;

            // find centerpoint
            centerPoint = CenterPoint(vertices);

            //centerPoint = Vector3.zero;
            tileColor = new Color(UnityEngine.Random.Range(0.0f, 1.0f), 
                UnityEngine.Random.Range(0.0f, 1.0f),
                UnityEngine.Random.Range(0.0f, 1.0f), 1);
            

            // sort points clockwise
            SortPointsClockwise(centerPoint);

            // create triangles
            if (ocean == false) CreateTriangles(tileColor);
            else CreateTrianglesOcean();
            foreach (Transform child in transform) Destroy(child.gameObject);

            // merge into one mesh
            UnifyMesh(ref tileMesh);
            Destroy(tileObject);
        }
开发者ID:jellyberg2,项目名称:Planet-Architect,代码行数:29,代码来源:VoronoiTile.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnityEngine.MeshCollider类代码示例发布时间:2022-05-26
下一篇:
C# UnityEngine.Matrix4x4类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap