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


C# MeshFilter.GetComponent方法代码示例

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


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

示例1: MeshToString

    public static string MeshToString(MeshFilter mf)
    {
        Mesh m = mf.sharedMesh;
        Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

        StringBuilder sb = new StringBuilder();

        sb.Append("g ").Append(mf.name).Append("\n");
        foreach(Vector3 v in m.vertices) {
            sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,v.z));
        }
        sb.Append("\n");
        foreach(Vector3 v in m.normals) {
            sb.Append(string.Format("vn {0} {1} {2}\n",v.x,v.y,v.z));
        }
        sb.Append("\n");
        foreach(Vector3 v in m.uv) {
            sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
        }
        for (int material=0; material < m.subMeshCount; material ++) {
            sb.Append("\n");
            sb.Append("usemtl ").Append(mats[material].name).Append("\n");
            sb.Append("usemap ").Append(mats[material].name).Append("\n");

            int[] triangles = m.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[i]+1, triangles[i+1]+1, triangles[i+2]+1));
            }
        }

        return sb.ToString();
    }
开发者ID:Daburu,项目名称:Daburu-Tools,代码行数:33,代码来源:ObjExporter.cs

示例2: EJMMesh

		public EJMMesh(MeshFilter component){
			isSkinned = false;
			_mFilter = component;
			mRenderer = component.GetComponent<Renderer> ();
			targettransform = component.transform;
			SetSharedMesh (_mFilter.sharedMesh);
			RefreshMatrix ();
		}
开发者ID:anteaterho,项目名称:SpoutTestTemp,代码行数:8,代码来源:EJMMesh.cs

示例3: MeshToString

        public static string MeshToString(MeshFilter mf)
        {
            var m = mf.sharedMesh;

            var sb = new StringBuilder();

            sb.AppendLine("# Exported from PrimitivesPro, Unity3D asset");
            sb.AppendLine("# http://u3d.as/4gQ");
            sb.AppendLine("--------------------------------------------");
            sb.AppendLine();

            if (mf.GetComponent<Renderer>() && mf.GetComponent<Renderer>().sharedMaterial)
            {
                sb.Append("mtllib ").Append(mf.GetComponent<Renderer>().sharedMaterial.name + ".mtl").Append("\n");
            }

            sb.Append("g ").Append(mf.name).Append("\n");
            foreach (var v in m.vertices)
            {
                sb.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, v.z));
            }
            sb.Append("\n");
            foreach (var v in m.normals)
            {
                sb.Append(string.Format("vn {0} {1} {2}\n", v.x, v.y, v.z));
            }
            sb.Append("\n");
            foreach (var v in m.uv)
            {
                sb.Append(string.Format("vt {0} {1}\n", v.x, v.y));
            }
            for (var material = 0; material < m.subMeshCount; material++)
            {
                sb.Append("\n");
                sb.Append("usemtl ").Append("default").Append("\n");

                int[] triangles = m.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[i] + 1, triangles[i + 1] + 1, triangles[i + 2] + 1));
                }
            }
            return sb.ToString();
        }
开发者ID:jfeng94,项目名称:Thesis,代码行数:45,代码来源:ObjExporter.cs

示例4: MeshToFile

        public static void MeshToFile(MeshFilter mf, string rootPath, string filename, bool exportMaterial)
        {
            var objFile = rootPath + "/" + filename + ".obj";

            using (var sw = new StreamWriter(objFile))
            {
                sw.Write(MeshToString(mf));
            }

            if (mf.GetComponent<Renderer>() && mf.GetComponent<Renderer>().sharedMaterial)
            {
                var materialFile = rootPath + "/" + mf.GetComponent<Renderer>().sharedMaterial.name + ".mtl";

                using (var sw = new StreamWriter(materialFile))
                {
                    sw.Write(MaterialToFile(mf.GetComponent<Renderer>().sharedMaterial, materialFile, rootPath));
                }
            }
        }
开发者ID:jaroosh,项目名称:Habitat,代码行数:19,代码来源:ObjExporter.cs

示例5: MeshToString

	public static string MeshToString(MeshFilter mf, Transform t) 
	{	
		Vector3 s 		= t.localScale;
		Vector3 p 		= t.localPosition;
		Quaternion r 	= t.localRotation;
		
		
		int numVertices = 0;
		Mesh m = mf.sharedMesh;
		if (!m)
		{
			return "####Error####";
		}
		Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;
		
		StringBuilder sb = new StringBuilder();
		
		foreach(Vector3 vv in m.vertices)
		{
			Vector3 v = t.TransformPoint(vv);
			numVertices++;
			sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,-v.z));
		}
		sb.Append("\n");
		foreach(Vector3 nn in m.normals) 
		{
			Vector3 v = r * nn;
			sb.Append(string.Format("vn {0} {1} {2}\n",-v.x,-v.y,v.z));
		}
		sb.Append("\n");
		foreach(Vector3 v in m.uv) 
		{
			sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
		}
		for (int material=0; material < m.subMeshCount; material ++) 
		{
			sb.Append("\n");
			sb.Append("usemtl ").Append(mats[material].name).Append("\n");
			sb.Append("usemap ").Append(mats[material].name).Append("\n");
			
			int[] triangles = m.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[i]+1+StartIndex, triangles[i+1]+1+StartIndex, triangles[i+2]+1+StartIndex));
			}
		}
		
		StartIndex += numVertices;
		return sb.ToString();
	}
开发者ID:JustJessTV,项目名称:GitMergeTest,代码行数:50,代码来源:objExport.cs

示例6: MeshToString

    public static string MeshToString(Transform tr, MeshFilter mf, string prefName)
    {
        Mesh m = mf.mesh;
        Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

        //Debug.Log("subnesh count=" + m.subMeshCount.ToString());

        int vertexShift = vertexCounter;

        StringBuilder sb = new StringBuilder();

        sb.Append("g ").Append(prefName + mf.name).Append("\n");

        foreach (Vector3 v in m.vertices)
        {
            vertexCounter++;
            Matrix4x4 trMatrix = tr.localToWorldMatrix;
            Vector3 v2 = trMatrix.MultiplyPoint3x4(v);
            //Vector3 v2 = tr.TransformPoint(v);
            sb.Append(string.Format("v {0} {1} {2}\n", v2.x, v2.y, v2.z));
        }
        sb.Append("\n");
        foreach (Vector3 v in m.normals)
        {
            Matrix4x4 trMatrix = tr.localToWorldMatrix;
            Vector3 v2 = trMatrix.MultiplyPoint3x4(v);
            //Vector3 v2 = tr.TransformPoint(v);
            sb.Append(string.Format("vn {0} {1} {2}\n", v2.x, v2.y, v2.z));
        }
        sb.Append("\n");
        foreach (Vector3 v in m.uv)
        {
            sb.Append(string.Format("vt {0} {1}\n", v.x, v.y));
        }
        for (int material = 0; material < m.subMeshCount; material++)
        {
            sb.Append("\n");
            sb.Append("usemtl ").Append(prefName + mats[material].name).Append("\n");
            sb.Append("usemap ").Append(prefName + mats[material].name).Append("\n");

            int[] triangles = m.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[i] + 1 + vertexShift, triangles[i + 1] + 1 + vertexShift, triangles[i + 2] + 1 + vertexShift));
            }
        }
        return sb.ToString();
    }
开发者ID:Angel07,项目名称:SpineConstructor,代码行数:49,代码来源:ObjExporter.cs

