Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Username883 · May 02, 2013 at 02:28 PM · meshaudiodynamiccreatebuffer

Creating a dynamic mesh with audio = crash after 30secs ?

Hello all

I'm trying to make a mesh using audio. I have just a rectangle which size and color are set on samples and spectrum values.

When i run game mode, it "works" for 30seconds, then slow and finally, unity crash, even if i try to stop the game mode.

Maybe i have to destroy my mesh while creating another ?

I would like to instantiate this mesh, in point to make a shape with sound, is it possible in the same script or is it a bad way to do that ?

Thanks for reading

Here is the script :

 #pragma strict
 
 var numSamples : int=1024;
 
 var numSpectrum : int=1024;
 
 var widthBranche : float;
 
 var heightBranche : float;
 
 
 private var h:float;
 h *= 0.66;
 
 private var samples:float[];
 
 private var spectrums:float[];
 
 
 var tronc:GameObject;
 var brancheObject:GameObject;
 
 
 var branche:Mesh;
 var brancheMaterial:Material;
 var verticesBranche:Vector3[];
 var filterBranche:MeshFilter;
 var triangleBranche: int[];
 var normalsBranche:Vector3[];
 var uvBranche:Vector2[];
 var rendererBranche:MeshRenderer;
 
 function Start () {
 
     samples=new float[numSamples];
     spectrums=new float[numSpectrum];
     
     
     tronc=GameObject.CreatePrimitive(PrimitiveType.Sphere);
     tronc.name="tronc"; 
     
     brancheObject=new GameObject(); 
     brancheObject.name="branche"; 
     
     
     var filterBranche:MeshFilter=brancheObject.AddComponent(MeshFilter);
     branche=new Mesh();
     filterBranche.mesh=branche;
     rendererBranche=brancheObject.AddComponent(MeshRenderer);
         
     
 }
 
 
 function Update () {
 
 
     audio.GetOutputData(samples,0);
  
     audio.GetSpectrumData(spectrums,0,FFTWindow.BlackmanHarris);
     
         for (var i:int=0;i<numSamples;i++) {
 
 
         if (samples[i]>0) {
     
         if (spectrums[i]>0) {
         
         
         var couleur:Color=new Color(spectrums[i],spectrums[i],samples[i]);
         var couleur2:Color=new Color(spectrums[i]*1000,spectrums[i]*2000,samples[i]*200);
         var duration:float=1.0;    
         var lerp=Mathf.PingPong(Time.time,duration)/duration;
         
         widthBranche=spectrums[i]*1000;
         heightBranche=samples[i]*200;        
                 
         verticesBranche=new Vector3[4];
     
         verticesBranche[0] = new Vector3(0, 0, 0);
         verticesBranche[1] = new Vector3(widthBranche, 0, 0);
         verticesBranche[2] = new Vector3(0, heightBranche, 0);
         verticesBranche[3] = new Vector3(widthBranche, heightBranche, 0);
 
         branche.vertices=verticesBranche;
     
         triangleBranche=new int[6];
     
         triangleBranche[0] = 0;    
         triangleBranche[1] = 2;
         triangleBranche[2] = 1;
 
         triangleBranche[3] = 2;
         triangleBranche[4] = 3;
         triangleBranche[5] = 1;        
     
         branche.triangles=triangleBranche;
     
         normalsBranche=new Vector3[4];        
     
         normalsBranche[0] = -Vector3.forward;
         normalsBranche[1] = -Vector3.forward;
         normalsBranche[2] = -Vector3.forward;
         normalsBranche[3] = -Vector3.forward;
     
         branche.normals=normalsBranche;
     
         uvBranche=new Vector2[4];
     
         uvBranche[0] = new Vector2(0, 0);
         uvBranche[1] = new Vector2(1, 0);
         uvBranche[2] = new Vector2(0, 1);
         uvBranche[3] = new Vector2(1, 1);
 
         branche.uv = uvBranche;
     
         brancheMaterial=new Material(Shader.Find("Particles/Additive"));
         rendererBranche.material.color=Color.Lerp(couleur,couleur2,lerp);    
                                 
         
         
         
         }}else{}
     }
 }
 
 

 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to connect walls corners 3 Answers

Adding Verticies to Mesh 1 Answer

Dynamic Mesh Collider - Optimization 1 Answer

Dynamic Pathfinding 1 Answer

Can I move just some of the verts on a mesh? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges