Hello everyone!
It’s my first time to write a thread… I need help ![]()
I’m making a real-time voice reponsive mesh,
I’d like to make those mesh vertices move by audio data from microphone.
So far, I made a procedural speare mesh and successfully made them moving.
But, for some reason, after I activate my script(voice to mesh), vertices of procedural speare mesh are messed up. I attached screenshot.
<IMAGE 1> Perfect procedural spear mesh without running voice to mesh script
messed up spear mesh after activate script
wireframe view
I don’t understand why this is happening…
here’s my c# code.
using System.Collections;
using UnityEngine;
public class VertAnimation : MonoBehaviour {
private Mesh mesh;
private Vector3[] verts = RoundedCube.vertices;
private Vector3 vertPos;
private GameObject[] reactor;
//public GameObject AngerCrystal;
private const string TAG_REACTORS = "ReactingSound";
// Use this for initialization
void OnEnable()
{
}
void Start()
{
mesh = GetComponent<MeshFilter>().mesh;
verts = mesh.vertices;
foreach (Vector3 vert in verts)
{
vertPos = transform.TransformPoint(vert);
GameObject reactor = new GameObject(TAG_REACTORS);
reactor.transform.position = vertPos;
reactor.transform.parent = transform;
reactor.tag = TAG_REACTORS;
// reactor.AddComponent<VertHandleGizmo>()._parent = this;
}
}
void FixedUpdate()
{
reactor = GameObject.FindGameObjectsWithTag(TAG_REACTORS);
for (int i = 0; i < verts.Length; i++)
{
verts[i] = reactor[i].transform.localPosition - RoundedCube.MeshSize; // ALIGN THE CENTER OF VIBE TO 0,0,0(HALF OF CUBE SIZE)
verts[i] = verts[i] * (AudioVis._samples[i] + 0.1f) * 1000;
}
mesh.vertices = verts;
// mesh.RecalculateBounds();
// mesh.RecalculateNormals();
// if(Input.GetKey(KeyCode.S) == true)
// {
// SaveVertsPos();
// }
}
/*void SaveVertsPos()
{
Vector3[] VertsPos = new Vector3[verts.Length];
for (int i = 0; i < verts.Length; i++)
{
reactor[i] = AngerCrystal;
VertsPos[i] = AngerCrystal.transform.position;
Debug.Log(VertsPos[1].ToString("F2"));
}
}*/
}
Thank you for reading.