示例7: MeshToString

 public static string MeshToString(MeshFilter mf)
 {
     Mesh sharedMesh = mf.sharedMesh;
     Material[] sharedMaterials = mf.GetComponent<Renderer>().sharedMaterials;
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.Append("g ").Append(mf.name).Append("\n");
     Vector3[] vertices = sharedMesh.vertices;
     for (int i = 0; i < vertices.Length; i++)
     {
         Vector3 vector = vertices[i];
         stringBuilder.Append(string.Format("v {0} {1} {2}\n", -vector.x, vector.y, vector.z));
     }
     stringBuilder.Append("\n");
     Vector3[] normals = sharedMesh.normals;
     for (int j = 0; j < normals.Length; j++)
     {
         Vector3 vector2 = normals[j];
         stringBuilder.Append(string.Format("vn {0} {1} {2}\n", -vector2.x, vector2.y, vector2.z));
     }
     stringBuilder.Append("\n");
     Vector2[] uv = sharedMesh.uv;
     for (int k = 0; k < uv.Length; k++)
     {
         Vector3 vector3 = uv[k];
         stringBuilder.Append(string.Format("vt {0} {1}\n", vector3.x, vector3.y));
     }
     for (int l = 0; l < sharedMesh.subMeshCount; l++)
     {
         stringBuilder.Append("\n");
         stringBuilder.Append("usemtl ").Append(sharedMaterials[l].name).Append("\n");
         stringBuilder.Append("usemap ").Append(sharedMaterials[l].name).Append("\n");
         int[] triangles = sharedMesh.GetTriangles(l);
         for (int m = 0; m < triangles.Length; m += 3)
         {
             stringBuilder.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", triangles[m + 2] + 1, triangles[m + 1] + 1, triangles[m] + 1));
         }
     }
     return stringBuilder.ToString();
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:39,代码来源:RTPObjExporter.cs

示例8: WriteMesh

    void WriteMesh(MeshFilter meshFilter, StreamWriter outFile, string indent)
    {
        string verticesFileName = mPath + meshFilter.name + ".vertices";
        string normalsFileName = mPath + meshFilter.name + ".normals";
        string uvsFileName = mPath + meshFilter.name + ".uvs";
        string indicesFileName = mPath + meshFilter.name + ".indices";

        WriteArrayToFile (verticesFileName, meshFilter.sharedMesh.vertices);
        WriteArrayToFile (normalsFileName, meshFilter.sharedMesh.normals);
        WriteArrayToFile (uvsFileName, meshFilter.sharedMesh.uv);
        WriteArrayToFile (indicesFileName, meshFilter.sharedMesh.triangles);

        outFile.WriteLine (indent + "<Mesh id=\"" + GetId (meshFilter.transform) + "\" parentId=\"" + GetId (meshFilter.transform.parent) + "\" vertices=\"" + verticesFileName + "\" normals=\"" + normalsFileName + "\" uvs=\"" + uvsFileName + "\" indices=\"" + indicesFileName + "\">");

        WriteTransform (meshFilter.transform, outFile, indent + indent);

        MeshRenderer meshRenderer = meshFilter.GetComponent<MeshRenderer> ();

        if (meshRenderer != null) {
            WriteMaterial (meshRenderer, outFile, indent + indent);
        }

        outFile.WriteLine (indent + "</Mesh>");
    }
开发者ID:pboechat,项目名称:simpleraytracer,代码行数:24,代码来源:simpleraytracer.cs

示例9: MeshToString

    private static string MeshToString(MeshFilter mf, Dictionary<string, ObjMaterial> materialList)
    {
        Mesh m = mf.sharedMesh;
        Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

        StringBuilder sb = new StringBuilder();

        sb.Append("g ").Append(mf.name).Append("\n");
        foreach(Vector3 lv in m.vertices)
        {
            Vector3 wv = mf.transform.TransformPoint(lv);

            //This is sort of ugly - inverting x-component since we're in
            //a different coordinate system than "everyone" is "used to".
            sb.Append(string.Format("v {0} {1} {2}\n",-wv.x,wv.y,wv.z));
        }
        sb.Append("\n");

        foreach(Vector3 lv in m.normals)
        {
            Vector3 wv = mf.transform.TransformDirection(lv);

            sb.Append(string.Format("vn {0} {1} {2}\n",-wv.x,wv.y,wv.z));
        }
        sb.Append("\n");

        foreach(Vector3 v in m.uv)
        {
            sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
        }

        for (int material=0; material < m.subMeshCount; material ++) {
            sb.Append("\n");
            sb.Append("usemtl ").Append(mats[material].name).Append("\n");
            sb.Append("usemap ").Append(mats[material].name).Append("\n");

            //See if this material is already in the materiallist.
            try
            {
                ObjMaterial objMaterial = new ObjMaterial();

                objMaterial.name = mats[material].name;

                if (mats[material].mainTexture)
                    objMaterial.textureName = EditorUtility.GetAssetPath(mats[material].mainTexture);
                else
                    objMaterial.textureName = null;

                materialList.Add(objMaterial.name, objMaterial);
            }
            catch (ArgumentException)
            {
                //Already in the dictionary
            }

            int[] triangles = m.GetTriangles(material);
            for (int i=0;i<triangles.Length;i+=3)
            {
                //Because we inverted the x-component, we also needed to alter the triangle winding.
                sb.Append(string.Format("f {1}/{1}/{1} {0}/{0}/{0} {2}/{2}/{2}\n",
                                        triangles[i]+1 + vertexOffset, triangles[i+1]+1 + normalOffset, triangles[i+2]+1 + uvOffset));
            }
        }

        vertexOffset += m.vertices.Length;
        normalOffset += m.normals.Length;
        uvOffset += m.uv.Length;

        return sb.ToString();
    }
开发者ID:shinobushiva,项目名称:Unity-Utils,代码行数:70,代码来源:EditorObjExporter.cs

示例10: GetWorldPositionFromGridCoordinate

    public static Vector3 GetWorldPositionFromGridCoordinate(MeshFilter planeMeshFilter, float x, float y, int width, int height)
    {
        var localPoint = GetLocalPositionFromGridCoordinate(planeMeshFilter, x, y, width, height);

        var transform = planeMeshFilter.GetComponent<Transform>();
        return transform.TransformPoint(localPoint);
    }
开发者ID:j0rg3n,项目名称:capitalist-pigs-ngj11-game,代码行数:7,代码来源:MathUtil.cs

示例11: VoxelMeshToObjFile

    public static void VoxelMeshToObjFile(string filepath, MeshFilter mf)
    {
        // based on http://wiki.unity3d.com/index.php?title=ObjExporter
        using (StreamWriter writer = new StreamWriter(filepath))
        {
            Mesh m = mf.mesh;
            Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

            writer.Write("g ");
            writer.WriteLine(mf.name);
            foreach (Vector3 v in m.vertices)
            {
                writer.WriteLine("v {0} {1} {2}", v.x, v.y, v.z);
            }
            writer.WriteLine();
            foreach (Vector3 v in m.normals)
            {
                writer.WriteLine("vn {0} {1} {2}", v.x, v.y, v.z);
            }
            writer.WriteLine();
            foreach (Vector3 v in m.uv)
            {
                writer.WriteLine("vt {0} {1}", v.x, v.y);
            }
            for (int material = 0; material < m.subMeshCount; material++)
            {
                writer.WriteLine();
                writer.Write("usemtl ");
                writer.WriteLine(mats[material].name);
                writer.Write("usemap ");
                writer.WriteLine(mats[material].name);

                int[] triangles = m.GetTriangles(material);
                for (int i = 0; i < triangles.Length; i += 3)
                {
                    writer.WriteLine("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}",
                        triangles[i] + 1, triangles[i + 1] + 1, triangles[i + 2] + 1);
                }
            }
        }
    }
开发者ID:BluBambu,项目名称:MultiVoxel,代码行数:41,代码来源:VoxelSerializer.cs

示例12: ProcessMesh

	public static void ProcessMesh(MeshFilter mf, Transform t)
	{
		int numVertices = 0;

		Mesh m = mf.mesh;
		if (!m)
		{
			meshString.Append("####Error####\n");
			return;
		}

		foreach (Vector3 vv in m.vertices)
		{
			Vector3 v = t.TransformPoint(vv);
			numVertices++;
			meshString.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, -v.z));
		}
		meshString.Append("\n");
		foreach (Vector3 nn in m.normals)
		{
			Vector3 v = t.TransformDirection(nn);
			meshString.Append(string.Format("vn {0} {1} {2}\n", -v.x, -v.y, v.z));
		}
		meshString.Append("\n");
		foreach (Vector3 v in m.uv)
		{
			meshString.Append(string.Format("vt {0} {1}\n", v.x, v.y));
		}

		Material[] mats = mf.GetComponent<MeshRenderer>().materials;
		for (int material = 0; material < m.subMeshCount; material++)
		{
			Material mat = mats[material % mats.Length];
			string matName = mat.name.Replace(" (Instance)", "").Replace(' ', '_').Replace("__", "_");

			if (!materialList.ContainsKey(matName))
			{
				materialList.Add(matName, mat);
			}

			meshString.Append("\n");
			meshString.Append("usemtl ").Append(matName).Append("\n");
			meshString.Append("usemap ").Append(matName).Append("\n");

			int[] triangles = m.GetTriangles(material);
			for (int i = 0; i < triangles.Length; i += 3)
			{
				meshString.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
					triangles[i    ] + 1 + indexOffset, 
					triangles[i + 1] + 1 + indexOffset, 
					triangles[i + 2] + 1 + indexOffset));
			}
		}

		indexOffset += numVertices;
	}
