- Home /
How do i modify a mesh Filter(C#)?
Hello i would like to know how can i modify a mesh filter in unity (i have gone to the meshFilter API but doesnt say on how to modify the current mesh)???
$$anonymous$$odify in what sense? Are you trying to deform the mesh?
I posted an answer over an hour ago, but unfortunately Unity is very slow at moderation.
well i have been working with CSG and i am having some trouble with this, when i perform a boolean operation the mesh expands(when the scale is not one) or the mesh i have created and try to replace/modify just renders away from the objects position(when the position is not 0). If you know what i mean?
Cam you post some code? Are you trying go modify the msh vertices at run time?
If you follow my link and the thread you'll find out what i am doing. :P
Answer by felipin · Sep 23, 2016 at 11:41 AM
Hello buddy, alright, the first thing that you must know probably it's how to access the mesh, them you'll need to know how a mesh is structured (vertices, triangles, color, normal, UV, etc.) for you starting to modify meshes.
Here is a little MonoBehaviour showing how that works.
 public class MeshModifier : MonoBehaviour
 {
     private MeshFilter meshFilter;
     
     private void Awake ()
     {
         meshFilter = gameObject.GetComponent<MeshFilter> ();
         
         ModifyMesh (meshFilter.mesh);
     }
     
     private void ModifyMesh (Mesh mesh)
     {
         if (!mesh)
         {
             return;
         }
         
         Vector3[] vertices = mesh.vertices;
         
         // Modify vertices (Move all the vertices one unit to the right)
         for (int i = 0; i < mesh.vertexCount; i++)
         {
             vertices[i].x++;
         }
         
         mesh.vertices = vertices;
     }
 }
Sorry for my bad English.
Thanks-ish, but its not fixing my problem visit here look at post #12.
Answer by rich2020 · Sep 23, 2016 at 11:44 AM
 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     void Update() {
         Mesh mesh = GetComponent<MeshFilter>().mesh;
         Vector3[] vertices = mesh.vertices;
         Vector3[] normals = mesh.normals;
         int i = 0;
         while (i < vertices.Length) {
             vertices[i] += normals[i] * Mathf.Sin(Time.time);
             i++;
         }
         mesh.vertices = vertices;
     }
 }
From here: https://docs.unity3d.com/ScriptReference/Mesh.html
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                