开发者ID:stefanmarks,项目名称:MotionServer_Clients,代码行数:56,代码来源:ObjExporter.cs

示例13: MeshToString

	private static string MeshToString(MeshFilter mf, Dictionary<string, ObjMaterial> materialList) 
	{
		Mesh m = mf.sharedMesh;
		Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

		StringBuilder sb = new StringBuilder();

		sb.Append("g ").Append(mf.name).Append("\n");
		
		foreach(Vector3 lv in m.vertices) 
		{
			Vector3 wv = lv;
				
			// this is not how to convert from left to right handed coordinates
			//This is sort of ugly - inverting x-component since we're in
			//a different coordinate system than "everyone" is "used to".
			sb.Append(string.Format("v {0} {1} {2}\n",-wv.x,wv.y,wv.z));
		}

		sb.Append("\n");

		foreach(Vector3 lv in m.normals) 
		{
			Vector3 wv = lv;

			sb.Append(string.Format("vn {0} {1} {2}\n",-wv.x,wv.y,wv.z));
		}

		sb.Append("\n");

		foreach(Vector3 v in m.uv) 
		{
			sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
		}

		for (int i = 0; i < m.subMeshCount; i ++)
		{
			sb.Append("\n");
			sb.Append("g ").Append(mats[i].name).Append("\n");
			sb.Append("usemtl ").Append(mats[i].name).Append("\n");
			sb.Append("usemap ").Append(mats[i].name).Append("\n");

			ObjMaterial objMaterial = new ObjMaterial();

			objMaterial.name = mats[i].name;

			if (mats[i].mainTexture)
				objMaterial.textureName = UnityEditor.AssetDatabase.GetAssetPath(mats[i].mainTexture);
			else 
				objMaterial.textureName = null;

			materialList.Add(objMaterial.name, objMaterial);

			int[] tri = m.GetTriangles(i);
			for (int n = 0; n < tri.Length; n += 3) 
			{
				//Because we inverted the x-component, we also needed to alter the triangle winding.
				sb.Append(string.Format("f {1}/{1}/{1} {0}/{0}/{0} {2}/{2}/{2}\n", 
				tri[n]+1 + vertexOffset, tri[n+1]+1 + normalOffset, tri[n+2]+1 + uvOffset));
			}
		}

		vertexOffset += m.vertices.Length;
		normalOffset += m.normals.Length;
		uvOffset += m.uv.Length;

		return sb.ToString();
	}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:68,代码来源:EditorObjExporter.cs

示例14: buildMesh

		public void buildMesh (Vector3 position)
		{	
			VoxelDrawMesh draw = new VoxelDrawMesh ();
			Debug.Log (real_.Count + "count");
			foreach (KeyValuePair<VectorInt3, VoxelShadowHandler> kv in this.real_) {
				VectorInt4 v = draw.addRect (Vector3.up, kv.Key + new VectorInt3(0, 0, -1) , VoxelShadowHandler.GetUV(kv.Value.real), VoxelShadowHandler.GetUV(kv.Value.ghost), Color.black);
			}

			_mesh = draw.crateMeshFilter ("Shadow", _material);
			if (_offset != null) {
				_mesh.gameObject.transform.SetParent (this._offset.transform);
			} else {
				_mesh.gameObject.transform.SetParent (this.transform);		
			}
			
			_mesh.gameObject.transform.localPosition = Vector3.zero;
			_mesh.gameObject.transform.localScale = Vector3.one;
			_mesh.gameObject.transform.localRotation = Quaternion.Euler (Vector3.zero);
			
			_mesh.gameObject.SetActive (true);
			Renderer renderer = _mesh.GetComponent<Renderer> ();
			renderer.material = this._material;
			showMesh (position);
		}
开发者ID:CzDreamer,项目名称:eat,代码行数:24,代码来源:VoxelShadow.cs

示例15: MeshContainer

 public MeshContainer(MeshFilter meshFilter)
 {
     Mesh = meshFilter.mesh;
     transform = meshFilter.GetComponent<Transform>();
     isAnimated = false;
 }
开发者ID:ZepLI,项目名称:U3D,代码行数:6,代码来源:MeshContainer.cs


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